tinyramfs: simplification and cleanup
This commit is contained in:
parent
bd16dcbd77
commit
0b96f116dd
@ -6,7 +6,7 @@ Tinyramfs - tiny initramfs written in POSIX shell
|
||||
|
||||
# SYNOPSIS
|
||||
|
||||
*tinyramfs* [option ...]
|
||||
*tinyramfs* [option]...
|
||||
|
||||
# DESCRIPTION
|
||||
|
||||
@ -15,20 +15,11 @@ with focus on portability.
|
||||
|
||||
# OPTIONS
|
||||
|
||||
*-m*, *--modules* <directory>
|
||||
|
||||
Specify directory where modules stored. Default is */lib/modules*.
|
||||
|
||||
*-s*, *--sources* <directory>
|
||||
|
||||
Specify directory where tinyramfs stored files such as *device-helper*
|
||||
and *init*. Default is */usr/share/tinyramfs*.
|
||||
|
||||
*-o*, *--output* <output>
|
||||
*-o*, *--output* <file>
|
||||
|
||||
Specify output location where initramfs image will be stored.
|
||||
|
||||
*-c*, *--config* <config>
|
||||
*-c*, *--config* <file>
|
||||
|
||||
Specify config location. Default is */etc/tinyramfs/config*.
|
||||
|
||||
@ -37,11 +28,24 @@ with focus on portability.
|
||||
Specify kernel version. Useful for bootstraping future system with modular
|
||||
kernel. Default is current kernel version.
|
||||
|
||||
*-m*, *--modules* <directory>
|
||||
|
||||
Specify directory where modules stored. Default is */lib/modules*.
|
||||
This option has no effect if *monolith* or *hostonly* were enabled in config.
|
||||
|
||||
*-H*, *--hooks* <directory>
|
||||
|
||||
Specify additional hooks location. Default is */usr/share/tinyramfs/hooks*
|
||||
and */etc/tinyramfs/hooks*.
|
||||
|
||||
*-D*, *--helper* <file>
|
||||
|
||||
Specify location to device helper. Default is */usr/share/tinyramfs/device-helper*.
|
||||
|
||||
*-I*, *--init* <file>
|
||||
|
||||
Specify location to init script. Default is */usr/share/tinyramfs/init*.
|
||||
|
||||
*-d*, *--debug*
|
||||
|
||||
Enable debug mode. Useful for reporting bugs in build stage.
|
||||
|
@ -80,8 +80,9 @@ interact with build and init system.
|
||||
- B: tmpdir - full path of tinyramfs working directory (initramfs rootfs in future)
|
||||
- B: kernel - kernel version
|
||||
- B: moddir - modules directory
|
||||
- B: init - path to init script
|
||||
- B: helper - path to device-helper script
|
||||
- B: config - config location
|
||||
- B: srcdir - directory of tinyramfs system files
|
||||
- B: output - output path
|
||||
- BI: see tinyramfs.config(5)
|
||||
```
|
||||
|
68
tinyramfs
68
tinyramfs
@ -22,14 +22,15 @@ usage()
|
||||
{
|
||||
cat << EOF
|
||||
usage: ${0##*/} [option]...
|
||||
-o, --output <file> set initramfs output path
|
||||
-c, --config <file> set config file path
|
||||
-m, --modules <dir> set modules directory
|
||||
-s, --sources <dir> set sources directory
|
||||
-k, --kernel <ver> set kernel version
|
||||
-H, --hooks <dir> set hooks directory
|
||||
-d, --debug enable debug mode
|
||||
-f, --force overwrite initramfs image
|
||||
-o, --output <file> set path to initramfs image
|
||||
-c, --config <file> set path to config
|
||||
-k, --kernel <ver> set kernel version
|
||||
-m, --modules <dir> set path to modules
|
||||
-H, --hooks <dir> set directory to hooks
|
||||
-D, --helper <file> set path to device helper
|
||||
-I, --init <file> set path to init script
|
||||
-d, --debug enable debug mode
|
||||
-f, --force overwrite initramfs image
|
||||
EOF
|
||||
}
|
||||
|
||||
@ -42,18 +43,21 @@ parse_arguments()
|
||||
-c | --config)
|
||||
config="${2:?}"; shift 2
|
||||
;;
|
||||
-m | --modules)
|
||||
moddir="${2:?}"; shift 2
|
||||
;;
|
||||
-s | --sources)
|
||||
srcdir="${2:?}"; shift 2
|
||||
;;
|
||||
-k | --kernel)
|
||||
kernel="${2:?}"; shift 2
|
||||
;;
|
||||
-m | --modules)
|
||||
moddir="${2:?}"; shift 2
|
||||
;;
|
||||
-H | --hooks)
|
||||
hksdir="${2:?}"; shift 2
|
||||
;;
|
||||
-D | --helper)
|
||||
helper="${2:?}"; shift 2
|
||||
;;
|
||||
-I | --init)
|
||||
init="${2:?}"; shift 2
|
||||
;;
|
||||
-d | --debug)
|
||||
debug=1; shift 1
|
||||
;;
|
||||
@ -76,8 +80,9 @@ parse_arguments()
|
||||
|
||||
: "${kernel:=$(uname -r)}"
|
||||
: "${moddir:=/lib/modules}"
|
||||
: "${srcdir:=/usr/share/tinyramfs}"
|
||||
: "${output:=/boot/tinyramfs-${kernel}}"
|
||||
: "${init:=/usr/share/tinyramfs/init}"
|
||||
: "${helper:=/usr/share/tinyramfs/device-helper}"
|
||||
: "${output:=${TMPDIR:-/tmp}/tinyramfs-${kernel}}"
|
||||
|
||||
mkdir -p "${tmpdir:=${TMPDIR:-/tmp}/tinyramfs.$$}"
|
||||
|
||||
@ -113,15 +118,15 @@ prepare_initramfs()
|
||||
|
||||
for _binary in \
|
||||
\[ sh ln env kill mkdir sleep mount \
|
||||
printf switch_root "${srcdir}/device-helper"
|
||||
printf switch_root "$helper"
|
||||
do
|
||||
copy_binary "$_binary"
|
||||
done
|
||||
|
||||
command -v blkid > /dev/null && copy_binary blkid
|
||||
|
||||
copy_file "${srcdir}/init" /init 755 0
|
||||
copy_file "$config" /etc/tinyramfs/config 644 0
|
||||
copy_file "$init" /init 755 0
|
||||
copy_file "$config" /etc/tinyramfs/config 644 0
|
||||
}
|
||||
|
||||
copy_file()
|
||||
@ -184,6 +189,9 @@ copy_binary()
|
||||
|
||||
copy_file "$binary" "/bin/${binary##*/}" 755 1
|
||||
|
||||
# Skip copying binary dependencies if ldd not available.
|
||||
command -v ldd || return 0
|
||||
|
||||
# Copy binary dependencies if any exist.
|
||||
ldd "$binary" 2> /dev/null |
|
||||
|
||||
@ -289,25 +297,17 @@ copy_modules()
|
||||
-type f 2> /dev/null |
|
||||
|
||||
while read -r _module || [ "$_module" ]; do
|
||||
|
||||
# Strip path and extension
|
||||
_module="${_module##*/}"
|
||||
_module="${_module%%.*}"
|
||||
|
||||
# Skip unneeded modules and skip modules which
|
||||
# depends on them as well
|
||||
case $(modprobe -S "$kernel" -D "$_module") in
|
||||
*wmi* | *gpu* | *net*) continue ;;
|
||||
esac 2> /dev/null
|
||||
|
||||
copy_module "$_module"
|
||||
copy_file "$_module" "/lib/modules/${_module#$moddir}" 644 0
|
||||
done
|
||||
fi
|
||||
|
||||
copy_binary modprobe
|
||||
|
||||
copy_file "${moddir}/${kernel}/modules.order" "/lib/modules/${kernel}/modules.order" 644 0
|
||||
copy_file "${moddir}/${kernel}/modules.builtin" "/lib/modules/${kernel}/modules.builtin" 644 0
|
||||
copy_file "${moddir}/${kernel}/modules.order" \
|
||||
"/lib/modules/${kernel}/modules.order" 644 0
|
||||
|
||||
copy_file "${moddir}/${kernel}/modules.builtin" \
|
||||
"/lib/modules/${kernel}/modules.builtin" 644 0
|
||||
|
||||
depmod -b "$tmpdir" "$kernel"
|
||||
}
|
||||
@ -327,8 +327,6 @@ make_initramfs()
|
||||
print "done! check out $output"
|
||||
)
|
||||
|
||||
[ "$(id -u)" = 0 ] || panic "must be run as root"
|
||||
|
||||
# Exit if command fails and disable globbing.
|
||||
set -ef
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user