From 416670ca72ad56bf62e646f5b66b071a5d3a415d Mon Sep 17 00:00:00 2001 From: Ivan Davidov Date: Sat, 23 Apr 2016 01:43:40 +0300 Subject: [PATCH] Added support for PID 1 shell during boot. Added option to use local downloaded sources with no requirement on internet connection. Added option to use predefined configuration files for kernel and BusyBox. Initramfs structure has been reorganized - now /etc/03_init.sh can be edited and the persisted changes will be applied on reboot. Scripts 01 and 02 are not affected since they are used before the overlay takes place. Added helper script file which generates hard disk image as sparse file. QEMU scripts have been enhanced for easier boot with hard disk images. Internal comments have been improved. --- .../etc/{prepare.sh => 01_prepare.sh} | 2 + .../etc/{switch.sh => 02_overlay.sh} | 6 +-- src/08_generate_rootfs/etc/03_init.sh | 46 +++++++++++++++++++ src/config_predefined/README.txt | 5 ++ 4 files changed, 56 insertions(+), 3 deletions(-) rename src/08_generate_rootfs/etc/{prepare.sh => 01_prepare.sh} (65%) rename src/08_generate_rootfs/etc/{switch.sh => 02_overlay.sh} (96%) create mode 100755 src/08_generate_rootfs/etc/03_init.sh create mode 100644 src/config_predefined/README.txt diff --git a/src/08_generate_rootfs/etc/prepare.sh b/src/08_generate_rootfs/etc/01_prepare.sh similarity index 65% rename from src/08_generate_rootfs/etc/prepare.sh rename to src/08_generate_rootfs/etc/01_prepare.sh index ce05206b5..e1b9aa552 100755 --- a/src/08_generate_rootfs/etc/prepare.sh +++ b/src/08_generate_rootfs/etc/01_prepare.sh @@ -1,7 +1,9 @@ #!/bin/sh +echo "Suppress most kernel messages." dmesg -n 1 +echo "Mount all core filesystems." mount -t devtmpfs none /dev mount -t proc none /proc mount -t tmpfs none /tmp -o mode=1777 diff --git a/src/08_generate_rootfs/etc/switch.sh b/src/08_generate_rootfs/etc/02_overlay.sh similarity index 96% rename from src/08_generate_rootfs/etc/switch.sh rename to src/08_generate_rootfs/etc/02_overlay.sh index d8fea5efb..2deaee910 100755 --- a/src/08_generate_rootfs/etc/switch.sh +++ b/src/08_generate_rootfs/etc/02_overlay.sh @@ -106,7 +106,7 @@ for DEVICE in /dev/* ; do mkdir -p $UPPER_DIR mkdir -p $WORK_DIR - mount -t overlay -o lowerdir=/mnt:$OVERLAY_DIR,upperdir=$UPPER_DIR,workdir=$WORK_DIR none /mnt 2>/dev/null + mount -t overlay -o lowerdir=$OVERLAY_DIR:/mnt,upperdir=$UPPER_DIR,workdir=$WORK_DIR none /mnt 2>/dev/null OUT=$? if [ ! "$OUT" = "0" ] ; then @@ -142,9 +142,9 @@ mount --move /tmp /mnt/tmp # The new mountpoint becomes file system root. All original root folders are # deleted automatically as part of the command execution. The '/sbin/init' # process is invoked and it becomes the new PID 1 parent process. -exec switch_root /mnt /sbin/init +exec switch_root /mnt /etc/03_init.sh -echo "You can never see this... unless there is a serious bug..." +echo "(/etc/02_overlay.sh) - there is a serious bug..." # Wait until any key has been pressed. read -n1 -s diff --git a/src/08_generate_rootfs/etc/03_init.sh b/src/08_generate_rootfs/etc/03_init.sh new file mode 100755 index 000000000..f1d53f3c4 --- /dev/null +++ b/src/08_generate_rootfs/etc/03_init.sh @@ -0,0 +1,46 @@ +#!/bin/sh + +# If you have persistent overlay support then you can edit this file and replace +# the default initialization of the system. For example, you could use this: +# +# exec setsid cttyhach sh +# +# This gives you PID 1 shell inside the initramfs area. Since this is a PID 1 +# shell, you can still invoke the original initialization logic by executing +# this command: +# +# exec /sbin/init + +cat << CEOF + + Wait 5 seconds for the default system initialization process based on the + files /sbin/init and /etc/inittab or press any key for PID 1 shell. + +CEOF + +read -t 5 -n1 -s key + +if [ "$key" = "" ] ; then + # Use default initialization logic based on configuration in '/etc/inittab'. + echo "Executing /sbin/init as PID 1." + exec /sbin/init +else + +# Using no indentation for this snippet or otherwise it causes kernel panic. +cat << CEOF + + This is PID 1 shell. Execute the following in order to continue with the + default system initialization process: + + exec /sbin/init + +CEOF + + exec setsid cttyhack sh +fi + +echo "(/etc/03_init.sh) - there is a serious bug..." + +# Wait until any key has been pressed. +read -n1 -s + diff --git a/src/config_predefined/README.txt b/src/config_predefined/README.txt new file mode 100644 index 000000000..f458cbda5 --- /dev/null +++ b/src/config_predefined/README.txt @@ -0,0 +1,5 @@ +TODO 1- add documentation about this folder and the purpose of the predefined +configuration file. + +TODO 2 - Edit all comments and readme files to use maximum 80 chars per line. +