Btrfs in natty

After having followed the btrfs features and implementation progress for a while and following the btrfs integration done in natty I wanted to see how far the filesystem has progressed so far.

Note that while I consider btrfs usable, it’s still experimental and has it’s issues, so don’t cry if you don’t have backups of your data! (I do). It’s also a good idea to subscribe to the linux-btrfs malining list and join

Cool things:


One of the main points that attracted me to btrfs was the transparent compression, since that’s something what most other linux filesystems are missing.

Btrfs has supported gzip as compression for a while and 2.6.38 added lzo support to it (the mount option is compress=lzo), so I went and tried both.
The results were pretty much as I had read on the net: Phoronix, LWN.
Lzo uses almost no cpu time here and does give some space improvements, so unless you need the CPU time, I would probably use it by default wherever possible.
In the end I settled with gzip/zlib compression on both my EeePC 1000H and my Thinkpad T510. It does make the EeePC a bit slower a bit but I’m happy to have more disk space, on my Thinkpad it’s barely noticible.

One currently annoying thing is that you can’t really recompress data on an uncompressed FS once you mount it with compress. It should be possible with the defrag command, but that’s currently a bit tricky to use. This affects the installation process, as ubiquity doesn’t let you specify custom mount options, thankfully someone had a workaround for that already which is basically letting ubiquity run the partitioning, and once the partition is created, run:

sudo mount -o remount,compress /dev/sda1 /target

and voilá, all data will be compressed during the installation, after that just adjust the mount option in fstab and you’re set.
My Kubuntu 11.04 64-bit installation used only 1.6GB disk space after installation. 🙂


Really cool feature, esp. since I never really got around learning how to use LVM, ubiquity doesn’t support LVM, and in natty some work was done to integrate snapshotting into apt so we’ll have the possiblity to roll-back upgrades sometime in the future! Main point there is that ubiquity creates a @ (root) and @home subvolume by default if you choose btrfs for root in the advanced partitioning dialog in natty.

Using that, creating a snapshot of root is pretty trivial:

sudo mount /dev/sda1 /mnt

sudo btrfs subvolume snapshot /mnt/@ /mnt/@_snap

mounting /dev/sda1 without a subvol= option will mount the actual FS, so you can see the root subolume that’s usually invisible. Now you create a snapshot of root – @_snap – which behaves like any other subvolume except that it shares data with @.

Now while that is easy, actually using the new subvolume as root and throwing the changes to @ away took me a few trashed VMs to figure out, so here goes:

sudo mount /dev/sda1 /mnt

edit /mnt/@_snap/etc/fstab so it mounts @_snap as /,

reboot and change the kernel entry at the grub prompt so it uses the kernel and initramfs from @_snap, and set it to use @_snap as root. Once you’ve booted run

sudo update-grub

which will make sure grub.cfg now has the kernel entries from @_snap, now run

sudo grub-install /dev/sda

If you forget to do that, grub’s $prefix will stll show to (hd0,msdos1)/@/boot/grub, which we don’t want (see blow).
Now you can get rid of your old rootfs if you want to free some disk space:

sudo btrfs subvolume delete /mnt/@

now, if you didn’t run grub-install, $prefix would point still point to the deleted subvolume resulting in a “file not found” error and a grub rescue> prompt, so don’t forget that. (It’s what happened to me at least)

So, while making a snapshot is easy, you should know what you do if you plan to actually use it. The integration with update-manager and grub is planned to be improved in oneiric so this will get easier.

Some (currently) not so cool things (that you should know):


the btrfsck utility that’s currently shipped is pretty much useless, as it can’t actually fix any errors it finds, only report them. Also, it runs really slow on boot (8s on my thinkpad, 30 on my EeePC), so you usually want to delete the /sbin/fsck.btrfs symlink. A working btrfsck has been promised for a long time, though in February someone said the release is imminent, let’s hope for the best.


while btrfs supports TRIM, you don’t really want to use it currently, there’s a bug that resulted in every fsync() call taking over a second on my system. Now consider that dpkg calls fsync() several times per package and you can imagine the performance.


grub2 in natty doesn’t have lzo support, so you don’t want to use that for root currently without a seperate boot partition.


while btrfs already has some defragmentation support, the command only runs on files, not directories, so you need some shell magic to defragment the whole FS.

Launchpad bug 774217

not the fault of btrfs but it bit me on my eeePC when Installed without a boot partition.


Btrfs Homepage


4 thoughts on “Btrfs in natty

  1. Hi Yofel,
    great summary on the current status – I should have found this earlier. Currently I’m stuck @grub rescue prompt. I made a specific snapshot default (created by apt-snapshot-btrfs – which is a must in such configurations)….how did you recover from there?

    1. Case 1/2:
      If you’re in the same situation as I was in, running ‘set’ in the rescue promt should show the old subvolume:
      so set it to the right value first:
      > set prefix=(hd0,msdos1)/YOUR NEW SUBVOLUME/boot/grub
      > ls (hd0,msdos1)/
      you can list the available subvolumes first (assuming your system is on sda1)
      Now try to get to the normal boot menu:
      > insmod normal
      > normal
      Now you should be back to the usual grub menu where you can boot from.
      Case 2/2:
      You used ‘btrfs set-default’, in that case you could set the prefix to
      as the snapshots are hidden now, not sure if it’ll work and I haven’t found out yet how to access the now hidden subvolumes again.
      EDIT: (from #btrfs)
      darkling: You can mount the top-level subvolume (the original default) again with subvolid=0,
      darkling: and then use set-default to set it back to that top level.
      darkling: (You may have to use 5 instead of 0 — I think there might be a bug in there somewhere where 0 isn’t interpreted right)
      0 worked for me. with:
      sudo mount -o subvolid=0 /dev/sda1 /mnt
      sudo btrfs sub set-default /mnt/ /mnt/

  2. I was running in case 2/2 and it took some more attempts to figure out how to make the system boot again:
    insmod linux
    linux /vmlinuz root=/dev/sda <– setting this correctly I was running into severe btrfsck error, so I had to get into the initrd busybox – easiest way is specifying a wrong root disk
    initrd /initrd.img
    boot <– this will boot into initrd busybox
    mkdir /mnt <– maybe you don't need that but I didn't spend too much time figuring out the correct layout in the ubuntu initrd
    sudo mount -o subvolid=0 /dev/sda1 /mnt
    sudo /mnt/@/sbin/btrfs sub set-default /mnt/ /mnt/ <– no btrfs in initrd

    the system is boot now. The filesystems are mounted as expected. The only remaining problem is still a btrfsck problem. But this time "I"gnore works. This might not be the most elegant way, but it worked for me.
    Next step is to correct the btrfs errors – or reinstall.

  3. Why, oh why didn’t I read this post before installing Natty. Takes me 5 min to boot! I then started upgrading to Oneiric this morning. 10 hours in, and it now says there’s 12 hours left. Sigh…

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s