diff --git a/docs/tinyramfs.8.scd b/docs/tinyramfs.8.scd index 47b1c2c..f2f05f1 100644 --- a/docs/tinyramfs.8.scd +++ b/docs/tinyramfs.8.scd @@ -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* - - Specify directory where modules stored. Default is */lib/modules*. - -*-s*, *--sources* - - Specify directory where tinyramfs stored files such as *device-helper* - and *init*. Default is */usr/share/tinyramfs*. - -*-o*, *--output* +*-o*, *--output* Specify output location where initramfs image will be stored. -*-c*, *--config* +*-c*, *--config* 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* + + Specify directory where modules stored. Default is */lib/modules*. + This option has no effect if *monolith* or *hostonly* were enabled in config. + *-H*, *--hooks* Specify additional hooks location. Default is */usr/share/tinyramfs/hooks* and */etc/tinyramfs/hooks*. +*-D*, *--helper* + + Specify location to device helper. Default is */usr/share/tinyramfs/device-helper*. + +*-I*, *--init* + + Specify location to init script. Default is */usr/share/tinyramfs/init*. + *-d*, *--debug* Enable debug mode. Useful for reporting bugs in build stage. diff --git a/docs/tinyramfs.hooks.7.scd b/docs/tinyramfs.hooks.7.scd index b68c9b4..1640fc9 100644 --- a/docs/tinyramfs.hooks.7.scd +++ b/docs/tinyramfs.hooks.7.scd @@ -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) ``` diff --git a/tinyramfs b/tinyramfs index b23b7a7..92a4041 100755 --- a/tinyramfs +++ b/tinyramfs @@ -22,14 +22,15 @@ usage() { cat << EOF usage: ${0##*/} [option]... - -o, --output set initramfs output path - -c, --config set config file path - -m, --modules set modules directory - -s, --sources set sources directory - -k, --kernel set kernel version - -H, --hooks set hooks directory - -d, --debug enable debug mode - -f, --force overwrite initramfs image + -o, --output set path to initramfs image + -c, --config set path to config + -k, --kernel set kernel version + -m, --modules set path to modules + -H, --hooks set directory to hooks + -D, --helper set path to device helper + -I, --init 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