我在恢复我制作的加密文件系统备份时遇到了一些问题。备份是一个包含单个磁盘分区的 .img 文件。此分区是一个 luks 容器,其中驻留着一个逻辑卷组“vg-crypt”。在这个卷组中,我有两个逻辑卷,lv-crypt-root 和 lv-crypt-swap。
在我新安装的 Ubuntu 中,我按如下方式操作
cryptsetup luksOpen /media/lars/SHD/disk.img backup
密码....为了检查逻辑卷组是否被识别,我输入:
pvs
这告诉我:
PV VG Fmt Attr PSize PFree
/dev/mapper/backup vgcrypt lvm2 a-- 151,11g 196,00m
/dev/mapper/tphd vgtphd lvm2 a-- 151,11g 116,00m
到目前为止一切顺利,我的当前根卷(tphd 或 vgtphd)以及我的备份 vg(backup 或 vgcrypt)都被识别,现在让我们检查备份卷中的 lv:
lvdisplay /dev/vgcrypt
...
--- Logical volume ---
LV Path /dev/vgcrypt/lv-crypt-root
LV Name lv-crypt-root
VG Name vgcrypt
LV UUID Nc4vsK-IcqB-l2S1-iyIJ-rSOj-vzqt-osGcn5
LV Write Access read/write
LV Creation host, time ubuntu, 2013-06-19 10:40:44 +0200
LV Status suspended
# open 0
LV Size 147,12 GiB
Current LE 37663
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 252:5
--- Logical volume ---
LV Path /dev/vgcrypt/lv-crypt-swap
LV Name lv-crypt-swap
VG Name vgcrypt
LV UUID ExEizv-aHCn-ZG1Q-nqj5-jSQE-NKYG-2RKyVb
LV Write Access read/write
LV Creation host, time ubuntu, 2013-06-19 10:41:14 +0200
LV Status suspended
# open 0
LV Size 3,80 GiB
Current LE 973
..... bla bla
结论,lv是被认可的。
问题就从这里开始,我尝试挂载 lv:
mount /dev/vgcrypt/lv-crypt-root /mnt/lvm/
给我
mount: special device /dev/vgcrypt/lv-crypt-root does not exist
通过以下方式确保其处于活动状态:
vgchange -ay /dev/vgcrypt
我懂了:
device-mapper: resume ioctl on failed: Invalid argument
Unable to resume vgcrypt-lv--crypt--root (252:5)
device-mapper: resume ioctl on failed: Invalid argument
Unable to resume vgcrypt-lv--crypt--swap (252:6)
2 logical volume(s) in volume group "vgcrypt" now active
我完全不知道这意味着什么,所以我开始谷歌搜索,发现也许我应该使用 vgexport 导出未激活的 vg,如下所示:
vgchange -an /dev/vgcrypt
Attempted to decrement suspended device counter below zero.
Attempted to decrement suspended device counter below zero.
0 logical volume(s) in volume group "vgcrypt" now active
和
vgexport vgcrypt
Volume group "vgcrypt" has active logical volumes
对我来说这似乎很矛盾。
有人能给我指明正确的方向吗?任何帮助都将不胜感激 :)
PS 刚刚检查了系统日志,看起来相关但对我来说没有多大意义:
(过滤掉所有 wifi 信息:)
cat /var/log/syslog | grep kernel | grep -v wlan | grep -v cfg80211 | tail -n 40 | cut -f 5-90 -d " "
kernel: [58297.025013] device-mapper: table: 252:8: linear: dm-linear: Device lookup failed
kernel: [58297.025023] device-mapper: ioctl: error adding target to table
kernel: [58297.026024] device-mapper: table: 252:8: linear: dm-linear: Device lookup failed
kernel: [58297.026030] device-mapper: ioctl: error adding target to table
kernel: [58297.026901] device-mapper: table: 252:8: linear: dm-linear: Device lookup failed
kernel: [58297.026907] device-mapper: ioctl: error adding target to table
kernel: [58297.077530] device-mapper: multipath: version 1.5.1 loaded
kernel: [59654.867358] device-mapper: table: 252:5: dm-7 too small for target: start=2048, len=308535296, dev_size=284453912
kernel: [59654.867994] device-mapper: table: 252:6: dm-7 too small for target: start=308537344, len=7970816, dev_size=284453912
kernel: [59655.179856] device-mapper: table: 252:5: dm-7 too small for target: start=2048, len=308535296, dev_size=284453912
kernel: [59655.180623] device-mapper: table: 252:6: dm-7 too small for target: start=308537344, len=7970816, dev_size=284453912
kernel: [59776.851223] device-mapper: table: 252:5: dm-7 too small for target: start=2048, len=308535296, dev_size=284453912
kernel: [59776.851860] device-mapper: table: 252:6: dm-7 too small for target: start=308537344, len=7970816, dev_size=284453912
kernel: [59777.149049] device-mapper: table: 252:5: dm-7 too small for target: start=2048, len=308535296, dev_size=284453912
kernel: [59777.149561] device-mapper: table: 252:6: dm-7 too small for target: start=308537344, len=7970816, dev_size=284453912
kernel: [60837.153424] device-mapper: table: 252:5: dm-7 too small for target: start=2048, len=308535296, dev_size=284453912
kernel: [60837.154789] device-mapper: table: 252:6: dm-7 too small for target: start=308537344, len=7970816, dev_size=284453912
kernel: [61508.827915] device-mapper: table: 252:5: dm-7 too small for target: start=2048, len=308535296, dev_size=284453912
kernel: [61508.831243] device-mapper: table: 252:6: dm-7 too small for target: start=308537344, len=7970816, dev_size=284453912
kernel: [61514.020906] device-mapper: table: 252:5: dm-7 too small for target: start=2048, len=308535296, dev_size=284453912
kernel: [61514.021532] device-mapper: table: 252:6: dm-7 too small for target: start=308537344, len=7970816, dev_size=284453912
kernel: [61514.311394] device-mapper: table: 252:5: dm-7 too small for target: start=2048, len=308535296, dev_size=284453912
kernel: [61514.311906] device-mapper: table: 252:6: dm-7 too small for target: start=308537344, len=7970816, dev_size=284453912
答案1
LVM 未打开您的 LV,这在输出中已经很明显了lvdisplay
(已暂停)。设备映射器系统日志输出还有一些其他详细信息:两个设备无法激活,因为它们的一个组件丢失;另外两个设备无法激活,因为支持设备太小。后面的消息具有与失败的 vgchange 匹配的设备编号。
我猜你的备份图像被截断了。
获取更多信息:
sudo vgchange --refresh
sudo pvs --partial --verbose
sudo lvs --partial --segments -o+devices vgcrypt/lv-crypt-root
sudo blockdev --getsize64 /dev/mapper/backup
sudo pvdisplay --units=b /dev/mapper/backup
第一个命令强制重新读取存储在 PV 上的 VG 元数据,第二个命令列出所有 PV(包括任何缺失的 PV),第三个命令提供有关 LV 和数据所在位置的更详细信息。最后两个命令比较 PV 的预期大小和实际大小。
答案2
我通过以下步骤解决了这个问题:
- 检查物理分区(即 /dev/sda5)的大小(parted)是否小于 lvm 物理卷(PV)(pvscan)
- 禁用 lvm
pvchange -an
- 使用 fdisk -l,记下每个分区的起始块
- 使用 fdisk 删除分区(即 /dev/sda5)并写入更改
- 使用 fdisk 创建一个相同类型(主分区、逻辑分区)的新分区,从与前一个分区完全相同的块开始,并以比以前更远的块结束(如果您可以将整个磁盘放在它后面),然后将类型更改为 Linux LVM(8e),将更改写入磁盘
- 按照步骤 1 检查尺寸
- 启用 lvm
pvchange -ay