Skip to content
This repository

Netboot Upgrade #59

Closed
wants to merge 4 commits into from

2 participants

Joel Pedraza Lars Op den Kamp
Joel Pedraza

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

Joel Pedraza saik0 closed this
Lars Op den Kamp

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 1 changed file with 113 additions and 80 deletions. Show diff stats Hide diff stats

  1. +113 80 packages/initramfs/sysutils/busybox-initramfs/scripts/init
193 packages/initramfs/sysutils/busybox-initramfs/scripts/init 100755 → 100644
@@ -22,15 +22,11 @@
22 22 ################################################################################
23 23
24 24 UPDATE_DIR=/storage/.update
  25 +UPDATE=0
25 26
26 27 IMAGE_SYSTEM="SYSTEM"
27 28 IMAGE_KERNEL="KERNEL"
28   -REBOOT="0"
29   -
30   -# defaults for booting from an nbd root
31   -NBD_ROOT_SERVER="192.168.1.1"
32   -NBD_ROOT_PORT="2000"
33   -NFS_OVERLAY="192.168.1.1:/var/lib/overlay"
  29 +REBOOT=0
34 30
35 31 # mount all needed special filesystems
36 32 /bin/busybox mount -t devtmpfs none /dev
@@ -41,46 +37,31 @@ NFS_OVERLAY="192.168.1.1:/var/lib/overlay"
41 37 echo '1 4 1 7' > /proc/sys/kernel/printk
42 38
43 39 # parse command line arguments
44   - for arg in $(cat /proc/cmdline); do
45   - case $arg in
46   - debugging)
47   - DEBUG=yes
48   - ;;
49   - nosplash)
50   - SPLASH=no
51   - ;;
52   - bootchart)
53   - BOOTCHART=yes
54   - ;;
55   - fastboot)
56   - FASTBOOT=yes
57   - ;;
58   - netboot)
59   - NETBOOT=yes
60   - ;;
61   - nbdroot=*)
62   - nbdroot="${arg#nbdroot=}"
63   - NBD_ROOT_SERVER=$( echo "${nbdroot}" | /bin/busybox sed 's/:.*//')
64   - NBD_ROOT_PORT=$( echo "${nbdroot}" | /bin/busybox sed 's/.*://')
65   - ;;
66   - nbdserver=*)
67   - NBD_ROOT_SERVER="${arg#nbdserver=}"
68   - ;;
69   - nbdport=*)
70   - NBD_ROOT_PORT="${arg#nbdport=}"
71   - ;;
72   - nfsoverlay=*)
73   - NFS_OVERLAY="${arg#nfsoverlay=}"
74   - ;;
75   - esac
76   - done
  40 + while read line; do
  41 + for arg in $line; do
  42 + case $arg in
  43 + debugging)
  44 + DEBUG=yes
  45 + ;;
  46 + nosplash)
  47 + SPLASH=no
  48 + ;;
  49 + bootchart)
  50 + BOOTCHART=yes
  51 + ;;
  52 + fastboot)
  53 + FASTBOOT=yes
  54 + ;;
  55 + esac
  56 + done
  57 + done < /proc/cmdline
77 58
78   - if test "$FASTBOOT" = "yes"; then
  59 + if [ "$FASTBOOT" = "yes" ]; then
79 60 IONICE="/bin/busybox ionice -c 1 -n 0"
80 61 fi
81 62
82 63 progress() {
83   - if test "$DEBUG" = "yes"; then
  64 + if [ "$DEBUG" = "yes" ]; then
84 65 echo "### $1 ###"
85 66 fi
86 67 }
@@ -144,7 +125,7 @@ NFS_OVERLAY="192.168.1.1:/var/lib/overlay"
144 125 $IONICE /bin/busybox mv $UPDATE_DIR/$2 $3
145 126 $IONICE /bin/busybox mount -o remount,ro /flash
146 127 $IONICE /bin/busybox sync
147   - [ "$2" = "$IMAGE_KERNEL" ] && REBOOT="1"
  128 + [ "$2" = "$IMAGE_KERNEL" ] && REBOOT=1
