commit abbf37adaaad1b972cb0843374c7ba1779e688af
parent 8bb3ac145700a80e458f9ee6dc993b78b2a3631b
Author: emmett1 <emmett1.2miligrams@gmail.com>
Date: Fri, 12 Jun 2020 18:02:38 +0800
updated
Diffstat:
2 files changed, 25 insertions(+), 9 deletions(-)
diff --git a/init b/init
@@ -64,7 +64,7 @@ do_boot_live() {
SYSTEM=/run/initramfs/system
WRITEDIR=/run/initramfs/overlayfs/write
WORKDIR=/run/initramfs/overlayfs/work
- sfsimg=/run/initramfs/medium/rootfs/filesystem.sfs
+ sfsimg=$MEDIUM/boot/filesystem.sfs
delay=${delay:-5}
mkdir -p $MEDIUM $SYSTEM $WRITEDIR $WORKDIR
@@ -86,6 +86,16 @@ do_boot_live() {
# Tell system to skip fsck during startup
> $newroot/fastboot
+
+ if [ -d "$MEDIUM"/rootfs ]; then
+ cp -Ra "$MEDIUM"/rootfs/* $newroot
+ fi
+
+ # Execute custom script before switch root
+ if [ -f $newroot/root/custom_script.sh ]; then
+ chmod +x $newroot/root/custom_script.sh
+ chroot $newroot sh /root/custom_script.sh
+ fi
}
do_try_resume() {
@@ -129,7 +139,7 @@ for param in $cmdline ; do
noresume ) noresume=true ;;
ro ) ro="ro" ;;
rw ) ro="rw" ;;
- initrd ) initrd=true ;;
+ shell ) shell=true ;;
live ) live=true ;;
esac
done
@@ -156,7 +166,8 @@ 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
-if [ "$initrd" = true ]; then
+if [ "$shell" = true ]; then
+ echo "shell requested, drop to shell"
shell
fi
diff --git a/mkinitrd b/mkinitrd
@@ -143,8 +143,11 @@ if [ ! -d "/lib/modules/$1" ] ; then
exit 1
fi
-if [ ! $(type -p cpio) ]; then
- echo "'cpio' not found"
+CPIO=$(type -p cpio)
+CPIO=$(type -p bsdcpio)
+
+if [ ! "$CPIO" ]; then
+ echo "Either 'cpio' nor 'bsdcpio' not found"
exit 1
fi
@@ -166,12 +169,14 @@ add_file $DATADIR/$INITIN init 755
# add required binaries
for b in bash sh cat cp killall ls mkdir mount umount sed awk sleep ln rm setsid \
- uname readlink basename modprobe blkid switch_root depmod kmod lsmod insmod; do
+ uname readlink basename modprobe blkid switch_root depmod kmod lsmod insmod chroot chmod; do
add_binary $b
done
-# add dirs
-add_dir /etc/modprobe.d/
+# add modprobe.d dir
+if [ -d /etc/modprobe.d/ ]; then
+ add_dir /etc/modprobe.d/
+fi
# add required terminfo
add_file /usr/share/terminfo/l/linux
@@ -231,7 +236,7 @@ done
finalize_modules
-( cd $INITRDDIR ; find . | cpio -o -H newc --quiet | gzip -9 ) > $INITRD
+( cd $INITRDDIR ; find . | $CPIO -o -H newc --quiet | gzip -9 ) > $INITRD
# Remove the temporary directories
rm -rf $INITRDDIR