How to Install Arch Linux with Btrfs

This article provides a step-by-step guide on how to install Arch Linux with Btrfs.

Arch Linux is a lightweight, rolling-release distribution known for its simplicity and flexibility. One of its most compelling features is its minimalism, which allows users to build their systems from the ground up. Btrfs (B-tree file system) is a modern file system that offers advanced features like snapshotting, compression, and dynamic volume management, making it an attractive choice for Arch users looking for more control over their storage system.

This guide will walk you through the process of installing Arch Linux with Btrfs, covering everything from preparing your system to configuring your file system and completing the installation.

Prerequisites

Before starting the installation, make sure you have the following:

  1. A computer or virtual machine with a UEFI-compatible BIOS.
  2. A bootable USB drive with the Arch Linux ISO (download from the official Arch Linux website).
  3. A reliable internet connection for downloading packages during installation.
  4. Familiarity with the Linux command line interface (CLI), as Arch Linux installation is done entirely through the terminal.

Step 1: Booting from the Arch Linux Live Environment

  1. Create a bootable USB drive: You can use tools like dd or Rufus to create a bootable Arch Linux USB drive from the downloaded ISO.

    sudo dd if=archlinux-YYYY.MM.DD-x86_64.iso of=/dev/sdX bs=4M status=progress && sync
    

    Replace /dev/sdX with your actual USB device.

  2. Boot from the USB drive: Insert the USB drive into the machine, reboot, and enter the UEFI/BIOS settings. Select the USB drive as the primary boot device.

  3. Start the Arch Linux installer: Once the system boots, you’ll be in the Arch Linux live environment. From here, you’ll perform the installation via the command line.

Step 2: Setting Up the Disk

Arch Linux doesn’t include a graphical installer, so you will set up everything manually, including partitioning and formatting the disk. In this guide, we’ll use Btrfs as the file system.

  1. Identify the disk: List all available disks and partitions with the following command:

    lsblk
    

    Identify the target disk for the Arch installation (e.g., /dev/sda). Be very careful here to choose the correct disk, as the following steps will erase all data on it.

  2. Partition the disk: We’ll use gdisk to create a GPT (GUID Partition Table) partition scheme.

    gdisk /dev/sda
    
    • Create a new partition: Type n to create a new partition.

    • Select the partition type: Choose 1 to create a partition for the system’s bootloader (EFI).

    • Create the root partition: Choose 2 to create a root partition for Arch Linux.

    • You should have at least two partitions:

      • A 512MB partition for the EFI system (type EF00).
      • The rest of the space for the root partition (type 8300).

    After partitioning, save and exit by typing w.

  3. Format the partitions: Format the EFI partition as FAT32 and the root partition as Btrfs.

    mkfs.fat -F32 /dev/sda1  # Format EFI partition
    mkfs.btrfs /dev/sda2     # Format root partition with Btrfs
    
  4. Mount the partitions: Mount the root partition to /mnt and the EFI partition to /mnt/boot.

    mount /dev/sda2 /mnt
    mkdir /mnt/boot
    mount /dev/sda1 /mnt/boot
    

Step 3: Installing Arch Linux Base System

Now that the disk is prepared, you can begin installing the base system.

  1. Select the mirror: Update the system’s mirror list to ensure the fastest download speeds.

    cp /etc/pacman.d/mirrorlist /mnt/etc/pacman.d/
    curl -o /mnt/etc/pacman.d/mirrorlist https://archlinux.org/mirrorlist/all/
    
  2. Install the base system: Install the minimal set of Arch Linux packages, including the base system and necessary utilities.

    pacstrap /mnt base linux linux-firmware btrfs-progs vim
    
  3. Generate the fstab file: After installing the base system, generate the /etc/fstab file to define the file system mounts.

    genfstab -U /mnt >> /mnt/etc/fstab
    
  4. Chroot into the new system: Change root into the new installation to continue the configuration.

    arch-chroot /mnt
    

Step 4: Configuring the System

Now that you have the base system set up, it’s time to configure your new Arch Linux installation.

  1. Set the timezone: Set your system’s time zone. For example, if you’re in New York:

    ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime
    hwclock --systohc
    
  2. Localization: Uncomment your locale in /etc/locale.gen. For English (US), uncomment:

    en_US.UTF-8 UTF-8
    

    Generate the locale:

    locale-gen
    

    Set the system locale:

    echo "LANG=en_US.UTF-8" > /etc/locale.conf
    
  3. Configure the hostname: Set the hostname of your system. For example, archlinux:

    echo "archlinux" > /etc/hostname
    
  4. Set up the root password: Set the root password to secure the system.

    passwd
    
  5. Install necessary packages: Install essential packages, including a bootloader (GRUB for UEFI systems).

    pacman -S grub efibootmgr
    
  6. Install and configure GRUB: Install GRUB and configure it for UEFI systems.

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

    Generate the GRUB configuration file:

    grub-mkconfig -o /boot/grub/grub.cfg
    

Step 5: Enabling Btrfs Features

Btrfs provides features like snapshots and compression that can be configured to make the most of the file system. For now, you will mount the Btrfs root partition as it is. However, it’s recommended to use subvolumes for better management of data.

  1. Create Btrfs subvolumes: Btrfs subvolumes allow you to separate data and manage them independently. Commonly, a @ subvolume is used for root data, and @home can be used for the /home directory.

    mount -o compress=zstd /dev/sda2 /mnt
    btrfs subvolume create /mnt/@
    btrfs subvolume create /mnt/@home
    
  2. Unmount and remount subvolumes: Once you’ve created subvolumes, unmount the Btrfs partition and remount the subvolumes as separate mount points.

    umount /mnt
    mount -o subvol=@,compress=zstd /dev/sda2 /mnt
    mkdir /mnt/home
    mount -o subvol=@home /dev/sda2 /mnt/home
    
  3. Update fstab for subvolumes: Edit /mnt/etc/fstab to include the subvolumes:

    UUID=<uuid_of_sda2> /               btrfs   subvol=@,compress=zstd 0 0
    UUID=<uuid_of_sda2> /home           btrfs   subvol=@home,compress=zstd 0 0
    

Step 6: Finalizing the Installation

  1. Exit chroot and reboot: Exit the chroot environment and unmount the partitions:

    exit
    umount -R /mnt
    reboot
    
  2. Reboot into Arch Linux: Remove the installation media, and your system should boot into the Arch Linux installation with the Btrfs file system.

Conclusion

By following these steps, you’ve successfully installed Arch Linux with Btrfs. This setup gives you a flexible and powerful file system, with features like snapshots and compression, that can be useful for managing system files and data more efficiently. From here, you can customize your Arch installation further by adding packages, configuring users, and fine-tuning your system to meet your needs.