wok-current view busybox/stuff/init @ rev 7752

Up: parcellite to 0.9.3.
author Christopher Rogers <slaxemulator@gmail.com>
date Mon Dec 20 23:30:17 2010 +0000 (2010-12-20)
parents a841d189e474
children 8135f4172a69
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 failed()
10 {
11 echo -e "\\033[70G[ \\033[1;31mFailed\\033[0;39m ]"
12 }
14 try_init()
15 {
16 if [ ! -d /mnt/etc ] && grep -q cryptoroot= /proc/cmdline; then
17 modprobe dm-mod
18 modprobe dm-crypt
19 modprobe aes-i586
20 root="$(sed 's/.*cryptoroot=\([^ ]*\).*/\1/' < /proc/cmdline)"
21 dev=${root#/dev/}
22 dmlabel=crypto-$dev
23 if cryptsetup isLuks $root 2> /dev/null; then
24 cryptsetup luksOpen $root $dmlabel
25 else
26 read -s -t 60 -p "Pass phrase : " passphrase
27 key=$(echo $passphrase | hashalot -x -n 32 sha512)
28 blocks=$(cat $(find /sys/block | grep /$dev/size))
29 echo 0 $blocks crypt aes-plain $key 0 $root 0 | \
30 dmsetup create $dmlabel
31 fi
32 mount /dev/mapper/$dmlabel /mnt
33 fi
34 if [ -d /mnt/etc ]; then
35 umount /sys
36 [ -n "$1" ] && for i in $@ ; do
37 cp -a $i /mnt$(dirname $i)
38 done
39 umount /proc
40 launch_init
41 fi
42 failed
43 }
45 mount_mapper()
46 {
47 mount $root /mnt
48 try_init /dev/mapper $@
49 }
51 lvmsetup()
52 {
53 if grep -q lvmroot= /proc/cmdline; then
54 modprobe dm-mod
55 vgscan --ignorelockingfailure
56 vgchange -ay --ignorelockingfailure
57 root="/dev/mapper/$(sed 's/.*lvmroot=\([^ ]*\).*/\1/' < /proc/cmdline)"
58 return 0
59 fi
60 return 1
61 }
63 load_raid()
64 {
65 while read line; do
66 case "$line" in
67 *raid10*) modprobe raid10 ;;
68 *raid0*) modprobe raid0 ;;
69 *raid1*) modprobe raid1 ;;
70 *raid[456]*) modprobe raid456 ;;
71 esac
72 done
73 }
75 mount -t proc proc /proc
76 mount -t sysfs sysfs /sys
77 if grep -q dmraid= /proc/cmdline; then
78 root="$(sed 's/.*dmraid=\([^ ]*\).*/\1/' < /proc/cmdline)"
79 echo -n "Switching / to dmraid $root..."
80 dmraid -s | grep ^type | awk '{ print $3 }' | load_raid
81 case "$root" in
82 /dev/*);;
83 *) root=/dev/mapper/$(dmraid -s|grep ^name|awk '{print $3}')p${root#p};;
84 esac
85 dmraid -ay
86 lvmsetup
87 mount_mapper
88 fi
89 if grep -q softraid= /proc/cmdline; then
90 root="$(sed 's/.*softraid=\([^ ]*\).*/\1/' < /proc/cmdline)"
91 echo -n "Switching / to softraid $root..."
92 mdadm --examine --scan --config=partitions > /etc/mdadm.conf
93 grep -qs " $root " /etc/mdadm.conf ||
94 root=$(awk '/dev.md/ { print $2; exit }' < /etc/mdadm.conf)
95 grep level=raid /etc/mdadm.conf | load_raid
96 mdadm --assemble --scan
97 lvmsetup
98 mount_mapper /etc/mdadm.conf
99 fi
100 if lvmsetup; then
101 echo -n "Switching / to lvm $root..."
102 mount_mapper
103 fi
104 if grep -q loopfs= /proc/cmdline; then
105 loopfs="$(sed 's/.*loopfs=\([^ ]*\).*/\1/' < /proc/cmdline)"
106 dev=${loopfs%,*}
107 loopfs=${loopfs#*,}
108 echo -n "Switching / to loop $loopfs on $dev..."
109 if ! mount $dev /mnt; then
110 if echo $dev | grep -q "/dev/sd"; then
111 delay=`cat /sys/module/usb_storage/parameters/delay_use`
112 delay=$((1+$delay))
113 echo -n "sleep for $delay seconds..."
114 sleep $delay
115 fi
116 mount $dev /mnt || loopfs=""
117 fi
118 if [ -n "$loopfs" ]; then
119 losetup /dev/loop0 /mnt/$loopfs
120 mount /dev/loop0 /mnt 2> /dev/null
121 fi
122 try_init
123 fi
124 grep -q cryptoroot= /proc/cmdline && try_init
125 if grep -q rootuuid= /proc/cmdline; then
126 root="$(sed 's/.*rootuuid=\([^ ]*\).*/\1/' < /proc/cmdline)"
127 mount $(blkid | grep $root | sed 's/:.*//') /mnt && try_init
128 fi
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