15

Is it possible to convert btrfs to ext4 without losing data? I'm experiencing a very low speed on read/write operations on btrfs.

7

I'm just going on the available tools, not experience or documentation. You might want to test this with a partition (even just an image) you don't mind losing if it all goes wrong. Don't attempt this without taking a backup.

btrfs-convert has a roll-back function to undo a conversion. I'm not sure if this works for partitions that weren't converted to btrfs with btrfs-convert.

  1. Start by unmounting the filesystem. If it's essential to the system, boot into a LiveCD.

  2. Install btrfs-tools

    sudo apt-get install btrfs-tools
    
  3. Roll back the conversion

    sudo btrfs-convert -r /dev/sdXn
    
3
  • 6
    Note, that this will only work with converted filesystems and only if you haven't deleted the snapshot of the original ext3/4 filesystem. – htorque Apr 21 '11 at 15:19
  • Thank you but unfortunately this doesn't work for a btrfs partition not converted from other file systems. H guess I have to reinstall. – mFat Apr 23 '11 at 4:14
  • 9
    Be aware that this will discard any changes made on the filesystem since you converted it. It will be restored to the contents of the ext2/3 filesystem as it was before you converted. – poolie Jan 27 '12 at 9:07
3

As far as I know you cannot convert btrfs to any other filesystem.

1
  • 1
    not true if you converted ext to btrfs! you would have a snapshot to roll back the changes – Fookatchu Mar 21 '14 at 17:55
1

I did this using a system with multiboot distros (Ubuntu on ext4, Xubuntu on btrfs). Running Ubuntu, I have taken the Xubuntu btrfs home partition, and archived it using fsarchiver. I was then able to restore it, again using fsarchiver, to a different partition and specify ext4 filesystem type. That seemed to work okay.

Still in Ubuntu, I mounted the Xubuntu root partition on /mnt, and edited /mnt/@/etc/fstab to change the mount for /home to point to the new ext4 partition, changing both the UUID and the fs type, and deleting the subvolume data. I saved the file, and rebooted into Xubuntu.

There was an error in booting, and booting halted. The error was that I had another partition I wanted to mount to my ~/Documents directory which failed. I selected to manually fix the problem. It turns out that my root partition mounted okay as ext4, but when I did a list command I got

#ls /home
@home

So the original btrfs subvolume structure was still there in the ext4 filesystem. I issued the command

mount --bind /home/@home /home

I then pressed ctrl-D to continue booting, and Xubuntu continued booting and everything came up fine. I haven't done it yet, as I'm still on this initial boot, but I'm certain I could put that bind command in my fstab file. Or perhaps I could have left the subvolume info in the fstab entry, I don't know.

What I will do instead, however (this is off-topic), is take a more mature instance of a /home (ext4) partition for Xubuntu from another computer and use that instead. I've already proven that this will work.

0

The solution that works in all cases, is of course to copy everything from the root partition to a directory on another partition (assuming you have one with enough free space), reformat / as ext4, copy back. I just did that, and hit a few issues so I thought I'd write a little howto:

  • Boot on a rescue USB key, mount both partitions (let's say /mnt for the real root partition, and /dest for the partition serving as a temporary destination)
  • Beware that you should mount the BTRFS subvolumes too (I didn't do that, and I lost all of /var, /opt, /root...). The best way is probably to do the usual chroot dance (mount --bind /dev /mnt/dev; mount --bind /sys /mnt/sys; mount --bind /proc /mnt/proc; chroot /mnt) and then mount -a -t btrfs so that the subvolumes described in /etc/fstab are all mounted.
  • Exit the chroot or use another TTY (Ctrl+Alt+F2), and launch the copy, like cp -a /mnt /dest
  • Reformat the partition:
  • umount /mnt
  • mkfs.ext4 /dev/*the_root_device*
  • mount /dev/*the_root_device* /mnt
  • Copy back the data with cp -a /dest/mnt/* /mnt

And now (in the chroot) don't forget to

  • edit /etc/fstab to remove all subvolumes, change the filesystem type from btrfs to ext4, and update the UUID (see the output of blkid, or switch to a label like LABEL=rootfs after doing tune2fs -L rootfs /dev/*the_root_device*)
  • mkinitrd, and recreate the bootloader (I use another distro so I don't have the exact command for this step on ubuntu). Cross fingers and reboot. Finally, remember to clean up the /mnt copy in the temporary destination.

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.