A Btrfs field test and workshop

In the Hot Seat

Hard Linking Limited

If you rely heavily on hard linking when creating backups, you need to bear in mind one of the peculiarities of Btrfs: It allows only a very limited number of hard links to a single file within a directory. The Release Notes for SUSE Linux Enterprise Server 11 SP2 refer to 150 hard links being permitted in production [5]. Again, significant improvements can be expected in the future.

If you can do without a full snapshot of a subvolume and only need snapshots of individual files, Btrfs also has an answer. Space-saving COW clones of files are created with:

cp --reflink <C><I>SOURCE DEST<C><I>

This is a practical method, for example, of cloning a disk image for a virtual machine.

Rollback

A typical application for this simple, flexible, and cheap way of creating snapshots can also take the worries out of system updates: a complete rollback after package installations. openSUSE and the SUSE Enterprise Server offer snapper [6] for this purpose, whereas Fedora and Oracle Linux versions provide the Yum plugin yum-plugin-fs-snapshot with Btrfs support. Current Debian and Ubuntu distributions offer apt-btrfs-snapshot.

All of these programs use hooks in the respective package managers to create a snapshot of the subvolume on which the system is installed, before installing new packages or updates. After a failed update, this process lets you take a quick step backward to a working configuration. You can run the package manager manually or perform an automatic update as a cron job to install the current security fixes regularly.

Of course, this approach assumes you installed the operating system on Btrfs or that you use the btrfs-convert program to convert existing ext3 or ext4 filesystems to Btrfs. This migration variant even includes the option of returning to the original filesystem if necessary. The only prerequisite for this conversion is sufficient free space on the original filesystem for both the data of the old system and the copy on the new Btrfs system.

During this process, Btrfs stores the first megabyte at the beginning of the device at an alternate position, builds its own metadata, and references the data blocks on the ext3/4 filesystem. At the end of the process, you have a snapshot of the original data. New metadata and data are written by Btrfs at free locations on the hard drive so that none of the blocks of the original filesystem are lost. As long as the snapshot of the original ext3/4 filesystem exists, you can revert. However, you will lose all changes since the conversion. GRUB 2 (since 1.99-rc2) also lets you boot from a Btrfs filesystem; you don't need an extra partition for /boot with an alternative filesystem.

Fast and Painless

A successful conversion of the root filesystem begins with a reboot in a rescue environment, such as the one you find on an Ubuntu installation CD. But, this does not give you the btrfs-convert command. Therefore, before rebooting the system, you should copy it to /boot, which is usually a partition of its own. After changing the entry for the root filesystem in /etc/fstab from ext4 to btrfs, the only thing missing for a successful restart is a successful conversion.

After booting the rescue environment, you can mount the boot partition, instead of the root filesystem, to access the conversion tool. Next, perform a fsck of the original filesystem, followed by the conversion itself and a restart of the converted system (Figure 8).

Figure 8: A filesystem check followed by the conversion of the filesystem from ext4 to Btrfs. This process is fast and painless, at least for a filesystem with little data.

After starting the system, the newly converted Btrfs superficially looks fairly inconspicuous as the root filesystem. Closer inspection shows that a lot of things have happened (Figure 9). The striking feature of this converted filesystem is also the lack of metadata redundancy.

Figure 9: The Btrfs filesystem converted from ext4 needs almost as much space for metadata as for data. Also, the entire disk is already assigned. The ext4 filesystem is available as an image file.

Buy this article as PDF

Download Article PDF now with Express Checkout
Price $2.95
(incl. VAT)

Buy ADMIN Magazine

Related content

comments powered by Disqus