wok-6.x annotate busybox/stuff/init @ rev 7844

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