Install Arch Linux With Btrfs Snapshotting
Preface
Arch Linux is a general-purpose distribution well-known for its cutting-edge technology and flexible configuration. With Btrfs snapshots, we can take the advantage of its fast-pace while being confident of the system’s stability. Let’s start.
Prerequisites
- A newly-created Vultr instance.
- Some free time and patience.
Preparations
You can choose the Arch Linux ISO from the ISO library when creating the instance. If not, you can load that in the machine’s settings. As the time of writing the newest (2017.01.01) ISO is available in the library. If that ISO is outdated, I recommend downloading it again.
After the machine starts, click View Console
and boot the system up. We need to set up a root password for the environment so that we can access it from our working computer:
passwdsystemctl start sshd
Close the VNC window and connect to the machine via ssh:
ssh root@<your host ip here>
Install tmux
so that we can keep our session across unstable connections:
pacman -Sy tmux
If the connection accidentally closes during the installation, simply ssh back to the machine and run:
tmux attach
Installation
First things first, let’s partition the disk.
lsblkmkfs.btrfs -m single -L arch /dev/vdamount -o compress=lzo /dev/vda /mnt
Next comes the tricky part: creating subvolumes.
cd /mntbtrfs su cr @btrfs su cr @bootbtrfs su cr @homebtrfs su cr @logbtrfs su cr @pkgbtrfs su cr @srvbtrfs su cr @tmp
Then, mount the subvolumes.
cd /umount /mntmount -o compress=lzo,subvol=@ /dev/vda /mntcd /mntmkdir -p {boot,home,srv,var/{log,cache/pacman/pkg,tmp}}mount -o compress=lzo,subvol=@boot /dev/vda bootmount -o compress=lzo,subvol=@home /dev/vda homemount -o compress=lzo,subvol=@log /dev/vda var/logmount -o compress=lzo,subvol=@pkg /dev/vda var/cache/pacman/pkgmount -o compress=lzo,subvol=@srv /dev/vda srvmount -o compress=lzo,subvol=@tmp /dev/vda var/tmp
Install the base system.
pacstrap -i /mnt base base-devel snapper vim
Configure the system.
genfstab -U /mnt >> /mnt/etc/fstabarch-chroot /mntln -s /usr/share/zoneinfo/Region/City /etc/localtime # Replace Region/City with your valuehwclock --systohcvim /etc/locale.gen # Uncomment en_US.UTF-8 UTF-8 linelocale-genecho "LANG=en_US.UTF-8" > /etc/locale.confpacman -S networkmanager echo "your-hostname" > /etc/hostname # Replace your-hostname with your valuevim /etc/hosts # Configure 127.0.0.1 and ::1 lines accordinglysystemctl enable NetworkManager.service
Enable sshd for future remote logins.
vim /etc/ssh/sshd_config # Set PermitRootLogin yessystemctl enable sshd.service
Note that the best practice is putting your public key into the ~/.ssh/authorized_keys
file instead of enabling password login for root.
Configure the initramfs so that it satisfies our need for btrfs.
vim /etc/mkinitcpio.conf
Locate MODULES="..."
and add btrfs
into the list. Re-generate the initramfs:
mkinitcpio -p linux
Set the root password.
passwd
Install and configure the bootloader.
pacman -S grubgrub-install /dev/vdagrub-mkconfig -o /boot/grub/grub.cfg
Reboot and remove the ISO in your machine control panel.
exitreboot
Connect to the server again (perhaps after a short while; wait until the boot completes). Note that the server fingerprint has changed, so you may need to alter your known_hosts
file:
vim ~/.ssh/known_hostsssh root@<your host ip here>
Let’s configure snapper, which automates the snapshotting procedure.
snapper -c root create-config /
Edit the config and alter TIMELINE_LIMIT_{HOURLY,DAILY,WEEKLY,MONTHLY,YEARLY}
according to your needs.
vim /etc/snapper/configs/root
Enable the systemd timers.
systemctl enable snapper-timeline.timersystemctl start snapper-timeline.timersystemctl enable snapper-cleanup.timersystemctl start snapper-cleanup.timer
Job’s done!
The configuration of the system is now finished. For more detailed information about how to use snapper, consult the wiki page or snapper(8)
for more information. Enjoy your new Arch Linux with btrfs auto-snapshotting system!
Want to contribute?
You could earn up to $300 by adding new articles
Suggest an update
Request an article
Leave a Comment