Thomas-Tsai / partclone

Partclone provides utilities to backup a partition smartly and it is designed for higher compatibility of the file system by using existing library.
GNU General Public License v2.0
306 stars 104 forks source link

Restored Btrfs partition not mountable #242

Open arnogon opened 7 months ago

arnogon commented 7 months ago

I backuped my memory card which contained 1 non-boot Btrfs partition with clonezilla-live-20230426-lunar-amd64 (partclone v0.3.23), and later restored it to the same card. After the restoration the partition is unmountable. I don't believe partclone showed any error when doing the backup.

This is the partclone command used:

partclone.btrfs -z 10485760 -N -L /var/log/partclone.log -c -s /dev/mmcblk0p1 --output - | zstdmt -c -3 > /home/partimag/2023-12-17-14-img/mmcblk0p1.btrfs-ptcl-img.zst 2> /tmp/img_out_err.81j5St

And this is the error message when trying to mount:

user@debian:~$ sudo mount /dev/mmcblk0p1 /media/user/mmcblk0p1
mount: /media/user/mmcblk0p1: can't read superblock on /dev/mmcblk0p1.
       dmesg(1) may have more information after failed mount system call.
Thomas-Tsai commented 7 months ago

Hi,

Could you also provide more information? Please let us know:

  1. Linux kernel
  2. The error message from dmesg
  3. The memory card type?

Some suggestions for you to fix the btrfs are:

  1. run fsck.btrfs
  2. btrfs scrub

We need more information and hope we can re-produce the same issue to fix the problem.

arnogon commented 7 months ago
  1. Linux kernel: 6.1.0-9-amd64
  2. dmesg error message
    [  404.019396] mmc0: cannot verify signal voltage switch
    [  404.174237] BTRFS info (device mmcblk0p1): using crc32c (crc32c-intel) checksum algorithm
    [  404.174256] BTRFS info (device mmcblk0p1): using free space tree
    [  404.188430] BTRFS info (device mmcblk0p1): bdev /dev/mmcblk0p1 errs: wr 0, rd 0, flush 0, corrupt 1, gen 0
    [  404.376594] BTRFS info (device mmcblk0p1): enabling ssd optimizations
    [  404.377304] BTRFS info (device mmcblk0p1): checking UUID tree
    [  404.378597] BTRFS critical (device mmcblk0p1): corrupt leaf: root=256 block=192339574784 slot=157 ino=1192291, invalid inode transid: has 23989 expect [0, 23971]
    [  404.378602] BTRFS error (device mmcblk0p1): read time tree block corruption detected on logical 192339574784 mirror 1
    [  404.379701] BTRFS critical (device mmcblk0p1): corrupt leaf: root=256 block=192339574784 slot=157 ino=1192291, invalid inode transid: has 23989 expect [0, 23971]
    [  404.379706] BTRFS error (device mmcblk0p1): read time tree block corruption detected on logical 192339574784 mirror 2
    [  404.380254] BTRFS critical (device mmcblk0p1): corrupt leaf: root=256 block=192339574784 slot=157 ino=1192291, invalid inode transid: has 23989 expect [0, 23971]
  3. Memory card type: SanDisk Extreme 512GB
  4. I got a bunch of errors with btrfs check :
    
    ref mismatch on [590504206336 131072] extent item 1, found 0
    data extent[590504206336, 131072] bytenr mimsmatch, extent item bytenr 590504206336 file item bytenr 0
    data extent[590504206336, 131072] referencer count mismatch (root 256 owner 1193734 offset 134012928) wanted 1 have 0
    backpointer mismatch on [590504206336 131072]
    owner ref check failed [590504206336 131072]
    ref mismatch on [590504337408 126976] extent item 1, found 0
    data extent[590504337408, 126976] bytenr mimsmatch, extent item bytenr 590504337408 file item bytenr 0
    data extent[590504337408, 126976] referencer count mismatch (root 256 owner 1193734 offset 140697600) wanted 1 have 0
    backpointer mismatch on [590504337408 126976]
    owner ref check failed [590504337408 126976]
    ref mismatch on [590504464384 126976] extent item 1, found 0
    data extent[590504464384, 126976] bytenr mimsmatch, extent item bytenr 590504464384 file item bytenr 0
    data extent[590504464384, 126976] referencer count mismatch (root 256 owner 1193734 offset 140828672) wanted 1 have 0
    backpointer mismatch on [590504464384 126976]
    owner ref check failed [590504464384 126976]
    ref mismatch on [590504591360 135168] extent item 1, found 0
    data extent[590504591360, 135168] bytenr mimsmatch, extent item bytenr 590504591360 file item bytenr 0
    data extent[590504591360, 135168] referencer count mismatch (root 256 owner 1193734 offset 142213120) wanted 1 have 0
    backpointer mismatch on [590504591360 135168]
    owner ref check failed [590504591360 135168]
    ERROR: errors found in extent allocation tree or chunk allocation
    [3/7] checking free space tree
    [4/7] checking fs roots
    parent transid verify failed on 192339574784 wanted 23952 found 23989
    Ignoring transid failure
    ERROR: root [256 0] level 0 does not match 2

