Milton D. Miller II | 0e77514 | 2016-01-20 14:57:54 -0600 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
Milton Miller | ba65b7b | 2016-02-05 12:07:53 -0600 | [diff] [blame] | 3 | fslist="proc sys dev run" |
Milton D. Miller II | 0e77514 | 2016-01-20 14:57:54 -0600 | [diff] [blame] | 4 | rodir=run/initramfs/ro |
| 5 | rwdir=run/initramfs/rw |
| 6 | upper=$rwdir/cow |
| 7 | work=$rwdir/work |
| 8 | |
| 9 | cd / |
Milton Miller | ba65b7b | 2016-02-05 12:07:53 -0600 | [diff] [blame] | 10 | mkdir -p $fslist |
Milton D. Miller II | 0e77514 | 2016-01-20 14:57:54 -0600 | [diff] [blame] | 11 | mount dev dev -tdevtmpfs |
| 12 | mount sys sys -tsysfs |
| 13 | mount proc proc -tproc |
| 14 | if ! grep run proc/mounts |
| 15 | then |
| 16 | mount tmpfs run -t tmpfs -o mode=755,nodev |
| 17 | fi |
| 18 | |
| 19 | mkdir -p $rodir $rwdir |
| 20 | |
| 21 | cp -rp init shutdown update whitelist bin sbin usr lib etc var run/initramfs |
| 22 | |
| 23 | # To start a interactive shell with job control at this point, run |
| 24 | # getty 38400 ttyS4 |
| 25 | |
| 26 | findmtd() { |
| 27 | m=$(grep -xl "$1" /sys/class/mtd/*/name) |
| 28 | m=${m%/name} |
| 29 | m=${m##*/} |
| 30 | echo $m |
| 31 | } |
| 32 | |
Andrew Jeffery | 25a5022 | 2016-02-23 23:47:23 +1030 | [diff] [blame] | 33 | blkid_fs_type() { |
| 34 | # Emulate util-linux's `blkid -s TYPE -o value $1` |
| 35 | # Example busybox blkid output: |
| 36 | # # blkid /dev/mtdblock5 |
| 37 | # /dev/mtdblock5: TYPE="squashfs" |
| 38 | # Process output to extract TYPE value "squashfs". |
| 39 | blkid $1 | sed -e 's/^.*TYPE="//' -e 's/".*$//' |
| 40 | } |
| 41 | |
| 42 | probe_fs_type() { |
| 43 | fst=$(blkid_fs_type $1) |
| 44 | echo ${fst:=jffs2} |
| 45 | } |
| 46 | |
Milton D. Miller II | a81cb93 | 2016-03-07 17:46:28 -0600 | [diff] [blame] | 47 | # This fw_get_env_var is a possibly broken version of fw_printenv that |
| 48 | # does not check the crc or flag byte. |
Gunnar Mills | e5b3860 | 2018-08-31 12:39:15 -0500 | [diff] [blame] | 49 | # The u-boot environment starts with a crc32, followed by a flag byte |
Milton D. Miller II | ab61836 | 2016-03-02 15:23:22 -0600 | [diff] [blame] | 50 | # when a redundannt environment is configured, followed by var=value\0 sets. |
| 51 | # The flag byte for nand is a 1 byte counter; for nor it is a 1 or 0 byte. |
Milton D. Miller II | ab61836 | 2016-03-02 15:23:22 -0600 | [diff] [blame] | 52 | |
| 53 | get_fw_env_var() { |
Milton D. Miller II | a81cb93 | 2016-03-07 17:46:28 -0600 | [diff] [blame] | 54 | # do we have 1 or 2 copies of the environment? |
| 55 | # count non-blank non-comment lines |
| 56 | # copies=$(grep -v ^# /etc/fw_env.config | grep -c [::alnum::]) |
| 57 | # ... we could if we had the fw_env.config in the initramfs |
Edward A. James | fd6f07c | 2017-08-15 14:18:12 -0500 | [diff] [blame] | 58 | copies=2 |
Milton D. Miller II | a81cb93 | 2016-03-07 17:46:28 -0600 | [diff] [blame] | 59 | |
| 60 | # * Change \n to \r and \0 to \n |
| 61 | # * Skip to the 5th byte to skip over crc |
| 62 | # * then skip to the first or 2nd byte to skip over flag if it exists |
| 63 | # * stop parsing at first empty line corresponding to the |
| 64 | # double \0 at the end of the environment. |
| 65 | # * print the value of the variable name passed as argument |
| 66 | |
Edward A. James | eb77a8f | 2017-07-14 12:32:44 -0500 | [diff] [blame] | 67 | envdev=$(findmtd u-boot-env) |
| 68 | if test -n $envdev |
| 69 | then |
| 70 | cat /dev/$envdev | |
| 71 | tr '\n\000' '\r\n' | |
| 72 | tail -c +5 | tail -c +${copies-1} | |
| 73 | sed -ne '/^$/,$d' -e "s/^$1=//p" |
| 74 | fi |
Milton D. Miller II | ab61836 | 2016-03-02 15:23:22 -0600 | [diff] [blame] | 75 | } |
| 76 | |
Milton D. Miller II | 71e7ec1 | 2016-03-02 18:28:54 -0600 | [diff] [blame] | 77 | setup_resolv() { |
| 78 | runresolv=/run/systemd/resolve/resolv.conf |
| 79 | etcresolv=/etc/resolv.conf |
| 80 | |
| 81 | if test ! -e $etcresolv -a ! -L $etcresolv |
| 82 | then |
| 83 | mkdir -p ${runresolv%/*} |
| 84 | ln -s $runresolv $etcresolv |
| 85 | fi |
| 86 | if test ! -f $runresolv |
| 87 | then |
| 88 | cat /proc/net/pnp > $runresolv |
| 89 | fi |
| 90 | |
| 91 | return 0 |
| 92 | } |
| 93 | |
| 94 | try_tftp() { |
| 95 | # split into tftp:// host:port/ path/on/remote |
| 96 | # then spilt off / and then :port from the end of host:port/ |
| 97 | # and : from the beginning of port |
| 98 | |
| 99 | rest="${1#tftp://}" |
| 100 | path=${rest#*/} |
| 101 | host=${rest%$path} |
| 102 | host="${host%/}" |
| 103 | port="${host#${host%:*}}" |
| 104 | host="${host%$port}" |
| 105 | port="${port#:}" |
| 106 | |
| 107 | setup_resolv |
| 108 | |
| 109 | if test -z "$host" -o -z "$path" |
| 110 | then |
| 111 | debug_takeover "Invalid tftp download url '$url'." |
| 112 | elif echo "Downloading '$url' from $host ..." && |
| 113 | ! tftp -g -r "$path" -l /run/image-rofs "$host" ${port+"$port"} |
| 114 | then |
| 115 | debug_takeover "Download of '$url' failed." |
| 116 | fi |
| 117 | } |
| 118 | |
| 119 | try_wget() { |
| 120 | setup_resolv |
| 121 | |
| 122 | echo "Downloading '$1' ..." |
| 123 | if ! wget -O /run/image-rofs "$1" |
| 124 | then |
| 125 | debug_takeover "Download of '$url' failed." |
| 126 | fi |
| 127 | } |
| 128 | |
Milton Miller | 2250982 | 2016-02-05 13:04:29 -0600 | [diff] [blame] | 129 | debug_takeover() { |
| 130 | echo "$@" |
| 131 | test -n "$@" && echo Enter password to try to manually fix. |
| 132 | cat << HERE |
| 133 | After fixing run exit to continue this script, or reboot -f to retry, or |
| 134 | touch /takeover and exit to become PID 1 allowing editing of this script. |
| 135 | HERE |
| 136 | |
| 137 | while ! sulogin && ! test -f /takeover |
| 138 | do |
| 139 | echo getty failed, retrying |
| 140 | done |
| 141 | |
| 142 | # Touch /takeover in the above getty to become pid 1 |
| 143 | if test -e /takeover |
| 144 | then |
| 145 | cat << HERE |
| 146 | |
| 147 | Takeover of init requested. Executing /bin/sh as PID 1. |
| 148 | When finished exec new init or cleanup and run reboot -f. |
| 149 | |
| 150 | Warning: No job control! Shell exit will panic the system! |
| 151 | HERE |
| 152 | export PS1=init#\ |
| 153 | exec /bin/sh |
| 154 | fi |
| 155 | } |
| 156 | |
Milton D. Miller II | 0e77514 | 2016-01-20 14:57:54 -0600 | [diff] [blame] | 157 | rofs=$(findmtd rofs) |
| 158 | rwfs=$(findmtd rwfs) |
| 159 | |
Milton Miller | ba65b7b | 2016-02-05 12:07:53 -0600 | [diff] [blame] | 160 | rodev=/dev/mtdblock${rofs#mtd} |
| 161 | rwdev=/dev/mtdblock${rwfs#mtd} |
| 162 | |
Milton Miller | ec0ba3c | 2016-02-23 21:48:48 -0600 | [diff] [blame] | 163 | # Set to y for yes, anything else for no. |
| 164 | force_rwfst_jffs2=y |
| 165 | flash_images_before_init=n |
Milton D. Miller II | 71e7ec1 | 2016-03-02 18:28:54 -0600 | [diff] [blame] | 166 | consider_download_files=y |
| 167 | consider_download_tftp=y |
| 168 | consider_download_http=y |
| 169 | consider_download_ftp=y |
Milton Miller | ec0ba3c | 2016-02-23 21:48:48 -0600 | [diff] [blame] | 170 | |
Milton D. Miller II | 0e77514 | 2016-01-20 14:57:54 -0600 | [diff] [blame] | 171 | rofst=squashfs |
Andrew Jeffery | 25a5022 | 2016-02-23 23:47:23 +1030 | [diff] [blame] | 172 | rwfst=$(probe_fs_type $rwdev) |
Milton Miller | ba65b7b | 2016-02-05 12:07:53 -0600 | [diff] [blame] | 173 | roopts=ro |
| 174 | rwopts=rw |
| 175 | |
Milton Miller | ec0ba3c | 2016-02-23 21:48:48 -0600 | [diff] [blame] | 176 | image=/run/initramfs/image- |
| 177 | trigger=${image}rwfs |
| 178 | |
Milton Miller | ba65b7b | 2016-02-05 12:07:53 -0600 | [diff] [blame] | 179 | init=/sbin/init |
Milton Miller | ec0ba3c | 2016-02-23 21:48:48 -0600 | [diff] [blame] | 180 | fsckbase=/sbin/fsck. |
| 181 | fsck=$fsckbase$rwfst |
Milton Miller | 5c212e4 | 2016-02-06 16:05:06 -0600 | [diff] [blame] | 182 | fsckopts=-a |
Milton D. Miller II | 90b6847 | 2016-02-27 15:48:52 -0600 | [diff] [blame] | 183 | optfile=/run/initramfs/init-options |
Milton Miller | 49ce6a1 | 2016-05-25 18:52:04 -0500 | [diff] [blame] | 184 | optbase=/run/initramfs/init-options-base |
Milton D. Miller II | 71e7ec1 | 2016-03-02 18:28:54 -0600 | [diff] [blame] | 185 | urlfile=/run/initramfs/init-download-url |
Milton D. Miller II | 383bfc7 | 2016-02-29 11:35:14 -0600 | [diff] [blame] | 186 | update=/run/initramfs/update |
Milton D. Miller II | 90b6847 | 2016-02-27 15:48:52 -0600 | [diff] [blame] | 187 | |
Milton D. Miller II | 6d85431 | 2016-03-07 07:59:09 -0600 | [diff] [blame] | 188 | if test -e /${optfile##*/} |
| 189 | then |
| 190 | cp /${optfile##*/} $optfile |
| 191 | fi |
| 192 | |
Milton Miller | 49ce6a1 | 2016-05-25 18:52:04 -0500 | [diff] [blame] | 193 | if test -e /${optbase##*/} |
| 194 | then |
| 195 | cp /${optbase##*/} $optbase |
| 196 | else |
| 197 | touch $optbase |
| 198 | fi |
| 199 | |
Milton D. Miller II | 90b6847 | 2016-02-27 15:48:52 -0600 | [diff] [blame] | 200 | if test ! -f $optfile |
| 201 | then |
Milton Miller | 49ce6a1 | 2016-05-25 18:52:04 -0500 | [diff] [blame] | 202 | cat /proc/cmdline $optbase > $optfile |
Milton D. Miller II | ab61836 | 2016-03-02 15:23:22 -0600 | [diff] [blame] | 203 | get_fw_env_var openbmcinit >> $optfile |
| 204 | get_fw_env_var openbmconce >> $optfile |
Milton D. Miller II | 90b6847 | 2016-02-27 15:48:52 -0600 | [diff] [blame] | 205 | fi |
Milton D. Miller II | 0e77514 | 2016-01-20 14:57:54 -0600 | [diff] [blame] | 206 | |
| 207 | echo rofs = $rofs $rofst rwfs = $rwfs $rwfst |
| 208 | |
Milton D. Miller II | 90b6847 | 2016-02-27 15:48:52 -0600 | [diff] [blame] | 209 | if grep -w debug-init-sh $optfile |
Milton D. Miller II | 0e77514 | 2016-01-20 14:57:54 -0600 | [diff] [blame] | 210 | then |
Milton Miller | 2250982 | 2016-02-05 13:04:29 -0600 | [diff] [blame] | 211 | debug_takeover "Debug initial shell requested by command line." |
Milton D. Miller II | 0e77514 | 2016-01-20 14:57:54 -0600 | [diff] [blame] | 212 | fi |
| 213 | |
Milton D. Miller II | 71e7ec1 | 2016-03-02 18:28:54 -0600 | [diff] [blame] | 214 | if test "x$consider_download_files" = xy && |
| 215 | grep -w openbmc-init-download-files $optfile |
| 216 | then |
| 217 | if test -f ${urlfile##*/} |
| 218 | then |
| 219 | cp ${urlfile##*/} $urlfile |
| 220 | fi |
| 221 | if test ! -f $urlfile |
| 222 | then |
| 223 | get_fw_env_var openbmcinitdownloadurl > $urlfile |
| 224 | fi |
| 225 | url="$(cat $urlfile)" |
| 226 | rest="${url#*://}" |
| 227 | proto="${url%$rest}" |
| 228 | |
| 229 | if test -z "$url" |
| 230 | then |
| 231 | echo "Download url empty. Ignoring download request." |
| 232 | elif test -z "$proto" |
| 233 | then |
| 234 | echo "Download failed." |
| 235 | elif test "$proto" = tftp:// |
| 236 | then |
| 237 | if test "x$consider_download_tftp" = xy |
| 238 | then |
| 239 | try_tftp "$url" |
| 240 | else |
| 241 | echo "Download failed." |
| 242 | fi |
| 243 | elif test "$proto" = http:// |
| 244 | then |
| 245 | if test "x$consider_download_http" = xy |
| 246 | then |
| 247 | try_wget "$url" |
| 248 | else |
| 249 | echo "Download failed." |
| 250 | fi |
| 251 | elif test "$proto" = ftp:// |
| 252 | then |
| 253 | if test "x$consider_download_ftp" = xy |
| 254 | then |
| 255 | try_wget "$url" |
| 256 | else |
| 257 | echo "Download failed." |
| 258 | fi |
| 259 | else |
| 260 | echo "Download failed." |
| 261 | fi |
| 262 | fi |
| 263 | |
Milton D. Miller II | 21786ff | 2016-02-27 17:01:13 -0600 | [diff] [blame] | 264 | # If there are images in root move them to /run/initramfs/ or /run/ now. |
Milton Miller | ec0ba3c | 2016-02-23 21:48:48 -0600 | [diff] [blame] | 265 | imagebasename=${image##*/} |
Milton D. Miller II | 21786ff | 2016-02-27 17:01:13 -0600 | [diff] [blame] | 266 | if test -n "${imagebasename}" && ls /${imagebasename}* > /dev/null 2>&1 |
Milton Miller | ec0ba3c | 2016-02-23 21:48:48 -0600 | [diff] [blame] | 267 | then |
Milton D. Miller II | 21786ff | 2016-02-27 17:01:13 -0600 | [diff] [blame] | 268 | if test "x$flash_images_before_init" = xy |
| 269 | then |
| 270 | echo "Flash images found, will update before starting init." |
| 271 | mv /${imagebasename}* ${image%$imagebasename} |
| 272 | else |
| 273 | echo "Flash images found, will use but deferring flash update." |
| 274 | mv /${imagebasename}* /run/ |
| 275 | fi |
Milton Miller | ec0ba3c | 2016-02-23 21:48:48 -0600 | [diff] [blame] | 276 | fi |
| 277 | |
Milton D. Miller II | 90b6847 | 2016-02-27 15:48:52 -0600 | [diff] [blame] | 278 | if grep -w clean-rwfs-filesystem $optfile |
Milton Miller | ec0ba3c | 2016-02-23 21:48:48 -0600 | [diff] [blame] | 279 | then |
| 280 | echo "Cleaning of read-write overlay filesystem requested." |
| 281 | touch $trigger |
| 282 | fi |
| 283 | |
Lei YU | a08c996 | 2018-07-20 15:11:27 +0800 | [diff] [blame] | 284 | if grep -w factory-reset $optfile |
| 285 | then |
| 286 | echo "Factory reset requested." |
| 287 | touch $trigger |
| 288 | do_save=--no-save-files |
| 289 | else |
| 290 | do_save=--save-files |
| 291 | fi |
| 292 | |
Milton Miller | ec0ba3c | 2016-02-23 21:48:48 -0600 | [diff] [blame] | 293 | if test "x$force_rwfst_jffs2" = xy -a $rwfst != jffs2 -a ! -f $trigger |
| 294 | then |
| 295 | echo "Converting read-write overlay filesystem to jffs2 forced." |
| 296 | touch $trigger |
| 297 | fi |
| 298 | |
| 299 | if ls $image* > /dev/null 2>&1 |
| 300 | then |
Milton D. Miller II | 383bfc7 | 2016-02-29 11:35:14 -0600 | [diff] [blame] | 301 | if ! test -x $update |
Milton Miller | ec0ba3c | 2016-02-23 21:48:48 -0600 | [diff] [blame] | 302 | then |
Milton D. Miller II | 383bfc7 | 2016-02-29 11:35:14 -0600 | [diff] [blame] | 303 | debug_takeover "Flash update requested but $update missing!" |
Milton Miller | ec0ba3c | 2016-02-23 21:48:48 -0600 | [diff] [blame] | 304 | elif test -f $trigger -a ! -s $trigger |
| 305 | then |
Lei YU | a08c996 | 2018-07-20 15:11:27 +0800 | [diff] [blame] | 306 | if [ $do_save = "--save-files" ] |
| 307 | then |
| 308 | echo "Saving selected files from read-write overlay filesystem." |
| 309 | else |
| 310 | echo "No files will be selected for save." |
| 311 | fi |
| 312 | $update --no-restore-files $do_save |
Milton Miller | ec0ba3c | 2016-02-23 21:48:48 -0600 | [diff] [blame] | 313 | echo "Clearing read-write overlay filesystem." |
| 314 | flash_eraseall /dev/$rwfs |
| 315 | echo "Restoring saved files to read-write overlay filesystem." |
| 316 | touch $trigger |
Milton D. Miller II | 383bfc7 | 2016-02-29 11:35:14 -0600 | [diff] [blame] | 317 | $update --no-save-files --clean-saved-files |
Milton Miller | ec0ba3c | 2016-02-23 21:48:48 -0600 | [diff] [blame] | 318 | else |
Lei YU | a08c996 | 2018-07-20 15:11:27 +0800 | [diff] [blame] | 319 | $update --clean-saved-files $do_save |
Milton Miller | ec0ba3c | 2016-02-23 21:48:48 -0600 | [diff] [blame] | 320 | fi |
| 321 | |
| 322 | rwfst=$(probe_fs_type $rwdev) |
| 323 | fsck=$fsckbase$rwfst |
| 324 | fi |
| 325 | |
Milton D. Miller II | 5d772b0 | 2016-02-27 17:31:39 -0600 | [diff] [blame] | 326 | if grep -w overlay-filesystem-in-ram $optfile |
| 327 | then |
| 328 | rwfst=none |
| 329 | fi |
| 330 | |
Milton D. Miller II | 77be704 | 2016-02-29 12:10:34 -0600 | [diff] [blame] | 331 | copyfiles= |
| 332 | if grep -w copy-files-to-ram $optfile |
| 333 | then |
| 334 | rwfst=none |
| 335 | copyfiles=y |
| 336 | fi |
| 337 | |
| 338 | # It would be nice to do this after fsck but that mean rofs is mounted |
| 339 | # which triggers the mtd is mounted check |
| 340 | if test "$rwfst$copyfiles" = noney |
| 341 | then |
| 342 | touch $trigger |
| 343 | $update --copy-files --clean-saved-files --no-restore-files |
| 344 | fi |
| 345 | |
Milton D. Miller II | 9ecec17 | 2016-02-27 17:31:39 -0600 | [diff] [blame] | 346 | if grep -w copy-base-filesystem-to-ram $optfile && |
| 347 | test ! -e /run/image-rofs && ! cp $rodev /run/image-rofs |
| 348 | then |
| 349 | # Remove any partial copy to avoid attempted usage later |
| 350 | if test -e /run/image-rofs |
| 351 | then |
| 352 | ls -l /run/image-rofs |
| 353 | rm -f /run/image-rofs |
| 354 | fi |
| 355 | debug_takeover "Copying $rodev to /run/image-rofs failed." |
| 356 | fi |
| 357 | |
Milton D. Miller II | a8f26b6 | 2016-02-27 16:04:32 -0600 | [diff] [blame] | 358 | if test -s /run/image-rofs |
| 359 | then |
| 360 | rodev=/run/image-rofs |
| 361 | roopts=$roopts,loop |
| 362 | fi |
| 363 | |
Milton Miller | 5c212e4 | 2016-02-06 16:05:06 -0600 | [diff] [blame] | 364 | mount $rodev $rodir -t $rofst -o $roopts |
| 365 | |
| 366 | if test -x $rodir$fsck |
| 367 | then |
| 368 | for fs in $fslist |
| 369 | do |
| 370 | mount --bind $fs $rodir/$fs |
| 371 | done |
| 372 | chroot $rodir $fsck $fsckopts $rwdev |
| 373 | rc=$? |
| 374 | for fs in $fslist |
| 375 | do |
| 376 | umount $rodir/$fs |
| 377 | done |
| 378 | if test $rc -gt 1 |
| 379 | then |
| 380 | debug_takeover "fsck of read-write fs on $rwdev failed (rc=$rc)" |
| 381 | fi |
Milton D. Miller II | ed3680d | 2016-02-27 16:38:16 -0600 | [diff] [blame] | 382 | elif test "$rwfst" != jffs2 -a "$rwfst" != none |
Milton Miller | e442584 | 2016-02-23 21:00:06 -0600 | [diff] [blame] | 383 | then |
Milton Miller | 5c212e4 | 2016-02-06 16:05:06 -0600 | [diff] [blame] | 384 | echo "No '$fsck' in read only fs, skipping fsck." |
| 385 | fi |
| 386 | |
Milton D. Miller II | ed3680d | 2016-02-27 16:38:16 -0600 | [diff] [blame] | 387 | if test "$rwfst" = none |
| 388 | then |
| 389 | echo "Running with read-write overlay in RAM for this boot." |
| 390 | echo "No state will be preserved unless flash update performed." |
| 391 | elif ! mount $rwdev $rwdir -t $rwfst -o $rwopts |
Milton D. Miller II | 0e77514 | 2016-01-20 14:57:54 -0600 | [diff] [blame] | 392 | then |
Milton Miller | 2250982 | 2016-02-05 13:04:29 -0600 | [diff] [blame] | 393 | msg="$(cat)" << HERE |
| 394 | |
| 395 | Mounting read-write $rwdev filesystem failed. Please fix and run |
Andrew Jeffery | e4f6d37 | 2016-02-17 17:19:58 +1030 | [diff] [blame] | 396 | mount $rwdev $rwdir -t $rwfst -o $rwopts |
Milton Miller | 2250982 | 2016-02-05 13:04:29 -0600 | [diff] [blame] | 397 | to to continue, or do change nothing to run from RAM for this boot. |
| 398 | HERE |
| 399 | debug_takeover "$msg" |
Milton D. Miller II | 0e77514 | 2016-01-20 14:57:54 -0600 | [diff] [blame] | 400 | fi |
| 401 | |
Milton D. Miller II | 0e77514 | 2016-01-20 14:57:54 -0600 | [diff] [blame] | 402 | rm -rf $work |
Milton Miller | 5c212e4 | 2016-02-06 16:05:06 -0600 | [diff] [blame] | 403 | mkdir -p $upper $work |
Milton D. Miller II | 0e77514 | 2016-01-20 14:57:54 -0600 | [diff] [blame] | 404 | |
| 405 | mount -t overlay -o lowerdir=$rodir,upperdir=$upper,workdir=$work cow /root |
| 406 | |
Milton Miller | 2250982 | 2016-02-05 13:04:29 -0600 | [diff] [blame] | 407 | while ! chroot /root /bin/sh -c "test -x '$init' -a -s '$init'" |
| 408 | do |
| 409 | msg="$(cat)" << HERE |
| 410 | |
| 411 | Unable to confirm /sbin/init is an executable non-empty file |
| 412 | in merged file system mounted at /root. |
| 413 | |
| 414 | Change Root test failed! Invoking emergency shell. |
| 415 | HERE |
| 416 | debug_takeover "$msg" |
| 417 | done |
Milton D. Miller II | 0e77514 | 2016-01-20 14:57:54 -0600 | [diff] [blame] | 418 | |
Milton Miller | ba65b7b | 2016-02-05 12:07:53 -0600 | [diff] [blame] | 419 | for f in $fslist |
Milton D. Miller II | 0e77514 | 2016-01-20 14:57:54 -0600 | [diff] [blame] | 420 | do |
| 421 | mount --move $f root/$f |
| 422 | done |
| 423 | |
Milton Miller | ba65b7b | 2016-02-05 12:07:53 -0600 | [diff] [blame] | 424 | # switch_root /root $init |
| 425 | exec chroot /root $init |
Milton D. Miller II | 0e77514 | 2016-01-20 14:57:54 -0600 | [diff] [blame] | 426 | |