1

I have a failing hard disk drive, which contains a partition forming part of my root filesystem:

matt@ryzen3950 ~> btrfs device stats /dev/dm-2
[/dev/mapper/cryptsda1].write_io_errs    0
[/dev/mapper/cryptsda1].read_io_errs     0
[/dev/mapper/cryptsda1].flush_io_errs    0
[/dev/mapper/cryptsda1].corruption_errs  12
[/dev/mapper/cryptsda1].generation_errs  0

I have another storage device that I'd like to replace this one with. To do this, I first partitioned and encrypted my new drive:

matt@ryzen3950 ~> sudo parted /dev/sdd
(parted) mklabel gpt                                                      
(parted) mkpart primary btrfs 1MiB 100%                                   
(parted) quit                                                             
matt@ryzen3950 ~> sudo cryptsetup luksFormat /dev/sdd1
matt@ryzen3950 ~> sudo cryptsetup open --type luks /dev/sdd1 cryptsdd1

(I did not perform any mkfs on this)

Then, I attempted to perform btrfs replace (note, this filesystem is currently live):

sudo btrfs replace start /dev/mapper/cryptsda1 /dev/mapper/cryptsdd1 /

However, I get the error:

/dev/mapper/cryptsdd1 appears to contain a partition table (atari).
ERROR: use the -f option to force overwrite of /dev/mapper/cryptsdd1

This makes it sound like I should not have partitioned the drive first. Should I have done the following instead?

sudo btrfs replace start /dev/sda /devsdd /

If not, what's the correct way to do this?

Finally, what is <path> in btrfs replace? I believe it's the filesystem mount point (e.g., / on a live root filesystem). Is this correct?

I read the full btrfs-replace manpage as well as the btrfs wiki, but was not able to find the answers to my questions.

1 Answer 1

0

However, I get the error:

/dev/mapper/cryptsdd1 appears to contain a partition table (atari).
ERROR: use the -f option to force overwrite of /dev/mapper/cryptsdd1

Just run the btrfs command with -f as suggested or run wipefs -a /dev/mapper/cryptsdd1 first.

You are actually hitting a known issue in libblkid (already fixed with newest util-linux), library which is used for detecting filesystems on devices and most storage tools use it -- btrfs is using it here to make sure the device you are trying to use is empty so it can warn users to not remove an existing filesystem by accident. In this case libblkid wrongly thinks the newly created LUKS device contains atari partition table, this is a false positive it just thinks some random data is atari superblock.

This makes it sound like I should not have partitioned the drive first. Should I have done the following instead?

sudo btrfs replace start /dev/sda /devsdd /

Definitely not, btrfs only cares about the filesystem level, it doesn't "know" about the underlying partitions and LUKS devices, recreating those first is the right thing to do.

Finally, what is <path> in btrfs replace? I believe it's the filesystem mount point (e.g., / on a live root filesystem). Is this correct?

I'm not btrfs expert, but I think this is correct and the first version of your btrfs replace command looks ok to me. Definitely make a backup first.

3
  • I saw the -f flag but was reluctant to use it without knowing it was the right choice. Is it ok that there is currently no btrfs filesystem on the decrypted partition? Should I have done a mkfs.btrfs first?
    – MattHusz
    Jun 26, 2021 at 18:23
  • From your suggestion to perform wipefs, I imagine I was not supposed to perform mkfs.btrfs first. Running that command and then using the original btrfs replace command above (without -f) appears to be working.
    – MattHusz
    Jun 26, 2021 at 18:34
  • Yes, I think the device should be empty. wipefs basically removes the "fake" atari partition table so btrfs is no longer complaining. Running commands with the force option can be scary but here btrfs complained about the newly created /dev/mapper/cryptsdd1 so it was safe. Jun 26, 2021 at 18:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .