<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.alpinelinux.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Blt</id>
	<title>Alpine Linux - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.alpinelinux.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Blt"/>
	<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/wiki/Special:Contributions/Blt"/>
	<updated>2026-05-04T01:47:56Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.40.0</generator>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=23813</id>
		<title>Full disk encryption secure boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=23813"/>
		<updated>2023-07-19T16:30:12Z</updated>

		<summary type="html">&lt;p&gt;Blt: /* Grub settings */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Disclaimer : this is not to be followed, only for testing purposes. This will be updated when GRUB 2.12 rc1 will be available for LUKSv2, GRUB and FDE to work&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
This guide is to explain, step-by-step, how to setup Alpine Linux with Full Disk Encryption using LUKS2, LVM (one Physical Volume Partition with three Logical Volume Partitions (/ /boot &amp;amp; swap) with hibernation on a NVMe drive, with UEFI &amp;amp; Secure Boot. This guide has been written using Alpine Linux Std 3.16.1, please adapt some commands if needed.&lt;br /&gt;
&lt;br /&gt;
The goal of this guide is to follow the KISS principle, but another file system can be used, multiple partitions for /home; /var/log etc.. can also be added, if the proposed configuration is not meeting your requirements.&lt;br /&gt;
&lt;br /&gt;
= Installing packages =&lt;br /&gt;
&lt;br /&gt;
To facilitate the partitioning we will use gdisk :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lsblk gptfdisk&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For encryption, we will use cryptsetup :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add cryptsetup&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For LVM:&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lvm2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For using and managing UEFI, multiple packages are needed :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efibootmgr e2fsprogs grub grub-efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Preparing / overwriting the disk =&lt;br /&gt;
&lt;br /&gt;
This can take long, on my side for a 500GB nVME it tooks ~30 minutes.&lt;br /&gt;
&amp;lt;pre&amp;gt;# haveged -n 0 | dd of=/dev/nvme0n1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Partitioning the disk =&lt;br /&gt;
&lt;br /&gt;
Let&#039;s assume the disk is /dev/nvme0n1 and no partition is present, we will create two partitions :&lt;br /&gt;
 &lt;br /&gt;
* one for UEFI&lt;br /&gt;
* one for LVM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; # gdisk /dev/nvme0n1&lt;br /&gt;
GPT fdisk (gdisk) version 1.0.9.1&lt;br /&gt;
&lt;br /&gt;
Partition table scan:&lt;br /&gt;
  MBR: not present&lt;br /&gt;
  BSD: not present&lt;br /&gt;
  APM: not present&lt;br /&gt;
  GPT: not present&lt;br /&gt;
&lt;br /&gt;
Creating new GPT entries in memory.&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (1-128, default 1): &lt;br /&gt;
First sector (34-1000215182, default = 2048) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (2048-1000215182, default = 1000214527) or {+-}size{KMGTP}: 512M&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): ef00&lt;br /&gt;
Changed type of partition to &#039;EFI system partition&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (2-128, default 2): &lt;br /&gt;
First sector (34-1000215182, default = 1050624) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (1050624-1000215182, default = 1000214527) or {+-}size{KMGTP}: &lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8309&lt;br /&gt;
Changed type of partition to &#039;Linux LUKS&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): w&lt;br /&gt;
&lt;br /&gt;
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING&lt;br /&gt;
PARTITIONS!!&lt;br /&gt;
&lt;br /&gt;
Do you want to proceed? (Y/N): Y&lt;br /&gt;
OK; writing new GUID partition table (GPT) to /dev/nvme0n1.&lt;br /&gt;
The operation has completed successfully.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring LUKS =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 1000 --use-random luksFormat /dev/nvme0n1p2&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p2 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p2: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&lt;br /&gt;
# cryptsetup luksOpen /dev/nvme0n1p2 lvmcrypt&lt;br /&gt;
&lt;br /&gt;
= LVM : Physical &amp;amp; Logical Volumes creation=&lt;br /&gt;
&amp;lt;pre&amp;gt;# pvcreate /dev/mapper/lvmcrypt&lt;br /&gt;
  Physical volume &amp;quot;/dev/mapper/lvmcrypt&amp;quot; successfully created.&lt;br /&gt;
# vgcreate vg0 /dev/mapper/lvmcrypt&lt;br /&gt;
  Volume group &amp;quot;vg0&amp;quot; successfully created&lt;br /&gt;
# lvcreate -L 20G vg0 -n swap (I have a 16GB RAM laptop)&lt;br /&gt;
  Logical volume &amp;quot;swap&amp;quot; created.&lt;br /&gt;
# lvcreate -l 100%FREE vg0 -n root&lt;br /&gt;
  Logical volume &amp;quot;root&amp;quot; created.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To check the creation :&lt;br /&gt;
&amp;lt;pre&amp;gt;# lvscan&lt;br /&gt;
  ACTIVE            &#039;/dev/vg0/swap&#039; [20.00 GiB] inherit&lt;br /&gt;
  ACTIVE            &#039;/dev/vg0/root&#039; [455.92 GiB] inherit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Mounting points and File System =&lt;br /&gt;
&lt;br /&gt;
Create vfat file system for UEFI partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.vfat /dev/nvme0n1p1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for / partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/vg0/root&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Activate SWAP:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkswap /dev/vg0/swap&lt;br /&gt;
# swapon /dev/vg0/swap&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mount / partition to /mnt :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t ext4 /dev/vg0/root /mnt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create /boot/efi:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /mnt/boot/efi -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mount UEFI partition to /mnt/boot/efi :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t vfat /dev/nvme0n1p1 /mnt/boot/efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk&lt;br /&gt;
nvme0n1        259:0    0 476.9G  0 disk  &lt;br /&gt;
├─nvme0n1p1    259:1    0   511M  0 part  /mnt/boot/efi&lt;br /&gt;
└─nvme0n1p2    259:2    0 476.4G  0 part  &lt;br /&gt;
  └─lvmcrypt   253:0    0 476.4G  0 crypt &lt;br /&gt;
    ├─vg0-swap 253:1    0    20G  0 lvm   [SWAP]&lt;br /&gt;
    └─vg0-root 253:2    0 456.4G  0 lvm   /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Installing Alpine =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# setup-disk -m sys /mnt/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= mkinitfs settings &amp;amp; modules =&lt;br /&gt;
Edit the /mnt/etc/mkinitfs/mkinitfs.conf file and append the modules to the features parameters (keymap only needed if your keyboard is not QWERTY):&lt;br /&gt;
&amp;lt;pre&amp;gt;features=&amp;quot;ata base ide scsi usb virtio ext4 lvm nvme keymap cryptsetup cryptkey resume&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Regenerate the initram:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkinitfs -c /mnt/etc/mkinitfs/mkinitfs.conf -b /mnt/ $(ls /mnt/lib/modules/)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Grub settings =&lt;br /&gt;
&lt;br /&gt;
Create a crypto_keyfile.bin to avoid typing the passphrase twice during the boot process (one for Grub partition, one for Alpine partition):&lt;br /&gt;
&amp;lt;pre&amp;gt;# touch /mnt/crypto_keyfile.bin&lt;br /&gt;
# chmod 600 /mnt/crypto_keyfile.bin&lt;br /&gt;
# dd if=/dev/random bs=512 count=4 | xxd -p -c999 | tr -d &#039;\n&#039; &amp;gt; /mnt/crypto_keyfile.bin&lt;br /&gt;
# cryptsetup luksAddKey /dev/nvme0n1p2 /mnt/crypto_keyfile.bin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, let&#039;s mount and chroot to our fresh installation:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t proc /proc /mnt/proc&lt;br /&gt;
# mount --rbind /dev /mnt/dev&lt;br /&gt;
# mount --make-rslave /mnt/dev&lt;br /&gt;
# mount --rbind /sys /mnt/sys&lt;br /&gt;
# chroot /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit /etc/default/grub and add cryptkey after cryptdm=root parameter like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_TIMEOUT=2&lt;br /&gt;
GRUB_DISABLE_SUBMENU=y&lt;br /&gt;
GRUB_DISABLE_RECOVERY=true&lt;br /&gt;
GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;modules=sd-mod,usb-storage,ext4,nvme cryptroot=UUID=XXXX cryptdm=lvmcrypt cryptkey quiet rootfstype=ext4&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
XXXX could be found with blkid command&lt;br /&gt;
&lt;br /&gt;
Add a new GRUB_PRELOAD_MODULES line like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_PRELOAD_MODULES=&amp;quot;luks cryptodisk part_gpt lvm&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, add the cryptodisk parameter :&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_ENABLE_CRYPTODISK=y&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let&#039;s show the UUID of our partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk -f&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a /root/grub-pre.cfg and replace &amp;lt;XXXX-UUID_WITHOUT_HYPHENS&amp;gt; with your encrypted lvm partition UUID (here /dev/nvme0n1p2) without hyphens, replace &amp;lt;YYYY&amp;gt; with VG UUID from vgdisplay and replace &amp;lt;ZZZZ&amp;gt; with LV UUID from lvdisplay of your /dev/vg0/root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set crypto_uuid=&amp;lt;XXXX-UUID_WITHOUT_HYPHENS&amp;gt;&lt;br /&gt;
cryptomount -u $crypto_uuid&lt;br /&gt;
set root=&#039;lvmid/&amp;lt;YYYY&amp;gt;/&amp;lt;ZZZZ&amp;gt;&#039;&lt;br /&gt;
set prefix=($root)/boot/grub&lt;br /&gt;
insmod normal&lt;br /&gt;
normal&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring Secure Boot =&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efi-mkkeys efibootmgr sbsigntool&lt;br /&gt;
# efi-mkkeys -s &amp;quot;Your Name&amp;quot; -o /etc/uefi-keys&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Re-install Grub:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /boot/efi/EFI/AlpineLinuxSecureBoot&lt;br /&gt;
# grub-mkimage -p /boot/grub -O x86_64-efi -c /root/grub-pre.cfg -o /tmp/grubx64.efi luks2 part_gpt cryptodisk lvm ext2 gcry_rijndael pbkdf2 gcry_sha512&lt;br /&gt;
# install -v /tmp/grubx64.efi /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sed -i &#039;s/SecureBoot/SecureB00t/&#039; /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi&lt;br /&gt;
# cd /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sbsign --key /etc/uefi-keys/db.key --cert /etc/uefi-keys/db.crt --output grubx64.efi.signed grubx64.efi&lt;br /&gt;
# grub-mkconfig -o /boot/grub/grub.cfg&lt;br /&gt;
# efibootmgr --disk /dev/nvme0n1p1 --part 1 --create --label &#039;Alpine Linux Secure Boot Signed&#039; --load /EFI/AlpineLinuxSecureBoot/grubx64.efi.signed --verbose&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To check that your .efi is signed :&lt;br /&gt;
&amp;lt;pre&amp;gt; # sbverify --cert /etc/uefi-keys/db.crt /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi.signed &lt;br /&gt;
Signature verification OK&lt;br /&gt;
# sbverify --list /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi.signed&lt;br /&gt;
signature 1&lt;br /&gt;
image signature issuers:&lt;br /&gt;
 - /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
image signature certificates:&lt;br /&gt;
 - subject: /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
   issuer:  /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy db.auth, KEK.auth and PK.auth files from /etc/uefi-keys to a FAT formatted file system.&lt;br /&gt;
&lt;br /&gt;
Reboot &amp;amp; enter into your UEFI (Fx key depending of your laptop)&lt;br /&gt;
&lt;br /&gt;
== Import keys to UEFI ==&lt;br /&gt;
&lt;br /&gt;
This is just an example from an XPS laptop, each UEFI is unique.&lt;br /&gt;
&lt;br /&gt;
# Go to &#039;&#039;&#039;Boot Configuration&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;Secure Boot&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Enable Secure Boot&#039;&#039;&#039; to &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Secure Boot Mode&#039;&#039;&#039; to &#039;&#039;&#039;Deployed Mode&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Enable Custom Mode&#039;&#039;&#039; to &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
# Go to &#039;&#039;&#039;Custom Mode Key Management&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Reset All Keys&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;db&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;db.auth&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;KEK&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;KEK.auth&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;PK&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;PK.auth&#039;&#039;&#039;&lt;br /&gt;
# &#039;&#039;&#039;APPLY CHANGES&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;EXIT&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Check Secure Boot State:&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add mokutil&lt;br /&gt;
# mokutil --sb-state&lt;br /&gt;
SecureBoot enabled&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Congrats!&lt;br /&gt;
&lt;br /&gt;
== Hibernate on encrypted LVM swap partition ==&lt;br /&gt;
&lt;br /&gt;
Find your vg0-swap UUID :&lt;br /&gt;
&amp;lt;pre&amp;gt;lsblk -f&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add resume parameter to your /etc/default/grub :&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_CMDLINE_LINUX_DEFAULT=....resume=UUID=&amp;lt;UUID of your vg0-swap partition&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add a line to your /etc/fstab :&lt;br /&gt;
&amp;lt;pre&amp;gt;/dev/vg0/swap   none            swap     sw    0 0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Enable swap service during boot :&lt;br /&gt;
&amp;lt;pre&amp;gt;rc-update add swap default&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Install zzz and test it&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add zzz&lt;br /&gt;
zzz- Z&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Done and congrats !&lt;/div&gt;</summary>
		<author><name>Blt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=23811</id>
		<title>Full disk encryption secure boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=23811"/>
		<updated>2023-07-18T16:06:18Z</updated>

		<summary type="html">&lt;p&gt;Blt: add disclaimer&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Disclaimer : this is not to be followed, only for testing purposes. This will be updated when GRUB 2.12 rc1 will be available for LUKSv2, GRUB and FDE to work&#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
This guide is to explain, step-by-step, how to setup Alpine Linux with Full Disk Encryption using LUKS2, LVM (one Physical Volume Partition with three Logical Volume Partitions (/ /boot &amp;amp; swap) with hibernation on a NVMe drive, with UEFI &amp;amp; Secure Boot. This guide has been written using Alpine Linux Std 3.16.1, please adapt some commands if needed.&lt;br /&gt;
&lt;br /&gt;
The goal of this guide is to follow the KISS principle, but another file system can be used, multiple partitions for /home; /var/log etc.. can also be added, if the proposed configuration is not meeting your requirements.&lt;br /&gt;
&lt;br /&gt;
= Installing packages =&lt;br /&gt;
&lt;br /&gt;
To facilitate the partitioning we will use gdisk :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lsblk gptfdisk&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For encryption, we will use cryptsetup :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add cryptsetup&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For LVM:&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lvm2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For using and managing UEFI, multiple packages are needed :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efibootmgr e2fsprogs grub grub-efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Preparing / overwriting the disk =&lt;br /&gt;
&lt;br /&gt;
This can take long, on my side for a 500GB nVME it tooks ~30 minutes.&lt;br /&gt;
&amp;lt;pre&amp;gt;# haveged -n 0 | dd of=/dev/nvme0n1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Partitioning the disk =&lt;br /&gt;
&lt;br /&gt;
Let&#039;s assume the disk is /dev/nvme0n1 and no partition is present, we will create two partitions :&lt;br /&gt;
 &lt;br /&gt;
* one for UEFI&lt;br /&gt;
* one for LVM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; # gdisk /dev/nvme0n1&lt;br /&gt;
GPT fdisk (gdisk) version 1.0.9.1&lt;br /&gt;
&lt;br /&gt;
Partition table scan:&lt;br /&gt;
  MBR: not present&lt;br /&gt;
  BSD: not present&lt;br /&gt;
  APM: not present&lt;br /&gt;
  GPT: not present&lt;br /&gt;
&lt;br /&gt;
Creating new GPT entries in memory.&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (1-128, default 1): &lt;br /&gt;
First sector (34-1000215182, default = 2048) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (2048-1000215182, default = 1000214527) or {+-}size{KMGTP}: 512M&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): ef00&lt;br /&gt;
Changed type of partition to &#039;EFI system partition&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (2-128, default 2): &lt;br /&gt;
First sector (34-1000215182, default = 1050624) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (1050624-1000215182, default = 1000214527) or {+-}size{KMGTP}: &lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8309&lt;br /&gt;
Changed type of partition to &#039;Linux LUKS&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): w&lt;br /&gt;
&lt;br /&gt;
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING&lt;br /&gt;
PARTITIONS!!&lt;br /&gt;
&lt;br /&gt;
Do you want to proceed? (Y/N): Y&lt;br /&gt;
OK; writing new GUID partition table (GPT) to /dev/nvme0n1.&lt;br /&gt;
The operation has completed successfully.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring LUKS =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 1000 --use-random luksFormat /dev/nvme0n1p2&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p2 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p2: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&lt;br /&gt;
# cryptsetup luksOpen /dev/nvme0n1p2 lvmcrypt&lt;br /&gt;
&lt;br /&gt;
= LVM : Physical &amp;amp; Logical Volumes creation=&lt;br /&gt;
&amp;lt;pre&amp;gt;# pvcreate /dev/mapper/lvmcrypt&lt;br /&gt;
  Physical volume &amp;quot;/dev/mapper/lvmcrypt&amp;quot; successfully created.&lt;br /&gt;
# vgcreate vg0 /dev/mapper/lvmcrypt&lt;br /&gt;
  Volume group &amp;quot;vg0&amp;quot; successfully created&lt;br /&gt;
# lvcreate -L 20G vg0 -n swap (I have a 16GB RAM laptop)&lt;br /&gt;
  Logical volume &amp;quot;swap&amp;quot; created.&lt;br /&gt;
# lvcreate -l 100%FREE vg0 -n root&lt;br /&gt;
  Logical volume &amp;quot;root&amp;quot; created.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To check the creation :&lt;br /&gt;
&amp;lt;pre&amp;gt;# lvscan&lt;br /&gt;
  ACTIVE            &#039;/dev/vg0/swap&#039; [20.00 GiB] inherit&lt;br /&gt;
  ACTIVE            &#039;/dev/vg0/root&#039; [455.92 GiB] inherit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Mounting points and File System =&lt;br /&gt;
&lt;br /&gt;
Create vfat file system for UEFI partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.vfat /dev/nvme0n1p1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for / partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/vg0/root&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Activate SWAP:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkswap /dev/vg0/swap&lt;br /&gt;
# swapon /dev/vg0/swap&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mount / partition to /mnt :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t ext4 /dev/vg0/root /mnt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create /boot/efi:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /mnt/boot/efi -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mount UEFI partition to /mnt/boot/efi :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t vfat /dev/nvme0n1p1 /mnt/boot/efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk&lt;br /&gt;
nvme0n1        259:0    0 476.9G  0 disk  &lt;br /&gt;
├─nvme0n1p1    259:1    0   511M  0 part  /mnt/boot/efi&lt;br /&gt;
└─nvme0n1p2    259:2    0 476.4G  0 part  &lt;br /&gt;
  └─lvmcrypt   253:0    0 476.4G  0 crypt &lt;br /&gt;
    ├─vg0-swap 253:1    0    20G  0 lvm   [SWAP]&lt;br /&gt;
    └─vg0-root 253:2    0 456.4G  0 lvm   /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Installing Alpine =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# setup-disk -m sys /mnt/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= mkinitfs settings &amp;amp; modules =&lt;br /&gt;
Edit the /mnt/etc/mkinitfs/mkinitfs.conf file and append the modules to the features parameters (keymap only needed if your keyboard is not QWERTY):&lt;br /&gt;
&amp;lt;pre&amp;gt;features=&amp;quot;ata base ide scsi usb virtio ext4 lvm nvme keymap cryptsetup cryptkey resume&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Regenerate the initram:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkinitfs -c /mnt/etc/mkinitfs/mkinitfs.conf -b /mnt/ $(ls /mnt/lib/modules/)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Grub settings =&lt;br /&gt;
&lt;br /&gt;
Create a crypto_keyfile.bin to avoid typing the passphrase twice during the boot process (one for Grub partition, one for Alpine partition):&lt;br /&gt;
&amp;lt;pre&amp;gt;# touch /mnt/crypto_keyfile.bin&lt;br /&gt;
# chmod 600 /mnt/crypto_keyfile.bin&lt;br /&gt;
# dd if=/dev/random bs=512 count=4 | xxd -p -c999 | tr -d &#039;\n&#039; &amp;gt; /mnt/crypto_keyfile.bin&lt;br /&gt;
# cryptsetup luksAddKey /dev/nvme0n1p2 /mnt/crypto_keyfile.bin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, let&#039;s mount and chroot to our fresh installation:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t proc /proc /mnt/proc&lt;br /&gt;
# mount --rbind /dev /mnt/dev&lt;br /&gt;
# mount --make-rslave /mnt/dev&lt;br /&gt;
# mount --rbind /sys /mnt/sys&lt;br /&gt;
# chroot /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit /etc/default/grub and add cryptkey after cryptdm=root parameter like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_TIMEOUT=2&lt;br /&gt;
GRUB_DISABLE_SUBMENU=y&lt;br /&gt;
GRUB_DISABLE_RECOVERY=true&lt;br /&gt;
GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;modules=sd-mod,usb-storage,ext4,nvme cryptroot=UUID=XXXX cryptdm=lvmcrypt cryptkey quiet rootfstype=ext4&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
XXXX could be found with blkid command&lt;br /&gt;
&lt;br /&gt;
Add a new GRUB_PRELOAD_MODULES line like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_PRELOAD_MODULES=&amp;quot;luks cryptodisk part_gpt lvm ext4&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, add the cryptodisk parameter :&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_ENABLE_CRYPTODISK=y&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let&#039;s show the UUID of our partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk -f&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a /root/grub-pre.cfg and replace &amp;lt;XXXX-UUID_WITHOUT_HYPHENS&amp;gt; with your encrypted lvm partition UUID (here /dev/nvme0n1p2) without hyphens, replace &amp;lt;YYYY&amp;gt; with VG UUID from vgdisplay and replace &amp;lt;ZZZZ&amp;gt; with LV UUID from lvdisplay of your /dev/vg0/root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set crypto_uuid=&amp;lt;XXXX-UUID_WITHOUT_HYPHENS&amp;gt;&lt;br /&gt;
cryptomount -u $crypto_uuid&lt;br /&gt;
set root=&#039;lvmid/&amp;lt;YYYY&amp;gt;/&amp;lt;ZZZZ&amp;gt;&#039;&lt;br /&gt;
set prefix=($root)/boot/grub&lt;br /&gt;
insmod normal&lt;br /&gt;
normal&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring Secure Boot =&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efi-mkkeys efibootmgr sbsigntool&lt;br /&gt;
# efi-mkkeys -s &amp;quot;Your Name&amp;quot; -o /etc/uefi-keys&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Re-install Grub:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /boot/efi/EFI/AlpineLinuxSecureBoot&lt;br /&gt;
# grub-mkimage -p /boot/grub -O x86_64-efi -c /root/grub-pre.cfg -o /tmp/grubx64.efi luks2 part_gpt cryptodisk lvm ext2 gcry_rijndael pbkdf2 gcry_sha512&lt;br /&gt;
# install -v /tmp/grubx64.efi /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sed -i &#039;s/SecureBoot/SecureB00t/&#039; /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi&lt;br /&gt;
# cd /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sbsign --key /etc/uefi-keys/db.key --cert /etc/uefi-keys/db.crt --output grubx64.efi.signed grubx64.efi&lt;br /&gt;
# grub-mkconfig -o /boot/grub/grub.cfg&lt;br /&gt;
# efibootmgr --disk /dev/nvme0n1p1 --part 1 --create --label &#039;Alpine Linux Secure Boot Signed&#039; --load /EFI/AlpineLinuxSecureBoot/grubx64.efi.signed --verbose&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To check that your .efi is signed :&lt;br /&gt;
&amp;lt;pre&amp;gt; # sbverify --cert /etc/uefi-keys/db.crt /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi.signed &lt;br /&gt;
Signature verification OK&lt;br /&gt;
# sbverify --list /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi.signed&lt;br /&gt;
signature 1&lt;br /&gt;
image signature issuers:&lt;br /&gt;
 - /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
image signature certificates:&lt;br /&gt;
 - subject: /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
   issuer:  /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy db.auth, KEK.auth and PK.auth files from /etc/uefi-keys to a FAT formatted file system.&lt;br /&gt;
&lt;br /&gt;
Reboot &amp;amp; enter into your UEFI (Fx key depending of your laptop)&lt;br /&gt;
&lt;br /&gt;
== Import keys to UEFI ==&lt;br /&gt;
&lt;br /&gt;
This is just an example from an XPS laptop, each UEFI is unique.&lt;br /&gt;
&lt;br /&gt;
# Go to &#039;&#039;&#039;Boot Configuration&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;Secure Boot&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Enable Secure Boot&#039;&#039;&#039; to &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Secure Boot Mode&#039;&#039;&#039; to &#039;&#039;&#039;Deployed Mode&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Enable Custom Mode&#039;&#039;&#039; to &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
# Go to &#039;&#039;&#039;Custom Mode Key Management&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Reset All Keys&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;db&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;db.auth&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;KEK&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;KEK.auth&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;PK&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;PK.auth&#039;&#039;&#039;&lt;br /&gt;
# &#039;&#039;&#039;APPLY CHANGES&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;EXIT&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Check Secure Boot State:&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add mokutil&lt;br /&gt;
# mokutil --sb-state&lt;br /&gt;
SecureBoot enabled&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Congrats!&lt;br /&gt;
&lt;br /&gt;
== Hibernate on encrypted LVM swap partition ==&lt;br /&gt;
&lt;br /&gt;
Find your vg0-swap UUID :&lt;br /&gt;
&amp;lt;pre&amp;gt;lsblk -f&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add resume parameter to your /etc/default/grub :&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_CMDLINE_LINUX_DEFAULT=....resume=UUID=&amp;lt;UUID of your vg0-swap partition&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add a line to your /etc/fstab :&lt;br /&gt;
&amp;lt;pre&amp;gt;/dev/vg0/swap   none            swap     sw    0 0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Enable swap service during boot :&lt;br /&gt;
&amp;lt;pre&amp;gt;rc-update add swap default&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Install zzz and test it&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add zzz&lt;br /&gt;
zzz- Z&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Done and congrats !&lt;/div&gt;</summary>
		<author><name>Blt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22699</id>
		<title>Full disk encryption secure boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22699"/>
		<updated>2022-11-30T17:19:02Z</updated>

		<summary type="html">&lt;p&gt;Blt: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This guide is to explain, step-by-step, how to setup Alpine Linux with Full Disk Encryption using LUKS2, LVM (one Physical Volume Partition with three Logical Volume Partitions (/ /boot &amp;amp; swap) with hibernation on a NVMe drive, with UEFI &amp;amp; Secure Boot. This guide has been written using Alpine Linux Std 3.16.1, please adapt some commands if needed.&lt;br /&gt;
&lt;br /&gt;
The goal of this guide is to follow the KISS principle, but another file system can be used, multiple partitions for /home; /var/log etc.. can also be added, if the proposed configuration is not meeting your requirements.&lt;br /&gt;
&lt;br /&gt;
= Installing packages =&lt;br /&gt;
&lt;br /&gt;
To facilitate the partitioning we will use gdisk :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lsblk gptfdisk&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For encryption, we will use cryptsetup :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add cryptsetup&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For LVM:&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lvm2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For using and managing UEFI, multiple packages are needed :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efibootmgr e2fsprogs grub grub-efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To improve the entropy :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add haveged&lt;br /&gt;
# rc-service haveged start&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Preparing / overwriting the disk =&lt;br /&gt;
&lt;br /&gt;
This can take long, on my side for a 500GB nVME it tooks ~30 minutes.&lt;br /&gt;
&amp;lt;pre&amp;gt;# haveged -n 0 | dd of=/dev/nvme0n1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Partitioning the disk =&lt;br /&gt;
&lt;br /&gt;
Let&#039;s assume the disk is /dev/nvme0n1 and no partition is present, we will create two partitions :&lt;br /&gt;
 &lt;br /&gt;
* one for UEFI&lt;br /&gt;
* one for LVM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; # gdisk /dev/nvme0n1&lt;br /&gt;
GPT fdisk (gdisk) version 1.0.9.1&lt;br /&gt;
&lt;br /&gt;
Partition table scan:&lt;br /&gt;
  MBR: not present&lt;br /&gt;
  BSD: not present&lt;br /&gt;
  APM: not present&lt;br /&gt;
  GPT: not present&lt;br /&gt;
&lt;br /&gt;
Creating new GPT entries in memory.&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (1-128, default 1): &lt;br /&gt;
First sector (34-1000215182, default = 2048) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (2048-1000215182, default = 1000214527) or {+-}size{KMGTP}: 512M&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): ef00&lt;br /&gt;
Changed type of partition to &#039;EFI system partition&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (2-128, default 2): &lt;br /&gt;
First sector (34-1000215182, default = 1050624) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (1050624-1000215182, default = 1000214527) or {+-}size{KMGTP}: &lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8309&lt;br /&gt;
Changed type of partition to &#039;Linux LUKS&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): w&lt;br /&gt;
&lt;br /&gt;
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING&lt;br /&gt;
PARTITIONS!!&lt;br /&gt;
&lt;br /&gt;
Do you want to proceed? (Y/N): Y&lt;br /&gt;
OK; writing new GUID partition table (GPT) to /dev/nvme0n1.&lt;br /&gt;
The operation has completed successfully.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring LUKS =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 1000 --use-random luksFormat /dev/nvme0n1p2&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p2 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p2: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&lt;br /&gt;
# cryptsetup luksOpen /dev/nvme0n1p2 lvmcrypt&lt;br /&gt;
&lt;br /&gt;
= LVM : Physical &amp;amp; Logical Volumes creation=&lt;br /&gt;
&amp;lt;pre&amp;gt;# pvcreate /dev/mapper/lvmcrypt&lt;br /&gt;
  Physical volume &amp;quot;/dev/mapper/lvmcrypt&amp;quot; successfully created.&lt;br /&gt;
# vgcreate vg0 /dev/mapper/lvmcrypt&lt;br /&gt;
  Volume group &amp;quot;vg0&amp;quot; successfully created&lt;br /&gt;
# lvcreate -L 20G vg0 -n swap (I have a 16GB RAM laptop)&lt;br /&gt;
  Logical volume &amp;quot;swap&amp;quot; created.&lt;br /&gt;
# lvcreate -l 100%FREE vg0 -n root&lt;br /&gt;
  Logical volume &amp;quot;root&amp;quot; created.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To check the creation :&lt;br /&gt;
&amp;lt;pre&amp;gt;# lvscan&lt;br /&gt;
  ACTIVE            &#039;/dev/vg0/swap&#039; [20.00 GiB] inherit&lt;br /&gt;
  ACTIVE            &#039;/dev/vg0/root&#039; [455.92 GiB] inherit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Mounting points and File System =&lt;br /&gt;
&lt;br /&gt;
Create vfat file system for UEFI partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.vfat /dev/nvme0n1p1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for / partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/vg0/root&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Activate SWAP:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkswap /dev/vg0/swap&lt;br /&gt;
# swapon /dev/vg0/swap&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mount / partition to /mnt :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t ext4 /dev/vg0/root /mnt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create /boot/efi:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /mnt/boot/efi -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mount UEFI partition to /mnt/boot/efi :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t vfat /dev/nvme0n1p1 /mnt/boot/efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk&lt;br /&gt;
nvme0n1        259:0    0 476.9G  0 disk  &lt;br /&gt;
├─nvme0n1p1    259:1    0   511M  0 part  /mnt/boot/efi&lt;br /&gt;
└─nvme0n1p2    259:2    0 476.4G  0 part  &lt;br /&gt;
  └─lvmcrypt   253:0    0 476.4G  0 crypt &lt;br /&gt;
    ├─vg0-swap 253:1    0    20G  0 lvm   [SWAP]&lt;br /&gt;
    └─vg0-root 253:2    0 456.4G  0 lvm   /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Installing Alpine =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# setup-disk -m sys /mnt/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= mkinitfs settings &amp;amp; modules =&lt;br /&gt;
Edit the /mnt/etc/mkinitfs/mkinitfs.conf file and append the modules to the features parameters (keymap only needed if your keyboard is not QWERTY):&lt;br /&gt;
&amp;lt;pre&amp;gt;features=&amp;quot;ata base ide scsi usb virtio ext4 lvm nvme keymap cryptsetup cryptkey resume&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Regenerate the initram:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkinitfs -c /mnt/etc/mkinitfs/mkinitfs.conf -b /mnt/ $(ls /mnt/lib/modules/)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Grub settings =&lt;br /&gt;
&lt;br /&gt;
Create a crypto_keyfile.bin to avoid typing the passphrase twice during the boot process (one for Grub partition, one for Alpine partition):&lt;br /&gt;
&amp;lt;pre&amp;gt;# touch /mnt/crypto_keyfile.bin&lt;br /&gt;
# chmod 600 /mnt/crypto_keyfile.bin&lt;br /&gt;
# dd if=/dev/random bs=512 count=4 | xxd -p -c999 | tr -d &#039;\n&#039; &amp;gt; /mnt/crypto_keyfile.bin&lt;br /&gt;
# cryptsetup luksAddKey /dev/nvme0n1p2 /mnt/crypto_keyfile.bin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, let&#039;s mount and chroot to our fresh installation:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t proc /proc /mnt/proc&lt;br /&gt;
# mount --rbind /dev /mnt/dev&lt;br /&gt;
# mount --make-rslave /mnt/dev&lt;br /&gt;
# mount --rbind /sys /mnt/sys&lt;br /&gt;
# chroot /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit /etc/default/grub and add cryptkey after cryptdm=root parameter like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_TIMEOUT=2&lt;br /&gt;
GRUB_DISABLE_SUBMENU=y&lt;br /&gt;
GRUB_DISABLE_RECOVERY=true&lt;br /&gt;
GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;modules=sd-mod,usb-storage,ext4,nvme cryptroot=UUID=XXXX cryptdm=lvmcrypt cryptkey quiet rootfstype=ext4&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add a new GRUB_PRELOAD_MODULES line like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_PRELOAD_MODULES=&amp;quot;luks cryptodisk part_gpt lvm ext4&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, add the cryptodisk parameter :&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_ENABLE_CRYPTODISK=y&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let&#039;s show the UUID of our partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk -f&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a /root/grub-pre.cfg and replace &amp;lt;XXXX-UUID_WITHOUT_HYPHENS&amp;gt; with your encrypted lvm partition UUID (here /dev/nvme0n1p2) without hyphens, replace &amp;lt;YYYY&amp;gt; with VG UUID from vgdisplay and replace &amp;lt;ZZZZ&amp;gt; with LV UUID from lvdisplay of your /dev/vg0/root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set crypto_uuid=&amp;lt;XXXX-UUID_WITHOUT_HYPHENS&amp;gt;&lt;br /&gt;
cryptomount -u $crypto_uuid&lt;br /&gt;
set root=&#039;lvmid/&amp;lt;YYYY&amp;gt;/&amp;lt;ZZZZ&amp;gt;&#039;&lt;br /&gt;
set prefix=($root)/boot/grub&lt;br /&gt;
insmod normal&lt;br /&gt;
normal&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring Secure Boot =&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efi-mkkeys efibootmgr sbsigntool&lt;br /&gt;
# efi-mkkeys -s &amp;quot;Your Name&amp;quot; -o /etc/uefi-keys&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Re-install Grub:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /boot/efi/EFI/AlpineLinuxSecureBoot&lt;br /&gt;
# grub-mkimage -p /boot/grub -O x86_64-efi -c /root/grub-pre.cfg -o /tmp/grubx64.efi luks2 part_gpt cryptodisk lvm ext2 gcry_rijndael pbkdf2 gcry_sha512&lt;br /&gt;
# install -v /tmp/grubx64.efi /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sed -i &#039;s/SecureBoot/SecureB00t/&#039; /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi&lt;br /&gt;
# cd /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sbsign --key /etc/uefi-keys/db.key --cert /etc/uefi-keys/db.crt --output grubx64.efi.signed grubx64.efi&lt;br /&gt;
# grub-mkconfig -o /boot/grub/grub.cfg&lt;br /&gt;
# efibootmgr --disk /dev/nvme0n1p1 --part 1 --create --label &#039;Alpine Linux Secure Boot Signed&#039; --load /EFI/AlpineLinuxSecureBoot/grubx64.efi.signed --verbose&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To check that your .efi is signed :&lt;br /&gt;
&amp;lt;pre&amp;gt; # sbverify --cert /etc/uefi-keys/db.crt /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi.signed &lt;br /&gt;
Signature verification OK&lt;br /&gt;
# sbverify --list /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi.signed&lt;br /&gt;
signature 1&lt;br /&gt;
image signature issuers:&lt;br /&gt;
 - /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
image signature certificates:&lt;br /&gt;
 - subject: /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
   issuer:  /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy db.auth, KEK.auth and PK.auth files from /etc/uefi-keys to a FAT formatted file system.&lt;br /&gt;
&lt;br /&gt;
Reboot &amp;amp; enter into your UEFI (Fx key depending of your laptop)&lt;br /&gt;
&lt;br /&gt;
== Import keys to UEFI ==&lt;br /&gt;
&lt;br /&gt;
This is just an example from an XPS laptop, each UEFI is unique.&lt;br /&gt;
&lt;br /&gt;
# Go to &#039;&#039;&#039;Boot Configuration&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;Secure Boot&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Enable Secure Boot&#039;&#039;&#039; to &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Secure Boot Mode&#039;&#039;&#039; to &#039;&#039;&#039;Deployed Mode&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Enable Custom Mode&#039;&#039;&#039; to &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
# Go to &#039;&#039;&#039;Custom Mode Key Management&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Reset All Keys&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;db&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;db.auth&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;KEK&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;KEK.auth&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;PK&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;PK.auth&#039;&#039;&#039;&lt;br /&gt;
# &#039;&#039;&#039;APPLY CHANGES&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;EXIT&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Check Secure Boot State:&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add mokutil&lt;br /&gt;
# mokutil --sb-state&lt;br /&gt;
SecureBoot enabled&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Congrats!&lt;br /&gt;
&lt;br /&gt;
== Hibernate on encrypted LVM swap partition ==&lt;br /&gt;
&lt;br /&gt;
Find your vg0-swap UUID :&lt;br /&gt;
&amp;lt;pre&amp;gt;lsblk -f&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add resume parameter to your /etc/default/grub :&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_CMDLINE_LINUX_DEFAULT=....resume=UUID=&amp;lt;UUID of your vg0-swap partition&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add a line to your /etc/fstab :&lt;br /&gt;
&amp;lt;pre&amp;gt;/dev/vg0/swap   none            swap     sw    0 0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Enable swap service during boot :&lt;br /&gt;
&amp;lt;pre&amp;gt;rc-update add swap default&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Install zzz and test it&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add zzz&lt;br /&gt;
zzz- Z&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Done and congrats !&lt;/div&gt;</summary>
		<author><name>Blt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22698</id>
		<title>Full disk encryption secure boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22698"/>
		<updated>2022-11-30T17:18:54Z</updated>

		<summary type="html">&lt;p&gt;Blt: two small format issues&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Draft}}&lt;br /&gt;
&lt;br /&gt;
This guide is to explain, step-by-step, how to setup Alpine Linux with Full Disk Encryption using LUKS2, LVM (one Physical Volume Partition with three Logical Volume Partitions (/ /boot &amp;amp; swap) with hibernation on a NVMe drive, with UEFI &amp;amp; Secure Boot. This guide has been written using Alpine Linux Std 3.16.1, please adapt some commands if needed.&lt;br /&gt;
&lt;br /&gt;
The goal of this guide is to follow the KISS principle, but another file system can be used, multiple partitions for /home; /var/log etc.. can also be added, if the proposed configuration is not meeting your requirements.&lt;br /&gt;
&lt;br /&gt;
= Installing packages =&lt;br /&gt;
&lt;br /&gt;
To facilitate the partitioning we will use gdisk :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lsblk gptfdisk&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For encryption, we will use cryptsetup :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add cryptsetup&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For LVM:&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lvm2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For using and managing UEFI, multiple packages are needed :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efibootmgr e2fsprogs grub grub-efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To improve the entropy :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add haveged&lt;br /&gt;
# rc-service haveged start&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Preparing / overwriting the disk =&lt;br /&gt;
&lt;br /&gt;
This can take long, on my side for a 500GB nVME it tooks ~30 minutes.&lt;br /&gt;
&amp;lt;pre&amp;gt;# haveged -n 0 | dd of=/dev/nvme0n1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Partitioning the disk =&lt;br /&gt;
&lt;br /&gt;
Let&#039;s assume the disk is /dev/nvme0n1 and no partition is present, we will create two partitions :&lt;br /&gt;
 &lt;br /&gt;
* one for UEFI&lt;br /&gt;
* one for LVM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; # gdisk /dev/nvme0n1&lt;br /&gt;
GPT fdisk (gdisk) version 1.0.9.1&lt;br /&gt;
&lt;br /&gt;
Partition table scan:&lt;br /&gt;
  MBR: not present&lt;br /&gt;
  BSD: not present&lt;br /&gt;
  APM: not present&lt;br /&gt;
  GPT: not present&lt;br /&gt;
&lt;br /&gt;
Creating new GPT entries in memory.&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (1-128, default 1): &lt;br /&gt;
First sector (34-1000215182, default = 2048) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (2048-1000215182, default = 1000214527) or {+-}size{KMGTP}: 512M&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): ef00&lt;br /&gt;
Changed type of partition to &#039;EFI system partition&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (2-128, default 2): &lt;br /&gt;
First sector (34-1000215182, default = 1050624) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (1050624-1000215182, default = 1000214527) or {+-}size{KMGTP}: &lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8309&lt;br /&gt;
Changed type of partition to &#039;Linux LUKS&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): w&lt;br /&gt;
&lt;br /&gt;
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING&lt;br /&gt;
PARTITIONS!!&lt;br /&gt;
&lt;br /&gt;
Do you want to proceed? (Y/N): Y&lt;br /&gt;
OK; writing new GUID partition table (GPT) to /dev/nvme0n1.&lt;br /&gt;
The operation has completed successfully.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring LUKS =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 1000 --use-random luksFormat /dev/nvme0n1p2&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p2 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p2: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&lt;br /&gt;
# cryptsetup luksOpen /dev/nvme0n1p2 lvmcrypt&lt;br /&gt;
&lt;br /&gt;
= LVM : Physical &amp;amp; Logical Volumes creation=&lt;br /&gt;
&amp;lt;pre&amp;gt;# pvcreate /dev/mapper/lvmcrypt&lt;br /&gt;
  Physical volume &amp;quot;/dev/mapper/lvmcrypt&amp;quot; successfully created.&lt;br /&gt;
# vgcreate vg0 /dev/mapper/lvmcrypt&lt;br /&gt;
  Volume group &amp;quot;vg0&amp;quot; successfully created&lt;br /&gt;
# lvcreate -L 20G vg0 -n swap (I have a 16GB RAM laptop)&lt;br /&gt;
  Logical volume &amp;quot;swap&amp;quot; created.&lt;br /&gt;
# lvcreate -l 100%FREE vg0 -n root&lt;br /&gt;
  Logical volume &amp;quot;root&amp;quot; created.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To check the creation :&lt;br /&gt;
&amp;lt;pre&amp;gt;# lvscan&lt;br /&gt;
  ACTIVE            &#039;/dev/vg0/swap&#039; [20.00 GiB] inherit&lt;br /&gt;
  ACTIVE            &#039;/dev/vg0/root&#039; [455.92 GiB] inherit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Mounting points and File System =&lt;br /&gt;
&lt;br /&gt;
Create vfat file system for UEFI partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.vfat /dev/nvme0n1p1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for / partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/vg0/root&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Activate SWAP:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkswap /dev/vg0/swap&lt;br /&gt;
# swapon /dev/vg0/swap&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mount / partition to /mnt :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t ext4 /dev/vg0/root /mnt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create /boot/efi:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /mnt/boot/efi -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mount UEFI partition to /mnt/boot/efi :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t vfat /dev/nvme0n1p1 /mnt/boot/efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk&lt;br /&gt;
nvme0n1        259:0    0 476.9G  0 disk  &lt;br /&gt;
├─nvme0n1p1    259:1    0   511M  0 part  /mnt/boot/efi&lt;br /&gt;
└─nvme0n1p2    259:2    0 476.4G  0 part  &lt;br /&gt;
  └─lvmcrypt   253:0    0 476.4G  0 crypt &lt;br /&gt;
    ├─vg0-swap 253:1    0    20G  0 lvm   [SWAP]&lt;br /&gt;
    └─vg0-root 253:2    0 456.4G  0 lvm   /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Installing Alpine =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# setup-disk -m sys /mnt/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= mkinitfs settings &amp;amp; modules =&lt;br /&gt;
Edit the /mnt/etc/mkinitfs/mkinitfs.conf file and append the modules to the features parameters (keymap only needed if your keyboard is not QWERTY):&lt;br /&gt;
&amp;lt;pre&amp;gt;features=&amp;quot;ata base ide scsi usb virtio ext4 lvm nvme keymap cryptsetup cryptkey resume&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Regenerate the initram:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkinitfs -c /mnt/etc/mkinitfs/mkinitfs.conf -b /mnt/ $(ls /mnt/lib/modules/)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Grub settings =&lt;br /&gt;
&lt;br /&gt;
Create a crypto_keyfile.bin to avoid typing the passphrase twice during the boot process (one for Grub partition, one for Alpine partition):&lt;br /&gt;
&amp;lt;pre&amp;gt;# touch /mnt/crypto_keyfile.bin&lt;br /&gt;
# chmod 600 /mnt/crypto_keyfile.bin&lt;br /&gt;
# dd if=/dev/random bs=512 count=4 | xxd -p -c999 | tr -d &#039;\n&#039; &amp;gt; /mnt/crypto_keyfile.bin&lt;br /&gt;
# cryptsetup luksAddKey /dev/nvme0n1p2 /mnt/crypto_keyfile.bin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, let&#039;s mount and chroot to our fresh installation:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t proc /proc /mnt/proc&lt;br /&gt;
# mount --rbind /dev /mnt/dev&lt;br /&gt;
# mount --make-rslave /mnt/dev&lt;br /&gt;
# mount --rbind /sys /mnt/sys&lt;br /&gt;
# chroot /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit /etc/default/grub and add cryptkey after cryptdm=root parameter like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_TIMEOUT=2&lt;br /&gt;
GRUB_DISABLE_SUBMENU=y&lt;br /&gt;
GRUB_DISABLE_RECOVERY=true&lt;br /&gt;
GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;modules=sd-mod,usb-storage,ext4,nvme cryptroot=UUID=XXXX cryptdm=lvmcrypt cryptkey quiet rootfstype=ext4&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add a new GRUB_PRELOAD_MODULES line like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_PRELOAD_MODULES=&amp;quot;luks cryptodisk part_gpt lvm ext4&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, add the cryptodisk parameter :&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_ENABLE_CRYPTODISK=y&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let&#039;s show the UUID of our partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk -f&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a /root/grub-pre.cfg and replace &amp;lt;XXXX-UUID_WITHOUT_HYPHENS&amp;gt; with your encrypted lvm partition UUID (here /dev/nvme0n1p2) without hyphens, replace &amp;lt;YYYY&amp;gt; with VG UUID from vgdisplay and replace &amp;lt;ZZZZ&amp;gt; with LV UUID from lvdisplay of your /dev/vg0/root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set crypto_uuid=&amp;lt;XXXX-UUID_WITHOUT_HYPHENS&amp;gt;&lt;br /&gt;
cryptomount -u $crypto_uuid&lt;br /&gt;
set root=&#039;lvmid/&amp;lt;YYYY&amp;gt;/&amp;lt;ZZZZ&amp;gt;&#039;&lt;br /&gt;
set prefix=($root)/boot/grub&lt;br /&gt;
insmod normal&lt;br /&gt;
normal&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring Secure Boot =&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efi-mkkeys efibootmgr sbsigntool&lt;br /&gt;
# efi-mkkeys -s &amp;quot;Your Name&amp;quot; -o /etc/uefi-keys&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Re-install Grub:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /boot/efi/EFI/AlpineLinuxSecureBoot&lt;br /&gt;
# grub-mkimage -p /boot/grub -O x86_64-efi -c /root/grub-pre.cfg -o /tmp/grubx64.efi luks2 part_gpt cryptodisk lvm ext2 gcry_rijndael pbkdf2 gcry_sha512&lt;br /&gt;
# install -v /tmp/grubx64.efi /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sed -i &#039;s/SecureBoot/SecureB00t/&#039; /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi&lt;br /&gt;
# cd /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sbsign --key /etc/uefi-keys/db.key --cert /etc/uefi-keys/db.crt --output grubx64.efi.signed grubx64.efi&lt;br /&gt;
# grub-mkconfig -o /boot/grub/grub.cfg&lt;br /&gt;
# efibootmgr --disk /dev/nvme0n1p1 --part 1 --create --label &#039;Alpine Linux Secure Boot Signed&#039; --load /EFI/AlpineLinuxSecureBoot/grubx64.efi.signed --verbose&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To check that your .efi is signed :&lt;br /&gt;
&amp;lt;pre&amp;gt; # sbverify --cert /etc/uefi-keys/db.crt /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi.signed &lt;br /&gt;
Signature verification OK&lt;br /&gt;
# sbverify --list /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi.signed&lt;br /&gt;
signature 1&lt;br /&gt;
image signature issuers:&lt;br /&gt;
 - /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
image signature certificates:&lt;br /&gt;
 - subject: /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
   issuer:  /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy db.auth, KEK.auth and PK.auth files from /etc/uefi-keys to a FAT formatted file system.&lt;br /&gt;
&lt;br /&gt;
Reboot &amp;amp; enter into your UEFI (Fx key depending of your laptop)&lt;br /&gt;
&lt;br /&gt;
== Import keys to UEFI ==&lt;br /&gt;
&lt;br /&gt;
This is just an example from an XPS laptop, each UEFI is unique.&lt;br /&gt;
&lt;br /&gt;
# Go to &#039;&#039;&#039;Boot Configuration&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;Secure Boot&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Enable Secure Boot&#039;&#039;&#039; to &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Secure Boot Mode&#039;&#039;&#039; to &#039;&#039;&#039;Deployed Mode&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Enable Custom Mode&#039;&#039;&#039; to &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
# Go to &#039;&#039;&#039;Custom Mode Key Management&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Reset All Keys&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;db&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;db.auth&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;KEK&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;KEK.auth&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;PK&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;PK.auth&#039;&#039;&#039;&lt;br /&gt;
# &#039;&#039;&#039;APPLY CHANGES&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;EXIT&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Check Secure Boot State:&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add mokutil&lt;br /&gt;
# mokutil --sb-state&lt;br /&gt;
SecureBoot enabled&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Congrats!&lt;br /&gt;
&lt;br /&gt;
== Hibernate on encrypted LVM swap partition ==&lt;br /&gt;
&lt;br /&gt;
Find your vg0-swap UUID :&lt;br /&gt;
&amp;lt;pre&amp;gt;lsblk -f&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add resume parameter to your /etc/default/grub :&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_CMDLINE_LINUX_DEFAULT=....resume=UUID=&amp;lt;UUID of your vg0-swap partition&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add a line to your /etc/fstab :&lt;br /&gt;
&amp;lt;pre&amp;gt;/dev/vg0/swap   none            swap     sw    0 0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Enable swap service during boot :&lt;br /&gt;
&amp;lt;pre&amp;gt;rc-update add swap default&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Install zzz and test it&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add zzz&lt;br /&gt;
zzz- Z&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Done and congrats !&lt;/div&gt;</summary>
		<author><name>Blt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22697</id>
		<title>Full disk encryption secure boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22697"/>
		<updated>2022-11-30T17:17:17Z</updated>

		<summary type="html">&lt;p&gt;Blt: done&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Draft}}&lt;br /&gt;
&lt;br /&gt;
This guide is to explain, step-by-step, how to setup Alpine Linux with Full Disk Encryption using LUKS2, LVM (one Physical Volume Partition with three Logical Volume Partitions (/ /boot &amp;amp; swap) with hibernation on a NVMe drive, with UEFI &amp;amp; Secure Boot. This guide has been written using Alpine Linux Std 3.16.1, please adapt some commands if needed.&lt;br /&gt;
&lt;br /&gt;
The goal of this guide is to follow the KISS principle, but another file system can be used, multiple partitions for /home; /var/log etc.. can also be added, if the proposed configuration is not meeting your requirements.&lt;br /&gt;
&lt;br /&gt;
= Installing packages =&lt;br /&gt;
&lt;br /&gt;
To facilitate the partitioning we will use gdisk :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lsblk gptfdisk&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For encryption, we will use cryptsetup :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add cryptsetup&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For LVM:&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lvm2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For using and managing UEFI, multiple packages are needed :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efibootmgr e2fsprogs grub grub-efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To improve the entropy :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add haveged&lt;br /&gt;
# rc-service haveged start&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Preparing / overwriting the disk =&lt;br /&gt;
&lt;br /&gt;
This can take long, on my side for a 500GB nVME it tooks ~30 minutes.&lt;br /&gt;
&amp;lt;pre&amp;gt;# haveged -n 0 | dd of=/dev/nvme0n1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Partitioning the disk =&lt;br /&gt;
&lt;br /&gt;
Let&#039;s assume the disk is /dev/nvme0n1 and no partition is present, we will create two partitions :&lt;br /&gt;
 &lt;br /&gt;
* one for UEFI&lt;br /&gt;
* one for LVM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; # gdisk /dev/nvme0n1&lt;br /&gt;
GPT fdisk (gdisk) version 1.0.9.1&lt;br /&gt;
&lt;br /&gt;
Partition table scan:&lt;br /&gt;
  MBR: not present&lt;br /&gt;
  BSD: not present&lt;br /&gt;
  APM: not present&lt;br /&gt;
  GPT: not present&lt;br /&gt;
&lt;br /&gt;
Creating new GPT entries in memory.&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (1-128, default 1): &lt;br /&gt;
First sector (34-1000215182, default = 2048) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (2048-1000215182, default = 1000214527) or {+-}size{KMGTP}: 512M&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): ef00&lt;br /&gt;
Changed type of partition to &#039;EFI system partition&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (2-128, default 2): &lt;br /&gt;
First sector (34-1000215182, default = 1050624) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (1050624-1000215182, default = 1000214527) or {+-}size{KMGTP}: &lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8309&lt;br /&gt;
Changed type of partition to &#039;Linux LUKS&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): w&lt;br /&gt;
&lt;br /&gt;
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING&lt;br /&gt;
PARTITIONS!!&lt;br /&gt;
&lt;br /&gt;
Do you want to proceed? (Y/N): Y&lt;br /&gt;
OK; writing new GUID partition table (GPT) to /dev/nvme0n1.&lt;br /&gt;
The operation has completed successfully.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring LUKS =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 1000 --use-random luksFormat /dev/nvme0n1p2&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p2 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p2: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&lt;br /&gt;
# cryptsetup luksOpen /dev/nvme0n1p2 lvmcrypt&lt;br /&gt;
&lt;br /&gt;
= LVM : Physical &amp;amp; Logical Volumes creation=&lt;br /&gt;
&amp;lt;pre&amp;gt;# pvcreate /dev/mapper/lvmcrypt&lt;br /&gt;
  Physical volume &amp;quot;/dev/mapper/lvmcrypt&amp;quot; successfully created.&lt;br /&gt;
# vgcreate vg0 /dev/mapper/lvmcrypt&lt;br /&gt;
  Volume group &amp;quot;vg0&amp;quot; successfully created&lt;br /&gt;
# lvcreate -L 20G vg0 -n swap (I have a 16GB RAM laptop)&lt;br /&gt;
  Logical volume &amp;quot;swap&amp;quot; created.&lt;br /&gt;
# lvcreate -l 100%FREE vg0 -n root&lt;br /&gt;
  Logical volume &amp;quot;root&amp;quot; created.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To check the creation :&lt;br /&gt;
&amp;lt;pre&amp;gt;# lvscan&lt;br /&gt;
  ACTIVE            &#039;/dev/vg0/swap&#039; [20.00 GiB] inherit&lt;br /&gt;
  ACTIVE            &#039;/dev/vg0/root&#039; [455.92 GiB] inherit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Mounting points and File System =&lt;br /&gt;
&lt;br /&gt;
Create vfat file system for UEFI partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.vfat /dev/nvme0n1p1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for / partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/vg0/root&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Activate SWAP:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkswap /dev/vg0/swap&lt;br /&gt;
# swapon /dev/vg0/swap&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mount / partition to /mnt :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t ext4 /dev/vg0/root /mnt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create /boot/efi:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /mnt/boot/efi -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mount UEFI partition to /mnt/boot/efi :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t vfat /dev/nvme0n1p1 /mnt/boot/efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk&lt;br /&gt;
nvme0n1        259:0    0 476.9G  0 disk  &lt;br /&gt;
├─nvme0n1p1    259:1    0   511M  0 part  /mnt/boot/efi&lt;br /&gt;
└─nvme0n1p2    259:2    0 476.4G  0 part  &lt;br /&gt;
  └─lvmcrypt   253:0    0 476.4G  0 crypt &lt;br /&gt;
    ├─vg0-swap 253:1    0    20G  0 lvm   [SWAP]&lt;br /&gt;
    └─vg0-root 253:2    0 456.4G  0 lvm   /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Installing Alpine =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# setup-disk -m sys /mnt/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= mkinitfs settings &amp;amp; modules =&lt;br /&gt;
Edit the /mnt/etc/mkinitfs/mkinitfs.conf file and append the modules to the features parameters (keymap only needed if your keyboard is not QWERTY):&lt;br /&gt;
&amp;lt;pre&amp;gt;features=&amp;quot;ata base ide scsi usb virtio ext4 lvm nvme keymap cryptsetup cryptkey resume&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Regenerate the initram:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkinitfs -c /mnt/etc/mkinitfs/mkinitfs.conf -b /mnt/ $(ls /mnt/lib/modules/)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Grub settings =&lt;br /&gt;
&lt;br /&gt;
Create a crypto_keyfile.bin to avoid typing the passphrase twice during the boot process (one for Grub partition, one for Alpine partition):&lt;br /&gt;
&amp;lt;pre&amp;gt;# touch /mnt/crypto_keyfile.bin&lt;br /&gt;
# chmod 600 /mnt/crypto_keyfile.bin&lt;br /&gt;
# dd if=/dev/random bs=512 count=4 | xxd -p -c999 | tr -d &#039;\n&#039; &amp;gt; /mnt/c&lt;br /&gt;
rypto_keyfile.bin&lt;br /&gt;
# cryptsetup luksAddKey /dev/nvme0n1p2 /mnt/crypto_keyfile.bin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, let&#039;s mount and chroot to our fresh installation:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t proc /proc /mnt/proc&lt;br /&gt;
# mount --rbind /dev /mnt/dev&lt;br /&gt;
# mount --make-rslave /mnt/dev&lt;br /&gt;
# mount --rbind /sys /mnt/sys&lt;br /&gt;
# chroot /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit /etc/default/grub and add cryptkey after cryptdm=root parameter like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_TIMEOUT=2&lt;br /&gt;
GRUB_DISABLE_SUBMENU=y&lt;br /&gt;
GRUB_DISABLE_RECOVERY=true&lt;br /&gt;
GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;modules=sd-mod,usb-storage,ext4,nvme cryptroot=UUID=XXXX cryptdm=lvmcrypt cryptkey quiet rootfstype=ext4&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add a new GRUB_PRELOAD_MODULES line like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_PRELOAD_MODULES=&amp;quot;luks cryptodisk part_gpt lvm ext4&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, add the cryptodisk parameter :&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_ENABLE_CRYPTODISK=y&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let&#039;s show the UUID of our partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk -f&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a /root/grub-pre.cfg and replace &amp;lt;XXXX-UUID_WITHOUT_HYPHENS&amp;gt; with your encrypted lvm partition UUID (here /dev/nvme0n1p2) without hyphens, replace &amp;lt;YYYY&amp;gt; with VG UUID from vgdisplay and replace &amp;lt;ZZZZ&amp;gt; with LV UUID from lvdisplay of your /dev/vg0/root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set crypto_uuid=&amp;lt;XXXX-UUID_WITHOUT_HYPHENS&amp;gt;&lt;br /&gt;
cryptomount -u $crypto_uuid&lt;br /&gt;
set root=&#039;lvmid/&amp;lt;YYYY&amp;gt;/&amp;lt;ZZZZ&amp;gt;&#039;&lt;br /&gt;
set prefix=($root)/boot/grub&lt;br /&gt;
insmod normal&lt;br /&gt;
normal&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring Secure Boot =&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efi-mkkeys efibootmgr sbsigntool&lt;br /&gt;
# efi-mkkeys -s &amp;quot;Your Name&amp;quot; -o /etc/uefi-keys&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Re-install Grub:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /boot/efi/EFI/AlpineLinuxSecureBoot&lt;br /&gt;
grub-mkimage -p /boot/grub -O x86_64-efi -c /root/grub-pre.cfg -o /tmp/grubx64.efi luks2 part_gpt cryptodisk lvm ext2 gcry_rijndael pbkdf2 gcry_sha512&lt;br /&gt;
# install -v /tmp/grubx64.efi /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sed -i &#039;s/SecureBoot/SecureB00t/&#039; /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi&lt;br /&gt;
# cd /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sbsign --key /etc/uefi-keys/db.key --cert /etc/uefi-keys/db.crt --output grubx64.efi.signed grubx64.efi&lt;br /&gt;
# grub-mkconfig -o /boot/grub/grub.cfg&lt;br /&gt;
# efibootmgr --disk /dev/nvme0n1p1 --part 1 --create --label &#039;Alpine Linux Secure Boot Signed&#039; --load /EFI/AlpineLinuxSecureBoot/grubx64.efi.signed --verbose&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To check that your .efi is signed :&lt;br /&gt;
&amp;lt;pre&amp;gt; # sbverify --cert /etc/uefi-keys/db.crt /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi.signed &lt;br /&gt;
Signature verification OK&lt;br /&gt;
# sbverify --list /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi.signed&lt;br /&gt;
signature 1&lt;br /&gt;
image signature issuers:&lt;br /&gt;
 - /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
image signature certificates:&lt;br /&gt;
 - subject: /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
   issuer:  /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy db.auth, KEK.auth and PK.auth files from /etc/uefi-keys to a FAT formatted file system.&lt;br /&gt;
&lt;br /&gt;
Reboot &amp;amp; enter into your UEFI (Fx key depending of your laptop)&lt;br /&gt;
&lt;br /&gt;
== Import keys to UEFI ==&lt;br /&gt;
&lt;br /&gt;
This is just an example from an XPS laptop, each UEFI is unique.&lt;br /&gt;
&lt;br /&gt;
# Go to &#039;&#039;&#039;Boot Configuration&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;Secure Boot&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Enable Secure Boot&#039;&#039;&#039; to &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Secure Boot Mode&#039;&#039;&#039; to &#039;&#039;&#039;Deployed Mode&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Enable Custom Mode&#039;&#039;&#039; to &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
# Go to &#039;&#039;&#039;Custom Mode Key Management&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Reset All Keys&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;db&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;db.auth&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;KEK&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;KEK.auth&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;PK&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;PK.auth&#039;&#039;&#039;&lt;br /&gt;
# &#039;&#039;&#039;APPLY CHANGES&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;EXIT&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Check Secure Boot State:&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add mokutil&lt;br /&gt;
# mokutil --sb-state&lt;br /&gt;
SecureBoot enabled&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Congrats!&lt;br /&gt;
&lt;br /&gt;
== Hibernate on encrypted LVM swap partition ==&lt;br /&gt;
&lt;br /&gt;
Find your vg0-swap UUID :&lt;br /&gt;
&amp;lt;pre&amp;gt;lsblk -f&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add resume parameter to your /etc/default/grub :&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_CMDLINE_LINUX_DEFAULT=....resume=UUID=&amp;lt;UUID of your vg0-swap partition&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add a line to your /etc/fstab :&lt;br /&gt;
&amp;lt;pre&amp;gt;/dev/vg0/swap   none            swap     sw    0 0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Enable swap service during boot :&lt;br /&gt;
&amp;lt;pre&amp;gt;rc-update add swap default&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Install zzz and test it&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add zzz&lt;br /&gt;
zzz- Z&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Done and congrats !&lt;/div&gt;</summary>
		<author><name>Blt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22214</id>
		<title>Full disk encryption secure boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22214"/>
		<updated>2022-08-08T21:35:15Z</updated>

		<summary type="html">&lt;p&gt;Blt: formating&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Draft}}&lt;br /&gt;
&lt;br /&gt;
This guide is to explain, step-by-step, how to setup Alpine Linux with Full Disk Encryption using LUKS2, LVM (one Physical Volume Partition with three Logical Volume Partitions (/ /boot &amp;amp; swap) with hibernation on a NVMe drive, with UEFI &amp;amp; Secure Boot (and hopefully tpm as well : WIP). This guide has been written using Alpine Linux Std 3.16.1, please adapt some commands if needed.&lt;br /&gt;
&lt;br /&gt;
The goal of this guide is to follow the KISS principle, but another file system can be used, multiple partitions for /home; /var/log etc.. can also be added, if the proposed configuration is not meeting your requirements.&lt;br /&gt;
&lt;br /&gt;
= Installing packages =&lt;br /&gt;
&lt;br /&gt;
To facilitate the partitioning we will use gdisk :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lsblk gptfdisk&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For encryption, we will use cryptsetup :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add cryptsetup&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For LVM:&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lvm2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For using and managing UEFI, multiple packages are needed :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efibootmgr e2fsprogs grub grub-efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To improve the entropy :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add haveged&lt;br /&gt;
# rc-service haveged start&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Preparing / overwriting the disk =&lt;br /&gt;
&lt;br /&gt;
This can take long, on my side for a 500GB nVME it tooks ~30 minutes.&lt;br /&gt;
&amp;lt;pre&amp;gt;# haveged -n 0 | dd of=/dev/nvme0n1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Partitioning the disk =&lt;br /&gt;
&lt;br /&gt;
Let&#039;s assume the disk is /dev/nvme0n1 and no partition is present, we will create two partitions :&lt;br /&gt;
 &lt;br /&gt;
* one for UEFI&lt;br /&gt;
* one for LVM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; # gdisk /dev/nvme0n1&lt;br /&gt;
GPT fdisk (gdisk) version 1.0.9.1&lt;br /&gt;
&lt;br /&gt;
Partition table scan:&lt;br /&gt;
  MBR: not present&lt;br /&gt;
  BSD: not present&lt;br /&gt;
  APM: not present&lt;br /&gt;
  GPT: not present&lt;br /&gt;
&lt;br /&gt;
Creating new GPT entries in memory.&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (1-128, default 1): &lt;br /&gt;
First sector (34-1000215182, default = 2048) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (2048-1000215182, default = 1000214527) or {+-}size{KMGTP}: 512M&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): ef00&lt;br /&gt;
Changed type of partition to &#039;EFI system partition&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (2-128, default 2): &lt;br /&gt;
First sector (34-1000215182, default = 1050624) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (1050624-1000215182, default = 1000214527) or {+-}size{KMGTP}: &lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8309&lt;br /&gt;
Changed type of partition to &#039;Linux LUKS&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): w&lt;br /&gt;
&lt;br /&gt;
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING&lt;br /&gt;
PARTITIONS!!&lt;br /&gt;
&lt;br /&gt;
Do you want to proceed? (Y/N): Y&lt;br /&gt;
OK; writing new GUID partition table (GPT) to /dev/nvme0n1.&lt;br /&gt;
The operation has completed successfully.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring LUKS =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 1000 --use-random luksFormat /dev/nvme0n1p2&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p2 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p2: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&lt;br /&gt;
# cryptsetup luksOpen /dev/nvme0n1p2 lvmcrypt&lt;br /&gt;
&lt;br /&gt;
= LVM : Physical &amp;amp; Logical Volumes creation=&lt;br /&gt;
&amp;lt;pre&amp;gt;# pvcreate /dev/mapper/lvmcrypt&lt;br /&gt;
  Physical volume &amp;quot;/dev/mapper/lvmcrypt&amp;quot; successfully created.&lt;br /&gt;
# vgcreate vg0 /dev/mapper/lvmcrypt&lt;br /&gt;
  Volume group &amp;quot;vg0&amp;quot; successfully created&lt;br /&gt;
# lvcreate -L 20G vg0 -n swap (I have a 16GB RAM laptop)&lt;br /&gt;
  Logical volume &amp;quot;swap&amp;quot; created.&lt;br /&gt;
# lvcreate -l 100%FREE vg0 -n root&lt;br /&gt;
  Logical volume &amp;quot;root&amp;quot; created.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To check the creation :&lt;br /&gt;
&amp;lt;pre&amp;gt;# lvscan&lt;br /&gt;
  ACTIVE            &#039;/dev/vg0/swap&#039; [20.00 GiB] inherit&lt;br /&gt;
  ACTIVE            &#039;/dev/vg0/root&#039; [455.92 GiB] inherit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Mounting points and File System =&lt;br /&gt;
&lt;br /&gt;
Create vfat file system for UEFI partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.vfat /dev/nvme0n1p1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for / partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/vg0/root&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Activate SWAP:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkswap /dev/vg0/swap&lt;br /&gt;
# swapon /dev/vg0/swap&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mount / partition to /mnt :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t ext4 /dev/vg0/root /mnt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create /boot/efi:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /mnt/boot/efi -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mount UEFI partition to /mnt/boot/efi :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t vfat /dev/nvme0n1p1 /mnt/boot/efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk&lt;br /&gt;
nvme0n1        259:0    0 476.9G  0 disk  &lt;br /&gt;
├─nvme0n1p1    259:1    0   511M  0 part  /mnt/boot/efi&lt;br /&gt;
└─nvme0n1p2    259:2    0 476.4G  0 part  &lt;br /&gt;
  └─lvmcrypt   253:0    0 476.4G  0 crypt &lt;br /&gt;
    ├─vg0-swap 253:1    0    20G  0 lvm   [SWAP]&lt;br /&gt;
    └─vg0-root 253:2    0 456.4G  0 lvm   /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Installing Alpine =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# setup-disk -m sys /mnt/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= mkinitfs settings &amp;amp; modules =&lt;br /&gt;
Edit the /mnt/etc/mkinitfs/mkinitfs.conf file and append the modules to the features parameters (keymap only needed if your keyboard is not QWERTY):&lt;br /&gt;
&amp;lt;pre&amp;gt;features=&amp;quot;ata base ide scsi usb virtio ext4 lvm nvme keymap cryptsetup cryptkey resume&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Regenerate the initram:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkinitfs -c /mnt/etc/mkinitfs/mkinitfs.conf -b /mnt/ $(ls /mnt/lib/modules/)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Grub settings =&lt;br /&gt;
&lt;br /&gt;
Create a crypto_keyfile.bin to avoid typing the passphrase twice during the boot process (one for Grub partition, one for Alpine partition):&lt;br /&gt;
&amp;lt;pre&amp;gt;# touch /mnt/crypto_keyfile.bin&lt;br /&gt;
# chmod 600 /mnt/crypto_keyfile.bin&lt;br /&gt;
# dd if=/dev/random bs=512 count=4 | xxd -p -c999 | tr -d &#039;\n&#039; &amp;gt; /mnt/c&lt;br /&gt;
rypto_keyfile.bin&lt;br /&gt;
# cryptsetup luksAddKey /dev/nvme0n1p2 /mnt/crypto_keyfile.bin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, let&#039;s mount and chroot to our fresh installation:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t proc /proc /mnt/proc&lt;br /&gt;
# mount --rbind /dev /mnt/dev&lt;br /&gt;
# mount --make-rslave /mnt/dev&lt;br /&gt;
# mount --rbind /sys /mnt/sys&lt;br /&gt;
# chroot /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit /etc/default/grub and add cryptkey after cryptdm=root parameter like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_TIMEOUT=2&lt;br /&gt;
GRUB_DISABLE_SUBMENU=y&lt;br /&gt;
GRUB_DISABLE_RECOVERY=true&lt;br /&gt;
GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;modules=sd-mod,usb-storage,ext4,nvme cryptroot=UUID=XXXX cryptdm=lvmcrypt cryptkey quiet rootfstype=ext4&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add a new GRUB_PRELOAD_MODULES line like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_PRELOAD_MODULES=&amp;quot;luks cryptodisk part_gpt lvm ext4&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, add the cryptodisk parameter :&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_ENABLE_CRYPTODISK=y&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let&#039;s show the UUID of our partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk -f&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a /root/grub-pre.cfg and replace &amp;lt;XXXX-UUID_WITHOUT_HYPHENS&amp;gt; with your encrypted lvm partition UUID (here /dev/nvme0n1p2) without hyphens, replace &amp;lt;YYYY&amp;gt; with VG UUID from vgdisplay and replace &amp;lt;ZZZZ&amp;gt; with LV UUID from lvdisplay of your /dev/vg0/root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set crypto_uuid=&amp;lt;XXXX-UUID_WITHOUT_HYPHENS&amp;gt;&lt;br /&gt;
cryptomount -u $crypto_uuid&lt;br /&gt;
set root=&#039;lvmid/&amp;lt;YYYY&amp;gt;/&amp;lt;ZZZZ&amp;gt;&#039;&lt;br /&gt;
set prefix=($root)/boot/grub&lt;br /&gt;
insmod normal&lt;br /&gt;
normal&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring Secure Boot =&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efi-mkkeys efibootmgr sbsigntool&lt;br /&gt;
# efi-mkkeys -s &amp;quot;Your Name&amp;quot; -o /etc/uefi-keys&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Re-install Grub:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /boot/efi/EFI/AlpineLinuxSecureBoot&lt;br /&gt;
grub-mkimage -p /boot/grub -O x86_64-efi -c /root/grub-pre.cfg -o /tmp/grubx64.efi luks2 part_gpt cryptodisk lvm ext2 gcry_rijndael pbkdf2 gcry_sha512&lt;br /&gt;
# install -v /tmp/grubx64.efi /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sed -i &#039;s/SecureBoot/SecureB00t/&#039; /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi&lt;br /&gt;
# cd /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sbsign --key /etc/uefi-keys/db.key --cert /etc/uefi-keys/db.crt --output grubx64.efi.signed grubx64.efi&lt;br /&gt;
# grub-mkconfig -o /boot/grub/grub.cfg&lt;br /&gt;
# efibootmgr --disk /dev/nvme0n1p1 --part 1 --create --label &#039;Alpine Linux Secure Boot Signed&#039; --load /EFI/AlpineLinuxSecureBoot/grubx64.efi.signed --verbose&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To check that your .efi is signed :&lt;br /&gt;
&amp;lt;pre&amp;gt; # sbverify --cert /etc/uefi-keys/db.crt /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi.signed &lt;br /&gt;
Signature verification OK&lt;br /&gt;
# sbverify --list /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi.signed&lt;br /&gt;
signature 1&lt;br /&gt;
image signature issuers:&lt;br /&gt;
 - /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
image signature certificates:&lt;br /&gt;
 - subject: /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
   issuer:  /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy db.auth, KEK.auth and PK.auth files from /etc/uefi-keys to a FAT formatted file system.&lt;br /&gt;
&lt;br /&gt;
Reboot &amp;amp; enter into your UEFI (Fx key depending of your laptop)&lt;br /&gt;
&lt;br /&gt;
== Import keys to UEFI ==&lt;br /&gt;
&lt;br /&gt;
This is just an example from an XPS laptop, each UEFI is unique.&lt;br /&gt;
&lt;br /&gt;
# Go to &#039;&#039;&#039;Boot Configuration&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;Secure Boot&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Enable Secure Boot&#039;&#039;&#039; to &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Secure Boot Mode&#039;&#039;&#039; to &#039;&#039;&#039;Deployed Mode&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Enable Custom Mode&#039;&#039;&#039; to &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
# Go to &#039;&#039;&#039;Custom Mode Key Management&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Reset All Keys&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;db&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;db.auth&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;KEK&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;KEK.auth&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;PK&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;PK.auth&#039;&#039;&#039;&lt;br /&gt;
# &#039;&#039;&#039;APPLY CHANGES&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;EXIT&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Check Secure Boot State:&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add mokutil&lt;br /&gt;
# mokutil --sb-state&lt;br /&gt;
SecureBoot enabled&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Congrats!&lt;br /&gt;
&lt;br /&gt;
== Hibernate on encrypted LVM swap partition ==&lt;br /&gt;
&lt;br /&gt;
Find your vg0-swap UUID :&lt;br /&gt;
&amp;lt;pre&amp;gt;lsblk -f&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add resume parameter to your /etc/default/grub :&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_CMDLINE_LINUX_DEFAULT=....resume=UUID=&amp;lt;UUID of your vg0-swap partition&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add a line to your /etc/fstab :&lt;br /&gt;
&amp;lt;pre&amp;gt;/dev/vg0/swap   none            swap     sw    0 0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Enable swap service during boot :&lt;br /&gt;
&amp;lt;pre&amp;gt;rc-update add swap default&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Install zzz and test it&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add zzz&lt;br /&gt;
zzz- Z&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Blt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22213</id>
		<title>Full disk encryption secure boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22213"/>
		<updated>2022-08-08T21:34:45Z</updated>

		<summary type="html">&lt;p&gt;Blt: finsh hibernate&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Draft}}&lt;br /&gt;
&lt;br /&gt;
This guide is to explain, step-by-step, how to setup Alpine Linux with Full Disk Encryption using LUKS2, LVM (one Physical Volume Partition with three Logical Volume Partitions (/ /boot &amp;amp; swap) with hibernation on a NVMe drive, with UEFI &amp;amp; Secure Boot (and hopefully tpm as well : WIP). This guide has been written using Alpine Linux Std 3.16.1, please adapt some commands if needed.&lt;br /&gt;
&lt;br /&gt;
The goal of this guide is to follow the KISS principle, but another file system can be used, multiple partitions for /home; /var/log etc.. can also be added, if the proposed configuration is not meeting your requirements.&lt;br /&gt;
&lt;br /&gt;
= Installing packages =&lt;br /&gt;
&lt;br /&gt;
To facilitate the partitioning we will use gdisk :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lsblk gptfdisk&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For encryption, we will use cryptsetup :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add cryptsetup&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For LVM:&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lvm2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For using and managing UEFI, multiple packages are needed :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efibootmgr e2fsprogs grub grub-efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To improve the entropy :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add haveged&lt;br /&gt;
# rc-service haveged start&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Preparing / overwriting the disk =&lt;br /&gt;
&lt;br /&gt;
This can take long, on my side for a 500GB nVME it tooks ~30 minutes.&lt;br /&gt;
&amp;lt;pre&amp;gt;# haveged -n 0 | dd of=/dev/nvme0n1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Partitioning the disk =&lt;br /&gt;
&lt;br /&gt;
Let&#039;s assume the disk is /dev/nvme0n1 and no partition is present, we will create two partitions :&lt;br /&gt;
 &lt;br /&gt;
* one for UEFI&lt;br /&gt;
* one for LVM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; # gdisk /dev/nvme0n1&lt;br /&gt;
GPT fdisk (gdisk) version 1.0.9.1&lt;br /&gt;
&lt;br /&gt;
Partition table scan:&lt;br /&gt;
  MBR: not present&lt;br /&gt;
  BSD: not present&lt;br /&gt;
  APM: not present&lt;br /&gt;
  GPT: not present&lt;br /&gt;
&lt;br /&gt;
Creating new GPT entries in memory.&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (1-128, default 1): &lt;br /&gt;
First sector (34-1000215182, default = 2048) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (2048-1000215182, default = 1000214527) or {+-}size{KMGTP}: 512M&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): ef00&lt;br /&gt;
Changed type of partition to &#039;EFI system partition&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (2-128, default 2): &lt;br /&gt;
First sector (34-1000215182, default = 1050624) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (1050624-1000215182, default = 1000214527) or {+-}size{KMGTP}: &lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8309&lt;br /&gt;
Changed type of partition to &#039;Linux LUKS&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): w&lt;br /&gt;
&lt;br /&gt;
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING&lt;br /&gt;
PARTITIONS!!&lt;br /&gt;
&lt;br /&gt;
Do you want to proceed? (Y/N): Y&lt;br /&gt;
OK; writing new GUID partition table (GPT) to /dev/nvme0n1.&lt;br /&gt;
The operation has completed successfully.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring LUKS =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 1000 --use-random luksFormat /dev/nvme0n1p2&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p2 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p2: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&lt;br /&gt;
# cryptsetup luksOpen /dev/nvme0n1p2 lvmcrypt&lt;br /&gt;
&lt;br /&gt;
= LVM : Physical &amp;amp; Logical Volumes creation=&lt;br /&gt;
&amp;lt;pre&amp;gt;# pvcreate /dev/mapper/lvmcrypt&lt;br /&gt;
  Physical volume &amp;quot;/dev/mapper/lvmcrypt&amp;quot; successfully created.&lt;br /&gt;
# vgcreate vg0 /dev/mapper/lvmcrypt&lt;br /&gt;
  Volume group &amp;quot;vg0&amp;quot; successfully created&lt;br /&gt;
# lvcreate -L 20G vg0 -n swap (I have a 16GB RAM laptop)&lt;br /&gt;
  Logical volume &amp;quot;swap&amp;quot; created.&lt;br /&gt;
# lvcreate -l 100%FREE vg0 -n root&lt;br /&gt;
  Logical volume &amp;quot;root&amp;quot; created.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To check the creation :&lt;br /&gt;
&amp;lt;pre&amp;gt;# lvscan&lt;br /&gt;
  ACTIVE            &#039;/dev/vg0/swap&#039; [20.00 GiB] inherit&lt;br /&gt;
  ACTIVE            &#039;/dev/vg0/root&#039; [455.92 GiB] inherit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Mounting points and File System =&lt;br /&gt;
&lt;br /&gt;
Create vfat file system for UEFI partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.vfat /dev/nvme0n1p1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for / partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/vg0/root&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Activate SWAP:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkswap /dev/vg0/swap&lt;br /&gt;
# swapon /dev/vg0/swap&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mount / partition to /mnt :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t ext4 /dev/vg0/root /mnt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create /boot/efi:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /mnt/boot/efi -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mount UEFI partition to /mnt/boot/efi :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t vfat /dev/nvme0n1p1 /mnt/boot/efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk&lt;br /&gt;
nvme0n1        259:0    0 476.9G  0 disk  &lt;br /&gt;
├─nvme0n1p1    259:1    0   511M  0 part  /mnt/boot/efi&lt;br /&gt;
└─nvme0n1p2    259:2    0 476.4G  0 part  &lt;br /&gt;
  └─lvmcrypt   253:0    0 476.4G  0 crypt &lt;br /&gt;
    ├─vg0-swap 253:1    0    20G  0 lvm   [SWAP]&lt;br /&gt;
    └─vg0-root 253:2    0 456.4G  0 lvm   /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Installing Alpine =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# setup-disk -m sys /mnt/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= mkinitfs settings &amp;amp; modules =&lt;br /&gt;
Edit the /mnt/etc/mkinitfs/mkinitfs.conf file and append the modules to the features parameters (keymap only needed if your keyboard is not QWERTY):&lt;br /&gt;
&amp;lt;pre&amp;gt;features=&amp;quot;ata base ide scsi usb virtio ext4 lvm nvme keymap cryptsetup cryptkey resume&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Regenerate the initram:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkinitfs -c /mnt/etc/mkinitfs/mkinitfs.conf -b /mnt/ $(ls /mnt/lib/modules/)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Grub settings =&lt;br /&gt;
&lt;br /&gt;
Create a crypto_keyfile.bin to avoid typing the passphrase twice during the boot process (one for Grub partition, one for Alpine partition):&lt;br /&gt;
&amp;lt;pre&amp;gt;# touch /mnt/crypto_keyfile.bin&lt;br /&gt;
# chmod 600 /mnt/crypto_keyfile.bin&lt;br /&gt;
# dd if=/dev/random bs=512 count=4 | xxd -p -c999 | tr -d &#039;\n&#039; &amp;gt; /mnt/c&lt;br /&gt;
rypto_keyfile.bin&lt;br /&gt;
# cryptsetup luksAddKey /dev/nvme0n1p2 /mnt/crypto_keyfile.bin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, let&#039;s mount and chroot to our fresh installation:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t proc /proc /mnt/proc&lt;br /&gt;
# mount --rbind /dev /mnt/dev&lt;br /&gt;
# mount --make-rslave /mnt/dev&lt;br /&gt;
# mount --rbind /sys /mnt/sys&lt;br /&gt;
# chroot /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit /etc/default/grub and add cryptkey after cryptdm=root parameter like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_TIMEOUT=2&lt;br /&gt;
GRUB_DISABLE_SUBMENU=y&lt;br /&gt;
GRUB_DISABLE_RECOVERY=true&lt;br /&gt;
GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;modules=sd-mod,usb-storage,ext4,nvme cryptroot=UUID=XXXX cryptdm=lvmcrypt cryptkey quiet rootfstype=ext4&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add a new GRUB_PRELOAD_MODULES line like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_PRELOAD_MODULES=&amp;quot;luks cryptodisk part_gpt lvm ext4&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, add the cryptodisk parameter :&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_ENABLE_CRYPTODISK=y&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let&#039;s show the UUID of our partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk -f&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a /root/grub-pre.cfg and replace &amp;lt;XXXX-UUID_WITHOUT_HYPHENS&amp;gt; with your encrypted lvm partition UUID (here /dev/nvme0n1p2) without hyphens, replace &amp;lt;YYYY&amp;gt; with VG UUID from vgdisplay and replace &amp;lt;ZZZZ&amp;gt; with LV UUID from lvdisplay of your /dev/vg0/root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set crypto_uuid=&amp;lt;XXXX-UUID_WITHOUT_HYPHENS&amp;gt;&lt;br /&gt;
cryptomount -u $crypto_uuid&lt;br /&gt;
set root=&#039;lvmid/&amp;lt;YYYY&amp;gt;/&amp;lt;ZZZZ&amp;gt;&#039;&lt;br /&gt;
set prefix=($root)/boot/grub&lt;br /&gt;
insmod normal&lt;br /&gt;
normal&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring Secure Boot =&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efi-mkkeys efibootmgr sbsigntool&lt;br /&gt;
# efi-mkkeys -s &amp;quot;Your Name&amp;quot; -o /etc/uefi-keys&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Re-install Grub:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /boot/efi/EFI/AlpineLinuxSecureBoot&lt;br /&gt;
grub-mkimage -p /boot/grub -O x86_64-efi -c /root/grub-pre.cfg -o /tmp/grubx64.efi luks2 part_gpt cryptodisk lvm ext2 gcry_rijndael pbkdf2 gcry_sha512&lt;br /&gt;
# install -v /tmp/grubx64.efi /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sed -i &#039;s/SecureBoot/SecureB00t/&#039; /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi&lt;br /&gt;
# cd /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sbsign --key /etc/uefi-keys/db.key --cert /etc/uefi-keys/db.crt --output grubx64.efi.signed grubx64.efi&lt;br /&gt;
# grub-mkconfig -o /boot/grub/grub.cfg&lt;br /&gt;
# efibootmgr --disk /dev/nvme0n1p1 --part 1 --create --label &#039;Alpine Linux Secure Boot Signed&#039; --load /EFI/AlpineLinuxSecureBoot/grubx64.efi.signed --verbose&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To check that your .efi is signed :&lt;br /&gt;
&amp;lt;pre&amp;gt; # sbverify --cert /etc/uefi-keys/db.crt /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi.signed &lt;br /&gt;
Signature verification OK&lt;br /&gt;
# sbverify --list /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi.signed&lt;br /&gt;
signature 1&lt;br /&gt;
image signature issuers:&lt;br /&gt;
 - /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
image signature certificates:&lt;br /&gt;
 - subject: /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
   issuer:  /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy db.auth, KEK.auth and PK.auth files from /etc/uefi-keys to a FAT formatted file system.&lt;br /&gt;
&lt;br /&gt;
Reboot &amp;amp; enter into your UEFI (Fx key depending of your laptop)&lt;br /&gt;
&lt;br /&gt;
== Import keys to UEFI ==&lt;br /&gt;
&lt;br /&gt;
This is just an example from an XPS laptop, each UEFI is unique.&lt;br /&gt;
&lt;br /&gt;
# Go to &#039;&#039;&#039;Boot Configuration&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;Secure Boot&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Enable Secure Boot&#039;&#039;&#039; to &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Secure Boot Mode&#039;&#039;&#039; to &#039;&#039;&#039;Deployed Mode&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Enable Custom Mode&#039;&#039;&#039; to &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
# Go to &#039;&#039;&#039;Custom Mode Key Management&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Reset All Keys&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;db&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;db.auth&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;KEK&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;KEK.auth&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;PK&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;PK.auth&#039;&#039;&#039;&lt;br /&gt;
# &#039;&#039;&#039;APPLY CHANGES&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;EXIT&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Check Secure Boot State:&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add mokutil&lt;br /&gt;
# mokutil --sb-state&lt;br /&gt;
SecureBoot enabled&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Congrats!&lt;br /&gt;
&lt;br /&gt;
== Hibernate on encrypted LVM swap partition ==&lt;br /&gt;
&lt;br /&gt;
Find your vg0-swap UUID :&lt;br /&gt;
&amp;lt;pre&amp;gt;lsblk -f&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add resume parameter to your /etc/default/grub :&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_CMDLINE_LINUX_DEFAULT=....resume=UUID=&amp;lt;UUID of your vg0-swap partition&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add a line to your /etc/fstab :&lt;br /&gt;
&amp;lt;pre&amp;gt;/dev/vg0/swap   none            swap     sw    0 0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Enable swap service during boot :&lt;br /&gt;
&amp;lt;pre&amp;gt;rc-update add swap default&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Install zzz and test it&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add zzz&lt;br /&gt;
zzz- Z&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Blt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22212</id>
		<title>Full disk encryption secure boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22212"/>
		<updated>2022-08-08T11:44:03Z</updated>

		<summary type="html">&lt;p&gt;Blt: add resume and hibernate section&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Draft}}&lt;br /&gt;
&lt;br /&gt;
This guide is to explain, step-by-step, how to setup Alpine Linux with Full Disk Encryption using LUKS2, LVM (one Physical Volume Partition with three Logical Volume Partitions (/ /boot &amp;amp; swap) with hibernation on a NVMe drive, with UEFI &amp;amp; Secure Boot (and hopefully tpm as well : WIP). This guide has been written using Alpine Linux Std 3.16.1, please adapt some commands if needed.&lt;br /&gt;
&lt;br /&gt;
The goal of this guide is to follow the KISS principle, but another file system can be used, multiple partitions for /home; /var/log etc.. can also be added, if the proposed configuration is not meeting your requirements.&lt;br /&gt;
&lt;br /&gt;
= Installing packages =&lt;br /&gt;
&lt;br /&gt;
To facilitate the partitioning we will use gdisk :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lsblk gptfdisk&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For encryption, we will use cryptsetup :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add cryptsetup&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For LVM:&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lvm2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For using and managing UEFI, multiple packages are needed :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efibootmgr e2fsprogs grub grub-efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To improve the entropy :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add haveged&lt;br /&gt;
# rc-service haveged start&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Preparing / overwriting the disk =&lt;br /&gt;
&lt;br /&gt;
This can take long, on my side for a 500GB nVME it tooks ~30 minutes.&lt;br /&gt;
&amp;lt;pre&amp;gt;# haveged -n 0 | dd of=/dev/nvme0n1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Partitioning the disk =&lt;br /&gt;
&lt;br /&gt;
Let&#039;s assume the disk is /dev/nvme0n1 and no partition is present, we will create two partitions :&lt;br /&gt;
 &lt;br /&gt;
* one for UEFI&lt;br /&gt;
* one for LVM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; # gdisk /dev/nvme0n1&lt;br /&gt;
GPT fdisk (gdisk) version 1.0.9.1&lt;br /&gt;
&lt;br /&gt;
Partition table scan:&lt;br /&gt;
  MBR: not present&lt;br /&gt;
  BSD: not present&lt;br /&gt;
  APM: not present&lt;br /&gt;
  GPT: not present&lt;br /&gt;
&lt;br /&gt;
Creating new GPT entries in memory.&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (1-128, default 1): &lt;br /&gt;
First sector (34-1000215182, default = 2048) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (2048-1000215182, default = 1000214527) or {+-}size{KMGTP}: 512M&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): ef00&lt;br /&gt;
Changed type of partition to &#039;EFI system partition&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (2-128, default 2): &lt;br /&gt;
First sector (34-1000215182, default = 1050624) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (1050624-1000215182, default = 1000214527) or {+-}size{KMGTP}: &lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8309&lt;br /&gt;
Changed type of partition to &#039;Linux LUKS&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): w&lt;br /&gt;
&lt;br /&gt;
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING&lt;br /&gt;
PARTITIONS!!&lt;br /&gt;
&lt;br /&gt;
Do you want to proceed? (Y/N): Y&lt;br /&gt;
OK; writing new GUID partition table (GPT) to /dev/nvme0n1.&lt;br /&gt;
The operation has completed successfully.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring LUKS =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 1000 --use-random luksFormat /dev/nvme0n1p2&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p2 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p2: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&lt;br /&gt;
# cryptsetup luksOpen /dev/nvme0n1p2 lvmcrypt&lt;br /&gt;
&lt;br /&gt;
= LVM : Physical &amp;amp; Logical Volumes creation=&lt;br /&gt;
&amp;lt;pre&amp;gt;# pvcreate /dev/mapper/lvmcrypt&lt;br /&gt;
  Physical volume &amp;quot;/dev/mapper/lvmcrypt&amp;quot; successfully created.&lt;br /&gt;
# vgcreate vg0 /dev/mapper/lvmcrypt&lt;br /&gt;
  Volume group &amp;quot;vg0&amp;quot; successfully created&lt;br /&gt;
# lvcreate -L 20G vg0 -n swap (I have a 16GB RAM laptop)&lt;br /&gt;
  Logical volume &amp;quot;swap&amp;quot; created.&lt;br /&gt;
# lvcreate -l 100%FREE vg0 -n root&lt;br /&gt;
  Logical volume &amp;quot;root&amp;quot; created.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To check the creation :&lt;br /&gt;
&amp;lt;pre&amp;gt;# lvscan&lt;br /&gt;
  ACTIVE            &#039;/dev/vg0/swap&#039; [20.00 GiB] inherit&lt;br /&gt;
  ACTIVE            &#039;/dev/vg0/root&#039; [455.92 GiB] inherit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Mounting points and File System =&lt;br /&gt;
&lt;br /&gt;
Create vfat file system for UEFI partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.vfat /dev/nvme0n1p1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for / partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/vg0/root&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Activate SWAP:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkswap /dev/vg0/swap&lt;br /&gt;
# swapon /dev/vg0/swap&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mount / partition to /mnt :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t ext4 /dev/vg0/root /mnt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create /boot/efi:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /mnt/boot/efi -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mount UEFI partition to /mnt/boot/efi :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t vfat /dev/nvme0n1p1 /mnt/boot/efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk&lt;br /&gt;
nvme0n1        259:0    0 476.9G  0 disk  &lt;br /&gt;
├─nvme0n1p1    259:1    0   511M  0 part  /mnt/boot/efi&lt;br /&gt;
└─nvme0n1p2    259:2    0 476.4G  0 part  &lt;br /&gt;
  └─lvmcrypt   253:0    0 476.4G  0 crypt &lt;br /&gt;
    ├─vg0-swap 253:1    0    20G  0 lvm   [SWAP]&lt;br /&gt;
    └─vg0-root 253:2    0 456.4G  0 lvm   /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Installing Alpine =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# setup-disk -m sys /mnt/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= mkinitfs settings &amp;amp; modules =&lt;br /&gt;
Edit the /mnt/etc/mkinitfs/mkinitfs.conf file and append the modules to the features parameters (keymap only needed if your keyboard is not QWERTY):&lt;br /&gt;
&amp;lt;pre&amp;gt;features=&amp;quot;ata base ide scsi usb virtio ext4 lvm nvme keymap cryptsetup cryptkey resume&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Regenerate the initram:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkinitfs -c /mnt/etc/mkinitfs/mkinitfs.conf -b /mnt/ $(ls /mnt/lib/modules/)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Grub settings =&lt;br /&gt;
&lt;br /&gt;
Create a crypto_keyfile.bin to avoid typing the passphrase twice during the boot process (one for Grub partition, one for Alpine partition):&lt;br /&gt;
&amp;lt;pre&amp;gt;# touch /mnt/crypto_keyfile.bin&lt;br /&gt;
# chmod 600 /mnt/crypto_keyfile.bin&lt;br /&gt;
# dd if=/dev/random bs=512 count=4 | xxd -p -c999 | tr -d &#039;\n&#039; &amp;gt; /mnt/c&lt;br /&gt;
rypto_keyfile.bin&lt;br /&gt;
# cryptsetup luksAddKey /dev/nvme0n1p2 /mnt/crypto_keyfile.bin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, let&#039;s mount and chroot to our fresh installation:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t proc /proc /mnt/proc&lt;br /&gt;
# mount --rbind /dev /mnt/dev&lt;br /&gt;
# mount --make-rslave /mnt/dev&lt;br /&gt;
# mount --rbind /sys /mnt/sys&lt;br /&gt;
# chroot /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit /etc/default/grub and add cryptkey after cryptdm=root parameter like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_TIMEOUT=2&lt;br /&gt;
GRUB_DISABLE_SUBMENU=y&lt;br /&gt;
GRUB_DISABLE_RECOVERY=true&lt;br /&gt;
GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;modules=sd-mod,usb-storage,ext4,nvme cryptroot=UUID=XXXX cryptdm=lvmcrypt cryptkey quiet rootfstype=ext4&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add a new GRUB_PRELOAD_MODULES line like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_PRELOAD_MODULES=&amp;quot;luks cryptodisk part_gpt lvm ext4&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, add the cryptodisk parameter :&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_ENABLE_CRYPTODISK=y&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let&#039;s show the UUID of our partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk -f&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a /root/grub-pre.cfg and replace &amp;lt;XXXX-UUID_WITHOUT_HYPHENS&amp;gt; with your encrypted lvm partition UUID (here /dev/nvme0n1p2) without hyphens, replace &amp;lt;YYYY&amp;gt; with VG UUID from vgdisplay and replace &amp;lt;ZZZZ&amp;gt; with LV UUID from lvdisplay of your /dev/vg0/root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set crypto_uuid=&amp;lt;XXXX-UUID_WITHOUT_HYPHENS&amp;gt;&lt;br /&gt;
cryptomount -u $crypto_uuid&lt;br /&gt;
set root=&#039;lvmid/&amp;lt;YYYY&amp;gt;/&amp;lt;ZZZZ&amp;gt;&#039;&lt;br /&gt;
set prefix=($root)/boot/grub&lt;br /&gt;
insmod normal&lt;br /&gt;
normal&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring Secure Boot =&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efi-mkkeys efibootmgr sbsigntool&lt;br /&gt;
# efi-mkkeys -s &amp;quot;Your Name&amp;quot; -o /etc/uefi-keys&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Re-install Grub:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /boot/efi/EFI/AlpineLinuxSecureBoot&lt;br /&gt;
grub-mkimage -p /boot/grub -O x86_64-efi -c /root/grub-pre.cfg -o /tmp/grubx64.efi luks2 part_gpt cryptodisk lvm ext2 gcry_rijndael pbkdf2 gcry_sha512&lt;br /&gt;
# install -v /tmp/grubx64.efi /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sed -i &#039;s/SecureBoot/SecureB00t/&#039; /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi&lt;br /&gt;
# cd /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sbsign --key /etc/uefi-keys/db.key --cert /etc/uefi-keys/db.crt --output grubx64.efi.signed grubx64.efi&lt;br /&gt;
# grub-mkconfig -o /boot/grub/grub.cfg&lt;br /&gt;
# efibootmgr --disk /dev/nvme0n1p1 --part 1 --create --label &#039;Alpine Linux Secure Boot Signed&#039; --load /EFI/AlpineLinuxSecureBoot/grubx64.efi.signed --verbose&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To check that your .efi is signed :&lt;br /&gt;
&amp;lt;pre&amp;gt; # sbverify --cert /etc/uefi-keys/db.crt /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi.signed &lt;br /&gt;
Signature verification OK&lt;br /&gt;
# sbverify --list /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi.signed&lt;br /&gt;
signature 1&lt;br /&gt;
image signature issuers:&lt;br /&gt;
 - /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
image signature certificates:&lt;br /&gt;
 - subject: /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
   issuer:  /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy db.auth, KEK.auth and PK.auth files from /etc/uefi-keys to a FAT formatted file system.&lt;br /&gt;
&lt;br /&gt;
Reboot &amp;amp; enter into your UEFI (Fx key depending of your laptop)&lt;br /&gt;
&lt;br /&gt;
== Import keys to UEFI ==&lt;br /&gt;
&lt;br /&gt;
This is just an example from an XPS laptop, each UEFI is unique.&lt;br /&gt;
&lt;br /&gt;
# Go to &#039;&#039;&#039;Boot Configuration&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;Secure Boot&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Enable Secure Boot&#039;&#039;&#039; to &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Secure Boot Mode&#039;&#039;&#039; to &#039;&#039;&#039;Deployed Mode&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Enable Custom Mode&#039;&#039;&#039; to &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
# Go to &#039;&#039;&#039;Custom Mode Key Management&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Reset All Keys&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;db&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;db.auth&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;KEK&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;KEK.auth&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;PK&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;PK.auth&#039;&#039;&#039;&lt;br /&gt;
# &#039;&#039;&#039;APPLY CHANGES&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;EXIT&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Check Secure Boot State:&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add mokutil&lt;br /&gt;
# mokutil --sb-state&lt;br /&gt;
SecureBoot enabled&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Congrats!&lt;br /&gt;
&lt;br /&gt;
== Hibernate on encrypted LVM swap partition ==&lt;br /&gt;
&lt;br /&gt;
Add a line to your /etc/fstab :&lt;br /&gt;
&amp;lt;pre&amp;gt;/dev/vg0/swap   none            swap     sw    0 0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Enable swap service during boot :&lt;br /&gt;
&amp;lt;pre&amp;gt;rc-update add swap default&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Blt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22211</id>
		<title>Full disk encryption secure boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22211"/>
		<updated>2022-08-08T10:20:31Z</updated>

		<summary type="html">&lt;p&gt;Blt: ordering issue&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Draft}}&lt;br /&gt;
&lt;br /&gt;
This guide is to explain, step-by-step, how to setup Alpine Linux with Full Disk Encryption using LUKS2, LVM (one Physical Volume Partition with three Logical Volume Partitions (/ /boot &amp;amp; swap) with hibernation on a NVMe drive, with UEFI &amp;amp; Secure Boot (and hopefully tpm as well : WIP). This guide has been written using Alpine Linux Std 3.16.1, please adapt some commands if needed.&lt;br /&gt;
&lt;br /&gt;
The goal of this guide is to follow the KISS principle, but another file system can be used, multiple partitions for /home; /var/log etc.. can also be added, if the proposed configuration is not meeting your requirements.&lt;br /&gt;
&lt;br /&gt;
= Installing packages =&lt;br /&gt;
&lt;br /&gt;
To facilitate the partitioning we will use gdisk :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lsblk gptfdisk&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For encryption, we will use cryptsetup :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add cryptsetup&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For LVM:&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lvm2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For using and managing UEFI, multiple packages are needed :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efibootmgr e2fsprogs grub grub-efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To improve the entropy :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add haveged&lt;br /&gt;
# rc-service haveged start&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Preparing / overwriting the disk =&lt;br /&gt;
&lt;br /&gt;
This can take long, on my side for a 500GB nVME it tooks ~30 minutes.&lt;br /&gt;
&amp;lt;pre&amp;gt;# haveged -n 0 | dd of=/dev/nvme0n1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Partitioning the disk =&lt;br /&gt;
&lt;br /&gt;
Let&#039;s assume the disk is /dev/nvme0n1 and no partition is present, we will create two partitions :&lt;br /&gt;
 &lt;br /&gt;
* one for UEFI&lt;br /&gt;
* one for LVM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; # gdisk /dev/nvme0n1&lt;br /&gt;
GPT fdisk (gdisk) version 1.0.9.1&lt;br /&gt;
&lt;br /&gt;
Partition table scan:&lt;br /&gt;
  MBR: not present&lt;br /&gt;
  BSD: not present&lt;br /&gt;
  APM: not present&lt;br /&gt;
  GPT: not present&lt;br /&gt;
&lt;br /&gt;
Creating new GPT entries in memory.&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (1-128, default 1): &lt;br /&gt;
First sector (34-1000215182, default = 2048) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (2048-1000215182, default = 1000214527) or {+-}size{KMGTP}: 512M&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): ef00&lt;br /&gt;
Changed type of partition to &#039;EFI system partition&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (2-128, default 2): &lt;br /&gt;
First sector (34-1000215182, default = 1050624) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (1050624-1000215182, default = 1000214527) or {+-}size{KMGTP}: &lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8309&lt;br /&gt;
Changed type of partition to &#039;Linux LUKS&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): w&lt;br /&gt;
&lt;br /&gt;
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING&lt;br /&gt;
PARTITIONS!!&lt;br /&gt;
&lt;br /&gt;
Do you want to proceed? (Y/N): Y&lt;br /&gt;
OK; writing new GUID partition table (GPT) to /dev/nvme0n1.&lt;br /&gt;
The operation has completed successfully.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring LUKS =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 1000 --use-random luksFormat /dev/nvme0n1p2&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p2 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p2: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&lt;br /&gt;
# cryptsetup luksOpen /dev/nvme0n1p2 lvmcrypt&lt;br /&gt;
&lt;br /&gt;
= LVM : Physical &amp;amp; Logical Volumes creation=&lt;br /&gt;
&amp;lt;pre&amp;gt;# pvcreate /dev/mapper/lvmcrypt&lt;br /&gt;
  Physical volume &amp;quot;/dev/mapper/lvmcrypt&amp;quot; successfully created.&lt;br /&gt;
# vgcreate vg0 /dev/mapper/lvmcrypt&lt;br /&gt;
  Volume group &amp;quot;vg0&amp;quot; successfully created&lt;br /&gt;
# lvcreate -L 20G vg0 -n swap (I have a 16GB RAM laptop)&lt;br /&gt;
  Logical volume &amp;quot;swap&amp;quot; created.&lt;br /&gt;
# lvcreate -l 100%FREE vg0 -n root&lt;br /&gt;
  Logical volume &amp;quot;root&amp;quot; created.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To check the creation :&lt;br /&gt;
&amp;lt;pre&amp;gt;# lvscan&lt;br /&gt;
  ACTIVE            &#039;/dev/vg0/swap&#039; [20.00 GiB] inherit&lt;br /&gt;
  ACTIVE            &#039;/dev/vg0/root&#039; [455.92 GiB] inherit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Mounting points and File System =&lt;br /&gt;
&lt;br /&gt;
Create vfat file system for UEFI partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.vfat /dev/nvme0n1p1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for / partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/vg0/root&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Activate SWAP:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkswap /dev/vg0/swap&lt;br /&gt;
# swapon /dev/vg0/swap&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mount / partition to /mnt :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t ext4 /dev/vg0/root /mnt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create /boot/efi:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /mnt/boot/efi -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mount UEFI partition to /mnt/boot/efi :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t vfat /dev/nvme0n1p1 /mnt/boot/efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk&lt;br /&gt;
nvme0n1        259:0    0 476.9G  0 disk  &lt;br /&gt;
├─nvme0n1p1    259:1    0   511M  0 part  /mnt/boot/efi&lt;br /&gt;
└─nvme0n1p2    259:2    0 476.4G  0 part  &lt;br /&gt;
  └─lvmcrypt   253:0    0 476.4G  0 crypt &lt;br /&gt;
    ├─vg0-swap 253:1    0    20G  0 lvm   [SWAP]&lt;br /&gt;
    └─vg0-root 253:2    0 456.4G  0 lvm   /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Installing Alpine =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# setup-disk -m sys /mnt/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= mkinitfs settings &amp;amp; modules =&lt;br /&gt;
Edit the /mnt/etc/mkinitfs/mkinitfs.conf file and append the modules to the features parameters (keymap only needed if your keyboard is not QWERTY):&lt;br /&gt;
&amp;lt;pre&amp;gt;features=&amp;quot;ata base ide scsi usb virtio ext4 lvm nvme keymap cryptsetup cryptkey&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Regenerate the initram:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkinitfs -c /mnt/etc/mkinitfs/mkinitfs.conf -b /mnt/ $(ls /mnt/lib/modules/)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Grub settings =&lt;br /&gt;
&lt;br /&gt;
Create a crypto_keyfile.bin to avoid typing the passphrase twice during the boot process (one for Grub partition, one for Alpine partition):&lt;br /&gt;
&amp;lt;pre&amp;gt;# touch /mnt/crypto_keyfile.bin&lt;br /&gt;
# chmod 600 /mnt/crypto_keyfile.bin&lt;br /&gt;
# dd if=/dev/random bs=512 count=4 | xxd -p -c999 | tr -d &#039;\n&#039; &amp;gt; /mnt/c&lt;br /&gt;
rypto_keyfile.bin&lt;br /&gt;
# cryptsetup luksAddKey /dev/nvme0n1p2 /mnt/crypto_keyfile.bin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, let&#039;s mount and chroot to our fresh installation:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t proc /proc /mnt/proc&lt;br /&gt;
# mount --rbind /dev /mnt/dev&lt;br /&gt;
# mount --make-rslave /mnt/dev&lt;br /&gt;
# mount --rbind /sys /mnt/sys&lt;br /&gt;
# chroot /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit /etc/default/grub and add cryptkey after cryptdm=root parameter like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_TIMEOUT=2&lt;br /&gt;
GRUB_DISABLE_SUBMENU=y&lt;br /&gt;
GRUB_DISABLE_RECOVERY=true&lt;br /&gt;
GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;modules=sd-mod,usb-storage,ext4,nvme cryptroot=UUID=XXXX cryptdm=lvmcrypt cryptkey quiet rootfstype=ext4&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add a new GRUB_PRELOAD_MODULES line like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_PRELOAD_MODULES=&amp;quot;luks cryptodisk part_gpt lvm ext4&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, add the cryptodisk parameter :&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_ENABLE_CRYPTODISK=y&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let&#039;s show the UUID of our partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk -f&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a /root/grub-pre.cfg and replace &amp;lt;XXXX-UUID_WITHOUT_HYPHENS&amp;gt; with your encrypted lvm partition UUID (here /dev/nvme0n1p2) without hyphens, replace &amp;lt;YYYY&amp;gt; with VG UUID from vgdisplay and replace &amp;lt;ZZZZ&amp;gt; with LV UUID from lvdisplay of your /dev/vg0/root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set crypto_uuid=&amp;lt;XXXX-UUID_WITHOUT_HYPHENS&amp;gt;&lt;br /&gt;
cryptomount -u $crypto_uuid&lt;br /&gt;
set root=&#039;lvmid/&amp;lt;YYYY&amp;gt;/&amp;lt;ZZZZ&amp;gt;&#039;&lt;br /&gt;
set prefix=($root)/boot/grub&lt;br /&gt;
insmod normal&lt;br /&gt;
normal&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring Secure Boot =&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efi-mkkeys efibootmgr sbsigntool&lt;br /&gt;
# efi-mkkeys -s &amp;quot;Your Name&amp;quot; -o /etc/uefi-keys&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Re-install Grub:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /boot/efi/EFI/AlpineLinuxSecureBoot&lt;br /&gt;
grub-mkimage -p /boot/grub -O x86_64-efi -c /root/grub-pre.cfg -o /tmp/grubx64.efi luks2 part_gpt cryptodisk lvm ext2 gcry_rijndael pbkdf2 gcry_sha512&lt;br /&gt;
# install -v /tmp/grubx64.efi /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sed -i &#039;s/SecureBoot/SecureB00t/&#039; /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi&lt;br /&gt;
# cd /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sbsign --key /etc/uefi-keys/db.key --cert /etc/uefi-keys/db.crt --output grubx64.efi.signed grubx64.efi&lt;br /&gt;
# grub-mkconfig -o /boot/grub/grub.cfg&lt;br /&gt;
# efibootmgr --disk /dev/nvme0n1p1 --part 1 --create --label &#039;Alpine Linux Secure Boot Signed&#039; --load /EFI/AlpineLinuxSecureBoot/grubx64.efi.signed --verbose&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To check that your .efi is signed :&lt;br /&gt;
&amp;lt;pre&amp;gt; # sbverify --cert /etc/uefi-keys/db.crt /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi.signed &lt;br /&gt;
Signature verification OK&lt;br /&gt;
# sbverify --list /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi.signed&lt;br /&gt;
signature 1&lt;br /&gt;
image signature issuers:&lt;br /&gt;
 - /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
image signature certificates:&lt;br /&gt;
 - subject: /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
   issuer:  /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Copy db.auth, KEK.auth and PK.auth files from /etc/uefi-keys to a FAT formatted file system.&lt;br /&gt;
&lt;br /&gt;
Reboot &amp;amp; enter into your UEFI (Fx key depending of your laptop)&lt;br /&gt;
&lt;br /&gt;
== Import keys to UEFI ==&lt;br /&gt;
&lt;br /&gt;
This is just an example from an XPS laptop, each UEFI is unique.&lt;br /&gt;
&lt;br /&gt;
# Go to &#039;&#039;&#039;Boot Configuration&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;Secure Boot&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Enable Secure Boot&#039;&#039;&#039; to &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Secure Boot Mode&#039;&#039;&#039; to &#039;&#039;&#039;Deployed Mode&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Enable Custom Mode&#039;&#039;&#039; to &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
# Go to &#039;&#039;&#039;Custom Mode Key Management&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Reset All Keys&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;db&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;db.auth&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;KEK&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;KEK.auth&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;PK&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;PK.auth&#039;&#039;&#039;&lt;br /&gt;
# &#039;&#039;&#039;APPLY CHANGES&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;EXIT&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Check Secure Boot State:&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add mokutil&lt;br /&gt;
# mokutil --sb-state&lt;br /&gt;
SecureBoot enabled&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Congrats!&lt;/div&gt;</summary>
		<author><name>Blt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22210</id>
		<title>Full disk encryption secure boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22210"/>
		<updated>2022-08-08T10:16:54Z</updated>

		<summary type="html">&lt;p&gt;Blt: missing lvm in grub-mkimage&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Draft}}&lt;br /&gt;
&lt;br /&gt;
This guide is to explain, step-by-step, how to setup Alpine Linux with Full Disk Encryption using LUKS2, LVM (one Physical Volume Partition with three Logical Volume Partitions (/ /boot &amp;amp; swap) with hibernation on a NVMe drive, with UEFI &amp;amp; Secure Boot (and hopefully tpm as well : WIP). This guide has been written using Alpine Linux Std 3.16.1, please adapt some commands if needed.&lt;br /&gt;
&lt;br /&gt;
The goal of this guide is to follow the KISS principle, but another file system can be used, multiple partitions for /home; /var/log etc.. can also be added, if the proposed configuration is not meeting your requirements.&lt;br /&gt;
&lt;br /&gt;
= Installing packages =&lt;br /&gt;
&lt;br /&gt;
To facilitate the partitioning we will use gdisk :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lsblk gptfdisk&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For encryption, we will use cryptsetup :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add cryptsetup&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For LVM:&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lvm2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For using and managing UEFI, multiple packages are needed :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efibootmgr e2fsprogs grub grub-efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To improve the entropy :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add haveged&lt;br /&gt;
# rc-service haveged start&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Preparing / overwriting the disk =&lt;br /&gt;
&lt;br /&gt;
This can take long, on my side for a 500GB nVME it tooks ~30 minutes.&lt;br /&gt;
&amp;lt;pre&amp;gt;# haveged -n 0 | dd of=/dev/nvme0n1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Partitioning the disk =&lt;br /&gt;
&lt;br /&gt;
Let&#039;s assume the disk is /dev/nvme0n1 and no partition is present, we will create two partitions :&lt;br /&gt;
 &lt;br /&gt;
* one for UEFI&lt;br /&gt;
* one for LVM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; # gdisk /dev/nvme0n1&lt;br /&gt;
GPT fdisk (gdisk) version 1.0.9.1&lt;br /&gt;
&lt;br /&gt;
Partition table scan:&lt;br /&gt;
  MBR: not present&lt;br /&gt;
  BSD: not present&lt;br /&gt;
  APM: not present&lt;br /&gt;
  GPT: not present&lt;br /&gt;
&lt;br /&gt;
Creating new GPT entries in memory.&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (1-128, default 1): &lt;br /&gt;
First sector (34-1000215182, default = 2048) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (2048-1000215182, default = 1000214527) or {+-}size{KMGTP}: 512M&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): ef00&lt;br /&gt;
Changed type of partition to &#039;EFI system partition&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (2-128, default 2): &lt;br /&gt;
First sector (34-1000215182, default = 1050624) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (1050624-1000215182, default = 1000214527) or {+-}size{KMGTP}: &lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8309&lt;br /&gt;
Changed type of partition to &#039;Linux LUKS&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): w&lt;br /&gt;
&lt;br /&gt;
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING&lt;br /&gt;
PARTITIONS!!&lt;br /&gt;
&lt;br /&gt;
Do you want to proceed? (Y/N): Y&lt;br /&gt;
OK; writing new GUID partition table (GPT) to /dev/nvme0n1.&lt;br /&gt;
The operation has completed successfully.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring LUKS =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 1000 --use-random luksFormat /dev/nvme0n1p2&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p2 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p2: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&lt;br /&gt;
# cryptsetup luksOpen /dev/nvme0n1p2 lvmcrypt&lt;br /&gt;
&lt;br /&gt;
= LVM : Physical &amp;amp; Logical Volumes creation=&lt;br /&gt;
&amp;lt;pre&amp;gt;# pvcreate /dev/mapper/lvmcrypt&lt;br /&gt;
  Physical volume &amp;quot;/dev/mapper/lvmcrypt&amp;quot; successfully created.&lt;br /&gt;
# vgcreate vg0 /dev/mapper/lvmcrypt&lt;br /&gt;
  Volume group &amp;quot;vg0&amp;quot; successfully created&lt;br /&gt;
# lvcreate -L 20G vg0 -n swap (I have a 16GB RAM laptop)&lt;br /&gt;
  Logical volume &amp;quot;swap&amp;quot; created.&lt;br /&gt;
# lvcreate -l 100%FREE vg0 -n root&lt;br /&gt;
  Logical volume &amp;quot;root&amp;quot; created.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To check the creation :&lt;br /&gt;
&amp;lt;pre&amp;gt;# lvscan&lt;br /&gt;
  ACTIVE            &#039;/dev/vg0/swap&#039; [20.00 GiB] inherit&lt;br /&gt;
  ACTIVE            &#039;/dev/vg0/root&#039; [455.92 GiB] inherit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Mounting points and File System =&lt;br /&gt;
&lt;br /&gt;
Create vfat file system for UEFI partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.vfat /dev/nvme0n1p1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for / partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/vg0/root&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Activate SWAP:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkswap /dev/vg0/swap&lt;br /&gt;
# swapon /dev/vg0/swap&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mount / partition to /mnt :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t ext4 /dev/vg0/root /mnt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create /boot/efi:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /mnt/boot/efi -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mount UEFI partition to /mnt/boot/efi :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t vfat /dev/nvme0n1p1 /mnt/boot/efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk&lt;br /&gt;
nvme0n1        259:0    0 476.9G  0 disk  &lt;br /&gt;
├─nvme0n1p1    259:1    0   511M  0 part  /mnt/boot/efi&lt;br /&gt;
└─nvme0n1p2    259:2    0 476.4G  0 part  &lt;br /&gt;
  └─lvmcrypt   253:0    0 476.4G  0 crypt &lt;br /&gt;
    ├─vg0-swap 253:1    0    20G  0 lvm   [SWAP]&lt;br /&gt;
    └─vg0-root 253:2    0 456.4G  0 lvm   /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Installing Alpine =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# setup-disk -m sys /mnt/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= mkinitfs settings &amp;amp; modules =&lt;br /&gt;
Edit the /mnt/etc/mkinitfs/mkinitfs.conf file and append the modules to the features parameters (keymap only needed if your keyboard is not QWERTY):&lt;br /&gt;
&amp;lt;pre&amp;gt;features=&amp;quot;ata base ide scsi usb virtio ext4 lvm nvme keymap cryptsetup cryptkey&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Regenerate the initram:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkinitfs -c /mnt/etc/mkinitfs/mkinitfs.conf -b /mnt/ $(ls /mnt/lib/modules/)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Grub settings =&lt;br /&gt;
&lt;br /&gt;
Create a crypto_keyfile.bin to avoid typing the passphrase twice during the boot process (one for Grub partition, one for Alpine partition):&lt;br /&gt;
&amp;lt;pre&amp;gt;# touch /mnt/crypto_keyfile.bin&lt;br /&gt;
# chmod 600 /mnt/crypto_keyfile.bin&lt;br /&gt;
# dd if=/dev/random bs=512 count=4 | xxd -p -c999 | tr -d &#039;\n&#039; &amp;gt; /mnt/c&lt;br /&gt;
rypto_keyfile.bin&lt;br /&gt;
# cryptsetup luksAddKey /dev/nvme0n1p2 /mnt/crypto_keyfile.bin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, let&#039;s mount and chroot to our fresh installation:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t proc /proc /mnt/proc&lt;br /&gt;
# mount --rbind /dev /mnt/dev&lt;br /&gt;
# mount --make-rslave /mnt/dev&lt;br /&gt;
# mount --rbind /sys /mnt/sys&lt;br /&gt;
# chroot /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit /etc/default/grub and add cryptkey after cryptdm=root parameter like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_TIMEOUT=2&lt;br /&gt;
GRUB_DISABLE_SUBMENU=y&lt;br /&gt;
GRUB_DISABLE_RECOVERY=true&lt;br /&gt;
GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;modules=sd-mod,usb-storage,ext4,nvme cryptroot=UUID=XXXX cryptdm=lvmcrypt cryptkey quiet rootfstype=ext4&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add a new GRUB_PRELOAD_MODULES line like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_PRELOAD_MODULES=&amp;quot;luks cryptodisk part_gpt lvm ext4&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, add the cryptodisk parameter :&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_ENABLE_CRYPTODISK=y&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let&#039;s show the UUID of our partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk -f&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a /root/grub-pre.cfg and replace &amp;lt;XXXX-UUID_WITHOUT_HYPHENS&amp;gt; with your encrypted lvm partition UUID (here /dev/nvme0n1p2) without hyphens, replace &amp;lt;YYYY&amp;gt; with VG UUID from vgdisplay and replace &amp;lt;ZZZZ&amp;gt; with LV UUID from lvdisplay of your /dev/vg0/root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set crypto_uuid=&amp;lt;XXXX-UUID_WITHOUT_HYPHENS&amp;gt;&lt;br /&gt;
cryptomount -u $crypto_uuid&lt;br /&gt;
set root=&#039;lvmid/&amp;lt;YYYY&amp;gt;/&amp;lt;ZZZZ&amp;gt;&#039;&lt;br /&gt;
set prefix=($root)/boot/grub&lt;br /&gt;
insmod normal&lt;br /&gt;
normal&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring Secure Boot =&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efi-mkkeys efibootmgr sbsigntool&lt;br /&gt;
# efi-mkkeys -s &amp;quot;Your Name&amp;quot; -o /etc/uefi-keys&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Re-install Grub:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /boot/efi/EFI/AlpineLinuxSecureBoot&lt;br /&gt;
grub-mkimage -p /boot/grub -O x86_64-efi -c /root/grub-pre.cfg -o /tmp/grubx64.efi luks2 part_gpt cryptodisk lvm ext2 gcry_rijndael pbkdf2 gcry_sha512&lt;br /&gt;
# install -v /tmp/grubx64.efi /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sed -i &#039;s/SecureBoot/SecureB00t/&#039; /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi&lt;br /&gt;
# cd /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sbsign --key /etc/uefi-keys/db.key --cert /etc/uefi-keys/db.crt --output grubx64.efi.signed grubx64.efi&lt;br /&gt;
# grub-mkconfig -o /boot/grub/grub.cfg&lt;br /&gt;
# efibootmgr --disk /dev/nvme0n1p1 --part 1 --create --label &#039;Alpine Linux Secure Boot Signed&#039; --load /EFI/AlpineLinuxSecureBoot/grubx64.efi.signed --verbose&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To check that your .efi is signed :&lt;br /&gt;
&amp;lt;pre&amp;gt; # sbverify --cert /etc/uefi-keys/db.crt /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi.signed &lt;br /&gt;
Signature verification OK&lt;br /&gt;
# sbverify --list /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi.signed&lt;br /&gt;
signature 1&lt;br /&gt;
image signature issuers:&lt;br /&gt;
 - /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
image signature certificates:&lt;br /&gt;
 - subject: /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
   issuer:  /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reboot &amp;amp; enter into your UEFI (Fx key depending of your laptop)&lt;br /&gt;
&lt;br /&gt;
== Import keys to UEFI ==&lt;br /&gt;
&lt;br /&gt;
Copy db.auth, KEK.auth and PK.auth files from /etc/uefi-keys to a FAT formatted file system.&lt;br /&gt;
This is just an example from an XPS laptop, each UEFI is unique.&lt;br /&gt;
&lt;br /&gt;
# Go to &#039;&#039;&#039;Boot Configuration&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;Secure Boot&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Enable Secure Boot&#039;&#039;&#039; to &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Secure Boot Mode&#039;&#039;&#039; to &#039;&#039;&#039;Deployed Mode&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Enable Custom Mode&#039;&#039;&#039; to &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
# Go to &#039;&#039;&#039;Custom Mode Key Management&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Reset All Keys&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;db&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;db.auth&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;KEK&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;KEK.auth&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;PK&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;PK.auth&#039;&#039;&#039;&lt;br /&gt;
# &#039;&#039;&#039;APPLY CHANGES&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;EXIT&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Check Secure Boot State:&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add mokutil&lt;br /&gt;
# mokutil --sb-state&lt;br /&gt;
SecureBoot enabled&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Congrats!&lt;/div&gt;</summary>
		<author><name>Blt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22204</id>
		<title>Full disk encryption secure boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22204"/>
		<updated>2022-08-07T22:08:17Z</updated>

		<summary type="html">&lt;p&gt;Blt: typo lvmcrypt&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Draft}}&lt;br /&gt;
&lt;br /&gt;
This guide is to explain, step-by-step, how to setup Alpine Linux with Full Disk Encryption using LUKS2, LVM (one Physical Volume Partition with three Logical Volume Partitions (/ /boot &amp;amp; swap) with hibernation on a NVMe drive, with UEFI &amp;amp; Secure Boot (and hopefully tpm as well : WIP). This guide has been written using Alpine Linux Std 3.16.1, please adapt some commands if needed.&lt;br /&gt;
&lt;br /&gt;
The goal of this guide is to follow the KISS principle, but another file system can be used, multiple partitions for /home; /var/log etc.. can also be added, if the proposed configuration is not meeting your requirements.&lt;br /&gt;
&lt;br /&gt;
= Installing packages =&lt;br /&gt;
&lt;br /&gt;
To facilitate the partitioning we will use gdisk :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lsblk gptfdisk&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For encryption, we will use cryptsetup :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add cryptsetup&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For LVM:&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lvm2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For using and managing UEFI, multiple packages are needed :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efibootmgr e2fsprogs grub grub-efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To improve the entropy :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add haveged&lt;br /&gt;
# rc-service haveged start&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Preparing / overwriting the disk =&lt;br /&gt;
&lt;br /&gt;
This can take long, on my side for a 500GB nVME it tooks ~30 minutes.&lt;br /&gt;
&amp;lt;pre&amp;gt;# haveged -n 0 | dd of=/dev/nvme0n1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Partitioning the disk =&lt;br /&gt;
&lt;br /&gt;
Let&#039;s assume the disk is /dev/nvme0n1 and no partition is present, we will create two partitions :&lt;br /&gt;
 &lt;br /&gt;
* one for UEFI&lt;br /&gt;
* one for LVM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; # gdisk /dev/nvme0n1&lt;br /&gt;
GPT fdisk (gdisk) version 1.0.9.1&lt;br /&gt;
&lt;br /&gt;
Partition table scan:&lt;br /&gt;
  MBR: not present&lt;br /&gt;
  BSD: not present&lt;br /&gt;
  APM: not present&lt;br /&gt;
  GPT: not present&lt;br /&gt;
&lt;br /&gt;
Creating new GPT entries in memory.&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (1-128, default 1): &lt;br /&gt;
First sector (34-1000215182, default = 2048) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (2048-1000215182, default = 1000214527) or {+-}size{KMGTP}: 512M&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): ef00&lt;br /&gt;
Changed type of partition to &#039;EFI system partition&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (2-128, default 2): &lt;br /&gt;
First sector (34-1000215182, default = 1050624) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (1050624-1000215182, default = 1000214527) or {+-}size{KMGTP}: &lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8309&lt;br /&gt;
Changed type of partition to &#039;Linux LUKS&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): w&lt;br /&gt;
&lt;br /&gt;
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING&lt;br /&gt;
PARTITIONS!!&lt;br /&gt;
&lt;br /&gt;
Do you want to proceed? (Y/N): Y&lt;br /&gt;
OK; writing new GUID partition table (GPT) to /dev/nvme0n1.&lt;br /&gt;
The operation has completed successfully.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring LUKS =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 1000 --use-random luksFormat /dev/nvme0n1p2&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p2 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p2: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&lt;br /&gt;
# cryptsetup luksOpen /dev/nvme0n1p2 lvmcrypt&lt;br /&gt;
&lt;br /&gt;
= LVM : Physical &amp;amp; Logical Volumes creation=&lt;br /&gt;
&amp;lt;pre&amp;gt;# pvcreate /dev/mapper/lvmcrypt&lt;br /&gt;
  Physical volume &amp;quot;/dev/mapper/lvmcrypt&amp;quot; successfully created.&lt;br /&gt;
# vgcreate vg0 /dev/mapper/lvmcrypt&lt;br /&gt;
  Volume group &amp;quot;vg0&amp;quot; successfully created&lt;br /&gt;
# lvcreate -L 20G vg0 -n swap (I have a 16GB RAM laptop)&lt;br /&gt;
  Logical volume &amp;quot;swap&amp;quot; created.&lt;br /&gt;
# lvcreate -l 100%FREE vg0 -n root&lt;br /&gt;
  Logical volume &amp;quot;root&amp;quot; created.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To check the creation :&lt;br /&gt;
&amp;lt;pre&amp;gt;# lvscan&lt;br /&gt;
  ACTIVE            &#039;/dev/vg0/swap&#039; [20.00 GiB] inherit&lt;br /&gt;
  ACTIVE            &#039;/dev/vg0/root&#039; [455.92 GiB] inherit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Mounting points and File System =&lt;br /&gt;
&lt;br /&gt;
Create vfat file system for UEFI partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.vfat /dev/nvme0n1p1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for / partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/vg0/root&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Activate SWAP:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkswap /dev/vg0/swap&lt;br /&gt;
# swapon /dev/vg0/swap&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mount / partition to /mnt :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t ext4 /dev/vg0/root /mnt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create /boot/efi:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /mnt/boot/efi -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mount UEFI partition to /mnt/boot/efi :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t vfat /dev/nvme0n1p1 /mnt/boot/efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk&lt;br /&gt;
nvme0n1        259:0    0 476.9G  0 disk  &lt;br /&gt;
├─nvme0n1p1    259:1    0   511M  0 part  /mnt/boot/efi&lt;br /&gt;
└─nvme0n1p2    259:2    0 476.4G  0 part  &lt;br /&gt;
  └─lvmcrypt   253:0    0 476.4G  0 crypt &lt;br /&gt;
    ├─vg0-swap 253:1    0    20G  0 lvm   [SWAP]&lt;br /&gt;
    └─vg0-root 253:2    0 456.4G  0 lvm   /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Installing Alpine =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# setup-disk -m sys /mnt/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= mkinitfs settings &amp;amp; modules =&lt;br /&gt;
Edit the /mnt/etc/mkinitfs/mkinitfs.conf file and append the modules to the features parameters (keymap only needed if your keyboard is not QWERTY):&lt;br /&gt;
&amp;lt;pre&amp;gt;features=&amp;quot;ata base ide scsi usb virtio ext4 lvm nvme keymap cryptsetup cryptkey&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Regenerate the initram:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkinitfs -c /mnt/etc/mkinitfs/mkinitfs.conf -b /mnt/ $(ls /mnt/lib/modules/)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Grub settings =&lt;br /&gt;
&lt;br /&gt;
Create a crypto_keyfile.bin to avoid typing the passphrase twice during the boot process (one for Grub partition, one for Alpine partition):&lt;br /&gt;
&amp;lt;pre&amp;gt;# touch /mnt/crypto_keyfile.bin&lt;br /&gt;
# chmod 600 /mnt/crypto_keyfile.bin&lt;br /&gt;
# dd if=/dev/random bs=512 count=4 | xxd -p -c999 | tr -d &#039;\n&#039; &amp;gt; /mnt/c&lt;br /&gt;
rypto_keyfile.bin&lt;br /&gt;
# cryptsetup luksAddKey /dev/nvme0n1p2 /mnt/crypto_keyfile.bin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, let&#039;s mount and chroot to our fresh installation:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t proc /proc /mnt/proc&lt;br /&gt;
# mount --rbind /dev /mnt/dev&lt;br /&gt;
# mount --make-rslave /mnt/dev&lt;br /&gt;
# mount --rbind /sys /mnt/sys&lt;br /&gt;
# chroot /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit /etc/default/grub and add cryptkey after cryptdm=root parameter like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_TIMEOUT=2&lt;br /&gt;
GRUB_DISABLE_SUBMENU=y&lt;br /&gt;
GRUB_DISABLE_RECOVERY=true&lt;br /&gt;
GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;modules=sd-mod,usb-storage,ext4,nvme cryptroot=UUID=XXXX cryptdm=lvmcrypt cryptkey quiet rootfstype=ext4&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add a new GRUB_PRELOAD_MODULES line like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_PRELOAD_MODULES=&amp;quot;luks cryptodisk part_gpt lvm ext4&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, add the cryptodisk parameter :&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_ENABLE_CRYPTODISK=y&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let&#039;s show the UUID of our partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk -f&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a /root/grub-pre.cfg and replace &amp;lt;XXXX-UUID_WITHOUT_HYPHENS&amp;gt; with your encrypted lvm partition UUID (here /dev/nvme0n1p2) without hyphens, replace &amp;lt;YYYY&amp;gt; with VG UUID from vgdisplay and replace &amp;lt;ZZZZ&amp;gt; with LV UUID from lvdisplay of your /dev/vg0/root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set crypto_uuid=&amp;lt;XXXX-UUID_WITHOUT_HYPHENS&amp;gt;&lt;br /&gt;
cryptomount -u $crypto_uuid&lt;br /&gt;
set root=&#039;lvmid/&amp;lt;YYYY&amp;gt;/&amp;lt;ZZZZ&amp;gt;&#039;&lt;br /&gt;
set prefix=($root)/boot/grub&lt;br /&gt;
insmod normal&lt;br /&gt;
normal&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring Secure Boot =&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efi-mkkeys efibootmgr sbsigntool&lt;br /&gt;
# efi-mkkeys -s &amp;quot;Your Name&amp;quot; -o /etc/uefi-keys&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Re-install Grub:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /boot/efi/EFI/AlpineLinuxSecureBoot&lt;br /&gt;
grub-mkimage -p /boot/grub -O x86_64-efi -c /root/grub-pre.cfg -o /tmp/grubx64.efi luks2 part_gpt cryptodisk ext2 gcry_rijndael pbkdf2 gcry_sha512&lt;br /&gt;
# install -v /tmp/grubx64.efi /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sed -i &#039;s/SecureBoot/SecureB00t/&#039; /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi&lt;br /&gt;
# cd /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sbsign --key /etc/uefi-keys/db.key --cert /etc/uefi-keys/db.crt --output grubx64.efi.signed grubx64.efi&lt;br /&gt;
# grub-mkconfig -o /boot/grub/grub.cfg&lt;br /&gt;
# efibootmgr --disk /dev/nvme0n1p1 --part 1 --create --label &#039;Alpine Linux Secure Boot Signed&#039; --load /EFI/AlpineLinuxSecureBoot/grubx64.efi.signed --verbose&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To check that your .efi is signed :&lt;br /&gt;
&amp;lt;pre&amp;gt; # sbverify --cert /etc/uefi-keys/db.crt /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi.signed &lt;br /&gt;
Signature verification OK&lt;br /&gt;
# sbverify --list /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi.signed&lt;br /&gt;
signature 1&lt;br /&gt;
image signature issuers:&lt;br /&gt;
 - /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
image signature certificates:&lt;br /&gt;
 - subject: /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
   issuer:  /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reboot &amp;amp; enter into your UEFI (Fx key depending of your laptop)&lt;br /&gt;
&lt;br /&gt;
== Import keys to UEFI ==&lt;br /&gt;
&lt;br /&gt;
Copy db.auth, KEK.auth and PK.auth files from /etc/uefi-keys to a FAT formatted file system.&lt;br /&gt;
This is just an example from an XPS laptop, each UEFI is unique.&lt;br /&gt;
&lt;br /&gt;
# Go to &#039;&#039;&#039;Boot Configuration&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;Secure Boot&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Enable Secure Boot&#039;&#039;&#039; to &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Secure Boot Mode&#039;&#039;&#039; to &#039;&#039;&#039;Deployed Mode&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Enable Custom Mode&#039;&#039;&#039; to &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
# Go to &#039;&#039;&#039;Custom Mode Key Management&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Reset All Keys&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;db&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;db.auth&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;KEK&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;KEK.auth&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;PK&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;PK.auth&#039;&#039;&#039;&lt;br /&gt;
# &#039;&#039;&#039;APPLY CHANGES&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;EXIT&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Check Secure Boot State:&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add mokutil&lt;br /&gt;
# mokutil --sb-state&lt;br /&gt;
SecureBoot enabled&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Congrats!&lt;/div&gt;</summary>
		<author><name>Blt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22203</id>
		<title>Full disk encryption secure boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22203"/>
		<updated>2022-08-07T21:43:14Z</updated>

		<summary type="html">&lt;p&gt;Blt: typo on XXXX UUID&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Draft}}&lt;br /&gt;
&lt;br /&gt;
This guide is to explain, step-by-step, how to setup Alpine Linux with Full Disk Encryption using LUKS2, LVM (one Physical Volume Partition with three Logical Volume Partitions (/ /boot &amp;amp; swap) with hibernation on a NVMe drive, with UEFI &amp;amp; Secure Boot (and hopefully tpm as well : WIP). This guide has been written using Alpine Linux Std 3.16.1, please adapt some commands if needed.&lt;br /&gt;
&lt;br /&gt;
The goal of this guide is to follow the KISS principle, but another file system can be used, multiple partitions for /home; /var/log etc.. can also be added, if the proposed configuration is not meeting your requirements.&lt;br /&gt;
&lt;br /&gt;
= Installing packages =&lt;br /&gt;
&lt;br /&gt;
To facilitate the partitioning we will use gdisk :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lsblk gptfdisk&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For encryption, we will use cryptsetup :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add cryptsetup&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For LVM:&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lvm2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For using and managing UEFI, multiple packages are needed :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efibootmgr e2fsprogs grub grub-efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To improve the entropy :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add haveged&lt;br /&gt;
# rc-service haveged start&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Preparing / overwriting the disk =&lt;br /&gt;
&lt;br /&gt;
This can take long, on my side for a 500GB nVME it tooks ~30 minutes.&lt;br /&gt;
&amp;lt;pre&amp;gt;# haveged -n 0 | dd of=/dev/nvme0n1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Partitioning the disk =&lt;br /&gt;
&lt;br /&gt;
Let&#039;s assume the disk is /dev/nvme0n1 and no partition is present, we will create two partitions :&lt;br /&gt;
 &lt;br /&gt;
* one for UEFI&lt;br /&gt;
* one for LVM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; # gdisk /dev/nvme0n1&lt;br /&gt;
GPT fdisk (gdisk) version 1.0.9.1&lt;br /&gt;
&lt;br /&gt;
Partition table scan:&lt;br /&gt;
  MBR: not present&lt;br /&gt;
  BSD: not present&lt;br /&gt;
  APM: not present&lt;br /&gt;
  GPT: not present&lt;br /&gt;
&lt;br /&gt;
Creating new GPT entries in memory.&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (1-128, default 1): &lt;br /&gt;
First sector (34-1000215182, default = 2048) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (2048-1000215182, default = 1000214527) or {+-}size{KMGTP}: 512M&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): ef00&lt;br /&gt;
Changed type of partition to &#039;EFI system partition&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (2-128, default 2): &lt;br /&gt;
First sector (34-1000215182, default = 1050624) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (1050624-1000215182, default = 1000214527) or {+-}size{KMGTP}: &lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8309&lt;br /&gt;
Changed type of partition to &#039;Linux LUKS&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): w&lt;br /&gt;
&lt;br /&gt;
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING&lt;br /&gt;
PARTITIONS!!&lt;br /&gt;
&lt;br /&gt;
Do you want to proceed? (Y/N): Y&lt;br /&gt;
OK; writing new GUID partition table (GPT) to /dev/nvme0n1.&lt;br /&gt;
The operation has completed successfully.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring LUKS =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 1000 --use-random luksFormat /dev/nvme0n1p2&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p2 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p2: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&lt;br /&gt;
# cryptsetup luksOpen /dev/nvme0n1p2 lvmcrypt&lt;br /&gt;
&lt;br /&gt;
= LVM : Physical &amp;amp; Logical Volumes creation=&lt;br /&gt;
&amp;lt;pre&amp;gt;# pvcreate /dev/mapper/lvmcrypt&lt;br /&gt;
  Physical volume &amp;quot;/dev/mapper/lvmcrypt&amp;quot; successfully created.&lt;br /&gt;
# vgcreate vg0 /dev/mapper/lvmcrypt&lt;br /&gt;
  Volume group &amp;quot;vg0&amp;quot; successfully created&lt;br /&gt;
# lvcreate -L 20G vg0 -n swap (I have a 16GB RAM laptop)&lt;br /&gt;
  Logical volume &amp;quot;swap&amp;quot; created.&lt;br /&gt;
# lvcreate -l 100%FREE vg0 -n root&lt;br /&gt;
  Logical volume &amp;quot;root&amp;quot; created.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To check the creation :&lt;br /&gt;
&amp;lt;pre&amp;gt;# lvscan&lt;br /&gt;
  ACTIVE            &#039;/dev/vg0/swap&#039; [20.00 GiB] inherit&lt;br /&gt;
  ACTIVE            &#039;/dev/vg0/root&#039; [455.92 GiB] inherit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Mounting points and File System =&lt;br /&gt;
&lt;br /&gt;
Create vfat file system for UEFI partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.vfat /dev/nvme0n1p1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for / partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/vg0/root&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Activate SWAP:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkswap /dev/vg0/swap&lt;br /&gt;
# swapon /dev/vg0/swap&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mount / partition to /mnt :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t ext4 /dev/vg0/root /mnt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create /boot/efi:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /mnt/boot/efi -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mount UEFI partition to /mnt/boot/efi :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t vfat /dev/nvme0n1p1 /mnt/boot/efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk&lt;br /&gt;
nvme0n1        259:0    0 476.9G  0 disk  &lt;br /&gt;
├─nvme0n1p1    259:1    0   511M  0 part  /mnt/boot/efi&lt;br /&gt;
└─nvme0n1p2    259:2    0 476.4G  0 part  &lt;br /&gt;
  └─lvmcrypt   253:0    0 476.4G  0 crypt &lt;br /&gt;
    ├─vg0-swap 253:1    0    20G  0 lvm   [SWAP]&lt;br /&gt;
    └─vg0-root 253:2    0 456.4G  0 lvm   /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Installing Alpine =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# setup-disk -m sys /mnt/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= mkinitfs settings &amp;amp; modules =&lt;br /&gt;
Edit the /mnt/etc/mkinitfs/mkinitfs.conf file and append the modules to the features parameters (keymap only needed if your keyboard is not QWERTY):&lt;br /&gt;
&amp;lt;pre&amp;gt;features=&amp;quot;ata base ide scsi usb virtio ext4 lvm nvme keymap cryptsetup cryptkey&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Regenerate the initram:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkinitfs -c /mnt/etc/mkinitfs/mkinitfs.conf -b /mnt/ $(ls /mnt/lib/modules/)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Grub settings =&lt;br /&gt;
&lt;br /&gt;
Create a crypto_keyfile.bin to avoid typing the passphrase twice during the boot process (one for Grub partition, one for Alpine partition):&lt;br /&gt;
&amp;lt;pre&amp;gt;# touch /mnt/crypto_keyfile.bin&lt;br /&gt;
# chmod 600 /mnt/crypto_keyfile.bin&lt;br /&gt;
# dd if=/dev/random bs=512 count=4 | xxd -p -c999 | tr -d &#039;\n&#039; &amp;gt; /mnt/c&lt;br /&gt;
rypto_keyfile.bin&lt;br /&gt;
# cryptsetup luksAddKey /dev/nvme0n1p2 /mnt/crypto_keyfile.bin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, let&#039;s mount and chroot to our fresh installation:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t proc /proc /mnt/proc&lt;br /&gt;
# mount --rbind /dev /mnt/dev&lt;br /&gt;
# mount --make-rslave /mnt/dev&lt;br /&gt;
# mount --rbind /sys /mnt/sys&lt;br /&gt;
# chroot /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit /etc/default/grub and add cryptkey after cryptdm=root parameter like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_TIMEOUT=2&lt;br /&gt;
GRUB_DISABLE_SUBMENU=y&lt;br /&gt;
GRUB_DISABLE_RECOVERY=true&lt;br /&gt;
GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;modules=sd-mod,usb-storage,ext4,nvme cryptroot=UUID=XXXX cryptdm=root cryptkey quiet rootfstype=ext4&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add a new GRUB_PRELOAD_MODULES line like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_PRELOAD_MODULES=&amp;quot;luks cryptodisk part_gpt lvm ext4&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, add the cryptodisk parameter :&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_ENABLE_CRYPTODISK=y&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let&#039;s show the UUID of our partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk -f&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a /root/grub-pre.cfg and replace &amp;lt;XXXX-UUID_WITHOUT_HYPHENS&amp;gt; with your encrypted lvm partition UUID (here /dev/nvme0n1p2) without hyphens, replace &amp;lt;YYYY&amp;gt; with VG UUID from vgdisplay and replace &amp;lt;ZZZZ&amp;gt; with LV UUID from lvdisplay of your /dev/vg0/root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set crypto_uuid=&amp;lt;XXXX-UUID_WITHOUT_HYPHENS&amp;gt;&lt;br /&gt;
cryptomount -u $crypto_uuid&lt;br /&gt;
set root=&#039;lvmid/&amp;lt;YYYY&amp;gt;/&amp;lt;ZZZZ&amp;gt;&#039;&lt;br /&gt;
set prefix=($root)/boot/grub&lt;br /&gt;
insmod normal&lt;br /&gt;
normal&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring Secure Boot =&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efi-mkkeys efibootmgr sbsigntool&lt;br /&gt;
# efi-mkkeys -s &amp;quot;Your Name&amp;quot; -o /etc/uefi-keys&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Re-install Grub:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /boot/efi/EFI/AlpineLinuxSecureBoot&lt;br /&gt;
grub-mkimage -p /boot/grub -O x86_64-efi -c /root/grub-pre.cfg -o /tmp/grubx64.efi luks2 part_gpt cryptodisk ext2 gcry_rijndael pbkdf2 gcry_sha512&lt;br /&gt;
# install -v /tmp/grubx64.efi /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sed -i &#039;s/SecureBoot/SecureB00t/&#039; /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi&lt;br /&gt;
# cd /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sbsign --key /etc/uefi-keys/db.key --cert /etc/uefi-keys/db.crt --output grubx64.efi.signed grubx64.efi&lt;br /&gt;
# grub-mkconfig -o /boot/grub/grub.cfg&lt;br /&gt;
# efibootmgr --disk /dev/nvme0n1p1 --part 1 --create --label &#039;Alpine Linux Secure Boot Signed&#039; --load /EFI/AlpineLinuxSecureBoot/grubx64.efi.signed --verbose&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To check that your .efi is signed :&lt;br /&gt;
&amp;lt;pre&amp;gt; # sbverify --cert /etc/uefi-keys/db.crt /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi.signed &lt;br /&gt;
Signature verification OK&lt;br /&gt;
# sbverify --list /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi.signed&lt;br /&gt;
signature 1&lt;br /&gt;
image signature issuers:&lt;br /&gt;
 - /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
image signature certificates:&lt;br /&gt;
 - subject: /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
   issuer:  /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reboot &amp;amp; enter into your UEFI (Fx key depending of your laptop)&lt;br /&gt;
&lt;br /&gt;
== Import keys to UEFI ==&lt;br /&gt;
&lt;br /&gt;
Copy db.auth, KEK.auth and PK.auth files from /etc/uefi-keys to a FAT formatted file system.&lt;br /&gt;
This is just an example from an XPS laptop, each UEFI is unique.&lt;br /&gt;
&lt;br /&gt;
# Go to &#039;&#039;&#039;Boot Configuration&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;Secure Boot&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Enable Secure Boot&#039;&#039;&#039; to &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Secure Boot Mode&#039;&#039;&#039; to &#039;&#039;&#039;Deployed Mode&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Enable Custom Mode&#039;&#039;&#039; to &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
# Go to &#039;&#039;&#039;Custom Mode Key Management&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Reset All Keys&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;db&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;db.auth&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;KEK&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;KEK.auth&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;PK&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;PK.auth&#039;&#039;&#039;&lt;br /&gt;
# &#039;&#039;&#039;APPLY CHANGES&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;EXIT&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Check Secure Boot State:&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add mokutil&lt;br /&gt;
# mokutil --sb-state&lt;br /&gt;
SecureBoot enabled&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Congrats!&lt;/div&gt;</summary>
		<author><name>Blt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22202</id>
		<title>Full disk encryption secure boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22202"/>
		<updated>2022-08-07T21:34:09Z</updated>

		<summary type="html">&lt;p&gt;Blt: grub adding cryptodisk option&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Draft}}&lt;br /&gt;
&lt;br /&gt;
This guide is to explain, step-by-step, how to setup Alpine Linux with Full Disk Encryption using LUKS2, LVM (one Physical Volume Partition with three Logical Volume Partitions (/ /boot &amp;amp; swap) with hibernation on a NVMe drive, with UEFI &amp;amp; Secure Boot (and hopefully tpm as well : WIP). This guide has been written using Alpine Linux Std 3.16.1, please adapt some commands if needed.&lt;br /&gt;
&lt;br /&gt;
The goal of this guide is to follow the KISS principle, but another file system can be used, multiple partitions for /home; /var/log etc.. can also be added, if the proposed configuration is not meeting your requirements.&lt;br /&gt;
&lt;br /&gt;
= Installing packages =&lt;br /&gt;
&lt;br /&gt;
To facilitate the partitioning we will use gdisk :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lsblk gptfdisk&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For encryption, we will use cryptsetup :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add cryptsetup&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For LVM:&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lvm2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For using and managing UEFI, multiple packages are needed :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efibootmgr e2fsprogs grub grub-efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To improve the entropy :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add haveged&lt;br /&gt;
# rc-service haveged start&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Preparing / overwriting the disk =&lt;br /&gt;
&lt;br /&gt;
This can take long, on my side for a 500GB nVME it tooks ~30 minutes.&lt;br /&gt;
&amp;lt;pre&amp;gt;# haveged -n 0 | dd of=/dev/nvme0n1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Partitioning the disk =&lt;br /&gt;
&lt;br /&gt;
Let&#039;s assume the disk is /dev/nvme0n1 and no partition is present, we will create two partitions :&lt;br /&gt;
 &lt;br /&gt;
* one for UEFI&lt;br /&gt;
* one for LVM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; # gdisk /dev/nvme0n1&lt;br /&gt;
GPT fdisk (gdisk) version 1.0.9.1&lt;br /&gt;
&lt;br /&gt;
Partition table scan:&lt;br /&gt;
  MBR: not present&lt;br /&gt;
  BSD: not present&lt;br /&gt;
  APM: not present&lt;br /&gt;
  GPT: not present&lt;br /&gt;
&lt;br /&gt;
Creating new GPT entries in memory.&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (1-128, default 1): &lt;br /&gt;
First sector (34-1000215182, default = 2048) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (2048-1000215182, default = 1000214527) or {+-}size{KMGTP}: 512M&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): ef00&lt;br /&gt;
Changed type of partition to &#039;EFI system partition&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (2-128, default 2): &lt;br /&gt;
First sector (34-1000215182, default = 1050624) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (1050624-1000215182, default = 1000214527) or {+-}size{KMGTP}: &lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8309&lt;br /&gt;
Changed type of partition to &#039;Linux LUKS&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): w&lt;br /&gt;
&lt;br /&gt;
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING&lt;br /&gt;
PARTITIONS!!&lt;br /&gt;
&lt;br /&gt;
Do you want to proceed? (Y/N): Y&lt;br /&gt;
OK; writing new GUID partition table (GPT) to /dev/nvme0n1.&lt;br /&gt;
The operation has completed successfully.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring LUKS =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 1000 --use-random luksFormat /dev/nvme0n1p2&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p2 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p2: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&lt;br /&gt;
# cryptsetup luksOpen /dev/nvme0n1p2 lvmcrypt&lt;br /&gt;
&lt;br /&gt;
= LVM : Physical &amp;amp; Logical Volumes creation=&lt;br /&gt;
&amp;lt;pre&amp;gt;# pvcreate /dev/mapper/lvmcrypt&lt;br /&gt;
  Physical volume &amp;quot;/dev/mapper/lvmcrypt&amp;quot; successfully created.&lt;br /&gt;
# vgcreate vg0 /dev/mapper/lvmcrypt&lt;br /&gt;
  Volume group &amp;quot;vg0&amp;quot; successfully created&lt;br /&gt;
# lvcreate -L 20G vg0 -n swap (I have a 16GB RAM laptop)&lt;br /&gt;
  Logical volume &amp;quot;swap&amp;quot; created.&lt;br /&gt;
# lvcreate -l 100%FREE vg0 -n root&lt;br /&gt;
  Logical volume &amp;quot;root&amp;quot; created.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To check the creation :&lt;br /&gt;
&amp;lt;pre&amp;gt;# lvscan&lt;br /&gt;
  ACTIVE            &#039;/dev/vg0/swap&#039; [20.00 GiB] inherit&lt;br /&gt;
  ACTIVE            &#039;/dev/vg0/root&#039; [455.92 GiB] inherit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Mounting points and File System =&lt;br /&gt;
&lt;br /&gt;
Create vfat file system for UEFI partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.vfat /dev/nvme0n1p1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for / partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/vg0/root&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Activate SWAP:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkswap /dev/vg0/swap&lt;br /&gt;
# swapon /dev/vg0/swap&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mount / partition to /mnt :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t ext4 /dev/vg0/root /mnt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create /boot/efi:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /mnt/boot/efi -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mount UEFI partition to /mnt/boot/efi :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t vfat /dev/nvme0n1p1 /mnt/boot/efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk&lt;br /&gt;
nvme0n1        259:0    0 476.9G  0 disk  &lt;br /&gt;
├─nvme0n1p1    259:1    0   511M  0 part  /mnt/boot/efi&lt;br /&gt;
└─nvme0n1p2    259:2    0 476.4G  0 part  &lt;br /&gt;
  └─lvmcrypt   253:0    0 476.4G  0 crypt &lt;br /&gt;
    ├─vg0-swap 253:1    0    20G  0 lvm   [SWAP]&lt;br /&gt;
    └─vg0-root 253:2    0 456.4G  0 lvm   /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Installing Alpine =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# setup-disk -m sys /mnt/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= mkinitfs settings &amp;amp; modules =&lt;br /&gt;
Edit the /mnt/etc/mkinitfs/mkinitfs.conf file and append the modules to the features parameters (keymap only needed if your keyboard is not QWERTY):&lt;br /&gt;
&amp;lt;pre&amp;gt;features=&amp;quot;ata base ide scsi usb virtio ext4 lvm nvme keymap cryptsetup cryptkey&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Regenerate the initram:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkinitfs -c /mnt/etc/mkinitfs/mkinitfs.conf -b /mnt/ $(ls /mnt/lib/modules/)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Grub settings =&lt;br /&gt;
&lt;br /&gt;
Create a crypto_keyfile.bin to avoid typing the passphrase twice during the boot process (one for Grub partition, one for Alpine partition):&lt;br /&gt;
&amp;lt;pre&amp;gt;# touch /mnt/crypto_keyfile.bin&lt;br /&gt;
# chmod 600 /mnt/crypto_keyfile.bin&lt;br /&gt;
# dd if=/dev/random bs=512 count=4 | xxd -p -c999 | tr -d &#039;\n&#039; &amp;gt; /mnt/c&lt;br /&gt;
rypto_keyfile.bin&lt;br /&gt;
# cryptsetup luksAddKey /dev/nvme0n1p2 /mnt/crypto_keyfile.bin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, let&#039;s mount and chroot to our fresh installation:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t proc /proc /mnt/proc&lt;br /&gt;
# mount --rbind /dev /mnt/dev&lt;br /&gt;
# mount --make-rslave /mnt/dev&lt;br /&gt;
# mount --rbind /sys /mnt/sys&lt;br /&gt;
# chroot /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit /etc/default/grub and add cryptkey after cryptdm=root parameter like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_TIMEOUT=2&lt;br /&gt;
GRUB_DISABLE_SUBMENU=y&lt;br /&gt;
GRUB_DISABLE_RECOVERY=true&lt;br /&gt;
GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;modules=sd-mod,usb-storage,ext4,nvme cryptroot=UUID=XXXX cryptdm=root cryptkey quiet rootfstype=ext4&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add a new GRUB_PRELOAD_MODULES line like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_PRELOAD_MODULES=&amp;quot;luks cryptodisk part_gpt lvm ext4&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, add the cryptodisk parameter :&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_ENABLE_CRYPTODISK=y&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let&#039;s show the UUID of our partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk -f&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a /root/grub-pre.cfg and replace &amp;lt;XXXX-UUID_WITHOUT_HYPHENS&amp;gt; with your encrypted root partition UUID (here vg0-root) without hyphens, replace &amp;lt;YYYY&amp;gt; with VG UUID from vgdisplay and replace &amp;lt;ZZZZ&amp;gt; with LV UUID from lvdisplay of your /dev/vg0/root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set crypto_uuid=&amp;lt;XXXX-UUID_WITHOUT_HYPHENS&amp;gt;&lt;br /&gt;
cryptomount -u $crypto_uuid&lt;br /&gt;
set root=&#039;lvmid/&amp;lt;YYYY&amp;gt;/&amp;lt;ZZZZ&amp;gt;&#039;&lt;br /&gt;
set prefix=($root)/boot/grub&lt;br /&gt;
insmod normal&lt;br /&gt;
normal&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring Secure Boot =&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efi-mkkeys efibootmgr sbsigntool&lt;br /&gt;
# efi-mkkeys -s &amp;quot;Your Name&amp;quot; -o /etc/uefi-keys&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Re-install Grub:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /boot/efi/EFI/AlpineLinuxSecureBoot&lt;br /&gt;
grub-mkimage -p /boot/grub -O x86_64-efi -c /root/grub-pre.cfg -o /tmp/grubx64.efi luks2 part_gpt cryptodisk ext2 gcry_rijndael pbkdf2 gcry_sha512&lt;br /&gt;
# install -v /tmp/grubx64.efi /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sed -i &#039;s/SecureBoot/SecureB00t/&#039; /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi&lt;br /&gt;
# cd /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sbsign --key /etc/uefi-keys/db.key --cert /etc/uefi-keys/db.crt --output grubx64.efi.signed grubx64.efi&lt;br /&gt;
# grub-mkconfig -o /boot/grub/grub.cfg&lt;br /&gt;
# efibootmgr --disk /dev/nvme0n1p1 --part 1 --create --label &#039;Alpine Linux Secure Boot Signed&#039; --load /EFI/AlpineLinuxSecureBoot/grubx64.efi.signed --verbose&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To check that your .efi is signed :&lt;br /&gt;
&amp;lt;pre&amp;gt; # sbverify --cert /etc/uefi-keys/db.crt /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi.signed &lt;br /&gt;
Signature verification OK&lt;br /&gt;
# sbverify --list /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi.signed&lt;br /&gt;
signature 1&lt;br /&gt;
image signature issuers:&lt;br /&gt;
 - /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
image signature certificates:&lt;br /&gt;
 - subject: /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
   issuer:  /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reboot &amp;amp; enter into your UEFI (Fx key depending of your laptop)&lt;br /&gt;
&lt;br /&gt;
== Import keys to UEFI ==&lt;br /&gt;
&lt;br /&gt;
Copy db.auth, KEK.auth and PK.auth files from /etc/uefi-keys to a FAT formatted file system.&lt;br /&gt;
This is just an example from an XPS laptop, each UEFI is unique.&lt;br /&gt;
&lt;br /&gt;
# Go to &#039;&#039;&#039;Boot Configuration&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;Secure Boot&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Enable Secure Boot&#039;&#039;&#039; to &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Secure Boot Mode&#039;&#039;&#039; to &#039;&#039;&#039;Deployed Mode&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Enable Custom Mode&#039;&#039;&#039; to &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
# Go to &#039;&#039;&#039;Custom Mode Key Management&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Reset All Keys&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;db&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;db.auth&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;KEK&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;KEK.auth&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;PK&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;PK.auth&#039;&#039;&#039;&lt;br /&gt;
# &#039;&#039;&#039;APPLY CHANGES&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;EXIT&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Check Secure Boot State:&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add mokutil&lt;br /&gt;
# mokutil --sb-state&lt;br /&gt;
SecureBoot enabled&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Congrats!&lt;/div&gt;</summary>
		<author><name>Blt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22201</id>
		<title>Full disk encryption secure boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22201"/>
		<updated>2022-08-07T19:20:44Z</updated>

		<summary type="html">&lt;p&gt;Blt: tweak grub for lvm&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Draft}}&lt;br /&gt;
&lt;br /&gt;
This guide is to explain, step-by-step, how to setup Alpine Linux with Full Disk Encryption using LUKS2, LVM (one Physical Volume Partition with three Logical Volume Partitions (/ /boot &amp;amp; swap) with hibernation on a NVMe drive, with UEFI &amp;amp; Secure Boot (and hopefully tpm as well : WIP). This guide has been written using Alpine Linux Std 3.16.1, please adapt some commands if needed.&lt;br /&gt;
&lt;br /&gt;
The goal of this guide is to follow the KISS principle, but another file system can be used, multiple partitions for /home; /var/log etc.. can also be added, if the proposed configuration is not meeting your requirements.&lt;br /&gt;
&lt;br /&gt;
= Installing packages =&lt;br /&gt;
&lt;br /&gt;
To facilitate the partitioning we will use gdisk :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lsblk gptfdisk&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For encryption, we will use cryptsetup :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add cryptsetup&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For LVM:&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lvm2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For using and managing UEFI, multiple packages are needed :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efibootmgr e2fsprogs grub grub-efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To improve the entropy :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add haveged&lt;br /&gt;
# rc-service haveged start&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Preparing / overwriting the disk =&lt;br /&gt;
&lt;br /&gt;
This can take long, on my side for a 500GB nVME it tooks ~30 minutes.&lt;br /&gt;
&amp;lt;pre&amp;gt;# haveged -n 0 | dd of=/dev/nvme0n1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Partitioning the disk =&lt;br /&gt;
&lt;br /&gt;
Let&#039;s assume the disk is /dev/nvme0n1 and no partition is present, we will create two partitions :&lt;br /&gt;
 &lt;br /&gt;
* one for UEFI&lt;br /&gt;
* one for LVM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; # gdisk /dev/nvme0n1&lt;br /&gt;
GPT fdisk (gdisk) version 1.0.9.1&lt;br /&gt;
&lt;br /&gt;
Partition table scan:&lt;br /&gt;
  MBR: not present&lt;br /&gt;
  BSD: not present&lt;br /&gt;
  APM: not present&lt;br /&gt;
  GPT: not present&lt;br /&gt;
&lt;br /&gt;
Creating new GPT entries in memory.&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (1-128, default 1): &lt;br /&gt;
First sector (34-1000215182, default = 2048) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (2048-1000215182, default = 1000214527) or {+-}size{KMGTP}: 512M&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): ef00&lt;br /&gt;
Changed type of partition to &#039;EFI system partition&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (2-128, default 2): &lt;br /&gt;
First sector (34-1000215182, default = 1050624) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (1050624-1000215182, default = 1000214527) or {+-}size{KMGTP}: &lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8309&lt;br /&gt;
Changed type of partition to &#039;Linux LUKS&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): w&lt;br /&gt;
&lt;br /&gt;
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING&lt;br /&gt;
PARTITIONS!!&lt;br /&gt;
&lt;br /&gt;
Do you want to proceed? (Y/N): Y&lt;br /&gt;
OK; writing new GUID partition table (GPT) to /dev/nvme0n1.&lt;br /&gt;
The operation has completed successfully.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring LUKS =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 1000 --use-random luksFormat /dev/nvme0n1p2&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p2 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p2: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&lt;br /&gt;
# cryptsetup luksOpen /dev/nvme0n1p2 lvmcrypt&lt;br /&gt;
&lt;br /&gt;
= LVM : Physical &amp;amp; Logical Volumes creation=&lt;br /&gt;
&amp;lt;pre&amp;gt;# pvcreate /dev/mapper/lvmcrypt&lt;br /&gt;
  Physical volume &amp;quot;/dev/mapper/lvmcrypt&amp;quot; successfully created.&lt;br /&gt;
# vgcreate vg0 /dev/mapper/lvmcrypt&lt;br /&gt;
  Volume group &amp;quot;vg0&amp;quot; successfully created&lt;br /&gt;
# lvcreate -L 20G vg0 -n swap (I have a 16GB RAM laptop)&lt;br /&gt;
  Logical volume &amp;quot;swap&amp;quot; created.&lt;br /&gt;
# lvcreate -l 100%FREE vg0 -n root&lt;br /&gt;
  Logical volume &amp;quot;root&amp;quot; created.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To check the creation :&lt;br /&gt;
&amp;lt;pre&amp;gt;# lvscan&lt;br /&gt;
  ACTIVE            &#039;/dev/vg0/swap&#039; [20.00 GiB] inherit&lt;br /&gt;
  ACTIVE            &#039;/dev/vg0/root&#039; [455.92 GiB] inherit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Mounting points and File System =&lt;br /&gt;
&lt;br /&gt;
Create vfat file system for UEFI partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.vfat /dev/nvme0n1p1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for / partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/vg0/root&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Activate SWAP:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkswap /dev/vg0/swap&lt;br /&gt;
# swapon /dev/vg0/swap&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mount / partition to /mnt :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t ext4 /dev/vg0/root /mnt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create /boot/efi:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /mnt/boot/efi -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mount UEFI partition to /mnt/boot/efi :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t vfat /dev/nvme0n1p1 /mnt/boot/efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk&lt;br /&gt;
nvme0n1        259:0    0 476.9G  0 disk  &lt;br /&gt;
├─nvme0n1p1    259:1    0   511M  0 part  /mnt/boot/efi&lt;br /&gt;
└─nvme0n1p2    259:2    0 476.4G  0 part  &lt;br /&gt;
  └─lvmcrypt   253:0    0 476.4G  0 crypt &lt;br /&gt;
    ├─vg0-swap 253:1    0    20G  0 lvm   [SWAP]&lt;br /&gt;
    └─vg0-root 253:2    0 456.4G  0 lvm   /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Installing Alpine =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# setup-disk -m sys /mnt/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= mkinitfs settings &amp;amp; modules =&lt;br /&gt;
Edit the /mnt/etc/mkinitfs/mkinitfs.conf file and append the modules to the features parameters (keymap only needed if your keyboard is not QWERTY):&lt;br /&gt;
&amp;lt;pre&amp;gt;features=&amp;quot;ata base ide scsi usb virtio ext4 lvm nvme keymap cryptsetup cryptkey&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Regenerate the initram:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkinitfs -c /mnt/etc/mkinitfs/mkinitfs.conf -b /mnt/ $(ls /mnt/lib/modules/)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Grub settings =&lt;br /&gt;
&lt;br /&gt;
Create a crypto_keyfile.bin to avoid typing the passphrase twice during the boot process (one for Grub partition, one for Alpine partition):&lt;br /&gt;
&amp;lt;pre&amp;gt;# touch /mnt/crypto_keyfile.bin&lt;br /&gt;
# chmod 600 /mnt/crypto_keyfile.bin&lt;br /&gt;
# dd if=/dev/random bs=512 count=4 | xxd -p -c999 | tr -d &#039;\n&#039; &amp;gt; /mnt/c&lt;br /&gt;
rypto_keyfile.bin&lt;br /&gt;
# cryptsetup luksAddKey /dev/nvme0n1p2 /mnt/crypto_keyfile.bin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, let&#039;s mount and chroot to our fresh installation:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t proc /proc /mnt/proc&lt;br /&gt;
# mount --rbind /dev /mnt/dev&lt;br /&gt;
# mount --make-rslave /mnt/dev&lt;br /&gt;
# mount --rbind /sys /mnt/sys&lt;br /&gt;
# chroot /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit /etc/default/grub and add cryptkey after cryptdm=root parameter like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_TIMEOUT=2&lt;br /&gt;
GRUB_DISABLE_SUBMENU=y&lt;br /&gt;
GRUB_DISABLE_RECOVERY=true&lt;br /&gt;
GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;modules=sd-mod,usb-storage,ext4,nvme cryptroot=UUID=XXXX cryptdm=root cryptkey quiet rootfstype=ext4&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add a new GRUB_PRELOAD_MODULES line like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_PRELOAD_MODULES=&amp;quot;luks cryptodisk part_gpt lvm ext4&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let&#039;s show the UUID of our partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk -f&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a /root/grub-pre.cfg and replace &amp;lt;XXXX-UUID_WITHOUT_HYPHENS&amp;gt; with your encrypted root partition UUID (here vg0-root) without hyphens, replace &amp;lt;YYYY&amp;gt; with VG UUID from vgdisplay and replace &amp;lt;ZZZZ&amp;gt; with LV UUID from lvdisplay of your /dev/vg0/root&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set crypto_uuid=&amp;lt;XXXX-UUID_WITHOUT_HYPHENS&amp;gt;&lt;br /&gt;
cryptomount -u $crypto_uuid&lt;br /&gt;
set root=&#039;lvmid/&amp;lt;YYYY&amp;gt;/&amp;lt;ZZZZ&amp;gt;&#039;&lt;br /&gt;
set prefix=($root)/boot/grub&lt;br /&gt;
insmod normal&lt;br /&gt;
normal&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring Secure Boot =&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efi-mkkeys efibootmgr sbsigntool&lt;br /&gt;
# efi-mkkeys -s &amp;quot;Your Name&amp;quot; -o /etc/uefi-keys&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Re-install Grub:&lt;br /&gt;
&amp;lt;pre&amp;gt;# grub-mkimage -p /boot/grub -O x86_64-efi -c /root/grub-pre.cfg -o /tmp/grubx64.efi luks2 part_gpt cryptodisk ext2 gcry_rijndael pbkdf2 gcry_sha512&lt;br /&gt;
# install -v /tmp/grubx64.efi /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sed -i &#039;s/SecureBoot/SecureB00t/&#039; /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi&lt;br /&gt;
# cd /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sbsign --key /etc/uefi-keys/db.key --cert /etc/uefi-keys/db.crt --output grubx64.efi.signed grubx64.efi&lt;br /&gt;
# grub-mkconfig -o /boot/grub/grub.cfg&lt;br /&gt;
# efibootmgr --disk /dev/nvme0n1p1 --part 1 --create --label &#039;Alpine Linux Secure Boot Signed&#039; --load /EFI/AlpineLinuxSecureBoot/grubx64.efi.signed --verbose&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To check that your .efi is signed :&lt;br /&gt;
&amp;lt;pre&amp;gt; # sbverify --cert /etc/uefi-keys/db.crt /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi.signed &lt;br /&gt;
Signature verification OK&lt;br /&gt;
# sbverify --list /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi.signed&lt;br /&gt;
signature 1&lt;br /&gt;
image signature issuers:&lt;br /&gt;
 - /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
image signature certificates:&lt;br /&gt;
 - subject: /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
   issuer:  /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reboot &amp;amp; enter into your UEFI (Fx key depending of your laptop)&lt;br /&gt;
&lt;br /&gt;
== Import keys to UEFI ==&lt;br /&gt;
&lt;br /&gt;
Copy db.auth, KEK.auth and PK.auth files from /etc/uefi-keys to a FAT formatted file system.&lt;br /&gt;
This is just an example from an XPS laptop, each UEFI is unique.&lt;br /&gt;
&lt;br /&gt;
# Go to &#039;&#039;&#039;Boot Configuration&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;Secure Boot&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Enable Secure Boot&#039;&#039;&#039; to &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Secure Boot Mode&#039;&#039;&#039; to &#039;&#039;&#039;Deployed Mode&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Enable Custom Mode&#039;&#039;&#039; to &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
# Go to &#039;&#039;&#039;Custom Mode Key Management&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Reset All Keys&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;db&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;db.auth&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;KEK&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;KEK.auth&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;PK&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;PK.auth&#039;&#039;&#039;&lt;br /&gt;
# &#039;&#039;&#039;APPLY CHANGES&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;EXIT&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Check Secure Boot State:&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add mokutil&lt;br /&gt;
# mokutil --sb-state&lt;br /&gt;
SecureBoot enabled&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Congrats!&lt;/div&gt;</summary>
		<author><name>Blt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22200</id>
		<title>Full disk encryption secure boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22200"/>
		<updated>2022-08-07T18:34:32Z</updated>

		<summary type="html">&lt;p&gt;Blt: missing bloc end&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Draft}}&lt;br /&gt;
&lt;br /&gt;
This guide is to explain, step-by-step, how to setup Alpine Linux with Full Disk Encryption using LUKS2, LVM (one Physical Volume Partition with three Logical Volume Partitions (/ /boot &amp;amp; swap) with hibernation on a NVMe drive, with UEFI &amp;amp; Secure Boot (and hopefully tpm as well : WIP). This guide has been written using Alpine Linux Std 3.16.1, please adapt some commands if needed.&lt;br /&gt;
&lt;br /&gt;
The goal of this guide is to follow the KISS principle, but another file system can be used, multiple partitions for /home; /var/log etc.. can also be added, if the proposed configuration is not meeting your requirements.&lt;br /&gt;
&lt;br /&gt;
= Installing packages =&lt;br /&gt;
&lt;br /&gt;
To facilitate the partitioning we will use gdisk :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lsblk gptfdisk&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For encryption, we will use cryptsetup :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add cryptsetup&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For LVM:&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lvm2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For using and managing UEFI, multiple packages are needed :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efibootmgr e2fsprogs grub grub-efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To improve the entropy :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add haveged&lt;br /&gt;
# rc-service haveged start&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Preparing / overwriting the disk =&lt;br /&gt;
&lt;br /&gt;
This can take long, on my side for a 500GB nVME it tooks ~30 minutes.&lt;br /&gt;
&amp;lt;pre&amp;gt;# haveged -n 0 | dd of=/dev/nvme0n1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Partitioning the disk =&lt;br /&gt;
&lt;br /&gt;
Let&#039;s assume the disk is /dev/nvme0n1 and no partition is present, we will create two partitions :&lt;br /&gt;
 &lt;br /&gt;
* one for UEFI&lt;br /&gt;
* one for LVM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; # gdisk /dev/nvme0n1&lt;br /&gt;
GPT fdisk (gdisk) version 1.0.9.1&lt;br /&gt;
&lt;br /&gt;
Partition table scan:&lt;br /&gt;
  MBR: not present&lt;br /&gt;
  BSD: not present&lt;br /&gt;
  APM: not present&lt;br /&gt;
  GPT: not present&lt;br /&gt;
&lt;br /&gt;
Creating new GPT entries in memory.&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (1-128, default 1): &lt;br /&gt;
First sector (34-1000215182, default = 2048) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (2048-1000215182, default = 1000214527) or {+-}size{KMGTP}: 512M&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): ef00&lt;br /&gt;
Changed type of partition to &#039;EFI system partition&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (2-128, default 2): &lt;br /&gt;
First sector (34-1000215182, default = 1050624) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (1050624-1000215182, default = 1000214527) or {+-}size{KMGTP}: &lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8309&lt;br /&gt;
Changed type of partition to &#039;Linux LUKS&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): w&lt;br /&gt;
&lt;br /&gt;
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING&lt;br /&gt;
PARTITIONS!!&lt;br /&gt;
&lt;br /&gt;
Do you want to proceed? (Y/N): Y&lt;br /&gt;
OK; writing new GUID partition table (GPT) to /dev/nvme0n1.&lt;br /&gt;
The operation has completed successfully.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring LUKS =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 1000 --use-random luksFormat /dev/nvme0n1p2&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p2 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p2: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&lt;br /&gt;
# cryptsetup luksOpen /dev/nvme0n1p2 lvmcrypt&lt;br /&gt;
&lt;br /&gt;
= LVM : Physical &amp;amp; Logical Volumes creation=&lt;br /&gt;
&amp;lt;pre&amp;gt;# pvcreate /dev/mapper/lvmcrypt&lt;br /&gt;
  Physical volume &amp;quot;/dev/mapper/lvmcrypt&amp;quot; successfully created.&lt;br /&gt;
# vgcreate vg0 /dev/mapper/lvmcrypt&lt;br /&gt;
  Volume group &amp;quot;vg0&amp;quot; successfully created&lt;br /&gt;
# lvcreate -L 20G vg0 -n swap (I have a 16GB RAM laptop)&lt;br /&gt;
  Logical volume &amp;quot;swap&amp;quot; created.&lt;br /&gt;
# lvcreate -l 100%FREE vg0 -n root&lt;br /&gt;
  Logical volume &amp;quot;root&amp;quot; created.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To check the creation :&lt;br /&gt;
&amp;lt;pre&amp;gt;# lvscan&lt;br /&gt;
  ACTIVE            &#039;/dev/vg0/swap&#039; [20.00 GiB] inherit&lt;br /&gt;
  ACTIVE            &#039;/dev/vg0/root&#039; [455.92 GiB] inherit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Mounting points and File System =&lt;br /&gt;
&lt;br /&gt;
Create vfat file system for UEFI partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.vfat /dev/nvme0n1p1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for / partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/vg0/root&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Activate SWAP:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkswap /dev/vg0/swap&lt;br /&gt;
# swapon /dev/vg0/swap&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mount / partition to /mnt :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t ext4 /dev/vg0/root /mnt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create /boot/efi:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /mnt/boot/efi -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mount UEFI partition to /mnt/boot/efi :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t vfat /dev/nvme0n1p1 /mnt/boot/efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk&lt;br /&gt;
nvme0n1        259:0    0 476.9G  0 disk  &lt;br /&gt;
├─nvme0n1p1    259:1    0   511M  0 part  /mnt/boot/efi&lt;br /&gt;
└─nvme0n1p2    259:2    0 476.4G  0 part  &lt;br /&gt;
  └─lvmcrypt   253:0    0 476.4G  0 crypt &lt;br /&gt;
    ├─vg0-swap 253:1    0    20G  0 lvm   [SWAP]&lt;br /&gt;
    └─vg0-root 253:2    0 456.4G  0 lvm   /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Installing Alpine =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# setup-disk -m sys /mnt/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= mkinitfs settings &amp;amp; modules =&lt;br /&gt;
Edit the /mnt/etc/mkinitfs/mkinitfs.conf file and append the cryptsetup and lvm modules to the features parameter (keymap only needed if QWERTY is not used):&lt;br /&gt;
&amp;lt;pre&amp;gt;features=&amp;quot;...keymap cryptsetup cryptkey&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Regenerate the initram:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkinitfs -c /mnt/etc/mkinitfs/mkinitfs.conf -b /mnt/ $(ls /mnt/lib/modules/)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Grub settings =&lt;br /&gt;
&lt;br /&gt;
Create a crypto_keyfile.bin to avoid typing the passphrase twice during the boot process (one for Grub partition, one for Alpine partition):&lt;br /&gt;
&amp;lt;pre&amp;gt;# touch /mnt/crypto_keyfile.bin&lt;br /&gt;
# chmod 600 /mnt/crypto_keyfile.bin&lt;br /&gt;
# dd bs=512 count=4 if=/dev/urandom of=/mnt/crypto_keyfile.bin&lt;br /&gt;
# cryptsetup luksAddKey /dev/nvme0n1p3 /mnt/crypto_keyfile.bin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, let&#039;s mount and chroot to our fresh installation:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t proc /proc /mnt/proc&lt;br /&gt;
# mount --rbind /dev /mnt/dev&lt;br /&gt;
# mount --make-rslave /mnt/dev&lt;br /&gt;
# mount --rbind /sys /mnt/sys&lt;br /&gt;
# chroot /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let&#039;s show the UUID of our partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk -f&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit /etc/default/grub and add a new line starting with GRUB_CMDLINE_LINUX parameter, replacing &amp;lt;UUID&amp;gt; with the UUID of the encrypted partition (in this case /dev/nvme0n1p3) and adding a new GRUB_PRELOAD_MODULES line like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_CMDLINE_LINUX=&amp;quot;cryptroot=UUID=&amp;lt;UUID&amp;gt; cryptdm=nvme0n1p3-crypt cryptkey&amp;quot;&lt;br /&gt;
GRUB_PRELOAD_MODULES=&amp;quot;luks cryptodisk part_gpt&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a /root/grub-pre.cfg and replace &amp;lt;UUID_WITHOUT_HYPHENS&amp;gt; with your encrypted root partition UUID (here /dev/nvme0n1p3) without hyphens&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set crypto_uuid=&amp;lt;UUID_WITHOUT_HYPHENS&amp;gt;&lt;br /&gt;
cryptomount -u $crypto_uuid&lt;br /&gt;
set root=crypto0&lt;br /&gt;
set prefix=($root)/boot/grub&lt;br /&gt;
insmod normal&lt;br /&gt;
normal&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring Secure Boot =&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efi-mkkeys efibootmgr sbsigntool&lt;br /&gt;
# efi-mkkeys -s &amp;quot;Your Name&amp;quot; -o /etc/uefi-keys&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Re-install Grub:&lt;br /&gt;
&amp;lt;pre&amp;gt;# grub-mkimage -p /boot/grub -O x86_64-efi -c /root/grub-pre.cfg -o /tmp/grubx64.efi luks2 part_gpt cryptodisk ext2 gcry_rijndael pbkdf2 gcry_sha512&lt;br /&gt;
# install -v /tmp/grubx64.efi /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sed -i &#039;s/SecureBoot/SecureB00t/&#039; /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi&lt;br /&gt;
# cd /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sbsign --key /etc/uefi-keys/db.key --cert /etc/uefi-keys/db.crt --output grubx64.efi.signed grubx64.efi&lt;br /&gt;
# grub-mkconfig -o /boot/grub/grub.cfg&lt;br /&gt;
# efibootmgr --disk /dev/nvme0n1p1 --part 1 --create --label &#039;Alpine Linux Secure Boot Signed&#039; --load /EFI/AlpineLinuxSecureBoot/grubx64.efi.signed --verbose&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To check that your .efi is signed :&lt;br /&gt;
&amp;lt;pre&amp;gt; # sbverify --cert /etc/uefi-keys/db.crt /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi.signed &lt;br /&gt;
Signature verification OK&lt;br /&gt;
# sbverify --list /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi.signed&lt;br /&gt;
signature 1&lt;br /&gt;
image signature issuers:&lt;br /&gt;
 - /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
image signature certificates:&lt;br /&gt;
 - subject: /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
   issuer:  /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reboot &amp;amp; enter into your UEFI (Fx key depending of your laptop)&lt;br /&gt;
&lt;br /&gt;
== Import keys to UEFI ==&lt;br /&gt;
&lt;br /&gt;
Copy db.auth, KEK.auth and PK.auth files from /etc/uefi-keys to a FAT formatted file system.&lt;br /&gt;
This is just an example from an XPS laptop, each UEFI is unique.&lt;br /&gt;
&lt;br /&gt;
# Go to &#039;&#039;&#039;Boot Configuration&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;Secure Boot&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Enable Secure Boot&#039;&#039;&#039; to &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Secure Boot Mode&#039;&#039;&#039; to &#039;&#039;&#039;Deployed Mode&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Enable Custom Mode&#039;&#039;&#039; to &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
# Go to &#039;&#039;&#039;Custom Mode Key Management&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Reset All Keys&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;db&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;db.auth&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;KEK&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;KEK.auth&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;PK&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;PK.auth&#039;&#039;&#039;&lt;br /&gt;
# &#039;&#039;&#039;APPLY CHANGES&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;EXIT&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Check Secure Boot State:&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add mokutil&lt;br /&gt;
# mokutil --sb-state&lt;br /&gt;
SecureBoot enabled&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Congrats!&lt;/div&gt;</summary>
		<author><name>Blt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22199</id>
		<title>Full disk encryption secure boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22199"/>
		<updated>2022-08-07T18:33:51Z</updated>

		<summary type="html">&lt;p&gt;Blt: small tweaks and proof until &amp;#039;Installing Alpine&amp;#039;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Draft}}&lt;br /&gt;
&lt;br /&gt;
This guide is to explain, step-by-step, how to setup Alpine Linux with Full Disk Encryption using LUKS2, LVM (one Physical Volume Partition with three Logical Volume Partitions (/ /boot &amp;amp; swap) with hibernation on a NVMe drive, with UEFI &amp;amp; Secure Boot (and hopefully tpm as well : WIP). This guide has been written using Alpine Linux Std 3.16.1, please adapt some commands if needed.&lt;br /&gt;
&lt;br /&gt;
The goal of this guide is to follow the KISS principle, but another file system can be used, multiple partitions for /home; /var/log etc.. can also be added, if the proposed configuration is not meeting your requirements.&lt;br /&gt;
&lt;br /&gt;
= Installing packages =&lt;br /&gt;
&lt;br /&gt;
To facilitate the partitioning we will use gdisk :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lsblk gptfdisk&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For encryption, we will use cryptsetup :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add cryptsetup&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For LVM:&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lvm2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For using and managing UEFI, multiple packages are needed :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efibootmgr e2fsprogs grub grub-efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To improve the entropy :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add haveged&lt;br /&gt;
# rc-service haveged start&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Preparing / overwriting the disk =&lt;br /&gt;
&lt;br /&gt;
This can take long, on my side for a 500GB nVME it tooks ~30 minutes.&lt;br /&gt;
&amp;lt;pre&amp;gt;# haveged -n 0 | dd of=/dev/nvme0n1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Partitioning the disk =&lt;br /&gt;
&lt;br /&gt;
Let&#039;s assume the disk is /dev/nvme0n1 and no partition is present, we will create two partitions :&lt;br /&gt;
 &lt;br /&gt;
* one for UEFI&lt;br /&gt;
* one for LVM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt; # gdisk /dev/nvme0n1&lt;br /&gt;
GPT fdisk (gdisk) version 1.0.9.1&lt;br /&gt;
&lt;br /&gt;
Partition table scan:&lt;br /&gt;
  MBR: not present&lt;br /&gt;
  BSD: not present&lt;br /&gt;
  APM: not present&lt;br /&gt;
  GPT: not present&lt;br /&gt;
&lt;br /&gt;
Creating new GPT entries in memory.&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (1-128, default 1): &lt;br /&gt;
First sector (34-1000215182, default = 2048) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (2048-1000215182, default = 1000214527) or {+-}size{KMGTP}: 512M&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): ef00&lt;br /&gt;
Changed type of partition to &#039;EFI system partition&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (2-128, default 2): &lt;br /&gt;
First sector (34-1000215182, default = 1050624) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (1050624-1000215182, default = 1000214527) or {+-}size{KMGTP}: &lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8309&lt;br /&gt;
Changed type of partition to &#039;Linux LUKS&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): w&lt;br /&gt;
&lt;br /&gt;
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING&lt;br /&gt;
PARTITIONS!!&lt;br /&gt;
&lt;br /&gt;
Do you want to proceed? (Y/N): Y&lt;br /&gt;
OK; writing new GUID partition table (GPT) to /dev/nvme0n1.&lt;br /&gt;
The operation has completed successfully.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring LUKS =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 1000 --use-random luksFormat /dev/nvme0n1p2&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p2 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p2: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&lt;br /&gt;
# cryptsetup luksOpen /dev/nvme0n1p2 lvmcrypt&lt;br /&gt;
&lt;br /&gt;
= LVM : Physical &amp;amp; Logical Volumes creation=&lt;br /&gt;
&amp;lt;pre&amp;gt;# pvcreate /dev/mapper/lvmcrypt&lt;br /&gt;
  Physical volume &amp;quot;/dev/mapper/lvmcrypt&amp;quot; successfully created.&lt;br /&gt;
# vgcreate vg0 /dev/mapper/lvmcrypt&lt;br /&gt;
  Volume group &amp;quot;vg0&amp;quot; successfully created&lt;br /&gt;
# lvcreate -L 20G vg0 -n swap (I have a 16GB RAM laptop)&lt;br /&gt;
  Logical volume &amp;quot;swap&amp;quot; created.&lt;br /&gt;
# lvcreate -l 100%FREE vg0 -n root&lt;br /&gt;
  Logical volume &amp;quot;root&amp;quot; created.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To check the creation :&lt;br /&gt;
&amp;lt;pre&amp;gt;# lvscan&lt;br /&gt;
  ACTIVE            &#039;/dev/vg0/swap&#039; [20.00 GiB] inherit&lt;br /&gt;
  ACTIVE            &#039;/dev/vg0/root&#039; [455.92 GiB] inherit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Mounting points and File System =&lt;br /&gt;
&lt;br /&gt;
Create vfat file system for UEFI partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.vfat /dev/nvme0n1p1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for / partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/vg0/root&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Activate SWAP:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkswap /dev/vg0/swap&lt;br /&gt;
# swapon /dev/vg0/swap&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mount / partition to /mnt :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t ext4 /dev/vg0/root /mnt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create /boot/efi:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /mnt/boot/efi -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mount UEFI partition to /mnt/boot/efi :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t vfat /dev/nvme0n1p1 /mnt/boot/efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk&lt;br /&gt;
nvme0n1        259:0    0 476.9G  0 disk  &lt;br /&gt;
├─nvme0n1p1    259:1    0   511M  0 part  /mnt/boot/efi&lt;br /&gt;
└─nvme0n1p2    259:2    0 476.4G  0 part  &lt;br /&gt;
  └─lvmcrypt   253:0    0 476.4G  0 crypt &lt;br /&gt;
    ├─vg0-swap 253:1    0    20G  0 lvm   [SWAP]&lt;br /&gt;
    └─vg0-root 253:2    0 456.4G  0 lvm   /mnt&lt;br /&gt;
&lt;br /&gt;
= Installing Alpine =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# setup-disk -m sys /mnt/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= mkinitfs settings &amp;amp; modules =&lt;br /&gt;
Edit the /mnt/etc/mkinitfs/mkinitfs.conf file and append the cryptsetup and lvm modules to the features parameter (keymap only needed if QWERTY is not used):&lt;br /&gt;
&amp;lt;pre&amp;gt;features=&amp;quot;...keymap cryptsetup cryptkey&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Regenerate the initram:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkinitfs -c /mnt/etc/mkinitfs/mkinitfs.conf -b /mnt/ $(ls /mnt/lib/modules/)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Grub settings =&lt;br /&gt;
&lt;br /&gt;
Create a crypto_keyfile.bin to avoid typing the passphrase twice during the boot process (one for Grub partition, one for Alpine partition):&lt;br /&gt;
&amp;lt;pre&amp;gt;# touch /mnt/crypto_keyfile.bin&lt;br /&gt;
# chmod 600 /mnt/crypto_keyfile.bin&lt;br /&gt;
# dd bs=512 count=4 if=/dev/urandom of=/mnt/crypto_keyfile.bin&lt;br /&gt;
# cryptsetup luksAddKey /dev/nvme0n1p3 /mnt/crypto_keyfile.bin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, let&#039;s mount and chroot to our fresh installation:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t proc /proc /mnt/proc&lt;br /&gt;
# mount --rbind /dev /mnt/dev&lt;br /&gt;
# mount --make-rslave /mnt/dev&lt;br /&gt;
# mount --rbind /sys /mnt/sys&lt;br /&gt;
# chroot /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let&#039;s show the UUID of our partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk -f&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit /etc/default/grub and add a new line starting with GRUB_CMDLINE_LINUX parameter, replacing &amp;lt;UUID&amp;gt; with the UUID of the encrypted partition (in this case /dev/nvme0n1p3) and adding a new GRUB_PRELOAD_MODULES line like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_CMDLINE_LINUX=&amp;quot;cryptroot=UUID=&amp;lt;UUID&amp;gt; cryptdm=nvme0n1p3-crypt cryptkey&amp;quot;&lt;br /&gt;
GRUB_PRELOAD_MODULES=&amp;quot;luks cryptodisk part_gpt&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a /root/grub-pre.cfg and replace &amp;lt;UUID_WITHOUT_HYPHENS&amp;gt; with your encrypted root partition UUID (here /dev/nvme0n1p3) without hyphens&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set crypto_uuid=&amp;lt;UUID_WITHOUT_HYPHENS&amp;gt;&lt;br /&gt;
cryptomount -u $crypto_uuid&lt;br /&gt;
set root=crypto0&lt;br /&gt;
set prefix=($root)/boot/grub&lt;br /&gt;
insmod normal&lt;br /&gt;
normal&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring Secure Boot =&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efi-mkkeys efibootmgr sbsigntool&lt;br /&gt;
# efi-mkkeys -s &amp;quot;Your Name&amp;quot; -o /etc/uefi-keys&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Re-install Grub:&lt;br /&gt;
&amp;lt;pre&amp;gt;# grub-mkimage -p /boot/grub -O x86_64-efi -c /root/grub-pre.cfg -o /tmp/grubx64.efi luks2 part_gpt cryptodisk ext2 gcry_rijndael pbkdf2 gcry_sha512&lt;br /&gt;
# install -v /tmp/grubx64.efi /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sed -i &#039;s/SecureBoot/SecureB00t/&#039; /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi&lt;br /&gt;
# cd /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sbsign --key /etc/uefi-keys/db.key --cert /etc/uefi-keys/db.crt --output grubx64.efi.signed grubx64.efi&lt;br /&gt;
# grub-mkconfig -o /boot/grub/grub.cfg&lt;br /&gt;
# efibootmgr --disk /dev/nvme0n1p1 --part 1 --create --label &#039;Alpine Linux Secure Boot Signed&#039; --load /EFI/AlpineLinuxSecureBoot/grubx64.efi.signed --verbose&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To check that your .efi is signed :&lt;br /&gt;
&amp;lt;pre&amp;gt; # sbverify --cert /etc/uefi-keys/db.crt /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi.signed &lt;br /&gt;
Signature verification OK&lt;br /&gt;
# sbverify --list /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi.signed&lt;br /&gt;
signature 1&lt;br /&gt;
image signature issuers:&lt;br /&gt;
 - /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
image signature certificates:&lt;br /&gt;
 - subject: /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
   issuer:  /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reboot &amp;amp; enter into your UEFI (Fx key depending of your laptop)&lt;br /&gt;
&lt;br /&gt;
== Import keys to UEFI ==&lt;br /&gt;
&lt;br /&gt;
Copy db.auth, KEK.auth and PK.auth files from /etc/uefi-keys to a FAT formatted file system.&lt;br /&gt;
This is just an example from an XPS laptop, each UEFI is unique.&lt;br /&gt;
&lt;br /&gt;
# Go to &#039;&#039;&#039;Boot Configuration&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;Secure Boot&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Enable Secure Boot&#039;&#039;&#039; to &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Secure Boot Mode&#039;&#039;&#039; to &#039;&#039;&#039;Deployed Mode&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Enable Custom Mode&#039;&#039;&#039; to &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
# Go to &#039;&#039;&#039;Custom Mode Key Management&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Reset All Keys&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;db&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;db.auth&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;KEK&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;KEK.auth&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;PK&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;PK.auth&#039;&#039;&#039;&lt;br /&gt;
# &#039;&#039;&#039;APPLY CHANGES&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;EXIT&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Check Secure Boot State:&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add mokutil&lt;br /&gt;
# mokutil --sb-state&lt;br /&gt;
SecureBoot enabled&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Congrats!&lt;/div&gt;</summary>
		<author><name>Blt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22198</id>
		<title>Full disk encryption secure boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22198"/>
		<updated>2022-08-07T17:52:02Z</updated>

		<summary type="html">&lt;p&gt;Blt: converting the guide for LVM until Installing Alpine&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Draft}}&lt;br /&gt;
&lt;br /&gt;
This guide is to explain, step-by-step, how to setup Alpine Linux with Full Disk Encryption using LUKS2, LVM (one Physical Volume Partition with three Logical Volume Partitions (/ /boot &amp;amp; swap) with hibernation on a NVMe drive, with UEFI &amp;amp; Secure Boot (and hopefully tpm as well : WIP). This guide has been written using Alpine Linux Std 3.16.1, please adapt some commands if needed.&lt;br /&gt;
&lt;br /&gt;
The goal of this guide is to follow the KISS principle, but another file system can be used, multiple partitions for /home; /var/log etc.. can also be added, if the proposed configuration is not meeting your requirements.&lt;br /&gt;
&lt;br /&gt;
= Installing packages =&lt;br /&gt;
&lt;br /&gt;
To facilitate the partitioning we will use gdisk :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lsblk gptfdisk&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For encryption, we will use cryptsetup :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add cryptsetup&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For LVM:&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lvm2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For using and managing UEFI, multiple packages are needed :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efibootmgr e2fsprogs grub grub-efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To improve the entropy :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add haveged&lt;br /&gt;
# rc-service haveged start&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Preparing / overwriting the disk =&lt;br /&gt;
&lt;br /&gt;
This can take long, on my side for a 500GB nVME it tooks ~30 minutes.&lt;br /&gt;
&amp;lt;pre&amp;gt;# haveged -n 0 | dd of=/dev/nvme0n1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Partitioning the disk =&lt;br /&gt;
&lt;br /&gt;
Let&#039;s assume the disk is /dev/nvme0n1 and no partition is present, we will create two partitions :&lt;br /&gt;
 &lt;br /&gt;
* one for UEFI&lt;br /&gt;
* one for LVM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# gdisk /dev/nvme0n1&lt;br /&gt;
GPT fdisk (gdisk) version 1.0.9.1&lt;br /&gt;
&lt;br /&gt;
Partition table scan:&lt;br /&gt;
  MBR: protective&lt;br /&gt;
  BSD: not present&lt;br /&gt;
  APM: not present&lt;br /&gt;
  GPT: present&lt;br /&gt;
&lt;br /&gt;
Found valid GPT with protective MBR; using GPT.&lt;br /&gt;
&lt;br /&gt;
Command (? for help): d&lt;br /&gt;
No partitions&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (1-128, default 1): &lt;br /&gt;
First sector (2048-1000215182, default = 2048) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (2048-1000215182, default = 1000214527) or {+-}size{KMGTP}: 512M&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): ef00&lt;br /&gt;
Changed type of partition to &#039;EFI system partition&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (2-128, default 2): &lt;br /&gt;
First sector (1048577-1000215182, default = 33556480) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (33556480-1000215182, default = 1000214527) or {+-}size{KMGTP}: &lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8309&lt;br /&gt;
Changed type of partition to &#039;Linux LUKS&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): w&lt;br /&gt;
&lt;br /&gt;
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING&lt;br /&gt;
PARTITIONS!!&lt;br /&gt;
&lt;br /&gt;
Do you want to proceed? (Y/N): Y&lt;br /&gt;
OK; writing new GUID partition table (GPT) to /dev/nvme0n1.&lt;br /&gt;
The operation has completed successfully.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring LUKS =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 1000 --use-random luksFormat /dev/nvme0n1p2&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p2 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p2: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&lt;br /&gt;
# cryptsetup luksOpen /dev/nvme0n1p2 lvmcrypt&lt;br /&gt;
&lt;br /&gt;
= LVM : Physical &amp;amp; Logical Volumes creation=&lt;br /&gt;
&amp;lt;pre&amp;gt;# pvcreate /dev/mapper/lvmcrypt&lt;br /&gt;
# vgcreate vg0 /dev/mapper/lvmcrypt&lt;br /&gt;
# lvcreate -L 20G vg0 -n swap (I have a 16GB RAM laptop)&lt;br /&gt;
# lvcreate -L 512M vg0 -n boot&lt;br /&gt;
# lvcreate -l 100%FREE vg0 -n root&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To check the creation :&lt;br /&gt;
&amp;lt;pre&amp;gt;# lvscan&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Mounting points and File System =&lt;br /&gt;
&lt;br /&gt;
Create vfat file system for UEFI partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.vfat /dev/nvme0n1p1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for / partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/vg0/root&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Activate SWAP:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkswap /dev/vg0/swap&lt;br /&gt;
# swapon /dev/vg0/swap&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mount / partition to /mnt :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t ext4 /dev/vg0/root /mnt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create /boot/efi:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /mnt/boot/efi -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mount UEFI partition to /mnt/boot/efi :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t vfat /dev/nvme0n1p1 /mnt/boot/efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Installing Alpine =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# setup-disk -m sys /mnt/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= mkinitfs settings &amp;amp; modules =&lt;br /&gt;
Edit the /mnt/etc/mkinitfs/mkinitfs.conf file and append the cryptsetup and lvm modules to the features parameter (keymap only needed if QWERTY is not used):&lt;br /&gt;
&amp;lt;pre&amp;gt;features=&amp;quot;...keymap cryptsetup cryptkey&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Regenerate the initram:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkinitfs -c /mnt/etc/mkinitfs/mkinitfs.conf -b /mnt/ $(ls /mnt/lib/modules/)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Grub settings =&lt;br /&gt;
&lt;br /&gt;
Create a crypto_keyfile.bin to avoid typing the passphrase twice during the boot process (one for Grub partition, one for Alpine partition):&lt;br /&gt;
&amp;lt;pre&amp;gt;# touch /mnt/crypto_keyfile.bin&lt;br /&gt;
# chmod 600 /mnt/crypto_keyfile.bin&lt;br /&gt;
# dd bs=512 count=4 if=/dev/urandom of=/mnt/crypto_keyfile.bin&lt;br /&gt;
# cryptsetup luksAddKey /dev/nvme0n1p3 /mnt/crypto_keyfile.bin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, let&#039;s mount and chroot to our fresh installation:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t proc /proc /mnt/proc&lt;br /&gt;
# mount --rbind /dev /mnt/dev&lt;br /&gt;
# mount --make-rslave /mnt/dev&lt;br /&gt;
# mount --rbind /sys /mnt/sys&lt;br /&gt;
# chroot /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let&#039;s show the UUID of our partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk -f&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit /etc/default/grub and add a new line starting with GRUB_CMDLINE_LINUX parameter, replacing &amp;lt;UUID&amp;gt; with the UUID of the encrypted partition (in this case /dev/nvme0n1p3) and adding a new GRUB_PRELOAD_MODULES line like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_CMDLINE_LINUX=&amp;quot;cryptroot=UUID=&amp;lt;UUID&amp;gt; cryptdm=nvme0n1p3-crypt cryptkey&amp;quot;&lt;br /&gt;
GRUB_PRELOAD_MODULES=&amp;quot;luks cryptodisk part_gpt&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a /root/grub-pre.cfg and replace &amp;lt;UUID_WITHOUT_HYPHENS&amp;gt; with your encrypted root partition UUID (here /dev/nvme0n1p3) without hyphens&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set crypto_uuid=&amp;lt;UUID_WITHOUT_HYPHENS&amp;gt;&lt;br /&gt;
cryptomount -u $crypto_uuid&lt;br /&gt;
set root=crypto0&lt;br /&gt;
set prefix=($root)/boot/grub&lt;br /&gt;
insmod normal&lt;br /&gt;
normal&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring Secure Boot =&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efi-mkkeys efibootmgr sbsigntool&lt;br /&gt;
# efi-mkkeys -s &amp;quot;Your Name&amp;quot; -o /etc/uefi-keys&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Re-install Grub:&lt;br /&gt;
&amp;lt;pre&amp;gt;# grub-mkimage -p /boot/grub -O x86_64-efi -c /root/grub-pre.cfg -o /tmp/grubx64.efi luks2 part_gpt cryptodisk ext2 gcry_rijndael pbkdf2 gcry_sha512&lt;br /&gt;
# install -v /tmp/grubx64.efi /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sed -i &#039;s/SecureBoot/SecureB00t/&#039; /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi&lt;br /&gt;
# cd /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sbsign --key /etc/uefi-keys/db.key --cert /etc/uefi-keys/db.crt --output grubx64.efi.signed grubx64.efi&lt;br /&gt;
# grub-mkconfig -o /boot/grub/grub.cfg&lt;br /&gt;
# efibootmgr --disk /dev/nvme0n1p1 --part 1 --create --label &#039;Alpine Linux Secure Boot Signed&#039; --load /EFI/AlpineLinuxSecureBoot/grubx64.efi.signed --verbose&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To check that your .efi is signed :&lt;br /&gt;
&amp;lt;pre&amp;gt; # sbverify --cert /etc/uefi-keys/db.crt /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi.signed &lt;br /&gt;
Signature verification OK&lt;br /&gt;
# sbverify --list /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi.signed&lt;br /&gt;
signature 1&lt;br /&gt;
image signature issuers:&lt;br /&gt;
 - /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
image signature certificates:&lt;br /&gt;
 - subject: /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
   issuer:  /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reboot &amp;amp; enter into your UEFI (Fx key depending of your laptop)&lt;br /&gt;
&lt;br /&gt;
== Import keys to UEFI ==&lt;br /&gt;
&lt;br /&gt;
Copy db.auth, KEK.auth and PK.auth files from /etc/uefi-keys to a FAT formatted file system.&lt;br /&gt;
This is just an example from an XPS laptop, each UEFI is unique.&lt;br /&gt;
&lt;br /&gt;
# Go to &#039;&#039;&#039;Boot Configuration&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;Secure Boot&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Enable Secure Boot&#039;&#039;&#039; to &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Secure Boot Mode&#039;&#039;&#039; to &#039;&#039;&#039;Deployed Mode&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Enable Custom Mode&#039;&#039;&#039; to &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
# Go to &#039;&#039;&#039;Custom Mode Key Management&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Reset All Keys&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;db&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;db.auth&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;KEK&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;KEK.auth&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;PK&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;PK.auth&#039;&#039;&#039;&lt;br /&gt;
# &#039;&#039;&#039;APPLY CHANGES&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;EXIT&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Check Secure Boot State:&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add mokutil&lt;br /&gt;
# mokutil --sb-state&lt;br /&gt;
SecureBoot enabled&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Congrats!&lt;/div&gt;</summary>
		<author><name>Blt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22180</id>
		<title>Full disk encryption secure boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22180"/>
		<updated>2022-08-04T13:18:05Z</updated>

		<summary type="html">&lt;p&gt;Blt: Delete Sequence of Events, same as contents&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Draft}}&lt;br /&gt;
&lt;br /&gt;
This guide is to explain step by step how to setup Alpine Linux with Full Disk Encryption using LUKS2, /boot &amp;amp; / together on the same partition, encrypted swap for hibernation on a nvme drive, with UEFI &amp;amp; Secure Boot.&lt;br /&gt;
The goal of this guide is to follow the KISS principle, lvm can be added, another file system can be used, multiple partitions for /home; /var/log etc.. can also be added, if running everything in one partition is not meeting your requirements.&lt;br /&gt;
&lt;br /&gt;
= Installing packages =&lt;br /&gt;
&lt;br /&gt;
To facilitate the partitioning we will use gdisk :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lsblk gptfdisk&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For encryption, we will use cryptsetup :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add cryptsetup&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For using and managing UEFI, multiple packages are needed :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efibootmgr e2fsprogs grub grub-efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Partitioning the disk =&lt;br /&gt;
&lt;br /&gt;
Let&#039;s assume the disk is /dev/nvme0n1 and no partition is present, we will create three partitions :&lt;br /&gt;
 &lt;br /&gt;
* one for UEFI&lt;br /&gt;
* one for /&lt;br /&gt;
* one for swap (hibernation)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# gdisk /dev/nvme0n1&lt;br /&gt;
GPT fdisk (gdisk) version 1.0.9.1&lt;br /&gt;
&lt;br /&gt;
Partition table scan:&lt;br /&gt;
  MBR: protective&lt;br /&gt;
  BSD: not present&lt;br /&gt;
  APM: not present&lt;br /&gt;
  GPT: present&lt;br /&gt;
&lt;br /&gt;
Found valid GPT with protective MBR; using GPT.&lt;br /&gt;
&lt;br /&gt;
Command (? for help): d&lt;br /&gt;
No partitions&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (1-128, default 1): &lt;br /&gt;
First sector (2048-1000215182, default = 2048) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (2048-1000215182, default = 1000214527) or {+-}size{KMGTP}: 512M&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): ef00&lt;br /&gt;
Changed type of partition to &#039;EFI system partition&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (2-128, default 2): &lt;br /&gt;
First sector (1048577-1000215182, default = 1050624) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (1050624-1000215182, default = 1000214527) or {+-}size{KMGTP}: 16G&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8200&lt;br /&gt;
Changed type of partition to &#039;Linux swap&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (3-128, default 3): &lt;br /&gt;
First sector (1048577-1000215182, default = 33556480) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (33556480-1000215182, default = 1000214527) or {+-}size{KMGTP}: &lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8309&lt;br /&gt;
Changed type of partition to &#039;Linux LUKS&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): w&lt;br /&gt;
&lt;br /&gt;
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING&lt;br /&gt;
PARTITIONS!!&lt;br /&gt;
&lt;br /&gt;
Do you want to proceed? (Y/N): Y&lt;br /&gt;
OK; writing new GUID partition table (GPT) to /dev/nvme0n1.&lt;br /&gt;
The operation has completed successfully.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring LUKS =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 5000 --use-random luksFormat /dev/nvme0n1p2&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p2 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p2: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&lt;br /&gt;
# cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 5000 --use-random luksFormat /dev/nvme0n1p3&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p3 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p3: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Mounting points and File System =&lt;br /&gt;
&lt;br /&gt;
Open the LUKS partitiond we just created:&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup luksOpen /dev/nvme0n1p2 nvme0n1p2-crypt&lt;br /&gt;
# cryptsetup luksOpen /dev/nvme0n1p3 nvme0n1p3-crypt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create vfat file system for UEFI partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.vfat /dev/nvme0n1p1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for swap partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/mapper/nvme0n1p2-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for / partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/mapper/nvme0n1p3-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create mounting points and mount partitions :&lt;br /&gt;
Mount / partition to /mnt :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t ext4 /dev/mapper/nvme0n1p3-crypt /mnt&amp;lt;/pre&amp;gt;&lt;br /&gt;
Create /boot/efi:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /mnt/boot/efi -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
Mount UEFI partition to /mnt/boot/efi :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t vfat /dev/nvme0n1p1 /mnt/boot/efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
Activate SWAP:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkswap /dev/mapper/nvme0n1p2-crypt&lt;br /&gt;
# swapon /dev/mapper/nvme0n1p2-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk&lt;br /&gt;
NAME                MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINTS&lt;br /&gt;
nvme0n1             259:0    0 476.9G  0 disk  &lt;br /&gt;
├─nvme0n1p1         259:1    0   511M  0 part  /mnt/boot/efi&lt;br /&gt;
├─nvme0n1p2         259:2    0  15.5G  0 part  &lt;br /&gt;
│ └─nvme0n1p2-crypt 253:0    0  15.5G  0 crypt [SWAP]&lt;br /&gt;
└─nvme0n1p3         259:3    0 460.9G  0 part  &lt;br /&gt;
  └─nvme0n1p3-crypt 253:1    0 460.9G  0 crypt /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Installing Alpine =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# setup-disk -m sys /mnt/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= mkinitfs settings &amp;amp; modules =&lt;br /&gt;
Edit the /mnt/etc/mkinitfs/mkinitfs.conf file and append the cryptsetup module to the features parameter (keymap only needed if QWERTY is not used):&lt;br /&gt;
&amp;lt;pre&amp;gt;features=&amp;quot;...keymap cryptsetup cryptkey&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Regenerate the initram:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkinitfs -c /mnt/etc/mkinitfs/mkinitfs.conf -b /mnt/ $(ls /mnt/lib/modules/)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Grub settings =&lt;br /&gt;
&lt;br /&gt;
Create a crypto_keyfile.bin to avoid typing the passphrase twice during the boot process (one for Grub partition, one for Alpine partition):&lt;br /&gt;
&amp;lt;pre&amp;gt;# touch /mnt/crypto_keyfile.bin&lt;br /&gt;
# chmod 600 /mnt/crypto_keyfile.bin&lt;br /&gt;
# dd bs=512 count=4 if=/dev/urandom of=/mnt/crypto_keyfile.bin&lt;br /&gt;
# cryptsetup luksAddKey /dev/nvme0n1p3 /mnt/crypto_keyfile.bin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, let&#039;s mount and chroot to our fresh installation:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t proc /proc /mnt/proc&lt;br /&gt;
# mount --rbind /dev /mnt/dev&lt;br /&gt;
# mount --make-rslave /mnt/dev&lt;br /&gt;
# mount --rbind /sys /mnt/sys&lt;br /&gt;
# chroot /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let&#039;s show the UUID of our partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk -f&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit /etc/default/grub and add a new line starting with GRUB_CMDLINE_LINUX parameter, replacing &amp;lt;UUID&amp;gt; with the UUID of the encrypted partition (in this case /dev/nvme0n1p3) and adding a new GRUB_PRELOAD_MODULES line like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_CMDLINE_LINUX=&amp;quot;cryptroot=UUID=&amp;lt;UUID&amp;gt; cryptdm=nvme0n1p3-crypt cryptkey&amp;quot;&lt;br /&gt;
GRUB_PRELOAD_MODULES=&amp;quot;luks cryptodisk part_gpt&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a /root/grub-pre.cfg and replace &amp;lt;UUID_WITHOUT_HYPHENS&amp;gt; with your encrypted root partition UUID (here /dev/nvme0n1p3) without hyphens&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set crypto_uuid=&amp;lt;UUID_WITHOUT_HYPHENS&amp;gt;&lt;br /&gt;
cryptomount -u $crypto_uuid&lt;br /&gt;
set root=crypto0&lt;br /&gt;
set prefix=($root)/boot/grub&lt;br /&gt;
insmod normal&lt;br /&gt;
normal&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring Secure Boot =&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efi-mkkeys efibootmgr sbsigntool&lt;br /&gt;
# efi-mkkeys -s &amp;quot;Your Name&amp;quot; -o /etc/uefi-keys&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Re-install Grub:&lt;br /&gt;
&amp;lt;pre&amp;gt;# grub-mkimage -p /boot/grub -O x86_64-efi -c /root/grub-pre.cfg -o /tmp/grubx64.efi luks2 part_gpt cryptodisk ext2 gcry_rijndael pbkdf2 gcry_sha512&lt;br /&gt;
# install -v /tmp/grubx64.efi /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sed -i &#039;s/SecureBoot/SecureB00t/&#039; /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi&lt;br /&gt;
# cd /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sbsign --key /etc/uefi-keys/db.key --cert /etc/uefi-keys/db.crt --output grubx64.efi.signed grubx64.efi&lt;br /&gt;
# grub-mkconfig -o /boot/grub/grub.cfg&lt;br /&gt;
# efibootmgr --disk /dev/nvme0n1p1 --part 1 --create --label &#039;Alpine Linux Secure Boot Signed&#039; --load /EFI/AlpineLinuxSecureBoot/grubx64.efi.signed --verbose&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To check that your .efi is signed :&lt;br /&gt;
&amp;lt;pre&amp;gt; # sbverify --cert /etc/uefi-keys/db.crt /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi.signed &lt;br /&gt;
Signature verification OK&lt;br /&gt;
sbverify --list /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi.signed&lt;br /&gt;
signature 1&lt;br /&gt;
image signature issuers:&lt;br /&gt;
 - /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
image signature certificates:&lt;br /&gt;
 - subject: /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
   issuer:  /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reboot &amp;amp; enter into your UEFI (Fx key depending of your laptop)&lt;br /&gt;
&lt;br /&gt;
== Import keys to UEFI ==&lt;br /&gt;
&lt;br /&gt;
Copy db.auth, KEK.auth and PK.auth files from /etc/uefi-keys to a FAT formatted file system.&lt;br /&gt;
This is just an example from an XPS laptop, each UEFI is unique.&lt;br /&gt;
&lt;br /&gt;
# Go to &#039;&#039;&#039;Boot Configuration&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;Secure Boot&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Enable Secure Boot&#039;&#039;&#039; to &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Secure Boot Mode&#039;&#039;&#039; to &#039;&#039;&#039;Deployed Mode&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Enable Custom Mode&#039;&#039;&#039; to &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
# Go to &#039;&#039;&#039;Custom Mode Key Management&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Reset All Keys&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;db&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;db.auth&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;KEK&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;KEK.auth&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;PK&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;PK.auth&#039;&#039;&#039;&lt;br /&gt;
# &#039;&#039;&#039;APPLY CHANGES&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;EXIT&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Check Secure Boot State:&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add mokutil&lt;br /&gt;
# mokutil --sb-state&lt;br /&gt;
SecureBoot enabled&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Congrats!&lt;/div&gt;</summary>
		<author><name>Blt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22179</id>
		<title>Full disk encryption secure boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22179"/>
		<updated>2022-08-04T13:16:02Z</updated>

		<summary type="html">&lt;p&gt;Blt: small add&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Draft}}&lt;br /&gt;
&lt;br /&gt;
This guide is to explain step by step how to setup Alpine Linux with Full Disk Encryption using LUKS2, /boot &amp;amp; / together on the same partition, encrypted swap for hibernation on a nvme drive, with UEFI &amp;amp; Secure Boot.&lt;br /&gt;
The goal of this guide is to follow the KISS principle, lvm can be added, another file system can be used, multiple partitions for /home; /var/log etc.. can also be added, if running everything in one partition is not meeting your requirements.&lt;br /&gt;
&lt;br /&gt;
= Sequence of Events =&lt;br /&gt;
&lt;br /&gt;
* Installing packages&lt;br /&gt;
* Partitioning the disk&lt;br /&gt;
* Configuring LUKS&lt;br /&gt;
* Mounting points and File System&lt;br /&gt;
* Installing Alpine&lt;br /&gt;
* mkinitfs settings &amp;amp; modules&lt;br /&gt;
* Grub settings&lt;br /&gt;
* Configuring Secure Boot&lt;br /&gt;
&lt;br /&gt;
= Installing packages =&lt;br /&gt;
&lt;br /&gt;
To facilitate the partitioning we will use gdisk :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lsblk gptfdisk&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For encryption, we will use cryptsetup :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add cryptsetup&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For using and managing UEFI, multiple packages are needed :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efibootmgr e2fsprogs grub grub-efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Partitioning the disk =&lt;br /&gt;
&lt;br /&gt;
Let&#039;s assume the disk is /dev/nvme0n1 and no partition is present, we will create three partitions :&lt;br /&gt;
 &lt;br /&gt;
* one for UEFI&lt;br /&gt;
* one for /&lt;br /&gt;
* one for swap (hibernation)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# gdisk /dev/nvme0n1&lt;br /&gt;
GPT fdisk (gdisk) version 1.0.9.1&lt;br /&gt;
&lt;br /&gt;
Partition table scan:&lt;br /&gt;
  MBR: protective&lt;br /&gt;
  BSD: not present&lt;br /&gt;
  APM: not present&lt;br /&gt;
  GPT: present&lt;br /&gt;
&lt;br /&gt;
Found valid GPT with protective MBR; using GPT.&lt;br /&gt;
&lt;br /&gt;
Command (? for help): d&lt;br /&gt;
No partitions&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (1-128, default 1): &lt;br /&gt;
First sector (2048-1000215182, default = 2048) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (2048-1000215182, default = 1000214527) or {+-}size{KMGTP}: 512M&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): ef00&lt;br /&gt;
Changed type of partition to &#039;EFI system partition&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (2-128, default 2): &lt;br /&gt;
First sector (1048577-1000215182, default = 1050624) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (1050624-1000215182, default = 1000214527) or {+-}size{KMGTP}: 16G&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8200&lt;br /&gt;
Changed type of partition to &#039;Linux swap&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (3-128, default 3): &lt;br /&gt;
First sector (1048577-1000215182, default = 33556480) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (33556480-1000215182, default = 1000214527) or {+-}size{KMGTP}: &lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8309&lt;br /&gt;
Changed type of partition to &#039;Linux LUKS&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): w&lt;br /&gt;
&lt;br /&gt;
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING&lt;br /&gt;
PARTITIONS!!&lt;br /&gt;
&lt;br /&gt;
Do you want to proceed? (Y/N): Y&lt;br /&gt;
OK; writing new GUID partition table (GPT) to /dev/nvme0n1.&lt;br /&gt;
The operation has completed successfully.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring LUKS =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 5000 --use-random luksFormat /dev/nvme0n1p2&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p2 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p2: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&lt;br /&gt;
# cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 5000 --use-random luksFormat /dev/nvme0n1p3&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p3 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p3: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Mounting points and File System =&lt;br /&gt;
&lt;br /&gt;
Open the LUKS partitiond we just created:&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup luksOpen /dev/nvme0n1p2 nvme0n1p2-crypt&lt;br /&gt;
# cryptsetup luksOpen /dev/nvme0n1p3 nvme0n1p3-crypt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create vfat file system for UEFI partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.vfat /dev/nvme0n1p1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for swap partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/mapper/nvme0n1p2-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for / partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/mapper/nvme0n1p3-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create mounting points and mount partitions :&lt;br /&gt;
Mount / partition to /mnt :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t ext4 /dev/mapper/nvme0n1p3-crypt /mnt&amp;lt;/pre&amp;gt;&lt;br /&gt;
Create /boot/efi:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /mnt/boot/efi -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
Mount UEFI partition to /mnt/boot/efi :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t vfat /dev/nvme0n1p1 /mnt/boot/efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
Activate SWAP:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkswap /dev/mapper/nvme0n1p2-crypt&lt;br /&gt;
# swapon /dev/mapper/nvme0n1p2-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk&lt;br /&gt;
NAME                MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINTS&lt;br /&gt;
nvme0n1             259:0    0 476.9G  0 disk  &lt;br /&gt;
├─nvme0n1p1         259:1    0   511M  0 part  /mnt/boot/efi&lt;br /&gt;
├─nvme0n1p2         259:2    0  15.5G  0 part  &lt;br /&gt;
│ └─nvme0n1p2-crypt 253:0    0  15.5G  0 crypt [SWAP]&lt;br /&gt;
└─nvme0n1p3         259:3    0 460.9G  0 part  &lt;br /&gt;
  └─nvme0n1p3-crypt 253:1    0 460.9G  0 crypt /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Installing Alpine =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# setup-disk -m sys /mnt/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= mkinitfs settings &amp;amp; modules =&lt;br /&gt;
Edit the /mnt/etc/mkinitfs/mkinitfs.conf file and append the cryptsetup module to the features parameter (keymap only needed if QWERTY is not used):&lt;br /&gt;
&amp;lt;pre&amp;gt;features=&amp;quot;...keymap cryptsetup cryptkey&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Regenerate the initram:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkinitfs -c /mnt/etc/mkinitfs/mkinitfs.conf -b /mnt/ $(ls /mnt/lib/modules/)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Grub settings =&lt;br /&gt;
&lt;br /&gt;
Create a crypto_keyfile.bin to avoid typing the passphrase twice during the boot process (one for Grub partition, one for Alpine partition):&lt;br /&gt;
&amp;lt;pre&amp;gt;# touch /mnt/crypto_keyfile.bin&lt;br /&gt;
# chmod 600 /mnt/crypto_keyfile.bin&lt;br /&gt;
# dd bs=512 count=4 if=/dev/urandom of=/mnt/crypto_keyfile.bin&lt;br /&gt;
# cryptsetup luksAddKey /dev/nvme0n1p3 /mnt/crypto_keyfile.bin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, let&#039;s mount and chroot to our fresh installation:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t proc /proc /mnt/proc&lt;br /&gt;
# mount --rbind /dev /mnt/dev&lt;br /&gt;
# mount --make-rslave /mnt/dev&lt;br /&gt;
# mount --rbind /sys /mnt/sys&lt;br /&gt;
# chroot /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let&#039;s show the UUID of our partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk -f&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit /etc/default/grub and add a new line starting with GRUB_CMDLINE_LINUX parameter, replacing &amp;lt;UUID&amp;gt; with the UUID of the encrypted partition (in this case /dev/nvme0n1p3) and adding a new GRUB_PRELOAD_MODULES line like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_CMDLINE_LINUX=&amp;quot;cryptroot=UUID=&amp;lt;UUID&amp;gt; cryptdm=nvme0n1p3-crypt cryptkey&amp;quot;&lt;br /&gt;
GRUB_PRELOAD_MODULES=&amp;quot;luks cryptodisk part_gpt&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a /root/grub-pre.cfg and replace &amp;lt;UUID_WITHOUT_HYPHENS&amp;gt; with your encrypted root partition UUID (here /dev/nvme0n1p3) without hyphens&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set crypto_uuid=&amp;lt;UUID_WITHOUT_HYPHENS&amp;gt;&lt;br /&gt;
cryptomount -u $crypto_uuid&lt;br /&gt;
set root=crypto0&lt;br /&gt;
set prefix=($root)/boot/grub&lt;br /&gt;
insmod normal&lt;br /&gt;
normal&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring Secure Boot =&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efi-mkkeys efibootmgr sbsigntool&lt;br /&gt;
# efi-mkkeys -s &amp;quot;Your Name&amp;quot; -o /etc/uefi-keys&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Re-install Grub:&lt;br /&gt;
&amp;lt;pre&amp;gt;# grub-mkimage -p /boot/grub -O x86_64-efi -c /root/grub-pre.cfg -o /tmp/grubx64.efi luks2 part_gpt cryptodisk ext2 gcry_rijndael pbkdf2 gcry_sha512&lt;br /&gt;
# install -v /tmp/grubx64.efi /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sed -i &#039;s/SecureBoot/SecureB00t/&#039; /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi&lt;br /&gt;
# cd /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sbsign --key /etc/uefi-keys/db.key --cert /etc/uefi-keys/db.crt --output grubx64.efi.signed grubx64.efi&lt;br /&gt;
# grub-mkconfig -o /boot/grub/grub.cfg&lt;br /&gt;
# efibootmgr --disk /dev/nvme0n1p1 --part 1 --create --label &#039;Alpine Linux Secure Boot Signed&#039; --load /EFI/AlpineLinuxSecureBoot/grubx64.efi.signed --verbose&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To check that your .efi is signed :&lt;br /&gt;
&amp;lt;pre&amp;gt; # sbverify --cert /etc/uefi-keys/db.crt /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi.signed &lt;br /&gt;
Signature verification OK&lt;br /&gt;
sbverify --list /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi.signed&lt;br /&gt;
signature 1&lt;br /&gt;
image signature issuers:&lt;br /&gt;
 - /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
image signature certificates:&lt;br /&gt;
 - subject: /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
   issuer:  /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reboot &amp;amp; enter into your UEFI (Fx key depending of your laptop)&lt;br /&gt;
&lt;br /&gt;
== Import keys to UEFI ==&lt;br /&gt;
&lt;br /&gt;
Copy db.auth, KEK.auth and PK.auth files from /etc/uefi-keys to a FAT formatted file system.&lt;br /&gt;
This is just an example from an XPS laptop, each UEFI is unique.&lt;br /&gt;
&lt;br /&gt;
# Go to &#039;&#039;&#039;Boot Configuration&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;Secure Boot&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Enable Secure Boot&#039;&#039;&#039; to &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Secure Boot Mode&#039;&#039;&#039; to &#039;&#039;&#039;Deployed Mode&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Enable Custom Mode&#039;&#039;&#039; to &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
# Go to &#039;&#039;&#039;Custom Mode Key Management&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Reset All Keys&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;db&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;db.auth&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;KEK&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;KEK.auth&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;PK&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;PK.auth&#039;&#039;&#039;&lt;br /&gt;
# &#039;&#039;&#039;APPLY CHANGES&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;EXIT&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Check Secure Boot State:&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add mokutil&lt;br /&gt;
# mokutil --sb-state&lt;br /&gt;
SecureBoot enabled&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Congrats!&lt;/div&gt;</summary>
		<author><name>Blt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22178</id>
		<title>Full disk encryption secure boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22178"/>
		<updated>2022-08-04T13:11:27Z</updated>

		<summary type="html">&lt;p&gt;Blt: Add Import keys to UEFI and check signature UEFI&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Draft}}&lt;br /&gt;
&lt;br /&gt;
This guide is to explain step by step how to setup Alpine Linux with Full Disk Encryption using LUKS2, /boot &amp;amp; / together on the same partition, encrypted swap for hibernation on a nvme drive, with UEFI &amp;amp; Secure Boot.&lt;br /&gt;
The goal of this guide is to follow the KISS principle, lvm can be added, another file system can be used, multiple partitions for /home; /var/log etc.. can also be added, if running everything in one partition is not meeting your requirements.&lt;br /&gt;
&lt;br /&gt;
= Sequence of Events =&lt;br /&gt;
&lt;br /&gt;
* Installing packages&lt;br /&gt;
* Partitioning the disk&lt;br /&gt;
* Configuring LUKS&lt;br /&gt;
* Mounting points and File System&lt;br /&gt;
* Installing Alpine&lt;br /&gt;
* mkinitfs settings &amp;amp; modules&lt;br /&gt;
* Grub settings&lt;br /&gt;
* Configuring Secure Boot&lt;br /&gt;
&lt;br /&gt;
= Installing packages =&lt;br /&gt;
&lt;br /&gt;
To facilitate the partitioning we will use gdisk :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lsblk gptfdisk&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For encryption, we will use cryptsetup :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add cryptsetup&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For using and managing UEFI, multiple packages are needed :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efibootmgr e2fsprogs grub grub-efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Partitioning the disk =&lt;br /&gt;
&lt;br /&gt;
Let&#039;s assume the disk is /dev/nvme0n1 and no partition is present, we will create three partitions :&lt;br /&gt;
 &lt;br /&gt;
* one for UEFI&lt;br /&gt;
* one for /&lt;br /&gt;
* one for swap (hibernation)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# gdisk /dev/nvme0n1&lt;br /&gt;
GPT fdisk (gdisk) version 1.0.9.1&lt;br /&gt;
&lt;br /&gt;
Partition table scan:&lt;br /&gt;
  MBR: protective&lt;br /&gt;
  BSD: not present&lt;br /&gt;
  APM: not present&lt;br /&gt;
  GPT: present&lt;br /&gt;
&lt;br /&gt;
Found valid GPT with protective MBR; using GPT.&lt;br /&gt;
&lt;br /&gt;
Command (? for help): d&lt;br /&gt;
No partitions&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (1-128, default 1): &lt;br /&gt;
First sector (2048-1000215182, default = 2048) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (2048-1000215182, default = 1000214527) or {+-}size{KMGTP}: 512M&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): ef00&lt;br /&gt;
Changed type of partition to &#039;EFI system partition&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (2-128, default 2): &lt;br /&gt;
First sector (1048577-1000215182, default = 1050624) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (1050624-1000215182, default = 1000214527) or {+-}size{KMGTP}: 16G&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8200&lt;br /&gt;
Changed type of partition to &#039;Linux swap&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (3-128, default 3): &lt;br /&gt;
First sector (1048577-1000215182, default = 33556480) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (33556480-1000215182, default = 1000214527) or {+-}size{KMGTP}: &lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8309&lt;br /&gt;
Changed type of partition to &#039;Linux LUKS&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): w&lt;br /&gt;
&lt;br /&gt;
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING&lt;br /&gt;
PARTITIONS!!&lt;br /&gt;
&lt;br /&gt;
Do you want to proceed? (Y/N): Y&lt;br /&gt;
OK; writing new GUID partition table (GPT) to /dev/nvme0n1.&lt;br /&gt;
The operation has completed successfully.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring LUKS =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 5000 --use-random luksFormat /dev/nvme0n1p2&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p2 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p2: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&lt;br /&gt;
# cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 5000 --use-random luksFormat /dev/nvme0n1p3&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p3 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p3: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Mounting points and File System =&lt;br /&gt;
&lt;br /&gt;
Open the LUKS partitiond we just created:&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup luksOpen /dev/nvme0n1p2 nvme0n1p2-crypt&lt;br /&gt;
# cryptsetup luksOpen /dev/nvme0n1p3 nvme0n1p3-crypt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create vfat file system for UEFI partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.vfat /dev/nvme0n1p1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for swap partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/mapper/nvme0n1p2-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for / partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/mapper/nvme0n1p3-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create mounting points and mount partitions :&lt;br /&gt;
Mount / partition to /mnt :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t ext4 /dev/mapper/nvme0n1p3-crypt /mnt&amp;lt;/pre&amp;gt;&lt;br /&gt;
Create /boot/efi:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /mnt/boot/efi -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
Mount UEFI partition to /mnt/boot/efi :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t vfat /dev/nvme0n1p1 /mnt/boot/efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
Activate SWAP:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkswap /dev/mapper/nvme0n1p2-crypt&lt;br /&gt;
# swapon /dev/mapper/nvme0n1p2-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk&lt;br /&gt;
NAME                MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINTS&lt;br /&gt;
nvme0n1             259:0    0 476.9G  0 disk  &lt;br /&gt;
├─nvme0n1p1         259:1    0   511M  0 part  /mnt/boot/efi&lt;br /&gt;
├─nvme0n1p2         259:2    0  15.5G  0 part  &lt;br /&gt;
│ └─nvme0n1p2-crypt 253:0    0  15.5G  0 crypt [SWAP]&lt;br /&gt;
└─nvme0n1p3         259:3    0 460.9G  0 part  &lt;br /&gt;
  └─nvme0n1p3-crypt 253:1    0 460.9G  0 crypt /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Installing Alpine =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# setup-disk -m sys /mnt/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= mkinitfs settings &amp;amp; modules =&lt;br /&gt;
Edit the /mnt/etc/mkinitfs/mkinitfs.conf file and append the cryptsetup module to the features parameter (keymap only needed if QWERTY is not used):&lt;br /&gt;
&amp;lt;pre&amp;gt;features=&amp;quot;...keymap cryptsetup cryptkey&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Regenerate the initram:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkinitfs -c /mnt/etc/mkinitfs/mkinitfs.conf -b /mnt/ $(ls /mnt/lib/modules/)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Grub settings =&lt;br /&gt;
&lt;br /&gt;
Create a crypto_keyfile.bin to avoid typing the passphrase twice during the boot process (one for Grub partition, one for Alpine partition):&lt;br /&gt;
&amp;lt;pre&amp;gt;# touch /mnt/crypto_keyfile.bin&lt;br /&gt;
# chmod 600 /mnt/crypto_keyfile.bin&lt;br /&gt;
# dd bs=512 count=4 if=/dev/urandom of=/mnt/crypto_keyfile.bin&lt;br /&gt;
# cryptsetup luksAddKey /dev/nvme0n1p3 /mnt/crypto_keyfile.bin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, let&#039;s mount and chroot to our fresh installation:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t proc /proc /mnt/proc&lt;br /&gt;
# mount --rbind /dev /mnt/dev&lt;br /&gt;
# mount --make-rslave /mnt/dev&lt;br /&gt;
# mount --rbind /sys /mnt/sys&lt;br /&gt;
# chroot /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let&#039;s show the UUID of our partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk -f&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit /etc/default/grub and add a new line starting with GRUB_CMDLINE_LINUX parameter, replacing &amp;lt;UUID&amp;gt; with the UUID of the encrypted partition (in this case /dev/nvme0n1p3) and adding a new GRUB_PRELOAD_MODULES line like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_CMDLINE_LINUX=&amp;quot;cryptroot=UUID=&amp;lt;UUID&amp;gt; cryptdm=nvme0n1p3-crypt cryptkey&amp;quot;&lt;br /&gt;
GRUB_PRELOAD_MODULES=&amp;quot;luks cryptodisk part_gpt&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a /root/grub-pre.cfg and replace &amp;lt;UUID_WITHOUT_HYPHENS&amp;gt; with your encrypted root partition UUID (here /dev/nvme0n1p3) without hyphens&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set crypto_uuid=&amp;lt;UUID_WITHOUT_HYPHENS&amp;gt;&lt;br /&gt;
cryptomount -u $crypto_uuid&lt;br /&gt;
set root=crypto0&lt;br /&gt;
set prefix=($root)/boot/grub&lt;br /&gt;
insmod normal&lt;br /&gt;
normal&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring Secure Boot =&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efi-mkkeys efibootmgr sbsigntool&lt;br /&gt;
# efi-mkkeys -s &amp;quot;Your Name&amp;quot; -o /etc/uefi-keys&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Re-install Grub:&lt;br /&gt;
&amp;lt;pre&amp;gt;# grub-mkimage -p /boot/grub -O x86_64-efi -c /root/grub-pre.cfg -o /tmp/grubx64.efi luks2 part_gpt cryptodisk ext2 gcry_rijndael pbkdf2 gcry_sha512&lt;br /&gt;
# install -v /tmp/grubx64.efi /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sed -i &#039;s/SecureBoot/SecureB00t/&#039; /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi&lt;br /&gt;
# cd /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sbsign --key /etc/uefi-keys/db.key --cert /etc/uefi-keys/db.crt --output grubx64.efi.signed grubx64.efi&lt;br /&gt;
# grub-mkconfig -o /boot/grub/grub.cfg&lt;br /&gt;
# efibootmgr --disk /dev/nvme0n1p1 --part 1 --create --label &#039;Alpine Linux Secure Boot Signed&#039; --load /EFI/AlpineLinuxSecureBoot/grubx64.efi.signed --verbose&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To check that your .efi is signed :&lt;br /&gt;
&amp;lt;pre&amp;gt; # sbverify --cert /etc/uefi-keys/db.crt /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi.signed &lt;br /&gt;
Signature verification OK&lt;br /&gt;
sbverify --list /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi.signed&lt;br /&gt;
signature 1&lt;br /&gt;
image signature issuers:&lt;br /&gt;
 - /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
image signature certificates:&lt;br /&gt;
 - subject: /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
   issuer:  /CN=&amp;quot;Your Name&amp;quot; (db)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reboot&lt;br /&gt;
&lt;br /&gt;
== Import keys to UEFI ==&lt;br /&gt;
&lt;br /&gt;
Copy db.auth, KEK.auth and PK.auth files from /etc/uefi-keys to a FAT formatted file system.&lt;br /&gt;
This is just an example from an XPS laptop, each UEFI is unique.&lt;br /&gt;
&lt;br /&gt;
# Go to &#039;&#039;&#039;Boot Configuration&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;Secure Boot&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Enable Secure Boot&#039;&#039;&#039; to &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Secure Boot Mode&#039;&#039;&#039; to &#039;&#039;&#039;Deployed Mode&#039;&#039;&#039;&lt;br /&gt;
# Change &#039;&#039;&#039;Enable Custom Mode&#039;&#039;&#039; to &#039;&#039;&#039;ON&#039;&#039;&#039;&lt;br /&gt;
# Go to &#039;&#039;&#039;Custom Mode Key Management&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Reset All Keys&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;db&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;db.auth&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;KEK&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;KEK.auth&#039;&#039;&#039;&lt;br /&gt;
#* &#039;&#039;&#039;Select Key Database&#039;&#039;&#039; select &#039;&#039;&#039;PK&#039;&#039;&#039; &amp;gt; Replace from file &amp;gt; select your Flash Drive &amp;gt; select &#039;&#039;&#039;PK.auth&#039;&#039;&#039;&lt;br /&gt;
# &#039;&#039;&#039;APPLY CHANGES&#039;&#039;&#039; &amp;gt; &#039;&#039;&#039;EXIT&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Check Secure Boot State:&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add mokutil&lt;br /&gt;
# mokutil --sb-state&lt;br /&gt;
SecureBoot enabled&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Congrats!&lt;/div&gt;</summary>
		<author><name>Blt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22177</id>
		<title>Full disk encryption secure boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22177"/>
		<updated>2022-08-04T11:16:23Z</updated>

		<summary type="html">&lt;p&gt;Blt: adding missing package, removing unnecessary command&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Draft}}&lt;br /&gt;
&lt;br /&gt;
This guide is to explain step by step how to setup Alpine Linux with Full Disk Encryption using LUKS2, /boot &amp;amp; / together on the same partition, encrypted swap for hibernation on a nvme drive, with UEFI &amp;amp; Secure Boot.&lt;br /&gt;
The goal of this guide is to follow the KISS principle, lvm can be added, another file system can be used, multiple partitions for /home; /var/log etc.. can also be added, if running everything in one partition is not meeting your requirements.&lt;br /&gt;
&lt;br /&gt;
= Sequence of Events =&lt;br /&gt;
&lt;br /&gt;
* Installing packages&lt;br /&gt;
* Partitioning the disk&lt;br /&gt;
* Configuring LUKS&lt;br /&gt;
* Mounting points and File System&lt;br /&gt;
* Installing Alpine&lt;br /&gt;
* mkinitfs settings &amp;amp; modules&lt;br /&gt;
* Grub settings&lt;br /&gt;
* Configuring Secure Boot&lt;br /&gt;
&lt;br /&gt;
= Installing packages =&lt;br /&gt;
&lt;br /&gt;
To facilitate the partitioning we will use gdisk :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lsblk gptfdisk&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For encryption, we will use cryptsetup :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add cryptsetup&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For using and managing UEFI, multiple packages are needed :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efibootmgr e2fsprogs grub grub-efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Partitioning the disk =&lt;br /&gt;
&lt;br /&gt;
Let&#039;s assume the disk is /dev/nvme0n1 and no partition is present, we will create three partitions :&lt;br /&gt;
 &lt;br /&gt;
* one for UEFI&lt;br /&gt;
* one for /&lt;br /&gt;
* one for swap (hibernation)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# gdisk /dev/nvme0n1&lt;br /&gt;
GPT fdisk (gdisk) version 1.0.9.1&lt;br /&gt;
&lt;br /&gt;
Partition table scan:&lt;br /&gt;
  MBR: protective&lt;br /&gt;
  BSD: not present&lt;br /&gt;
  APM: not present&lt;br /&gt;
  GPT: present&lt;br /&gt;
&lt;br /&gt;
Found valid GPT with protective MBR; using GPT.&lt;br /&gt;
&lt;br /&gt;
Command (? for help): d&lt;br /&gt;
No partitions&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (1-128, default 1): &lt;br /&gt;
First sector (2048-1000215182, default = 2048) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (2048-1000215182, default = 1000214527) or {+-}size{KMGTP}: 512M&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): ef00&lt;br /&gt;
Changed type of partition to &#039;EFI system partition&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (2-128, default 2): &lt;br /&gt;
First sector (1048577-1000215182, default = 1050624) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (1050624-1000215182, default = 1000214527) or {+-}size{KMGTP}: 16G&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8200&lt;br /&gt;
Changed type of partition to &#039;Linux swap&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (3-128, default 3): &lt;br /&gt;
First sector (1048577-1000215182, default = 33556480) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (33556480-1000215182, default = 1000214527) or {+-}size{KMGTP}: &lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8309&lt;br /&gt;
Changed type of partition to &#039;Linux LUKS&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): w&lt;br /&gt;
&lt;br /&gt;
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING&lt;br /&gt;
PARTITIONS!!&lt;br /&gt;
&lt;br /&gt;
Do you want to proceed? (Y/N): Y&lt;br /&gt;
OK; writing new GUID partition table (GPT) to /dev/nvme0n1.&lt;br /&gt;
The operation has completed successfully.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring LUKS =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 5000 --use-random luksFormat /dev/nvme0n1p2&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p2 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p2: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&lt;br /&gt;
# cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 5000 --use-random luksFormat /dev/nvme0n1p3&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p3 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p3: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Mounting points and File System =&lt;br /&gt;
&lt;br /&gt;
Open the LUKS partitiond we just created:&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup luksOpen /dev/nvme0n1p2 nvme0n1p2-crypt&lt;br /&gt;
# cryptsetup luksOpen /dev/nvme0n1p3 nvme0n1p3-crypt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create vfat file system for UEFI partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.vfat /dev/nvme0n1p1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for swap partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/mapper/nvme0n1p2-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for / partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/mapper/nvme0n1p3-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create mounting points and mount partitions :&lt;br /&gt;
Mount / partition to /mnt :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t ext4 /dev/mapper/nvme0n1p3-crypt /mnt&amp;lt;/pre&amp;gt;&lt;br /&gt;
Create /boot/efi:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /mnt/boot/efi -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
Mount UEFI partition to /mnt/boot/efi :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t vfat /dev/nvme0n1p1 /mnt/boot/efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
Activate SWAP:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkswap /dev/mapper/nvme0n1p2-crypt&lt;br /&gt;
# swapon /dev/mapper/nvme0n1p2-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk&lt;br /&gt;
NAME                MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINTS&lt;br /&gt;
nvme0n1             259:0    0 476.9G  0 disk  &lt;br /&gt;
├─nvme0n1p1         259:1    0   511M  0 part  /mnt/boot/efi&lt;br /&gt;
├─nvme0n1p2         259:2    0  15.5G  0 part  &lt;br /&gt;
│ └─nvme0n1p2-crypt 253:0    0  15.5G  0 crypt [SWAP]&lt;br /&gt;
└─nvme0n1p3         259:3    0 460.9G  0 part  &lt;br /&gt;
  └─nvme0n1p3-crypt 253:1    0 460.9G  0 crypt /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Installing Alpine =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# setup-disk -m sys /mnt/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= mkinitfs settings &amp;amp; modules =&lt;br /&gt;
Edit the /mnt/etc/mkinitfs/mkinitfs.conf file and append the cryptsetup module to the features parameter (keymap only needed if QWERTY is not used):&lt;br /&gt;
&amp;lt;pre&amp;gt;features=&amp;quot;...keymap cryptsetup cryptkey&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Regenerate the initram:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkinitfs -c /mnt/etc/mkinitfs/mkinitfs.conf -b /mnt/ $(ls /mnt/lib/modules/)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Grub settings =&lt;br /&gt;
&lt;br /&gt;
Create a crypto_keyfile.bin to avoid typing the passphrase twice during the boot process (one for Grub partition, one for Alpine partition):&lt;br /&gt;
&amp;lt;pre&amp;gt;# touch /mnt/crypto_keyfile.bin&lt;br /&gt;
# chmod 600 /mnt/crypto_keyfile.bin&lt;br /&gt;
# dd bs=512 count=4 if=/dev/urandom of=/mnt/crypto_keyfile.bin&lt;br /&gt;
# cryptsetup luksAddKey /dev/nvme0n1p3 /mnt/crypto_keyfile.bin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, let&#039;s mount and chroot to our fresh installation:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t proc /proc /mnt/proc&lt;br /&gt;
# mount --rbind /dev /mnt/dev&lt;br /&gt;
# mount --make-rslave /mnt/dev&lt;br /&gt;
# mount --rbind /sys /mnt/sys&lt;br /&gt;
# chroot /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let&#039;s show the UUID of our partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk -f&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit /etc/default/grub and add a new line starting with GRUB_CMDLINE_LINUX parameter, replacing &amp;lt;UUID&amp;gt; with the UUID of the encrypted partition (in this case /dev/nvme0n1p3) and adding a new GRUB_PRELOAD_MODULES line like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_CMDLINE_LINUX=&amp;quot;cryptroot=UUID=&amp;lt;UUID&amp;gt; cryptdm=nvme0n1p3-crypt cryptkey&amp;quot;&lt;br /&gt;
GRUB_PRELOAD_MODULES=&amp;quot;luks cryptodisk part_gpt&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a /root/grub-pre.cfg and replace &amp;lt;UUID_WITHOUT_HYPHENS&amp;gt; with your encrypted root partition UUID (here /dev/nvme0n1p3) without hyphens&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set crypto_uuid=&amp;lt;UUID_WITHOUT_HYPHENS&amp;gt;&lt;br /&gt;
cryptomount -u $crypto_uuid&lt;br /&gt;
set root=crypto0&lt;br /&gt;
set prefix=($root)/boot/grub&lt;br /&gt;
insmod normal&lt;br /&gt;
normal&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring Secure Boot =&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efi-mkkeys efibootmgr sbsigntool&lt;br /&gt;
# efi-mkkeys -s &amp;quot;Your Name&amp;quot; -o /etc/uefi-keys&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Re-install Grub:&lt;br /&gt;
&amp;lt;pre&amp;gt;# grub-mkimage -p /boot/grub -O x86_64-efi -c /root/grub-pre.cfg -o /tmp/grubx64.efi luks2 part_gpt cryptodisk ext2 gcry_rijndael pbkdf2 gcry_sha512&lt;br /&gt;
# install -v /tmp/grubx64.efi /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sed -i &#039;s/SecureBoot/SecureB00t/&#039; /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi&lt;br /&gt;
# cd /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sbsign --key /etc/uefi-keys/db.key --cert /etc/uefi-keys/db.crt --output grubx64.efi.signed grubx64.efi&lt;br /&gt;
# grub-mkconfig -o /boot/grub/grub.cfg&lt;br /&gt;
# efibootmgr --disk /dev/nvme0n1p1 --part 1 --create --label &#039;Alpine Linux Secure Boot Signed&#039; --load /EFI/AlpineLinuxSecureBoot/grubx64.efi.signed --verbose&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reboot&lt;br /&gt;
&lt;br /&gt;
Check Secure Boot State:&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add mokutil&lt;br /&gt;
# mokutil --sb-state&lt;br /&gt;
SecureBoot enabled&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Congrats!&lt;/div&gt;</summary>
		<author><name>Blt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22176</id>
		<title>Full disk encryption secure boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22176"/>
		<updated>2022-08-04T11:03:39Z</updated>

		<summary type="html">&lt;p&gt;Blt: small formating improvment&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Draft}}&lt;br /&gt;
&lt;br /&gt;
This guide is to explain step by step how to setup Alpine Linux with Full Disk Encryption using LUKS2, /boot &amp;amp; / together on the same partition, encrypted swap for hibernation on a nvme drive, with UEFI &amp;amp; Secure Boot.&lt;br /&gt;
The goal of this guide is to follow the KISS principle, lvm can be added, another file system can be used, multiple partitions for /home; /var/log etc.. can also be added, if running everything in one partition is not meeting your requirements.&lt;br /&gt;
&lt;br /&gt;
= Sequence of Events =&lt;br /&gt;
&lt;br /&gt;
* Installing packages&lt;br /&gt;
* Partitioning the disk&lt;br /&gt;
* Configuring LUKS&lt;br /&gt;
* Mounting points and File System&lt;br /&gt;
* Installing Alpine&lt;br /&gt;
* mkinitfs settings &amp;amp; modules&lt;br /&gt;
* Grub settings&lt;br /&gt;
* Configuring Secure Boot&lt;br /&gt;
&lt;br /&gt;
= Installing packages =&lt;br /&gt;
&lt;br /&gt;
To facilitate the partitioning we will use gdisk :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lsblk gptfdisk&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For encryption, we will use cryptsetup :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add cryptsetup&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For using and managing UEFI, multiple packages are needed :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efibootmgr e2fsprogs grub grub-efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Partitioning the disk =&lt;br /&gt;
&lt;br /&gt;
Let&#039;s assume the disk is /dev/nvme0n1 and no partition is present, we will create three partitions :&lt;br /&gt;
 &lt;br /&gt;
* one for UEFI&lt;br /&gt;
* one for /&lt;br /&gt;
* one for swap (hibernation)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# gdisk /dev/nvme0n1&lt;br /&gt;
GPT fdisk (gdisk) version 1.0.9.1&lt;br /&gt;
&lt;br /&gt;
Partition table scan:&lt;br /&gt;
  MBR: protective&lt;br /&gt;
  BSD: not present&lt;br /&gt;
  APM: not present&lt;br /&gt;
  GPT: present&lt;br /&gt;
&lt;br /&gt;
Found valid GPT with protective MBR; using GPT.&lt;br /&gt;
&lt;br /&gt;
Command (? for help): d&lt;br /&gt;
No partitions&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (1-128, default 1): &lt;br /&gt;
First sector (2048-1000215182, default = 2048) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (2048-1000215182, default = 1000214527) or {+-}size{KMGTP}: 512M&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): ef00&lt;br /&gt;
Changed type of partition to &#039;EFI system partition&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (2-128, default 2): &lt;br /&gt;
First sector (1048577-1000215182, default = 1050624) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (1050624-1000215182, default = 1000214527) or {+-}size{KMGTP}: 16G&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8200&lt;br /&gt;
Changed type of partition to &#039;Linux swap&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (3-128, default 3): &lt;br /&gt;
First sector (1048577-1000215182, default = 33556480) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (33556480-1000215182, default = 1000214527) or {+-}size{KMGTP}: &lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8309&lt;br /&gt;
Changed type of partition to &#039;Linux LUKS&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): w&lt;br /&gt;
&lt;br /&gt;
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING&lt;br /&gt;
PARTITIONS!!&lt;br /&gt;
&lt;br /&gt;
Do you want to proceed? (Y/N): Y&lt;br /&gt;
OK; writing new GUID partition table (GPT) to /dev/nvme0n1.&lt;br /&gt;
The operation has completed successfully.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring LUKS =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 5000 --use-random luksFormat /dev/nvme0n1p2&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p2 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p2: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&lt;br /&gt;
# cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 5000 --use-random luksFormat /dev/nvme0n1p3&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p3 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p3: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Mounting points and File System =&lt;br /&gt;
&lt;br /&gt;
Open the LUKS partitiond we just created:&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup luksOpen /dev/nvme0n1p2 nvme0n1p2-crypt&lt;br /&gt;
# cryptsetup luksOpen /dev/nvme0n1p3 nvme0n1p3-crypt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create vfat file system for UEFI partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.vfat /dev/nvme0n1p1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for swap partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/mapper/nvme0n1p2-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for / partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/mapper/nvme0n1p3-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create mounting points and mount partitions :&lt;br /&gt;
Mount / partition to /mnt :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t ext4 /dev/mapper/nvme0n1p3-crypt /mnt&amp;lt;/pre&amp;gt;&lt;br /&gt;
Create /boot/efi:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /mnt/boot/efi -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
Mount UEFI partition to /mnt/boot/efi :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t vfat /dev/nvme0n1p1 /mnt/boot/efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
Activate SWAP:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkswap /dev/mapper/nvme0n1p2-crypt&lt;br /&gt;
# swapon /dev/mapper/nvme0n1p2-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk&lt;br /&gt;
NAME                MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINTS&lt;br /&gt;
nvme0n1             259:0    0 476.9G  0 disk  &lt;br /&gt;
├─nvme0n1p1         259:1    0   511M  0 part  /mnt/boot/efi&lt;br /&gt;
├─nvme0n1p2         259:2    0  15.5G  0 part  &lt;br /&gt;
│ └─nvme0n1p2-crypt 253:0    0  15.5G  0 crypt [SWAP]&lt;br /&gt;
└─nvme0n1p3         259:3    0 460.9G  0 part  &lt;br /&gt;
  └─nvme0n1p3-crypt 253:1    0 460.9G  0 crypt /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Installing Alpine =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# setup-disk -m sys /mnt/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= mkinitfs settings &amp;amp; modules =&lt;br /&gt;
Edit the /mnt/etc/mkinitfs/mkinitfs.conf file and append the cryptsetup module to the features parameter (keymap only needed if QWERTY is not used):&lt;br /&gt;
&amp;lt;pre&amp;gt;features=&amp;quot;...keymap cryptsetup cryptkey&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Regenerate the initram:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkinitfs -c /mnt/etc/mkinitfs/mkinitfs.conf -b /mnt/ $(ls /mnt/lib/modules/)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Grub settings =&lt;br /&gt;
&lt;br /&gt;
Create a crypto_keyfile.bin to avoid typing the passphrase twice during the boot process (one for Grub partition, one for Alpine partition):&lt;br /&gt;
&amp;lt;pre&amp;gt;# touch /mnt/crypto_keyfile.bin&lt;br /&gt;
# chmod 600 /mnt/crypto_keyfile.bin&lt;br /&gt;
# dd bs=512 count=4 if=/dev/urandom of=/mnt/crypto_keyfile.bin&lt;br /&gt;
# cryptsetup luksAddKey /dev/nvme0n1p3 /mnt/crypto_keyfile.bin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, let&#039;s mount and chroot to our fresh installation:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t proc /proc /mnt/proc&lt;br /&gt;
# mount --rbind /dev /mnt/dev&lt;br /&gt;
# mount --make-rslave /mnt/dev&lt;br /&gt;
# mount --rbind /sys /mnt/sys&lt;br /&gt;
# chroot /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let&#039;s show the UUID of our partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk -f&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit /etc/default/grub and add a new line starting with GRUB_CMDLINE_LINUX parameter, replacing &amp;lt;UUID&amp;gt; with the UUID of the encrypted partition (in this case /dev/nvme0n1p3) and adding a new GRUB_PRELOAD_MODULES line like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_CMDLINE_LINUX=&amp;quot;cryptroot=UUID=&amp;lt;UUID&amp;gt; cryptdm=nvme0n1p3-crypt cryptkey&amp;quot;&lt;br /&gt;
GRUB_PRELOAD_MODULES=&amp;quot;luks cryptodisk part_gpt&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a /root/grub-pre.cfg and replace &amp;lt;UUID_WITHOUT_HYPHENS&amp;gt; with your encrypted root partition UUID (here /dev/nvme0n1p3) without hyphens&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set crypto_uuid=&amp;lt;UUID_WITHOUT_HYPHENS&amp;gt;&lt;br /&gt;
cryptomount -u $crypto_uuid&lt;br /&gt;
set root=crypto0&lt;br /&gt;
set prefix=($root)/boot/grub&lt;br /&gt;
insmod normal&lt;br /&gt;
normal&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring Secure Boot =&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efi-mkkeys efibootmgr&lt;br /&gt;
# efi-mkkeys -s &amp;quot;Your Name&amp;quot; -o /etc/uefi-keys&lt;br /&gt;
# echo &#039;disable_trigger=yes&#039; &amp;gt;&amp;gt; /etc/mkinitfs/mkinitfs.conf&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Re-install Grub:&lt;br /&gt;
&amp;lt;pre&amp;gt;# grub-mkimage -p /boot/grub -O x86_64-efi -c /root/grub-pre.cfg -o /tmp/grubx64.efi luks2 part_gpt cryptodisk ext2 gcry_rijndael pbkdf2 gcry_sha512&lt;br /&gt;
# install -v /tmp/grubx64.efi /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sed -i &#039;s/SecureBoot/SecureB00t/&#039; /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi&lt;br /&gt;
# cd /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sbsign --key /etc/uefi-keys/db.key --cert /etc/uefi-keys/db.crt --output grubx64.efi.signed grubx64.efi&lt;br /&gt;
# grub-mkconfig -o /boot/grub/grub.cfg&lt;br /&gt;
# efibootmgr --disk /dev/nvme0n1p1 --part 1 --create --label &#039;Alpine Linux Secure Boot Signed&#039; --load /EFI/AlpineLinuxSecureBoot/grubx64.efi.signed --verbose&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reboot&lt;br /&gt;
&lt;br /&gt;
Check Secure Boot State:&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add mokutil&lt;br /&gt;
# mokutil --sb-state&lt;br /&gt;
SecureBoot enabled&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Congrats!&lt;/div&gt;</summary>
		<author><name>Blt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22175</id>
		<title>Full disk encryption secure boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22175"/>
		<updated>2022-08-04T10:59:53Z</updated>

		<summary type="html">&lt;p&gt;Blt: Remove unnecessary option for grub-mkimage&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Draft}}&lt;br /&gt;
&lt;br /&gt;
This guide is to explain step by step how to setup Alpine Linux with Full Disk Encryption using LUKS2, /boot &amp;amp; / together on the same partition, encrypted swap for hibernation on a nvme drive, with UEFI &amp;amp; Secure Boot.&lt;br /&gt;
The goal of this guide is to follow the KISS principle, lvm can be added, another file system can be used, multiple partitions for /home; /var/log etc.. can also be added, if running everything in one partition is not meeting your requirements.&lt;br /&gt;
&lt;br /&gt;
= Sequence of Events =&lt;br /&gt;
&lt;br /&gt;
* Installing packages&lt;br /&gt;
* Partitioning the disk&lt;br /&gt;
* Configuring LUKS&lt;br /&gt;
* Mounting points and File System&lt;br /&gt;
* Installing Alpine&lt;br /&gt;
* mkinitfs settings &amp;amp; modules&lt;br /&gt;
* Grub settings&lt;br /&gt;
* Configuring Secure Boot&lt;br /&gt;
&lt;br /&gt;
= Installing packages =&lt;br /&gt;
&lt;br /&gt;
To facilitate the partitioning we will use gdisk :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lsblk gptfdisk&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For encryption, we will use cryptsetup :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add cryptsetup&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For using and managing UEFI, multiple packages are needed :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efibootmgr e2fsprogs grub grub-efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Partitioning the disk =&lt;br /&gt;
&lt;br /&gt;
Let&#039;s assume the disk is /dev/nvme0n1 and no partition is present, we will create three partitions :&lt;br /&gt;
 &lt;br /&gt;
* one for UEFI&lt;br /&gt;
* one for /&lt;br /&gt;
* one for swap (hibernation)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# gdisk /dev/nvme0n1&lt;br /&gt;
GPT fdisk (gdisk) version 1.0.9.1&lt;br /&gt;
&lt;br /&gt;
Partition table scan:&lt;br /&gt;
  MBR: protective&lt;br /&gt;
  BSD: not present&lt;br /&gt;
  APM: not present&lt;br /&gt;
  GPT: present&lt;br /&gt;
&lt;br /&gt;
Found valid GPT with protective MBR; using GPT.&lt;br /&gt;
&lt;br /&gt;
Command (? for help): d&lt;br /&gt;
No partitions&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (1-128, default 1): &lt;br /&gt;
First sector (2048-1000215182, default = 2048) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (2048-1000215182, default = 1000214527) or {+-}size{KMGTP}: 512M&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): ef00&lt;br /&gt;
Changed type of partition to &#039;EFI system partition&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (2-128, default 2): &lt;br /&gt;
First sector (1048577-1000215182, default = 1050624) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (1050624-1000215182, default = 1000214527) or {+-}size{KMGTP}: 16G&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8200&lt;br /&gt;
Changed type of partition to &#039;Linux swap&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (3-128, default 3): &lt;br /&gt;
First sector (1048577-1000215182, default = 33556480) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (33556480-1000215182, default = 1000214527) or {+-}size{KMGTP}: &lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8309&lt;br /&gt;
Changed type of partition to &#039;Linux LUKS&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): w&lt;br /&gt;
&lt;br /&gt;
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING&lt;br /&gt;
PARTITIONS!!&lt;br /&gt;
&lt;br /&gt;
Do you want to proceed? (Y/N): Y&lt;br /&gt;
OK; writing new GUID partition table (GPT) to /dev/nvme0n1.&lt;br /&gt;
The operation has completed successfully.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring LUKS =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 5000 --use-random luksFormat /dev/nvme0n1p2&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p2 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p2: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&lt;br /&gt;
cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 5000 --use-random luksFormat /dev/nvme0n1p3&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p3 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p3: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Mounting points and File System =&lt;br /&gt;
&lt;br /&gt;
Open the LUKS partitiond we just created:&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup luksOpen /dev/nvme0n1p2 nvme0n1p2-crypt&lt;br /&gt;
# cryptsetup luksOpen /dev/nvme0n1p3 nvme0n1p3-crypt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create vfat file system for UEFI partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.vfat /dev/nvme0n1p1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for swap partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/mapper/nvme0n1p2-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for / partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/mapper/nvme0n1p3-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create mounting points and mount partitions :&lt;br /&gt;
Mount / partition to /mnt :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t ext4 /dev/mapper/nvme0n1p3-crypt /mnt&amp;lt;/pre&amp;gt;&lt;br /&gt;
Create /boot/efi:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /mnt/boot/efi -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
Mount UEFI partition to /mnt/boot/efi :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t vfat /dev/nvme0n1p1 /mnt/boot/efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
Activate SWAP:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkswap /dev/mapper/nvme0n1p2-crypt&lt;br /&gt;
# swapon /dev/mapper/nvme0n1p2-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk&lt;br /&gt;
NAME                MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINTS&lt;br /&gt;
nvme0n1             259:0    0 476.9G  0 disk  &lt;br /&gt;
├─nvme0n1p1         259:1    0   511M  0 part  /mnt/boot/efi&lt;br /&gt;
├─nvme0n1p2         259:2    0  15.5G  0 part  &lt;br /&gt;
│ └─nvme0n1p2-crypt 253:0    0  15.5G  0 crypt [SWAP]&lt;br /&gt;
└─nvme0n1p3         259:3    0 460.9G  0 part  &lt;br /&gt;
  └─nvme0n1p3-crypt 253:1    0 460.9G  0 crypt /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Installing Alpine =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# setup-disk -m sys /mnt/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= mkinitfs settings &amp;amp; modules =&lt;br /&gt;
Edit the /mnt/etc/mkinitfs/mkinitfs.conf file and append the cryptsetup module to the features parameter (keymap only needed if QWERTY is not used):&lt;br /&gt;
&amp;lt;pre&amp;gt;features=&amp;quot;...keymap cryptsetup cryptkey&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Regenerate the initram:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkinitfs -c /mnt/etc/mkinitfs/mkinitfs.conf -b /mnt/ $(ls /mnt/lib/modules/)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Grub settings =&lt;br /&gt;
&lt;br /&gt;
Create a crypto_keyfile.bin to avoid typing the passphrase twice during the boot process (one for Grub partition, one for Alpine partition):&lt;br /&gt;
&amp;lt;pre&amp;gt;# touch /mnt/crypto_keyfile.bin&lt;br /&gt;
# chmod 600 /mnt/crypto_keyfile.bin&lt;br /&gt;
# dd bs=512 count=4 if=/dev/urandom of=/mnt/crypto_keyfile.bin&lt;br /&gt;
# cryptsetup luksAddKey /dev/nvme0n1p3 /mnt/crypto_keyfile.bin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, let&#039;s mount and chroot to our fresh installation:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t proc /proc /mnt/proc&lt;br /&gt;
# mount --rbind /dev /mnt/dev&lt;br /&gt;
# mount --make-rslave /mnt/dev&lt;br /&gt;
# mount --rbind /sys /mnt/sys&lt;br /&gt;
# chroot /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let&#039;s show the UUID of our partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk -f&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit /etc/default/grub and add a new line starting with GRUB_CMDLINE_LINUX parameter, replacing &amp;lt;UUID&amp;gt; with the UUID of the encrypted partition (in this case /dev/nvme0n1p3) and adding a new GRUB_PRELOAD_MODULES line like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_CMDLINE_LINUX=&amp;quot;cryptroot=UUID=&amp;lt;UUID&amp;gt; cryptdm=nvme0n1p3-crypt cryptkey&amp;quot;&lt;br /&gt;
GRUB_PRELOAD_MODULES=&amp;quot;luks cryptodisk part_gpt&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a /root/grub-pre.cfg and replace &amp;lt;UUID_WITHOUT_HYPHENS&amp;gt; with your encrypted root partition UUID (here /dev/nvme0n1p3) without hyphens&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set crypto_uuid=&amp;lt;UUID_WITHOUT_HYPHENS&amp;gt;&lt;br /&gt;
cryptomount -u $crypto_uuid&lt;br /&gt;
set root=crypto0&lt;br /&gt;
set prefix=($root)/boot/grub&lt;br /&gt;
insmod normal&lt;br /&gt;
normal&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring Secure Boot =&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efi-mkkeys efibootmgr&lt;br /&gt;
efi-mkkeys -s &amp;quot;Your Name&amp;quot; -o /etc/uefi-keys&lt;br /&gt;
echo &#039;disable_trigger=yes&#039; &amp;gt;&amp;gt; /etc/mkinitfs/mkinitfs.conf&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Re-install Grub:&lt;br /&gt;
&amp;lt;pre&amp;gt;# grub-mkimage -p /boot/grub -O x86_64-efi -c /root/grub-pre.cfg -o /tmp/grubx64.efi luks2 part_gpt cryptodisk ext2 gcry_rijndael pbkdf2 gcry_sha512&lt;br /&gt;
# install -v /tmp/grubx64.efi /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sed -i &#039;s/SecureBoot/SecureB00t/&#039; /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi&lt;br /&gt;
# cd /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sbsign --key /etc/uefi-keys/db.key --cert /etc/uefi-keys/db.crt --output grubx64.efi.signed grubx64.efi&lt;br /&gt;
# grub-mkconfig -o /boot/grub/grub.cfg&lt;br /&gt;
# efibootmgr --disk /dev/nvme0n1p1 --part 1 --create --label &#039;Alpine Linux Secure Boot Signed&#039; --load /EFI/AlpineLinuxSecureBoot/grubx64.efi.signed --verbose&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reboot&lt;br /&gt;
&lt;br /&gt;
Check Secure Boot State:&lt;br /&gt;
&amp;lt;pre&amp;gt;#apk add mokutil&lt;br /&gt;
mokutil --sb-state&lt;br /&gt;
SecureBoot enabled&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Congrats!&lt;/div&gt;</summary>
		<author><name>Blt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22173</id>
		<title>Full disk encryption secure boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22173"/>
		<updated>2022-08-03T14:46:20Z</updated>

		<summary type="html">&lt;p&gt;Blt: Adding SecureBoot&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Draft}}&lt;br /&gt;
&lt;br /&gt;
This guide is to explain step by step how to setup Alpine Linux with Full Disk Encryption using LUKS2, /boot &amp;amp; / together on the same partition, encrypted swap for hibernation on a nvme drive, with UEFI &amp;amp; Secure Boot.&lt;br /&gt;
The goal of this guide is to follow the KISS principle, lvm can be added, another file system can be used, multiple partitions for /home; /var/log etc.. can also be added, if running everything in one partition is not meeting your requirements.&lt;br /&gt;
&lt;br /&gt;
= Sequence of Events =&lt;br /&gt;
&lt;br /&gt;
* Installing packages&lt;br /&gt;
* Partitioning the disk&lt;br /&gt;
* Configuring LUKS&lt;br /&gt;
* Mounting points and File System&lt;br /&gt;
* Installing Alpine&lt;br /&gt;
* mkinitfs settings &amp;amp; modules&lt;br /&gt;
* Grub settings&lt;br /&gt;
* Configuring Secure Boot&lt;br /&gt;
&lt;br /&gt;
= Installing packages =&lt;br /&gt;
&lt;br /&gt;
To facilitate the partitioning we will use gdisk :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lsblk gptfdisk&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For encryption, we will use cryptsetup :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add cryptsetup&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For using and managing UEFI, multiple packages are needed :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efibootmgr e2fsprogs grub grub-efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Partitioning the disk =&lt;br /&gt;
&lt;br /&gt;
Let&#039;s assume the disk is /dev/nvme0n1 and no partition is present, we will create three partitions :&lt;br /&gt;
 &lt;br /&gt;
* one for UEFI&lt;br /&gt;
* one for /&lt;br /&gt;
* one for swap (hibernation)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# gdisk /dev/nvme0n1&lt;br /&gt;
GPT fdisk (gdisk) version 1.0.9.1&lt;br /&gt;
&lt;br /&gt;
Partition table scan:&lt;br /&gt;
  MBR: protective&lt;br /&gt;
  BSD: not present&lt;br /&gt;
  APM: not present&lt;br /&gt;
  GPT: present&lt;br /&gt;
&lt;br /&gt;
Found valid GPT with protective MBR; using GPT.&lt;br /&gt;
&lt;br /&gt;
Command (? for help): d&lt;br /&gt;
No partitions&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (1-128, default 1): &lt;br /&gt;
First sector (2048-1000215182, default = 2048) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (2048-1000215182, default = 1000214527) or {+-}size{KMGTP}: 512M&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): ef00&lt;br /&gt;
Changed type of partition to &#039;EFI system partition&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (2-128, default 2): &lt;br /&gt;
First sector (1048577-1000215182, default = 1050624) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (1050624-1000215182, default = 1000214527) or {+-}size{KMGTP}: 16G&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8200&lt;br /&gt;
Changed type of partition to &#039;Linux swap&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (3-128, default 3): &lt;br /&gt;
First sector (1048577-1000215182, default = 33556480) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (33556480-1000215182, default = 1000214527) or {+-}size{KMGTP}: &lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8309&lt;br /&gt;
Changed type of partition to &#039;Linux LUKS&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): w&lt;br /&gt;
&lt;br /&gt;
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING&lt;br /&gt;
PARTITIONS!!&lt;br /&gt;
&lt;br /&gt;
Do you want to proceed? (Y/N): Y&lt;br /&gt;
OK; writing new GUID partition table (GPT) to /dev/nvme0n1.&lt;br /&gt;
The operation has completed successfully.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring LUKS =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 5000 --use-random luksFormat /dev/nvme0n1p2&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p2 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p2: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&lt;br /&gt;
cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 5000 --use-random luksFormat /dev/nvme0n1p3&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p3 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p3: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Mounting points and File System =&lt;br /&gt;
&lt;br /&gt;
Open the LUKS partitiond we just created:&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup luksOpen /dev/nvme0n1p2 nvme0n1p2-crypt&lt;br /&gt;
# cryptsetup luksOpen /dev/nvme0n1p3 nvme0n1p3-crypt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create vfat file system for UEFI partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.vfat /dev/nvme0n1p1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for swap partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/mapper/nvme0n1p2-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for / partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/mapper/nvme0n1p3-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create mounting points and mount partitions :&lt;br /&gt;
Mount / partition to /mnt :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t ext4 /dev/mapper/nvme0n1p3-crypt /mnt&amp;lt;/pre&amp;gt;&lt;br /&gt;
Create /boot/efi:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /mnt/boot/efi -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
Mount UEFI partition to /mnt/boot/efi :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t vfat /dev/nvme0n1p1 /mnt/boot/efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
Activate SWAP:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkswap /dev/mapper/nvme0n1p2-crypt&lt;br /&gt;
# swapon /dev/mapper/nvme0n1p2-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk&lt;br /&gt;
NAME                MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINTS&lt;br /&gt;
nvme0n1             259:0    0 476.9G  0 disk  &lt;br /&gt;
├─nvme0n1p1         259:1    0   511M  0 part  /mnt/boot/efi&lt;br /&gt;
├─nvme0n1p2         259:2    0  15.5G  0 part  &lt;br /&gt;
│ └─nvme0n1p2-crypt 253:0    0  15.5G  0 crypt [SWAP]&lt;br /&gt;
└─nvme0n1p3         259:3    0 460.9G  0 part  &lt;br /&gt;
  └─nvme0n1p3-crypt 253:1    0 460.9G  0 crypt /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Installing Alpine =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# setup-disk -m sys /mnt/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= mkinitfs settings &amp;amp; modules =&lt;br /&gt;
Edit the /mnt/etc/mkinitfs/mkinitfs.conf file and append the cryptsetup module to the features parameter (keymap only needed if QWERTY is not used):&lt;br /&gt;
&amp;lt;pre&amp;gt;features=&amp;quot;...keymap cryptsetup cryptkey&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Regenerate the initram:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkinitfs -c /mnt/etc/mkinitfs/mkinitfs.conf -b /mnt/ $(ls /mnt/lib/modules/)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Grub settings =&lt;br /&gt;
&lt;br /&gt;
Create a crypto_keyfile.bin to avoid typing the passphrase twice during the boot process (one for Grub partition, one for Alpine partition):&lt;br /&gt;
&amp;lt;pre&amp;gt;# touch /mnt/crypto_keyfile.bin&lt;br /&gt;
# chmod 600 /mnt/crypto_keyfile.bin&lt;br /&gt;
# dd bs=512 count=4 if=/dev/urandom of=/mnt/crypto_keyfile.bin&lt;br /&gt;
# cryptsetup luksAddKey /dev/nvme0n1p3 /mnt/crypto_keyfile.bin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, let&#039;s mount and chroot to our fresh installation:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t proc /proc /mnt/proc&lt;br /&gt;
# mount --rbind /dev /mnt/dev&lt;br /&gt;
# mount --make-rslave /mnt/dev&lt;br /&gt;
# mount --rbind /sys /mnt/sys&lt;br /&gt;
# chroot /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let&#039;s show the UUID of our partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk -f&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit /etc/default/grub and add a new line starting with GRUB_CMDLINE_LINUX parameter, replacing &amp;lt;UUID&amp;gt; with the UUID of the encrypted partition (in this case /dev/nvme0n1p3) and adding a new GRUB_PRELOAD_MODULES line like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_CMDLINE_LINUX=&amp;quot;cryptroot=UUID=&amp;lt;UUID&amp;gt; cryptdm=nvme0n1p3-crypt cryptkey&amp;quot;&lt;br /&gt;
GRUB_PRELOAD_MODULES=&amp;quot;luks cryptodisk part_gpt&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a /root/grub-pre.cfg and replace &amp;lt;UUID_WITHOUT_HYPHENS&amp;gt; with your encrypted root partition UUID (here /dev/nvme0n1p3) without hyphens&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set crypto_uuid=&amp;lt;UUID_WITHOUT_HYPHENS&amp;gt;&lt;br /&gt;
cryptomount -u $crypto_uuid&lt;br /&gt;
set root=crypto0&lt;br /&gt;
set prefix=($root)/boot/grub&lt;br /&gt;
insmod normal&lt;br /&gt;
normal&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring Secure Boot =&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efi-mkkeys efibootmgr&lt;br /&gt;
efi-mkkeys -s &amp;quot;Your Name&amp;quot; -o /etc/uefi-keys&lt;br /&gt;
echo &#039;disable_trigger=yes&#039; &amp;gt;&amp;gt; /etc/mkinitfs/mkinitfs.conf&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Re-install Grub:&lt;br /&gt;
&amp;lt;pre&amp;gt;# grub-mkimage -m /etc/uefi-keys/PK.crt -p /boot/grub -O x86_64-efi -c /root/grub-pre.cfg -o /tmp/grubx64.efi luks2 part_gpt cryptodisk ext2 gcry_rijndael pbkdf2 gcry_sha512&lt;br /&gt;
# install -v /tmp/grubx64.efi /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sed -i &#039;s/SecureBoot/SecureB00t/&#039; /boot/efi/EFI/AlpineLinuxSecureBoot/grubx64.efi&lt;br /&gt;
# cd /boot/efi/EFI/AlpineLinuxSecureBoot/&lt;br /&gt;
# sbsign --key /etc/uefi-keys/db.key --cert /etc/uefi-keys/db.crt --output grubx64.efi.signed grubx64.efi&lt;br /&gt;
# grub-mkconfig -o /boot/grub/grub.cfg&lt;br /&gt;
# efibootmgr --disk /dev/nvme0n1p1 --part 1 --create --label &#039;Alpine Linux Secure Boot Signed&#039; --load /EFI/AlpineLinuxSecureBoot/grubx64.efi.signed --verbose&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reboot&lt;br /&gt;
&lt;br /&gt;
Check Secure Boot State:&lt;br /&gt;
&amp;lt;pre&amp;gt;#apk add mokutil&lt;br /&gt;
mokutil --sb-state&lt;br /&gt;
SecureBoot enabled&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Congrats!&lt;/div&gt;</summary>
		<author><name>Blt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22153</id>
		<title>Full disk encryption secure boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22153"/>
		<updated>2022-07-28T09:36:20Z</updated>

		<summary type="html">&lt;p&gt;Blt: adding Grub LUKS2 tweak&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Draft}}&lt;br /&gt;
&lt;br /&gt;
This guide is to explain step by step how to setup Alpine Linux with Full Disk Encryption using LUKS2, /boot &amp;amp; / together on the same partition, encrypted swap for hibernation on a nvme drive, with UEFI &amp;amp; Secure Boot.&lt;br /&gt;
The goal of this guide is to follow the KISS principle, lvm can be added, another file system can be used, multiple partitions for /home; /var/log etc.. can also be added, if running everything in one partition is not meeting your requirements.&lt;br /&gt;
&lt;br /&gt;
= Sequence of Events =&lt;br /&gt;
&lt;br /&gt;
* Installing packages&lt;br /&gt;
* Partitioning the disk&lt;br /&gt;
* Configuring LUKS&lt;br /&gt;
* Mounting points and File System&lt;br /&gt;
* Installing Alpine&lt;br /&gt;
* mkinitfs settings &amp;amp; modules&lt;br /&gt;
* Grub settings&lt;br /&gt;
* Configuring Secure Boot&lt;br /&gt;
&lt;br /&gt;
= Installing packages =&lt;br /&gt;
&lt;br /&gt;
To facilitate the partitioning we will use gdisk :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lsblk gptfdisk&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For encryption, we will use cryptsetup :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add cryptsetup&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For using and managing UEFI, multiple packages are needed :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efibootmgr e2fsprogs grub grub-efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Partitioning the disk =&lt;br /&gt;
&lt;br /&gt;
Let&#039;s assume the disk is /dev/nvme0n1 and no partition is present, we will create three partitions :&lt;br /&gt;
 &lt;br /&gt;
* one for UEFI&lt;br /&gt;
* one for /&lt;br /&gt;
* one for swap (hibernation)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# gdisk /dev/nvme0n1&lt;br /&gt;
GPT fdisk (gdisk) version 1.0.9.1&lt;br /&gt;
&lt;br /&gt;
Partition table scan:&lt;br /&gt;
  MBR: protective&lt;br /&gt;
  BSD: not present&lt;br /&gt;
  APM: not present&lt;br /&gt;
  GPT: present&lt;br /&gt;
&lt;br /&gt;
Found valid GPT with protective MBR; using GPT.&lt;br /&gt;
&lt;br /&gt;
Command (? for help): d&lt;br /&gt;
No partitions&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (1-128, default 1): &lt;br /&gt;
First sector (2048-1000215182, default = 2048) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (2048-1000215182, default = 1000214527) or {+-}size{KMGTP}: 512M&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): ef00&lt;br /&gt;
Changed type of partition to &#039;EFI system partition&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (2-128, default 2): &lt;br /&gt;
First sector (1048577-1000215182, default = 1050624) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (1050624-1000215182, default = 1000214527) or {+-}size{KMGTP}: 16G&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8200&lt;br /&gt;
Changed type of partition to &#039;Linux swap&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (3-128, default 3): &lt;br /&gt;
First sector (1048577-1000215182, default = 33556480) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (33556480-1000215182, default = 1000214527) or {+-}size{KMGTP}: &lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8309&lt;br /&gt;
Changed type of partition to &#039;Linux LUKS&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): w&lt;br /&gt;
&lt;br /&gt;
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING&lt;br /&gt;
PARTITIONS!!&lt;br /&gt;
&lt;br /&gt;
Do you want to proceed? (Y/N): Y&lt;br /&gt;
OK; writing new GUID partition table (GPT) to /dev/nvme0n1.&lt;br /&gt;
The operation has completed successfully.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring LUKS =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 5000 --use-random luksFormat /dev/nvme0n1p2&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p2 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p2: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&lt;br /&gt;
cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 5000 --use-random luksFormat /dev/nvme0n1p3&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p3 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p3: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Mounting points and File System =&lt;br /&gt;
&lt;br /&gt;
Open the LUKS partitiond we just created:&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup luksOpen /dev/nvme0n1p2 nvme0n1p2-crypt&lt;br /&gt;
# cryptsetup luksOpen /dev/nvme0n1p3 nvme0n1p3-crypt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create vfat file system for UEFI partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.vfat /dev/nvme0n1p1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for swap partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/mapper/nvme0n1p2-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for / partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/mapper/nvme0n1p3-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create mounting points and mount partitions :&lt;br /&gt;
Mount / partition to /mnt :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t ext4 /dev/mapper/nvme0n1p3-crypt /mnt&amp;lt;/pre&amp;gt;&lt;br /&gt;
Create /boot/efi:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /mnt/boot/efi -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
Mount UEFI partition to /mnt/boot/efi :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t vfat /dev/nvme0n1p1 /mnt/boot/efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
Activate SWAP:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkswap /dev/mapper/nvme0n1p2-crypt&lt;br /&gt;
# swapon /dev/mapper/nvme0n1p2-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk&lt;br /&gt;
NAME                MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINTS&lt;br /&gt;
nvme0n1             259:0    0 476.9G  0 disk  &lt;br /&gt;
├─nvme0n1p1         259:1    0   511M  0 part  /mnt/boot/efi&lt;br /&gt;
├─nvme0n1p2         259:2    0  15.5G  0 part  &lt;br /&gt;
│ └─nvme0n1p2-crypt 253:0    0  15.5G  0 crypt [SWAP]&lt;br /&gt;
└─nvme0n1p3         259:3    0 460.9G  0 part  &lt;br /&gt;
  └─nvme0n1p3-crypt 253:1    0 460.9G  0 crypt /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Installing Alpine =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# setup-disk -m sys /mnt/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= mkinitfs settings &amp;amp; modules =&lt;br /&gt;
Edit the /mnt/etc/mkinitfs/mkinitfs.conf file and append the cryptsetup module to the features parameter (keymap only needed if QWERTY is not used):&lt;br /&gt;
&amp;lt;pre&amp;gt;features=&amp;quot;...keymap cryptsetup cryptkey&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Regenerate the initram:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkinitfs -c /mnt/etc/mkinitfs/mkinitfs.conf -b /mnt/ $(ls /mnt/lib/modules/)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Grub settings =&lt;br /&gt;
&lt;br /&gt;
Create a crypto_keyfile.bin to avoid typing the passphrase twice during the boot process (one for Grub partition, one for Alpine partition):&lt;br /&gt;
&amp;lt;pre&amp;gt;# touch /mnt/crypto_keyfile.bin&lt;br /&gt;
# chmod 600 /mnt/crypto_keyfile.bin&lt;br /&gt;
# dd bs=512 count=4 if=/dev/urandom of=/mnt/crypto_keyfile.bin&lt;br /&gt;
# cryptsetup luksAddKey /dev/nvme0n1p3 /mnt/crypto_keyfile.bin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, let&#039;s mount and chroot to our fresh installation:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t proc /proc /mnt/proc&lt;br /&gt;
# mount --rbind /dev /mnt/dev&lt;br /&gt;
# mount --make-rslave /mnt/dev&lt;br /&gt;
# mount --rbind /sys /mnt/sys&lt;br /&gt;
# chroot /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let&#039;s show the UUID of our partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk -f&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit /etc/default/grub and add a new line starting with GRUB_CMDLINE_LINUX parameter, replacing &amp;lt;UUID&amp;gt; with the UUID of the encrypted partition (in this case /dev/nvme0n1p3) and adding a new GRUB_PRELOAD_MODULES line like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_CMDLINE_LINUX=&amp;quot;cryptroot=UUID=&amp;lt;UUID&amp;gt; cryptdm=nvme0n1p3-crypt cryptkey&amp;quot;&lt;br /&gt;
GRUB_PRELOAD_MODULES=&amp;quot;luks cryptodisk part_gpt&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a /root/grub-pre.cfg and replace &amp;lt;UUID_WITHOUT_HYPHENS&amp;gt; with your encrypted root partition UUID (here /dev/nvme0n1p3) without hyphens&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set crypto_uuid=&amp;lt;UUID_WITHOUT_HYPHENS&amp;gt;&lt;br /&gt;
cryptomount -u $crypto_uuid&lt;br /&gt;
set root=crypto0&lt;br /&gt;
set prefix=($root)/boot/grub&lt;br /&gt;
insmod normal&lt;br /&gt;
normal&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Re-install Grub:&lt;br /&gt;
&amp;lt;pre&amp;gt;# grub-mkimage -p /boot/grub -O x86_64-efi -c /root/grub-pre.cfg -o /tmp/grubx64.efi luks2 part_gpt cryptodisk ext2 gcry_rijndael pbkdf2 gcry_sha512&lt;br /&gt;
# install -v /tmp/grubx64.efi /boot/efi/EFI/AlpineLinux/&lt;br /&gt;
# grub-mkconfig -o /boot/grub/grub.cfg&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring Secure Boot =&lt;/div&gt;</summary>
		<author><name>Blt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22152</id>
		<title>Full disk encryption secure boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22152"/>
		<updated>2022-07-28T09:12:34Z</updated>

		<summary type="html">&lt;p&gt;Blt: adding cryptkey to mkinitfs&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Draft}}&lt;br /&gt;
&lt;br /&gt;
This guide is to explain step by step how to setup Alpine Linux with Full Disk Encryption using LUKS2, /boot &amp;amp; / together on the same partition, encrypted swap for hibernation on a nvme drive, with UEFI &amp;amp; Secure Boot.&lt;br /&gt;
The goal of this guide is to follow the KISS principle, lvm can be added, another file system can be used, multiple partitions for /home; /var/log etc.. can also be added, if running everything in one partition is not meeting your requirements.&lt;br /&gt;
&lt;br /&gt;
= Sequence of Events =&lt;br /&gt;
&lt;br /&gt;
* Installing packages&lt;br /&gt;
* Partitioning the disk&lt;br /&gt;
* Configuring LUKS&lt;br /&gt;
* Mounting points and File System&lt;br /&gt;
* Installing Alpine&lt;br /&gt;
* mkinitfs settings &amp;amp; modules&lt;br /&gt;
* Grub settings&lt;br /&gt;
* Configuring Secure Boot&lt;br /&gt;
&lt;br /&gt;
= Installing packages =&lt;br /&gt;
&lt;br /&gt;
To facilitate the partitioning we will use gdisk :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lsblk gptfdisk&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For encryption, we will use cryptsetup :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add cryptsetup&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For using and managing UEFI, multiple packages are needed :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efibootmgr e2fsprogs grub grub-efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Partitioning the disk =&lt;br /&gt;
&lt;br /&gt;
Let&#039;s assume the disk is /dev/nvme0n1 and no partition is present, we will create three partitions :&lt;br /&gt;
 &lt;br /&gt;
* one for UEFI&lt;br /&gt;
* one for /&lt;br /&gt;
* one for swap (hibernation)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# gdisk /dev/nvme0n1&lt;br /&gt;
GPT fdisk (gdisk) version 1.0.9.1&lt;br /&gt;
&lt;br /&gt;
Partition table scan:&lt;br /&gt;
  MBR: protective&lt;br /&gt;
  BSD: not present&lt;br /&gt;
  APM: not present&lt;br /&gt;
  GPT: present&lt;br /&gt;
&lt;br /&gt;
Found valid GPT with protective MBR; using GPT.&lt;br /&gt;
&lt;br /&gt;
Command (? for help): d&lt;br /&gt;
No partitions&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (1-128, default 1): &lt;br /&gt;
First sector (2048-1000215182, default = 2048) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (2048-1000215182, default = 1000214527) or {+-}size{KMGTP}: 512M&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): ef00&lt;br /&gt;
Changed type of partition to &#039;EFI system partition&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (2-128, default 2): &lt;br /&gt;
First sector (1048577-1000215182, default = 1050624) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (1050624-1000215182, default = 1000214527) or {+-}size{KMGTP}: 16G&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8200&lt;br /&gt;
Changed type of partition to &#039;Linux swap&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (3-128, default 3): &lt;br /&gt;
First sector (1048577-1000215182, default = 33556480) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (33556480-1000215182, default = 1000214527) or {+-}size{KMGTP}: &lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8309&lt;br /&gt;
Changed type of partition to &#039;Linux LUKS&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): w&lt;br /&gt;
&lt;br /&gt;
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING&lt;br /&gt;
PARTITIONS!!&lt;br /&gt;
&lt;br /&gt;
Do you want to proceed? (Y/N): Y&lt;br /&gt;
OK; writing new GUID partition table (GPT) to /dev/nvme0n1.&lt;br /&gt;
The operation has completed successfully.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring LUKS =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 5000 --use-random luksFormat /dev/nvme0n1p2&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p2 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p2: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&lt;br /&gt;
cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 5000 --use-random luksFormat /dev/nvme0n1p3&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p3 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p3: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Mounting points and File System =&lt;br /&gt;
&lt;br /&gt;
Open the LUKS partitiond we just created:&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup luksOpen /dev/nvme0n1p2 nvme0n1p2-crypt&lt;br /&gt;
# cryptsetup luksOpen /dev/nvme0n1p3 nvme0n1p3-crypt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create vfat file system for UEFI partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.vfat /dev/nvme0n1p1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for swap partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/mapper/nvme0n1p2-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for / partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/mapper/nvme0n1p3-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create mounting points and mount partitions :&lt;br /&gt;
Mount / partition to /mnt :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t ext4 /dev/mapper/nvme0n1p3-crypt /mnt&amp;lt;/pre&amp;gt;&lt;br /&gt;
Create /boot/efi:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /mnt/boot/efi -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
Mount UEFI partition to /mnt/boot/efi :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t vfat /dev/nvme0n1p1 /mnt/boot/efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
Activate SWAP:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkswap /dev/mapper/nvme0n1p2-crypt&lt;br /&gt;
# swapon /dev/mapper/nvme0n1p2-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk&lt;br /&gt;
NAME                MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINTS&lt;br /&gt;
nvme0n1             259:0    0 476.9G  0 disk  &lt;br /&gt;
├─nvme0n1p1         259:1    0   511M  0 part  /mnt/boot/efi&lt;br /&gt;
├─nvme0n1p2         259:2    0  15.5G  0 part  &lt;br /&gt;
│ └─nvme0n1p2-crypt 253:0    0  15.5G  0 crypt [SWAP]&lt;br /&gt;
└─nvme0n1p3         259:3    0 460.9G  0 part  &lt;br /&gt;
  └─nvme0n1p3-crypt 253:1    0 460.9G  0 crypt /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Installing Alpine =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# setup-disk -m sys /mnt/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= mkinitfs settings &amp;amp; modules =&lt;br /&gt;
Edit the /mnt/etc/mkinitfs/mkinitfs.conf file and append the cryptsetup module to the features parameter (keymap only needed if QWERTY is not used):&lt;br /&gt;
&amp;lt;pre&amp;gt;features=&amp;quot;...keymap cryptsetup cryptkey&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Regenerate the initram:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkinitfs -c /mnt/etc/mkinitfs/mkinitfs.conf -b /mnt/ $(ls /mnt/lib/modules/)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Grub settings =&lt;br /&gt;
&lt;br /&gt;
Create a crypto_keyfile.bin to avoid typing the passphrase twice during the boot process (one for Grub partition, one for Alpine partition):&lt;br /&gt;
&amp;lt;pre&amp;gt;# touch /mnt/crypto_keyfile.bin&lt;br /&gt;
# chmod 600 /mnt/crypto_keyfile.bin&lt;br /&gt;
# dd bs=512 count=4 if=/dev/urandom of=/mnt/crypto_keyfile.bin&lt;br /&gt;
# cryptsetup luksAddKey /dev/nvme0n1p3 /mnt/crypto_keyfile.bin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, let&#039;s mount and chroot to our fresh installation:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t proc /proc /mnt/proc&lt;br /&gt;
# mount --rbind /dev /mnt/dev&lt;br /&gt;
# mount --make-rslave /mnt/dev&lt;br /&gt;
# mount --rbind /sys /mnt/sys&lt;br /&gt;
# chroot /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let&#039;s show the UUID of our partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk -f&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit /etc/default/grub and add a new line starting with GRUB_CMDLINE_LINUX parameter, replacing &amp;lt;UUID&amp;gt; with the UUID of the encrypted partition (in this case /dev/nvme0n1p3):&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_TIMEOUT=2&lt;br /&gt;
GRUB_DISABLE_SUBMENU=y&lt;br /&gt;
GRUB_DISABLE_RECOVERY=true&lt;br /&gt;
GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;cryptroot=UUID=&amp;lt;UUID&amp;gt; cryptdm=nvme0n1p3-crypt cryptkey modules=sd-mod,usb-storage,ext4,nvme quiet rootfstype=ext4&amp;quot;&lt;br /&gt;
GRUB_PRELOAD_MODULES=&amp;quot;luks cryptodisk part_gpt ext4&amp;quot;&lt;br /&gt;
GRUB_ENABLE_CRYPTODISK=y&lt;br /&gt;
GRUB_DISABLE_OS_PROBER=y&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Re-install Grub:&lt;br /&gt;
&amp;lt;pre&amp;gt;# grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=AlpineLinux --modules=&amp;quot;luks2 part_gpt cryptodisk ext2 gcry_rijndael pbkdf2 gcry_sha512&amp;quot;&lt;br /&gt;
# grub-mkconfig -o /boot/grub/grub.cfg&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring Secure Boot =&lt;/div&gt;</summary>
		<author><name>Blt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=LVM_on_LUKS&amp;diff=22151</id>
		<title>LVM on LUKS</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=LVM_on_LUKS&amp;diff=22151"/>
		<updated>2022-07-28T08:52:02Z</updated>

		<summary type="html">&lt;p&gt;Blt: /* Luks2 */ add a note to remove hyphens from UUID&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
This documentation describes how to set up Alpine Linux on a fully encrypted disk (apart from the bootloader partition). We will have an LVM container installed inside an encrypted partition. To encrypt the partition containing the LVM volume group, dm-crypt (which is managed by the &amp;lt;code&amp;gt;cryptsetup&amp;lt;/code&amp;gt; command) and its LUKS subsystem is used.&lt;br /&gt;
&lt;br /&gt;
Note that your {{path|/boot/}} partition must be non-encrypted to work with Syslinux. When using GRUB2 it is possible to boot from an encrypted partition to provide a layer of protection from [https://en.wikipedia.org/wiki/Evil_maid_attack Evil Maid attacks], but Syslinux doesn&#039;t support that.&lt;br /&gt;
&lt;br /&gt;
== Storage Device Name ==&lt;br /&gt;
&lt;br /&gt;
To find your storage device&#039;s name, you could either install {{pkg|util-linux}} (&amp;lt;code&amp;gt;apk add util-linux&amp;lt;/code&amp;gt;) and find your device using the &amp;lt;code&amp;gt;lsblk&amp;lt;/code&amp;gt; command, or you could make an educated guess by using BusyBox&#039;s &amp;lt;code&amp;gt;blkid&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;df&amp;lt;/code&amp;gt; commands, and running &amp;lt;code&amp;gt;ls /dev/sd*&amp;lt;/code&amp;gt; if you are installing to a USB, SATA or SCSI device, &amp;lt;code&amp;gt;ls /dev/fd*&amp;lt;/code&amp;gt; for floppy disks and &amp;lt;code&amp;gt;ls /dev/hd*&amp;lt;/code&amp;gt; for IDE (PATA) devices.&lt;br /&gt;
&lt;br /&gt;
The following documentation uses the {{path|/dev/sda}} device as installation destination. If your environment uses a different name for your storage device, use the corresponding device name in the examples.&lt;br /&gt;
&lt;br /&gt;
= Setting up Alpine Linux Using LVM on Top of a LUKS Partition =&lt;br /&gt;
&lt;br /&gt;
To install Alpine Linux on logical volumes running on top of a LUKS encrypted partition, you cannot use the [[Installation|official installation]] procedure. The installation requires several manual steps you must run in the Alpine Linux Live CD environment.&lt;br /&gt;
&lt;br /&gt;
== Preparing the Temporary Installation Environment ==&lt;br /&gt;
&lt;br /&gt;
Before you begin to install Alpine Linux, prepare the temporary environment:&lt;br /&gt;
&lt;br /&gt;
Boot the latest Alpine Linux Installation CD. At the login prompt, use the &amp;lt;code&amp;gt;root&amp;lt;/code&amp;gt; user without a password to log in. Now we will follow the [[Setup-alpine]] script and make our changes along the way.&lt;br /&gt;
&lt;br /&gt;
Run the scripts in this order:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# setup-keymap&lt;br /&gt;
# setup-hostname&lt;br /&gt;
# setup-interfaces&lt;br /&gt;
# rc-service networking start&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you are configuring static networking (i.e. you didn&#039;t configure any interfaces to use DHCP), run &amp;lt;code&amp;gt;setup-dns&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you are using Wi-Fi you may need to do run &amp;lt;code&amp;gt;rc-update add wpa_supplicant boot&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# passwd&lt;br /&gt;
# setup-timezone&lt;br /&gt;
# rc-update add networking boot&lt;br /&gt;
# rc-update add urandom boot&lt;br /&gt;
# rc-update add acpid default&lt;br /&gt;
# rc-service acpid start&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit your {{Path|/etc/hosts}} to look like this, replacing &amp;lt;hostname&amp;gt; with your hostname and &amp;lt;domain&amp;gt; with your TLD (if you don&#039;t have a TLD, use &#039;localdomain&#039;:&lt;br /&gt;
{{Tip|The default text editor in BusyBox is &amp;lt;code&amp;gt;vi&amp;lt;/code&amp;gt; (pronounced &#039;&#039;vee-eye&#039;&#039;).}}&lt;br /&gt;
{{Cat|/etc/hosts|127.0.0.1       &amp;lt;hostname&amp;gt; &amp;lt;hostname&amp;gt;.&amp;lt;domain&amp;gt; localhost localhost.localdomain&lt;br /&gt;
::1             &amp;lt;hostname&amp;gt; &amp;lt;hostname&amp;gt;.&amp;lt;domain&amp;gt; localhost localhost.localdomain}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# setup-ntp&lt;br /&gt;
# setup-apkrepos&lt;br /&gt;
# apk update&lt;br /&gt;
# setup-sshd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here&#039;s where we deviate from the install script.&lt;br /&gt;
&lt;br /&gt;
Install the following packages required to set up LVM and LUKS:&lt;br /&gt;
&lt;br /&gt;
{{Note|The &amp;lt;code&amp;gt;parted&amp;lt;/code&amp;gt; partition editor is needed for advanced partitioning and GPT disklabels. BusyBox &amp;lt;code&amp;gt;fdisk&amp;lt;/code&amp;gt; is a very stripped-down version with minimal functionality}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lvm2 cryptsetup e2fsprogs parted mkinitfs&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Optionally, if you want to overwrite your storage with random data first, install &amp;lt;code&amp;gt;haveged&amp;lt;/code&amp;gt;, which is a random number generator based on hardware events and has a higher throughput than &amp;lt;code&amp;gt;/dev/urandom&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add haveged&lt;br /&gt;
# rc-service haveged start&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Creating the Partition Layout ==&lt;br /&gt;
&lt;br /&gt;
Depending on your motherboard, bios features and configuration&lt;br /&gt;
we can either use partition table in MBR (legacy BIOS)&lt;br /&gt;
or GUID Partition Table (GPT).&lt;br /&gt;
We&#039;ll describe both with example layouts.&lt;br /&gt;
&lt;br /&gt;
=== BIOS/MBR with DOS disklabel ===&lt;br /&gt;
&lt;br /&gt;
We&#039;ll be partitioning the storage device with a non-encrypted &amp;lt;code&amp;gt;/boot&amp;lt;/code&amp;gt; partition for use with the Syslinux bootloader. Syslinux is meant for use with legacy BIOS and an MSDOS MBR partition table. &amp;lt;br&amp;gt;&lt;br /&gt;
Syslinux does support GPT partition tables but GRUB2 is the better option for UEFI (UEFI is possible only with GPT).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;+---------------------------+------------------------+-----------------------+&lt;br /&gt;
| Partition name            | Partition purpose      | Filesystem type       |&lt;br /&gt;
+---------------------------+------------------------+-----------------------+&lt;br /&gt;
| /dev/sda1                 | Boot partition         | ext4                  |&lt;br /&gt;
| /dev/sda2                 | LUKS container         | LUKS                  |&lt;br /&gt;
| |-&amp;gt; /dev/mapper/lvmcrypt  | LVM container          | LVM                   |&lt;br /&gt;
|  |-&amp;gt; /dev/vg01/root       | Root partition         | ext4                  |&lt;br /&gt;
|  |-&amp;gt; /dev/vg01/swap       | Swap partition         | swap                  |&lt;br /&gt;
+---------------------------+------------------------+-----------------------+&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Warning|This will delete an existing partition table and make your data very hard to recover. If you want to dual boot, stop here and ask an expert.}}&lt;br /&gt;
&lt;br /&gt;
Create a partition of approximately 100MB to boot from, then assign the rest of the space to your LUKS partition.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# parted -a optimal&lt;br /&gt;
(parted) mklabel msdos&lt;br /&gt;
(parted) mkpart primary ext4 0% 100M&lt;br /&gt;
(parted) set 1 boot on&lt;br /&gt;
(parted) mkpart primary ext4 100M 100%&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To view your partition table, type &amp;lt;code&amp;gt;print&amp;lt;/code&amp;gt; while still in &amp;lt;code&amp;gt;parted&amp;lt;/code&amp;gt;. Your results should look something like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;(parted) print&lt;br /&gt;
Model: ATA TOSHIBA ******** (scsi)&lt;br /&gt;
Disk /dev/sda: 1000GB&lt;br /&gt;
Sector size (logical/physical): 512B/4096B&lt;br /&gt;
Partition Table: msdos&lt;br /&gt;
Disk Flags:&lt;br /&gt;
&lt;br /&gt;
Number  Start   End     Size    Type     File system  Flags&lt;br /&gt;
 1      1049kB  99.6MB  98.6MB  primary  ext4         boot&lt;br /&gt;
 2      99.6MB  1000GB  1000GB  primary  ext4&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== UEFI with GPT disklabel ===&lt;br /&gt;
&lt;br /&gt;
We will be encrypting the whole disk except for the EFI system partition mounted at &amp;lt;code&amp;gt;/boot/efi&amp;lt;/code&amp;gt;. This means GRUB2 will decrypt the LUKS volume and load the kernel from there, preventing someone with physical access to your computer from maliciously installing a rootkit (or bootkit) in your boot partition while your computer is not unlocked. The partitioning scheme will look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;+---------------------------+------------------------+-----------------------+&lt;br /&gt;
| Partition name            | Partition purpose      | Filesystem type       |&lt;br /&gt;
+---------------------------+------------------------+-----------------------+&lt;br /&gt;
| /dev/sda1                 | EFI system partition   | fat32                 |&lt;br /&gt;
| /dev/sda2                 | LUKS container         | LUKS                  |&lt;br /&gt;
| |-&amp;gt; /dev/mapper/lvmcrypt  | LVM container          | LVM                   |&lt;br /&gt;
|  |-&amp;gt; /dev/vg01/root       | Root partition         | ext4                  |&lt;br /&gt;
|  |-&amp;gt; /dev/vg01/boot       | Boot partition         | ext4                  |&lt;br /&gt;
|  |-&amp;gt; /dev/vg01/swap       | Swap partition         | swap                  |&lt;br /&gt;
+---------------------------+------------------------+-----------------------+&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Warning|This will delete an existing partition table and make your data very hard to recover. If you want to dual boot, stop here and ask an expert.}}&lt;br /&gt;
&lt;br /&gt;
Create an EFI system partition of approximately 200MB, then assign the rest of the space to your LUKS partition.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# parted -a optimal&lt;br /&gt;
(parted) mklabel gpt&lt;br /&gt;
(parted) mkpart primary fat32 0% 200M&lt;br /&gt;
(parted) name 1 esp&lt;br /&gt;
(parted) set 1 esp on&lt;br /&gt;
(parted) mkpart primary ext4 200M 100%&lt;br /&gt;
(parted) name 2 crypto-luks&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Optional: Overwrite LUKS Partition with Random Data ==&lt;br /&gt;
&lt;br /&gt;
This should be done if your hard drive wasn&#039;t encrypted previously. It helps purge old, non-encrypted data and makes it harder for an attacker to work out how much data you have on your drive if they have access to the encrypted contents.&lt;br /&gt;
&lt;br /&gt;
We&#039;ll use {{pkg|haveged}} as it is considerably faster than {{path|/dev/urandom}} when generating pseudo-random numbers (it&#039;s almost as high in throughput as {{path|/dev/zero}}), and is (supposedly) very close to truly random.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# haveged -n 0 | dd of=/dev/sda2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Encrypting the LVM Physical Volume Partition == &lt;br /&gt;
&lt;br /&gt;
To encrypt the partition that will later contain the LVM PV, you could either use the default settings (aes-xts-plain64 cipher with 256-bit key and Argon2 hashing with iter-time 2000ms), or you could use these settings which have added security with the trade-off being a non-noticeable decrease in performance on modern computers:&lt;br /&gt;
&lt;br /&gt;
Default settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup luksFormat /dev/sda2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Luks1 Optimized for security:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup -v -c serpent-xts-plain64 -s 512 --hash whirlpool --iter-time 5000 --use-random luksFormat --type luks1 /dev/sda2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Luks2 Optimized for security:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 5000 --use-random luksFormat /dev/sda2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Converting between LUKS2 and LUKS1 ===&lt;br /&gt;
&lt;br /&gt;
It is sometimes possible to convert a LUKS2 volume to a LUKS1 volume. First take a backup of the LUKS header that you can restore if anything goes wrong:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup luksHeaderBackup /dev/sda2 --header-backup-file sda2-luks-header-backup&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then make sure all keys use &amp;lt;code&amp;gt;pbkdf2&amp;lt;/code&amp;gt; by adding a new key with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup luksAddKey --pbkdf pbkdf2 /dev/sda2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Remove keys that use &amp;lt;code&amp;gt;argon2i&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;argon2id&amp;lt;/code&amp;gt; with &amp;lt;code&amp;gt;cryptsetup luksRemoveKey /dev/sda2&amp;lt;/code&amp;gt;. You can check the key information using &amp;lt;code&amp;gt;cryptsetup luksDump /dev/sda2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now you can try the conversion, although it may not work.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup convert /dev/sda2 --type luks1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Creating the Logical Volumes and File Systems ==&lt;br /&gt;
&lt;br /&gt;
Open the LUKS partition:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup luksOpen /dev/sda2 lvmcrypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the PV on &amp;lt;code&amp;gt;lvmcrypt&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# pvcreate /dev/mapper/lvmcrypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the &amp;lt;code&amp;gt;vg0&amp;lt;/code&amp;gt; LVM VG in the &amp;lt;code&amp;gt;/dev/mapper/lvmcrypt&amp;lt;/code&amp;gt; PV:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# vgcreate vg0 /dev/mapper/lvmcrypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== LV Creation for BIOS/MBR ===&lt;br /&gt;
&lt;br /&gt;
This will create a 2GB swap partition and a root partition which takes up the rest of the space. This setup is for those who do not need to use the hibernate/suspend to disk state. If you do need to suspend to disk, create a swap partition slightly larger than the size of your RAM (change the size after &amp;lt;code&amp;gt;# lvcreate -L&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# lvcreate -L 2G vg0 -n swap&lt;br /&gt;
# lvcreate -l 100%FREE vg0 -n root&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The LVs created in the previous steps are automatically marked active. To verify, enter:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# lvscan&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== LV Creation for UEFI/GPT ===&lt;br /&gt;
&lt;br /&gt;
This will create a 2GB swap partition, a 2GB boot partition and a root partition which takes up the rest of the space. This setup is for those who do not need to use the hibernate/suspend to disk state. If you do need to suspend to disk, create a swap partition slightly larger than the size of your RAM (change the size after &amp;lt;code&amp;gt;# lvcreate -L&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# lvcreate -L 2G vg0 -n swap&lt;br /&gt;
# lvcreate -L 2G vg0 -n boot&lt;br /&gt;
# lvcreate -l 100%FREE vg0 -n root&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The LVs created in the previous steps are automatically marked active. To verify, enter:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# lvscan&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Creating and Mounting the File Systems ==&lt;br /&gt;
&lt;br /&gt;
Format the &amp;lt;code&amp;gt;root&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;boot&amp;lt;/code&amp;gt; LVs using the ext4 file system:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/vg0/root&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Format the swap LV:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkswap /dev/vg0/swap&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Before you can install Alpine Linux, you must mount the partitions and LVs. Mount the root LV to the &amp;lt;code&amp;gt;/mnt/&amp;lt;/code&amp;gt; directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t ext4 /dev/vg0/root /mnt/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next format your boot partition, create a mount point, then mount it:&lt;br /&gt;
&lt;br /&gt;
* If you&#039;re using BIOS and MBR:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/sda1&lt;br /&gt;
# mkdir -v /mnt/boot&lt;br /&gt;
# mount -t ext4 /dev/sda1 /mnt/boot&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* If you&#039;re using UEFI and GPT:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add dosfstools&lt;br /&gt;
# mkfs.fat -F32 /dev/sda1&lt;br /&gt;
# mkfs.ext4 /dev/vg0/boot&lt;br /&gt;
# mkdir -v /mnt/boot&lt;br /&gt;
# mount -t ext4 /dev/vg0/boot /mnt/boot&lt;br /&gt;
# mkdir -v /mnt/boot/efi&lt;br /&gt;
# mount -t vfat /dev/sda1 /mnt/boot/efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Lastly, activate your swap partition:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# swapon /dev/vg0/swap&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Installing Alpine Linux ==&lt;br /&gt;
&lt;br /&gt;
In this step you will install Alpine Linux in the &amp;lt;code&amp;gt;/mnt/&amp;lt;/code&amp;gt; directory, which contains the mounted file system structure:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# setup-disk -m sys /mnt/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The installer downloads the latest packages to install the base installation. Additionally, the installer automatically creates the entries for the mount points in {{Path|/etc/fstab}} file, which is currently mounted in the &amp;lt;code&amp;gt;/mnt/&amp;lt;/code&amp;gt; directory.&lt;br /&gt;
&lt;br /&gt;
{{Note|The automatic writing of the master boot record (MBR) fails in this step. Later, you&#039;ll manually write the MBR to the disk.}}&lt;br /&gt;
&lt;br /&gt;
The swap LV is not automatically added to the &amp;lt;code&amp;gt;fstab&amp;lt;/code&amp;gt; file. so we need to add the following line to the {{Path|/mnt/etc/fstab}} file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/dev/vg0/swap    swap    swap    defaults    0 0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit the {{Path|/mnt/etc/mkinitfs/mkinitfs.conf}} file and append the &amp;lt;code&amp;gt;cryptsetup&amp;lt;/code&amp;gt; module to the &amp;lt;code&amp;gt;features&amp;lt;/code&amp;gt; parameter:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;features=&amp;quot;... cryptsetup&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you are using GRUB with an encrypted &amp;lt;code&amp;gt;/boot&amp;lt;/code&amp;gt; you must add the &amp;lt;code&amp;gt;cryptkey&amp;lt;/code&amp;gt; feature so that Alpine can use a keyfile for decryption on boot.&lt;br /&gt;
&lt;br /&gt;
{{Note|Alpine Linux uses the &amp;lt;code&amp;gt;en-us&amp;lt;/code&amp;gt; keyboard mapping by default when prompting for the password to decrypt the partition at boot time. If you changed the keyboard mapping in the temporary environment and want to use it at the boot password prompt, be sure to add the &amp;lt;code&amp;gt;keymap&amp;lt;/code&amp;gt; feature to the list above.}}&lt;br /&gt;
&lt;br /&gt;
{{Note|Check the output of &amp;lt;code&amp;gt;mkinitfs -L&amp;lt;/code&amp;gt; and add the features necessary for your system to boot. You may need to add &amp;lt;code&amp;gt;kms&amp;lt;/code&amp;gt; in order to see a password prompt at boot. You may also need: &amp;lt;code&amp;gt;usb&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;lvm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ext4&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;nvme&amp;lt;/code&amp;gt;...}}&lt;br /&gt;
&lt;br /&gt;
Rebuild the initial RAM disk:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkinitfs -c /mnt/etc/mkinitfs/mkinitfs.conf -b /mnt/ $(ls /mnt/lib/modules/)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The command uses the settings from the &amp;lt;code&amp;gt;mkinitfs.conf&amp;lt;/code&amp;gt; file set in the &amp;lt;code&amp;gt;-c&amp;lt;/code&amp;gt; parameter to generate the RAM disk. The command is executed in the &amp;lt;code&amp;gt;/mnt/&amp;lt;/code&amp;gt; directory and the RAM disk is generated using the modules for the installed kernel. Without setting the kernel version using the &amp;lt;code&amp;gt;$(ls /mnt/lib/modules/&amp;lt;/code&amp;gt;) option, &amp;lt;code&amp;gt;mkinitfs&amp;lt;/code&amp;gt; tries to generate the RAM disk using the kernel version installed in the temporary environment, which can differ from the latest one installed by the &amp;lt;code&amp;gt;setup-disk&amp;lt;/code&amp;gt; utility.&lt;br /&gt;
&lt;br /&gt;
== Installing a bootloader ==&lt;br /&gt;
&lt;br /&gt;
To get the UUID of your storage device into a file for later use, run this command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# blkid -s UUID -o value /dev/sda2 &amp;gt; ~/uuid&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Tip|To easily read the UUID into a file so you don&#039;t have to type it manually, open the file in &amp;lt;code&amp;gt;vi&amp;lt;/code&amp;gt;, then type &amp;lt;code&amp;gt;:r /root/uuid&amp;lt;/code&amp;gt; to load the UUID onto a new line.}}&lt;br /&gt;
&lt;br /&gt;
=== Syslinux with BIOS ===&lt;br /&gt;
&lt;br /&gt;
Install the Syslinux package:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add syslinux&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit {{Path|/mnt/etc/update-extlinux.conf}} and append the following kernel options to the &amp;lt;code&amp;gt;default_kernel_opts&amp;lt;/code&amp;gt; parameter, replacing &amp;lt;UUID&amp;gt; with the UUID of &amp;lt;code&amp;gt;/dev/sda2&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;default_kernel_opts=&amp;quot;... cryptroot=UUID=&amp;lt;UUID of sda2&amp;gt; cryptdm=lvmcrypt&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;cryptroot&amp;lt;/code&amp;gt; parameter sets the ID of the device/partition that contains encrypted volumes, and the &amp;lt;code&amp;gt;cryptdm&amp;lt;/code&amp;gt; parameter uses the name of the mapping we have already configured a few lines above.&lt;br /&gt;
&lt;br /&gt;
We can also double check if &amp;lt;code&amp;gt;modules&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;root&amp;lt;/code&amp;gt; are set correctly, eg:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
modules=sd-mod,usb-storage,ext4,cryptsetup,keymap,cryptkey,kms,lvm&lt;br /&gt;
root=UUID=&amp;lt;UUID of /dev/mapper/vg0-root&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because the &amp;lt;code&amp;gt;update-extlinux&amp;lt;/code&amp;gt; utility operates only on the &amp;lt;code&amp;gt;/boot/&amp;lt;/code&amp;gt; directory, temporarily change the root to the &amp;lt;code&amp;gt;/mnt/&amp;lt;/code&amp;gt; directory and update the boot loader configuration:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# chroot /mnt/&lt;br /&gt;
# update-extlinux&lt;br /&gt;
# exit&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
: Because we didn&#039;t mount &amp;lt;code&amp;gt;/dev&amp;lt;/code&amp;gt; nor &amp;lt;code&amp;gt;/proc&amp;lt;/code&amp;gt; inside our &amp;lt;code&amp;gt;/mnt/&amp;lt;/code&amp;gt; chroot, some errors may occur when we run &amp;lt;code&amp;gt;update-extlinux&amp;lt;/code&amp;gt; command. But you can most likely ignore these.&lt;br /&gt;
&lt;br /&gt;
Write the MBR (without partition table) to the &amp;lt;code&amp;gt;/dev/sda&amp;lt;/code&amp;gt; device:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# dd bs=440 count=1 conv=notrunc if=/mnt/usr/share/syslinux/mbr.bin of=/dev/sda&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Grub with UEFI ===&lt;br /&gt;
&lt;br /&gt;
To avoid having to type your decryption password twice every boot (once for GRUB and once for Alpine), add a keyfile to your LUKS partition. The filename is important.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# touch /mnt/crypto_keyfile.bin&lt;br /&gt;
# chmod 600 /mnt/crypto_keyfile.bin&lt;br /&gt;
# dd bs=512 count=4 if=/dev/urandom of=/mnt/crypto_keyfile.bin&lt;br /&gt;
# cryptsetup luksAddKey /dev/sda2 /mnt/crypto_keyfile.bin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This keyfile is stored encrypted (it is in your LUKS partition), so its presence does not affect system security.&lt;br /&gt;
&lt;br /&gt;
Mount the required filesystems for the Grub EFI installer to the installation:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t proc /proc /mnt/proc&lt;br /&gt;
# mount --rbind /dev /mnt/dev&lt;br /&gt;
# mount --make-rslave /mnt/dev&lt;br /&gt;
# mount --rbind /sys /mnt/sys&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then run chroot:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# chroot /mnt&lt;br /&gt;
# source /etc/profile&lt;br /&gt;
# export PS1=&amp;quot;(chroot) $PS1&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Install &amp;lt;code&amp;gt;GRUB2&amp;lt;/code&amp;gt; for EFI and (optionally) remove syslinux:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add grub grub-efi efibootmgr&lt;br /&gt;
# apk del syslinux&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit {{Path|/etc/default/grub}} and add the following kernel options to the &amp;lt;code&amp;gt;GRUB_CMDLINE_LINUX_DEFAULT&amp;lt;/code&amp;gt; parameter, replacing &amp;lt;UUID&amp;gt; with the UUID of the encrypted partition (in this case, &amp;lt;code&amp;gt;/dev/sda2&amp;lt;/code&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cryptroot=UUID=&amp;lt;UUID&amp;gt; cryptdm=lvmcrypt cryptkey&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;cryptroot&amp;lt;/code&amp;gt; parameter sets the ID of the device/partition that contains encrypted volumes, and the &amp;lt;code&amp;gt;cryptdm&amp;lt;/code&amp;gt; parameter uses the name of the mapping we configured a few lines above.&lt;br /&gt;
The &amp;lt;code&amp;gt;cryptkey&amp;lt;/code&amp;gt; parameter indicates the existence of the file &amp;lt;code&amp;gt;/crypto_keyfile.bin&amp;lt;/code&amp;gt; you created previously.&lt;br /&gt;
&lt;br /&gt;
To enable GRUB to decrypt LUKS partitions and read LVM volumes add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_PRELOAD_MODULES=&amp;quot;luks cryptodisk part_gpt lvm&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If using Alpine v3.11 or later, &amp;lt;code&amp;gt;GRUB_ENABLE_CRYPTODISK=y&amp;lt;/code&amp;gt; should also be added to {{Path|/etc/default/grub}}.&lt;br /&gt;
&lt;br /&gt;
==== Luks1 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# (chroot) grub-install --target=x86_64-efi --efi-directory=/boot/efi&lt;br /&gt;
# (chroot) grub-mkconfig -o /boot/grub/grub.cfg&lt;br /&gt;
# (chroot) exit&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Luks2 ====&lt;br /&gt;
{{Note|The method is still experimental and you may lose your access to you OS at the next OS update}}&lt;br /&gt;
&lt;br /&gt;
Create a pre-config grub file: &amp;lt;code&amp;gt;/root/grub-pre.cfg&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set crypto_uuid=00001&lt;br /&gt;
cryptomount -u $crypto_uuid&lt;br /&gt;
set root=&#039;lvmid/00002/00003&#039;&lt;br /&gt;
set prefix=($root)/boot/grub&lt;br /&gt;
insmod normal&lt;br /&gt;
normal&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can find:&lt;br /&gt;
* 00001 with &amp;lt;code&amp;gt;blkid&amp;lt;/code&amp;gt; and find the uuid of your encrypted disk, i.e &amp;lt;code&amp;gt;/dev/nvme0n1p2&amp;lt;/code&amp;gt; remove hyphens from the UUID&lt;br /&gt;
* 00002 with &amp;lt;code&amp;gt;vgdisplay&amp;lt;/code&amp;gt; &amp;amp; VG UUID&lt;br /&gt;
* 00003 with &amp;lt;code&amp;gt;lvdisplay&amp;lt;/code&amp;gt; &amp;amp; LV UUID of the root partition /&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# (chroot) grub-mkimage -p /boot/grub -O x86_64-efi -c /root/grub-pre.cfg -o /tmp/grubx64.efi luks2 part_gpt cryptodisk lvm ext2 gcry_rijndael pbkdf2 gcry_sha512&lt;br /&gt;
# (chroot) install -v /tmp/grubx64.efi /boot/efi/EFI/grub/&lt;br /&gt;
# (chroot) grub-mkconfig -o /boot/grub/grub.cfg&lt;br /&gt;
# (chroot) exit&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Unmounting the Volumes and Partitions ==&lt;br /&gt;
&lt;br /&gt;
Unmount the &amp;lt;code&amp;gt;/mnt/&amp;lt;/code&amp;gt; partitions, deactivate the LVM volumes, close the LUKS partition and reboot:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cd&lt;br /&gt;
# umount -l /mnt/dev&lt;br /&gt;
# umount -l /mnt/proc&lt;br /&gt;
# umount -l /mnt/sys&lt;br /&gt;
# umount /mnt/boot/efi&lt;br /&gt;
# umount /mnt/boot&lt;br /&gt;
# swapoff /dev/vg0/swap&lt;br /&gt;
# umount /mnt&lt;br /&gt;
# vgchange -a n&lt;br /&gt;
# cryptsetup luksClose lvmcrypt&lt;br /&gt;
# reboot&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Troubleshooting =&lt;br /&gt;
&lt;br /&gt;
== General Procedure ==&lt;br /&gt;
&lt;br /&gt;
In case your system fails to boot, you can verify the settings and fix incorrect configurations.&lt;br /&gt;
&lt;br /&gt;
Reboot and do the steps in [[#Preparing_the_Temporary_Installation_Environment|Prepare the temporary installation environment]] again.&lt;br /&gt;
&lt;br /&gt;
Setup the LUKS partition and activate the LVs:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup luksOpen /dev/sda2&lt;br /&gt;
# vgchange -ay&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[#Creating_and_Mounting_the_File Systems|Mount the file systems]]&lt;br /&gt;
&lt;br /&gt;
Verify that you run the steps described in the [[#Installing_Alpine_Linux|Installing Alpine Linux]] section correctly. Update the configuration if necessary, unmount the partitions, then reboot.&lt;br /&gt;
&lt;br /&gt;
== System can&#039;t find boot device ==&lt;br /&gt;
&lt;br /&gt;
 * GPT partition table on a motherboard that runs BIOS instead of UEFI&lt;br /&gt;
 * running an MSDOS/MBR/Syslinux install without enabling legacy boot mode in the UEFI settings&lt;br /&gt;
&lt;br /&gt;
== I see &amp;quot;can not mount /sysroot&amp;quot; during boot ==&lt;br /&gt;
&lt;br /&gt;
 * incorrect device UUID&lt;br /&gt;
 * missing module in &amp;lt;code&amp;gt;/mnt/etc/update-extlinux.conf&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;/mnt/etc/mkinitfs/mkinitfs.conf&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== normal.mod not found ==&lt;br /&gt;
&lt;br /&gt;
 * re-install &amp;lt;code&amp;gt;grub-install --target=x86_64-efi&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Secure boot ==&lt;br /&gt;
&lt;br /&gt;
If secure boot complains of an unsigned bootloader, you can either disable it or adapt [https://wiki.archlinux.org/index.php/Secure_Boot this] guide to sign GRUB. If you&#039;re using Syslinux, then secure boot should be automatically disabled when you enable legacy boot mode.&lt;br /&gt;
&lt;br /&gt;
= Hardening =&lt;br /&gt;
&lt;br /&gt;
* To harden, you should disable DMA[https://old.iseclab.org/papers/acsac2012dma.pdf]{{dead link}} and install a hardened version of AES (TRESOR[https://www1.informatik.uni-erlangen.de/tresor] or Loop-Amnesia[http://moongate.ydns.eu/amnesia.html]) since by default cryptsetup with luks uses AES by default.&lt;br /&gt;
* Disable DMA in the BIOS and set the password for the BIOS according to Wikipedia.[https://en.wikipedia.org/wiki/DMA_attack]&lt;br /&gt;
* Blacklist kernel modules that use DMA and any unused expansion modules (FireWire, CardBus, ExpressCard, Thunderbolt, USB 3.0, PCI Express and hotplug modules) that use DMA.&lt;br /&gt;
&lt;br /&gt;
= Mounting additional encrypted filesystems at boot =&lt;br /&gt;
&lt;br /&gt;
If you would like other encrypted LUKS partitions to be decrypted and mounted automatically during boot, for example if you have &amp;lt;code&amp;gt;/home&amp;lt;/code&amp;gt; on a separate physical drive, some extra steps are required.&lt;br /&gt;
{{Note|This does not apply for volumes&lt;br /&gt;
within your main encrypted partition &amp;lt;code&amp;gt;/dev/sda2&amp;lt;/code&amp;gt;}}&lt;br /&gt;
For the purposes of these instructions we will say &amp;lt;code&amp;gt;/dev/sdb1&amp;lt;/code&amp;gt; contains an LVM volume that should be mounted at &amp;lt;code&amp;gt;/home&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Create a keyfile and add it to the LUKS partition:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# dd bs=512 count=4 if=/dev/urandom of=/root/crypt-home-keyfile.bin&lt;br /&gt;
# cryptsetup luksAddKey /dev/sdb1 /root/crypt-home-keyfile.bin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alpine, like Gentoo, uses the &amp;lt;code&amp;gt;dmcrypt&amp;lt;/code&amp;gt; service rather than &amp;lt;code&amp;gt;/etc/crypttab&amp;lt;/code&amp;gt;. Add the following lines to &amp;lt;code&amp;gt;/etc/conf.d/dmcrypt&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;target=crypt-home&lt;br /&gt;
source=&#039;/dev/sdb1&#039;&lt;br /&gt;
key=&#039;/root/crypt-home-keyfile.bin&#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add an entry to &amp;lt;code&amp;gt;/etc/fstab&amp;lt;/code&amp;gt;, changing &amp;lt;code&amp;gt;vg1&amp;lt;/code&amp;gt; to the name of your LVM volume group:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;/dev/vg1/home /home ext4 rw,relatime 0 2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Enable the dmcrypt and lvm services to start on boot:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# rc-update add dmcrypt boot&lt;br /&gt;
# rc-update add lvm boot&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After a reboot the partition should be decrypted and mounted automatically.&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
*[[Bootloaders]]&lt;br /&gt;
*[[Alpine setup scripts]]&lt;br /&gt;
*[[Installing on GPT LVM]]&lt;br /&gt;
*[[Setting up LVM on GPT-labeled disks]]&lt;br /&gt;
*[[Setting up disks manually]]&lt;br /&gt;
*https://wiki.gentoo.org/wiki/Syslinux&lt;br /&gt;
*https://wiki.gentoo.org/wiki/GRUB2&lt;br /&gt;
*https://wiki.archlinux.org/index.php/Syslinux&lt;br /&gt;
*https://wiki.archlinux.org/index.php/GRUB&lt;br /&gt;
*https://wiki.gentoo.org/wiki/Sakaki&#039;s_EFI_Install_Guide&lt;br /&gt;
*https://battlepenguin.com/tech/alpine-linux-with-full-disk-encryption/&lt;br /&gt;
*https://wiki.gentoo.org/wiki/Dm-crypt&lt;br /&gt;
&lt;br /&gt;
[[Category:Storage]]&lt;br /&gt;
[[Category:Security]]&lt;/div&gt;</summary>
		<author><name>Blt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22150</id>
		<title>Full disk encryption secure boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22150"/>
		<updated>2022-07-27T14:38:24Z</updated>

		<summary type="html">&lt;p&gt;Blt: typos&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Draft}}&lt;br /&gt;
&lt;br /&gt;
This guide is to explain step by step how to setup Alpine Linux with Full Disk Encryption using LUKS2, /boot &amp;amp; / together on the same partition, encrypted swap for hibernation on a nvme drive, with UEFI &amp;amp; Secure Boot.&lt;br /&gt;
The goal of this guide is to follow the KISS principle, lvm can be added, another file system can be used, multiple partitions for /home; /var/log etc.. can also be added, if running everything in one partition is not meeting your requirements.&lt;br /&gt;
&lt;br /&gt;
= Sequence of Events =&lt;br /&gt;
&lt;br /&gt;
* Installing packages&lt;br /&gt;
* Partitioning the disk&lt;br /&gt;
* Configuring LUKS&lt;br /&gt;
* Mounting points and File System&lt;br /&gt;
* Installing Alpine&lt;br /&gt;
* mkinitfs settings &amp;amp; modules&lt;br /&gt;
* Grub settings&lt;br /&gt;
* Configuring Secure Boot&lt;br /&gt;
&lt;br /&gt;
= Installing packages =&lt;br /&gt;
&lt;br /&gt;
To facilitate the partitioning we will use gdisk :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lsblk gptfdisk&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For encryption, we will use cryptsetup :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add cryptsetup&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For using and managing UEFI, multiple packages are needed :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efibootmgr e2fsprogs grub grub-efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Partitioning the disk =&lt;br /&gt;
&lt;br /&gt;
Let&#039;s assume the disk is /dev/nvme0n1 and no partition is present, we will create three partitions :&lt;br /&gt;
 &lt;br /&gt;
* one for UEFI&lt;br /&gt;
* one for /&lt;br /&gt;
* one for swap (hibernation)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# gdisk /dev/nvme0n1&lt;br /&gt;
GPT fdisk (gdisk) version 1.0.9.1&lt;br /&gt;
&lt;br /&gt;
Partition table scan:&lt;br /&gt;
  MBR: protective&lt;br /&gt;
  BSD: not present&lt;br /&gt;
  APM: not present&lt;br /&gt;
  GPT: present&lt;br /&gt;
&lt;br /&gt;
Found valid GPT with protective MBR; using GPT.&lt;br /&gt;
&lt;br /&gt;
Command (? for help): d&lt;br /&gt;
No partitions&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (1-128, default 1): &lt;br /&gt;
First sector (2048-1000215182, default = 2048) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (2048-1000215182, default = 1000214527) or {+-}size{KMGTP}: 512M&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): ef00&lt;br /&gt;
Changed type of partition to &#039;EFI system partition&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (2-128, default 2): &lt;br /&gt;
First sector (1048577-1000215182, default = 1050624) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (1050624-1000215182, default = 1000214527) or {+-}size{KMGTP}: 16G&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8200&lt;br /&gt;
Changed type of partition to &#039;Linux swap&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (3-128, default 3): &lt;br /&gt;
First sector (1048577-1000215182, default = 33556480) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (33556480-1000215182, default = 1000214527) or {+-}size{KMGTP}: &lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8309&lt;br /&gt;
Changed type of partition to &#039;Linux LUKS&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): w&lt;br /&gt;
&lt;br /&gt;
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING&lt;br /&gt;
PARTITIONS!!&lt;br /&gt;
&lt;br /&gt;
Do you want to proceed? (Y/N): Y&lt;br /&gt;
OK; writing new GUID partition table (GPT) to /dev/nvme0n1.&lt;br /&gt;
The operation has completed successfully.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring LUKS =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 5000 --use-random luksFormat /dev/nvme0n1p2&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p2 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p2: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&lt;br /&gt;
cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 5000 --use-random luksFormat /dev/nvme0n1p3&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p3 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p3: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Mounting points and File System =&lt;br /&gt;
&lt;br /&gt;
Open the LUKS partitiond we just created:&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup luksOpen /dev/nvme0n1p2 nvme0n1p2-crypt&lt;br /&gt;
# cryptsetup luksOpen /dev/nvme0n1p3 nvme0n1p3-crypt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create vfat file system for UEFI partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.vfat /dev/nvme0n1p1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for swap partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/mapper/nvme0n1p2-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for / partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/mapper/nvme0n1p3-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create mounting points and mount partitions :&lt;br /&gt;
Mount / partition to /mnt :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t ext4 /dev/mapper/nvme0n1p3-crypt /mnt&amp;lt;/pre&amp;gt;&lt;br /&gt;
Create /boot/efi:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /mnt/boot/efi -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
Mount UEFI partition to /mnt/boot/efi :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t vfat /dev/nvme0n1p1 /mnt/boot/efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
Activate SWAP:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkswap /dev/mapper/nvme0n1p2-crypt&lt;br /&gt;
# swapon /dev/mapper/nvme0n1p2-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk&lt;br /&gt;
NAME                MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINTS&lt;br /&gt;
nvme0n1             259:0    0 476.9G  0 disk  &lt;br /&gt;
├─nvme0n1p1         259:1    0   511M  0 part  /mnt/boot/efi&lt;br /&gt;
├─nvme0n1p2         259:2    0  15.5G  0 part  &lt;br /&gt;
│ └─nvme0n1p2-crypt 253:0    0  15.5G  0 crypt [SWAP]&lt;br /&gt;
└─nvme0n1p3         259:3    0 460.9G  0 part  &lt;br /&gt;
  └─nvme0n1p3-crypt 253:1    0 460.9G  0 crypt /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Installing Alpine =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# setup-disk -m sys /mnt/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= mkinitfs settings &amp;amp; modules =&lt;br /&gt;
Edit the /mnt/etc/mkinitfs/mkinitfs.conf file and append the cryptsetup module to the features parameter (keymap only needed if QWERTY is not used):&lt;br /&gt;
&amp;lt;pre&amp;gt;features=&amp;quot;...keymap cryptsetup&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Regenerate the initram:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkinitfs -c /mnt/etc/mkinitfs/mkinitfs.conf -b /mnt/ $(ls /mnt/lib/modules/)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Grub settings =&lt;br /&gt;
&lt;br /&gt;
Create a crypto_keyfile.bin to avoid typing the passphrase twice during the boot process (one for Grub partition, one for Alpine partition):&lt;br /&gt;
&amp;lt;pre&amp;gt;# touch /mnt/crypto_keyfile.bin&lt;br /&gt;
# chmod 600 /mnt/crypto_keyfile.bin&lt;br /&gt;
# dd bs=512 count=4 if=/dev/urandom of=/mnt/crypto_keyfile.bin&lt;br /&gt;
# cryptsetup luksAddKey /dev/nvme0n1p3 /mnt/crypto_keyfile.bin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, let&#039;s mount and chroot to our fresh installation:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t proc /proc /mnt/proc&lt;br /&gt;
# mount --rbind /dev /mnt/dev&lt;br /&gt;
# mount --make-rslave /mnt/dev&lt;br /&gt;
# mount --rbind /sys /mnt/sys&lt;br /&gt;
# chroot /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let&#039;s show the UUID of our partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk -f&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit /etc/default/grub and add a new line starting with GRUB_CMDLINE_LINUX parameter, replacing &amp;lt;UUID&amp;gt; with the UUID of the encrypted partition (in this case /dev/nvme0n1p3):&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_TIMEOUT=2&lt;br /&gt;
GRUB_DISABLE_SUBMENU=y&lt;br /&gt;
GRUB_DISABLE_RECOVERY=true&lt;br /&gt;
GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;cryptroot=UUID=XXXX cryptdm=nvme0n1p3-crypt cryptkey modules=sd-mod,usb-storage,ext4,nvme quiet rootfstype=ext4&amp;quot;&lt;br /&gt;
GRUB_PRELOAD_MODULES=&amp;quot;luks cryptodisk part_gpt ext4&amp;quot;&lt;br /&gt;
GRUB_ENABLE_CRYPTODISK=y&lt;br /&gt;
GRUB_DISABLE_OS_PROBER=y&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Re-install Grub:&lt;br /&gt;
&amp;lt;pre&amp;gt;# grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=AlpineLinux --modules=&amp;quot;luks2 part_gpt cryptodisk ext2 gcry_rijndael pbkdf2 gcry_sha512&amp;quot;&lt;br /&gt;
# grub-mkconfig -o /boot/grub/grub.cfg&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring Secure Boot =&lt;/div&gt;</summary>
		<author><name>Blt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22149</id>
		<title>Full disk encryption secure boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22149"/>
		<updated>2022-07-27T14:32:37Z</updated>

		<summary type="html">&lt;p&gt;Blt: typos&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Draft}}&lt;br /&gt;
&lt;br /&gt;
This guide is to explain step by step how to setup Alpine Linux with Full Disk Encryption using LUKS2, /boot &amp;amp; / together on the same partition, encrypted swap for hibernation on a nvme drive, with UEFI &amp;amp; Secure Boot.&lt;br /&gt;
The goal of this guide is to follow the KISS principle, lvm can be added, another file system can be used, multiple partitions for /home; /var/log etc.. can also be added, if running everything in one partition is not meeting your requirements.&lt;br /&gt;
&lt;br /&gt;
= Sequence of Events =&lt;br /&gt;
&lt;br /&gt;
* Installing packages&lt;br /&gt;
* Partitioning the disk&lt;br /&gt;
* Configuring LUKS&lt;br /&gt;
* Mounting points and File System&lt;br /&gt;
* Installing Alpine&lt;br /&gt;
* mkinitfs settings &amp;amp; modules&lt;br /&gt;
* Grub settings&lt;br /&gt;
* Configuring Secure Boot&lt;br /&gt;
&lt;br /&gt;
= Installing packages =&lt;br /&gt;
&lt;br /&gt;
To facilitate the partitioning we will use gdisk :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lsblk gptfdisk&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For encryption, we will use cryptsetup :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add cryptsetup&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For using and managing UEFI, multiple packages are needed :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efibootmgr e2fsprogs grub grub-efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Partitioning the disk =&lt;br /&gt;
&lt;br /&gt;
Let&#039;s assume the disk is /dev/nvme0n1 and no partition is present, we will create three partitions :&lt;br /&gt;
 &lt;br /&gt;
* one for UEFI&lt;br /&gt;
* one for /&lt;br /&gt;
* one for swap (hibernation)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# gdisk /dev/nvme0n1&lt;br /&gt;
GPT fdisk (gdisk) version 1.0.9.1&lt;br /&gt;
&lt;br /&gt;
Partition table scan:&lt;br /&gt;
  MBR: protective&lt;br /&gt;
  BSD: not present&lt;br /&gt;
  APM: not present&lt;br /&gt;
  GPT: present&lt;br /&gt;
&lt;br /&gt;
Found valid GPT with protective MBR; using GPT.&lt;br /&gt;
&lt;br /&gt;
Command (? for help): d&lt;br /&gt;
No partitions&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (1-128, default 1): &lt;br /&gt;
First sector (2048-1000215182, default = 2048) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (2048-1000215182, default = 1000214527) or {+-}size{KMGTP}: 512M&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): ef00&lt;br /&gt;
Changed type of partition to &#039;EFI system partition&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (2-128, default 2): &lt;br /&gt;
First sector (1048577-1000215182, default = 1050624) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (1050624-1000215182, default = 1000214527) or {+-}size{KMGTP}: 16G&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8200&lt;br /&gt;
Changed type of partition to &#039;Linux swap&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (3-128, default 3): &lt;br /&gt;
First sector (1048577-1000215182, default = 33556480) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (33556480-1000215182, default = 1000214527) or {+-}size{KMGTP}: &lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8309&lt;br /&gt;
Changed type of partition to &#039;Linux LUKS&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): w&lt;br /&gt;
&lt;br /&gt;
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING&lt;br /&gt;
PARTITIONS!!&lt;br /&gt;
&lt;br /&gt;
Do you want to proceed? (Y/N): Y&lt;br /&gt;
OK; writing new GUID partition table (GPT) to /dev/nvme0n1.&lt;br /&gt;
The operation has completed successfully.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring LUKS =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 5000 --use-random luksFormat /dev/nvme0n1p2&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p2 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p2: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&lt;br /&gt;
cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 5000 --use-random luksFormat /dev/nvme0n1p3&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p3 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p3: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Mounting points and File System =&lt;br /&gt;
&lt;br /&gt;
Open the LUKS partitiond we just created:&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup luksOpen /dev/nvme0n1p2 nvme0n1p2-crypt&lt;br /&gt;
# cryptsetup luksOpen /dev/nvme0n1p3 nvme0n1p3-crypt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create vfat file system for UEFI partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.vfat /dev/nvme0n1p1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for swap partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/mapper/nvme0n1p2-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for / partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/mapper/nvme0n1p3-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create mounting points and mount partitions :&lt;br /&gt;
Mount / partition to /mnt :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t ext4 /dev/mapper/nvme0n1p3-crypt /mnt&amp;lt;/pre&amp;gt;&lt;br /&gt;
Create /boot/efi:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /mnt/boot/efi -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
Mount UEFI partition to /mnt/boot/efi :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t vfat /dev/nvme0n1p1 /mnt/boot/efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
Activate SWAP:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkswap /dev/mapper/nvme0n1p2-crypt&lt;br /&gt;
# swapon /dev/mapper/nvme0n1p2-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk&lt;br /&gt;
NAME                MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINTS&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Installing Alpine =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# setup-disk -m sys /mnt/&lt;br /&gt;
MOUNTPOINT=/mnt setup-alpine&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= mkinitfs settings &amp;amp; modules =&lt;br /&gt;
Edit the /mnt/etc/mkinitfs/mkinitfs.conf file and append the cryptsetup module to the features parameter (keymap only needed if QWERTY is not used):&lt;br /&gt;
&amp;lt;pre&amp;gt;features=&amp;quot;... ext4 keymap cryptsetup&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Regenerate the initram:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkinitfs -c /mnt/etc/mkinitfs/mkinitfs.conf -b /mnt/ $(ls /mnt/lib/modules/)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Grub settings =&lt;br /&gt;
&lt;br /&gt;
Create a crypto_keyfile.bin to avoid typing the passphrase twice during the boot process (one for Grub partition, one for Alpine partition):&lt;br /&gt;
&amp;lt;pre&amp;gt;# touch /mnt/crypto_keyfile.bin&lt;br /&gt;
# chmod 600 /mnt/crypto_keyfile.bin&lt;br /&gt;
# dd bs=512 count=4 if=/dev/urandom of=/mnt/crypto_keyfile.bin&lt;br /&gt;
# cryptsetup luksAddKey /dev/nvme0n1p2 /mnt/crypto_keyfile.bin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, let&#039;s mount and chroot to our fresh installation:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t proc /proc /mnt/proc&lt;br /&gt;
# mount --rbind /dev /mnt/dev&lt;br /&gt;
# mount --make-rslave /mnt/dev&lt;br /&gt;
# mount --rbind /sys /mnt/sys&lt;br /&gt;
# chroot /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let&#039;s show the UUID of our partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk -f&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit /etc/default/grub and add a new line starting with GRUB_CMDLINE_LINUX parameter, replacing &amp;lt;UUID&amp;gt; with the UUID of the encrypted partition (in this case /dev/nvme0n1p2):&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_TIMEOUT=2&lt;br /&gt;
GRUB_DISABLE_SUBMENU=y&lt;br /&gt;
GRUB_DISABLE_RECOVERY=true&lt;br /&gt;
GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;cryptroot=UUID=XXXX cryptdm=nvme0n1p2-crypt cryptkey modules=sd-mod,usb-storage,ext4,nvme quiet rootfstype=ext4&amp;quot;&lt;br /&gt;
GRUB_PRELOAD_MODULES=&amp;quot;luks cryptodisk part_gpt ext4&amp;quot;&lt;br /&gt;
GRUB_ENABLE_CRYPTODISK=y&lt;br /&gt;
GRUB_DISABLE_OS_PROBER=y&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Re-install Grub:&lt;br /&gt;
&amp;lt;pre&amp;gt;# grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=AlpineLinux&lt;br /&gt;
# grub-mkconfig -o /boot/grub/grub.cfg&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring Secure Boot =&lt;/div&gt;</summary>
		<author><name>Blt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22147</id>
		<title>Full disk encryption secure boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22147"/>
		<updated>2022-07-27T14:25:05Z</updated>

		<summary type="html">&lt;p&gt;Blt: typos&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Draft}}&lt;br /&gt;
&lt;br /&gt;
This guide is to explain step by step how to setup Alpine Linux with Full Disk Encryption using LUKS2, /boot &amp;amp; / together on the same partition, encrypted swap for hibernation on a nvme drive, with UEFI &amp;amp; Secure Boot.&lt;br /&gt;
The goal of this guide is to follow the KISS principle, lvm can be added, another file system can be used, multiple partitions for /home; /var/log etc.. can also be added, if running everything in one partition is not meeting your requirements.&lt;br /&gt;
&lt;br /&gt;
= Sequence of Events =&lt;br /&gt;
&lt;br /&gt;
* Installing packages&lt;br /&gt;
* Partitioning the disk&lt;br /&gt;
* Configuring LUKS&lt;br /&gt;
* Mounting points and File System&lt;br /&gt;
* Installing Alpine&lt;br /&gt;
* mkinitfs settings &amp;amp; modules&lt;br /&gt;
* Grub settings&lt;br /&gt;
* Configuring Secure Boot&lt;br /&gt;
&lt;br /&gt;
= Installing packages =&lt;br /&gt;
&lt;br /&gt;
To facilitate the partitioning we will use gdisk :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lsblk gptfdisk&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For encryption, we will use cryptsetup :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add cryptsetup&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For using and managing UEFI, multiple packages are needed :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efibootmgr e2fsprogs grub grub-efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Partitioning the disk =&lt;br /&gt;
&lt;br /&gt;
Let&#039;s assume the disk is /dev/nvme0n1 and no partition is present, we will create three partitions :&lt;br /&gt;
 &lt;br /&gt;
* one for UEFI&lt;br /&gt;
* one for /&lt;br /&gt;
* one for swap (hibernation)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# gdisk /dev/nvme0n1&lt;br /&gt;
GPT fdisk (gdisk) version 1.0.9.1&lt;br /&gt;
&lt;br /&gt;
Partition table scan:&lt;br /&gt;
  MBR: protective&lt;br /&gt;
  BSD: not present&lt;br /&gt;
  APM: not present&lt;br /&gt;
  GPT: present&lt;br /&gt;
&lt;br /&gt;
Found valid GPT with protective MBR; using GPT.&lt;br /&gt;
&lt;br /&gt;
Command (? for help): d&lt;br /&gt;
No partitions&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (1-128, default 1): &lt;br /&gt;
First sector (2048-1000215182, default = 2048) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (2048-1000215182, default = 1000214527) or {+-}size{KMGTP}: 512M&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): ef00&lt;br /&gt;
Changed type of partition to &#039;EFI system partition&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (2-128, default 2): &lt;br /&gt;
First sector (1048577-1000215182, default = 1050624) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (1050624-1000215182, default = 1000214527) or {+-}size{KMGTP}: 16G&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8200&lt;br /&gt;
Changed type of partition to &#039;Linux swap&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (3-128, default 3): &lt;br /&gt;
First sector (1048577-1000215182, default = 33556480) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (33556480-1000215182, default = 1000214527) or {+-}size{KMGTP}: &lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8309&lt;br /&gt;
Changed type of partition to &#039;Linux LUKS&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): w&lt;br /&gt;
&lt;br /&gt;
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING&lt;br /&gt;
PARTITIONS!!&lt;br /&gt;
&lt;br /&gt;
Do you want to proceed? (Y/N): Y&lt;br /&gt;
OK; writing new GUID partition table (GPT) to /dev/nvme0n1.&lt;br /&gt;
The operation has completed successfully.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring LUKS =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 5000 --use-random luksFormat /dev/nvme0n1p2&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p2 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p2: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&lt;br /&gt;
cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 5000 --use-random luksFormat /dev/nvme0n1p3&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p3 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p3: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Mounting points and File System =&lt;br /&gt;
&lt;br /&gt;
Open the LUKS partitiond we just created:&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup luksOpen /dev/nvme0n1p2 nvme0n1p2-crypt&lt;br /&gt;
# cryptsetup luksOpen /dev/nvme0n1p3 nvme0n1p3-crypt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create vfat file system for UEFI partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.vfat /dev/nvme0n1p1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for / partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/mapper/nvme0n1p2-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for swap partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/mapper/nvme0n1p3-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create mounting points and mount partitions :&lt;br /&gt;
Mount / partition to /mnt :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t ext4 /dev/mapper/nvme0n1p3-crypt /mnt&amp;lt;/pre&amp;gt;&lt;br /&gt;
Create /boot/efi:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /mnt/boot/efi -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
Mount UEFI partition to /mnt/boot/efi :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t vfat /dev/nvme0n1p1 /mnt/boot/efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
Activate SWAP:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkswap /dev/mapper/nvme0n1p2-crypt&lt;br /&gt;
# swapon /dev/mapper/nvme0n1p2-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk&lt;br /&gt;
NAME                MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINTS&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Installing Alpine =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# setup-disk -m sys /mnt/&lt;br /&gt;
MOUNTPOINT=/mnt setup-alpine&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= mkinitfs settings &amp;amp; modules =&lt;br /&gt;
Edit the /mnt/etc/mkinitfs/mkinitfs.conf file and append the cryptsetup module to the features parameter (keymap only needed if QWERTY is not used):&lt;br /&gt;
&amp;lt;pre&amp;gt;features=&amp;quot;... ext4 keymap cryptsetup&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Regenerate the initram:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkinitfs -c /mnt/etc/mkinitfs/mkinitfs.conf -b /mnt/ $(ls /mnt/lib/modules/)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Grub settings =&lt;br /&gt;
&lt;br /&gt;
Create a crypto_keyfile.bin to avoid typing the passphrase twice during the boot process (one for Grub partition, one for Alpine partition):&lt;br /&gt;
&amp;lt;pre&amp;gt;# touch /mnt/crypto_keyfile.bin&lt;br /&gt;
# chmod 600 /mnt/crypto_keyfile.bin&lt;br /&gt;
# dd bs=512 count=4 if=/dev/urandom of=/mnt/crypto_keyfile.bin&lt;br /&gt;
# cryptsetup luksAddKey /dev/nvme0n1p2 /mnt/crypto_keyfile.bin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, let&#039;s mount and chroot to our fresh installation:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t proc /proc /mnt/proc&lt;br /&gt;
# mount --rbind /dev /mnt/dev&lt;br /&gt;
# mount --make-rslave /mnt/dev&lt;br /&gt;
# mount --rbind /sys /mnt/sys&lt;br /&gt;
# chroot /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let&#039;s show the UUID of our partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk -f&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit /etc/default/grub and add a new line starting with GRUB_CMDLINE_LINUX parameter, replacing &amp;lt;UUID&amp;gt; with the UUID of the encrypted partition (in this case /dev/nvme0n1p2):&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_TIMEOUT=2&lt;br /&gt;
GRUB_DISABLE_SUBMENU=y&lt;br /&gt;
GRUB_DISABLE_RECOVERY=true&lt;br /&gt;
GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;cryptroot=UUID=XXXX cryptdm=nvme0n1p2-crypt cryptkey modules=sd-mod,usb-storage,ext4,nvme quiet rootfstype=ext4&amp;quot;&lt;br /&gt;
GRUB_PRELOAD_MODULES=&amp;quot;luks cryptodisk part_gpt ext4&amp;quot;&lt;br /&gt;
GRUB_ENABLE_CRYPTODISK=y&lt;br /&gt;
GRUB_DISABLE_OS_PROBER=y&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Re-install Grub:&lt;br /&gt;
&amp;lt;pre&amp;gt;# grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=AlpineLinux&lt;br /&gt;
# grub-mkconfig -o /boot/grub/grub.cfg&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring Secure Boot =&lt;/div&gt;</summary>
		<author><name>Blt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22144</id>
		<title>Full disk encryption secure boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22144"/>
		<updated>2022-07-27T14:13:42Z</updated>

		<summary type="html">&lt;p&gt;Blt: updating Grub&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Draft}}&lt;br /&gt;
&lt;br /&gt;
This guide is to explain step by step how to setup Alpine Linux with Full Disk Encryption using LUKS2, /boot &amp;amp; / together on the same partition, encrypted swap for hibernation on a nvme drive, with UEFI &amp;amp; Secure Boot.&lt;br /&gt;
The goal of this guide is to follow the KISS principle, lvm can be added, another file system can be used, multiple partitions for /home; /var/log etc.. can also be added, if running everything in one partition is not meeting your requirements.&lt;br /&gt;
&lt;br /&gt;
= Sequence of Events =&lt;br /&gt;
&lt;br /&gt;
* Installing packages&lt;br /&gt;
* Partitioning the disk&lt;br /&gt;
* Configuring LUKS&lt;br /&gt;
* Mounting points and File System&lt;br /&gt;
* Installing Alpine&lt;br /&gt;
* mkinitfs settings &amp;amp; modules&lt;br /&gt;
* Grub settings&lt;br /&gt;
* Configuring Secure Boot&lt;br /&gt;
&lt;br /&gt;
= Installing packages =&lt;br /&gt;
&lt;br /&gt;
To facilitate the partitioning we will use gdisk :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lsblk gptfdisk&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For encryption, we will use cryptsetup :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add cryptsetup&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For using and managing UEFI, multiple packages are needed :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efibootmgr e2fsprogs grub grub-efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Partitioning the disk =&lt;br /&gt;
&lt;br /&gt;
Let&#039;s assume the disk is /dev/nvme0n1 and no partition is present, we will create three partitions :&lt;br /&gt;
 &lt;br /&gt;
* one for UEFI&lt;br /&gt;
* one for /&lt;br /&gt;
* one for swap (hibernation)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# gdisk /dev/nvme0n1&lt;br /&gt;
GPT fdisk (gdisk) version 1.0.9.1&lt;br /&gt;
&lt;br /&gt;
Partition table scan:&lt;br /&gt;
  MBR: protective&lt;br /&gt;
  BSD: not present&lt;br /&gt;
  APM: not present&lt;br /&gt;
  GPT: present&lt;br /&gt;
&lt;br /&gt;
Found valid GPT with protective MBR; using GPT.&lt;br /&gt;
&lt;br /&gt;
Command (? for help): d&lt;br /&gt;
No partitions&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (1-128, default 1): &lt;br /&gt;
First sector (2048-1000215182, default = 2048) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (2048-1000215182, default = 1000214527) or {+-}size{KMGTP}: 512M&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): ef00&lt;br /&gt;
Changed type of partition to &#039;EFI system partition&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (2-128, default 2): &lt;br /&gt;
First sector (1048577-1000215182, default = 1050624) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (1050624-1000215182, default = 1000214527) or {+-}size{KMGTP}: 16G&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8200&lt;br /&gt;
Changed type of partition to &#039;Linux swap&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (3-128, default 3): &lt;br /&gt;
First sector (1048577-1000215182, default = 33556480) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (33556480-1000215182, default = 1000214527) or {+-}size{KMGTP}: &lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8309&lt;br /&gt;
Changed type of partition to &#039;Linux LUKS&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): w&lt;br /&gt;
&lt;br /&gt;
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING&lt;br /&gt;
PARTITIONS!!&lt;br /&gt;
&lt;br /&gt;
Do you want to proceed? (Y/N): Y&lt;br /&gt;
OK; writing new GUID partition table (GPT) to /dev/nvme0n1.&lt;br /&gt;
The operation has completed successfully.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring LUKS =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 5000 --use-random luksFormat /dev/nvme0n1p2&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p2 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p2: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&lt;br /&gt;
cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 5000 --use-random luksFormat /dev/nvme0n1p3&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p3 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p3: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Mounting points and File System =&lt;br /&gt;
&lt;br /&gt;
Open the LUKS partitiond we just created:&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup luksOpen /dev/nvme0n1p2 nvme0n1p2-crypt&lt;br /&gt;
# cryptsetup luksOpen /dev/nvme0n1p3 nvme0n1p3-crypt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create vfat file system for UEFI partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.vfat /dev/nvme0n1p1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for / partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/mapper/nvme0n1p2-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for swap partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/mapper/nvme0n1p3-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create mounting points and mount partitions :&lt;br /&gt;
Mount / partition to /mnt :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t ext4 /dev/mapper/nvme0n1p2-crypt /mnt&amp;lt;/pre&amp;gt;&lt;br /&gt;
Create /boot/efi:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /mnt/boot/efi -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
Mount UEFI partition to /mnt/boot/efi :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t vfat /dev/nvme0n1p1 /mnt/boot/efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
Activate SWAP:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkswap /dev/mapper/nvme0n1p3-crypt&lt;br /&gt;
# swapon /dev/mapper/nvme0n1p3-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk&lt;br /&gt;
NAME                MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINTS&lt;br /&gt;
loop0                 7:0    0 105.2M  1 loop  /.modloop&lt;br /&gt;
sda                   8:0    1   7.6G  0 disk  /media/sda&lt;br /&gt;
├─sda1                8:1    1   148M  0 part  &lt;br /&gt;
└─sda2                8:2    1   1.4M  0 part  &lt;br /&gt;
nvme0n1             259:0    0 476.9G  0 disk  &lt;br /&gt;
├─nvme0n1p1         259:1    0   511M  0 part  /mnt/boot/efi&lt;br /&gt;
├─nvme0n1p2         259:2    0  15.5G  0 part  &lt;br /&gt;
│ └─nvme0n1p2-crypt 253:0    0  15.5G  0 crypt /mnt&lt;br /&gt;
└─nvme0n1p3         259:3    0 460.9G  0 part  &lt;br /&gt;
  └─nvme0n1p3-crypt 253:1    0 460.9G  0 crypt [SWAP]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Installing Alpine =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# setup-disk -m sys /mnt/&lt;br /&gt;
MOUNTPOINT=/mnt setup-alpine&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= mkinitfs settings &amp;amp; modules =&lt;br /&gt;
Edit the /mnt/etc/mkinitfs/mkinitfs.conf file and append the cryptsetup module to the features parameter (keymap only needed if QWERTY is not used):&lt;br /&gt;
&amp;lt;pre&amp;gt;features=&amp;quot;... ext4 keymap cryptsetup&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Regenerate the initram:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkinitfs -c /mnt/etc/mkinitfs/mkinitfs.conf -b /mnt/ $(ls /mnt/lib/modules/)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Grub settings =&lt;br /&gt;
&lt;br /&gt;
Create a crypto_keyfile.bin to avoid typing the passphrase twice during the boot process (one for Grub partition, one for Alpine partition):&lt;br /&gt;
&amp;lt;pre&amp;gt;# touch /mnt/crypto_keyfile.bin&lt;br /&gt;
# chmod 600 /mnt/crypto_keyfile.bin&lt;br /&gt;
# dd bs=512 count=4 if=/dev/urandom of=/mnt/crypto_keyfile.bin&lt;br /&gt;
# cryptsetup luksAddKey /dev/nvme0n1p2 /mnt/crypto_keyfile.bin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, let&#039;s mount and chroot to our fresh installation:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t proc /proc /mnt/proc&lt;br /&gt;
# mount --rbind /dev /mnt/dev&lt;br /&gt;
# mount --make-rslave /mnt/dev&lt;br /&gt;
# mount --rbind /sys /mnt/sys&lt;br /&gt;
# chroot /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let&#039;s show the UUID of our partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk -f&lt;br /&gt;
nvme0n1                                                                                                            &lt;br /&gt;
├─nvme0n1p1 vfat 62E0-E4C0 509.7M 0% /boot/efi&lt;br /&gt;
├─nvme0n1p2 crypto_LUKS 275836d9-05af-4e1a-bce5-335ef3bcd6e8                &lt;br /&gt;
│ └─nvme0n1p2-crypt ext4 9bed7992-81cc-4126-8bbd-4e724dbb7bdd 13.9G     3% /&lt;br /&gt;
└─nvme0n1p3 crypto_LUKS 67eae09f-f533-4bfa-b874-e17016929138                &lt;br /&gt;
  └─nvme0n1p3-crypt swap fcb8594e-2409-4365-bf0b-0199c3acf1c6                &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit /etc/default/grub and add a new line starting with GRUB_CMDLINE_LINUX parameter, replacing &amp;lt;UUID&amp;gt; with the UUID of the encrypted partition (in this case /dev/nvme0n1p2):&lt;br /&gt;
&amp;lt;pre&amp;gt;GRUB_TIMEOUT=2&lt;br /&gt;
GRUB_DISABLE_SUBMENU=y&lt;br /&gt;
GRUB_DISABLE_RECOVERY=true&lt;br /&gt;
GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;cryptroot=UUID=275836d9-05af-4e1a-bce5-335ef3bcd6e8 cryptdm=nvme0n1p2-crypt cryptkey modules=sd-mod,usb-storage,ext4,nvme quiet rootfstype=ext4&amp;quot;&lt;br /&gt;
GRUB_PRELOAD_MODULES=&amp;quot;luks cryptodisk part_gpt ext4&amp;quot;&lt;br /&gt;
GRUB_ENABLE_CRYPTODISK=y&lt;br /&gt;
GRUB_DISABLE_OS_PROBER=y&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Re-install Grub:&lt;br /&gt;
&amp;lt;pre&amp;gt;# grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=AlpineLinux&lt;br /&gt;
# grub-mkconfig -o /boot/grub/grub.cfg&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring Secure Boot =&lt;/div&gt;</summary>
		<author><name>Blt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22143</id>
		<title>Full disk encryption secure boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22143"/>
		<updated>2022-07-27T09:02:39Z</updated>

		<summary type="html">&lt;p&gt;Blt: Update Grub UUID&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Draft}}&lt;br /&gt;
&lt;br /&gt;
This guide is to explain step by step how to setup Alpine Linux with Full Disk Encryption using LUKS2, /boot &amp;amp; / together on the same partition, encrypted swap for hibernation on a nvme drive, with UEFI &amp;amp; Secure Boot.&lt;br /&gt;
The goal of this guide is to follow the KISS principle, lvm can be added, another file system can be used, multiple partitions for /home; /var/log etc.. can also be added, if running everything in one partition is not meeting your requirements.&lt;br /&gt;
&lt;br /&gt;
= Sequence of Events =&lt;br /&gt;
&lt;br /&gt;
* Installing packages&lt;br /&gt;
* Partitioning the disk&lt;br /&gt;
* Configuring LUKS&lt;br /&gt;
* Mounting points and File System&lt;br /&gt;
* Installing Alpine&lt;br /&gt;
* mkinitfs settings &amp;amp; modules&lt;br /&gt;
* Grub settings&lt;br /&gt;
* Configuring Secure Boot&lt;br /&gt;
&lt;br /&gt;
= Installing packages =&lt;br /&gt;
&lt;br /&gt;
To facilitate the partitioning we will use gdisk :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lsblk gptfdisk&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For encryption, we will use cryptsetup :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add cryptsetup&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For using and managing UEFI, multiple packages are needed :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efibootmgr e2fsprogs grub grub-efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Partitioning the disk =&lt;br /&gt;
&lt;br /&gt;
Let&#039;s assume the disk is /dev/nvme0n1 and no partition is present, we will create three partitions :&lt;br /&gt;
 &lt;br /&gt;
* one for UEFI&lt;br /&gt;
* one for /&lt;br /&gt;
* one for swap (hibernation)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# gdisk /dev/nvme0n1&lt;br /&gt;
GPT fdisk (gdisk) version 1.0.9.1&lt;br /&gt;
&lt;br /&gt;
Partition table scan:&lt;br /&gt;
  MBR: protective&lt;br /&gt;
  BSD: not present&lt;br /&gt;
  APM: not present&lt;br /&gt;
  GPT: present&lt;br /&gt;
&lt;br /&gt;
Found valid GPT with protective MBR; using GPT.&lt;br /&gt;
&lt;br /&gt;
Command (? for help): d&lt;br /&gt;
No partitions&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (1-128, default 1): &lt;br /&gt;
First sector (2048-1000215182, default = 2048) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (2048-1000215182, default = 1000214527) or {+-}size{KMGTP}: 512M&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): ef00&lt;br /&gt;
Changed type of partition to &#039;EFI system partition&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (2-128, default 2): &lt;br /&gt;
First sector (1048577-1000215182, default = 1050624) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (1050624-1000215182, default = 1000214527) or {+-}size{KMGTP}: 16G&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8200&lt;br /&gt;
Changed type of partition to &#039;Linux swap&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (3-128, default 3): &lt;br /&gt;
First sector (1048577-1000215182, default = 33556480) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (33556480-1000215182, default = 1000214527) or {+-}size{KMGTP}: &lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8309&lt;br /&gt;
Changed type of partition to &#039;Linux LUKS&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): w&lt;br /&gt;
&lt;br /&gt;
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING&lt;br /&gt;
PARTITIONS!!&lt;br /&gt;
&lt;br /&gt;
Do you want to proceed? (Y/N): Y&lt;br /&gt;
OK; writing new GUID partition table (GPT) to /dev/nvme0n1.&lt;br /&gt;
The operation has completed successfully.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring LUKS =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 5000 --use-random luksFormat /dev/nvme0n1p2&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p2 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p2: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&lt;br /&gt;
cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 5000 --use-random luksFormat /dev/nvme0n1p3&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p3 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p3: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Mounting points and File System =&lt;br /&gt;
&lt;br /&gt;
Open the LUKS partitiond we just created:&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup luksOpen /dev/nvme0n1p2 nvme0n1p2-crypt&lt;br /&gt;
# cryptsetup luksOpen /dev/nvme0n1p3 nvme0n1p3-crypt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create vfat file system for UEFI partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.vfat /dev/nvme0n1p1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for / partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/mapper/nvme0n1p2-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for swap partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/mapper/nvme0n1p3-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create mounting points and mount partitions :&lt;br /&gt;
Mount / partition to /mnt :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t ext4 /dev/mapper/nvme0n1p2-crypt /mnt&amp;lt;/pre&amp;gt;&lt;br /&gt;
Create /boot/efi:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /mnt/boot/efi -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
Mount UEFI partition to /mnt/boot/efi :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t vfat /dev/nvme0n1p1 /mnt/boot/efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
Activate SWAP:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkswap /dev/mapper/nvme0n1p3-crypt&lt;br /&gt;
# swapon /dev/mapper/nvme0n1p3-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk&lt;br /&gt;
NAME                MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINTS&lt;br /&gt;
loop0                 7:0    0 105.2M  1 loop  /.modloop&lt;br /&gt;
sda                   8:0    1   7.6G  0 disk  /media/sda&lt;br /&gt;
├─sda1                8:1    1   148M  0 part  &lt;br /&gt;
└─sda2                8:2    1   1.4M  0 part  &lt;br /&gt;
nvme0n1             259:0    0 476.9G  0 disk  &lt;br /&gt;
├─nvme0n1p1         259:1    0   511M  0 part  /mnt/boot/efi&lt;br /&gt;
├─nvme0n1p2         259:2    0  15.5G  0 part  &lt;br /&gt;
│ └─nvme0n1p2-crypt 253:0    0  15.5G  0 crypt /mnt&lt;br /&gt;
└─nvme0n1p3         259:3    0 460.9G  0 part  &lt;br /&gt;
  └─nvme0n1p3-crypt 253:1    0 460.9G  0 crypt [SWAP]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Installing Alpine =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# setup-disk -m sys /mnt/&lt;br /&gt;
MOUNTPOINT=/mnt setup-alpine&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= mkinitfs settings &amp;amp; modules =&lt;br /&gt;
Edit the /mnt/etc/mkinitfs/mkinitfs.conf file and append the cryptsetup module to the features parameter:&lt;br /&gt;
&amp;lt;pre&amp;gt; features=&amp;quot;... cryptsetup&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Regenerate the initram:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkinitfs -c /mnt/etc/mkinitfs/mkinitfs.conf -b /mnt/ $(ls /mnt/lib/modules/)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Grub settings =&lt;br /&gt;
&lt;br /&gt;
Create a crypto_keyfile.bin to avoid typing the passphrase twice during the boot process (one for Grub partition, one for Alpine partition):&lt;br /&gt;
&amp;lt;pre&amp;gt; # touch /mnt/crypto_keyfile.bin&lt;br /&gt;
# chmod 600 /mnt/crypto_keyfile.bin&lt;br /&gt;
# dd bs=512 count=4 if=/dev/urandom of=/mnt/crypto_keyfile.bin&lt;br /&gt;
# cryptsetup luksAddKey /dev/nvme0n1p2 /mnt/crypto_keyfile.bin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, let&#039;s mount and chroot to our fresh installation:&lt;br /&gt;
&amp;lt;pre&amp;gt; # mount -t proc /proc /mnt/proc&lt;br /&gt;
# mount --rbind /dev /mnt/dev&lt;br /&gt;
# mount --make-rslave /mnt/dev&lt;br /&gt;
# mount --rbind /sys /mnt/sys&lt;br /&gt;
# chroot /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let&#039;s show the UUID of our partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt; # lsblk -f&lt;br /&gt;
nvme0n1                                                                                                            &lt;br /&gt;
├─nvme0n1p1 vfat 62E0-E4C0 509.7M 0% /boot/efi&lt;br /&gt;
├─nvme0n1p2 crypto_LUKS 275836d9-05af-4e1a-bce5-335ef3bcd6e8                &lt;br /&gt;
│ └─nvme0n1p2-crypt ext4 9bed7992-81cc-4126-8bbd-4e724dbb7bdd 13.9G     3% /&lt;br /&gt;
└─nvme0n1p3 crypto_LUKS 67eae09f-f533-4bfa-b874-e17016929138                &lt;br /&gt;
  └─nvme0n1p3-crypt swap fcb8594e-2409-4365-bf0b-0199c3acf1c6                &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit /etc/default/grub and add a new line starting with GRUB_CMDLINE_LINUX parameter, replacing &amp;lt;UUID&amp;gt; with the UUID of the encrypted partition (in this case /dev/nvme0n1p2):&lt;br /&gt;
&amp;lt;pre&amp;gt; GRUB_CMDLINE_LINUX=&amp;quot;cryptroot=UUID=275836d9-05af-4e1a-bce5-335ef3bcd6e8=nvme0n1p2-crypt:allow-discards cryptkey&amp;quot;&lt;br /&gt;
GRUB_PRELOAD_MODULES=&amp;quot;luks cryptodisk part_gpt&amp;quot;&lt;br /&gt;
GRUB_ENABLE_CRYPTODISK=y&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Re-install Grub:&lt;br /&gt;
&amp;lt;pre&amp;gt; # grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=AlpineLinux&lt;br /&gt;
# grub-mkconfig -o /boot/grub/grub.cfg&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring Secure Boot =&lt;/div&gt;</summary>
		<author><name>Blt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22142</id>
		<title>Full disk encryption secure boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22142"/>
		<updated>2022-07-27T07:58:07Z</updated>

		<summary type="html">&lt;p&gt;Blt: Format&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Draft}}&lt;br /&gt;
&lt;br /&gt;
This guide is to explain step by step how to setup Alpine Linux with Full Disk Encryption using LUKS2, /boot &amp;amp; / together on the same partition, encrypted swap for hibernation on a nvme drive, with UEFI &amp;amp; Secure Boot.&lt;br /&gt;
The goal of this guide is to follow the KISS principle, lvm can be added, another file system can be used, multiple partitions for /home; /var/log etc.. can also be added, if running everything in one partition is not meeting your requirements.&lt;br /&gt;
&lt;br /&gt;
= Sequence of Events =&lt;br /&gt;
&lt;br /&gt;
* Installing packages&lt;br /&gt;
* Partitioning the disk&lt;br /&gt;
* Configuring LUKS&lt;br /&gt;
* Mounting points and File System&lt;br /&gt;
* Installing Alpine&lt;br /&gt;
* mkinitfs settings &amp;amp; modules&lt;br /&gt;
* Grub settings&lt;br /&gt;
* Configuring Secure Boot&lt;br /&gt;
&lt;br /&gt;
= Installing packages =&lt;br /&gt;
&lt;br /&gt;
To facilitate the partitioning we will use gdisk :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lsblk gptfdisk&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For encryption, we will use cryptsetup :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add cryptsetup&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For using and managing UEFI, multiple packages are needed :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efibootmgr e2fsprogs grub grub-efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Partitioning the disk =&lt;br /&gt;
&lt;br /&gt;
Let&#039;s assume the disk is /dev/nvme0n1 and no partition is present, we will create three partitions :&lt;br /&gt;
 &lt;br /&gt;
* one for UEFI&lt;br /&gt;
* one for /&lt;br /&gt;
* one for swap (hibernation)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# gdisk /dev/nvme0n1&lt;br /&gt;
GPT fdisk (gdisk) version 1.0.9.1&lt;br /&gt;
&lt;br /&gt;
Partition table scan:&lt;br /&gt;
  MBR: protective&lt;br /&gt;
  BSD: not present&lt;br /&gt;
  APM: not present&lt;br /&gt;
  GPT: present&lt;br /&gt;
&lt;br /&gt;
Found valid GPT with protective MBR; using GPT.&lt;br /&gt;
&lt;br /&gt;
Command (? for help): d&lt;br /&gt;
No partitions&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (1-128, default 1): &lt;br /&gt;
First sector (2048-1000215182, default = 2048) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (2048-1000215182, default = 1000214527) or {+-}size{KMGTP}: 512M&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): ef00&lt;br /&gt;
Changed type of partition to &#039;EFI system partition&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (2-128, default 2): &lt;br /&gt;
First sector (1048577-1000215182, default = 1050624) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (1050624-1000215182, default = 1000214527) or {+-}size{KMGTP}: 16G&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8200&lt;br /&gt;
Changed type of partition to &#039;Linux swap&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (3-128, default 3): &lt;br /&gt;
First sector (1048577-1000215182, default = 33556480) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (33556480-1000215182, default = 1000214527) or {+-}size{KMGTP}: &lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8309&lt;br /&gt;
Changed type of partition to &#039;Linux LUKS&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): w&lt;br /&gt;
&lt;br /&gt;
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING&lt;br /&gt;
PARTITIONS!!&lt;br /&gt;
&lt;br /&gt;
Do you want to proceed? (Y/N): Y&lt;br /&gt;
OK; writing new GUID partition table (GPT) to /dev/nvme0n1.&lt;br /&gt;
The operation has completed successfully.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring LUKS =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 5000 --use-random luksFormat /dev/nvme0n1p2&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p2 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p2: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&lt;br /&gt;
cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 5000 --use-random luksFormat /dev/nvme0n1p3&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p3 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p3: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Mounting points and File System =&lt;br /&gt;
&lt;br /&gt;
Open the LUKS partitiond we just created:&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup luksOpen /dev/nvme0n1p2 nvme0n1p2-crypt&lt;br /&gt;
# cryptsetup luksOpen /dev/nvme0n1p3 nvme0n1p3-crypt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create vfat file system for UEFI partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.vfat /dev/nvme0n1p1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for / partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/mapper/nvme0n1p2-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for swap partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/mapper/nvme0n1p3-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create mounting points and mount partitions :&lt;br /&gt;
Mount / partition to /mnt :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t ext4 /dev/mapper/nvme0n1p2-crypt /mnt&amp;lt;/pre&amp;gt;&lt;br /&gt;
Create /boot/efi:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /mnt/boot/efi -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
Mount UEFI partition to /mnt/boot/efi :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t vfat /dev/nvme0n1p1 /mnt/boot/efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
Activate SWAP:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkswap /dev/mapper/nvme0n1p3-crypt&lt;br /&gt;
# swapon /dev/mapper/nvme0n1p3-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk&lt;br /&gt;
NAME                MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINTS&lt;br /&gt;
loop0                 7:0    0 105.2M  1 loop  /.modloop&lt;br /&gt;
sda                   8:0    1   7.6G  0 disk  /media/sda&lt;br /&gt;
├─sda1                8:1    1   148M  0 part  &lt;br /&gt;
└─sda2                8:2    1   1.4M  0 part  &lt;br /&gt;
nvme0n1             259:0    0 476.9G  0 disk  &lt;br /&gt;
├─nvme0n1p1         259:1    0   511M  0 part  /mnt/boot/efi&lt;br /&gt;
├─nvme0n1p2         259:2    0  15.5G  0 part  &lt;br /&gt;
│ └─nvme0n1p2-crypt 253:0    0  15.5G  0 crypt /mnt&lt;br /&gt;
└─nvme0n1p3         259:3    0 460.9G  0 part  &lt;br /&gt;
  └─nvme0n1p3-crypt 253:1    0 460.9G  0 crypt [SWAP]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Installing Alpine =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# setup-disk -m sys /mnt/&lt;br /&gt;
MOUNTPOINT=/mnt setup-alpine&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= mkinitfs settings &amp;amp; modules =&lt;br /&gt;
Edit the /mnt/etc/mkinitfs/mkinitfs.conf file and append the cryptsetup module to the features parameter:&lt;br /&gt;
&amp;lt;pre&amp;gt; features=&amp;quot;... cryptsetup&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Regenerate the initram:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkinitfs -c /mnt/etc/mkinitfs/mkinitfs.conf -b /mnt/ $(ls /mnt/lib/modules/)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Grub settings =&lt;br /&gt;
&lt;br /&gt;
Create a crypto_keyfile.bin to avoid typing the passphrase twice during the boot process (one for Grub partition, one for Alpine partition):&lt;br /&gt;
&amp;lt;pre&amp;gt; # touch /mnt/crypto_keyfile.bin&lt;br /&gt;
# chmod 600 /mnt/crypto_keyfile.bin&lt;br /&gt;
# dd bs=512 count=4 if=/dev/urandom of=/mnt/crypto_keyfile.bin&lt;br /&gt;
# cryptsetup luksAddKey /dev/nvme0n1p2 /mnt/crypto_keyfile.bin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, let&#039;s mount and chroot to our fresh installation:&lt;br /&gt;
&amp;lt;pre&amp;gt; # mount -t proc /proc /mnt/proc&lt;br /&gt;
# mount --rbind /dev /mnt/dev&lt;br /&gt;
# mount --make-rslave /mnt/dev&lt;br /&gt;
# mount --rbind /sys /mnt/sys&lt;br /&gt;
# chroot /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let&#039;s show the UUID of our partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt; # lsblk -f&lt;br /&gt;
nvme0n1                                                                                                            &lt;br /&gt;
├─nvme0n1p1 vfat 62E0-E4C0 509.7M 0% /boot/efi&lt;br /&gt;
├─nvme0n1p2 crypto_LUKS 275836d9-05af-4e1a-bce5-335ef3bcd6e8                &lt;br /&gt;
│ └─nvme0n1p2-crypt ext4 9bed7992-81cc-4126-8bbd-4e724dbb7bdd 13.9G     3% /&lt;br /&gt;
└─nvme0n1p3 crypto_LUKS 67eae09f-f533-4bfa-b874-e17016929138                &lt;br /&gt;
  └─nvme0n1p3-crypt swap fcb8594e-2409-4365-bf0b-0199c3acf1c6                &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit /etc/default/grub and add a new line starting with GRUB_CMDLINE_LINUX parameter, replacing &amp;lt;UUID&amp;gt; with the UUID of the encrypted partition (in this case /dev/nvme0n1p2):&lt;br /&gt;
&amp;lt;pre&amp;gt; GRUB_CMDLINE_LINUX=&amp;quot;cryptroot=/dev/nvme0n1p2:nvme0n1p2-crypt:allow-discards cryptkey&amp;quot;&lt;br /&gt;
GRUB_PRELOAD_MODULES=&amp;quot;luks cryptodisk part_gpt&amp;quot;&lt;br /&gt;
GRUB_ENABLE_CRYPTODISK=y&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Re-install Grub:&lt;br /&gt;
&amp;lt;pre&amp;gt; # grub-install --target=x86_64-efi --efi-directory=/boot/efi&lt;br /&gt;
# grub-mkconfig -o /boot/grub/grub.cfg&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring Secure Boot =&lt;/div&gt;</summary>
		<author><name>Blt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22141</id>
		<title>Full disk encryption secure boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22141"/>
		<updated>2022-07-27T07:56:29Z</updated>

		<summary type="html">&lt;p&gt;Blt: Adding mkinitfs and Grub&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Draft}}&lt;br /&gt;
&lt;br /&gt;
This guide is to explain step by step how to setup Alpine Linux with Full Disk Encryption using LUKS2, /boot &amp;amp; / together on the same partition, encrypted swap for hibernation on a nvme drive, with UEFI &amp;amp; Secure Boot.&lt;br /&gt;
The goal of this guide is to follow the KISS principle, lvm can be added, another file system can be used, multiple partitions for /home; /var/log etc.. can also be added, if running everything in one partition is not meeting your requirements.&lt;br /&gt;
&lt;br /&gt;
= Sequence of Events =&lt;br /&gt;
&lt;br /&gt;
* Installing packages&lt;br /&gt;
* Partitioning the disk&lt;br /&gt;
* Configuring LUKS&lt;br /&gt;
* Mounting points and File System&lt;br /&gt;
* Installing Alpine&lt;br /&gt;
* mkinitfs settings &amp;amp; modules&lt;br /&gt;
* Grub settings&lt;br /&gt;
* Configuring Secure Boot&lt;br /&gt;
&lt;br /&gt;
= Installing packages =&lt;br /&gt;
&lt;br /&gt;
To facilitate the partitioning we will use gdisk :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lsblk gptfdisk&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For encryption, we will use cryptsetup :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add cryptsetup&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For using and managing UEFI, multiple packages are needed :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add efibootmgr e2fsprogs grub grub-efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Partitioning the disk =&lt;br /&gt;
&lt;br /&gt;
Let&#039;s assume the disk is /dev/nvme0n1 and no partition is present, we will create three partitions :&lt;br /&gt;
 &lt;br /&gt;
* one for UEFI&lt;br /&gt;
* one for /&lt;br /&gt;
* one for swap (hibernation)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# gdisk /dev/nvme0n1&lt;br /&gt;
GPT fdisk (gdisk) version 1.0.9.1&lt;br /&gt;
&lt;br /&gt;
Partition table scan:&lt;br /&gt;
  MBR: protective&lt;br /&gt;
  BSD: not present&lt;br /&gt;
  APM: not present&lt;br /&gt;
  GPT: present&lt;br /&gt;
&lt;br /&gt;
Found valid GPT with protective MBR; using GPT.&lt;br /&gt;
&lt;br /&gt;
Command (? for help): d&lt;br /&gt;
No partitions&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (1-128, default 1): &lt;br /&gt;
First sector (2048-1000215182, default = 2048) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (2048-1000215182, default = 1000214527) or {+-}size{KMGTP}: 512M&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): ef00&lt;br /&gt;
Changed type of partition to &#039;EFI system partition&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (2-128, default 2): &lt;br /&gt;
First sector (1048577-1000215182, default = 1050624) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (1050624-1000215182, default = 1000214527) or {+-}size{KMGTP}: 16G&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8200&lt;br /&gt;
Changed type of partition to &#039;Linux swap&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (3-128, default 3): &lt;br /&gt;
First sector (1048577-1000215182, default = 33556480) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (33556480-1000215182, default = 1000214527) or {+-}size{KMGTP}: &lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8309&lt;br /&gt;
Changed type of partition to &#039;Linux LUKS&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): w&lt;br /&gt;
&lt;br /&gt;
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING&lt;br /&gt;
PARTITIONS!!&lt;br /&gt;
&lt;br /&gt;
Do you want to proceed? (Y/N): Y&lt;br /&gt;
OK; writing new GUID partition table (GPT) to /dev/nvme0n1.&lt;br /&gt;
The operation has completed successfully.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring LUKS =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 5000 --use-random luksFormat /dev/nvme0n1p2&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p2 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p2: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&lt;br /&gt;
cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 5000 --use-random luksFormat /dev/nvme0n1p3&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p3 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p3: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Mounting points and File System =&lt;br /&gt;
&lt;br /&gt;
Open the LUKS partitiond we just created:&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup luksOpen /dev/nvme0n1p2 nvme0n1p2-crypt&lt;br /&gt;
# cryptsetup luksOpen /dev/nvme0n1p3 nvme0n1p3-crypt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create vfat file system for UEFI partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.vfat /dev/nvme0n1p1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for / partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/mapper/nvme0n1p2-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for swap partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/mapper/nvme0n1p3-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create mounting points and mount partitions :&lt;br /&gt;
Mount / partition to /mnt :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t ext4 /dev/mapper/nvme0n1p2-crypt /mnt&amp;lt;/pre&amp;gt;&lt;br /&gt;
Create /boot/efi:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /mnt/boot/efi -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
Mount UEFI partition to /mnt/boot/efi :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t vfat /dev/nvme0n1p1 /mnt/boot/efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
Activate SWAP:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkswap /dev/mapper/nvme0n1p3-crypt&lt;br /&gt;
# swapon /dev/mapper/nvme0n1p3-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk&lt;br /&gt;
NAME                MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINTS&lt;br /&gt;
loop0                 7:0    0 105.2M  1 loop  /.modloop&lt;br /&gt;
sda                   8:0    1   7.6G  0 disk  /media/sda&lt;br /&gt;
├─sda1                8:1    1   148M  0 part  &lt;br /&gt;
└─sda2                8:2    1   1.4M  0 part  &lt;br /&gt;
nvme0n1             259:0    0 476.9G  0 disk  &lt;br /&gt;
├─nvme0n1p1         259:1    0   511M  0 part  /mnt/boot/efi&lt;br /&gt;
├─nvme0n1p2         259:2    0  15.5G  0 part  &lt;br /&gt;
│ └─nvme0n1p2-crypt 253:0    0  15.5G  0 crypt /mnt&lt;br /&gt;
└─nvme0n1p3         259:3    0 460.9G  0 part  &lt;br /&gt;
  └─nvme0n1p3-crypt 253:1    0 460.9G  0 crypt [SWAP]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Installing Alpine =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# setup-disk -m sys /mnt/&lt;br /&gt;
MOUNTPOINT=/mnt setup-alpine&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= mkinitfs settings &amp;amp; modules =&lt;br /&gt;
Edit the /mnt/etc/mkinitfs/mkinitfs.conf file and append the cryptsetup module to the features parameter:&lt;br /&gt;
&amp;lt;pre&amp;gt; features=&amp;quot;... cryptsetup&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
Regenerate the initram:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkinitfs -c /mnt/etc/mkinitfs/mkinitfs.conf -b /mnt/ $(ls /mnt/lib/modules/)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Grub settings =&lt;br /&gt;
&lt;br /&gt;
Create a crypto_keyfile.bin to avoid typing the passphrase twice during the boot process (one for Grub partition, one for Alpine partition):&lt;br /&gt;
&amp;lt;pre&amp;gt; # touch /mnt/crypto_keyfile.bin&lt;br /&gt;
# chmod 600 /mnt/crypto_keyfile.bin&lt;br /&gt;
# dd bs=512 count=4 if=/dev/urandom of=/mnt/crypto_keyfile.bin&lt;br /&gt;
# cryptsetup luksAddKey /dev/nvme0n1p2 /mnt/crypto_keyfile.bin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, let&#039;s mount and chroot to our fresh installation:&lt;br /&gt;
&amp;lt;pre&amp;gt; # mount -t proc /proc /mnt/proc&lt;br /&gt;
# mount --rbind /dev /mnt/dev&lt;br /&gt;
# mount --make-rslave /mnt/dev&lt;br /&gt;
# mount --rbind /sys /mnt/sys&lt;br /&gt;
# chroot /mnt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let&#039;s show the UUID of our partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt; # lsblk -f&lt;br /&gt;
nvme0n1                                                                                                            &lt;br /&gt;
├─nvme0n1p1         vfat                                       62E0-E4C0                             509.7M     0% /boot/efi&lt;br /&gt;
├─nvme0n1p2         crypto_LUKS                                275836d9-05af-4e1a-bce5-335ef3bcd6e8                &lt;br /&gt;
│ └─nvme0n1p2-crypt ext4                                       9bed7992-81cc-4126-8bbd-4e724dbb7bdd   13.9G     3% /&lt;br /&gt;
└─nvme0n1p3         crypto_LUKS                                67eae09f-f533-4bfa-b874-e17016929138                &lt;br /&gt;
  └─nvme0n1p3-crypt swap                                       fcb8594e-2409-4365-bf0b-0199c3acf1c6                &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit /etc/default/grub and add a new line starting with GRUB_CMDLINE_LINUX parameter, replacing &amp;lt;UUID&amp;gt; with the UUID of the encrypted partition (in this case /dev/nvme0n1p2):&lt;br /&gt;
&amp;lt;pre&amp;gt; GRUB_CMDLINE_LINUX=&amp;quot;cryptroot=/dev/nvme0n1p2:nvme0n1p2-crypt:allow-discards cryptkey&amp;quot;&lt;br /&gt;
GRUB_PRELOAD_MODULES=&amp;quot;luks cryptodisk part_gpt&amp;quot;&lt;br /&gt;
GRUB_ENABLE_CRYPTODISK=y&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Re-install Grub:&lt;br /&gt;
&amp;lt;pre&amp;gt; # grub-install --target=x86_64-efi --efi-directory=/boot/efi&lt;br /&gt;
# grub-mkconfig -o /boot/grub/grub.cfg&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring Secure Boot =&lt;/div&gt;</summary>
		<author><name>Blt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22140</id>
		<title>Full disk encryption secure boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22140"/>
		<updated>2022-07-27T07:23:29Z</updated>

		<summary type="html">&lt;p&gt;Blt: Adding SWAP&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Draft}}&lt;br /&gt;
&lt;br /&gt;
This guide is to explain step by step how to setup Alpine Linux with Full Disk Encryption using LUKS2, /boot &amp;amp; / together on the same partition, encrypted swap for hibernation on a nvme drive, with UEFI &amp;amp; Secure Boot.&lt;br /&gt;
The goal of this guide is to follow the KISS principle, lvm can be added, another file system can be used, multiple partitions for /home; /var/log etc.. can also be added, if running everything in one partition is not meeting your requirements.&lt;br /&gt;
&lt;br /&gt;
= Sequence of Events =&lt;br /&gt;
&lt;br /&gt;
* Installing packages&lt;br /&gt;
* Partitioning the disk&lt;br /&gt;
* Configuring LUKS&lt;br /&gt;
* Mounting points and File System&lt;br /&gt;
* Installing Alpine&lt;br /&gt;
* Grub settings&lt;br /&gt;
* mkinitfs settings &amp;amp; modules&lt;br /&gt;
* Configuring Secure Boot&lt;br /&gt;
&lt;br /&gt;
= Installing packages =&lt;br /&gt;
&lt;br /&gt;
To facilitate the partitioning we will use gdisk :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lsblk gptfdisk&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For encryption, we will use cryptsetup :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add cryptsetup&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For using and managing UEFI, multiple packages are needed :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add e2fsprogs grub grub-efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Partitioning the disk =&lt;br /&gt;
&lt;br /&gt;
Let&#039;s assume the disk is /dev/nvme0n1 and no partition is present, we will create three partitions :&lt;br /&gt;
 &lt;br /&gt;
* one for UEFI&lt;br /&gt;
* one for /&lt;br /&gt;
* one for swap (hibernation)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# gdisk /dev/nvme0n1&lt;br /&gt;
GPT fdisk (gdisk) version 1.0.9.1&lt;br /&gt;
&lt;br /&gt;
Partition table scan:&lt;br /&gt;
  MBR: protective&lt;br /&gt;
  BSD: not present&lt;br /&gt;
  APM: not present&lt;br /&gt;
  GPT: present&lt;br /&gt;
&lt;br /&gt;
Found valid GPT with protective MBR; using GPT.&lt;br /&gt;
&lt;br /&gt;
Command (? for help): d&lt;br /&gt;
No partitions&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (1-128, default 1): &lt;br /&gt;
First sector (2048-1000215182, default = 2048) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (2048-1000215182, default = 1000214527) or {+-}size{KMGTP}: 512M&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): ef00&lt;br /&gt;
Changed type of partition to &#039;EFI system partition&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (2-128, default 2): &lt;br /&gt;
First sector (1048577-1000215182, default = 1050624) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (1050624-1000215182, default = 1000214527) or {+-}size{KMGTP}: 16G&lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8200&lt;br /&gt;
Changed type of partition to &#039;Linux swap&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (3-128, default 3): &lt;br /&gt;
First sector (1048577-1000215182, default = 33556480) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (33556480-1000215182, default = 1000214527) or {+-}size{KMGTP}: &lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8309&lt;br /&gt;
Changed type of partition to &#039;Linux LUKS&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): w&lt;br /&gt;
&lt;br /&gt;
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING&lt;br /&gt;
PARTITIONS!!&lt;br /&gt;
&lt;br /&gt;
Do you want to proceed? (Y/N): Y&lt;br /&gt;
OK; writing new GUID partition table (GPT) to /dev/nvme0n1.&lt;br /&gt;
The operation has completed successfully.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring LUKS =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 5000 --use-random luksFormat /dev/nvme0n1p2&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p2 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p2: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&lt;br /&gt;
cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 5000 --use-random luksFormat /dev/nvme0n1p3&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p3 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p3: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Mounting points and File System =&lt;br /&gt;
&lt;br /&gt;
Open the LUKS partitiond we just created:&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup luksOpen /dev/nvme0n1p2 nvme0n1p2-crypt&lt;br /&gt;
# cryptsetup luksOpen /dev/nvme0n1p3 nvme0n1p3-crypt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create vfat file system for UEFI partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.vfat /dev/nvme0n1p1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for / partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/mapper/nvme0n1p2-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for swap partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/mapper/nvme0n1p3-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create mounting points and mount partitions :&lt;br /&gt;
Mount / partition to /mnt :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t ext4 /dev/mapper/nvme0n1p2-crypt /mnt&amp;lt;/pre&amp;gt;&lt;br /&gt;
Create /boot/efi:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /mnt/boot/efi -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
Mount UEFI partition to /mnt/boot/efi :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t vfat /dev/nvme0n1p1 /mnt/boot/efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
Activate SWAP:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkswap /dev/mapper/nvme0n1p3-crypt&lt;br /&gt;
# swapon /dev/mapper/nvme0n1p3-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check partition scheme:&lt;br /&gt;
&amp;lt;pre&amp;gt;# lsblk&lt;br /&gt;
NAME                MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINTS&lt;br /&gt;
loop0                 7:0    0 105.2M  1 loop  /.modloop&lt;br /&gt;
sda                   8:0    1   7.6G  0 disk  /media/sda&lt;br /&gt;
├─sda1                8:1    1   148M  0 part  &lt;br /&gt;
└─sda2                8:2    1   1.4M  0 part  &lt;br /&gt;
nvme0n1             259:0    0 476.9G  0 disk  &lt;br /&gt;
├─nvme0n1p1         259:1    0   511M  0 part  /mnt/boot/efi&lt;br /&gt;
├─nvme0n1p2         259:2    0  15.5G  0 part  &lt;br /&gt;
│ └─nvme0n1p2-crypt 253:0    0  15.5G  0 crypt /mnt&lt;br /&gt;
└─nvme0n1p3         259:3    0 460.9G  0 part  &lt;br /&gt;
  └─nvme0n1p3-crypt 253:1    0 460.9G  0 crypt [SWAP]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Installing Alpine =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# setup-disk -m sys /mnt/&lt;br /&gt;
MOUNTPOINT=/mnt setup-alpine&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Grub settings =&lt;br /&gt;
&lt;br /&gt;
= mkinitfs settings &amp;amp; modules =&lt;br /&gt;
&lt;br /&gt;
= Configuring Secure Boot =&lt;/div&gt;</summary>
		<author><name>Blt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22135</id>
		<title>Full disk encryption secure boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22135"/>
		<updated>2022-07-26T21:33:35Z</updated>

		<summary type="html">&lt;p&gt;Blt: Adding LUKS, Mounting points and File System and Installing Alpine&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Draft}}&lt;br /&gt;
&lt;br /&gt;
This guide is to explain step by step how to setup Alpine Linux with Full Disk Encryption using LUKS2, /boot &amp;amp; / together on the same partition, encrypted swap for hibernation on a nvme drive, with UEFI &amp;amp; Secure Boot.&lt;br /&gt;
The goal of this guide is to follow the KISS principle, lvm can be added, another file system can be used, multiple partitions for /home; /var/log etc.. can also be added, if running everything in one partition is not meeting your requirements.&lt;br /&gt;
&lt;br /&gt;
= Sequence of Events =&lt;br /&gt;
&lt;br /&gt;
* Installing packages&lt;br /&gt;
* Partitioning the disk&lt;br /&gt;
* Configuring LUKS&lt;br /&gt;
* Mounting points and File System&lt;br /&gt;
* Installing Alpine&lt;br /&gt;
* Grub settings&lt;br /&gt;
* mkinitfs settings &amp;amp; modules&lt;br /&gt;
* Configuring Secure Boot&lt;br /&gt;
&lt;br /&gt;
= Installing packages =&lt;br /&gt;
&lt;br /&gt;
To facilitate the partitioning we will use gdisk :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add gptfdisk&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For encryption, we will use cryptsetup :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add cryptsetup&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For using and managing UEFI, multiple packages are needed :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add e2fsprogs grub grub-efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Partitioning the disk =&lt;br /&gt;
&lt;br /&gt;
Let&#039;s assume the disk is /dev/nvme0n1 and no partition is present, we will create three partitions :&lt;br /&gt;
 &lt;br /&gt;
* one for UEFI&lt;br /&gt;
* one for /&lt;br /&gt;
* one for swap (hibernation)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# gdisk /dev/nvme0n1&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (1-128, default 1): &lt;br /&gt;
First sector (2048-1000215182, default = 2048) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (2048-1000215182, default = 1000214527) or {+-}size{KMGTP}: 512M&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): ef00&lt;br /&gt;
Changed type of partition to &#039;EFI system partition&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (2-128, default 2): &lt;br /&gt;
First sector (1048577-1000215182, default = 1050624) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (1050624-1000215182, default = 1000214527) or {+-}size{KMGTP}: &lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8309&lt;br /&gt;
Changed type of partition to &#039;Linux LUKS&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): w&lt;br /&gt;
&lt;br /&gt;
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING&lt;br /&gt;
PARTITIONS!!&lt;br /&gt;
&lt;br /&gt;
Do you want to proceed? (Y/N): Y&lt;br /&gt;
OK; writing new GUID partition table (GPT) to /dev/nvme0n1.&lt;br /&gt;
The operation has completed successfully.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuring LUKS =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 5000 --use-random luksFormat /dev/nvme0n1p2&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p2 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p2: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&lt;br /&gt;
cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 5000 --use-random luksFormat /dev/nvme0n1p3&lt;br /&gt;
&lt;br /&gt;
WARNING!&lt;br /&gt;
========&lt;br /&gt;
This will overwrite data on /dev/nvme0n1p3 irrevocably.&lt;br /&gt;
&lt;br /&gt;
Are you sure? (Type &#039;yes&#039; in capital letters): YES&lt;br /&gt;
Enter passphrase for /dev/nvme0n1p3: &lt;br /&gt;
Verify passphrase: &lt;br /&gt;
Key slot 0 created.&lt;br /&gt;
Command successful.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Mounting points and File System =&lt;br /&gt;
&lt;br /&gt;
Open the LUKS partitiond we just created:&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup luksOpen /dev/nvme0n1p2 nvme0n1p2-crypt&lt;br /&gt;
# cryptsetup luksOpen /dev/nvme0n1p3 nvme0n1p3-crypt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create vfat file system for UEFI partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.vfat /dev/nvme0n1p1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for / partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/mapper/nvme0n1p2-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ext4 file system for swap partition:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkfs.ext4 /dev/mapper/nvme0n1p3-crypt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create mounting points and mount partitions :&lt;br /&gt;
Mount / partition to /mnt :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t ext4 /dev/mapper/nvme0n1p2-crypt /mnt&amp;lt;/pre&amp;gt;&lt;br /&gt;
Create /boot/efi:&lt;br /&gt;
&amp;lt;pre&amp;gt;# mkdir /mnt/boot/efi -p&amp;lt;/pre&amp;gt;&lt;br /&gt;
Mount UEFI partition to /mnt/boot/efi :&lt;br /&gt;
&amp;lt;pre&amp;gt;# mount -t ext4 /dev/mapper/nvme0n1p1 /mnt/boot/efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Installing Alpine =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# setup-disk -m sys /mnt/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Grub settings =&lt;br /&gt;
&lt;br /&gt;
= mkinitfs settings &amp;amp; modules =&lt;br /&gt;
&lt;br /&gt;
= Configuring Secure Boot =&lt;/div&gt;</summary>
		<author><name>Blt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22134</id>
		<title>Full disk encryption secure boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22134"/>
		<updated>2022-07-26T20:59:21Z</updated>

		<summary type="html">&lt;p&gt;Blt: Packages &amp;amp; Partitions&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Draft}}&lt;br /&gt;
&lt;br /&gt;
This guide is to explain step by step how to setup Alpine Linux with Full Disk Encryption using LUKS2, /boot &amp;amp; / together on the same partition on a nvme drive, with UEFI &amp;amp; Secure Boot.&lt;br /&gt;
&lt;br /&gt;
= Sequence of Events =&lt;br /&gt;
&lt;br /&gt;
* Installing packages&lt;br /&gt;
* Partitioning the disk&lt;br /&gt;
* Configuring LUKS&lt;br /&gt;
* Installing Alpine&lt;br /&gt;
* Configuring Secure Boot&lt;br /&gt;
&lt;br /&gt;
= Installing packages =&lt;br /&gt;
&lt;br /&gt;
To facilitate the partitioning we will use gdisk :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add gptfdisk&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For encryption, we will use cryptsetup :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add cryptsetup&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For using and managing UEFI, multiple packages are needed :&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add e2fsprogs grub grub-efi&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Partitioning the disk =&lt;br /&gt;
Let&#039;s assume the disk is /dev/nvme0n1 and no partitions are present, we will create two partitions only : one for UEFI, one for /&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# gdisk /dev/nvme0n1&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (1-128, default 1): &lt;br /&gt;
First sector (2048-1000215182, default = 2048) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (2048-1000215182, default = 1000214527) or {+-}size{KMGTP}: 512M&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): ef00&lt;br /&gt;
Changed type of partition to &#039;EFI system partition&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): n&lt;br /&gt;
Partition number (2-128, default 2): &lt;br /&gt;
First sector (1048577-1000215182, default = 1050624) or {+-}size{KMGTP}: &lt;br /&gt;
Last sector (1050624-1000215182, default = 1000214527) or {+-}size{KMGTP}: &lt;br /&gt;
Current type is 8300 (Linux filesystem)&lt;br /&gt;
Hex code or GUID (L to show codes, Enter = 8300): 8309&lt;br /&gt;
Changed type of partition to &#039;Linux LUKS&#039;&lt;br /&gt;
&lt;br /&gt;
Command (? for help): w&lt;br /&gt;
&lt;br /&gt;
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING&lt;br /&gt;
PARTITIONS!!&lt;br /&gt;
&lt;br /&gt;
Do you want to proceed? (Y/N): Y&lt;br /&gt;
OK; writing new GUID partition table (GPT) to /dev/nvme0n1.&lt;br /&gt;
The operation has completed successfully.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Blt</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22132</id>
		<title>Full disk encryption secure boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22132"/>
		<updated>2022-07-26T17:18:32Z</updated>

		<summary type="html">&lt;p&gt;Blt: Page creation&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Draft}}&lt;br /&gt;
&lt;br /&gt;
This guide is to explain step by step how to setup Alpine Linux with Full Disk Encryption using LUKS2, /boot &amp;amp; / together on the same partition, with UEFI &amp;amp; Secure Boot.&lt;/div&gt;</summary>
		<author><name>Blt</name></author>
	</entry>
</feed>