我注意到有时vgchange -a n [vgname]
似乎没有正确关闭卷组。这种情况最常发生,当我实际准备一个新系统时,我不知道是什么原因造成的。考虑以下磁盘结构(的输出lsblk -o name,fstype
)
NAME FSTYPE
/dev/sdx
+- /dev/sdx1 crypto_LUKS
| +- test_luks LVM2_member
| | +- test_lvm-test ext4
当我以正常方式(,等)打开所有这些东西时cryptsetup open ...
,vgchange -a y ...
做一些事情test_lvm-test
,然后用
umount [mountpoint of test_lvm-test]
vgchange -a n test_lvm
cryptsetup close test_luks
test_lvm
vgs
按预期从输出中消失。但是,如果我刚刚创建了这个结构(见下文重现),第一次安装它,然后以同样的方式关闭它,test_lvm
不会从vgs
. 相反,vgs
抱怨物理卷的设备“没有被过滤器找到或拒绝”。要从vgs
我必须重新打开test_luks
和删除错误test_lvm
,请再次禁用test_lvm
并再次关闭test_luks
。
为什么会这样?为什么LVM在第一次挂载时保留了test_lvm
after的句柄,但之后没有?vgchange -a n test_lvm; cryptsetup close test_luks
我能够像这样在 VirtualBox 中使用 Arch Linux Live CD“Arch Linux 5.2.5-arch1-1-ARCH”最一致地重现这种行为
# Let /dev/sdx1 be the partition to test this on
#
# Create LVM on LUKS with one ext4 volume
#
cryptsetup luksFormat --cipher aes-xts-plain64 --hash sha256 --label "Test (Encrypted)" /dev/sdx1
cryptsetup open /dev/sdx1 test_luks
pvcreate /dev/mapper/test_luks
vgcreate test_lvm /dev/mapper/test_luks
lvcreate --extents 100%FREE test_lvm --name test
mkfs.ext4 -L Test /dev/test_lvm/test
#
# Mount volume and write to it
#
mount /dev/test_lvm/test /mnt
echo "Hello World" > /mnt/test.txt
#
# Unmount everything
#
umount /mnt
vgchange -a n test_lvm
# -> 0 logical volume(s) in volume group "test_lvm" now active
cryptsetup close test_luks
#
# Check vgs
#
vgs
# -> Warning: Device for PV [uuid] not found or rejected by a filter.
# -> Warning: Device for PV [same uuid] not found or rejected by a filter.
# -> Couldn't find device with uuid [same uuid again].
# -> VG #PV #LV #SM Attr VSize VFree
# -> test_lvm 1 1 0 wz-pn- 492.00m 0
#
# Mount and unmount again
#
cryptsetup open /dev/sdx1 test_luks
vgs
# No error this time
vgchange -a n test_lvm
cryptsetup close test_luks
# test_lvm no longer listed in vgs and no errors.