slitaz-boot-scripts view init @ rev 425

init: some speeds for ttyS0
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Feb 15 12:33:39 2016 +0100 (2016-02-15)
parents e8a0127be52e
children 6373374e4683
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 [ -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 }
73 arg() {
74 grep -q $1 /proc/cmdline
75 }
78 got() {
79 arg $1= && root="$(sed "s/.*$1=\([^ ]*\).*/\1/" </proc/cmdline)"
80 }
83 msg() {
84 echo "Switching / to $1..."
85 }
88 use() {
89 got $1 && msg "$1 $root"
90 }
93 mnt() {
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 }
110 mod() {
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 }
118 try() {
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 }
145 lvm() {
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 }
155 ldraid() {
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 }
170 if [ "$1" != 'log' ]; then
171 busybox mount -t proc proc /proc
172 busybox mount -t sysfs sys /sys
173 busybox mount -t tmpfs tmpfs /run
174 x=/sbin/init; echo "[ -x $x ] && exec $x" >/run/init
175 $0 log 2>&1 | tee /run/boot.log
176 busybox umount /sys
177 busybox umount /proc
178 . /run/init
179 sh
180 fi
182 for i in /sys/block/*/dev /sys/block/*/*/dev ; do
183 [ -s "$i" ] || continue
184 n=${i%/dev}
185 n=/dev/${n##*/}
186 [ -e $n ] && continue
187 echo "Create $n "
188 mknod $n b $(sed 's/:/ /' < $i)
189 done
191 got modprobe && mod ${root//,/ }
193 [ -d /proc/sys/dev/cdrom ] &&
194 ln -s $(sed '/name/!d;s/.*:[^a-z]*//' /proc/sys/dev/cdrom/info) /dev/cdrom
196 grep -q serial /proc/ioports &&
197 echo "ttyS0::respawn:/sbin/getty 115200,38400,9600,4800,2400 ttyS0" >> /etc/inittab
199 if use dmraid; then
200 dmraid -s | sed '/^type/!ds/.*: *//' | ldraid
201 [ ${root:0:4} = /dev ] ||
202 root=/dev/mapper/$(dmraid -s|sed '/^name/!ds/.*: *//')p${root#p}
203 dmraid -ay
204 fi
205 use raiddev && raiddev="DEVICE ${root//,/ }"
206 use raidmail && raidmail="MAILADDR $root"
207 if use softraid; then
208 for i in 1 2 3 4 5 6 7 8 9; do
209 mdadm -E -s -c partitions > /etc/mdadm.conf
210 grep -qs " $root " /etc/mdadm.conf && break
211 sleep $i
212 done
213 [ "$raiddev" ] && echo "$raiddev" >> /etc/mdadm.conf
214 [ "$raidmail" ] && echo "$raidmail" >> /etc/mdadm.conf
215 grep level=raid /etc/mdadm.conf | ldraid
216 for i in 1 2 3 4 5 6 7 8 9; do
217 sleep $i
218 mdadm -A -s
219 grep -qs "^$(basename $root) : act" /proc/mdstat && break
220 done
221 grep -qs "^$(basename $root) : act" /proc/mdstat ||
222 root=$(awk '/^md/ { print "/dev/" $1; exit }' < /proc/mdstat)
223 lvm /etc/mdadm.conf
224 fi
225 lvm
227 if got mount; then
228 dev=$root
229 x=$(busybox blkid|grep $dev|sed 's/:.*//;q')
230 root=${x:-$dev}
231 [ "$dev" = "$root" ] || dev="$root ($dev)"
232 echo "Mount $dev..."
233 mnt /mnt
234 arg posixovl && echo "And posixovl..." &&
235 mount.posixovl -F /mnt -- -oallow_other -odefault_permissions -osuid
236 fi
238 got loopfs && echo "Into file $root..." &&
239 losetup /dev/loop0 /mnt/$root && busybox mount /dev/loop0 /mnt
240 got bindfs && echo "Bind ${root/,/ to }..." &&
241 busybox mount --bind /mnt/${root%,*} /mnt/${root/,//}
242 arg cryptoroot= && try
243 if use subroot; then
244 cp $(LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so /usr/sbin/chroot | sed\
245 's|.*=> \(/lib/l[^ ]*\).*|\1|;/^\//!d') /usr/sbin/chroot /run
246 r=$root/run
247 quit $r "export LD_LIBRARY_PATH=$r:/lib"\
248 "$root$(ls /run/ld-*so) $r/chroot $root" "/$root"
249 fi
250 quit
251 msg tmpfs
252 root=100
253 got tmpram
254 r=$root
255 inodes=0
256 got rootfsinodes && inodes=$root
257 root=90%
258 got rootfssize
259 [ $(busybox free|busybox awk '/Mem:/{print int(($4*100)/$3)}') -ge $r ] &&
260 busybox mount -t tmpfs -o size=$root,nr_inodes=$inodes tmpfs /mnt &&
261 for i in $(ls -ar /); do
262 case "$i" in
263 .*|cdrom) ;;
264 mnt|proc|sys) mkdir /mnt/$i;;
265 usr|var|rootfs*) mv /$i /mnt;;
266 *) cp -a /$i /mnt 2>/dev/null && continue
267 fail
268 busybox umount /mnt
269 exit
270 esac
271 done || fail 3mSkipped
272 quit
273 mod squashfs 2>/dev/null || exit
274 msg aufs
275 br=/mnt/.rw
276 mkdir $br /mnt/.wd
277 got rwdev && mnt $br && br=$br$d
278 o=
279 p=
280 c=/mnt/.cdrom
281 if [ -z "$(ls /mnt/rootfs* 2>/dev/null)" ]; then
282 root=/dev/cdrom/fs
283 got rodev
284 mkdir -p $c /mnt$c /mnt/.rw$c
285 mnt $c
286 o="-o 124"
287 p=/.cdrom/boot
288 c=$c$d
289 fi
290 l=0
291 r=
292 got isofs && r=:$c || for i in /mnt$p/rootfs?*.gz; do
293 fs=${i#*root}
294 r=$r:/mnt/.$fs
295 mkdir -p /mnt/.rw/mnt/.$fs /mnt/.$fs
296 losetup $o /dev/loop$l $i
297 busybox mount -o ro -t squashfs /dev/loop$((l++)) /mnt/.$fs
298 done
299 while read type opt; do
300 mod $type && busybox mount -t $type -o $opt none /mnt && break
301 done <<EOT
302 aufs br=$br$r
303 overlayfs workdir=/mnt/.wd${r/:/,lowerdir=},upperdir=$br
304 EOT
305 quit