blob: eed8cf53baae2cb53890194ea6804360f748e73f [file] [log] [blame]
Milton D. Miller IId89d5e02016-01-20 14:57:54 -06001#!/bin/sh
2
3rodir=run/initramfs/ro
4rwdir=run/initramfs/rw
5upper=$rwdir/cow
6work=$rwdir/work
7
8cd /
9mkdir -p sys proc dev run
10mount dev dev -tdevtmpfs
11mount sys sys -tsysfs
12mount proc proc -tproc
13if ! grep run proc/mounts
14then
15 mount tmpfs run -t tmpfs -o mode=755,nodev
16fi
17
18mkdir -p $rodir $rwdir
19
20cp -rp init shutdown update whitelist bin sbin usr lib etc var run/initramfs
21
22# To start a interactive shell with job control at this point, run
23# getty 38400 ttyS4
24
25findmtd() {
26 m=$(grep -xl "$1" /sys/class/mtd/*/name)
27 m=${m%/name}
28 m=${m##*/}
29 echo $m
30}
31
Milton D. Miller IIbf7bfd42016-01-27 20:18:16 -060032env=$(findmtd u-boot-env)
33if test -n $env
34then
35 ln -s /dev/$env /run/mtd:u-boot-env
36 cp /run/mtd:u-boot-env /run/fw_env
37fi
38
Milton D. Miller IId89d5e02016-01-20 14:57:54 -060039rofs=$(findmtd rofs)
40rwfs=$(findmtd rwfs)
41
42rofst=squashfs
43rwfst=ext4
44
45echo rofs = $rofs $rofst rwfs = $rwfs $rwfst
46
47if grep -w debug-init-sh /proc/cmdline ||
48 ! mount -o rw /dev/mtdblock${rwfs#mtd} $rwdir -t $rwfst
49then
50 echo Please mount the rw file system on $rwdir from this shell
51 while ! sulogin && ! test -f /takeover
52 do
53 echo getty failed, retrying
54 done
55fi
56
57# Touch /takeover in the above getty to become pid 1
58if test -e /takeover
59then
60 export PS1=init#\
61 exec /bin/sh
62fi
63
64mount -o ro /dev/mtdblock${rofs#mtd} $rodir -t $rofst
65
66rm -rf $work
67mkdir -p $upper
68mkdir -p $work
69
70mount -t overlay -o lowerdir=$rodir,upperdir=$upper,workdir=$work cow /root
71
Milton Miller92fdfc12016-02-05 11:06:39 -060072if ! chroot /root /bin/sh -c "test -x /sbin/init -a -s /sbin/init"
Milton D. Miller IId89d5e02016-01-20 14:57:54 -060073then
Milton Miller92fdfc12016-02-05 11:06:39 -060074 echo "Unable to confirm /sbin/init is an executable non-empty file."
75 echo "Change Root test failed! Invoking emergency shell."
Milton D. Miller IId89d5e02016-01-20 14:57:54 -060076 PS1=rescue#\ sulogin
77fi
78
79for f in sys dev proc run
80do
81 mount --move $f root/$f
82done
83
84# switch_root /root /sbin/init
85exec chroot /root /sbin/init
86