summaryrefslogtreecommitdiffstats
path: root/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-init.sh
blob: 431780a701aeeb3c3e7cb11494f98bc7703feb4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/sh

rodir=run/initramfs/ro
rwdir=run/initramfs/rw
upper=$rwdir/cow
work=$rwdir/work

cd /
mkdir -p sys proc dev run
mount dev dev -tdevtmpfs
mount sys sys -tsysfs
mount proc proc -tproc
if ! grep run proc/mounts
then
	mount tmpfs run -t tmpfs -o mode=755,nodev
fi

mkdir -p $rodir $rwdir

cp -rp init shutdown update whitelist bin sbin usr lib etc var run/initramfs

# To start a interactive shell with job control at this point, run
# getty 38400 ttyS4

findmtd() {
	m=$(grep -xl "$1" /sys/class/mtd/*/name)
	m=${m%/name}
	m=${m##*/}
	echo $m
}

rofs=$(findmtd rofs)
rwfs=$(findmtd rwfs)

rofst=squashfs
rwfst=ext4

echo rofs = $rofs $rofst   rwfs = $rwfs $rwfst

if grep -w debug-init-sh /proc/cmdline ||
	! mount -o rw /dev/mtdblock${rwfs#mtd} $rwdir -t $rwfst
then
	echo Please mount the rw file system on $rwdir from this shell
	while ! sulogin && ! test -f /takeover
	do
		echo getty failed, retrying
	done
fi

# Touch /takeover in the above getty to become pid 1
if test -e /takeover
then
	export PS1=init#\ 
	exec /bin/sh
fi

mount -o ro /dev/mtdblock${rofs#mtd} $rodir -t $rofst

rm -rf $work
mkdir -p $upper
mkdir -p $work

mount -t overlay -o lowerdir=$rodir,upperdir=$upper,workdir=$work cow /root

if ! chroot /root /bin/sh -c exit
then
	echo 'chroot test failed; invoking emergency shell.'
	PS1=rescue#\  sulogin
fi

for f in sys dev proc run
do
	mount --move $f root/$f
done

# switch_root /root /sbin/init
exec chroot /root /sbin/init

OpenPOWER on IntegriCloud