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