slitaz-boot-scripts view init @ rev 407

init: fix rootfsinodes default value
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Aug 02 11:03:52 2015 +0200 (2015-08-02)
parents d6c818f35639
children 1542a6f14fae
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, 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=$(blkid 2> /dev/null | sed "s|\"||g;/$(echo $root | tr / .)/!d;s|:.*||;q")
95 r=${r:-$root}
96 r=${r#/dev/}
97 r=/dev/${r%%/*}
98 d=${root#*$r}
99 busybox mount $r $1 && return
100 w=$(cat /sys/module/usb_storage/parameters/delay_use)
101 w=$((1+${w:-2}))
102 echo -n "Sleep $w seconds..."
103 sleep $w
104 busybox mount $r $1
105 }
107 mod()
108 {
109 for i in $@; do
110 echo "Loading module: $i"
111 modprobe $i 2>/dev/null || busybox insmod $(find /lib/modules|sed "/$i.ko/!dq")
112 done
113 }
115 try()
116 {
117 if [ ! -d /mnt/etc ] && got cryptoroot; then
118 mod dm-mod dm-crypt aes-256
119 d=${root#/dev/}
120 l=crypto-$d
121 if cryptsetup isLuks $root 2>/dev/null; then
122 cryptsetup luksOpen $root $l
123 else
124 read -st 60 -p "Pass phrase : " p
125 k=$(echo $p|hashalot -x -n 32 sha512)
126 echo 0 $(cat $(find /sys/block|grep /$d/size))\
127 crypt aes-plain $k 0 $root 0|dmsetup create $l
128 fi
129 busybox mount /dev/mapper/$l /mnt
130 fi
131 got subroot && return
132 got loopfs && return
133 if [ -d /mnt/etc ]; then
134 for i in $@; do
135 cp -a $i /mnt$(dirname $i)
136 done
137 quit
138 fi
139 fail
140 }
142 lvm()
143 {
144 use lvmroot || return
145 mod dm-mod
146 vgscan --ignorelockingfailure
147 vgchange -ay --ignorelockingfailure
148 busybox mount /dev/mapper/$root /mnt
149 try /dev/mapper $1
150 }
152 ldraid()
153 {
154 while read l; do
155 case "$l" in
156 *raid10*) mod raid10;;
157 *raid0*) mod raid0;;
158 *raid1*) mod raid1;;
159 *raid*) mod raid456;;
160 *mirror*) mod dm-mirror;;
161 esac
162 done
163 }
165 if [ "$1" != "log" ]; then
166 busybox mount -t proc proc /proc
167 busybox mount -t sysfs sys /sys
168 busybox mount -t tmpfs tmpfs /run
169 x=/sbin/init; echo "[ -x $x ] && exec $x" >/run/init
170 $0 log 2>&1 | tee /run/boot.log
171 busybox umount /proc
172 busybox umount /sys
173 . /run/init
174 sh
175 fi
176 got modprobe && mod ${root//,/ }
177 [ -d /proc/sys/dev/cdrom ] &&
178 ln -s $(sed '/name/!d;s/.*:[^a-z]*//' /proc/sys/dev/cdrom/info) /dev/cdrom
179 if use dmraid; then
180 dmraid -s | sed '/^type/!ds/.*: *//' | ldraid
181 [ ${root:0:4} = /dev ] ||
182 root=/dev/mapper/$(dmraid -s|sed '/^name/!ds/.*: *//')p${root#p}
183 dmraid -ay
184 fi
185 use raiddev && raiddev="DEVICE ${root//,/ }"
186 use raidmail && raidmail="MAILADDR $root"
187 if use softraid; then
188 mdadm -E -s -c partitions > /etc/mdadm.conf
189 [ "$raiddev" ] && echo "$raiddev" >> /etc/mdadm.conf
190 [ "$raidmail" ] && echo "$raidmail" >> /etc/mdadm.conf
191 grep -qs " $root " /etc/mdadm.conf ||
192 root=$(awk '/dev.md/{print $2;exit}' < /etc/mdadm.conf)
193 grep level=raid /etc/mdadm.conf | ldraid
194 for i in 1 2 3 4 5 6 7 8 9; do
195 sleep $i
196 mdadm -A -s
197 grep -qs ': act' /proc/mdstat && break
198 done
199 lvm /etc/mdadm.conf
200 fi
201 lvm
202 if got mount; then
203 dev=$root
204 x=$(blkid|grep $dev|sed 's/:.*//;q')
205 root=${x:-$dev}
206 [ "$dev" = "$root" ] || dev="$root ($dev)"
207 echo "Mount $dev..."
208 mnt /mnt
209 arg posixovl && echo "And posixovl..." &&
210 mount.posixovl -F /mnt -- -oallow_other -odefault_permissions -osuid
211 fi
212 got loopfs && echo "Into file $root..." &&
213 losetup /dev/loop0 /mnt/$root && busybox mount /dev/loop0 /mnt
214 got bindfs && echo "Bind ${root/,/ to }..." &&
215 busybox mount --bind /mnt/${root%,*} /mnt/${root/,//}
216 arg cryptoroot= && try
217 if use subroot; then
218 cp $(LD_TRACE_LOADED_OBJECTS=1 /lib/ld*.so /usr/sbin/chroot | sed\
219 's|.*=> \(/lib/l[^ ]*\).*|\1|;/^\//!d') /usr/sbin/chroot /run
220 r=$root/run
221 quit $r "export LD_LIBRARY_PATH=$r:/lib"\
222 "$root$(ls /run/ld-*so) $r/chroot $root" "/$root"
223 fi
224 quit
225 msg tmpfs
226 root=100
227 got tmpram
228 r=$root
229 inodes=0
230 got rootfsinodes && inodes=$root
231 root=90%
232 got rootfssize
233 [ $(busybox free|busybox awk '/Mem:/{print int(($4*100)/$3)}') -ge $r ] &&
234 busybox mount -t tmpfs -o size=$root,nr_inodes=$inodes tmpfs /mnt &&
235 for i in $(ls -ar /); do
236 case "$i" in
237 .*|cdrom) ;;
238 mnt|proc|sys) mkdir /mnt/$i;;
239 usr|var|rootfs*) mv /$i /mnt;;
240 *) cp -a /$i /mnt 2>/dev/null && continue
241 fail
242 busybox umount /mnt
243 exit
244 esac
245 done || fail 3mSkipped
246 quit
247 mod squashfs 2>/dev/null || exit
248 msg aufs
249 br=/mnt/.rw
250 mkdir $br /mnt/.wd
251 got rwdev && mnt $br && br=$br$d
252 o=
253 p=
254 c=/mnt/.cdrom
255 if [ -z "$(ls /mnt/rootfs* 2>/dev/null)" ]; then
256 root=/dev/cdrom/fs
257 got rodev
258 mkdir -p $c /mnt$c /mnt/.rw$c
259 mnt $c
260 o="-o 124"
261 p=/.cdrom/boot
262 c=$c$d
263 fi
264 l=0
265 r=
266 got isofs && r=:$c || for i in /mnt$p/rootfs?*.gz; do
267 fs=${i#*root}
268 r=$r:/mnt/.$fs
269 mkdir -p /mnt/.rw/mnt/.$fs /mnt/.$fs
270 losetup $o /dev/loop$l $i
271 busybox mount -o ro -t squashfs /dev/loop$((l++)) /mnt/.$fs
272 done
273 while read type opt; do
274 mod $type && busybox mount -t $type -o $opt none /mnt && break
275 done <<EOT
276 aufs br=$br$r
277 overlayfs workdir=/mnt/.wd${r/:/,lowerdir=},upperdir=$br
278 EOT
279 quit