Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Netboot Upgrade #59

Closed
wants to merge 4 commits into from

2 participants

@saik0

Add NFS /flash
Separate functions for booting root and storage
Tidy initramfs script (change some subshells to bash builtins for string manipulation)

@saik0 saik0 closed this
@opdenkamp

it's cleaner with the nbd related kernel options merged, but why rename the nfsoverlay?

also, please parse the old param names too, for backwards compat, or people who upgrade their installations will end up with systems that don't boot up

I see in the PR note that it's renamed so it matches the other options, which is fine.

but still parse the old options please :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 113 additions and 80 deletions.
  1. +113 −80 packages/initramfs/sysutils/busybox-initramfs/scripts/init
View
193 packages/initramfs/sysutils/busybox-initramfs/scripts/init 100755 → 100644
@@ -22,15 +22,11 @@
################################################################################
UPDATE_DIR=/storage/.update
+UPDATE=0
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"
+REBOOT=0
# mount all needed special filesystems
/bin/busybox mount -t devtmpfs none /dev
@@ -41,46 +37,31 @@ NFS_OVERLAY="192.168.1.1:/var/lib/overlay"
echo '1 4 1 7' > /proc/sys/kernel/printk
# parse command line arguments
- for arg in $(cat /proc/cmdline); do
- case $arg in
- debugging)
- DEBUG=yes
- ;;
- nosplash)
- SPLASH=no
- ;;
- bootchart)
- BOOTCHART=yes
- ;;
- 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=}"
- ;;
- esac
- done
+ while read line; do
+ for arg in $line; do
+ case $arg in
+ debugging)
+ DEBUG=yes
+ ;;
+ nosplash)
+ SPLASH=no
+ ;;
+ bootchart)
+ BOOTCHART=yes
+ ;;
+ fastboot)
+ FASTBOOT=yes
+ ;;
+ esac
+ done
+ done < /proc/cmdline
- if test "$FASTBOOT" = "yes"; then
+ if [ "$FASTBOOT" = "yes" ]; then
IONICE="/bin/busybox ionice -c 1 -n 0"
fi
progress() {
- if test "$DEBUG" = "yes"; then
+ if [ "$DEBUG" = "yes" ]; then
echo "### $1 ###"
fi
}
@@ -144,7 +125,7 @@ NFS_OVERLAY="192.168.1.1:/var/lib/overlay"
$IONICE /bin/busybox mv $UPDATE_DIR/$2 $3
$IONICE /bin/busybox mount -o remount,ro /flash
$IONICE /bin/busybox sync
- [ "$2" = "$IMAGE_KERNEL" ] && REBOOT="1"
+ [ "$2" = "$IMAGE_KERNEL" ] && REBOOT=1
fi
}
@@ -165,14 +146,52 @@ NFS_OVERLAY="192.168.1.1:/var/lib/overlay"
done
}
- mount_nbd() {
+ mount_boot() {
+ case $boot in
+ LABEL=*|UUID=*)
+ mount_boot_disk
+ ;;
+ NFS=*)
+ mount_boot_nfs
+ ;;
+ NBD=*)
+ mount_boot_nbd
+ ;;
+ esac
+ }
+
+ mount_boot_disk() {
+ # deal with hfs partitions
+ if [ -x /sbin/fsck_hfs ]; then
+ hfsdiskprep
+ fi
+
+ mount_part "$boot" "/flash" "ro,noatime"
+ show_splash
+
+ UPDATE=1
+ mount_disk
+
+ 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
+
+ /bin/busybox mount --move /flash /sysroot/flash
+ /bin/busybox mount --move /storage /sysroot/storage
+ }
+
+ mount_boot_nbd() {
+ boot=${boot#*=}
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 && \
+ $IONICE /bin/busybox nbd-client ${boot%%:*} ${boot##*:} /dev/nbd0 && \
mount_part "/dev/nbd0" "/sysroot" "ro" "squashfs"
retry_nr=$(( ${retry_nr} + 1 ))
@@ -183,67 +202,81 @@ NFS_OVERLAY="192.168.1.1:/var/lib/overlay"
done
if [ ! -e /sysroot/sbin/init ]; then
- error "INIT_2" "Could not mount NBD root from $NBD_ROOT_SERVER port $NBD_ROOT_PORT"
+ error "INIT_2" "Could not mount NBD root from $boot"
debug_shell
fi
- mount_part "$NFS_OVERLAY" "/sysroot/storage" "rw,nolock,retrans=10" "nfs"
+ mount_disk
+
+ /bin/busybox mount --move /storage /sysroot/storage
+ }
- if [ ! -d /sysroot/storage/$OVERLAY_DIR ]; then
- mkdir /sysroot/storage/$OVERLAY_DIR
+ mount_boot_nfs() {
+ boot=${boot#*=}
+ mount_part "$boot" "/flash" "ro,nolock,noatime" "nfs"
+ show_splash
+
+
+ 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
- /bin/busybox umount /sysroot/storage
- mount_part "$NFS_OVERLAY/$OVERLAY_DIR" "/sysroot/storage" "rw,nolock" "nfs"
+ mount_disk
+
+ /bin/busybox mount --move /flash /sysroot/flash
+ /bin/busybox mount --move /storage /sysroot/storage
}
mount_disk() {
+ case $disk in
+ LABEL=*|UUID=*)
+ mount_disk_disk
+ ;;
+ NFS=*)
+ mount_disk_nfs
+ ;;
+ esac
+ }
- # deal with hfs partitions
- if [ -x /sbin/fsck_hfs ]; then
- hfsdiskprep
- fi
-
- mount_part "$boot" "/flash" "ro,noatime"
- show_splash
-
- if [ -n "$disk" ]; then
- mount_part "$disk" "/storage" "rw,noatime"
+ mount_disk_disk() {
+ mount_part "$disk" "/storage" "rw,noatime"
+ if [ $UPDATE -gt 0 ]; then
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
+
+ if [ $REBOOT -gt 0 ]; then
echo "System reboots now..." && \
/bin/busybox reboot
fi
+
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
+ mount_disk_nfs() {
+ disk=${disk#*=}
- # move /flash and /storage to /sysroot
- /bin/busybox mount --move /flash /sysroot/flash
+ # provision NFS overlay
+ mount_part "$disk" "/storage" "rw,nolock,retrans=10" "nfs"
- if [ -n "$disk" ]; then
- /bin/busybox mount --move /storage /sysroot/storage
+ if [ ! -d /storage/$BOOTIF ]; then
+ mkdir /storage/$BOOTIF
fi
+
+ # remount provisioned NFS overlay
+ /bin/busybox umount /storage
+ mount_part "$disk/$BOOTIF" "/storage" "rw,nolock" "nfs"
}
- if [ -z "$NETBOOT" ]; then
- mount_disk
- else
- mount_nbd
- fi
+ mount_boot
# move some special filesystems
/bin/busybox mount --move /dev /sysroot/dev
Something went wrong with that request. Please try again.