Converting ext4 to btrfs

Hi,
I’ve decided to open a new thread because I’ve some questions to the possibility of converting my existing install of EnOS from ext4 to btrfs.
Basically I’m starting with a very simple installation: I’ve a single drive (1Tb) with a 100Gb / and the rest of the disk for /home. The EFI partition is on another drive that also contains Windows 10.
As far as I know btrfs works with subvolumes on a single partition (am I right?) so how can I convert? Also, right now I’m on a ext4 filesystem and I use the computer basically for home stuff, rendering (blender) gaming and ROM development. I would like to switch filesystem basically for the snapshot ability of btrfs, but I would like to know if it as a decremental effects the permeance in a way that could impact my use case. I’ve read a bit but I’m not sure if it will be noticeable or not.

Thanks for your time.

1 Like

Dead easy - pick btrfs as the filesystem when you install. Job done.

2 Likes

How about that?
:stuck_out_tongue_winking_eye:

I think what the above posters are getting at is…conversion to btrfs on a root filesystem is…not trivial. Unless you’re trying to do this as an academic exercise in how you could convert an existing ext4 install to btrfs, you’re going to be much better served by a reinstall on btrfs.

Not trivial but should be doable according to:

https://wiki.archlinux.org/title/Btrfs#Ext3/4_to_Btrfs_conversion

A bit involved but not that much, at least “in theory”. I don’t have any EXT4 system at the moment (not that much time either for that matter) but I would definitely try this at some point as an academic exercise as you say.

I’ve done this conversion a couple of times, and it wasn’t worth the time and effort - not only do you need to make sure you have 50%+ free space, the copying of data takes a long time, and even then various BTRFS features won’t be set up in the same way as with a fresh filesystem.

3 Likes

Perhaps the procedure of converting a root filesystem is better suited for a fresh install when BTRFS is not supported by the installer of a certain distro as @dalto said in another thread.

You actually can have multiple separately managed btrfs partitions with subvolumes in both. However, in most(but not all) cases this doesn’t make a lot of sense as you lose the ability of btrfs to share the space between them. In order to give you more specific advice, we would need to know how much free space you have on each partition and how your partitions are laid out on the disk.

There is definitely a small raw performance hit when you compare ext4 to btrfs. In most cases, it won’t be noticeable for desktop use cases but every situation is different so I couldn’t guarantee it.

If you have the space, it is pretty easy from my perspective. What do you find non-trivial about it?

Like any major filesystem operation, it comes with risks and you should backup your data first. As these things go, I think it is pretty straightforward.

You definitely need the free space, yes.

Unless you have a large amount of data and/or slow disks, converting the system will probably take less time than reinstalling and reconfiguring an entire system. Especially if it a long running system with lots of config.

Of course, you could always move the partitions around and use rsync to move the filesystems if you prefer.

Interesting. Which features are missing in this scenario? I usually run btrfs defrag afterwards to compress all the data.

Thanks everyone for the answer.

As I was thinking, so I need to reinstall the system to have only one partition right? And in that case, would you (or anyone else) suggest maybe to use zfs instead of btrfs? I’ve eared wonders of it but i find the installation processes a little daunting (I don’t really have much experience with different filesystems)

here my df output for the /dev/sda (stripped of tmpfs)

Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/sda1      ext4       96G   34G   58G  37% /
/dev/nvme0n1p1 vfat      463M  101M  362M  22% /efi
/dev/sda2      ext4      820G  134G  645G  18% /home

/dev/sda1 is / and /dev/sda2 /home.
Also in / I can reduce the space occupied by half because I’ve a snapshot taken that occupy roughly 50% of the used space.
As you can see I’ve 134Gb occupied in /home (android source code is huge!) and that was one of the things why I would prefer to not have to download it all again.

Nope. Although merging the two partitions makes it quite a bit more complicated.

Hmm…as a zfs advocate, I always thing it is a good idea to use zfs. That being said, there are a few things to consider:

  • The installer doesn’t support zfs so you will have to do something fairly elaborate to end up with a zfs on root EOS install.
  • zfs requires an investment of time to understand how it works and how to tune it.
  • zfs requires special handling on an ongoing basis since it uses out of tree modules to work.

There are tons of different ways you can do this. Here are a few:

  1. You could convert in-place. Level of difficulty - Moderate
    • Convert /dev/sda2 to btrfs
    • Take a snapshot of it named @home and the delete the old data
    • Mount @home as /home
    • Create a subvolume @
    • rsync the data from / to @
    • Remount @ in /etc/fstab with the correct options
    • Modify your kernel command line in /etc/default/grub and run grub-mkconfig
    • Run mkinitcpio -P to ensure you have btrfs support in your initram
    • Reboot and fix anything that is now broken
  2. You could reinstall but preserve /home, then migrate /home. Level of difficulty - Low
    • Shrink your home partition as much as possible and expand your root partition
    • Install into the root partition as btrfs and mount your existing /home partition without formatting it
    • Create a subvolume @home
    • rsync the contents of /home to @home
    • Remount @home as /home and change /etc/fstab to match
    • Delete the partition /dev/sda2
    • Expand the btrfs partition into the empty space
  3. You could reinstall. Level of difficulty - Low
    • Delete /dev/sda1 and /dev/sda2
    • Create one large partition on /dev/sda and install into it

No matter which option you choose, you should ensure you have a backup of the data you care about.

If it was me, I would go with option #1 because it looks more fun. For someone who is looking for less of a challenge, option #2 is actually a lot easier than it sounds from those steps.

2 Likes

Option #1 was the one I was leaning to myself. Only I’ve switched from grub to systemd-boot so I don’t know if I’ve to do something in there to make it work or not, but I’ll look into it and see.

mmm, ok, that’s seems a little (read very) much complicated for my use case and time, even if I’ll like to try it, so sadly I think I’ll skip that. Maybe trying it in a VM first and then see.
Side question tho: btrfs need those “special care” too or not?

I can help there. Are you using kernel-install or manually managing your entries?

Nope.

Thanks a lot, I’m manually managing the entries (only one really because windows is automatically added by systemd-boot)

In that case, you edit the entries, verify the device is correct(or change it) and add subvol=@ to the options line instead of etc/default/grub

Also, make sure you have an EOS/arch iso available to boot from. Some of those steps may require chrooting. Even if you can do it without chrooting, if you make any mistakes or forget anything you will probably need a chroot to fix it.

EDIT: I probably should point out that the second option is much, much easier and less risky since you don’t need to manually modify your root partition.

Ok thanks. I’ll think of what to do then. Keep the thread open for a bit so that if I need any assistance will ask directly here. Thank for the help and the really insightful explanation.

2 Likes

Ok, I’ve decided for a reinstall, one simple question:
if I use a single partition (the all disk) how can I divide the root and home subvolumes during the installation fase? or I’ve to create does afterwards (in that case I think I’ll need a little help)?

By default, the installer creates 4 subvolumes

  • @ - /
  • @home - /home
  • @cache - /var/cache
  • @log = /var/log

If you want something different than that, you can either edit the calamares config files prior to install or just change it afterwards.

1 Like

Really I think this 4 are ok. So I only have to choose my entire volume formatted in btrfs and it will detect and done everything correctly right?
Thanks a lot :grin:

Yes, set that partition as / if you are using manual partitioning

1 Like

Is this a new feature? I don’t think it created any when I tried BTRFS on a fresh install a few months back.