Mount LUKS BTRFS for arch-chroot
LUKS and BTRFS make for an interesting combination if you ever need to perform some work on another drive. This is a step-by-step procedure I wrote for myself after needing it more than once…
The ArchWiki already covers how to do this if you combine a few separate articles, but I wanted a unified document.
Mounting
- Identify the drive to mount.
$ sudo lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS ...output trimmed... nvme1n1 259:0 0 931.5G 0 disk ├─nvme1n1p1 259:1 0 1G 0 part └─nvme1n1p2 259:2 0 930.5G 0 part $ export DRIVE="nvme1n1"I have trimmed the output to show only the drive applicable here. I am also exporting it as a variable to use later.
- Decrypt the drive if encrypted. Otherwise, skip this step.
$ sudo --preserve-env=DRIVE cryptsetup luksOpen /dev/"${DRIVE}p2" luksvol Enter passphrase for /dev/nvme1n1p2:Note: If the prompt appears to freeze, be patient. It takes a few seconds to decrypt.
- Mount the
@subvolume.$ sudo mount --options subvol=@ /dev/mapper/luksvol /mntThe
@subvolume is the/directory. It needs to be mounted first.
NOTE: You may or may not have additional subvolumes, but it is safe to run the following commands regardless.
The following message may appear if a subvolume doesn’t exist.
mount: /mnt/.snapshots: fsconfig() failed: No such file or directory.
- Mount the
@homesubvolume.$ sudo mount --options subvol=@home /dev/mapper/luksvol /mnt/home - Mount the
@pkgsubvolume.$ sudo mount --options subvol=@pkg /dev/mapper/luksvol /mnt/var/cache/pacman/pkg - Mount the
@logsubvolume.$ sudo mount --options subvol=@log /dev/mapper/luksvol /mnt/var/log - Mount the
@snapshotssubvolume.$ sudo mount --options subvol=@snapshots /dev/mapper/luksvol /mnt/.snapshots
- Mount the
- Mount the
bootpartition. This is critical if you want to update the kernel or bootloader.$ sudo --preserve-env=DRIVE mount /dev/"${DRIVE}p1" /mnt/boot - Finally, you can
arch-chrootinto the mounted system.$ sudo arch-chroot /mnt
Cleanup
After exiting the arch-chroot, unmount everything.
$ sudo umount --recursive /mnt
If the drive was encrypted, close the LUKS volume.
$ sudo cryptsetup close luksvol
References:
- https://wiki.archlinux.org/title/Dm-crypt
- https://wiki.archlinux.org/title/Chroot#Running_on_Btrfs