User:AlonsoLP/Btrfs

From ArchWiki


mkfs.btrfs -L "Arch Linux" /dev/sda1

mkdir /mnt/btrfs-root mount -o defaults,relatime,discard,ssd,nodev,nosuid /dev/sda1 /mnt/btrfs-root

mkdir -p /mnt/btrfs/__snapshot mkdir -p /mnt/btrfs/__current btrfs subvolume create /mnt/btrfs-root/__current/root btrfs subvolume create /mnt/btrfs-root/__current/home

mkdir -p /mnt/btrfs-current mount -o defaults,relatime,discard,ssd,nodev,subvol=__current/root /dev/sda1 /mnt/btrfs-current mkdir -p /mnt/btrfs-current/home mount -o defaults,relatime,discard,ssd,nodev,nosuid,subvol=__current/home /dev/sda1 /mnt/btrfs-current/home

Install Arch Linux

pacstrap /mnt/btrfs-current base base-devel

genfstab -U -p /mnt/btrfs-current >> /mnt/btrfs-current/etc/fstab nano /mnt/btrfs-current/etc/fstab

  • copy the partition info for / and mount it on /run/btrfs-root (remember to remove subvol parameter! and add nodev,nosuid,noexec parameters)

arch-chroot /mnt/btrfs-current

pacman -S btrfs-progs

nano /etc/mkinitcpio.conf

  • Remove fsck and add btrfs to HOOKS

mkinitcpio -p linux

umount /mnt/btrfs-current/home umount /mnt/btrfs-current umount /mnt/btrfs-root

reboot

Otra fuente

  1. Arch installation on a BTRFS root filesystem

This is a cheatsheet with all the instructions to perform an installation of Arch Linux using BTRFS filesystem in /

Please, read **the entire document** before proceeding because it includes two different approaches. The key is to include /boot directory in the snapshots for root in order to be able to rollback the entire system without any problem it it is needed. Lets proceed!

[TOC]

    1. Laptop model

