I’d read a few things about btrfs, and since the latest Ubuntu release (12.04 LTS) apparently supports having the root filesystem on btrfs, I decided to give it a whirl on my home server.
Here are the instructions, so that I remember how I did it next time. Anyone else reading this, feel free to make use of it, but I won’t be held responsible if you break your computer – there may well be errors, large or small :)
The first nice thing about btrfs is that it replaces the md software RAID tools, as well as completely replacing LVM. Neither are much fun to work with, and I shan’t miss them.
I have a Shuttle SH55J2 at home, with a couple of mismatched hard drives (160Gb and 1Tb) and 16Gb of RAM.
I decided to set up the drives like this:
/dev/sda1 = 160Gb partition for RAID-1
/dev/sdb1 = 160Gb partition for RAID-1
/dev/sdb2 = 840Gb non-redundant partition for downloads and storage of unimportant things
This gives me 160Gb for the basic OS which is mirrored across both drives, so even if a hard drive dies my computer will still work.
The other 840Gb I can use for messing around with virtual machines, temporary file share storage, etc.
No swap for now, because I have 16Gb of RAM.
First gotcha – the Ubuntu install process does not support setting up a btrfs RAID1 system. It will allow you to install to a btrfs partition, but only as DUP/RAID0.
The fix: once the installer gets to the screen where it asks you about partitioning, press Ctrl+Alt+F2 to get to a prompt, and set up the RAID manually:
1 2 3 | |
Then Ctrl+Alt+F1 and back to the installer, and select manual partitioning.
Select the btrfs partition at /dev/sda1 – choose btrfs, mount as ‘/’, bootable flag on, and DO NOT FORMAT. The installer will warn you about existing files on the disk, but you’ve only just created the filesystem so there is nothing there to worry about.
Under mount options, select ‘noatime’, we will add other options later (they’re not selectable from the installer).
The installer will automatically create two subvolumes, whether you like it or not – @ for the root FS, and @home for /home.
Once the install is done, you’ll reboot and be met with a scary warning message from grub:
1
| |
It tells you to press any key to continue, but it’ll actually continue by itself if you just wait and press nothing. Still annoying though, so we’ll fix that first.
It’s actually a known bug, listed here.
The fix – edit the file /etc/grub.d/00_header and comment out these six lines:
1 2 3 4 5 6 | |
becomes:
1 2 3 4 5 6 | |
Then:
1
| |
Reboot, and all should be well.
Now, we’ll add those extra mount options to /etc/fstab:
1 2 | |
The ‘noatime,subvol=XYZ’ part should have been there already – I added the ‘compress=lzo,space_cache,autodefrag,inode_cache’ to make it faster or set it on fire or something.
Finally, apply all of the above:
1 2 3 4 | |
Edit: As Mayank Bansal points out, btrfs’s defragment command is not recursive, so actually this does NOT apply compression to the files already installed.
Given the issues with manually defragmenting all the files after the install, I would probably wait for Ubuntu 12.10 or even 13.04, whichever is the first to fully support installing to a compressed btrfs volume.
Since btrfs also seems to be significantly slower than ext4, especially for larger files, I actually recommend sticking with ext4 for now.