slitaz-boot-scripts view init @ rev 414

/etc/init.d/bootopts.sh: typo
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Aug 29 21:12:39 2015 +0200 (2015-08-29)
parents 4321dbbe16c7
children 29ec74a6d359
line source
1 #!/bin/sh
3 ### cached kernel parameters :
4 #
5 # modprobe=
6 # list of modules to load, example modprobe=r8169,btrfs
7 #
8 ### Frugal mode or live CD : using a root ram disk.
9 #
10 # tmpram= [RAMDISK]
11 # minimum % of free RAM to build the root tmpfs, default 100
12 # a lower value may work, such as 50
13 # rootfssize= [RAMDISK]
14 # size of / regarding the RAM size, default 90%
15 # rootfsinodes= [RAMDISK]
16 # files count of / regarding the RAM size, default 0 (unlimited)
17 #
18 ### Indirect mode ; an initramfs is used to mount root from the hard disk.
19 ### Any rootfs should fit, minimum required is slitaz-base.
20 #
21 # mount= [MOUNT]
22 # device with root loop file or sub directory
23 # posixovl [MOUNT]
24 # use posix attributes on a non posix filesystem (VFAT, NTFS...)
25 # loopfs= [MOUNT]
26 # loop file for root filesystem
27 # subroot= [MOUNT]
28 # sub directory for root filesystem
29 # bindfs= [MOUNT] (deprecated)
30 # bind out of root tree part
31 #
32 ### Special disk mode ; needs extra modules/softwares from preinit flavor.
33 #
34 # dmraid= [RAID]
35 # root semi hardware raid device name in /dev/mapper
36 # softraid= [RAID]
37 # root software device name in /dev/mapper
38 # lvmroot= [LVM]
39 # root logical volume name in /dev/mapper
40 # cryptoroot= [CRYPTO]
41 # encrypted root device using luks or loop-aes
42 #
43 ### Special mode used by loram flavor with aufs & squashfs
44 ### incremental/nested rootfs (russian dolls).
45 #
46 # rodev= [LORAM][MERGE]
47 # device (+ optional path) for the read only aufs branch
48 # rwdev= [LORAM][MERGE]
49 # (persistent) device for the r/w aufs branch instead of the ramfs
50 # isofs [LORAM]
51 # do not use squashfs filesystem images, but the cdrom filesystem only
53 fail()
54 {
55 echo -e '\033[70G[ \033[1;3'${1:-1mFailed}'\033[0;39m ]'
56 }
58 quit()
59 {
60 [ -d /mnt$4/etc ] || return
61 [ -n "$4" ] || busybox mount /mnt -o remount,ro
62 busybox mount --move /run /mnt/${1:-run}
63 cat>/run/init<<EOT
64 $2
65 x=/sbin/switch_root
66 [ -x \$x ] && exec \$x mnt $3 /sbin/init
67 EOT
68 fail 2mDone
69 exit
70 }
72 arg()
73 {
74 grep -q $1 /proc/cmdline
75 }
77 got()
78 {
79 arg $1= && root="$(sed "s/.*$1=\([^ ]*\).*/\1/" </proc/cmdline)"
80 }
82 msg()
83 {
84 echo "Switching / to $1..."
85 }
87 use()
88 {
89 got $1 && msg "$1 $root"
90 }
92 mnt()
93 {
94 r=$(busybox blkid 2> /dev/null | sed "s|\"||g;/${root//[^a-zA-Z0-9]/.}/!d;s|:.*||;q")
95 r=${r:-$root}
96 if [ ! -b $r ]; then
97 r=${r#/dev/}
98 r=/dev/${r%%/*}
99 fi
100 d=${root#*$r}
101 busybox mount $r $1 && return
102 w=$(cat /sys/module/usb_storage/parameters/delay_use)
103 w=$((1+${w:-2}))
104 echo -n "Sleep $w seconds..."
105 sleep $w
106 busybox mount $r $1
107 }
109 mod()
110 {
111 for i in $@; do
112 echo "Loading module: $i"
113 modprobe $i 2>/dev/null || busybox insmod $(find /lib/modules|sed "/$i.ko/!dq")
114 done
115 }
117 try()
118 {
119 if [ ! -d /mnt/etc ] && got cryptoroot; then
120 mod dm-mod dm-crypt aes-256
121 d=${root#/dev/}
122 l=crypto-$d
123 if cryptsetup isLuks $root 2>/dev/null; then
124 cryptsetup luksOpen $root $l
125 else
126 read -st 60 -p "Pass phrase : " p
127 k=$(echo $p|hashalot -x -n 32 sha512)
128 echo 0 $(cat $(find /sys/block|grep /$d/size))\
129 crypt aes-plain $k 0 $root 0|dmsetup create $l
130 fi
131 busybox mount /dev/mapper/$l /mnt
132 fi
133 got subroot && return
134 got loopfs && return
135 if [ -d /mnt/etc ]; then
136 for i in $@; do
137 cp -a $i /mnt$(dirname $i)
138 done
139 quit
140 fi
141 fail
142 }
144 lvm()
145 {
146 use lvmroot || return
147 mod dm-mod
148 vgscan --ignorelockingfailure
149 vgchange -ay --ignorelockingfailure
150 busybox mount /dev/mapper/$root /mnt
151 try /dev/mapper $1
152 }
154 ldraid()
155 {
156 while read l; do
157 case "$l" in
158 *raid10*) mod raid10;;
159 *raid0*) mod raid0;;
160 *raid1*) mod raid1;;
161 *raid*) mod raid456;;
162 *mirror*) mod dm-mirror;;
163 esac
164 done
165 }
167 if [ "$1" != "log" ]; then
168 busybox mount -t proc proc /proc
169 busybox mount -t sysfs sys /sys
170 busybox mount -t tmpfs tmpfs /run
171 x=/sbin/init; echo "[ -x $x ] && exec $x" >/run/init
172 $0 log 2>&1 | tee /run/boot.log
173 busybox umount /sys
174 busybox umount /proc
175 . /run/init
176 sh
177 fi
178 for i in /sys/block/*/dev /sys/block/*/*/dev ; do
179 [ -s "$i" ] || continue
180 n=${i%/dev}
181 n=/dev/${n##*/}
182 [ -e $n ] && continue
183 echo "Create $n "
184 mknod $n b $(sed 's/:/ /' < $i)
185 done
186 got modprobe && mod ${root//,/ }
187 [ -d /proc/sys/dev/cdrom ] &&
188 ln -s $(sed '/name/!d;s/.*:[^a-z]*//' /proc/sys/dev/cdrom/info) /dev/cdrom
189 if use dmraid; then
190 dmraid -s | sed '/^type/!ds/.*: *//' | ldraid
191 [ ${root:0:4} = /dev ] ||
192 root=/dev/mapper/$(dmraid -s|sed '/^name/!ds/.*: *//')p${root#p}
193 dmraid -ay
194 fi
195 use raiddev && raiddev="DEVICE ${root//,/ }"
196 use raidmail && raidmail="MAILADDR $root"
197 if use softraid; then
198 mdadm -E -s -c partitions > /etc/mdadm.conf
199 [ "$raiddev" ] && echo "$raiddev" >> /etc/mdadm.conf
200 [ "$raidmail" ] && echo "$raidmail" >> /etc/mdadm.conf
201 grep -qs " $root " /etc/mdadm.conf ||
202 root=$(awk '/dev.md/{print $2;exit}' < /etc/mdadm.conf)
203 grep level=raid /etc/mdadm.conf | ldraid
204 for i in 1 2 3 4 5 6 7 8 9; do
205 sleep $i
206 mdadm -A -s
207 grep -qs ': act' /proc/mdstat && break
208 done
209 lvm /etc/mdadm.conf
210 fi
211 lvm
212 if got mount; then
213 dev=$root
214 x=$(busybox blkid|grep $dev|sed 's/:.*//;q')
215 root=${x:-$dev}
216 [ "$dev" = "$root" ] || dev="$root ($dev)"
217 echo "Mount $dev..."
218 mnt /mnt
219 arg posixovl && echo "And posixovl..." &&
220 mount.posixovl -F /mnt -- -oallow_other -odefault_permissions -osuid
221 fi
222 got loopfs && echo "Into file $root..." &&
223 losetup /dev/loop0 /mnt/$root && busybox mount /dev/loop0 /mnt
224 got bindfs && echo "Bind ${root/,/ to }..." &&
225 busybox mount --bind /mnt/${root%,*} /mnt/${root/,//}
226 arg cryptoroot= && try
227 if use subroot; then
228 cp $(LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so /usr/sbin/chroot | sed\
229 's|.*=> \(/lib/l[^ ]*\).*|\1|;/^\//!d') /usr/sbin/chroot /run
230 r=$root/run
231 quit $r "export LD_LIBRARY_PATH=$r:/lib"\
232 "$root$(ls /run/ld-*so) $r/chroot $root" "/$root"
233 fi
234 quit
235 msg tmpfs
236 root=100
237 got tmpram
238 r=$root
239 inodes=0
240 got rootfsinodes && inodes=$root
241 root=90%
242 got rootfssize
243 [ $(busybox free|busybox awk '/Mem:/{print int(($4*100)/$3)}') -ge $r ] &&
244 busybox mount -t tmpfs -o size=$root,nr_inodes=$inodes tmpfs /mnt &&
245 for i in $(ls -ar /); do
246 case "$i" in
247 .*|cdrom) ;;
248 mnt|proc|sys) mkdir /mnt/$i;;
249 usr|var|rootfs*) mv /$i /mnt;;
250 *) cp -a /$i /mnt 2>/dev/null && continue
251 fail
252 busybox umount /mnt
253 exit
254 esac
255 done || fail 3mSkipped
256 quit
257 mod squashfs 2>/dev/null || exit
258 msg aufs
259 br=/mnt/.rw
260 mkdir $br /mnt/.wd
261 got rwdev && mnt $br && br=$br$d
262 o=
263 p=
264 c=/mnt/.cdrom
265 if [ -z "$(ls /mnt/rootfs* 2>/dev/null)" ]; then
266 root=/dev/cdrom/fs
267 got rodev
268 mkdir -p $c /mnt$c /mnt/.rw$c
269 mnt $c
270 o="-o 124"
271 p=/.cdrom/boot
272 c=$c$d
273 fi
274 l=0
275 r=
276 got isofs && r=:$c || for i in /mnt$p/rootfs?*.gz; do
277 fs=${i#*root}
278 r=$r:/mnt/.$fs
279 mkdir -p /mnt/.rw/mnt/.$fs /mnt/.$fs
280 losetup $o /dev/loop$l $i
281 busybox mount -o ro -t squashfs /dev/loop$((l++)) /mnt/.$fs
282 done
283 while read type opt; do
284 mod $type && busybox mount -t $type -o $opt none /mnt && break
285 done <<EOT
286 aufs br=$br$r
287 overlayfs workdir=/mnt/.wd${r/:/,lowerdir=},upperdir=$br
288 EOT
289 quit