fdupoux / fsarchiver

file system archiver for linux
http://www.fsarchiver.org
GNU General Public License v2.0
249 stars 41 forks source link

I cannot restore an archive of a btrfs partition with two subvolumes to a new btrfs partition #108

Closed ramanzes closed 2 years ago

ramanzes commented 3 years ago

0)

[root@fedora vs]# parted /dev/sdb print

Model: VMware, VMware Virtual S (scsi) Disk /dev/sdb: 129GB Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags:

Number Start End Size Type File system Flags 1 1049kB 1075MB 1074MB primary ext4 2 1075MB 119GB 118GB primary btrfs


0.1)

[root@fedora vs]# ls -s /mnt/sdd1

total 49396396 16 lost+found 267180 sdc3_btrfs_boot.fsa 49129200 sdc3_btrfs_r_h.fsa

0.2)

[root@fedora vs]# parted /dev/sdc print

Model: VMware, VMware Virtual S (scsi) Disk /dev/sdc: 1000GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags:

Number Start End Size File system Name Flags 1 1049kB 630MB 629MB fat32 EFI System Partition boot, esp 2 630MB 1704MB 1074MB ext4 3 1704MB 120GB 118GB btrfs 4 120GB 1000GB 880GB ntfs msftdata

fsarchiver savefs /mnt/sdd1/sdc3_btrfs_r_h.fsa /dev/sdc3 -v -j 3

not error/ all ok


BUT NOW

2)

fsarchiver restfs /mnt/sdd1/sdc3_btrfs_r_h.fsa id=0,dest=/dev/sdb2 -v

_executing [mkfs.btrfs -f /dev/sdb2 -L 'fedora_localhost-live' -U 'fb4bec6b-ce77-4fe1-8ace-e53dbd5721cf' -s 4096 ]... command [mkfs.btrfs -f /dev/sdb2 -L 'fedora_localhost-live' -U 'fb4bec6b-ce77-4fe1-8ace-e53dbd5721cf' -s 4096 ] returned 1 fs_btrfs.c#106,btrfs_mkfs(): command [mkfs.btrfs -f /dev/sdb2 -L 'fedora_localhost-live' -U 'fb4bec6b-ce77-4fe1-8ace-e53dbd5721cf' -s 4096 ] failed oper_restore.c#1296,extractar_filesystemextract(): **cannot make filesystem btrfs on partition /dev/sdb2**

why does not it work, because even the sizes of the partitions are the same ... what else is missing?

ramanzes commented 3 years ago

Everything is fine. after shutting down the original disk from vmware (/dev/sdc). Because it is impossible to create a partition with the same UUID as on another disk

ramanzes commented 3 years ago

This does not work, the subvolumes remain tied to the old disk. attempting to mount them from the root of the target partition mounts a subvolume of the (source) block device. Somewhere there is a binding ... Without the original disk, nothing happens at all in this case.

fdisk -l

with source disk:

Disk /dev/sdc: 931.51 GiB, 1000204886016 bytes, 1953525168 sectors Disk model: VMware Virtual S Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: gpt Disk identifier: 6AADA02D-8736-4D03-9EC3-6C660FE5A488

Device Start End Sectors Size Type /dev/sdc1 2048 1230847 1228800 600M EFI System /dev/sdc2 1230848 3327999 2097152 1G Linux filesystem /dev/sdc3 3328000 234440703 231112704 110.2G Linux filesystem /dev/sdc4 234440704 1953523711 1719083008 819.7G Microsoft basic data

target disk:

Disk /dev/sdb: 120 GiB, 128849018880 bytes, 251658240 sectors Disk model: VMware Virtual S Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: gpt Disk identifier: ACBCB2B9-9B80-4B04-A268-1E1E896737CD

Device Start End Sectors Size Type /dev/sdb1 2048 2099199 2097152 1G Linux filesystem /dev/sdb2 2099200 237182975 235083776 112.1G Linux filesystem

[root@fedora vs]# mount /dev/sdb2 /mnt/sdb2

[root@fedora vs]# df -h

Filesystem Size Used Avail Use% Mounted on devtmpfs 1.9G 0 1.9G 0% /dev tmpfs 2.0G 0 2.0G 0% /dev/shm tmpfs 779M 1.9M 777M 1% /run /dev/sda2 20G 7.4G 11G 41% / tmpfs 2.0G 56K 2.0G 1% /tmp /dev/sda3 22G 222M 20G 2% /home /dev/sda1 976M 279M 630M 31% /boot tmpfs 390M 120K 390M 1% /run/user/1000 /dev/sdc3 111G 81G 31G 73% /mnt/sdb2 ??????????????????????? ????????????????????

[root@fedora vs]# btrfs subvolume list /mnt/sdb2

ID 256 gen 571248 top level 5 path home ID 257 gen 571274 top level 5 path root ID 265 gen 571268 top level 257 path root/var/lib/machines

why is it connecting sdc3? maybe binding by uuid somewhere in metadata ...?

if the original disk is physically removed from the machine, then the partition is mounted correctly,

[root@fedora vs]# mount /dev/sdb2 /mnt/sdb2 [root@fedora vs]# df -h

Filesystem Size Used Avail Use% Mounted on devtmpfs 1.9G 0 1.9G 0% /dev tmpfs 2.0G 0 2.0G 0% /dev/shm tmpfs 779M 1.9M 777M 1% /run /dev/sda2 20G 7.4G 11G 41% / tmpfs 2.0G 56K 2.0G 1% /tmp /dev/sda3 22G 222M 20G 2% /home /dev/sda1 976M 279M 630M 31% /boot tmpfs 390M 112K 390M 1% /run/user/1000 /dev/sdb2 113G 78G 35G 70% /mnt/sdb2

but subvolumes are not mounted without a physically attached source drive.

and are not even seen as subvolumes.

[root@fedora vs]# btrfs subvolume list /mnt/sdb2 ...empty.. [root@fedora vs]# ls /mnt/sdb2

home root

[root@fedora vs]# mount -o subvol=root /dev/sdb2 /mnt/r

mount: /mnt/r: wrong fs type, bad option, bad superblock on /dev/sdb2, missing codepage or helper program, or other error.

when the source disc is inserted, the subvolumes are mounted and displayed from the source disc

p.s. So far, I came to the conclusion that btrfs can now be correctly transferred only with the tools of btrfs itself through snapshots ... (2021)

marcosfrm commented 3 years ago

Please use proper markdown "code" blocks: put command output between ```blabla```.

Second, use findmnt -u /mountpoint.

Last time I tested Btrfs in FSArchiver, subvolumes were saved as plain directories...

marcosfrm commented 3 years ago

I could not make it work. btrfs.ko is very picky about mounting devices with same UUID. I think the only solution is restfs' uuid= option to create a new one:

newuuid=$(uuidgen)
fsarchiver restfs foo.fsa id=0,dest=/dev/sdx1,uuid=$newuuid

Then you mount the partition and if necessary configure stuff that requires the UUID using $newuuid.

fdupoux commented 2 years ago

Btrfs uses UUID to identify the different physical volumes which belong to the same logical file system, so it is not possible to copy btrfs file systems when it causes multiple btrfs file system to have to same UUID on the same machine. This is expected, and hence I confirm you have to make sure different file systems will have different UUIDs.