1 #!/bin/sh 2 # 3 # $NetBSD: lvm,v 1.1.2.2 2009/01/17 20:43:44 mjf Exp $ 4 # 5 6 # PROVIDE: disks 7 8 $_rc_subr_loaded . /etc/rc.subr 9 10 name="lvm" 11 rcvar=$name 12 start_cmd="lvm_start" 13 stop_cmd="lvm_stop" 14 15 dm_test() 16 { 17 if [ -x /sbin/dmsetup ]; then 18 /sbin/dmsetup version >/dev/null 19 20 if [ $? -ne 0 ]; then 21 echo "Device-mapper not present in kernel" 22 exit; 23 fi 24 fi 25 } 26 27 lvm_start() 28 { 29 dm_test; 30 31 if [ -x /sbin/lvm ]; then 32 echo "Configuring lvm devices." 33 34 # Scan for all available VG's 35 /sbin/lvm vgscan --mknodes --ignorelockingfailure >/dev/null 36 37 # Activate all LV's and create apropriate nodes in /dev 38 /sbin/lvm vgchange --ignorelockingfailure -a y >/dev/null 39 40 echo " Activated Volume Groups:"`/sbin/lvm vgdisplay -C -o vg_name --noheadings 2>/dev/null` 41 fi 42 } 43 44 lvm_stop() 45 { 46 dm_test; 47 48 if [ -x /sbin/lvm ]; then 49 echo "Deconfiguring lvm devices." 50 51 LOGICAL_VOLUMES=`/sbin/lvm lvdisplay -C -o vg_name,lv_name -O vg_name --separator \/ --noheadings 2>/dev/null` 52 VOLUME_GROUPS=`/sbin/lvm vgdisplay -C -o vg_name --separator " " --noheadings 2>/dev/null` 53 54 for x in ${LOGICAL_VOLUMES}; do 55 IFS=":" 56 set -- `/sbin/lvm lvdisplay -c` 57 # The fourth argument in the column LV display is inkernel flag 58 LV_IS_ACTIVE=$4; 59 unset IFS 60 61 if [ ${LV_IS_ACTIVE} -eq 1 ]; then 62 echo " Shutting Down logical volume: ${x} " 63 /sbin/lvm lvchange -an --ignorelockingfailure -P ${x} >/dev/null 64 fi 65 done 66 67 for x in ${VOLUME_GROUPS}; do 68 echo "VG -> |${x}|" 69 # Set IFS to field separator 70 IFS=":" 71 set -- `/sbin/lvm vgdisplay -cA ${x} 2>/dev/null` 72 # The seventh parameter is number of opened LVs in a Volume Group 73 VG_HAS_ACTIVE_LV=$7 74 unset IFS 75 76 if [ "${VG_HAS_ACTIVE_LV}" = 0 ] 77 then 78 echo " Shutting Down volume group: ${x}" 79 /sbin/lvm vgchange -an --ignorelockingfailure -P ${x} >/dev/null 80 fi 81 done 82 fi 83 } 84 85 load_rc_config $name 86 run_rc_command "$1" 87 88