]> git.pld-linux.org Git - projects/geninitrd.git/blobdiff - geninitrd
- swsusp support from mis@pld-linux
[projects/geninitrd.git] / geninitrd
index d152eec39850fcced1d8a111c8c8c38cb8a78522..ea7d438e56abd1086cc8fec876b239626602f9fe 100755 (executable)
--- 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 <module>]"
        echo "       [--with=<module>] [--image-version] [--fstab=<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=<modules.conf>]"
        echo "       [--with-bootsplash] [--without-bootsplash]"
@@ -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
@@ -1082,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
@@ -1120,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
@@ -1162,6 +1180,9 @@ compress_image() {
        lzo)
                lzop -9 < "$IMAGE" > "$tmp" || return $?
                ;;
+       zstd)
+               zstd -9 < "$IMAGE" > "$tmp" || return $?
+               ;;
        none|no)
                cat < "$IMAGE" > "$tmp" || return $?
                ;;
@@ -1170,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
@@ -1178,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
@@ -1214,6 +1245,9 @@ while [ $# -gt 0 ]; do
        --without-fbcondecor)
                FB_CON_DECOR=no
                ;;
+       --without-swsusp)
+               USE_SWSUSP=no
+               ;;
        --with-suspend)
                USE_SUSPEND=yes
                ;;
@@ -1477,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"
 
@@ -1514,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"
 
@@ -1543,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
@@ -1615,6 +1657,10 @@ add_linuxrc <<-'EOF'
        fi
 EOF
 
+# mount early
+mount_tmp
+mount_run
+
 modules_add_linuxrc $MODULES
 
 # TODO: rewrite for busybox
@@ -1664,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'
@@ -1748,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
@@ -1776,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"
 
This page took 0.041981 seconds and 4 git commands to generate.