我尝试在启动 Debian Squeeze 系统时挂载 LVM 卷。由于某种原因,LVM 卷/组默认处于非活动状态,因此需要先激活它们才能进行任何挂载。此外,我的卷所属的卷组位于另一个物理 LVM 卷上。因此,我不能使用默认的/etc/init.d/lvm2
init 脚本,而是编写了自己的脚本,该脚本首先激活第一级 LVM 卷,然后激活我想要挂载的卷:
~# cat /etc/init.d/lvm2_vtt
#!/bin/sh
### BEGIN INIT INFO
# Provides: lvm2_vtt
# Required-Start: mountdevsubfs udev
# Required-Stop:
# Should-Start: mdadm-raid cryptdisks-early multipath-tools-boot
# Should-Stop: umountroot mdadm-raid
# Default-Start: S
# Default-Stop: 0 6
# X-Start-Before: checkfs mountall
# X-Stop-After: umountfs
### END INIT INFO
SCRIPTNAME=/etc/init.d/lvm2_vtt
. /lib/lsb/init-functions
[ -x /sbin/vgchange ] || exit 0
do_start()
{
echo "bla"> /root/hah
modprobe dm-mod 2> /dev/null || :
/sbin/vgscan --ignorelockingfailure --mknodes || :
/sbin/vgchange -aly --ignorelockingfailure || return 2
/sbin/vgscan
/sbin/vgchange -ay
/sbin/lvmdiskscan
/sbin/vgscan
/sbin/vgchange -ay agvtt-volume
}
do_stop()
{
/sbin/vgchange -aln --ignorelockingfailure || return 2
/sbin/vgchange -an agvtt-volume
}
case "$1" in
start)
log_begin_msg "Setting up LVM Volume Groups"
do_start
case "$?" in
0|1) log_end_msg 0 ;;
2) log_end_msg 1 ;;
esac
;;
stop)
log_begin_msg "Shutting down LVM Volume Groups"
do_stop
case "$?" in
0|1) log_end_msg 0 ;;
2) log_end_msg 1 ;;
esac
;;
restart|force-reload)
;;
*)
echo "Usage: $SCRIPTNAME {start|stop}" >&2
exit 3
;;
esac
该脚本有效,我可以手动执行它,它可以完成所有应该做的事情。我使用update-rc.d lvm2_vtt defaults
which works 激活它(尽管它抱怨某些运行级别不匹配):
~# ls -g /etc/rcS.d
total 4
-rw-r--r-- 1 root 447 Mar 24 2012 README
lrwxrwxrwx 1 root 24 Oct 23 12:18 S01mountkernfs.sh -> ../init.d/mountkernfs.sh
lrwxrwxrwx 1 root 14 Oct 23 12:18 S02udev -> ../init.d/udev
lrwxrwxrwx 1 root 26 Oct 23 12:18 S03mountdevsubfs.sh -> ../init.d/mountdevsubfs.sh
lrwxrwxrwx 1 root 18 Oct 23 12:18 S04bootlogd -> ../init.d/bootlogd
lrwxrwxrwx 1 root 18 Mar 1 11:26 S04lvm2_vtt -> ../init.d/lvm2_vtt
lrwxrwxrwx 1 root 21 Oct 23 12:18 S05hostname.sh -> ../init.d/hostname.sh
lrwxrwxrwx 1 root 25 Oct 23 12:18 S05hwclockfirst.sh -> ../init.d/hwclockfirst.sh
lrwxrwxrwx 1 root 22 Oct 23 12:18 S06checkroot.sh -> ../init.d/checkroot.sh
lrwxrwxrwx 1 root 20 Oct 23 12:18 S07hwclock.sh -> ../init.d/hwclock.sh
lrwxrwxrwx 1 root 24 Oct 23 12:18 S07ifupdown-clean -> ../init.d/ifupdown-clean
lrwxrwxrwx 1 root 27 Oct 23 12:18 S07module-init-tools -> ../init.d/module-init-tools
lrwxrwxrwx 1 root 17 Oct 23 12:18 S07mtab.sh -> ../init.d/mtab.sh
lrwxrwxrwx 1 root 20 Oct 23 12:18 S08checkfs.sh -> ../init.d/checkfs.sh
lrwxrwxrwx 1 root 18 Oct 23 12:18 S09ifupdown -> ../init.d/ifupdown
lrwxrwxrwx 1 root 21 Oct 23 12:18 S09mountall.sh -> ../init.d/mountall.sh
....
因此,我的 init 脚本在之前执行mountall
,它应该挂载 fstab 条目。我的 fstab 现在如下所示:
~# cat /etc/fstab
# the local partitions
proc /proc proc defaults 0 0
UUID=07791c3e-5388-4edc-b30f-a4b4f2dbcb33 none swap sw 0 0
UUID=6522596a-210d-47ab-8894-e6259ffd99ee / ext3 defaults 0 1
# our lvm volumes, secured and unsecured. Get the uuids using blkid.
UUID=66a66e81-9eb8-4ce8-a370-f3a48ece289e /space/secured xfs defaults 0 0
UUID=9e74cbd4-d3a0-4047-8466-74c00c14542a /space/unsecured xfs defaults 0 0
# these are simpler aliases
/space/unsecured /unsecured bind bind 0 0
/space/secured /secured bind bind 0 0
如您所见,首先挂载 LVM 卷(xfs 文件系统),然后为不同的位置创建一些绑定。
我现在看到的是,启动后 LVM 卷既未激活,也未正确安装。(它们不能处于非活动状态。)
我在这里遗漏了什么?