slitaz-modular view initramfs/init @ rev 1
Added tag 0.1-alpha for changeset 6d654d523ac8
author | Christopher Rogers <slaxemulator@gmail.com> |
---|---|
date | Thu Nov 25 03:32:42 2010 +0000 (2010-11-25) |
parents | |
children | d52e861c9970 |
line source
1 #!/bin/sh
3 launch_init()
4 {
5 echo -e "\\033[70G[ \\033[1;33mOK\\033[0;39m ]"
6 exec /sbin/switch_root mnt /sbin/init
7 }
9 launch_init_modular()
10 {
11 echo -e "\\033[70G[ \\033[1;33mOK\\033[0;39m ]"
12 exec /sbin/switch_root mnt /linuxrc
13 }
15 failed()
16 {
17 echo -e "\\033[70G[ \\033[1;31mFailed\\033[0;39m ]"
18 }
20 try_init()
21 {
22 if [ ! -d /mnt/etc ] && grep -q cryptoroot= /proc/cmdline; then
23 modprobe dm-mod
24 modprobe dm-crypt
25 modprobe aes-i586
26 root="$(sed 's/.*cryptoroot=\([^ ]*\).*/\1/' < /proc/cmdline)"
27 dev=${root#/dev/}
28 dmlabel=crypto-$dev
29 if cryptsetup isLuks $root 2> /dev/null; then
30 cryptsetup luksOpen $root $dmlabel
31 else
32 read -s -t 60 -p "Pass phrase : " passphrase
33 key=$(echo $passphrase | hashalot -x -n 32 sha512)
34 blocks=$(cat $(find /sys/block | grep /$dev/size))
35 echo 0 $blocks crypt aes-plain $key 0 $root 0 | \
36 dmsetup create $dmlabel
37 fi
38 mount /dev/mapper/$dmlabel /mnt
39 fi
40 if [ -d /mnt/etc ]; then
41 umount /sys
42 [ -n "$1" ] && for i in $@ ; do
43 cp -a $i /mnt$(dirname $i)
44 done
45 umount /proc
46 launch_init
47 fi
48 failed
49 }
51 mount_mapper()
52 {
53 mount $root /mnt
54 try_init /dev/mapper $@
55 }
57 lvmsetup()
58 {
59 if grep -q lvmroot= /proc/cmdline; then
60 modprobe dm-mod
61 vgscan --ignorelockingfailure
62 vgchange -ay --ignorelockingfailure
63 root="/dev/mapper/$(sed 's/.*lvmroot=\([^ ]*\).*/\1/' < /proc/cmdline)"
64 return 0
65 fi
66 return 1
67 }
69 load_raid()
70 {
71 while read line; do
72 case "$line" in
73 *raid10*) modprobe raid10 ;;
74 *raid0*) modprobe raid0 ;;
75 *raid1*) modprobe raid1 ;;
76 *raid[456]*) modprobe raid456 ;;
77 esac
78 done
79 }
81 mount -t proc proc /proc
82 mount -t sysfs sysfs /sys
83 if grep -q dmraid= /proc/cmdline; then
84 root="$(sed 's/.*dmraid=\([^ ]*\).*/\1/' < /proc/cmdline)"
85 echo -n "Switching / to dmraid $root..."
86 dmraid -s | grep ^type | awk '{ print $3 }' | load_raid
87 case "$root" in
88 /dev/*);;
89 *) root=/dev/mapper/$(dmraid -s|grep ^name|awk '{print $3}')p${root#p};;
90 esac
91 dmraid -ay
92 lvmsetup
93 mount_mapper
94 fi
95 if grep -q softraid= /proc/cmdline; then
96 root="$(sed 's/.*softraid=\([^ ]*\).*/\1/' < /proc/cmdline)"
97 echo -n "Switching / to softraid $root..."
98 mdadm --examine --scan --config=partitions > /etc/mdadm.conf
99 grep level=raid /etc/mdadm.conf | load_raid
100 mdadm --assemble --scan
101 lvmsetup
102 mount_mapper /etc/mdadm.conf
103 fi
104 if lvmsetup; then
105 echo -n "Switching / to lvm $root..."
106 mount_mapper
107 fi
108 if grep -q loopfs= /proc/cmdline; then
109 loopfs="$(sed 's/.*loopfs=\([^ ]*\).*/\1/' < /proc/cmdline)"
110 dev=${loopfs%,*}
111 loopfs=${loopfs#*,}
112 echo -n "Switching / to loop $loopfs on $dev..."
113 if ! mount $dev /mnt; then
114 if echo $dev | grep -q "/dev/sd"; then
115 delay=`cat /sys/module/usb_storage/parameters/delay_use`
116 delay=$((1+$delay))
117 echo -n "sleep for $delay seconds..."
118 sleep $delay
119 fi
120 mount $dev /mnt || loopfs=""
121 fi
122 if [ -n "$loopfs" ]; then
123 losetup /dev/loop0 /mnt/$loopfs
124 mount /dev/loop0 /mnt 2> /dev/null
125 fi
126 try_init
127 fi
128 grep -q cryptoroot= /proc/cmdline && try_init
129 umount /sys
130 echo -n "Switching / to tmpfs..."
131 size="$(grep rootfssize= < /proc/cmdline | \
132 sed 's/.*rootfssize=\([0-9]*[kmg%]\).*/-o size=\1/')"
133 free=$(busybox free | busybox awk '/Mem:/ { print int(($4*100)/$3) }')
134 umount /proc
135 [ -n "$size" ] || size="-o size=90%"
136 if [ $free -lt 100 ] || ! mount -t tmpfs $size tmpfs /mnt; then
137 echo -e "\\033[70G[ \\033[1;33mSkipped\\033[0;39m]"
138 exec /sbin/init
139 fi
140 for i in $(ls -a /); do
141 case "$i" in
142 .|..) ;;
143 mnt) mkdir /mnt/mnt;;
144 *) if ! cp -a /$i /mnt 2> /dev/null; then
145 failed
146 umount /mnt
147 exec /sbin/init
148 fi;;
149 esac
150 done
151 launch_init_modular