From bfdef0f304e13766423aaabd1022c888e3193ff6 Mon Sep 17 00:00:00 2001 From: davidovski Date: Sun, 13 Mar 2022 18:39:11 +0000 Subject: fixed mkinitrd --- Makefile | 6 ++- mkinitrd/init.in | 110 +++++++++++++++++++++++++++++++++++++++++++++ mkinitrd/initramfs-init.sh | 110 --------------------------------------------- mkinitrd/mkinitramfs.sh | 17 ++++--- 4 files changed, 122 insertions(+), 121 deletions(-) create mode 100644 mkinitrd/init.in delete mode 100644 mkinitrd/initramfs-init.sh diff --git a/Makefile b/Makefile index ff9704b..f7b9363 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,9 @@ utmps: mkdir -p $(DESTDIR)/var/log/utmps mv $(DESTDIR)/var/log/wtmp /var/log/utmps/ -install-mkinitramfs: mkinitrd/mkinitramfs.sh mkinitrd/initramfs-init.sh +install-mkinitramfs: mkinitrd/mkinitramfs.sh mkinitrd/init.in + install -d $(DESTDIR)$(PREFIX)/bin + install -d $(DESTDIR)$(PREFIX)/share/mkinitramfs install -m755 mkinitrd/mkinitramfs.sh ${DESTDIR}${PREFIX}/bin/mkinitramfs - install -m755 mkinitrd/initramfs-init.sh ${DESTDIR}${PREFIX}/bin/initramfs-init + install -m644 mkinitrd/init.in ${DESTDIR}${PREFIX}/share/mkinitramfs/ diff --git a/mkinitrd/init.in b/mkinitrd/init.in new file mode 100644 index 0000000..9353e0f --- /dev/null +++ b/mkinitrd/init.in @@ -0,0 +1,110 @@ +#!/bin/sh + +PATH=/bin:/usr/bin:/sbin:/usr/sbin +export PATH + +echo "Loading system..." + +problem() +{ + printf "Encountered a problem!\n\nDropping you to a shell.\n\n" + sh +} + +no_device() +{ + printf "The device %s, which is supposed to contain the\n" $1 + printf "root file system, does not exist.\n" + printf "Please fix this problem and exit this shell.\n\n" +} + +no_mount() +{ + printf "Could not mount device %s\n" $1 + printf "Sleeping forever. Please reboot and fix the kernel command line.\n\n" + printf "Maybe the device is formatted with an unsupported file system?\n\n" + printf "Or maybe filesystem type autodetection went wrong, in which case\n" + printf "you should add the rootfstype=... parameter to the kernel command line.\n\n" + printf "Available partitions:\n" +} + +do_mount_root() +{ + mkdir /.root + [ -n "$rootflags" ] && rootflags="$rootflags," + rootflags="$rootflags$ro" + + case "$root" in + /dev/* ) device=$root ;; + UUID=* ) eval $root; device="/dev/disk/by-uuid/$UUID" ;; + LABEL=*) eval $root; device="/dev/disk/by-label/$LABEL" ;; + "" ) echo "No root device specified." ; problem ;; + esac + + while [ ! -b "$device" ] ; do + no_device $device + problem + done + + if ! mount -n -t "$rootfstype" -o "$rootflags" "$device" /.root ; then + no_mount $device + cat /proc/partitions + while true ; do sleep 10000 ; done + else + echo "Successfully mounted device $root" + fi +} + +init=/sbin/init +root= +rootdelay= +rootfstype=auto +ro="ro" +rootflags= +device= + +mount -n -t devtmpfs devtmpfs /dev +mount -n -t proc proc /proc +mount -n -t sysfs sysfs /sys +mount -n -t tmpfs tmpfs /run + +read -r cmdline < /proc/cmdline + +for param in $cmdline ; do + case $param in + init=* ) init=${param#init=} ;; + root=* ) root=${param#root=} ;; + rootdelay=* ) rootdelay=${param#rootdelay=} ;; + rootfstype=*) rootfstype=${param#rootfstype=} ;; + rootflags=* ) rootflags=${param#rootflags=} ;; + ro ) ro="ro" ;; + rw ) ro="rw" ;; + esac +done + +# udevd location depends on version +if [ -x /sbin/udevd ]; then + UDEVD=/sbin/udevd +elif [ -x /lib/udev/udevd ]; then + UDEVD=/lib/udev/udevd +elif [ -x /lib/systemd/systemd-udevd ]; then + UDEVD=/lib/systemd/systemd-udevd +else + echo "Cannot find udevd nor systemd-udevd" + problem +fi + +${UDEVD} --daemon --resolve-names=never +udevadm trigger +udevadm settle + +if [ -f /etc/mdadm.conf ] ; then mdadm -As ; fi +if [ -x /sbin/vgchange ] ; then /sbin/vgchange -a y > /dev/null ; fi +if [ -n "$rootdelay" ] ; then sleep "$rootdelay" ; fi + +do_mount_root + +killall -w ${UDEVD##*/} + +exec switch_root /.root "$init" "$@" + diff --git a/mkinitrd/initramfs-init.sh b/mkinitrd/initramfs-init.sh deleted file mode 100644 index 9353e0f..0000000 --- a/mkinitrd/initramfs-init.sh +++ /dev/null @@ -1,110 +0,0 @@ -#!/bin/sh - -PATH=/bin:/usr/bin:/sbin:/usr/sbin -export PATH - -echo "Loading system..." - -problem() -{ - printf "Encountered a problem!\n\nDropping you to a shell.\n\n" - sh -} - -no_device() -{ - printf "The device %s, which is supposed to contain the\n" $1 - printf "root file system, does not exist.\n" - printf "Please fix this problem and exit this shell.\n\n" -} - -no_mount() -{ - printf "Could not mount device %s\n" $1 - printf "Sleeping forever. Please reboot and fix the kernel command line.\n\n" - printf "Maybe the device is formatted with an unsupported file system?\n\n" - printf "Or maybe filesystem type autodetection went wrong, in which case\n" - printf "you should add the rootfstype=... parameter to the kernel command line.\n\n" - printf "Available partitions:\n" -} - -do_mount_root() -{ - mkdir /.root - [ -n "$rootflags" ] && rootflags="$rootflags," - rootflags="$rootflags$ro" - - case "$root" in - /dev/* ) device=$root ;; - UUID=* ) eval $root; device="/dev/disk/by-uuid/$UUID" ;; - LABEL=*) eval $root; device="/dev/disk/by-label/$LABEL" ;; - "" ) echo "No root device specified." ; problem ;; - esac - - while [ ! -b "$device" ] ; do - no_device $device - problem - done - - if ! mount -n -t "$rootfstype" -o "$rootflags" "$device" /.root ; then - no_mount $device - cat /proc/partitions - while true ; do sleep 10000 ; done - else - echo "Successfully mounted device $root" - fi -} - -init=/sbin/init -root= -rootdelay= -rootfstype=auto -ro="ro" -rootflags= -device= - -mount -n -t devtmpfs devtmpfs /dev -mount -n -t proc proc /proc -mount -n -t sysfs sysfs /sys -mount -n -t tmpfs tmpfs /run - -read -r cmdline < /proc/cmdline - -for param in $cmdline ; do - case $param in - init=* ) init=${param#init=} ;; - root=* ) root=${param#root=} ;; - rootdelay=* ) rootdelay=${param#rootdelay=} ;; - rootfstype=*) rootfstype=${param#rootfstype=} ;; - rootflags=* ) rootflags=${param#rootflags=} ;; - ro ) ro="ro" ;; - rw ) ro="rw" ;; - esac -done - -# udevd location depends on version -if [ -x /sbin/udevd ]; then - UDEVD=/sbin/udevd -elif [ -x /lib/udev/udevd ]; then - UDEVD=/lib/udev/udevd -elif [ -x /lib/systemd/systemd-udevd ]; then - UDEVD=/lib/systemd/systemd-udevd -else - echo "Cannot find udevd nor systemd-udevd" - problem -fi - -${UDEVD} --daemon --resolve-names=never -udevadm trigger -udevadm settle - -if [ -f /etc/mdadm.conf ] ; then mdadm -As ; fi -if [ -x /sbin/vgchange ] ; then /sbin/vgchange -a y > /dev/null ; fi -if [ -n "$rootdelay" ] ; then sleep "$rootdelay" ; fi - -do_mount_root - -killall -w ${UDEVD##*/} - -exec switch_root /.root "$init" "$@" - diff --git a/mkinitrd/mkinitramfs.sh b/mkinitrd/mkinitramfs.sh index 42fad85..9acff17 100755 --- a/mkinitrd/mkinitramfs.sh +++ b/mkinitrd/mkinitramfs.sh @@ -1,9 +1,8 @@ -#!/bin/sh +#!/bin/bash # This file based in part on the mkinitramfs script for the LFS LiveCD # written by Alexander E. Patrakov and Jeremy Huntwork. -copy() -{ +copy() { local file if [ "$2" == "lib" ]; then @@ -12,7 +11,7 @@ copy() file=$(type -p $1) fi - if [ -n $file ] ; then + if [ "${#file}" != "0" ]; then cp $file $WDIR/$2 else echo "Missing required file: $1 for directory $2" @@ -35,7 +34,7 @@ fi printf "Creating $INITRAMFS_FILE... " -binfiles="sh cat cp dd killall ls mkdir mknod mount " +binfiles="bash cat cp dd killall ls mkdir mknod mount " binfiles="$binfiles umount sed sleep ln rm uname" binfiles="$binfiles readlink basename" @@ -78,7 +77,7 @@ for file in $(find /etc/udev/rules.d/ -type f) ; do done # Install any firmware present -cp -a /lib/firmware $WDIR/lib +[ -e /lib/firmware ] && cp -a /lib/firmware $WDIR/lib # Copy the RAID configuration file if present if [ -f /etc/mdadm.conf ] ; then @@ -104,6 +103,8 @@ for f in $binfiles ; do copy $d/$f bin done +ln -s bash $WDIR/bin/sh + # Add lvm if present if [ -x /sbin/lvm ] ; then sbinfiles="$sbinfiles lvm dmsetup"; fi @@ -156,7 +157,6 @@ sort $unsorted | uniq | while read library ; do [ "$library" == "linux-gate.so.1" ]; then continue fi - copy $library lib done @@ -167,8 +167,7 @@ if [ -d /lib/systemd ]; then cp -a /lib/systemd $WDIR/lib fi -# Install 100 4957 100 4957 0 0 36023 0 --:--:-- --:--:-- --:--:-- 36182 -the kernel modules if requested +# Install the kernel modules if requested if [ -n "$KERNEL_VERSION" ]; then find \ /lib/modules/$KERNEL_VERSION/kernel/{crypto,fs,lib} \ -- cgit v1.2.1