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