slitaz-modular view initramfs/init @ rev 77

Fixed config file in core profile.
author Christopher Rogers <slaxemulator@gmail.com>
date Thu Apr 14 13:20:42 2011 +0000 (2011-04-14)
parents 7071725cd1cc
children ea6b229d8c84
line source
1 #!/bin/sh
3 launch_init()
4 {
5 [ -d /proc/sys ] && umount /proc
6 echo -e "\\033[70G[ \\033[1;33mOK\\033[0;39m ]"
7 exec /sbin/switch_root mnt /sbin/init
8 }
10 launch_init_modular()
11 {
12 [ -d /proc/sys ] && umount /proc
13 echo -e "\\033[70G[ \\033[1;33mOK\\033[0;39m ]"
14 [ -d /mnt/initramfs ] || mkdir -p /mnt/initramfs
15 SYS_DIR="dev bin etc boot lib sbin home root usr var"
16 for dir in $SYS_DIR; do
17 cp -a /$dir /mnt/initramfs
18 done
19 [ -f /mnt/dev/sdc ] || mknod /mnt/dev/sdc b 8 32
20 [ -f /mnt/dev/sdc1 ] || mknod /mnt/dev/sdc1 b 8 33
21 MK_DIR="sys proc tmp media mnt"
22 for dir1 in $MK_DIR; do
23 mkdir -p /mnt/initramfs/$dir1
24 done
25 exec /sbin/switch_root mnt /linuxrc
26 }
28 failed()
29 {
30 [ -d /proc/sys ] && umount /proc
31 echo -e "\\033[70G[ \\033[1;31mFailed\\033[0;39m ]"
32 }
34 try_init()
35 {
36 if [ ! -d /mnt/etc ] && grep -q cryptoroot= /proc/cmdline; then
37 modprobe dm-mod
38 modprobe dm-crypt
39 modprobe aes-i586
40 root="$(sed 's/.*cryptoroot=\([^ ]*\).*/\1/' < /proc/cmdline)"
41 dev=${root#/dev/}
42 dmlabel=crypto-$dev
43 if cryptsetup isLuks $root 2> /dev/null; then
44 cryptsetup luksOpen $root $dmlabel
45 else
46 read -s -t 60 -p "Pass phrase : " passphrase
47 key=$(echo $passphrase | hashalot -x -n 32 sha512)
48 blocks=$(cat $(find /sys/block | grep /$dev/size))
49 echo 0 $blocks crypt aes-plain $key 0 $root 0 | \
50 dmsetup create $dmlabel
51 fi
52 mount /dev/mapper/$dmlabel /mnt
53 fi
54 if [ -d /mnt/etc ]; then
55 umount /sys
56 [ -n "$1" ] && for i in $@ ; do
57 cp -a $i /mnt$(dirname $i)
58 done
59 mount /mnt -o remount,ro
60 launch_init
61 fi
62 failed
63 }
65 mount_mapper()
66 {
67 mount $root /mnt
68 try_init /dev/mapper $@
69 }
71 lvmsetup()
72 {
73 grep -q lvmroot= /proc/cmdline || return 1
74 modprobe dm-mod
75 vgscan --ignorelockingfailure
76 vgchange -ay --ignorelockingfailure
77 root="/dev/mapper/$(sed 's/.*lvmroot=\([^ ]*\).*/\1/' < /proc/cmdline)"
78 return 0
79 }
81 load_raid()
82 {
83 while read line; do
84 case "$line" in
85 *raid10*) modprobe raid10 ;;
86 *raid0*) modprobe raid0 ;;
87 *raid1*) modprobe raid1 ;;
88 *raid[456]*) modprobe raid456 ;;
89 esac
90 done
91 }
93 mount -t proc proc /proc
94 mount -t sysfs sysfs /sys
95 if grep -q dmraid= /proc/cmdline; then
96 root="$(sed 's/.*dmraid=\([^ ]*\).*/\1/' < /proc/cmdline)"
97 echo -n "Switching / to dmraid $root..."
98 dmraid -s | grep ^type | awk '{ print $3 }' | load_raid
99 case "$root" in
100 /dev/*);;
101 *) root=/dev/mapper/$(dmraid -s|grep ^name|awk '{print $3}')p${root#p};;
102 esac
103 dmraid -ay
104 lvmsetup
105 mount_mapper
106 fi
107 if grep -q softraid= /proc/cmdline; then
108 root="$(sed 's/.*softraid=\([^ ]*\).*/\1/' < /proc/cmdline)"
109 echo -n "Switching / to softraid $root..."
110 mdadm --examine --scan --config=partitions > /etc/mdadm.conf
111 grep -qs " $root " /etc/mdadm.conf ||
112 root=$(awk '/dev.md/ { print $2; exit }' < /etc/mdadm.conf)
113 grep level=raid /etc/mdadm.conf | load_raid
114 mdadm --assemble --scan
115 lvmsetup
116 mount_mapper /etc/mdadm.conf
117 fi
118 if lvmsetup; then
119 echo -n "Switching / to lvm $root..."
120 mount_mapper
121 fi
122 if grep -q mount= /proc/cmdline; then
123 root="$(sed 's/.*mount=\([^ ]*\).*/\1/' < /proc/cmdline)"
124 dev=$(blkid | grep $root | sed 's/:.*//;q')
125 echo -n "Mounting $dev ($root) ..."
126 if ! mount $dev /mnt; then
127 if echo $dev | grep -q "/dev/sd"; then
128 delay=`cat /sys/module/usb_storage/parameters/delay_use`
129 delay=$((1+$delay))
130 echo -n "sleep for $delay seconds..."
131 sleep $delay
132 fi
133 mount $dev /mnt
134 fi
135 fi
136 if grep -q loopfs= /proc/cmdline; then
137 loopfs="$(sed 's/.*loopfs=\([^ ]*\).*/\1/' < /proc/cmdline)"
138 echo -n "Switching / to loop $loopfs..."
139 losetup /dev/loop0 /mnt/$loopfs
140 mount /dev/loop0 /mnt 2> /dev/null
141 fi
142 grep -q cryptoroot= /proc/cmdline && try_init
143 umount /sys
144 if grep -q subroot= /proc/cmdline; then
145 subroot="/$(sed 's/.*subroot=\([^ ]*\).*/\1/' < /proc/cmdline)" &&
146 if [ -s /usr/share/boot/busybox-static ]; then
147 mv /usr/share/boot/busybox-static .
148 /busybox-static rm -rf /etc /lib /*bin /usr /var
149 exec /busybox-static chroot /mnt$subroot /sbin/init
150 else
151 exec chroot /mnt$subroot /sbin/init
152 fi
153 fi
154 echo -n "Switching / to tmpfs..."
155 size="$(grep rootfssize= < /proc/cmdline | \
156 sed 's/.*rootfssize=\([0-9]*[kmg%]\).*/-o size=\1/')"
157 free=$(busybox free | busybox awk '/Mem:/ { print int(($4*100)/$3) }')
158 umount /proc
159 [ -n "$size" ] || size="-o size=90%"
160 if [ $free -lt 100 ] || ! mount -t tmpfs $size tmpfs /mnt; then
161 echo -e "\\033[70G[ \\033[1;33mSkipped\\033[0;39m]"
162 exec /sbin/init
163 fi
164 for i in $(ls -a /); do
165 case "$i" in
166 .|..) ;;
167 mnt) mkdir /mnt/mnt;;
168 *) if ! cp -a /$i /mnt 2> /dev/null; then
169 failed
170 umount /mnt
171 exec /sbin/init
172 fi;;
173 esac
174 done
175 launch_init_modular