NOTE: Last update to this gist was on Jun 2, 2018. Most of the things here are out of date (e.g consider using zstd for transparent compression instead of lzo), so do your own research as well. Take care!
- Plenty of storage - snapshots will take (sort of) a lot of space
- Latest Arch Linux install iso because those have newer kernels and more bugfixes in btrfs.
- Have previous experience with installing Arch (like you can install arch with a blind fold).
- Read everything through
Pick a partition scheme fitting your needs, GPT for UEFI and MBR for BIOS based systems.
We really need two of them, one for /boot and the other one will be a btrfs partition with subvolumes. Or whatever you desire, e.g swap partition. You know what to do
-
/dev/sda1 - this will be /boot with vfat filesystem because UEFI or syslinux for legacy BIOS boot
mkfs.fat -F32 /dev/sda1
-
/dev/sda2 - btrfs with bunch of subvolumes
mkfs.btrfs /dev/sda2
We will create few of them to support easy snapshoting with Snapper
mount /dev/sda2 /mnt
btrfs subvolume create /mnt/@root
btrfs subvolume create /mnt/@var
btrfs subvolume create /mnt/@home
btrfs subvolume create /mnt/@snapshots
umount /mnt
mount -o noatime,compress=lzo,space_cache,subvol=@root /dev/sda2 /mnt
mkdir /mnt/{boot,var,home,.snapshots}
mount -o noatime,compress=lzo,space_cache,subvol=@var /dev/sda2 /mnt/var
mount -o noatime,compress=lzo,space_cache,subvol=@home /dev/sda2 /mnt/home
mount -o noatime,compress=lzo,space_cache,subvol=@snapshots /dev/sda2 /mnt/.snapshots
I personally install using systemd-nspawn
, e.g systemd-nspawn --directory=/mnt --boot
. However, fstab and bootloader must be installed using arch-chroot
.
Make sure that fstab is okay after you finish. Do not forget to use subvol=@foo
and get rid of subvolid=
flags
You can create snapshots like so
btrfs subvolume snapshot -r / "/.snapshots/@root-$(date +%F-%R)"
And to restore from snapshot you just delete the currently used @root and replace it with a earlier snapshot
mount /dev/sda2 /mnt
btrfs subvolume delete /mnt/@root
brtfs subvolume snapshot /mnt/@snapshots/@root-2015-08-10-20:19 /mnt/@root
and then just reboot :)
you will probably want to use Snapper or something like that to manage your snapshots.
- syslinux sould be capable of booting a btrfs volume but afaik it is just talk, I havent found anyone in the internet who has a working syslinux btrfs boot without seperate /boot parition. Only GRUB is capable of booting from bare btrfs file system.
- /boot is not snapshottable with this setup, someone somewhere sugested to create a systemd service to copy files from btrfs /boot to your seperate FAT32 ESP partition when files change in /boot folder. I havent tried that yet.
ssd
mount option is considered harmful on non-rotational devices, unless you have newer kernel than 4.14 or have backported this commitdiscard
option isn't really good either, as it seems to cause performance drops on certain SSDs. Manual trimming is more flexible.
Thanks, it was good for me as a practical guide, as a newcomer to btrfs, but not arch.
I found i had to use mkfs.btrfs -f /dev/sda2 , in order to overwrite an existing fs because I had partitioned with cgisk, using 8300 linux filesytem - as according to the advice I had found.
A point for other followers: I had to use mkfs.btrfs -f -L 'arch' /dev/sda2 in order to configure my efi bootloader (i.e. sytemd bootctl) to load using label rather than UUID. A GPT partition label alone doesn't work with the bootloader to a btrfs subvolume
In answer to Randon Note (2): pacman-boot-backup-hook available in aur will do that for you. Also in aur, systemd-boot-pacman-hook will upgrade for systemd bootloader for you, and also, check ou hooks snap-pac and snap-pac-grub to make snapper snapshots after any pacman installation (and work with yay too).