From a3f3a62767b9325d90b3581001544b34495ecf9f Mon Sep 17 00:00:00 2001 From: Alain Kalker Date: Mon, 19 Mar 2012 17:22:23 +0100 Subject: [PATCH 1/9] busybox-initramfs: reorganize init script in preparation for boot type handlers Changes to kernel commandline parameters: Remove legacy parameters, to be added back later if desired. Add a new parameter: break= which will cause a debugging shell to be started after each or the specified boot steps. Functions: mount_part, mount_disk, mount_nbd: reorganize to use mount type handlers, which will support specifying kernel parameters like boot=TYPE=target and disk=TYPE=target. This initial commit only has mount_default, which supports LABEL=label and UUID=uuid, as well as block devices /dev/* and image files. error: show more meaningful error messages, containing the boot step and action which caused the error. If not debugging, halt the system. This prevents the error from causing more damage further on in the boot sequence. If debugging, start a debugging shell. update: make sure the file to update already exists at the destination, to prevent clobbering a rootfs mounted on /flash, which can be the case when mounting a mtd or NBD device. load_modules: enable loading of kernel modules in early boot, e.g. xhci-hcd to enable mount of USB3 devices on boot. Add a simple boot step sequencer, which allows for starting a debugging shell after each step. Signed-off-by: Alain Kalker --- .../sysutils/busybox-initramfs/scripts/init | 218 +++++++++--------- 1 file changed, 111 insertions(+), 107 deletions(-) diff --git a/packages/initramfs/sysutils/busybox-initramfs/scripts/init b/packages/initramfs/sysutils/busybox-initramfs/scripts/init index 003f930b0d..0146d6f525 100755 --- a/packages/initramfs/sysutils/busybox-initramfs/scripts/init +++ b/packages/initramfs/sysutils/busybox-initramfs/scripts/init @@ -21,17 +21,13 @@ # http://www.gnu.org/copyleft/gpl.html ################################################################################ +MODULE_DIR=/lib/modules UPDATE_DIR=/storage/.update IMAGE_SYSTEM="SYSTEM" IMAGE_KERNEL="KERNEL" REBOOT="0" -# defaults for booting from an nbd root -NBD_ROOT_SERVER="192.168.1.1" -NBD_ROOT_PORT="2000" -NFS_OVERLAY="192.168.1.1:/var/lib/overlay" - # mount all needed special filesystems /bin/busybox mount -t devtmpfs none /dev /bin/busybox mount -t proc none /proc @@ -62,22 +58,8 @@ NFS_OVERLAY="192.168.1.1:/var/lib/overlay" fastboot) FASTBOOT=yes ;; - netboot) - NETBOOT=yes - ;; - nbdroot=*) - nbdroot="${arg#nbdroot=}" - NBD_ROOT_SERVER=$( echo "${nbdroot}" | /bin/busybox sed 's/:.*//') - NBD_ROOT_PORT=$( echo "${nbdroot}" | /bin/busybox sed 's/.*://') - ;; - nbdserver=*) - NBD_ROOT_SERVER="${arg#nbdserver=}" - ;; - nbdport=*) - NBD_ROOT_PORT="${arg#nbdport=}" - ;; - nfsoverlay=*) - NFS_OVERLAY="${arg#nfsoverlay=}" + break=*) + BREAK="${arg#*=}" ;; esac done @@ -92,10 +74,6 @@ NFS_OVERLAY="192.168.1.1:/var/lib/overlay" fi } - error() { - echo "Error Code: $1 that means: $2" - } - debug_shell() { echo "### Starting debugging shell... type exit to quit ###" @@ -105,29 +83,66 @@ NFS_OVERLAY="192.168.1.1:/var/lib/overlay" /bin/busybox sh /dev/tty1 2>&1 } + error() { + # Display fatal error message + # $1:action which caused error, $2:message + echo "*** Error in $BOOT_STEP: $1: $2 ***" + if [ -z "$DEBUG" ]; then + /bin/busybox halt + else + debug_shell + fi + } + + break_after() { + # Start debug shell after boot step $1 + case $BREAK in + all|*$1*) + debug_shell + ;; + esac + } + + # Mount handlers + # All handlers take the following parameters: + # $1:target, $2:mountpoint, $3:mount options, [$4:fs type] + + mount_common() { + # Common mount handler, handles block devices and filesystem images + MOUNT_OPTIONS="-o $3" + [ -n "$4" ] && MOUNT_OPTIONS="-t $4 $MOUNT_OPTIONS" + + for i in 1 2 3 4 5 6 7 8 9 10; do + ERR_ENV=1 + + $IONICE /bin/busybox mount $MOUNT_OPTIONS $1 $2 > /dev/null 2>&1 + [ "$?" -eq "0" ] && ERR_ENV=0 && break + + /bin/busybox usleep 1000000 + done + [ "$ERR_ENV" -ne "0" ] && error "mount_common" "Could not mount $1" + } + mount_part() { -# progress "check filesystem $1 ..." -# /sbin/fsck -M -T -a $1 > /dev/null 2>&1 + # Mount a local or network filesystem + # $1:[TYPE=]target, $2:mountpoint, $3:mount options, [$4:fs type] + MOUNT_TARGET="${1#*=}" - for i in 1 2 3 4 5 6 7 8 9 10; do - ERR_ENV=1 - MOUNT_OPTIONS="-o $3 $1 $2" - - if [ -n "$4" ]; then - MOUNT_OPTIONS="-t $4 $MOUNT_OPTIONS" - fi - - progress "mount filesystem $1 ..." - $IONICE /bin/busybox mount $MOUNT_OPTIONS > /dev/null 2>&1 - [ "$?" -eq "0" ] && ERR_ENV=0 && break - - /bin/busybox usleep 1000000 - done - [ "$ERR_ENV" -ne "0" ] && error "INIT_4" "Could not mount $1" && debug_shell + progress "mount filesystem $1 ..." + case $1 in + LABEL=*|UUID=*|/*) + MOUNT_CMD="mount_common" + MOUNT_TARGET="$1" + ;; + *) + error "mount_part" "Unknown filesystem $1" + ;; + esac + $MOUNT_CMD "$MOUNT_TARGET" "$2" "$3" "$4" } update() { - if [ -f "$UPDATE_DIR/$2" ]; then + if [ -f "$UPDATE_DIR/$2" -a -f "$3" ]; then echo "updating $1..." $IONICE /bin/busybox mount -o remount,rw /flash $IONICE /bin/busybox mv $UPDATE_DIR/$2 $3 @@ -154,83 +169,73 @@ NFS_OVERLAY="192.168.1.1:/var/lib/overlay" done } - mount_nbd() { - retry_nr=0 - retry_delay=20 - OVERLAY_DIR=`cat /sys/class/net/eth0/address | /bin/busybox tr -d :` - - while [ ${retry_nr} -lt ${retry_delay} ] && [ ! -e /sysroot/sbin/init ]; do - [ ${retry_nr} -gt 0 ] && \ - $IONICE /bin/busybox nbd-client $NBD_ROOT_SERVER $NBD_ROOT_PORT /dev/nbd0 && \ - mount_part "/dev/nbd0" "/sysroot" "ro" "squashfs" - - retry_nr=$(( ${retry_nr} + 1 )) - - [ ! -e /sysroot/sbin/init ] && /bin/busybox usleep 1000000 - - [ ${retry_nr} -gt 0 ] + load_modules() { + progress "Loading kernel modules" + [ ! -f "/etc/modules" ] && return + for module in $(cat /etc/modules); do + progress "Loading kernel module $module" + /bin/busybox insmod "$MODULE_DIR/$module" || \ + error "load_modules" "Failed to load kernel module $module" done - - if [ ! -e /sysroot/sbin/init ]; then - error "INIT_2" "Could not mount NBD root from $NBD_ROOT_SERVER port $NBD_ROOT_PORT" - debug_shell - fi - - mount_part "$NFS_OVERLAY" "/sysroot/storage" "rw,nolock,retrans=10" "nfs" - - if [ ! -d /sysroot/storage/$OVERLAY_DIR ]; then - mkdir /sysroot/storage/$OVERLAY_DIR - fi - - /bin/busybox umount /sysroot/storage - mount_part "$NFS_OVERLAY/$OVERLAY_DIR" "/sysroot/storage" "rw,nolock" "nfs" } - mount_disk() { - # deal with hfs partitions + check_disks() { + progress "Checking disks" if [ -x /sbin/fsck_hfs ]; then + # deal with hfs partitions hfsdiskprep fi + } + mount_disks() { + progress "Mounting disks" mount_part "$boot" "/flash" "ro,noatime" + mount_part "$disk" "/storage" "rw,noatime" + } - if [ -n "$disk" ]; then - mount_part "$disk" "/storage" "rw,noatime" - - if [ -f "/flash/MACH_KERNEL" ]; then - IMAGE_KERNEL="MACH_KERNEL" - fi - - update "Kernel" "$IMAGE_KERNEL" "/flash/$IMAGE_KERNEL" - update "System" "$IMAGE_SYSTEM" "/flash/$IMAGE_SYSTEM" - - if test "$REBOOT" -eq "1"; then - echo "System reboots now..." && \ - /bin/busybox reboot - fi + check_update() { + progress "Checking for updates" + if [ -f "/flash/MACH_KERNEL" ]; then + IMAGE_KERNEL="MACH_KERNEL" fi - if [ -f "/flash/$IMAGE_SYSTEM" ]; then - mount_part "/flash/$IMAGE_SYSTEM" "/sysroot" "ro,loop" - [ "$ERR_ENV" -ne "0" ] && debug_shell - else - error "INIT_2" "Could not find system." - debug_shell - fi + update "Kernel" "$IMAGE_KERNEL" "/flash/$IMAGE_KERNEL" + update "System" "$IMAGE_SYSTEM" "/flash/$IMAGE_SYSTEM" - # move /flash and /storage to /sysroot - /bin/busybox mount --move /flash /sysroot/flash - - if [ -n "$disk" ]; then - /bin/busybox mount --move /storage /sysroot/storage + if test "$REBOOT" -eq "1"; then + echo "System reboots now..." && \ + /bin/busybox reboot fi } - if [ -z "$NETBOOT" ]; then - mount_disk - else - mount_nbd - fi + prepare_sysroot() { + progress "Preparing system" + + if [ -f "/flash/$IMAGE_SYSTEM" ]; then + # /flash is filesystem with system image file + mount_part "/flash/$IMAGE_SYSTEM" "/sysroot" "ro,loop" + /bin/busybox mount --move /flash /sysroot/flash + else + # /flash is actual root filesystem + /bin/busybox mount --move /flash /sysroot + fi + /bin/busybox mount --move /storage /sysroot/storage + + [ -f "/sysroot/sbin/init" ] || error "final_check" "Could not find system." + } + +# main boot sequence + for BOOT_STEP in \ + load_modules \ + check_disks \ + mount_disks \ + check_update \ + prepare_sysroot; do + $BOOT_STEP + [ -n "$DEBUG" ] && break_after $BOOT_STEP + done + + BOOT_STEP=final # move some special filesystems /bin/busybox mount --move /dev /sysroot/dev @@ -240,5 +245,4 @@ NFS_OVERLAY="192.168.1.1:/var/lib/overlay" # switch to new sysroot and start real init exec /bin/busybox switch_root /sysroot /sbin/init - error "INIT_3" "Error in initramfs. Could not switch to new root" - debug_shell + error "switch_root" "Error in initramfs. Could not switch to new root" From ac1d0eb0d941b5fba0a59794a79b7c7cdc1dc37b Mon Sep 17 00:00:00 2001 From: Alain Kalker Date: Mon, 19 Mar 2012 17:51:26 +0100 Subject: [PATCH 2/9] busybox-initramfs: init: add support for NBD mounts Example kernel command parameter: boot=NBD=192.168.1.1:2000 Signed-off-by: Alain Kalker --- .../sysutils/busybox-initramfs/scripts/init | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/packages/initramfs/sysutils/busybox-initramfs/scripts/init b/packages/initramfs/sysutils/busybox-initramfs/scripts/init index 0146d6f525..9c17d4fe87 100755 --- a/packages/initramfs/sysutils/busybox-initramfs/scripts/init +++ b/packages/initramfs/sysutils/busybox-initramfs/scripts/init @@ -28,6 +28,8 @@ IMAGE_SYSTEM="SYSTEM" IMAGE_KERNEL="KERNEL" REBOOT="0" +NBD_DEVS="0" + # mount all needed special filesystems /bin/busybox mount -t devtmpfs none /dev /bin/busybox mount -t proc none /proc @@ -123,6 +125,20 @@ REBOOT="0" [ "$ERR_ENV" -ne "0" ] && error "mount_common" "Could not mount $1" } + mount_nbd() { + # Mount NBD device + NBD_SERVER="${1%%:*}" + NBD_PORT="${1#*:}" + NBD_DEV="/dev/nbd$NBD_DEVS" + + $IONICE /bin/busybox nbd-client $NBD_SERVER $NBD_PORT $NBD_DEV > /dev/null 2>&1 || \ + error "nbd-client" "Could not connect to NBD server $1" + + mount_common "$NBD_DEV" "$2" "$3" "$4" + + NBD_DEVS=$(( ${NBD_DEVS} + 1 )) + } + mount_part() { # Mount a local or network filesystem # $1:[TYPE=]target, $2:mountpoint, $3:mount options, [$4:fs type] @@ -134,6 +150,9 @@ REBOOT="0" MOUNT_CMD="mount_common" MOUNT_TARGET="$1" ;; + NBD=*) + MOUNT_CMD="mount_nbd" + ;; *) error "mount_part" "Unknown filesystem $1" ;; From cd052262f822d41316eb4f60f6ddeabc9bacdb35 Mon Sep 17 00:00:00 2001 From: Alain Kalker Date: Mon, 19 Mar 2012 17:54:48 +0100 Subject: [PATCH 3/9] busybox-initramfs: init: add support for NFS mounts Example usage: boot=NFS=192.168.1.1:/tftpboot Signed-off-by: Alain Kalker --- .../initramfs/sysutils/busybox-initramfs/scripts/init | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/initramfs/sysutils/busybox-initramfs/scripts/init b/packages/initramfs/sysutils/busybox-initramfs/scripts/init index 9c17d4fe87..8b329c28d6 100755 --- a/packages/initramfs/sysutils/busybox-initramfs/scripts/init +++ b/packages/initramfs/sysutils/busybox-initramfs/scripts/init @@ -139,6 +139,13 @@ NBD_DEVS="0" NBD_DEVS=$(( ${NBD_DEVS} + 1 )) } + mount_nfs() { + # Mount NFS export + NFS_OPTIONS="$3,nolock,retrans=10" + + mount_common "$1" "$2" "$NFS_OPTIONS" "nfs" + } + mount_part() { # Mount a local or network filesystem # $1:[TYPE=]target, $2:mountpoint, $3:mount options, [$4:fs type] @@ -153,6 +160,9 @@ NBD_DEVS="0" NBD=*) MOUNT_CMD="mount_nbd" ;; + NFS=*) + MOUNT_CMD="mount_nfs" + ;; *) error "mount_part" "Unknown filesystem $1" ;; From b68c8324892eeb86da41de6cad460616e60ad966 Mon Sep 17 00:00:00 2001 From: Alain Kalker Date: Mon, 19 Mar 2012 18:55:38 +0100 Subject: [PATCH 4/9] busybox-initramfs: init: add kernel commandline parameter: overlay Adds a new kernel commandline parameter: overlay , which enables multiple clients to use a single configuration file while keeping their storage mounts separate. For the given example, the storage mounts will be under /var/lib/overlay/ This will only work with mount types which support subdirectory mounts. Example usage: disk=NFS=192.168.1.1:/var/lib/overlay overlay Signed-off-by: Alain Kalker --- .../initramfs/sysutils/busybox-initramfs/scripts/init | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/initramfs/sysutils/busybox-initramfs/scripts/init b/packages/initramfs/sysutils/busybox-initramfs/scripts/init index 8b329c28d6..e0a3a4811b 100755 --- a/packages/initramfs/sysutils/busybox-initramfs/scripts/init +++ b/packages/initramfs/sysutils/busybox-initramfs/scripts/init @@ -60,6 +60,9 @@ NBD_DEVS="0" fastboot) FASTBOOT=yes ;; + overlay) + OVERLAY=yes + ;; break=*) BREAK="${arg#*=}" ;; @@ -220,6 +223,14 @@ NBD_DEVS="0" progress "Mounting disks" mount_part "$boot" "/flash" "ro,noatime" mount_part "$disk" "/storage" "rw,noatime" + + [ -z "$OVERLAY" ] && return + OVERLAY_DIR=`cat /sys/class/net/eth0/address | /bin/busybox tr -d :` + if [ ! -d /storage/$OVERLAY_DIR ]; then + mkdir /storage/$OVERLAY_DIR + fi + /bin/busybox umount /storage + mount_part "$disk/$OVERLAY_DIR" "/storage" "rw,noatime" } check_update() { From 4f0052a875a153e6acfcaadd9a3c2b7e5ed5e7c4 Mon Sep 17 00:00:00 2001 From: Alain Kalker Date: Tue, 20 Mar 2012 04:43:52 +0100 Subject: [PATCH 5/9] busybox-initramfs: init: add support for CIFS mounts Example usage: disk=CIFS=//192.168.1.1/share,user=name,password=secret disk=SMB=//192.168.1.1/public,user=guest Note: comma's ',' are not allowed in CIFS options (for example in usernames or passwords) because they are used to separate options. Note: SMB is an alias for CIFS, for people who are more used to that name. Signed-off-by: Alain Kalker --- .../sysutils/busybox-initramfs/scripts/init | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/initramfs/sysutils/busybox-initramfs/scripts/init b/packages/initramfs/sysutils/busybox-initramfs/scripts/init index e0a3a4811b..55c27d2b6f 100755 --- a/packages/initramfs/sysutils/busybox-initramfs/scripts/init +++ b/packages/initramfs/sysutils/busybox-initramfs/scripts/init @@ -128,6 +128,15 @@ NBD_DEVS="0" [ "$ERR_ENV" -ne "0" ] && error "mount_common" "Could not mount $1" } + mount_cifs() { + # Mount CIFS (Samba) share + CIFS_SHARE="${1%%,*}" + CIFS_OPTIONS="${1#*,}" + [ "$CIFS_OPTIONS" = "$1" ] && CIFS_OPTIONS= + + mount_common "$CIFS_SHARE" "$2" "$3,$CIFS_OPTIONS" "cifs" + } + mount_nbd() { # Mount NBD device NBD_SERVER="${1%%:*}" @@ -160,6 +169,9 @@ NBD_DEVS="0" MOUNT_CMD="mount_common" MOUNT_TARGET="$1" ;; + CIFS=*|SMB=*) + MOUNT_CMD="mount_cifs" + ;; NBD=*) MOUNT_CMD="mount_nbd" ;; From 0de52e9de07c7499ddd47e405aed4d8e6074843c Mon Sep 17 00:00:00 2001 From: Alain Kalker Date: Tue, 20 Mar 2012 04:50:01 +0100 Subject: [PATCH 6/9] busybox-initramfs: init: cosmetics Don't add general mount options to NFS_OPTIONS, pass them as combined options instead. Signed-off-by: Alain Kalker --- packages/initramfs/sysutils/busybox-initramfs/scripts/init | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/initramfs/sysutils/busybox-initramfs/scripts/init b/packages/initramfs/sysutils/busybox-initramfs/scripts/init index 55c27d2b6f..db4b09358d 100755 --- a/packages/initramfs/sysutils/busybox-initramfs/scripts/init +++ b/packages/initramfs/sysutils/busybox-initramfs/scripts/init @@ -153,9 +153,9 @@ NBD_DEVS="0" mount_nfs() { # Mount NFS export - NFS_OPTIONS="$3,nolock,retrans=10" + NFS_OPTIONS="nolock,retrans=10" - mount_common "$1" "$2" "$NFS_OPTIONS" "nfs" + mount_common "$1" "$2" "$3,$NFS_OPTIONS" "nfs" } mount_part() { From 03fcc58fae35dfe28a008be9e85916cf68b9ada3 Mon Sep 17 00:00:00 2001 From: Alain Kalker Date: Tue, 20 Mar 2012 17:55:48 +0100 Subject: [PATCH 7/9] busybox-initramfs: init: Don't suppress output when debugging When debugging, any information about the problem is valuable, so don't suppress output. Add a variable: SILENT_OUT whose value is the file descriptor to use for commands that should normally be silent. Idea taken from buildsystem's config/path , and slightly shortened. Signed-off-by: Alain Kalker --- .../sysutils/busybox-initramfs/scripts/init | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/initramfs/sysutils/busybox-initramfs/scripts/init b/packages/initramfs/sysutils/busybox-initramfs/scripts/init index db4b09358d..e9ac8a8295 100755 --- a/packages/initramfs/sysutils/busybox-initramfs/scripts/init +++ b/packages/initramfs/sysutils/busybox-initramfs/scripts/init @@ -73,6 +73,13 @@ NBD_DEVS="0" IONICE="/bin/busybox ionice -c 1 -n 0" fi + if test "$DEBUG" = "yes"; then + exec 3>&1 + else + exec 3>/dev/null + fi + SILENT_OUT=3 + progress() { if test "$PROGRESS" = "yes"; then echo "### $1 ###" @@ -120,7 +127,7 @@ NBD_DEVS="0" for i in 1 2 3 4 5 6 7 8 9 10; do ERR_ENV=1 - $IONICE /bin/busybox mount $MOUNT_OPTIONS $1 $2 > /dev/null 2>&1 + $IONICE /bin/busybox mount $MOUNT_OPTIONS $1 $2 >&$SILENT_OUT 2>&1 [ "$?" -eq "0" ] && ERR_ENV=0 && break /bin/busybox usleep 1000000 @@ -143,7 +150,7 @@ NBD_DEVS="0" NBD_PORT="${1#*:}" NBD_DEV="/dev/nbd$NBD_DEVS" - $IONICE /bin/busybox nbd-client $NBD_SERVER $NBD_PORT $NBD_DEV > /dev/null 2>&1 || \ + $IONICE /bin/busybox nbd-client $NBD_SERVER $NBD_PORT $NBD_DEV >&$SILENT_OUT 2>&1 || \ error "nbd-client" "Could not connect to NBD server $1" mount_common "$NBD_DEV" "$2" "$3" "$4" @@ -208,7 +215,7 @@ NBD_DEVS="0" if [ "$FS_TYPE" = "\"hfs\"" -o "$FS_TYPE" = "\"hfsplus\"" ]; then progress "check filesystem $DEVICE [$FS_TYPE]..." - /bin/fsck_hfs -r -y $DEVICE > /dev/null 2>&1 + /bin/fsck_hfs -r -y $DEVICE >&$SILENT_OUT 2>&1 fi done } From 56b29979f60d7aa06167358ebb32c996862ed2ca Mon Sep 17 00:00:00 2001 From: Alain Kalker Date: Tue, 20 Mar 2012 19:57:09 +0100 Subject: [PATCH 8/9] busybox-initramfs: init: Allow overlay mount for mount types with parameters This fixes overlay mount so it doesn't add $OVERLAY_DIR at the end of the parameter list. Kernel commandline parameter 'overlay' should now work for both NFS and CIFS/SMB mounts, but alas, busybox CIFS mount doesn't (yet) support subdir mounts (regular mount does). Leaving this in for posterity. Signed-off-by: Alain Kalker --- .../sysutils/busybox-initramfs/scripts/init | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/initramfs/sysutils/busybox-initramfs/scripts/init b/packages/initramfs/sysutils/busybox-initramfs/scripts/init index e9ac8a8295..e3baf0d490 100755 --- a/packages/initramfs/sysutils/busybox-initramfs/scripts/init +++ b/packages/initramfs/sysutils/busybox-initramfs/scripts/init @@ -249,7 +249,17 @@ NBD_DEVS="0" mkdir /storage/$OVERLAY_DIR fi /bin/busybox umount /storage - mount_part "$disk/$OVERLAY_DIR" "/storage" "rw,noatime" + + # split $disk into $target,$options so we can append $OVERLAY_DIR + options="${disk#*,}" + target="${disk%%,*}" + if [ "$options" = "$disk" ]; then + disk="$target/$OVERLAY_DIR" + else + disk="$target/$OVERLAY_DIR,$options" + fi + + mount_part "$disk" "/storage" "rw,noatime" } check_update() { From 16a3f228361050026880c9c884148a598ac8f40b Mon Sep 17 00:00:00 2001 From: Alain Kalker Date: Tue, 20 Mar 2012 21:46:58 +0100 Subject: [PATCH 9/9] busybox-initramfs: init: cleanup, improve readability Use consistent whitespace for all `progress "..."` lines. Don't mount $disk if it is not set (e.g. in the installer). Don't check for /storage/$OVERLAY_DIR, just create it. Move the overlay functionality into an if statement. Don't move /storage if $disk is not set (e.g. in the installer). Signed-off-by: Alain Kalker --- .../sysutils/busybox-initramfs/scripts/init | 45 +++++++++++-------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/packages/initramfs/sysutils/busybox-initramfs/scripts/init b/packages/initramfs/sysutils/busybox-initramfs/scripts/init index e3baf0d490..e391c6b9c9 100755 --- a/packages/initramfs/sysutils/busybox-initramfs/scripts/init +++ b/packages/initramfs/sysutils/busybox-initramfs/scripts/init @@ -168,9 +168,9 @@ NBD_DEVS="0" mount_part() { # Mount a local or network filesystem # $1:[TYPE=]target, $2:mountpoint, $3:mount options, [$4:fs type] - MOUNT_TARGET="${1#*=}" - progress "mount filesystem $1 ..." + + MOUNT_TARGET="${1#*=}" case $1 in LABEL=*|UUID=*|/*) MOUNT_CMD="mount_common" @@ -222,6 +222,7 @@ NBD_DEVS="0" load_modules() { progress "Loading kernel modules" + [ ! -f "/etc/modules" ] && return for module in $(cat /etc/modules); do progress "Loading kernel module $module" @@ -232,6 +233,7 @@ NBD_DEVS="0" check_disks() { progress "Checking disks" + if [ -x /sbin/fsck_hfs ]; then # deal with hfs partitions hfsdiskprep @@ -240,30 +242,34 @@ NBD_DEVS="0" mount_disks() { progress "Mounting disks" + mount_part "$boot" "/flash" "ro,noatime" - mount_part "$disk" "/storage" "rw,noatime" - [ -z "$OVERLAY" ] && return - OVERLAY_DIR=`cat /sys/class/net/eth0/address | /bin/busybox tr -d :` - if [ ! -d /storage/$OVERLAY_DIR ]; then - mkdir /storage/$OVERLAY_DIR - fi - /bin/busybox umount /storage + if [ -n "$disk" ]; then + if [ -n "$OVERLAY" ]; then + OVERLAY_DIR=`cat /sys/class/net/eth0/address | /bin/busybox tr -d :` - # split $disk into $target,$options so we can append $OVERLAY_DIR - options="${disk#*,}" - target="${disk%%,*}" - if [ "$options" = "$disk" ]; then - disk="$target/$OVERLAY_DIR" - else - disk="$target/$OVERLAY_DIR,$options" + mount_part "$disk" "/storage" "rw,noatime" + mkdir -p /storage/$OVERLAY_DIR + /bin/busybox umount /storage + + # split $disk into $target,$options so we can append $OVERLAY_DIR + options="${disk#*,}" + target="${disk%%,*}" + if [ "$options" = "$disk" ]; then + disk="$target/$OVERLAY_DIR" + else + disk="$target/$OVERLAY_DIR,$options" + fi fi - mount_part "$disk" "/storage" "rw,noatime" + mount_part "$disk" "/storage" "rw,noatime" + fi } check_update() { progress "Checking for updates" + if [ -f "/flash/MACH_KERNEL" ]; then IMAGE_KERNEL="MACH_KERNEL" fi @@ -288,7 +294,10 @@ NBD_DEVS="0" # /flash is actual root filesystem /bin/busybox mount --move /flash /sysroot fi - /bin/busybox mount --move /storage /sysroot/storage + + if [ -n "$disk" ]; then + /bin/busybox mount --move /storage /sysroot/storage + fi [ -f "/sysroot/sbin/init" ] || error "final_check" "Could not find system." }