原帖:
我已经使用命令备份了一个驱动器及其所有分区
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$