原始帖子:
我使用以下命令备份了驱动器及其所有分区
dd if=/dev/sda of=/media/oshirowanen/external-drive/backups-2019/ubuntu.img
/dev/sda
是安装了 Ubuntu 18.04 并具有完整加密功能的 SSD。
在我擦除此驱动器并重新利用它之前,我想确保备份已经起作用。
我通过搜索 askubuntu 和其他 stackexchange 网站尝试了以下操作:
sudo losetup -P /dev/loop0 /media/oshirowanen/external-drive/backups-2019/ubuntu.img
[sudo] password for oshirowanen: [password goes here]
losetup: /media/oshirowanen/external-drive/backups-2019/ubuntu.img: failed to set up loop device: Device or resource busy
sudo losetup -P /dev/loop100 /media/oshirowanen/external-drive/backups-2019/ubuntu.img
sudo cryptsetup luksOpen /dev/loop100p5 img5
Enter passphrase for /dev/loop100p5: [password goes here]
cd /mnt
mkdir img5
sudo mount /dev/mapper/img5 img5
mount: /mnt/img5: unknown filesystem type 'LVM2_member'.
我做错什么了?cryptsetup
和lvm2
都已安装。
如果这不是备份驱动器的最佳方法,请建议其他更好的方法。
更新 1:
oshirowanen@desktop:~$ sudo pvscan
[sudo] password for oshirowanen:
WARNING: PV udJ9tW-vls3-YQOz-cLkW-lTsh-DMCF-zrfLD0 on /dev/mapper/img5 was already found on /dev/mapper/sda5_crypt.
WARNING: Disabling lvmetad cache which does not support duplicate PVs.
WARNING: Not using lvmetad because duplicate PVs were found.
WARNING: PV udJ9tW-vls3-YQOz-cLkW-lTsh-DMCF-zrfLD0 on /dev/mapper/img5 was already found on /dev/mapper/sda5_crypt.
WARNING: PV udJ9tW-vls3-YQOz-cLkW-lTsh-DMCF-zrfLD0 prefers device /dev/mapper/sda5_crypt because device is used by LV.
PV /dev/mapper/sda5_crypt VG ubuntu-vg lvm2 [232.16 GiB / 0 free]
Total: 1 [232.16 GiB] / in use: 1 [232.16 GiB] / in no VG: 0 [0 ]
oshirowanen@desktop:~$ sudo vgscan
WARNING: PV udJ9tW-vls3-YQOz-cLkW-lTsh-DMCF-zrfLD0 on /dev/mapper/img5 was already found on /dev/mapper/sda5_crypt.
WARNING: Disabling lvmetad cache which does not support duplicate PVs.
WARNING: Not using lvmetad because duplicate PVs were found.
Reading all physical volumes. This may take a while...
WARNING: PV udJ9tW-vls3-YQOz-cLkW-lTsh-DMCF-zrfLD0 on /dev/mapper/img5 was already found on /dev/mapper/sda5_crypt.
WARNING: PV udJ9tW-vls3-YQOz-cLkW-lTsh-DMCF-zrfLD0 prefers device /dev/mapper/sda5_crypt because device is used by LV.
Found volume group "ubuntu-vg" using metadata type lvm2
oshirowanen@desktop:~$ sudo vgs
WARNING: Not using lvmetad because duplicate PVs were found.
WARNING: Use multipath or vgimportclone to resolve duplicate PVs?
WARNING: After duplicates are resolved, run "pvscan --cache" to enable lvmetad.
WARNING: PV udJ9tW-vls3-YQOz-cLkW-lTsh-DMCF-zrfLD0 on /dev/mapper/img5 was already found on /dev/mapper/sda5_crypt.
WARNING: PV udJ9tW-vls3-YQOz-cLkW-lTsh-DMCF-zrfLD0 prefers device /dev/mapper/sda5_crypt because device is used by LV.
VG #PV #LV #SN Attr VSize VFree
ubuntu-vg 1 2 0 wz--n- 232.16g 0
oshirowanen@desktop:~$ sudo lvs
WARNING: Not using lvmetad because duplicate PVs were found.
WARNING: Use multipath or vgimportclone to resolve duplicate PVs?
WARNING: After duplicates are resolved, run "pvscan --cache" to enable lvmetad.
WARNING: PV udJ9tW-vls3-YQOz-cLkW-lTsh-DMCF-zrfLD0 on /dev/mapper/img5 was already found on /dev/mapper/sda5_crypt.
WARNING: PV udJ9tW-vls3-YQOz-cLkW-lTsh-DMCF-zrfLD0 prefers device /dev/mapper/sda5_crypt because device is used by LV.
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root ubuntu-vg -wi-ao---- <231.21g
swap_1 ubuntu-vg -wi-ao---- 980.00m
oshirowanen@desktop:~$ ls /dev/mapper/
control img5 sda5_crypt ubuntu--vg-root ubuntu--vg-swap_1
oshirowanen@desktop:~$
更新2:
ubuntu@ubuntu:~$ sudo losetup -P /dev/loop100 /media/ubuntu/external-drive/backups-2019/ubuntu.img
ubuntu@ubuntu:~$ sudo cryptsetup luksOpen /dev/loop100p5 img5
Enter passphrase for /dev/loop100p5:
ubuntu@ubuntu:~$ cd /mnt
ubuntu@ubuntu:/mnt$ sudo mkdir img5
ubuntu@ubuntu:/mnt$ sudo mount /dev/mapper/img5 img5
mount: /mnt/img5: unknown filesystem type 'LVM2_member'.
ubuntu@ubuntu:/mnt$ sudo pvscan
PV /dev/mapper/img5 VG ubuntu-vg lvm2 [232.16 GiB / 0 free]
Total: 1 [232.16 GiB] / in use: 1 [232.16 GiB] / in no VG: 0 [0 ]
ubuntu@ubuntu:/mnt$ sudo vgscan
Reading volume groups from cache.
Found volume group "ubuntu-vg" using metadata type lvm2
ubuntu@ubuntu:/mnt$ sudo vgs
VG #PV #LV #SN Attr VSize VFree
ubuntu-vg 1 2 0 wz--n- 232.16g 0
ubuntu@ubuntu:/mnt$ sudo lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root ubuntu-vg -wi-a----- <231.21g
swap_1 ubuntu-vg -wi-a----- 980.00m
ubuntu@ubuntu:/mnt$ ls /dev/mapper/
control img5 ubuntu--vg-root ubuntu--vg-swap_1
ubuntu@ubuntu:/mnt$
答案1
这里您得到的是 LUKS + LVM,您正在做的是解锁 LUKS 加密分区,然后尝试挂载 LVM 物理卷。这是错误的,您应该将逻辑卷挂载在您的卷组上ubuntu-vg
。
sudo mount /dev/mapper/ubuntu--vg-root /mnt
摘要:
Backup file: /media/ubuntu/external-drive/backups-2019/ubuntu.img
Accessible as a loop device at: /dev/loop100
Unlocked on: /dev/mapper/img5
PV: /dev/mapper/img5
VG: ubuntu-vg
LV: ubuntu-vg/root
LV Location: /dev/mapper/ubuntu--vg--root