1 #!/bin/sh 2 # 3 # $NetBSD: lvm,v 1.3 2009/03/05 10:35:43 haad 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 ifs_restore="$IFS"; 16 17 lvm_start() 18 { 19 if [ -x /sbin/dmsetup ]; then 20 /sbin/dmsetup version >/dev/null 21 if [ $? -ne 0 ]; then 22 warn "Device-mapper not present in kernel" 23 return 1; 24 fi 25 fi 26 27 if [ -x /sbin/lvm ]; then 28 echo "Configuring lvm devices." 29 30 # Scan for all available VG's 31 /sbin/lvm vgscan --mknodes --ignorelockingfailure >/dev/null 32 33 # Activate all LV's and create apropriate nodes in /dev 34 /sbin/lvm vgchange --ignorelockingfailure -a y >/dev/null 35 LV_LIST=$(/sbin/lvm vgdisplay -C -o vg_name --noheadings 2>/dev/null) 36 echo " Activated Volume Groups:" $LV_LIST 37 fi 38 } 39 40 lvm_stop() 41 { 42 if [ -x /sbin/dmsetup ]; then 43 /sbin/dmsetup version >/dev/null 44 if [ $? -ne 0 ]; then 45 warn "Device-mapper not present in kernel" 46 return 1; 47 fi 48 fi 49 50 if [ -x /sbin/lvm ]; then 51 echo "Unconfiguring lvm devices." 52 53 LOGICAL_VOLUMES=$(/sbin/lvm lvdisplay -C -o vg_name,lv_name \ 54 -O vg_name --separator \/ --noheadings 2>/dev/null) 55 VOLUME_GROUPS=$(/sbin/lvm vgdisplay -C -o vg_name \ 56 --separator " " --noheadings 2>/dev/null) 57 58 for lv in ${LOGICAL_VOLUMES}; do 59 LV_IS_ACTIVE=$(/sbin/lvm lvdisplay -C --noheadings \ 60 -o lv_attr $lv) 61 case $LV_IS_ACTIVE in 62 *a*) 63 echo " Shutting Down logical volume: ${lv}" 64 /sbin/lvm lvchange -an --ignorelockingfailure \ 65 -P ${lv} >/dev/null 66 ;; 67 esac 68 done 69 70 for vg in ${VOLUME_GROUPS}; do 71 # Set IFS to field separator 72 IFS=":" 73 set -- $(/sbin/lvm vgdisplay -cA ${vg} 2>/dev/null) 74 # The seventh parameter is number of opened LVs in a Volume Group 75 VG_HAS_ACTIVE_LV=$7 76 IFS="$ifs_restore"; 77 78 if [ "${VG_HAS_ACTIVE_LV}" = 0 ]; then 79 echo " Shutting Down volume group: ${vg}" 80 /sbin/lvm vgchange -an --ignorelockingfailure \ 81 -P ${vg} >/dev/null 82 fi 83 done 84 fi 85 } 86 87 load_rc_config $name 88 run_rc_command "$1" 89