Skip to content

Instantly share code, notes, and snippets.

@QaidVoid
Last active October 5, 2024 10:55
Show Gist options
  • Save QaidVoid/d83fa164e3534b816288d53ef3262c88 to your computer and use it in GitHub Desktop.
Save QaidVoid/d83fa164e3534b816288d53ef3262c88 to your computer and use it in GitHub Desktop.
Install Alpine Linux on Encrypted Btrfs partition

Alpine Linux Installation on Encrypted Btrfs partition

Setup keymap, hostname, interfaces and network

setup-alpine

When prompted to select the disk for installation, press Ctrl+C to cancel the guided installation process.

Add required packages for installation

apk add cryptsetup e2fsprogs btrfs-progs dosfstools parted mkinitfs

Partitioning

Create a EFI and Luks partition

parted /dev/sdX -a optimal
mklabel gpt
mkpart primary fat32 0% 200M
name 1 esp
set 1 esp on
mkpart primary btrfs 200M 100%
name 2 luks

Encrypt partition with LUKS

cryptsetup luksFormat /dev/sdX2

Unlock the partition

cryptsetup luksOpen /dev/sdX2 luks

Format LUKS partition as Btrfs

btrfs rescue create-control-device
mkfs.btrfs /dev/mapper/luks

Create Btrfs subvolumes

mount -t btrfs /dev/mapper/luks /mnt
btrfs sub create /mnt/root
btrfs sub create /mnt/home
btrfs sub create /mnt/var
umount /mnt

Mount subvolumes

mount -o noatime,nodiratime,compress=zstd,space_cache=v2,ssd,subvol=root /dev/mapper/luks /mnt
mkdir -p /mnt/home
mkdir -p /mnt/var
mount -o noatime,nodiratime,compress=zstd,space_cache=v2,ssd,subvol=home /dev/mapper/luks /mnt/home
mount -o noatime,nodiratime,compress=zstd,space_cache=v2,ssd,subvol=var /dev/mapper/luks /mnt/var

Mount EFI partition

mkfs.fat -F32 /dev/sdX1
mkdir -p /mnt/boot
mount -t vfat /dev/sdX1 /mnt/boot

Install the system

setup-disk -m sys /mnt/

Initramfs config

Edit /mnt/etc/mkinitfs/mkinitfs.conf and add cryptsetup to the features. Rebuild initramfs

mkinitfs -c /mnt/etc/mkinitfs/mkinitfs.conf -b /mnt $(ls /mnt/lib/modules/)

CHROOT

Mount necessary partitions

mount -t proc /proc /mnt/proc
mount --rbind /dev /mnt/dev
mount --make-rslave /mnt/dev
mount --rbind /sys /mnt/sys

Chroot on installation directory

chroot /mnt
source /etc/profile
export PS1="(chroot) $PS1"

Bootloader Configuration

Install necessary packages

apk add grub grub-efi efibootmgr

Edit /etc/default/grub and modify GRUB_CMDLINE_LINUX_DEFAULT

GRUB_CMDLINE_LINUX_DEFAULT="... cryptroot=UUID=<UUID of /dev/sdX2> cryptdm=luks rootflags=subvol=root rootfstype=btrfs"

Install grub

grub-install --target=x86_64-efi --efi-directory=/boot
grub-mkconfig -o /boot/grub/grub.cfg
@mr00k3
Copy link

mr00k3 commented Oct 3, 2024

Hi look at my fork, i fixed typo in line 16 and added btrfs rescue create-control-device because mkfs.btrfs got error if u can add it to main gist

@QaidVoid
Copy link
Author

QaidVoid commented Oct 5, 2024

Hi look at my fork, i fixed typo in line 16 and added btrfs rescue create-control-device because mkfs.btrfs got error if u can add it to main gist

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment