How to Create Btrfs Filesystem in Linux and its Features

December 15, 2014 | By
| Reply More

Btrfs (B-tree file system) is a new CoW (copy-on-write) file system for Linux. It's development began at Oracle Corporation in 2007 and it was marked as stable in August 2014. The purpose of Btrfs is to address the lack of pooling, snapshots, checksums, and integral multi-device spanning in Linux file systems and its goal was to let Linux scale for the storage that will be available. Scaling is not just about addressing the storage but also means being able to administer and to manage it with a clean interface that lets people see what's being used and makes it more reliable.

You should note that Btrfs has just become stable so it is recommended to always use the latest available version of the kernel to avoid any problems or bugs.

Btrfs Features

Among the most important features of the new file system:

  • Extent based file storage
  • 16 EiB maximum file size
  • Space-efficient packing of small files and indexed directories
  • Dynamic inode allocation
  • Writable snapshots and read-only snapshots
  • Subvolumes (separate internal filesystem roots)
  • Checksums on data and metadata
  • Compression (gzip and LZO)
  • Integrated multiple device support
  • File Striping, File Mirroring, and File Striping+Mirroring implementations
  • Efficient incremental backup
  • Background scrub process for finding and fixing errors on files with redundant copies
  • Online filesystem defragmentation and Offline filesystem check
  • Btrfs filesystem have much enhancement on RAID 5/ RAID 6 support and many bug fixes has been added on linux 3.19

You can read about the new features on this wiki article covering the subject.

Converting to Btrfs

WARNING: You should always backup your data before atempting to convert a file system. Although this operation is stable and safe it can lead to data loss and the only way to prevent this is to always have a backup of your data.

Converting an existing ext4 filesystem to btrfs is quite simple and straightforward, you will first need to use fsck to check if there are any errors on your existing partition and then use the btrfs-convert command to convert it. If the partition you wish to convert is /dev/sda3 you can do it like this:

# fsck.ext4 /dev/sda4
# btrfs-convert /dev/sda4

You can then use the mount command to mount it where you wish.

btrfs-convert

Converting the root partition

If you wish to convert the root partition of your system you will first have to boot a live CD, you can do this by using the Ubuntu installation CD and selecting "Try Ubuntu" from the first screen or use any other Live CD image available.

After you boot open a terminal and use it to convert the filesystem.

# fsck.ext4 /dev/sda1
# btrfs-convert /dev/sda1

Next chroot to the filesystem so you can change fstab and reinstall grub

# mount /dev/sda1 /mnt
# for i in dev dev/pts proc sys ; do mount --bind /$i /mnt/$i ; done
# chroot /mnt
# blkid | grep sda1

btrfs-root-convert

Now edit fstab and replace the current UUID of the / filesystem with the one blkid outputted and the filesystem type with btrfs, the new line should look like this:

UUID=8e7e80aa-337e-4179-966d-d60128bd3714 / btrfs defaults 0 1

Then reinstall Grub:

# grub-install /dev/sda
# update-grub

You can now reboot the machine without using the boot CD and use it with the new filesystem.

Filed Under : FILE SYSTEM, LINUX HOWTO, NEWS

Free Linux Ebook to Download

Leave a Reply

Commenting Policy:
Promotion of your products ? Comment gets deleted.
All comments are subject to moderation.