ERROR: errors found in fs roots Opening filesystem to check... Checking filesystem on /dev/mmcblk0p1 UUID: 5690ec67-0e23-4592-a381-01432a8abbb0 found 386806038528 bytes used, error(s) found total csum bytes: 376931744 total tree bytes: 509050880 total fs tree bytes: 81920 total extent tree bytes: 100974592 btree space waste bytes: 34763056 file data blocks allocated: 5087232 referenced 9916416

And this was with ```--repair```

[1/7] checking root items Fixed 0 roots. [2/7] checking extents ref mismatch on [13631488 12288] extent item 1, found 0 data extent[13631488, 12288] bytenr mimsmatch, extent item bytenr 13631488 file item bytenr 0 data extent[13631488, 12288] referencer count mismatch (root 256 owner 414370 offset 0) wanted 1 have 0 backpointer mismatch on [13631488 12288] owner ref check failed [13631488 12288] parent transid verify failed on 192339574784 wanted 23952 found 23989 Ignoring transid failure ERROR: root [256 0] level 0 does not match 2

failed to repair damaged filesystem, aborting


5. I can't run ```btrfs scrub``` because the device can't be mounted now.
Thomas-Tsai commented 7 months ago

Hi, I did a small test on Ubuntu 22.04. I create 500 GB btrfs and then copy some files(300G) into btrfs. Creating another empty disk, and then I run partclone clone/restore. The result is good; all files' checksums are correct.

I will do more tests with Linux kernel 6.1.0-9-amd64 and USB disk.

arnogon commented 7 months ago

Thank you.

One clarification: I used different systems to backup/restore the data and to mount the memory card. The one I use for backup/restoring was clonezilla-live-20230426-lunar-amd64 (6.2.0-20-generic), and the one I used for mounting the memory card was 6.1.0-9-amd64.

Here are some additional information that might help:

  1. I used the same setup to backup and restore a Btrfs /home partition (~50GB/160GB used) on a SSD not long ago without any problem. The SSD and the memory card were used on the same machine; however, the /home partition was converted from ext4 while the partition on the memory card was formatted to Btrfs.
  2. This is what I see in GParted for my ummountable, restored memory card. I can see how much space is used. image
  3. This is the partclone command used according to clonezilla log
    partclone.btrfs -z 10485760 -N -L /var/log/partclone.log -c -s /dev/mmcblk0p1 --output - | zstdmt -c -3 > /home/partimag/2023-12-17-14-img/mmcblk0p1.btrfs-ptcl-img.zst 2> /tmp/img_out_err.81j5St
Thomas-Tsai commented 7 months ago

Hi, I have a new test with a physical hard drive, which is 500 GB (300GB data). The clone and restore results are acceptable without errors.

Could you restore the image to another device?

arnogon commented 7 months ago

Okay, I'll try that. I would note though that I tried partclone.restore --restore_raw_file to restore the .img file and mounted that, and I had the same "can't read superblock" error.

arnogon commented 7 months ago

I tried restoring the image on another device but got the same error when mounting it.