Using BTRFS for the storage partition

Using BTRFS on flash cards
Converting the /storage-partition on your SD-card might help with issues where OE does not correctly wake up from stand-by. Using sd cards attached to USB or an internal SD-card-reader seems to cause problems with Linux. After waking up, the kernel finds issues with the filesystem and mounts it read-only, causing OE to malfunction. BTRFS offers features which can prevent this issue.

Warning: The filesystem „btrfs“ is quite solid, but the developers consider it to be experimental. The stability is good, but you may get into trouble when downgrading from OE3 to OE2, as the old kernel might not be able to mount the partition successfully. New kernels implement new features, and while there is always upward compatibility, there is no guarantee of downward compatibility.

Prerequisites: I use a stick-distro „Parted Magic“ as my universal solution for partition work, be it conversion, resizing or backup. Parted Magic fits onto a small USB-stick (512MB is enough), and it uses the newest stable kernel, so it keeps pace with the development in the filesystems. You might use any other Linux-distribution for the tasks which I describe, but it must include gparted and the btrfs-tools.

The easiest way to use Parted Magic is to download „unetbootin“, a small assistant for Windows or Linux which can automatically download and put Parted Magic onto a usb stick. Unetbootin can be found at http://unetbootin.sourceforge.net/

The following screenshots were taken on a VMware player, because it allows screenshots in a convenient way. The same steps can be performed directly on your htpc.

1.) Boot your HTPC from Parted Image, either from USB-stick or CD/DVD.

Parted Magic offers a menu, choose Option 1 or 2. There is no real advantage in using 64 bit, but it’s a habit ;-) Non-english users can change into „+ Language“ and load the software with their preferred keyboard layout, e.g. german or french.



2.) Booting parted magic takes a while...



After a minute or so, the PartedMagic-desktop appears. You are ready to go.

3.) Now, you need to determine the correct drive. The SD-card is usually /dev/sda or /dev/sdb. Start „Partition Editor“ (a fancy name for gparted).



4.) You switch between the physical devices in the upper right corner. Find the device that shows two partitions, „System“ and „Storage“. On my virtual machine, this turned out to be /dev/sdc. We want to convert the Storage-partition, which is /dev/sdc2. Take careful note of this name!



5.) Now, we get to do real business.

Start „Roxterm“ at the bottom of the window. Any other Terminal like xTerm or Terminal will work equally well.



6.) In Roxterm:

- Convert the partition with

btrfs-convert /dev/sdc2

- Now, we set the partitions mount options to ssd. This is important to reduce wear on flash-storage devices. Otherwise, btrfs will try to defragment itself periodically, causing lots of wear on the device. Activating the option is stored in the partition, so it is still in effect in OE after a reboot.

mount /dev/sdc2 –o ssd

- Type mount to see if the setting was applied successfully. Note the folder where sdc2 was mounted. It’s usually in /media/sdc2.



7.) Required clean-up:

Btrfs-convert creates a snapshot of the partition’s state at conversion time. This is great, but we need to get rid of it as it will eat up our drivespace.

- First, list the snapshot’s name with

btrfs subvolume list /media/sdc2

The name is usually „ext2_saved“.

- Second, change into the directory where sdc2 was mounted with

cd /media/sdc2

- Third, tell btrfs to delete the subvolume (snapshot) with

btrfs subvolume delete ext2_saved



That's it. You can reboot into OE and enjoy your favourite movies or music. :-)

Keep in mind that it's not advisable to access this partition from older Linuxkernels. BTRFS has been around since kernel 2.6.29, but it has been rewritten over the years. A volume is always upwards compatible, but using it with a new kernel will upgrade the structure.