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 and thought it would be useful to share with others.
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.
- Decrpyt 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. - 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/.snapshotsThe following message may appear if this subvolume doesn’t exist. You can safely proceed.
mount: /mnt/.snapshots: fsconfig() failed: No such file or directory. - 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, reencrypt.
$ sudo cryptsetup close luksvol
References:
- https://wiki.archlinux.org/title/Dm-crypt
- https://wiki.archlinux.org/title/Chroot#Running_on_Btrfs