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 "$@" |
Adriana Kobylak | 7fd0173 | 2020-03-12 11:12:59 -0500 | [diff] [blame] | 131 | |
| 132 | if ! grep -w enable-initrd-debug-sh "$optfile" |
| 133 | then |
| 134 | echo "Fatal error, triggering kernel panic!" |
| 135 | exit 1 |
| 136 | fi |
| 137 | |
| 138 | test -n "$@" && echo Try to manually fix. |
Milton Miller | 2250982 | 2016-02-05 13:04:29 -0600 | [diff] [blame] | 139 | cat << HERE |
| 140 | After fixing run exit to continue this script, or reboot -f to retry, or |
| 141 | touch /takeover and exit to become PID 1 allowing editing of this script. |
| 142 | HERE |
| 143 | |
Adriana Kobylak | 7fd0173 | 2020-03-12 11:12:59 -0500 | [diff] [blame] | 144 | while ! /bin/sh && ! test -f /takeover |
Milton Miller | 2250982 | 2016-02-05 13:04:29 -0600 | [diff] [blame] | 145 | do |
Adriana Kobylak | 7fd0173 | 2020-03-12 11:12:59 -0500 | [diff] [blame] | 146 | echo /bin/sh failed, retrying |
Milton Miller | 2250982 | 2016-02-05 13:04:29 -0600 | [diff] [blame] | 147 | done |
| 148 | |
Adriana Kobylak | 7fd0173 | 2020-03-12 11:12:59 -0500 | [diff] [blame] | 149 | # Touch /takeover in the above shell to become pid 1 |
Milton Miller | 2250982 | 2016-02-05 13:04:29 -0600 | [diff] [blame] | 150 | if test -e /takeover |
| 151 | then |
| 152 | cat << HERE |
| 153 | |
| 154 | Takeover of init requested. Executing /bin/sh as PID 1. |
| 155 | When finished exec new init or cleanup and run reboot -f. |
| 156 | |
| 157 | Warning: No job control! Shell exit will panic the system! |
| 158 | HERE |
| 159 | export PS1=init#\ |
| 160 | exec /bin/sh |
| 161 | fi |
| 162 | } |
| 163 | |
Milton D. Miller II | 0e77514 | 2016-01-20 14:57:54 -0600 | [diff] [blame] | 164 | rofs=$(findmtd rofs) |
| 165 | rwfs=$(findmtd rwfs) |
| 166 | |
Milton Miller | ba65b7b | 2016-02-05 12:07:53 -0600 | [diff] [blame] | 167 | rodev=/dev/mtdblock${rofs#mtd} |
| 168 | rwdev=/dev/mtdblock${rwfs#mtd} |
| 169 | |
Milton Miller | ec0ba3c | 2016-02-23 21:48:48 -0600 | [diff] [blame] | 170 | # Set to y for yes, anything else for no. |
| 171 | force_rwfst_jffs2=y |
| 172 | flash_images_before_init=n |
Milton D. Miller II | 71e7ec1 | 2016-03-02 18:28:54 -0600 | [diff] [blame] | 173 | consider_download_files=y |
| 174 | consider_download_tftp=y |
| 175 | consider_download_http=y |
| 176 | consider_download_ftp=y |
Milton Miller | ec0ba3c | 2016-02-23 21:48:48 -0600 | [diff] [blame] | 177 | |
Milton D. Miller II | 0e77514 | 2016-01-20 14:57:54 -0600 | [diff] [blame] | 178 | rofst=squashfs |
Andrew Jeffery | 25a5022 | 2016-02-23 23:47:23 +1030 | [diff] [blame] | 179 | rwfst=$(probe_fs_type $rwdev) |
Milton Miller | ba65b7b | 2016-02-05 12:07:53 -0600 | [diff] [blame] | 180 | roopts=ro |
| 181 | rwopts=rw |
| 182 | |
Milton Miller | ec0ba3c | 2016-02-23 21:48:48 -0600 | [diff] [blame] | 183 | image=/run/initramfs/image- |
| 184 | trigger=${image}rwfs |
| 185 | |
Milton Miller | ba65b7b | 2016-02-05 12:07:53 -0600 | [diff] [blame] | 186 | init=/sbin/init |
Milton Miller | ec0ba3c | 2016-02-23 21:48:48 -0600 | [diff] [blame] | 187 | fsckbase=/sbin/fsck. |
| 188 | fsck=$fsckbase$rwfst |
Milton Miller | 5c212e4 | 2016-02-06 16:05:06 -0600 | [diff] [blame] | 189 | fsckopts=-a |
Milton D. Miller II | 90b6847 | 2016-02-27 15:48:52 -0600 | [diff] [blame] | 190 | optfile=/run/initramfs/init-options |
Milton Miller | 49ce6a1 | 2016-05-25 18:52:04 -0500 | [diff] [blame] | 191 | optbase=/run/initramfs/init-options-base |
Milton D. Miller II | 71e7ec1 | 2016-03-02 18:28:54 -0600 | [diff] [blame] | 192 | urlfile=/run/initramfs/init-download-url |
Milton D. Miller II | 383bfc7 | 2016-02-29 11:35:14 -0600 | [diff] [blame] | 193 | update=/run/initramfs/update |
Milton D. Miller II | 90b6847 | 2016-02-27 15:48:52 -0600 | [diff] [blame] | 194 | |
Milton D. Miller II | 6d85431 | 2016-03-07 07:59:09 -0600 | [diff] [blame] | 195 | if test -e /${optfile##*/} |
| 196 | then |
| 197 | cp /${optfile##*/} $optfile |
| 198 | fi |
| 199 | |
Milton Miller | 49ce6a1 | 2016-05-25 18:52:04 -0500 | [diff] [blame] | 200 | if test -e /${optbase##*/} |
| 201 | then |
| 202 | cp /${optbase##*/} $optbase |
| 203 | else |
| 204 | touch $optbase |
| 205 | fi |
| 206 | |
Milton D. Miller II | 90b6847 | 2016-02-27 15:48:52 -0600 | [diff] [blame] | 207 | if test ! -f $optfile |
| 208 | then |
Milton Miller | 49ce6a1 | 2016-05-25 18:52:04 -0500 | [diff] [blame] | 209 | cat /proc/cmdline $optbase > $optfile |
Milton D. Miller II | ab61836 | 2016-03-02 15:23:22 -0600 | [diff] [blame] | 210 | get_fw_env_var openbmcinit >> $optfile |
| 211 | get_fw_env_var openbmconce >> $optfile |
Milton D. Miller II | 90b6847 | 2016-02-27 15:48:52 -0600 | [diff] [blame] | 212 | fi |
Milton D. Miller II | 0e77514 | 2016-01-20 14:57:54 -0600 | [diff] [blame] | 213 | |
| 214 | echo rofs = $rofs $rofst rwfs = $rwfs $rwfst |
| 215 | |
Milton D. Miller II | 90b6847 | 2016-02-27 15:48:52 -0600 | [diff] [blame] | 216 | if grep -w debug-init-sh $optfile |
Milton D. Miller II | 0e77514 | 2016-01-20 14:57:54 -0600 | [diff] [blame] | 217 | then |
Adriana Kobylak | 7fd0173 | 2020-03-12 11:12:59 -0500 | [diff] [blame] | 218 | if grep -w enable-initrd-debug-sh "$optfile" |
| 219 | then |
| 220 | debug_takeover "Debug initial shell requested by command line." |
| 221 | else |
| 222 | echo "Need to also add enable-initrd-debug-sh for debug shell." |
| 223 | fi |
Milton D. Miller II | 0e77514 | 2016-01-20 14:57:54 -0600 | [diff] [blame] | 224 | fi |
| 225 | |
Milton D. Miller II | 71e7ec1 | 2016-03-02 18:28:54 -0600 | [diff] [blame] | 226 | if test "x$consider_download_files" = xy && |
| 227 | grep -w openbmc-init-download-files $optfile |
| 228 | then |
| 229 | if test -f ${urlfile##*/} |
| 230 | then |
| 231 | cp ${urlfile##*/} $urlfile |
| 232 | fi |
| 233 | if test ! -f $urlfile |
| 234 | then |
| 235 | get_fw_env_var openbmcinitdownloadurl > $urlfile |
| 236 | fi |
| 237 | url="$(cat $urlfile)" |
| 238 | rest="${url#*://}" |
| 239 | proto="${url%$rest}" |
| 240 | |
| 241 | if test -z "$url" |
| 242 | then |
| 243 | echo "Download url empty. Ignoring download request." |
| 244 | elif test -z "$proto" |
| 245 | then |
| 246 | echo "Download failed." |
| 247 | elif test "$proto" = tftp:// |
| 248 | then |
| 249 | if test "x$consider_download_tftp" = xy |
| 250 | then |
| 251 | try_tftp "$url" |
| 252 | else |
| 253 | echo "Download failed." |
| 254 | fi |
| 255 | elif test "$proto" = http:// |
| 256 | then |
| 257 | if test "x$consider_download_http" = xy |
| 258 | then |
| 259 | try_wget "$url" |
| 260 | else |
| 261 | echo "Download failed." |
| 262 | fi |
| 263 | elif test "$proto" = ftp:// |
| 264 | then |
| 265 | if test "x$consider_download_ftp" = xy |
| 266 | then |
| 267 | try_wget "$url" |
| 268 | else |
| 269 | echo "Download failed." |
| 270 | fi |
| 271 | else |
| 272 | echo "Download failed." |
| 273 | fi |
| 274 | fi |
| 275 | |
Milton D. Miller II | 21786ff | 2016-02-27 17:01:13 -0600 | [diff] [blame] | 276 | # 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] | 277 | imagebasename=${image##*/} |
Milton D. Miller II | 21786ff | 2016-02-27 17:01:13 -0600 | [diff] [blame] | 278 | if test -n "${imagebasename}" && ls /${imagebasename}* > /dev/null 2>&1 |
Milton Miller | ec0ba3c | 2016-02-23 21:48:48 -0600 | [diff] [blame] | 279 | then |
Milton D. Miller II | 21786ff | 2016-02-27 17:01:13 -0600 | [diff] [blame] | 280 | if test "x$flash_images_before_init" = xy |
| 281 | then |
| 282 | echo "Flash images found, will update before starting init." |
| 283 | mv /${imagebasename}* ${image%$imagebasename} |
| 284 | else |
| 285 | echo "Flash images found, will use but deferring flash update." |
| 286 | mv /${imagebasename}* /run/ |
| 287 | fi |
Milton Miller | ec0ba3c | 2016-02-23 21:48:48 -0600 | [diff] [blame] | 288 | fi |
| 289 | |
Milton D. Miller II | 90b6847 | 2016-02-27 15:48:52 -0600 | [diff] [blame] | 290 | if grep -w clean-rwfs-filesystem $optfile |
Milton Miller | ec0ba3c | 2016-02-23 21:48:48 -0600 | [diff] [blame] | 291 | then |
| 292 | echo "Cleaning of read-write overlay filesystem requested." |
| 293 | touch $trigger |
| 294 | fi |
| 295 | |
Lei YU | a08c996 | 2018-07-20 15:11:27 +0800 | [diff] [blame] | 296 | if grep -w factory-reset $optfile |
| 297 | then |
| 298 | echo "Factory reset requested." |
| 299 | touch $trigger |
| 300 | do_save=--no-save-files |
| 301 | else |
| 302 | do_save=--save-files |
| 303 | fi |
| 304 | |
Milton Miller | ec0ba3c | 2016-02-23 21:48:48 -0600 | [diff] [blame] | 305 | if test "x$force_rwfst_jffs2" = xy -a $rwfst != jffs2 -a ! -f $trigger |
| 306 | then |
| 307 | echo "Converting read-write overlay filesystem to jffs2 forced." |
| 308 | touch $trigger |
| 309 | fi |
| 310 | |
| 311 | if ls $image* > /dev/null 2>&1 |
| 312 | then |
Milton D. Miller II | 383bfc7 | 2016-02-29 11:35:14 -0600 | [diff] [blame] | 313 | if ! test -x $update |
Milton Miller | ec0ba3c | 2016-02-23 21:48:48 -0600 | [diff] [blame] | 314 | then |
Milton D. Miller II | 383bfc7 | 2016-02-29 11:35:14 -0600 | [diff] [blame] | 315 | debug_takeover "Flash update requested but $update missing!" |
Milton Miller | ec0ba3c | 2016-02-23 21:48:48 -0600 | [diff] [blame] | 316 | elif test -f $trigger -a ! -s $trigger |
| 317 | then |
Lei YU | a08c996 | 2018-07-20 15:11:27 +0800 | [diff] [blame] | 318 | if [ $do_save = "--save-files" ] |
| 319 | then |
| 320 | echo "Saving selected files from read-write overlay filesystem." |
| 321 | else |
| 322 | echo "No files will be selected for save." |
| 323 | fi |
| 324 | $update --no-restore-files $do_save |
Milton Miller | ec0ba3c | 2016-02-23 21:48:48 -0600 | [diff] [blame] | 325 | echo "Clearing read-write overlay filesystem." |
| 326 | flash_eraseall /dev/$rwfs |
| 327 | echo "Restoring saved files to read-write overlay filesystem." |
| 328 | touch $trigger |
Milton D. Miller II | 383bfc7 | 2016-02-29 11:35:14 -0600 | [diff] [blame] | 329 | $update --no-save-files --clean-saved-files |
Milton Miller | ec0ba3c | 2016-02-23 21:48:48 -0600 | [diff] [blame] | 330 | else |
Lei YU | a08c996 | 2018-07-20 15:11:27 +0800 | [diff] [blame] | 331 | $update --clean-saved-files $do_save |
Milton Miller | ec0ba3c | 2016-02-23 21:48:48 -0600 | [diff] [blame] | 332 | fi |
| 333 | |
| 334 | rwfst=$(probe_fs_type $rwdev) |
| 335 | fsck=$fsckbase$rwfst |
| 336 | fi |
| 337 | |
Milton D. Miller II | 5d772b0 | 2016-02-27 17:31:39 -0600 | [diff] [blame] | 338 | if grep -w overlay-filesystem-in-ram $optfile |
| 339 | then |
| 340 | rwfst=none |
| 341 | fi |
| 342 | |
Milton D. Miller II | 77be704 | 2016-02-29 12:10:34 -0600 | [diff] [blame] | 343 | copyfiles= |
| 344 | if grep -w copy-files-to-ram $optfile |
| 345 | then |
| 346 | rwfst=none |
| 347 | copyfiles=y |
| 348 | fi |
| 349 | |
| 350 | # It would be nice to do this after fsck but that mean rofs is mounted |
| 351 | # which triggers the mtd is mounted check |
| 352 | if test "$rwfst$copyfiles" = noney |
| 353 | then |
| 354 | touch $trigger |
| 355 | $update --copy-files --clean-saved-files --no-restore-files |
| 356 | fi |
| 357 | |
Milton D. Miller II | 9ecec17 | 2016-02-27 17:31:39 -0600 | [diff] [blame] | 358 | if grep -w copy-base-filesystem-to-ram $optfile && |
| 359 | test ! -e /run/image-rofs && ! cp $rodev /run/image-rofs |
| 360 | then |
| 361 | # Remove any partial copy to avoid attempted usage later |
| 362 | if test -e /run/image-rofs |
| 363 | then |
| 364 | ls -l /run/image-rofs |
| 365 | rm -f /run/image-rofs |
| 366 | fi |
| 367 | debug_takeover "Copying $rodev to /run/image-rofs failed." |
| 368 | fi |
| 369 | |
Milton D. Miller II | a8f26b6 | 2016-02-27 16:04:32 -0600 | [diff] [blame] | 370 | if test -s /run/image-rofs |
| 371 | then |
| 372 | rodev=/run/image-rofs |
| 373 | roopts=$roopts,loop |
| 374 | fi |
| 375 | |
Milton Miller | 5c212e4 | 2016-02-06 16:05:06 -0600 | [diff] [blame] | 376 | mount $rodev $rodir -t $rofst -o $roopts |
| 377 | |
| 378 | if test -x $rodir$fsck |
| 379 | then |
| 380 | for fs in $fslist |
| 381 | do |
| 382 | mount --bind $fs $rodir/$fs |
| 383 | done |
| 384 | chroot $rodir $fsck $fsckopts $rwdev |
| 385 | rc=$? |
| 386 | for fs in $fslist |
| 387 | do |
| 388 | umount $rodir/$fs |
| 389 | done |
| 390 | if test $rc -gt 1 |
| 391 | then |
| 392 | debug_takeover "fsck of read-write fs on $rwdev failed (rc=$rc)" |
| 393 | fi |
Milton D. Miller II | ed3680d | 2016-02-27 16:38:16 -0600 | [diff] [blame] | 394 | elif test "$rwfst" != jffs2 -a "$rwfst" != none |
Milton Miller | e442584 | 2016-02-23 21:00:06 -0600 | [diff] [blame] | 395 | then |
Milton Miller | 5c212e4 | 2016-02-06 16:05:06 -0600 | [diff] [blame] | 396 | echo "No '$fsck' in read only fs, skipping fsck." |
| 397 | fi |
| 398 | |
Milton D. Miller II | ed3680d | 2016-02-27 16:38:16 -0600 | [diff] [blame] | 399 | if test "$rwfst" = none |
| 400 | then |
| 401 | echo "Running with read-write overlay in RAM for this boot." |
| 402 | echo "No state will be preserved unless flash update performed." |
| 403 | elif ! mount $rwdev $rwdir -t $rwfst -o $rwopts |
Milton D. Miller II | 0e77514 | 2016-01-20 14:57:54 -0600 | [diff] [blame] | 404 | then |
Milton Miller | 2250982 | 2016-02-05 13:04:29 -0600 | [diff] [blame] | 405 | msg="$(cat)" << HERE |
| 406 | |
| 407 | Mounting read-write $rwdev filesystem failed. Please fix and run |
Andrew Jeffery | e4f6d37 | 2016-02-17 17:19:58 +1030 | [diff] [blame] | 408 | mount $rwdev $rwdir -t $rwfst -o $rwopts |
Adriana Kobylak | 7fd0173 | 2020-03-12 11:12:59 -0500 | [diff] [blame] | 409 | or perform a factory reset with the clean-rwfs-filesystem option. |
Milton Miller | 2250982 | 2016-02-05 13:04:29 -0600 | [diff] [blame] | 410 | HERE |
| 411 | debug_takeover "$msg" |
Milton D. Miller II | 0e77514 | 2016-01-20 14:57:54 -0600 | [diff] [blame] | 412 | fi |
| 413 | |
Milton D. Miller II | 0e77514 | 2016-01-20 14:57:54 -0600 | [diff] [blame] | 414 | rm -rf $work |
Milton Miller | 5c212e4 | 2016-02-06 16:05:06 -0600 | [diff] [blame] | 415 | mkdir -p $upper $work |
Milton D. Miller II | 0e77514 | 2016-01-20 14:57:54 -0600 | [diff] [blame] | 416 | |
| 417 | mount -t overlay -o lowerdir=$rodir,upperdir=$upper,workdir=$work cow /root |
| 418 | |
Milton Miller | 2250982 | 2016-02-05 13:04:29 -0600 | [diff] [blame] | 419 | while ! chroot /root /bin/sh -c "test -x '$init' -a -s '$init'" |
| 420 | do |
| 421 | msg="$(cat)" << HERE |
| 422 | |
| 423 | Unable to confirm /sbin/init is an executable non-empty file |
| 424 | in merged file system mounted at /root. |
| 425 | |
Adriana Kobylak | 7fd0173 | 2020-03-12 11:12:59 -0500 | [diff] [blame] | 426 | Change Root test failed! |
Milton Miller | 2250982 | 2016-02-05 13:04:29 -0600 | [diff] [blame] | 427 | HERE |
| 428 | debug_takeover "$msg" |
| 429 | done |
Milton D. Miller II | 0e77514 | 2016-01-20 14:57:54 -0600 | [diff] [blame] | 430 | |
Milton Miller | ba65b7b | 2016-02-05 12:07:53 -0600 | [diff] [blame] | 431 | for f in $fslist |
Milton D. Miller II | 0e77514 | 2016-01-20 14:57:54 -0600 | [diff] [blame] | 432 | do |
| 433 | mount --move $f root/$f |
| 434 | done |
| 435 | |
Milton Miller | ba65b7b | 2016-02-05 12:07:53 -0600 | [diff] [blame] | 436 | # switch_root /root $init |
| 437 | exec chroot /root $init |
Milton D. Miller II | 0e77514 | 2016-01-20 14:57:54 -0600 | [diff] [blame] | 438 | |