148 129 fi
149 130 }
150 131
@@ -165,14 +146,52 @@ NFS_OVERLAY="192.168.1.1:/var/lib/overlay"
165 146 done
166 147 }
167 148
168   - mount_nbd() {
  149 + mount_boot() {
  150 + case $boot in
  151 + LABEL=*|UUID=*)
  152 + mount_boot_disk
  153 + ;;
  154 + NFS=*)
  155 + mount_boot_nfs
  156 + ;;
  157 + NBD=*)
  158 + mount_boot_nbd
  159 + ;;
  160 + esac
  161 + }
  162 +
  163 + mount_boot_disk() {
  164 + # deal with hfs partitions
  165 + if [ -x /sbin/fsck_hfs ]; then
  166 + hfsdiskprep
  167 + fi
  168 +
  169 + mount_part "$boot" "/flash" "ro,noatime"
  170 + show_splash
  171 +
  172 + UPDATE=1
  173 + mount_disk
  174 +
  175 + if [ -f "/flash/$IMAGE_SYSTEM" ]; then
  176 + mount_part "/flash/$IMAGE_SYSTEM" "/sysroot" "ro,loop"
  177 + [ "$ERR_ENV" -ne "0" ] && debug_shell
  178 + else
  179 + error "INIT_2" "Could not find system."
  180 + debug_shell
  181 + fi
  182 +
  183 + /bin/busybox mount --move /flash /sysroot/flash
  184 + /bin/busybox mount --move /storage /sysroot/storage
  185 + }
  186 +
  187 + mount_boot_nbd() {
  188 + boot=${boot#*=}
169 189 retry_nr=0
170 190 retry_delay=20
171   - OVERLAY_DIR=`cat /sys/class/net/eth0/address | /bin/busybox tr -d :`
172 191
173 192 while [ ${retry_nr} -lt ${retry_delay} ] && [ ! -e /sysroot/sbin/init ]; do
174 193 [ ${retry_nr} -gt 0 ] && \
175   - $IONICE /bin/busybox nbd-client $NBD_ROOT_SERVER $NBD_ROOT_PORT /dev/nbd0 && \
  194 + $IONICE /bin/busybox nbd-client ${boot%%:*} ${boot##*:} /dev/nbd0 && \
176 195 mount_part "/dev/nbd0" "/sysroot" "ro" "squashfs"
177 196
178 197 retry_nr=$(( ${retry_nr} + 1 ))
@@ -183,67 +202,81 @@ NFS_OVERLAY="192.168.1.1:/var/lib/overlay"
183 202 done
184 203
185 204 if [ ! -e /sysroot/sbin/init ]; then
186   - error "INIT_2" "Could not mount NBD root from $NBD_ROOT_SERVER port $NBD_ROOT_PORT"
  205 + error "INIT_2" "Could not mount NBD root from $boot"
187 206 debug_shell
188 207 fi
189 208
190   - mount_part "$NFS_OVERLAY" "/sysroot/storage" "rw,nolock,retrans=10" "nfs"
  209 + mount_disk
  210 +
  211 + /bin/busybox mount --move /storage /sysroot/storage
  212 + }
191 213
192   - if [ ! -d /sysroot/storage/$OVERLAY_DIR ]; then
193   - mkdir /sysroot/storage/$OVERLAY_DIR
  214 + mount_boot_nfs() {
  215 + boot=${boot#*=}
  216 + mount_part "$boot" "/flash" "ro,nolock,noatime" "nfs"
  217 + show_splash
  218 +
  219 +
  220 + if [ -f "/flash/$IMAGE_SYSTEM" ]; then
  221 + mount_part "/flash/$IMAGE_SYSTEM" "/sysroot" "ro,loop"
  222 + [ "$ERR_ENV" -ne "0" ] && debug_shell
  223 + else
  224 + error "INIT_2" "Could not find system."
  225 + debug_shell
194 226 fi
195 227
196   - /bin/busybox umount /sysroot/storage
197   - mount_part "$NFS_OVERLAY/$OVERLAY_DIR" "/sysroot/storage" "rw,nolock" "nfs"
  228 + mount_disk
  229 +
  230 + /bin/busybox mount --move /flash /sysroot/flash
  231 + /bin/busybox mount --move /storage /sysroot/storage
198 232 }
199 233
200 234 mount_disk() {
  235 + case $disk in
  236 + LABEL=*|UUID=*)
  237 + mount_disk_disk
  238 + ;;
  239 + NFS=*)
  240 + mount_disk_nfs
  241 + ;;
  242 + esac
  243 + }
201 244
202   - # deal with hfs partitions
203   - if [ -x /sbin/fsck_hfs ]; then
204   - hfsdiskprep
205   - fi
206   -
207   - mount_part "$boot" "/flash" "ro,noatime"
208   - show_splash
209   -
210   - if [ -n "$disk" ]; then
211   - mount_part "$disk" "/storage" "rw,noatime"
  245 + mount_disk_disk() {
  246 + mount_part "$disk" "/storage" "rw,noatime"
212 247
  248 + if [ $UPDATE -gt 0 ]; then
213 249 if [ -f "/flash/MACH_KERNEL" ]; then
214 250 IMAGE_KERNEL="MACH_KERNEL"
215 251 fi
216   -
  252 +
217 253 update "Kernel" "$IMAGE_KERNEL" "/flash/$IMAGE_KERNEL"
218 254 update "System" "$IMAGE_SYSTEM" "/flash/$IMAGE_SYSTEM"
219   -
220   - if test "$REBOOT" -eq "1"; then
  255 +
  256 + if [ $REBOOT -gt 0 ]; then
221 257 echo "System reboots now..." && \
222 258 /bin/busybox reboot
223 259 fi
  260 +
224 261 fi
  262 + }
225 263
226   - if [ -f "/flash/$IMAGE_SYSTEM" ]; then
227   - mount_part "/flash/$IMAGE_SYSTEM" "/sysroot" "ro,loop"
228   - [ "$ERR_ENV" -ne "0" ] && debug_shell
229   - else
230   - error "INIT_2" "Could not find system."
231   - debug_shell
232   - fi
  264 + mount_disk_nfs() {
  265 + disk=${disk#*=}
233 266
234   - # move /flash and /storage to /sysroot
235   - /bin/busybox mount --move /flash /sysroot/flash
  267 + # provision NFS overlay
  268 + mount_part "$disk" "/storage" "rw,nolock,retrans=10" "nfs"
236 269
237   - if [ -n "$disk" ]; then
238   - /bin/busybox mount --move /storage /sysroot/storage
  270 + if [ ! -d /storage/$BOOTIF ]; then
  271 + mkdir /storage/$BOOTIF
239 272 fi
  273 +
  274 + # remount provisioned NFS overlay
  275 + /bin/busybox umount /storage
  276 + mount_part "$disk/$BOOTIF" "/storage" "rw,nolock" "nfs"
240 277 }
241 278
242   - if [ -z "$NETBOOT" ]; then
243   - mount_disk
244   - else
245   - mount_nbd
246   - fi
  279 + mount_boot
247 280
248 281 # move some special filesystems
249 282 /bin/busybox mount --move /dev /sysroot/dev

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.