Arch_encrypted_install
Encrypted Arch Linux Installation w/ Encrypted Swap
The ultimate installation resource is always going to be the:
- Connect to Wi-Fi:
iwctl
[iwd]# device list
[iwd]# station wlan0 scan
[iwd]# station wlan0 connect NETGEAR80
# Enter your Password
# Check Connection
[iwd]# station wlan0 show
[iwd]# exit
ping -c 3 archlinux.org
- Update package databases:
pacman -Sy
- Set system clock:
timedatectl set-ntp true
- Partition your Disk:
- Identify your target disk (eg.
/dev/mmcblk0
):
lsblk
❗ If you already have an EFI partition you do not have to create another one and doing so can cause issues. First check with
fdisk -l
, before creating a new one.
Check your partitions:
fdisk -l | less
Device Size Type
/dev/mmcblk0p1 1G EFI System
/dev/mmcblk0p2 57.2G Linux root (x86-64)
Since I already have an EFI partition, I can just mount it:
mkdir -p /mnt/boot
mount /dev/mmcblk0p1 /mnt/boot
If you don’t already have an EFI partition, create one here:
- Use
fdisk
,parted
, orcfdisk
to create partitions.
cfdisk /dev/mmcblk0
1G boot partition, press
b
to set boot flagThe rest of the Memory Primary
/dev/mmcblk0p2
btrfs, pressp
to set primary flag.
- Format the EFI partition as FAT32:
mkfs.fat -F32 /dev/mmcblk0p1
- Leave the root partition unformatted for the encryption step next.
- Encrypt the Root Partition and Open it:
cryptsetup luksFormat /dev/mmcblk0p2
cryptsetup open /dev/mmcblk0p2 cryptroot
Create a Filesystem with Compression
mkfs.btrfs /dev/mapper/cryptroot
mount /dev/mapper/cryptroot /mnt
- Later, we will enable compression by mounting with options like
compress=zstd
infstab
or manually.
- Encrypted Swap
cfdisk /dev/mmcblk0
Select
New
-> Enter size (2x your RAM size) -> Set type toLinux swap
Select
Write
-> Typeyes
-> SelectQuit
Verify the new partition (e.g., /dev/mmcblk0p3
):
lsblk
Encrypt the swap partition with LUKS:
cryptsetup luksFormat /dev/mmcblk0p3
cryptsetup open /dev/mmcblk0p3 cryptswap
Format the decrypted swap partition:
mkswap /dev/mapper/cryptswap
Enable the swap:
swapon /dev/mapper/cryptswap
Add the swap to /mnt/etc/fstab
(this will be updated later in the genfstab
step, but you can manually ensure it):
echo '/dev/mapper/cryptswap none swap defaults 0 0' >> /mnt/etc/fstab
Add the swap partition to the LUKS configuration for automatic unlocking on boot:
echo 'cryptswap /dev/mmcblk0p3 none luks' >> /mnt/etc/crypttab
❗ Later, after
arch-chroot
, ensure themkinitcpio.conf
HOOKS includeresume
(afterencrypt
) if you plan on using hibernation. This will be covered in the initramfs step.
Continue with Arch Installation
Install the Base System and Essential Packages on /mnt
with pacstrap
pacstrap -K /mnt base linux-zen linux-zen-headers linux-firmware networkmanager helix grub lightdm lightdm-gtk-greeter btrfs-progs cryptsetup sudo base-devel
- Ensure
/mnt/boot
(EFI) is mounted as above. Withmount | grep /mnt/boot
To list all mounts under
/mnt
:findmnt /mnt
I had to remount
/mnt/boot
in order for the fstab to pick it up with:mount /dev/mmcblk0p1 /mnt/boot
- Generate the Filesystem Table:
genfstab -U /mnt >> /mnt/etc/fstab
#
cat /mnt/etc/fstab
# Add compression
vim /mnt/etc/fstab
- Important: It should list
/dev/mapper/cryptroot
mounted on/
with Btrfs options, and/dev/mmcblk0p1
on/boot
. If thefstab
doesn’t show both, you need to regenerate it after mounting the missing partition.
- Add compression, Only for the Encrypted Partition:
# fstab
/dev/mapper/cryptroot / btrfs rw,relatime,compress=zstd,ssd, #...snip
Remount root with compression without rebooting:
mount -o remount,compress=zstd /mnt
- Change Root into the New Installation
arch-chroot /mnt
Create a user:
useradd -m -G wheel -s /bin/bash yourusername
passwd yourusername
Enable sudo for wheel group:
EDITOR=vim visudo
If that doesn’t work, use vim /etc/sudoers
and edit the file accordingly.
Uncomment the line:
%wheel ALL=(ALL) ALL
- Edit
/etc/mkinitcpio.conf
in your new system to add theencrypt
hook beforefilesystems
Locate the
HOOKS
line (near the top)Insert
encrypt
beforefilesystems
vim /etc/mkinitcpio.conf
❗ NOTE how I also added the
resume
afterencrypt
# mkinitcpio.conf
# ... snip ...
HOOKS=(base udev autodetect microcode modconf kms keyboard keymap consolfont block encrypt resume filesystems fsck)
# ... snip ...
- Regenerate initramfs with:
mkinitcpio -p linux-zen
# Should output
Initcpio image generation successful
- Install Grub and EFI boot manager, (while still in chroot environment):
pacman -S grub efibootmgr
Install GRUB for UEFI Systems:
grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB
# Should output
Installation finished. No error reported.
Configure GRUB to unlock LUKS root partition
- Edit
/etc/default/grub
and modify the line starting withGRUB_CMDLINE_LINUX
to add:
cryptdevice=/dev/mmcblk0p2:cryptroot root=/dev/mapper/cryptroot
Example:
GRUB_CMDLINE_LINUX="cryptdevice=/dev/mmcblk0p2:cryptroot root=/dev/mapper/cryptroot"
Generate GRUB configuration:
grub-mkconfig -o /boot/grub/grub.cfg
# Should output
Adding boot menu entry for UEFI Firmware Settings ...
done
- Enable LightDM and NetworkManager
systemctl enable lightdm
systemctl enable NetworkManager
Configure LightDM greeter:
- Edit
/etc/lightdm/lightdm.conf
to add:
# lightdm.conf
[Seat:*]
greeter-session=lightdm-gtk-greeter
Exit arch-chroot
with exit
.
Unmount your partitions and reboot:
umount /mnt/boot
umount /mnt
cryptsetup close cryptroot
- Reboot
arch-chroot
Say you forgot something, like forgetting to add a user and password. You reboot and go to TTY into your system and are hit with a AHHH I can’t log in WTF!
Lol, don’t panic. It’s as easy as repeating some of the steps above. Reboot into the Live environment (like we just did for the install), remount your partitions and arch-chroot back in:
Open the encrypted root partition:
cryptsetup open /dev/mmcblk0p2 cryptroot
Mount the decrypted root:
mount /dev/mapper/cryptroot /mnt
Mount the EFI partition:
mount /dev/mmcblk0p1 /mnt/boot
Chroot into your installed system:
arch-chroot /mnt
useradd -m -G wheel -s /bin/bash yourusername
passwd yourusername
- The
-s /bin/bash
option sets the user’s default shell to Bash, which is the standard command-line interface. You can use another shell like Zsh (/bin/zsh
) if installed.
Uncomment the line %wheel ALL=(ALL:All) ALL
in /etc/sudoers
Exit chroot:
exit
Unmount and close LUKS:
umount /mnt/boot
umount /mnt
cryptsetup close cryptroot
reboot