X-Git-Url: https://git.pld-linux.org/?a=blobdiff_plain;f=geninitrd;h=ea7d438e56abd1086cc8fec876b239626602f9fe;hb=152a5bf18b37b825a9b6677153aa5af54df94d7b;hp=92a519d330a7692c42887516a2ca2485dc5f8097;hpb=fee61d3f4dd96bfdca441a8ab524d9928309559e;p=projects%2Fgeninitrd.git diff --git a/geninitrd b/geninitrd index 92a519d..ea7d438 100755 --- a/geninitrd +++ b/geninitrd @@ -17,6 +17,7 @@ PROGRAM=${0##*/} # list of geninitrd modules which need setup routine after commandline args parsing GENINITRD_MODS="" COMPRESS=yes +LILO_MICROCODE=yes STRIP=/usr/bin/strip target="" kernel="" @@ -46,7 +47,7 @@ proc_partitions=no usage() { echo "Usage: $PROGRAM [--version] [-v] [-f] [--ifneeded] [--preload ]" echo " [--with=] [--image-version] [--fstab=] [--nocompress]" - echo " [--compress=yes|xz|lzma|bzip2|gzip|lzo]" + echo " [--compress=yes|zstd|xz|lzma|bzip2|gzip|lzo]" echo " [--nostrip ] [--strip PATH/strip] [--strip=PATH/strip]" echo " [--initrdfs=rom|initramfs|ext2|cram] [--modules-conf=]" echo " [--with-bootsplash] [--without-bootsplash]" @@ -273,7 +274,7 @@ mount_run() { fi run_mounted=yes - echo "mount -t tmpfs run /run" | add_linuxrc + echo "mount -t tmpfs run /run -o mode=0755,noexec,nosuid,nodev" | add_linuxrc } # unmount all mountpoints mounted by geninitrd @@ -287,8 +288,7 @@ umount_all() { if is_yes "$run_mounted"; then add_linuxrc <<-EOF - mount --bind /run /newroot/run - umount /run + mount -n --move /run /newroot/run EOF run_mounted=no fi @@ -432,6 +432,10 @@ find_depmod() { smodule=$(basename_module $modpath) case "$smodule" in btrfs) + warn "mounting multidevice btrfs volume requires rootfsflags=device=/dev/...,device=/dev/... kernel option" + find_depmod "-libcrc32c" + ;; + ext4) find_depmod "-libcrc32c" ;; crc-t10dif) @@ -534,15 +538,20 @@ inst_exec() { inst "$@" $dest - local obj lib libs libdir + local obj lib libs libs_additional libdir for obj in "$@"; do case "$obj" in /lib/ld-linux.so.2 | /lib64/ld-linux-x86-64.so.2 | /libx32/ld-linux-x32.so.2) continue + ;; + /lib/libpthread.so* | /lib64/libpthread.so* | /libx32/libpthread.so*) + libs_additional="${obj%/libpthread*}/libgcc_s.so.1" + ;; esac - libs=$(ldd "$obj" | awk '/statically|linux-(gate|vdso)\.so/{next} NF == 2 {print $1} /=/{print $3}' | sort -u) - for lib in $libs; do + + libs=$(ldd "$obj" 2> /dev/null | awk '/statically|linux-(gate|vdso)\.so/{next} NF == 2 {print $1} /=/{print $3}' | sort -u) + for lib in $libs $libs_additional; do libdir=$(cd $(dirname "$lib"); pwd) if [ ! -f "$DESTDIR/$lib" ]; then inst_d $libdir @@ -556,7 +565,7 @@ inst_exec() { for _lib in $(get_libdir LIBDIR); do if [ -f $DESTDIR/$_lib/libc.so.0 ]; then lib=$DESTDIR/$_lib/libc.so.0 - lib=$(ldd "$lib" | awk '/statically|linux-(gate|vdso)\.so/{next} NF == 2 {print $1} /=/{print $3}' | sort -u) + lib=$(ldd "$lib" 2> /dev/null | awk '/statically|linux-(gate|vdso)\.so/{next} NF == 2 {print $1} /=/{print $3}' | sort -u) libdir=$(cd $(dirname "$lib"); pwd) if [ ! -e $DESTDIR$libdir ]; then libdir=$(dirname "$libdir") @@ -663,6 +672,11 @@ find_modules_for_devpath() { return fi + if [[ "$devpath" == /dev/nvme* ]]; then + find_module "nvme" + return + fi + if [[ "$devpath" == /dev/bcache* ]]; then find_modules_bcache "$devpath" return @@ -937,62 +951,43 @@ initrd_gen_initramfs_switchroot() { add_linuxrc <<-'EOF' device= eval "$(busybox awk -v root="$ROOT" ' - # http://9fans.net/archive/2006/09/261 - function h2d(str, hstr, res, num, n, digit, i) { - hstr = "0123456789abdcef"; - res = 0; + function h2d(str, hstr, res, num, n, digit, i) { # http://9fans.net/archive/2006/09/261 + hstr = "0123456789abdcef"; res = 0; n = split(tolower(str), digit, ""); for (i = 1; i <= n; i++) { num = index(hstr, digit[i]) - 1; res = res + (num * 16 ^ (n - i)); } - return res; } BEGIN { - num_pattern_short = "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"; num_pattern = "[0-9a-fA-F]" num_pattern_short; dev_pattern = "[hms][a-z][a-z]([0-9])+"; - partition = ""; - min = -1; maj = -1; - - # see if we have /dev/hdX or hdX, we can just take partition name - if (root ~ "^\/dev\/" dev_pattern "$" || root ~ "^" dev_pattern "$") { - partition = root - sub("^/dev/", "", partition); - - } else { - # unify values first - if (root ~ "^" num_pattern_short "$") { - # change "303" => "0x0303" + partition = ""; min = -1; maj = -1; + + if (root ~ "^\/dev\/" dev_pattern "$" || root ~ "^" dev_pattern "$") { # see if we have /dev/hdX or hdX, we can just take partition name + partition = root; sub("^/dev/", "", partition); + } else { # unify values first + if (root ~ "^" num_pattern_short "$") { # change "303" => "0x0303" root = "0x0" root - } else if (root ~ "^" num_pattern "$") { - # change "0303" => "0x0303" + } else if (root ~ "^" num_pattern "$") { # change "0303" => "0x0303" root = "0x" root } - maj = h2d(substr(root, 3, 2)); min = h2d(substr(root, 5, 2)); } } - partition && $4 == partition { maj = $1; min = $2; } $1 == maj && $2 == min { partition = $4; } - END { - if (maj >= 0 && min >= 0) { - printf("maj=%s; min=%s;\n", maj, min); - } - if (partition) { - printf("device=/dev/%s;\n", partition); - } - } - ' /proc/partitions)" + if (maj >= 0 && min >= 0) { printf("maj=%s; min=%s;\n", maj, min); } + if (partition) { printf("device=/dev/%s;\n", partition); } + }' /proc/partitions)" if [ -z "$device" ]; then - if [ "$DEBUGINITRD" ]; then + if [ "$DEBUGINITRD" -a "$DEBUGINITRD" != 'sh' ]; then cat /proc/partitions fi device=$ROOT @@ -1004,7 +999,11 @@ initrd_gen_initramfs_switchroot() { # XXX hack, fallback to rootdev from geninitrd time if [ ! -e "$device" ]; then + EOF + add_linuxrc <<-EOF device="$rootdev" + EOF + add_linuxrc <<-'EOF' echo "DEVICE set to $device based on fstab entry from initrd gen time" fi @@ -1037,7 +1036,7 @@ initrd_gen_initramfs_switchroot() { busybox_applet dmesg busybox_applet tail add_linuxrc <<-'EOF' - if [ "$DEBUGINITRD" ]; then + if [ "$DEBUGINITRD" -a "$DEBUGINITRD" != 'sh' ]; then echo "Last 20 lines of dmesg:" dmesg | tail -n 20 fi @@ -1097,13 +1096,13 @@ sym_exists() { return 1 fi - awk -vc=1 -vsymbol="$symbol" '($2 == "T" || $2 == "t") && $3 == symbol {c = 0} END {exit c}' $mapfile + awk -vc=1 -vsymbol="$symbol" '(tolower($2) == "t" || tolower($2) == "d") && $3 == symbol {c = 0} END {exit c}' $mapfile } # find best compressor (or forced one) for initrd find_compressor() { local mode="$1" - local compressors='xz lzma bzip2 gzip lzo' + local compressors='zstd xz lzma bzip2 gzip lzo' # a specified one, take it if ! is_yes "$mode"; then @@ -1135,6 +1134,10 @@ find_compressor() { sym=unlzo prog=/usr/bin/lzop ;; + zstd) + sym=zstd + prog=/usr/bin/zstd + ;; none|no) # any existing sym will work sym=initrd_load @@ -1177,6 +1180,9 @@ compress_image() { lzo) lzop -9 < "$IMAGE" > "$tmp" || return $? ;; + zstd) + zstd -9 < "$IMAGE" > "$tmp" || return $? + ;; none|no) cat < "$IMAGE" > "$tmp" || return $? ;; @@ -1185,6 +1191,16 @@ compress_image() { mv -f "$tmp" "$target" } +# prepend file to image +prepend_file_to_image() { + local file="$1" target="$2" tmp + tmp=$(mktemp "$target".XXXXXX) || die "mktemp failed" + + cat "$file" "$target" > "$tmp" || return $? + + mv -f "$tmp" "$target" +} + if [ -r /etc/sysconfig/geninitrd ]; then . /etc/sysconfig/geninitrd fi @@ -1193,7 +1209,7 @@ if [ ! -f /proc/mounts ]; then warn "/proc filesystem not mounted, may cause wrong results or failure." fi -geninitrd_load_mods ide luks multipath dmraid lvm md blkid udev tuxonice suspend fbsplash condecor bootsplash uvesafb nfs sata scsi usbkbd bcache +geninitrd_load_mods ide luks multipath dmraid lvm md blkid udev swsusp tuxonice suspend fbsplash condecor bootsplash uvesafb nfs sata scsi usbkbd bcache while [ $# -gt 0 ]; do case $1 in @@ -1229,6 +1245,9 @@ while [ $# -gt 0 ]; do --without-fbcondecor) FB_CON_DECOR=no ;; + --without-swsusp) + USE_SWSUSP=no + ;; --with-suspend) USE_SUSPEND=yes ;; @@ -1492,6 +1511,10 @@ if is_yes "$USE_SUSPEND"; then find_modules_suspend fi +if is_yes "$USE_SWSUSP"; then + find_modules_swsusp +fi + find_root "$fstab" || exit verbose "Using $rootdev as device for rootfs" @@ -1529,7 +1552,7 @@ chmod a+rx "$RCFILE" ln -s linuxrc $DESTDIR/init # create dirs that we really need -inst_d /{lib,bin,etc,dev{,/pts,/shm},loopfs,var,proc,run,sys} +inst_d /{lib,bin,sbin,etc,dev{,/pts,/shm},loopfs,var,proc,run,sys,tmp} modules_install "$MODULES" @@ -1558,7 +1581,11 @@ mount_proc kmsg "geninitrd/$VERSION starting" +inst_d /lib/geninitrd/ +inst /lib/geninitrd/functions.initrd /lib/geninitrd/functions.initrd + add_linuxrc <<-EOF + . /lib/geninitrd/functions.initrd # builtin defaults from geninitrd ROOT=$rootdev ROOTFS=$rootFs @@ -1576,6 +1603,9 @@ add_linuxrc <<-'EOF' if [ "${arg##root=}" != "${arg}" ]; then ROOT=${arg##root=} fi + if [ "${arg##rootfs=}" != "${arg}" ]; then + ROOTFS=${arg##rootfs=} + fi if [ "${arg##rootflags=}" != "${arg}" ]; then ROOTFLAGS=${arg##rootflags=} fi @@ -1627,6 +1657,10 @@ add_linuxrc <<-'EOF' fi EOF +# mount early +mount_tmp +mount_run + modules_add_linuxrc $MODULES # TODO: rewrite for busybox @@ -1676,6 +1710,7 @@ initrd_gen_stop_uvesafb # resume after killing local processes initrd_gen_tuxonice initrd_gen_suspend +initrd_gen_swsusp # clean up env add_linuxrc <<-'EOF' @@ -1760,14 +1795,16 @@ case "$INITRDFS" in die "Filesystem $INITRDFS not supported by $PROGRAM" esac -CONFIG_BLK_DEV_RAM_SIZE=$(ikconfig | awk -F= '/^CONFIG_BLK_DEV_RAM_SIZE/{print $2}') -if [ -z "$CONFIG_BLK_DEV_RAM_SIZE" ]; then - CONFIG_BLK_DEV_RAM_SIZE=4096 - warn "No CONFIG_BLK_DEV_RAM_SIZE detected, fallback to $CONFIG_BLK_DEV_RAM_SIZE" -fi +if [ "$INITRDFS" != "initramfs" ]; then + CONFIG_BLK_DEV_RAM_SIZE=$(ikconfig | awk -F= '/^CONFIG_BLK_DEV_RAM_SIZE/{print $2}') + if [ -z "$CONFIG_BLK_DEV_RAM_SIZE" ]; then + CONFIG_BLK_DEV_RAM_SIZE=4096 + warn "No CONFIG_BLK_DEV_RAM_SIZE detected, fallback to $CONFIG_BLK_DEV_RAM_SIZE" + fi -if [ "$IMAGESIZE" -gt $CONFIG_BLK_DEV_RAM_SIZE ]; then - warn "Your image size is larger than $CONFIG_BLK_DEV_RAM_SIZE, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!" + if [ "$IMAGESIZE" -gt $CONFIG_BLK_DEV_RAM_SIZE ]; then + warn "Your image size is larger than $CONFIG_BLK_DEV_RAM_SIZE, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!" + fi fi if ! is_no "$COMPRESS"; then @@ -1788,6 +1825,14 @@ else cp -a "$IMAGE" "$target" fi +# microcode support for lilo +if ! is_no "$LILO_MICROCODE"; then + if [ -x /sbin/lilo -a -f "/boot/intel-ucode.img" ]; then + verbose "Prepending $target with microcode image /boot/intel-ucode.img for LILO" + prepend_file_to_image "/boot/intel-ucode.img" "$target" + fi +fi + # XXX. check if bootsplash can output data to tmp dir not directly to initramfs image. initrd_gen_bootsplash "$target"