wok-6.x rev 5978

busybox: add lvm support in /init
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Aug 12 18:56:16 2010 +0200 (2010-08-12)
parents d9c510a41649
children e3e1af50a0a5
files busybox/stuff/init
line diff
     1.1 --- a/busybox/stuff/init	Thu Aug 12 10:09:15 2010 +0200
     1.2 +++ b/busybox/stuff/init	Thu Aug 12 18:56:16 2010 +0200
     1.3 @@ -6,6 +6,11 @@
     1.4  	exec /sbin/switch_root mnt /sbin/init
     1.5  }
     1.6  
     1.7 +failed()
     1.8 +{
     1.9 +	echo -e "\\033[70G[ \\033[1;31mFailed\\033[0;39m ]"
    1.10 +}
    1.11 +
    1.12  try_init()
    1.13  {
    1.14  	if [ ! -d /mnt/etc ] && grep -q cryptoroot= /proc/cmdline; then
    1.15 @@ -34,7 +39,7 @@
    1.16  		umount /proc
    1.17  		launch_init
    1.18  	fi
    1.19 -	echo -e "\\033[70G[ \\033[1;31mFailed\\033[0;39m ]"
    1.20 +	failed
    1.21  }
    1.22  
    1.23  mount_mapper()
    1.24 @@ -43,37 +48,55 @@
    1.25  	try_init /dev/mapper $@
    1.26  }
    1.27  
    1.28 +lvmsetup()
    1.29 +{
    1.30 +if grep -q lvmroot= /proc/cmdline; then
    1.31 +	modprobe dm-mod
    1.32 +	vgscan --ignorelockingfailure
    1.33 +	vgchange -ay --ignorelockingfailure
    1.34 +	root="/dev/mapper/$(sed 's/.*lvmroot=\([^ ]*\).*/\1/' < /proc/cmdline)"
    1.35 +	return 0
    1.36 +fi
    1.37 +return 1
    1.38 +}
    1.39 +
    1.40 +load_raid()
    1.41 +{
    1.42 +while read line; do
    1.43 +	case "$line" in
    1.44 +	*raid1*)	modprobe dm-mirror ;;
    1.45 +	*raid[456]*)	modprobe raid456 ;;
    1.46 +	esac
    1.47 +done
    1.48 +}
    1.49 +
    1.50  mount -t proc proc /proc
    1.51  mount -t sysfs sysfs /sys
    1.52  if grep -q dmraid= /proc/cmdline; then
    1.53  	root="$(sed 's/.*dmraid=\([^ ]*\).*/\1/' < /proc/cmdline)"
    1.54  	echo -n "Switching / to dmraid $root..."
    1.55 -	case "$(dmraid -s | grep ^type | awk '{ print $3 }')" in
    1.56 -	mirror)		modprobe dm-mirror;;
    1.57 -	raid[456]*)	modprobe raid456;;
    1.58 -	esac
    1.59 -	name=$(dmraid -s | grep ^name | awk '{ print $3 }')
    1.60 +	dmraid -s | grep ^type | awk '{ print $3 }' | load_raid
    1.61  	case "$root" in
    1.62  	/dev/*);;
    1.63 -	p*) root=/dev/mapper/${name}$root ;;
    1.64 -	*)  root=/dev/mapper/${name}p$root ;;
    1.65 +	*) root=/dev/mapper/$(dmraid -s|grep ^name|awk '{print $3}')p${root#p};;
    1.66  	esac
    1.67  	dmraid -ay
    1.68 +	lvmsetup 
    1.69  	mount_mapper
    1.70  fi
    1.71  if grep -q softraid= /proc/cmdline; then
    1.72  	root="$(sed 's/.*softraid=\([^ ]*\).*/\1/' < /proc/cmdline)"
    1.73  	echo -n "Switching / to softraid $root..."
    1.74  	mdadm --examine --scan --config=partitions > /etc/mdadm.conf
    1.75 -	grep level=raid /etc/mdadm.conf | while read line; do
    1.76 -		case "$line" in
    1.77 -		*=raid1\ *)	modprobe dm-mirror ;;
    1.78 -		*=raid[456]\ *)	modprobe raid456 ;;
    1.79 -		esac
    1.80 -	done
    1.81 +	grep level=raid /etc/mdadm.conf | load_raid
    1.82  	mdadm --assemble --scan
    1.83 +	lvmsetup 
    1.84  	mount_mapper /etc/mdadm.conf
    1.85  fi
    1.86 +if lvmsetup; then
    1.87 +	echo -n "Switching / to lvm $root..."
    1.88 +	mount_mapper
    1.89 +fi
    1.90  if grep -q loopfs= /proc/cmdline; then
    1.91  	loopfs="$(sed 's/.*loopfs=\([^ ]*\).*/\1/' < /proc/cmdline)"
    1.92  	dev=${loopfs%,*}
    1.93 @@ -111,7 +134,7 @@
    1.94  	.|..)	;;
    1.95  	mnt)	mkdir /mnt/mnt;;
    1.96  	*)	if ! cp -a /$i /mnt 2> /dev/null; then
    1.97 -			echo -e "\\033[70G[ \\033[1;31mFailed\\033[0;39m ]"
    1.98 +			failed
    1.99  			umount /mnt
   1.100  			exec /sbin/init
   1.101  		fi;;