2009-01-15 01:07:55 +03:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2021-08-22 02:00:30 +03:00
|
|
|
# $NetBSD: lvm,v 1.8 2021/08/21 23:00:30 andvar Exp $
|
2009-01-15 01:07:55 +03:00
|
|
|
#
|
|
|
|
|
2009-04-21 20:08:57 +04:00
|
|
|
# PROVIDE: lvm
|
2021-08-03 08:15:20 +03:00
|
|
|
# REQUIRE: root devpubd
|
2009-04-21 20:08:57 +04:00
|
|
|
# BEFORE: DISKS
|
2009-01-15 01:07:55 +03:00
|
|
|
|
|
|
|
$_rc_subr_loaded . /etc/rc.subr
|
|
|
|
|
|
|
|
name="lvm"
|
|
|
|
rcvar=$name
|
|
|
|
start_cmd="lvm_start"
|
|
|
|
stop_cmd="lvm_stop"
|
|
|
|
|
2009-01-20 03:40:59 +03:00
|
|
|
ifs_restore="$IFS";
|
2009-01-15 01:07:55 +03:00
|
|
|
|
|
|
|
lvm_start()
|
|
|
|
{
|
2009-01-20 03:40:59 +03:00
|
|
|
if [ -x /sbin/dmsetup ]; then
|
|
|
|
/sbin/dmsetup version >/dev/null
|
2020-07-04 09:24:53 +03:00
|
|
|
if [ $? -ne 0 ]; then
|
2009-01-20 03:40:59 +03:00
|
|
|
warn "Device-mapper not present in kernel"
|
|
|
|
return 1;
|
|
|
|
fi
|
|
|
|
fi
|
2009-01-15 01:07:55 +03:00
|
|
|
|
2009-01-20 03:40:59 +03:00
|
|
|
if [ -x /sbin/lvm ]; then
|
|
|
|
echo "Configuring lvm devices."
|
2009-01-15 01:07:55 +03:00
|
|
|
|
|
|
|
# Scan for all available VG's
|
2009-01-20 03:40:59 +03:00
|
|
|
/sbin/lvm vgscan --mknodes --ignorelockingfailure >/dev/null
|
2020-07-04 09:24:53 +03:00
|
|
|
|
2021-08-22 02:00:30 +03:00
|
|
|
# Activate all LV's and create appropriate nodes in /dev
|
2009-01-15 01:07:55 +03:00
|
|
|
/sbin/lvm vgchange --ignorelockingfailure -a y >/dev/null
|
2009-03-05 13:35:43 +03:00
|
|
|
LV_LIST=$(/sbin/lvm vgdisplay -C -o vg_name --noheadings 2>/dev/null)
|
2009-01-20 03:40:59 +03:00
|
|
|
echo " Activated Volume Groups:" $LV_LIST
|
|
|
|
fi
|
2009-01-15 01:07:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
lvm_stop()
|
|
|
|
{
|
2009-01-20 03:40:59 +03:00
|
|
|
if [ -x /sbin/dmsetup ]; then
|
|
|
|
/sbin/dmsetup version >/dev/null
|
2020-07-04 09:24:53 +03:00
|
|
|
if [ $? -ne 0 ]; then
|
2009-01-20 03:40:59 +03:00
|
|
|
warn "Device-mapper not present in kernel"
|
|
|
|
return 1;
|
|
|
|
fi
|
|
|
|
fi
|
2009-01-15 01:07:55 +03:00
|
|
|
|
2009-01-20 03:40:59 +03:00
|
|
|
if [ -x /sbin/lvm ]; then
|
|
|
|
echo "Unconfiguring lvm devices."
|
2020-07-04 09:24:53 +03:00
|
|
|
|
2009-01-20 03:40:59 +03:00
|
|
|
LOGICAL_VOLUMES=$(/sbin/lvm lvdisplay -C -o vg_name,lv_name \
|
|
|
|
-O vg_name --separator \/ --noheadings 2>/dev/null)
|
|
|
|
VOLUME_GROUPS=$(/sbin/lvm vgdisplay -C -o vg_name \
|
|
|
|
--separator " " --noheadings 2>/dev/null)
|
|
|
|
|
|
|
|
for lv in ${LOGICAL_VOLUMES}; do
|
|
|
|
LV_IS_ACTIVE=$(/sbin/lvm lvdisplay -C --noheadings \
|
|
|
|
-o lv_attr $lv)
|
|
|
|
case $LV_IS_ACTIVE in
|
|
|
|
*a*)
|
|
|
|
echo " Shutting Down logical volume: ${lv}"
|
|
|
|
/sbin/lvm lvchange -an --ignorelockingfailure \
|
|
|
|
-P ${lv} >/dev/null
|
|
|
|
;;
|
|
|
|
esac
|
2009-01-15 01:07:55 +03:00
|
|
|
done
|
2020-07-04 09:24:53 +03:00
|
|
|
|
2009-01-20 03:40:59 +03:00
|
|
|
for vg in ${VOLUME_GROUPS}; do
|
|
|
|
# Set IFS to field separator
|
|
|
|
IFS=":"
|
|
|
|
set -- $(/sbin/lvm vgdisplay -cA ${vg} 2>/dev/null)
|
|
|
|
# The seventh parameter is number of opened LVs in a Volume Group
|
|
|
|
VG_HAS_ACTIVE_LV=$7
|
|
|
|
IFS="$ifs_restore";
|
2020-07-04 09:24:53 +03:00
|
|
|
|
2009-01-20 03:40:59 +03:00
|
|
|
if [ "${VG_HAS_ACTIVE_LV}" = 0 ]; then
|
|
|
|
echo " Shutting Down volume group: ${vg}"
|
|
|
|
/sbin/lvm vgchange -an --ignorelockingfailure \
|
|
|
|
-P ${vg} >/dev/null
|
|
|
|
fi
|
2009-01-15 01:07:55 +03:00
|
|
|
done
|
2009-01-20 03:40:59 +03:00
|
|
|
fi
|
2009-01-15 01:07:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
load_rc_config $name
|
|
|
|
run_rc_command "$1"
|