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