slitaz-boot-scripts view init @ rev 446

network.sh: stop wpa_cli interactive mode with static_ip
author Richard Dunbar <mojo@slitaz.org>
date Fri Oct 27 12:18:19 2017 -0400 (2017-10-27)
parents 6373374e4683
children b92b0376b504
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/overlayfs & 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
54 fail() {
55 echo -e '\033[70G[ \033[1;3'${1:-1mFailed}'\033[0;39m ]'
56 }
59 quit() {
60 [ -d /mnt$4/etc ] || return
61 grep -q serial /proc/ioports && ! grep -q ttyS /mnt$4/etc/inittab &&
62 echo "ttyS0::respawn:/sbin/getty 115200,38400,9600,4800,2400 ttyS0" \
63 >> /mnt$4/etc/inittab
64 [ -n "$4" ] || grep -q 'tmpfs /mnt tmpfs' /proc/mounts ||
65 busybox mount /mnt -o remount,ro
66 busybox mount --move /run /mnt/${1:-run}
67 cat > /run/init <<EOT
68 $2
69 x=/sbin/switch_root
70 [ -x \$x ] && exec \$x mnt $3 /sbin/init
71 EOT
72 fail 2mDone
73 exit
74 }
77 arg() {
78 grep -q $1 /proc/cmdline
79 }
82 got() {
83 arg $1= && root="$(sed "s/.*$1=\([^ ]*\).*/\1/" </proc/cmdline)"
84 }
87 msg() {
88 echo "Switching / to $1..."
89 }
92 use() {
93 got $1 && msg "$1 $root"
94 }
97 mnt() {
98 r=$(busybox blkid 2> /dev/null | sed "s|\"||g;/${root//[^a-zA-Z0-9]/.}/!d;s|:.*||;q")
99 r=${r:-$root}
100 if [ ! -b $r ]; then
101 r=${r#/dev/}
102 r=/dev/${r%%/*}
103 fi
104 d=${root#*$r}
105 busybox mount $r $1 && return
106 w=$(cat /sys/module/usb_storage/parameters/delay_use)
107 w=$((1+${w:-2}))
108 echo -n "Sleep $w seconds..."
109 sleep $w
110 busybox mount $r $1
111 }
114 mod() {
115 for i in $@; do
116 echo "Loading module: $i"
117 modprobe $i 2>/dev/null || busybox insmod $(find /lib/modules|sed "/$i.ko/!dq")
118 done
119 }
122 try() {
123 if [ ! -d /mnt/etc ] && got cryptoroot; then
124 mod dm-mod dm-crypt aes-256
125 d=${root#/dev/}
126 l=crypto-$d
127 if cryptsetup isLuks $root 2>/dev/null; then
128 cryptsetup luksOpen $root $l
129 else
130 read -st 60 -p "Pass phrase : " p
131 k=$(echo $p|hashalot -x -n 32 sha512)
132 echo 0 $(cat $(find /sys/block|grep /$d/size))\
133 crypt aes-plain $k 0 $root 0|dmsetup create $l
134 fi
135 busybox mount /dev/mapper/$l /mnt
136 fi
137 got subroot && return
138 got loopfs && return
139 if [ -d /mnt/etc ]; then
140 for i in $@; do
141 cp -a $i /mnt$(dirname $i)
142 done
143 quit
144 fi
145 fail
146 }
149 lvm() {
150 use lvmroot || return
151 mod dm-mod
152 vgscan --ignorelockingfailure
153 vgchange -ay --ignorelockingfailure
154 busybox mount /dev/mapper/$root /mnt
155 try /dev/mapper $1
156 }
159 ldraid() {
160 while read l; do
161 case "$l" in
162 *raid10*) mod raid10;;
163 *raid0*) mod raid0;;
164 *raid1*) mod raid1;;
165 *raid*) mod raid456;;
166 *mirror*) mod dm-mirror;;
167 esac
168 done
169 }
174 if [ "$1" != 'log' ]; then
175 busybox mount -t proc proc /proc
176 busybox mount -t sysfs sys /sys
177 busybox mount -t tmpfs tmpfs /run
178 x=/sbin/init; echo "[ -x $x ] && exec $x" >/run/init
179 $0 log 2>&1 | tee /run/boot.log
180 busybox umount /sys
181 busybox umount /proc
182 . /run/init
183 sh
184 fi
186 for i in /sys/block/*/dev /sys/block/*/*/dev ; do
187 [ -s "$i" ] || continue
188 n=${i%/dev}
189 n=/dev/${n##*/}
190 [ -e $n ] && continue
191 echo "Create $n "
192 mknod $n b $(sed 's/:/ /' < $i)
193 done
195 got modprobe && mod ${root//,/ }
197 [ -d /proc/sys/dev/cdrom ] &&
198 ln -s $(sed '/name/!d;s/.*:[^a-z]*//' /proc/sys/dev/cdrom/info) /dev/cdrom
200 if use dmraid; then
201 dmraid -s | sed '/^type/!ds/.*: *//' | ldraid
202 [ ${root:0:4} = /dev ] ||
203 root=/dev/mapper/$(dmraid -s|sed '/^name/!ds/.*: *//')p${root#p}
204 dmraid -ay
205 fi
206 use raiddev && raiddev="DEVICE ${root//,/ }"
207 use raidmail && raidmail="MAILADDR $root"
208 if use softraid; then
209 for i in 1 2 3 4 5 6 7 8 9; do
210 mdadm -E -s -c partitions > /etc/mdadm.conf
211 grep -qs " $root " /etc/mdadm.conf && break
212 sleep $i
213 done
214 [ "$raiddev" ] && echo "$raiddev" >> /etc/mdadm.conf
215 [ "$raidmail" ] && echo "$raidmail" >> /etc/mdadm.conf
216 grep level=raid /etc/mdadm.conf | ldraid
217 for i in 1 2 3 4 5 6 7 8 9; do
218 sleep $i
219 mdadm -A -s
220 grep -qs "^$(basename $root) : act" /proc/mdstat && break
221 done
222 grep -qs "^$(basename $root) : act" /proc/mdstat ||
223 root=$(awk '/^md/ { print "/dev/" $1; exit }' < /proc/mdstat)
224 lvm /etc/mdadm.conf
225 fi
226 lvm
228 if got mount; then
229 dev=$root
230 x=$(busybox blkid|grep $dev|sed 's/:.*//;q')
231 root=${x:-$dev}
232 [ "$dev" = "$root" ] || dev="$root ($dev)"
233 echo "Mount $dev..."
234 mnt /mnt
235 arg posixovl && echo "And posixovl..." &&
236 mount.posixovl -F /mnt -- -oallow_other -odefault_permissions -osuid
237 fi
239 got loopfs && echo "Into file $root..." &&
240 losetup /dev/loop0 /mnt/$root && busybox mount /dev/loop0 /mnt
241 got bindfs && echo "Bind ${root/,/ to }..." &&
242 busybox mount --bind /mnt/${root%,*} /mnt/${root/,//}
243 arg cryptoroot= && try
244 if use subroot; then
245 cp $(LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so /usr/sbin/chroot | sed\
246 's|.*=> \(/lib/l[^ ]*\).*|\1|;/^\//!d') /usr/sbin/chroot /run
247 r=$root/run
248 quit $r "export LD_LIBRARY_PATH=$r:/lib"\
249 "$root$(ls /run/ld-*so) $r/chroot $root" "/$root"
250 fi
251 quit
252 msg tmpfs
253 root=100
254 got tmpram
255 r=$root
256 inodes=0
257 got rootfsinodes && inodes=$root
258 root=90%
259 got rootfssize
260 [ $(busybox free|busybox awk '/Mem:/{print int(($4*100)/$3)}') -ge $r ] &&
261 busybox mount -t tmpfs -o size=$root,nr_inodes=$inodes tmpfs /mnt &&
262 for i in $(ls -ar /); do
263 case "$i" in
264 .*|cdrom) ;;
265 mnt|proc|sys) mkdir /mnt/$i;;
266 usr|var|rootfs*) mv /$i /mnt;;
267 *) cp -a /$i /mnt 2>/dev/null && continue
268 fail
269 busybox umount /mnt
270 exit
271 esac
272 done || fail 3mSkipped
273 quit
274 mod squashfs 2>/dev/null || exit
275 msg aufs
276 br=/mnt/.rw
277 mkdir $br /mnt/.wd
278 got rwdev && mnt $br && br=$br$d
279 o=
280 p=
281 c=/mnt/.cdrom
282 if [ -z "$(ls /mnt/rootfs* 2>/dev/null)" ]; then
283 root=/dev/cdrom/fs
284 got rodev
285 mkdir -p $c /mnt$c /mnt/.rw$c
286 mnt $c
287 o="-o 124"
288 p=/.cdrom/boot
289 c=$c$d
290 fi
291 l=0
292 r=
293 got isofs && r=:$c || for i in /mnt$p/rootfs?*.gz; do
294 fs=${i#*root}
295 r=$r:/mnt/.$fs
296 mkdir -p /mnt/.rw/mnt/.$fs /mnt/.$fs
297 losetup $o /dev/loop$l $i
298 busybox mount -o ro -t squashfs /dev/loop$((l++)) /mnt/.$fs
299 done
300 while read type opt; do
301 mod $type && busybox mount -t $type -o $opt none /mnt && break
302 done <<EOT
303 aufs br=$br$r
304 overlayfs workdir=/mnt/.wd${r/:/,lowerdir=},upperdir=$br
305 EOT
306 quit