Template:Article summary text Template:Article summary heading Template:Article summary text Template:Article summary heading Template:Article summary text Template:Article summary link Template:Article summary link Template:Article summary link Template:Article summary text Template:Article summary end
Btrfs provides a number of features that make it an excellent candidate for using it as the root partition in an Arch Linux installation:
- instant snapshots
- non-volatile rollback support
- integrated multi-device support RAID
- online resize, add/remove devices, defragmentation
- online fsck, checksumming and auto-correction
For a tour of btrfs features see A tour of btrfs. As is common with FLOSS, there are a number of ways to configure btrfs as the root filesystem.
This article assumes your are doing a fresh install from the Arch Linux installation media.
- 1 mkinitcpio-btrfs
- 2 Prerequisites
- 3 btrfs-progs
- 4 Partition disks
- 5 Format the partitions
- 6 Mount the partitions
- 7 Install the base system
- 8 Configure the system
- 9 Install and configure a bootloader
- 10 Usage Hints
- 11 Known issues
First of all you need to decide, if you want to use some of Btrfs's neat features like non-volatile rollback or automatic mounting of degraded Btrfs multi-device (RAID) volumes. To enable this features you need a special package from the Arch User Repository called AUR. The package integrates some helpers in your boot process, to handle these features correctly.
This guide can also be followed without this package, through I generally recommend it. The relevant sections contain notes for both types of setup.
Boot up your Arch Linux installation media and configure your network connection if not done automatically.
To create a btrfs filesystem you will need to install the from Official Repositories. This package is normally present on your installation media. It is still a good idea to perform an update, to make sure you have the latest version of it.
Btrfs has build-in RAID support. Setting up at least RAID1 is recommended for enabling its internal selfhealing features. If you don't have two drives, setup two partitions of the same size on one drive.
Format the partitions
mkfs.btrfs to create your root partition.
# mkfs.btrfs -L root -m raid1 -d raid1 /dev/sda1 /dev/sdb1
Mount the partitions
Now it is time to mount the new filesystem. First create the mount directory:
# mount -o defaults,relatime,compress=lzo,ssd,discard /dev/sda1 /mnt
Configure the btrfs filesystem
Clone the btrfs root to an
__active subvolume for your future system root directory
/. This will enable you to take snapshots in a directory outside of your system root and helps keeping a clean filesystem structure.
# cd /mnt # btrfs subvolume snapshot . __active
If you plan on using the rollback features of btrfs, create a
__snapshot directory for containing snapshots.
# cd /mnt # mkdir __snapshot
You can create separate subvolumes for important FHS directories. This would allow you to monitor and adjust the size allocations for each subvolume using
# cd /mnt/__active # btrfs subvolume create home # btrfs subvolume create var # btrfs subvolume create usr
To see your handy work:
# btrfs subvolume list -p .
ID 256 parent 5 top level 5 path __active ID 258 parent 256 top level 5 path __active/home ID 259 parent 256 top level 5 path __active/usr ID 260 parent 256 top level 5 path __active/var
Btrfs supports to set a default subvolume, which is mounted if no
subvol= option is provided at mount time. If you plan to use AUR later on, you MUST set this default subvolume to your
# btrfs subvolume list .
ID 256 gen 98 top level 5 path __active
# btrfs subvolume set-default 256 .
Now that the subvolumes are created and we have a layout, lets mount the root subvolume directly:
# cd # umount /mnt # mount -o defaults,relatime,compress=lzo,ssd,discard /dev/sda1 /mnt
Install the base system
Proceed with bootstrap. If you plan to use
pacstrap command too.
# pacstrap /mnt base base-devel btrfs-progs kexec-tools grub
If you plan to useAUR download its tarball to your chroot environment.
# wget -O /mnt/root/mkinitcpio-btrfs.tar.gz https://aur.archlinux.org/packages/mk/mkinitcpio-btrfs/mkinitcpio-btrfs.tar.gz
Configure the system
Once the you have successfully configured your Arch Linux, it is important that we tweak some settings to get everything working together so when you reboot everything will work correctly.
Create a place where you mount the Btrfs root subvolume to create snapshots later.
# mkdir /var/lib/btrfs
# nano /mnt/etc/fstab
Add the following line, supplement
<uuid> for the UUID of the btrfs root partition:
UUID=<uuid> / btrfs defaults,relatime,compress=lzo,ssd,discard 0 0 UUID=<uuid> /var/lib/btrfs btrfs defaults,relatime,compress=lzo,ssd,discard,subvolid=0 0 0
/var/lib/btrfs/empty /var/lib/btrfs/__active none bind 0 0
To installAUR you need to extract the AUR package and build it.
# cd /root # tar -zxvf mkinitcpio-btrfs.tar.gz # cd mkinitcpio-btrfs # makepkg -i --asroot
After installation, modify
/etc/default/btrfs_advanced to your needs. And don't forget to add
btrfs-advanced to your
HOOKS variable in
Now regenerate your initial RAM-disk.
# mkinitcpio -p linux
Install and configure a bootloader
Now proceed with installing your bootloader.
Grub is able to boot directly from Btrfs root. So just do the usual installation steps.
# grub-install --target=i386-pc --recheck /dev/sda # grub-install --target=i386-pc --recheck /dev/sdb # cp /usr/share/locale/en\@quot/LC_MESSAGES/grub.mo /boot/grub/locale/en.mo # grub-mkconfig -o /boot/grub/grub.cfg
Make sure that your Btrfs root is correctly added to the kernel commandline in
/boot/grub/grub.cfg. Using UUIDs for device identification is especially useful for multi-device (RAID) setups, because all Btrfs devices own the same UUID.
To boot from Btrfs using syslinux EFI, you need to setup up a dedicated EFI partition in
/boot/efi. This partition needs to be formated as FAT32 (or HPFS on MacBooks). You need to set up your Syslinux directories on that special partition as described in Syslinux.
/boot/efi/EFI/syslinux/syslinux.cfg make sure your Btrfs root is correctly added to the
APPEND root=UUID=978e3e81-8048-4ae1-8a06-aa727458e8ff rw
To create a snapshot of your root filesystem execute:
# cd /var/lib/btrfs # sudo btrfs subvolume snapshot __active __snapshot/[snapshot name]
btrfs scrub for periodic online filesystem checks:
# sudo btrfs scrub start / # sudo btrfs scrub status /
If you use a multi device (RAID) setup, make sure you rebalance after system upgrades, to prevent kernel panic on device failure:
# sudo btrfs balance /