The installation has been done on a [Mountain Onyx](https://www.mountain.es/portatiles/onyx) laptop.

- **Screen**: 15,6" Full HD IPS Mate - **CPU**: Intel® Core™ i7 6700HQ - 4C/8T - **RAM**: 8GB DDR3L 1600 SODIMM - **Hard Disk**: SSD 240GB M.2 550MB/s - **GPU**: Nvidia GTX 960M 2GB GDDR5 + Intel i915 (Skylake) - **UEFI**

    1. Approach 1 [UEFI, GPT and GRUB]

I have been following [Official Arch Installation Guide](https://wiki.archlinux.org/index.php/Installation_guide). Arch ISO booted in UEFI mode using **systemd-boot**. It was configured a wired connection too.

      1. Partitioning

This is the selected layout for the UEFI/GPT system:

| Mount point | Partition | Partition type | FS Type | Bootable flag | Size | |-------------|-----------|---------------------|-----------|----|--------| | /boot/efi | /dev/sda1 | EFI System Partition| FAT32 | Yes | 512 MiB| | [SWAP] | /dev/sda2 | Linux swap | SWAP | No | 16 GiB | | / | /dev/sda3 | Linux | BTRFS | No | 222 GiB |

After creating the partitions using [fdisk](https://wiki.archlinux.org/index.php/Fdisk), it was necessary to format them. Again, I followed the guide without a problem.

    • IMPORTANT**: I used **-L** option with *mkfs* command in order to create a label for **/** (called **arch**).
      1. BTRFS layout

The only partition formated with BTRFS was /dev/sda3, which contains the whole root system. BTRFS was selected to enable snapshots support in order to avoid any possible problem with Arch updates. Sometimes, I have experimented that certain critical package updates can break the system. If it occurs, it is a good idea to have some snapshot to rollback the entire root filesystem. tmp subvolume has been created in order to avoid the inclusion of temporal files within the snapshots of rootvol. tmp snapshots never will be created, because all the files stored within tmp are temporal. This is the layout defined:

``` sda3 (Volume) | | - _active (Subvolume) | | | - rootvol (Subvolume - It will be the current /) | - homevol (Subvolume - it will be the current /home) | | | - tmp (Subvolume - It will be the current /tmp) | | - _snapshots (Subvolume - It will contain all the snapshots which are subvolumes too) ``` And these are the commands:

``` mkfs.btrfs -L arch /dev/sda3 mount /dev/sda3 /mnt cd /mnt btrfs subvolume create _active btrfs subvolume create _active/rootvol btrfs subvolume create _active/homevol btrfs subvolume create _active/tmp btrfs subvolume create _snapshots ```

Next, create all the directories needed and mount all the partitions (/boot/efi included) in order to start the installation:

``` cd .. umount /mnt mount -o subvol=_active/rootvol /dev/sda3 /mnt mkdir /mnt/{home,tmp,boot} mkdir /mnt/boot/efi mkdir /mnt/mnt/defvol mount -o subvol=_active/tmp /dev/sda3 /mnt/tmp mount /dev/sda1 /mnt/boot/efi mount -o subvol=_active/homevol /dev/sda3 /mnt/home mount -o subvol=/ /dev/sda3 /mnt/mnt/defvol ```

      1. Installing Arch Linux

Proceed with the installation according to the official guide.

      1. Fstab

After executing *genfstab -U /mnt >> /mnt/etc/fstab* to generate fstab file using **UUIDs** for the partitions, I edited fstab in order to remove completely **subvolids** for example (they are not needed and it makes rollback much more easy) and adding compression to BTRFS mounted points and this is the result. Please, be aware of **/mnt/defvol** mounting point. This directory is very important because the WHOLE BTRFS volume will be mounted here and you will have access to all subvolumes and snapshots created after the installation)

```

  1. /dev/sda3 LABEL=arch

UUID=9882a07e-0a0c-419d-bbdd-cbfbc4a6ffc9 / btrfs rw,relatime,compress=lzo,ssd,discard,autodefrag,space_cache,subvol=/_active/rootvol 0 0

  1. /dev/sda1

UUID=3074-C66B /boot/efi vfat rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 2

  1. /dev/sda3 LABEL=arch

UUID=9882a07e-0a0c-419d-bbdd-cbfbc4a6ffc9 /tmp btrfs rw,relatime,compress=lzo,ssd,discard,autodefrag,space_cache,subvol=_active/tmp 0 0

  1. /dev/sda3 LABEL=arch

UUID=9882a07e-0a0c-419d-bbdd-cbfbc4a6ffc9 /home btrfs rw,relatime,compress=lzo,ssd,discard,autodefrag,space_cache,subvol=_active/homevol 0 0

  1. /dev/sda2

UUID=9943adc7-d8a5-4500-bb35-3179aca961f5 none swap defaults 0 0

UUID=9882a07e-0a0c-419d-bbdd-cbfbc4a6ffc9 /mnt/defvol btrfs rw,relatime,compress=lzo,ssd,discard,autodefrag,space_cache,subvol=/ 0 0 ```

      1. Mkinitcpio

In order to enable BTRFS on initramfs image, I added **btrfs** on HOOK inside **/etc/mkinitcpio.conf**. Then, it was necessary to execute **mkinitcpio -p linux** again. If you install linux-lts kernel (Long Term Support), you will have to execute **mkinitcpio -p linux-lts**

      1. Microcode

I installed **intel-ucode** package because I have an Intel CPU.

      1. Bootloader

If you want to have BTRFS snapshots integrated from booting you will have to install GRUB. Thanks to [grub-btrfs](https://www.archlinux.org/packages/community/any/grub-btrfs/) package, you will be able to boot your system directly from any snapshot of ROOT created. All these snapshots will be populated in the GRUB menu.

GRUB is totally compatible with EFI systems. Install **grub** and **efibootmgr**:

   pacman -S grub efibootmgr

Install the GRUB EFI application executing this command (please, choose the directory where EFI application will be stored, in my case **/boot/efi**, the partition created before):

   grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=GRUB

Generate the main **grub.cfg** configuration file:

   grub-mkconfig -o /boot/grub/grub.cfg
      1. /tmp folder

Because of **/tmp** is another subvolume mounted as a traditional partition on */fstab*, temporary files won't be deleted by default when the system boots. This can cause some problems like preventing **insync** to start normally for example, because it uses a temporary file called *insync1000.sock* and if this file already exists, it won't run. In order to clean up */tmp* directory on every reboot, add this configuration file **/etc/tmpfiles.d/tmp.conf** with this content:

```

  1. Cleaining up /tmp directory everytime system boots

D! /tmp 1777 root root 0 ```

      1. Additional packages installed

A bunch of useful packages has been installed too: [tlp](https://wiki.archlinux.org/index.php/TLP) for energy saving and advanced power management, [reflector](https://wiki.archlinux.org/index.php/Reflector) for optimizing Arch mirrors repositories, [yay](https://newbloghosting.com/how-to-install-yay-on-arch-linux/) for compiling and installing packages easily from AUR repository, [snapd](https://wiki.archlinux.org/index.php/Snapd) to install snap packages, [btrfs-progs](https://wiki.archlinux.org/index.php/Btrfs) to manage BTRFS filesystem.

      1. Finish the steps in the Wiki

And reboot!!