Skip to content
Terencio Agozzino edited this page Apr 13, 2019 · 131 revisions

Arch Linux Icon

Installation with Btrfs and full disk encryption

After using Ubuntu and Debian for a while, I decided to switch to Arch Linux to provide a simple and lightweight OS. In addition, Arch Linux allows me to keep up to date with the latest versions of packages, which I greatly appreciate.

First of all, you should know that I'm willing to bring a new tutorial because I haven't yet found a tutorial to use Btrfs, encrypting the entire disk and providing a full installation of the basic packages.

NOTE: don't forget that Arch Wiki remains the ultimate reference.


Create a bootable UEFI USB

On the assumption that:

  • X is the volume ID;
  • Y is the partition ID.

Make a FAT32 partition with boot flag

sudo fdisk /dev/sdX

Formatting the USB Flash Drive

sudo mkfs.vfat -F32 /dev/sdXY

Labeling the USB Flash Drive

sudo mlabel -i /dev/sdXY ::LABEL

Installation of Arch Linux on the USB Flash Drive

Replace archlinux by the name of your ISO image of Arch Linux:

sudo dd bs=4M if=archlinux.iso of=/dev/sdX status=progress && sync
  • bs (block size): on modern equipment (less than 5 years old), 4MB is a good bet;
  • if: source of the ISO image of Arch Linux;
  • of: destination to install the ISO image of Arch Linux;
  • status: automatically print periodic updates in the standard output.

Start on USB key

To do that, checks the following things:

  • USB Flash Drive is first on the priority of boot;
  • Secure Boot is disabled.

Before installation

Before proceeding with the installation of Arch Linux, it is important to check if you have:

  • an Internet access;
  • booted in UEFI mode or not.

Internet access

To verify that your system has Internet access, you can check it by pinging to any site (e.g. Google):

ping -c 3 www.google.com

Boot mode

To find out if you started in UEFI mode (recommended), simply check that the following command returns a list of defined UEFI variables. Otherwise, it means you have started in BIOS Legacy mode:

efivar -l

Disk partitioning (UEFI)

The partitioning that follows concerns the UEFI installation. Be careful if you want to install Arch Linux in a Legacy BIOS mode.

Introduction

Since I use a Lenovo Thinkpad, I have different names for the partitions:

Partition name Commonly used partition name
/dev/nvme0n1p1 /dev/sdx1
/dev/nvme0n1p2 /dev/sdx2

Our Arch Linux will have two partitions:

Mount point Partition name Partition type Bootable flag Suggested size
/efi /dev/nvme0n1p1 EFI System Yes 512 Mo
/ /dev/nvme0n1p2 Linux LVM No Remainder of the device

Where / is the partition that will be encrypted and that will be a LVM having a physical volume containing a group volume that has two logical volumes:

  1. swap
  2. root

Finally, we will format the root volume in Btrfs and create two sub-volume:

  1. /mnt/root
  2. /mnt/home

NOTE: according to Theodore Ts'o, principal developer of ext3 and ext4 file systems, ext4 has improved features, it is not a major advance; it uses old technology and is a stop-gap. He adds that Btrfs is the best direction because "it offersimprovements in scalability, reliability and ease of management".

Without going into details, Btrfs is stable, allows for better data compression, easily handles snapshots and RAIDs.

Creation of the file system

In order to know the name of your disk, it is necessary to list the partition tables for the specified devices:

fdisk -l

Let's select our disk to build the table:

gdisk /dev/nvme0n1

Then, create a new empty GTP partition table by pressing the o key.

EFI

Partition number (1-128, default 1):
First sector (2048-2000409230, default = 2048) or {+-}size{KMGTP}:
Last sector (2048-2000409230, default = 2000409230) or {+-}size{KMGTP}: 512M
Current type is'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): ef00
Changed type of partition to 'EFI System'

/

Partition number (2-128, default 2):
First sector (1050624-2000409230, default = 1050624) or {+-}size{KMGTP}:
Last sector (1050624-2000409230, default = 2000409230) or {+-}size{KMGTP}:
Current type is'Linux filesystem'Hex code or GUID (L to show codes, Enter = 8300): 8e00
Changed type of partition to'Linux LVM'

Print the partition table

Before writing the two partitions, check that they are correct by pressing the p key.

You should have such a partition table:

Number Start (sector) End (sector) Size Code Name
1 2048 1050623 512.0 MiB EF00 EFI System
2 1050624 2000409230 953.4 GiB 8E00 Linux LVM

Write the partition table

Now that the partition table is created, all you have to do is write it to the disk by pressing the w key.

Setup disk encryption

In order to enable disk encryption, we will first create a root LUKS volume, open it and then format it.

To keep it short, LUKS is a container format that will be used to encrypt containers, where our encryption key will be stored.

Creation of a root LUKS volume

To encrypt our / partition, we will use the cryptsetup tool:

cryptsetup --cipher aes-xts-plain64 --hash sha512 --use-random --verify-passphrase luksFormat /dev/nvme0n1p2
Are you sure? YES
Enter passphrase (twice)

Opening the root LUKS volume as block device

The / partition being encrypted, we will open the LUKS container on /dev/nvme0n1p2 disk and name it root:

cryptsetup luksOpen /dev/nvme0n1p2 root
Enter passphrase

Clone this wiki locally