wok-4.x view busybox/stuff/init @ rev 4469
busybox/init: add raid support
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Mon Nov 09 17:17:30 2009 +0100 (2009-11-09) |
parents | 3c8195fabdd1 |
children | c5efd45ce56e |
line source
1 #!/bin/sh
3 mount_mapper()
4 {
5 mount $root /mnt
6 if [ -d /mnt/etc ]; then
7 umount /sys
8 for i in /dev/mapper $@ ; do
9 cp -a $i /mnt$i
10 done
11 umount /proc
12 echo -e "\\033[70G[ \\033[1;33mOK\\033[0;39m ]"
13 exec /sbin/switch_root mnt /sbin/init
14 fi
15 echo -e "\\033[70G[ \\033[1;31mFailed\\033[0;39m ]"
16 }
18 mount -t proc proc /proc
19 mount -t sysfs sysfs /sys
20 if grep -q dmraid= /proc/cmdline; then
21 root="$(sed 's/.*dmraid=\([^ ]*\).*/\1/' < /proc/cmdline)"
22 echo -n "Switching / to dmraid $root..."
23 case "$(dmraid -s | grep ^type | awk '{ print $3 }')" in
24 mirror) modprobe dm-mirror;;
25 raid[456]*) modprobe raid456;;
26 esac
27 name=$(dmraid -s | grep ^name | awk '{ print $3 }')
28 case "$root" in
29 /dev/*);;
30 p*) root=/dev/mapper/${name}$root ;;
31 *) root=/dev/mapper/${name}p$root ;;
32 esac
33 dmraid -ay
34 mount_mapper
35 elif grep -q softraid= /proc/cmdline; then
36 root="$(sed 's/.*softraid=\([^ ]*\).*/\1/' < /proc/cmdline)"
37 echo -n "Switching / to softraid $root..."
38 mdadm --examine --scan --config=partitions > /etc/mdadm.conf
39 grep level=raid /etc/mdadm.conf | while read line; do
40 case "$line" in
41 *=raid1\ *) modprobe dm-mirror ;;
42 *=raid[456]\ *) modprobe raid456 ;;
43 esac
44 done
45 mdadm --assemble --scan
46 mount_mapper /etc/mdadm.conf
47 fi
48 umount /sys
49 echo -n "Switching / to tmpfs..."
50 size="$(grep rootfssize= < /proc/cmdline | \
51 sed 's/.*rootfssize=\([0-9]*[kmg%]\).*/-o size=\1/')"
52 free=$(busybox free | busybox awk '/Mem:/ { print int(($4*100)/$3) }')
53 umount /proc
54 [ -n "$size" ] || size="-o size=90%"
55 if [ $free -lt 100 ] || ! mount -t tmpfs $size tmpfs /mnt; then
56 echo -e "\\033[70G[ \\033[1;33mSkipped\\033[0;39m]"
57 exec /sbin/init
58 fi
59 for i in $(ls -a /); do
60 case "$i" in
61 .|..) ;;
62 mnt) mkdir /mnt/mnt;;
63 *) if ! cp -a /$i /mnt 2> /dev/null; then
64 echo -e "\\033[70G[ \\033[1;31mFailed\\033[0;39m ]"
65 umount /mnt
66 exec /sbin/init
67 fi;;
68 esac
69 done
70 echo -e "\\033[70G[ \\033[1;33mOK\\033[0;39m ]"
71 exec /sbin/switch_root mnt /sbin/init