I'm attempting to install Arch Linux using the btrfs filesystem. I'm at the beginning of the install processes preparing my drive and I'm hitting an issue.

Firstly I begin to clear any GTP and MBR records from any previous installation attempts using:

gdisk /dev/sda

I then go into expert mode using x command and then use z to remove GTP and/or MBR.

I then use fdisk to create a new partition using the entire space on the drive - which is 119GB.

After creating the partition, and writing it, I then attempt to create the filesystem using:

mkfs.btrfs /dev/sda1

But I get an error:

/dev/sda1 appears to contain an existing filesystem (btrfs)

How is this so? All I have done is created a partition, so how can btrfs already exist as the filesystem type?

  • 1
    Just a hint: btrfs supports ditching the MBR/GPT and formatting the entire drive (instead of just certain partitions) with btrfs: wiki.archlinux.org/index.php/Btrfs#Partitioning – n.st May 8 '14 at 16:42
  • I was hesitant to call it ideal because it will prevent you from having any FAT, NTFS or Swap partitions (and I haven't tried the whole-disk thing myself yet). But if you don't need those, it should be fine. – n.st May 8 '14 at 16:56

Using dd we can wipe the partition table. I remember having success with dd while failing with gdisk's zero feature. (Make sure that you have your data backed up).

# dd if=/dev/zero of=/dev/sda bs=512 count=1024
  • Worked. Although I'm going to run with using btrfs on the entire drive instead of partitioning. I will mark as the solution though because it did work when I tried it. – James Jeffery May 8 '14 at 16:51
  • You aren't just wiping the partition table there (and that wouldn't be relevant anyway), you're also wiping the beginning of the first partition (in disk order), and thus wiping the beginning of the btrfs filesystem that was already there. – Gilles 'SO- stop being evil' May 8 '14 at 22:47

When you create a partition, it contains whatever was there before. For example, if you delete a partition that contained a filesystem and recreate a partition at exactly the same location without having written to that space in between, then you'll get the filesystem that was there before, intact. If the new partition starts at the same location as the old one but is larger, you can keep using the filesystem or (if the filesystem supports it) extend it to fill up the extra space. If the new partition is smaller, you can keep using the filesystem — but you need to have shrunk it to the new partition size before removing the old partition.

So here you have a filesystem, or maybe just the beginning of a filesystem, left over from a partition that started at the same location. Many versions of mkfs refuse to overwrite what appears to be an existing filesystem, because it's often a sign that you specified the wrong partition and an error could be catastrophic. If you want to overwrite an existing filesystem, you need to wipe part of it first, enough to make it unrecognizable. Linux comes with the wipefs utility to do that.

wipefs /dev/sda1

Zeroing enough bytes (say, a couple of megabytes) at the beginning of the partition tends to have the same effect.

  • on centos 7 I had to use the -a switch: wipefs -a /dev/sda to wipe the gpt label from a device. With a label btrfs filesystem will complain about existing filesystem as stated in the question – Chrisii Mar 18 '15 at 21:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.