<?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=Vlp</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=Vlp"/>
	<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/wiki/Special:Contributions/Vlp"/>
	<updated>2026-04-25T17:00:48Z</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=22822</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=22822"/>
		<updated>2022-12-28T15:10:53Z</updated>

		<summary type="html">&lt;p&gt;Vlp: &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;
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>Vlp</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22194</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=22194"/>
		<updated>2022-08-06T14:18:02Z</updated>

		<summary type="html">&lt;p&gt;Vlp: &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 LVM:&lt;br /&gt;
&amp;lt;div class=&amp;quot;toccolours mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
Add LVM on top of luks partition&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lvm2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&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&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;
= Preparing the disks =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# haveged -n 0 | dd of=/dev/nvme0n1p1&lt;br /&gt;
# haveged -n 0 | dd of=/dev/nvme0n1p2&lt;br /&gt;
# haveged -n 0 | dd of=/dev/nvme0n1p3&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>Vlp</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22193</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=22193"/>
		<updated>2022-08-06T14:17:26Z</updated>

		<summary type="html">&lt;p&gt;Vlp: &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 LVM:&lt;br /&gt;
&amp;lt;div class=&amp;quot;toccolours mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
expand to view&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lvm2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&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&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;
= Preparing the disks =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# haveged -n 0 | dd of=/dev/nvme0n1p1&lt;br /&gt;
# haveged -n 0 | dd of=/dev/nvme0n1p2&lt;br /&gt;
# haveged -n 0 | dd of=/dev/nvme0n1p3&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>Vlp</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22192</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=22192"/>
		<updated>2022-08-06T14:17:01Z</updated>

		<summary type="html">&lt;p&gt;Vlp: &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 LVM:&lt;br /&gt;
&amp;lt;div class=&amp;quot;toccolours mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lvm2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&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&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;
= Preparing the disks =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# haveged -n 0 | dd of=/dev/nvme0n1p1&lt;br /&gt;
# haveged -n 0 | dd of=/dev/nvme0n1p2&lt;br /&gt;
# haveged -n 0 | dd of=/dev/nvme0n1p3&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>Vlp</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22191</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=22191"/>
		<updated>2022-08-06T14:16:52Z</updated>

		<summary type="html">&lt;p&gt;Vlp: &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 LVM:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lvm2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&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&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;
= Preparing the disks =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# haveged -n 0 | dd of=/dev/nvme0n1p1&lt;br /&gt;
# haveged -n 0 | dd of=/dev/nvme0n1p2&lt;br /&gt;
# haveged -n 0 | dd of=/dev/nvme0n1p3&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>Vlp</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22190</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=22190"/>
		<updated>2022-08-06T14:16:12Z</updated>

		<summary type="html">&lt;p&gt;Vlp: &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;
&amp;lt;div class=&amp;quot;toccolours mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
For LVM:&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;# apk add lvm2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&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&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;
= Preparing the disks =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# haveged -n 0 | dd of=/dev/nvme0n1p1&lt;br /&gt;
# haveged -n 0 | dd of=/dev/nvme0n1p2&lt;br /&gt;
# haveged -n 0 | dd of=/dev/nvme0n1p3&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>Vlp</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22189</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=22189"/>
		<updated>2022-08-06T14:12:12Z</updated>

		<summary type="html">&lt;p&gt;Vlp: &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;
To improve the entropy :&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;
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;
= Preparing the disks =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# haveged -n 0 | dd of=/dev/nvme0n1p1&lt;br /&gt;
# haveged -n 0 | dd of=/dev/nvme0n1p2&lt;br /&gt;
# haveged -n 0 | dd of=/dev/nvme0n1p3&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;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;toccolours mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
Option LVM&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
bla bla&lt;br /&gt;
&amp;lt;pre&amp;gt;# echo &amp;quot;plop&amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vlp</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22188</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=22188"/>
		<updated>2022-08-06T14:09:44Z</updated>

		<summary type="html">&lt;p&gt;Vlp: &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;
To improve the entropy :&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;
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;
= Preparing the disks =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# haveged -n 0 | dd of=/dev/nvme0n1p1&lt;br /&gt;
# haveged -n 0 | dd of=/dev/nvme0n1p2&lt;br /&gt;
# haveged -n 0 | dd of=/dev/nvme0n1p3&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;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;toccolours mw-collapsible&amp;quot; style=&amp;quot;width:400px; overflow:auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;font-weight:bold;line-height:1.6;&amp;quot;&amp;gt;Lorem ipsum sample&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
BLA BLA&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vlp</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22187</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=22187"/>
		<updated>2022-08-06T14:09:01Z</updated>

		<summary type="html">&lt;p&gt;Vlp: &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;
To improve the entropy :&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;
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;
= Preparing the disks =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# haveged -n 0 | dd of=/dev/nvme0n1p1&lt;br /&gt;
# haveged -n 0 | dd of=/dev/nvme0n1p2&lt;br /&gt;
# haveged -n 0 | dd of=/dev/nvme0n1p3&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;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;toccolours mw-collapsible&amp;quot; style=&amp;quot;width:400px; overflow:auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;font-weight:bold;line-height:1.6;&amp;quot;&amp;gt;Lorem ipsum sample&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
This text is collapsible. {{Lorem}}&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vlp</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22185</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=22185"/>
		<updated>2022-08-05T09:32:34Z</updated>

		<summary type="html">&lt;p&gt;Vlp: &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;
To improve the entropy :&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;
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;
= Preparing the disks =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# haveged -n 0 | dd of=/dev/nvme0n1p1&lt;br /&gt;
# haveged -n 0 | dd of=/dev/nvme0n1p2&lt;br /&gt;
# haveged -n 0 | dd of=/dev/nvme0n1p3&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>Vlp</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22184</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=22184"/>
		<updated>2022-08-05T09:31:48Z</updated>

		<summary type="html">&lt;p&gt;Vlp: &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;
To improve the entropy :&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;
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;
&lt;br /&gt;
= Preparing the disks =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# haveged -n 0 | dd of=/dev/nvme0n1p1&lt;br /&gt;
# haveged -n 0 | dd of=/dev/nvme0n1p2&lt;br /&gt;
# haveged -n 0 | dd of=/dev/nvme0n1p3&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>Vlp</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22183</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=22183"/>
		<updated>2022-08-05T09:24:48Z</updated>

		<summary type="html">&lt;p&gt;Vlp: /* Installing packages */&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;
To improve the entropy :&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;
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>Vlp</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22182</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=22182"/>
		<updated>2022-08-05T09:01:15Z</updated>

		<summary type="html">&lt;p&gt;Vlp: &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>Vlp</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Full_disk_encryption_secure_boot&amp;diff=22181</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=22181"/>
		<updated>2022-08-05T09:00:53Z</updated>

		<summary type="html">&lt;p&gt;Vlp: &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;
&amp;lt;pre&amp;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>Vlp</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=LVM_on_LUKS&amp;diff=21467</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=21467"/>
		<updated>2022-01-07T21:39:33Z</updated>

		<summary type="html">&lt;p&gt;Vlp: /* Troubleshooting */&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&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) name 1 boot&lt;br /&gt;
(parted) set 1 boot on&lt;br /&gt;
(parted) mkpart primary ext4 100M 100%&lt;br /&gt;
(parted) name 2 crypto-luks&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 /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/devic&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;
==== Luk1 ====&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;
==== Luk2 ====&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;&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>Vlp</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=LVM_on_LUKS&amp;diff=21466</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=21466"/>
		<updated>2022-01-07T21:39:16Z</updated>

		<summary type="html">&lt;p&gt;Vlp: /* normal.mod not found */&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&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) name 1 boot&lt;br /&gt;
(parted) set 1 boot on&lt;br /&gt;
(parted) mkpart primary ext4 100M 100%&lt;br /&gt;
(parted) name 2 crypto-luks&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 /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/devic&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;
==== Luk1 ====&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;
==== Luk2 ====&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;&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>Vlp</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=LVM_on_LUKS&amp;diff=21465</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=21465"/>
		<updated>2022-01-07T21:39:09Z</updated>

		<summary type="html">&lt;p&gt;Vlp: /* Troubleshooting */&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&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) name 1 boot&lt;br /&gt;
(parted) set 1 boot on&lt;br /&gt;
(parted) mkpart primary ext4 100M 100%&lt;br /&gt;
(parted) name 2 crypto-luks&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 /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/devic&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;
==== Luk1 ====&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;
==== Luk2 ====&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;&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;
&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>Vlp</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=LVM_on_LUKS&amp;diff=20854</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=20854"/>
		<updated>2021-12-17T10:16:12Z</updated>

		<summary type="html">&lt;p&gt;Vlp: /* Encrypting the LVM Physical Volume Partition */&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 &amp;lt;code&amp;gt;/boot/&amp;lt;/code&amp;gt; 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 &amp;lt;code&amp;gt;util-linux&amp;lt;/code&amp;gt; (&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 &amp;lt;code&amp;gt;/dev/sda&amp;lt;/code&amp;gt; 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&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) name 1 boot&lt;br /&gt;
(parted) set 1 boot on&lt;br /&gt;
(parted) mkpart primary ext4 100M 100%&lt;br /&gt;
(parted) name 2 crypto-luks&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 &amp;lt;code&amp;gt;haveged&amp;lt;/code&amp;gt; as it is considerably faster than &amp;lt;code&amp;gt;/dev/urandom&amp;lt;/code&amp;gt; when generating pseudo-random numbers (it&#039;s almost as high in throughput as &amp;lt;code&amp;gt;/dev/zero&amp;lt;/code&amp;gt;), 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 /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/devic&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;
==== Luk1 ====&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;
==== Luk2 ====&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;&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;
== 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] 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>Vlp</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=LVM_on_LUKS&amp;diff=20853</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=20853"/>
		<updated>2021-12-17T10:15:43Z</updated>

		<summary type="html">&lt;p&gt;Vlp: /* Encrypting the LVM Physical Volume Partition */&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 &amp;lt;code&amp;gt;/boot/&amp;lt;/code&amp;gt; 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 &amp;lt;code&amp;gt;util-linux&amp;lt;/code&amp;gt; (&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 &amp;lt;code&amp;gt;/dev/sda&amp;lt;/code&amp;gt; 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&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) name 1 boot&lt;br /&gt;
(parted) set 1 boot on&lt;br /&gt;
(parted) mkpart primary ext4 100M 100%&lt;br /&gt;
(parted) name 2 crypto-luks&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 &amp;lt;code&amp;gt;haveged&amp;lt;/code&amp;gt; as it is considerably faster than &amp;lt;code&amp;gt;/dev/urandom&amp;lt;/code&amp;gt; when generating pseudo-random numbers (it&#039;s almost as high in throughput as &amp;lt;code&amp;gt;/dev/zero&amp;lt;/code&amp;gt;), 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 /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/devic&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If using Alpine v3.11 or later, and GRUB2 with encrypted /boot, the following should be used to avoid custom modifications (details in *Grub with UEFI* section otherwise):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup luksFormat --type luks1 /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;
==== Luk1 ====&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;
==== Luk2 ====&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;&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;
== 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] 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>Vlp</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=LVM_on_LUKS&amp;diff=20852</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=20852"/>
		<updated>2021-12-17T10:15:07Z</updated>

		<summary type="html">&lt;p&gt;Vlp: /* Encrypting the LVM Physical Volume Partition */&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 &amp;lt;code&amp;gt;/boot/&amp;lt;/code&amp;gt; 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 &amp;lt;code&amp;gt;util-linux&amp;lt;/code&amp;gt; (&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 &amp;lt;code&amp;gt;/dev/sda&amp;lt;/code&amp;gt; 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&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) name 1 boot&lt;br /&gt;
(parted) set 1 boot on&lt;br /&gt;
(parted) mkpart primary ext4 100M 100%&lt;br /&gt;
(parted) name 2 crypto-luks&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 &amp;lt;code&amp;gt;haveged&amp;lt;/code&amp;gt; as it is considerably faster than &amp;lt;code&amp;gt;/dev/urandom&amp;lt;/code&amp;gt; when generating pseudo-random numbers (it&#039;s almost as high in throughput as &amp;lt;code&amp;gt;/dev/zero&amp;lt;/code&amp;gt;), 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;
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 /dev/sda2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For luks2 add:&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/devic&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If using Alpine v3.11 or later, and GRUB2 with encrypted /boot, the following should be used to avoid custom modifications (details in *Grub with UEFI* section otherwise):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup luksFormat --type luks1 /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;
==== Luk1 ====&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;
==== Luk2 ====&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;&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;
== 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] 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>Vlp</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=LVM_on_LUKS&amp;diff=20851</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=20851"/>
		<updated>2021-12-17T10:11:42Z</updated>

		<summary type="html">&lt;p&gt;Vlp: /* Grub with UEFI */&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 &amp;lt;code&amp;gt;/boot/&amp;lt;/code&amp;gt; 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 &amp;lt;code&amp;gt;util-linux&amp;lt;/code&amp;gt; (&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 &amp;lt;code&amp;gt;/dev/sda&amp;lt;/code&amp;gt; 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&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) name 1 boot&lt;br /&gt;
(parted) set 1 boot on&lt;br /&gt;
(parted) mkpart primary ext4 100M 100%&lt;br /&gt;
(parted) name 2 crypto-luks&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 &amp;lt;code&amp;gt;haveged&amp;lt;/code&amp;gt; as it is considerably faster than &amp;lt;code&amp;gt;/dev/urandom&amp;lt;/code&amp;gt; when generating pseudo-random numbers (it&#039;s almost as high in throughput as &amp;lt;code&amp;gt;/dev/zero&amp;lt;/code&amp;gt;), 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;
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 /dev/sda2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For luks2 add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;--pbkdf pbkdf2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If using Alpine v3.11 or later, and GRUB2 with encrypted /boot, the following should be used to avoid custom modifications (details in *Grub with UEFI* section otherwise):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup luksFormat --type luks1 /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;
==== Luk1 ====&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;
==== Luk2 ====&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;&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;
== 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] 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>Vlp</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=LVM_on_LUKS&amp;diff=20850</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=20850"/>
		<updated>2021-12-17T10:11:14Z</updated>

		<summary type="html">&lt;p&gt;Vlp: /* Luk2 */&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 &amp;lt;code&amp;gt;/boot/&amp;lt;/code&amp;gt; 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 &amp;lt;code&amp;gt;util-linux&amp;lt;/code&amp;gt; (&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 &amp;lt;code&amp;gt;/dev/sda&amp;lt;/code&amp;gt; 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&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) name 1 boot&lt;br /&gt;
(parted) set 1 boot on&lt;br /&gt;
(parted) mkpart primary ext4 100M 100%&lt;br /&gt;
(parted) name 2 crypto-luks&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 &amp;lt;code&amp;gt;haveged&amp;lt;/code&amp;gt; as it is considerably faster than &amp;lt;code&amp;gt;/dev/urandom&amp;lt;/code&amp;gt; when generating pseudo-random numbers (it&#039;s almost as high in throughput as &amp;lt;code&amp;gt;/dev/zero&amp;lt;/code&amp;gt;), 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;
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 /dev/sda2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For luks2 add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;--pbkdf pbkdf2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If using Alpine v3.11 or later, and GRUB2 with encrypted /boot, the following should be used to avoid custom modifications (details in *Grub with UEFI* section otherwise):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup luksFormat --type luks1 /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 and use &amp;lt;code&amp;gt;grub-install&amp;lt;/code&amp;gt; to install Grub.&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;
==== Luk1 ====&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;
==== Luk2 ====&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;&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;
== 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] 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>Vlp</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=LVM_on_LUKS&amp;diff=20849</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=20849"/>
		<updated>2021-12-17T10:09:28Z</updated>

		<summary type="html">&lt;p&gt;Vlp: /* Luk2 */&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 &amp;lt;code&amp;gt;/boot/&amp;lt;/code&amp;gt; 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 &amp;lt;code&amp;gt;util-linux&amp;lt;/code&amp;gt; (&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 &amp;lt;code&amp;gt;/dev/sda&amp;lt;/code&amp;gt; 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&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) name 1 boot&lt;br /&gt;
(parted) set 1 boot on&lt;br /&gt;
(parted) mkpart primary ext4 100M 100%&lt;br /&gt;
(parted) name 2 crypto-luks&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 &amp;lt;code&amp;gt;haveged&amp;lt;/code&amp;gt; as it is considerably faster than &amp;lt;code&amp;gt;/dev/urandom&amp;lt;/code&amp;gt; when generating pseudo-random numbers (it&#039;s almost as high in throughput as &amp;lt;code&amp;gt;/dev/zero&amp;lt;/code&amp;gt;), 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;
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 /dev/sda2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For luks2 add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;--pbkdf pbkdf2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If using Alpine v3.11 or later, and GRUB2 with encrypted /boot, the following should be used to avoid custom modifications (details in *Grub with UEFI* section otherwise):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup luksFormat --type luks1 /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 and use &amp;lt;code&amp;gt;grub-install&amp;lt;/code&amp;gt; to install Grub.&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;
==== Luk1 ====&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;
==== Luk2 ====&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;&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_sha256&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;
== 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] 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>Vlp</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=LVM_on_LUKS&amp;diff=20848</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=20848"/>
		<updated>2021-12-16T19:52:15Z</updated>

		<summary type="html">&lt;p&gt;Vlp: /* Encrypting the LVM Physical Volume Partition */&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 &amp;lt;code&amp;gt;/boot/&amp;lt;/code&amp;gt; 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 &amp;lt;code&amp;gt;util-linux&amp;lt;/code&amp;gt; (&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 &amp;lt;code&amp;gt;/dev/sda&amp;lt;/code&amp;gt; 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&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) name 1 boot&lt;br /&gt;
(parted) set 1 boot on&lt;br /&gt;
(parted) mkpart primary ext4 100M 100%&lt;br /&gt;
(parted) name 2 crypto-luks&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 &amp;lt;code&amp;gt;haveged&amp;lt;/code&amp;gt; as it is considerably faster than &amp;lt;code&amp;gt;/dev/urandom&amp;lt;/code&amp;gt; when generating pseudo-random numbers (it&#039;s almost as high in throughput as &amp;lt;code&amp;gt;/dev/zero&amp;lt;/code&amp;gt;), 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;
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 /dev/sda2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For luks2 add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;--pbkdf pbkdf2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If using Alpine v3.11 or later, and GRUB2 with encrypted /boot, the following should be used to avoid custom modifications (details in *Grub with UEFI* section otherwise):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup luksFormat --type luks1 /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 and use &amp;lt;code&amp;gt;grub-install&amp;lt;/code&amp;gt; to install Grub.&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;
==== Luk1 ====&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;
==== Luk2 ====&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;&lt;br /&gt;
* 00002 with &amp;lt;code&amp;gt;vgdisplay&amp;lt;/code&amp;gt; &amp;amp; LV UUID of the root partition /&lt;br /&gt;
* 00003 with &amp;lt;code&amp;gt;lvdisplay&amp;lt;/code&amp;gt; &amp;amp; VG UUID&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 gcry_rijndael pbkdf2 gcry_sha256&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;
== 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] 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>Vlp</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=LVM_on_LUKS&amp;diff=20847</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=20847"/>
		<updated>2021-12-16T19:52:01Z</updated>

		<summary type="html">&lt;p&gt;Vlp: /* Encrypting the LVM Physical Volume Partition */&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 &amp;lt;code&amp;gt;/boot/&amp;lt;/code&amp;gt; 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 &amp;lt;code&amp;gt;util-linux&amp;lt;/code&amp;gt; (&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 &amp;lt;code&amp;gt;/dev/sda&amp;lt;/code&amp;gt; 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&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) name 1 boot&lt;br /&gt;
(parted) set 1 boot on&lt;br /&gt;
(parted) mkpart primary ext4 100M 100%&lt;br /&gt;
(parted) name 2 crypto-luks&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 &amp;lt;code&amp;gt;haveged&amp;lt;/code&amp;gt; as it is considerably faster than &amp;lt;code&amp;gt;/dev/urandom&amp;lt;/code&amp;gt; when generating pseudo-random numbers (it&#039;s almost as high in throughput as &amp;lt;code&amp;gt;/dev/zero&amp;lt;/code&amp;gt;), 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;
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 /dev/sda2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For luks2 add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;--pbkdf pbkdf2/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If using Alpine v3.11 or later, and GRUB2 with encrypted /boot, the following should be used to avoid custom modifications (details in *Grub with UEFI* section otherwise):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup luksFormat --type luks1 /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 and use &amp;lt;code&amp;gt;grub-install&amp;lt;/code&amp;gt; to install Grub.&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;
==== Luk1 ====&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;
==== Luk2 ====&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;&lt;br /&gt;
* 00002 with &amp;lt;code&amp;gt;vgdisplay&amp;lt;/code&amp;gt; &amp;amp; LV UUID of the root partition /&lt;br /&gt;
* 00003 with &amp;lt;code&amp;gt;lvdisplay&amp;lt;/code&amp;gt; &amp;amp; VG UUID&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 gcry_rijndael pbkdf2 gcry_sha256&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;
== 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] 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>Vlp</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=LVM_on_LUKS&amp;diff=20764</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=20764"/>
		<updated>2021-12-09T20:26:44Z</updated>

		<summary type="html">&lt;p&gt;Vlp: &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 &amp;lt;code&amp;gt;/boot/&amp;lt;/code&amp;gt; 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 &amp;lt;code&amp;gt;util-linux&amp;lt;/code&amp;gt; (&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 &amp;lt;code&amp;gt;/dev/sda&amp;lt;/code&amp;gt; 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&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) name 1 boot&lt;br /&gt;
(parted) set 1 boot on&lt;br /&gt;
(parted) mkpart primary ext4 100M 100%&lt;br /&gt;
(parted) name 2 crypto-luks&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 &amp;lt;code&amp;gt;haveged&amp;lt;/code&amp;gt; as it is considerably faster than &amp;lt;code&amp;gt;/dev/urandom&amp;lt;/code&amp;gt; when generating pseudo-random numbers (it&#039;s almost as high in throughput as &amp;lt;code&amp;gt;/dev/zero&amp;lt;/code&amp;gt;), 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;
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 /dev/sda2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If using Alpine v3.11 or later, and GRUB2 with encrypted /boot, the following should be used to avoid custom modifications (details in *Grub with UEFI* section otherwise):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup luksFormat --type luks1 /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 and use &amp;lt;code&amp;gt;grub-install&amp;lt;/code&amp;gt; to install Grub.&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;
==== Luk1 ====&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;
==== Luk2 ====&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;&lt;br /&gt;
* 00002 with &amp;lt;code&amp;gt;vgdisplay&amp;lt;/code&amp;gt; &amp;amp; LV UUID of the root partition /&lt;br /&gt;
* 00003 with &amp;lt;code&amp;gt;lvdisplay&amp;lt;/code&amp;gt; &amp;amp; VG UUID&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 gcry_rijndael pbkdf2 gcry_sha256&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;
== 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] 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>Vlp</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=LVM_on_LUKS&amp;diff=20763</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=20763"/>
		<updated>2021-12-09T20:26:10Z</updated>

		<summary type="html">&lt;p&gt;Vlp: &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 &amp;lt;code&amp;gt;/boot/&amp;lt;/code&amp;gt; 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 &amp;lt;code&amp;gt;util-linux&amp;lt;/code&amp;gt; (&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 &amp;lt;code&amp;gt;/dev/sda&amp;lt;/code&amp;gt; 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&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) name 1 boot&lt;br /&gt;
(parted) set 1 boot on&lt;br /&gt;
(parted) mkpart primary ext4 100M 100%&lt;br /&gt;
(parted) name 2 crypto-luks&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 &amp;lt;code&amp;gt;haveged&amp;lt;/code&amp;gt; as it is considerably faster than &amp;lt;code&amp;gt;/dev/urandom&amp;lt;/code&amp;gt; when generating pseudo-random numbers (it&#039;s almost as high in throughput as &amp;lt;code&amp;gt;/dev/zero&amp;lt;/code&amp;gt;), 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;
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 /dev/sda2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If using Alpine v3.11 or later, and GRUB2 with encrypted /boot, the following should be used to avoid custom modifications (details in *Grub with UEFI* section otherwise):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup luksFormat --type luks1 /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 and use &amp;lt;code&amp;gt;grub-install&amp;lt;/code&amp;gt; to install Grub.&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;
==== Luk1 ====&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;
==== Luk2 ====&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;&lt;br /&gt;
* 00002 with &amp;lt;code&amp;gt;vgdisplay&amp;lt;/code&amp;gt; &amp;amp; LV UUID of the root partition /&lt;br /&gt;
* 00003 with &amp;lt;code&amp;gt;lvdisplay&amp;lt;/code&amp;gt; &amp;amp; VG UUID&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-mkimage -p /boot/grub -O x86_64-efi -c /root/grub-pre.cfg -o /tmp/grubx64.efi luks2 part_gpt cryptodisk gcry_rijndael pbkdf2 gcry_sha256&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;
== 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] 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>Vlp</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=LVM_on_LUKS&amp;diff=20761</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=20761"/>
		<updated>2021-12-09T20:21:02Z</updated>

		<summary type="html">&lt;p&gt;Vlp: add luks2 process&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 &amp;lt;code&amp;gt;/boot/&amp;lt;/code&amp;gt; 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 &amp;lt;code&amp;gt;util-linux&amp;lt;/code&amp;gt; (&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 &amp;lt;code&amp;gt;/dev/sda&amp;lt;/code&amp;gt; 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&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) name 1 boot&lt;br /&gt;
(parted) set 1 boot on&lt;br /&gt;
(parted) mkpart primary ext4 100M 100%&lt;br /&gt;
(parted) name 2 crypto-luks&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 &amp;lt;code&amp;gt;haveged&amp;lt;/code&amp;gt; as it is considerably faster than &amp;lt;code&amp;gt;/dev/urandom&amp;lt;/code&amp;gt; when generating pseudo-random numbers (it&#039;s almost as high in throughput as &amp;lt;code&amp;gt;/dev/zero&amp;lt;/code&amp;gt;), 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;
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 /dev/sda2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If using Alpine v3.11 or later, and GRUB2 with encrypted /boot, the following should be used to avoid custom modifications (details in *Grub with UEFI* section otherwise):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# cryptsetup luksFormat --type luks1 /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 and use &amp;lt;code&amp;gt;grub-install&amp;lt;/code&amp;gt; to install Grub.&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;
==== Luk1 ====&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;
==== Luk2 ====&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;&lt;br /&gt;
* 00002 with &amp;lt;code&amp;gt;vgdisplay&amp;lt;/code&amp;gt; &amp;amp; LV UUID of the root partition /&lt;br /&gt;
* 00003 with &amp;lt;code&amp;gt;lvdisplay&amp;lt;/code&amp;gt; &amp;amp; VG UUID&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-mkimage -p /boot/grub -O x86_64-efi -c /root/grub-pre.cfg -o /tmp/grubx64.efi luks2 part_gpt cryptodisk gcry_rijndael pbkdf2 gcry_sha256&lt;br /&gt;
# (chroot) install -v /tmp/grubx64.efi /boot/efi/EFI/grub/&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;
== 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] 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>Vlp</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=ALSA&amp;diff=20760</id>
		<title>ALSA</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=ALSA&amp;diff=20760"/>
		<updated>2021-12-09T19:56:01Z</updated>

		<summary type="html">&lt;p&gt;Vlp: add alsa-ucm-conf&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Install ==&lt;br /&gt;
&lt;br /&gt;
First you will need to install the Alsa packages, Linux sound driver and volume adjuster.&lt;br /&gt;
&lt;br /&gt;
 # apk add alsa-utils alsa-utils-doc alsa-lib alsaconf alsa-ucm-conf&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
&lt;br /&gt;
Then you will need to add all your users (including root) to the &amp;lt;code&amp;gt;audio&amp;lt;/code&amp;gt; group.&lt;br /&gt;
&lt;br /&gt;
 # addgroup $USER audio&lt;br /&gt;
 # addgroup root audio&lt;br /&gt;
&lt;br /&gt;
Find the default sound card.&lt;br /&gt;
&lt;br /&gt;
 # alsamixer&lt;br /&gt;
&lt;br /&gt;
The default sound card will show up. Try turning up the volume of Master and the device(s) such as speakers or microphones that you need, and audio should work (&#039;&#039;F1&#039;&#039; - help, &#039;&#039;M&#039;&#039; - toggle mute, ...)&lt;br /&gt;
&lt;br /&gt;
If there are no volume controls visible, try hitting &#039;&#039;F6&#039;&#039; on your keyboard and toggling between the sound cards (which all might have the same name in the context menu that pops up except for the numbers next to and before the names).&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve found the sound card name that gives you volume controls, set the unique number that showed up in the &#039;&#039;F6&#039;&#039; context menu as your default soundcard.&lt;br /&gt;
&lt;br /&gt;
 # nano /usr/share/alsa/alsa.conf&lt;br /&gt;
&lt;br /&gt;
Scroll down until you find the lines that start with &amp;lt;code&amp;gt;defaults.ctl.card&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;defaults.pcm.card&amp;lt;/code&amp;gt; and put the number (you found in the &#039;&#039;F6&#039;&#039; context menu of the alsamixer command for the soundcard you want as your default) at the end of those lines separated by a space for each. For example, if the default sound card you want is &amp;quot;1&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;defaults.ctl.card 1&amp;lt;/code&amp;gt;&lt;br /&gt;
 &amp;lt;code&amp;gt;defaults.pcm.card 1&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Save your nano work by pressing &#039;&#039;Ctrl+O&#039;&#039; and confirm the changes by pressing &#039;&#039;Enter&#039;&#039;. Then exit nano by pressing &#039;&#039;Ctrl+X&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Try turning up the volume of Master and the device(s) such as speakers or microphones that you need with the &amp;lt;code&amp;gt;alsamixer&amp;lt;/code&amp;gt; command, and audio should work.&lt;br /&gt;
&lt;br /&gt;
Alsa service is not started on install, you need to start it and to add it on rc.&lt;br /&gt;
 rc-service alsa start&lt;br /&gt;
 rc-update add alsa&lt;br /&gt;
&lt;br /&gt;
Gstreamer can now catch the device and the audio mixer is working.&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation]]&lt;br /&gt;
[[Category:Desktop]]&lt;br /&gt;
[[Category:Multimedia]]&lt;br /&gt;
[[Category:Sound]]&lt;/div&gt;</summary>
		<author><name>Vlp</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Setting_up_a_laptop&amp;diff=20406</id>
		<title>Setting up a laptop</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Setting_up_a_laptop&amp;diff=20406"/>
		<updated>2021-12-04T12:16:53Z</updated>

		<summary type="html">&lt;p&gt;Vlp: adding option to:  `apk add --root=/mnt/root --initdb $(cat /etc/apk/world)` otherwise command won&amp;#039;t run&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Draft}}&lt;br /&gt;
&lt;br /&gt;
This guide is about a project to create a &#039;&#039;&#039;secured laptop&#039;&#039;&#039;.  For this project we take in consideration ways to extend battery life.  It covers tools and daemons that are must haves for a laptop setup.&lt;br /&gt;
&lt;br /&gt;
== Guide features ==&lt;br /&gt;
&lt;br /&gt;
*Deniable full disk encryption&lt;br /&gt;
*Two factor authentication (physical object (USB key), mind) &lt;br /&gt;
*Encrypted swap and hibernation&lt;br /&gt;
*Encrypted home on top of encrypted drive&lt;br /&gt;
*Memory sanitation&lt;br /&gt;
*Dynamic power modes&lt;br /&gt;
*Feature keys support&lt;br /&gt;
&lt;br /&gt;
== Rubberhose Attack ==&lt;br /&gt;
&lt;br /&gt;
Just a reminder that all attacks are subjected to the Rubberhose Attack dilemma, you either give up your encryption keys or be tortured with a rubberhose with the possibly of death.  See [https://en.wikipedia.org/wiki/Rubber-hose_cryptanalysis Wikipedia article].  We try to present [https://en.wikipedia.org/wiki/Deniable_encryption  deniable encryption (Wikipedia)] to avoid a rubberhose attack scenario.  In this article we use the words plausible deniability interchangeably with deniable encryption.  To achieve this we use a facade and require no metadata fingerprints to expose or hint of encrypted or hidden containers or hint as in detect of existence of an encrypted disk.  The keys should be stored using steganography where we dilute the randomness into the facade.  It also requires you not to brag about encryption or mention it because that is an invitation for the attacker to torture the victim.  Deniable encryption requires you not put encrypted as an entry title to your bootloader.  There shouldn&#039;t be an entry for your facade bootloader to the encrypted drive.&lt;br /&gt;
&lt;br /&gt;
== Why full disk? ==&lt;br /&gt;
&lt;br /&gt;
The full disk encryption provides sort of some plausible deniability or a valid alibi that you didn&#039;t encrypt it.  Is the drive just random noise, broken, or is it really encrypted?  The other reason is that it implies that everything is protected.&lt;br /&gt;
&lt;br /&gt;
But there could be problems if not done right.  For example, cryptsetup does leave a plaintext marking or some hints by default that it has been encrypted when using luks/luks2 mode if a detached header with option &amp;lt;code&amp;gt;--header &amp;lt;path&amp;gt;&amp;lt;/code&amp;gt; is not presented.[https://www.lisenet.com/2013/luks-add-keys-backup-and-restore-volume-header/][http://man7.org/linux/man-pages/man8/cryptsetup.8.html]  To gain credibility that we didn&#039;t really do the encryption, you have to wipe the +3 MiB region based on the number of key slots used; or store the headers on an external device.&lt;br /&gt;
&lt;br /&gt;
If you did deniable encryption incorrectly, it is possible to erase and restore the header.  This presents an opportunity to improve obfuscation.  When you pull out the USB key, it should erase the header but store it on the USB key atomically as in completely.  If you plug in the USB key, it will restore back the header.  cryptsetup has luks actions luksHeaderBackup and luksHeaderRestore to do this.&lt;br /&gt;
&lt;br /&gt;
== Starting at the beginning ==&lt;br /&gt;
&lt;br /&gt;
Grab a USB thumb drive with Alpine.  Set it up as usual but don&#039;t let it touch your drive yet.  Then, install all the tools into memory ramdisk but not in the hard drive yet.  The hard drive will be obliterated.&lt;br /&gt;
&lt;br /&gt;
You will then install Alpine using the steps:&lt;br /&gt;
&lt;br /&gt;
First you need WiFi, to get it run do the command below but say no or skip  the hard drive setup stuff:&lt;br /&gt;
&lt;br /&gt;
  setup-alpine&lt;br /&gt;
&lt;br /&gt;
Then, you need to install some tools into RAM temporarly:&lt;br /&gt;
  apk add e2fsprogs grub grub-bios grub-efi mkinitfs nano&lt;br /&gt;
&lt;br /&gt;
== Randomizing the drive with pseudorandom urandom entropy ==&lt;br /&gt;
&lt;br /&gt;
The first part is to erase the drive with random noise but in practical time.  There are many techniques to do this but should be done in one day or two minimum.&lt;br /&gt;
&lt;br /&gt;
You can use shred or dd to accomplish this depending on your needs and the availability of entropy.  Some techniques take longer.  Cryptologist Bruce Schneier recommended 7 times with specified pattern.  See [https://en.wikipedia.org/wiki/Data_erasure Wikipedia Article].  For practical purposes, we just do it random in one pass.  It should be random so that the facade of random noise hides the encrypted data which resembles noise.&lt;br /&gt;
&lt;br /&gt;
To list the drives on the system do &amp;lt;code&amp;gt;fdisk -l&amp;lt;/code&amp;gt;.  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;IMPORTANT: make sure you wipe the right specific drive.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To wipe the disk with random entropy do:&lt;br /&gt;
&lt;br /&gt;
  dd if=/dev/urandom of=/dev/sda&lt;br /&gt;
&lt;br /&gt;
== Creating GPG keys ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;As of this time, Alpine&#039;s mkinitfs does only one factor authentication with passphrase.&#039;&#039;&#039; You need to manually edit the initramfs-init.in in mkinitfs to support two factor authentication using cryptsetup.&lt;br /&gt;
&lt;br /&gt;
After you have scrambled the drive, you want to create your GPG keys.  You will use these keys to set the password(s) for your cryptsetup-luks partitions.  These keys should be stored on a USB thumb drive or other memory device but should not be on the USB boot thumb drive or on the encrypted drive.  The key should be a random 128 bit key wrapped in GPG and protected with a password.&lt;br /&gt;
&lt;br /&gt;
If you are using x, you need to do &amp;lt;code&amp;gt;sudo apk add pinentry-gtk&amp;lt;/code&amp;gt; to display password prompt properly for the next step.&lt;br /&gt;
&lt;br /&gt;
To install openssl and gpg do:&lt;br /&gt;
&lt;br /&gt;
  apk add openssl gnupg&lt;br /&gt;
&lt;br /&gt;
Then, to generate a key:&lt;br /&gt;
&lt;br /&gt;
  export GPG_TTY=$(tty) &amp;amp;&amp;amp; openssl rand -base64 512 | gpg --symmetric --cipher-algo aes --armor &amp;gt; /mnt/usb/$(openssl rand -hex 12)&lt;br /&gt;
&lt;br /&gt;
(Make sure your usb is mounted on /mnt/usb first.)&lt;br /&gt;
&lt;br /&gt;
The long file name comes from &amp;lt;code&amp;gt;openssl rand -hex 12&amp;lt;/code&amp;gt; so that we enhance plausible deniability.  The attacker cannot determine the purpose of the key.  Is it used for GitHub? for Email?&lt;br /&gt;
&lt;br /&gt;
The first part will produce 512 random bytes in wrap it in base64.  The random data will be piped to gpg which will wrap it in AES as ciphertext which again gets wrapped in base64 ascii armor.  For every partition including swap in some cases, you should create more gpg keys and store them in your USB thumb drives.  After you have produced your gpg keys, you will then use them as a password for cryptsetup/luks.&lt;br /&gt;
&lt;br /&gt;
You can replace aes above with the ones listed in &amp;lt;code&amp;gt;gpg --version&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
There should be a password generated for the swap.  This is to resume for your hibernate.  If you don&#039;t want to hibernate, then password is not required and all you need to do is to create/format the partition each time you boot without a password or with a one time random password.&lt;br /&gt;
&lt;br /&gt;
== Hiding the keys using steganography ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;WARNING:&#039;&#039; This section is considered experimental.  It requires the tool and the dependencies to be placed on another USB separate from the key files, the bootloaders, and encrypted disks.  The tool and dependencies need to be packaged together.  We decentralize these components so that the attacker doesn&#039;t connect the dots easily or immediately jumps to the conclusion for the requirements to decrypt.  Steghide automatically uses 128-bit AES in CBC mode to encrypt data.  This can be change if you don&#039;t like or trust AES with the -e option.  Use &amp;lt;code&amp;gt;steghide encinfo&amp;lt;/code&amp;gt; for other ciphers and modes.&lt;br /&gt;
&lt;br /&gt;
Fortunately, Alpine has a package for steganography called steghide.  To install steghide do:&lt;br /&gt;
&lt;br /&gt;
  apk add steghide&lt;br /&gt;
&lt;br /&gt;
You will place the keyfile in an image file.  The facade image file should be large enough that there is no apparent discernible difference between the original and the modified.  Do not use a small image with a small filesize.&lt;br /&gt;
&lt;br /&gt;
As mentioned previously luks headers could be 3MB large or more and an jpeg image file is not suitable.  Use another format like .au/.wav or another steganography utility that handles mp3s.  The mp3/wav should be fairly large enough to dilute the header.  So, something with long content is suitable.&lt;br /&gt;
&lt;br /&gt;
There are two basic commands to use with steghide embed and extract,&lt;br /&gt;
&lt;br /&gt;
To embed do:&lt;br /&gt;
&lt;br /&gt;
  steghide embed -ef key.gpg -cf image.jpg&lt;br /&gt;
&lt;br /&gt;
To extract do:&lt;br /&gt;
&lt;br /&gt;
  steghide extract -xf key.gpg -sf image.jpg&lt;br /&gt;
&lt;br /&gt;
To get a file list of files to ship out, use:&lt;br /&gt;
&lt;br /&gt;
  apk info -L libgcc libmcrypt libmhash libstdc++ libjpeg-turbo steghide&lt;br /&gt;
&lt;br /&gt;
== Full disk encryption with with cryptsetup-luks volumes ==&lt;br /&gt;
&lt;br /&gt;
=== Partitioning scheme ===&lt;br /&gt;
&lt;br /&gt;
This section presents a conceptual layout.  It should not be a knee-jerk approval to automatically use the partition tool which would compromise your plausible deniability.&lt;br /&gt;
&lt;br /&gt;
For the facade, we use an Ubuntu Live CD (or less skilled distro) to present the impression that we are not sophisticated or tech savvy enough to implement encryption.  Windows is also acceptable even better.  The immutable Live CD and immutable partition ensures that you are not compromised by a third party attacker that implants evidence.&lt;br /&gt;
&lt;br /&gt;
There could be possibly two bootloaders, one for the facade and the other to the encrypted drive stored on an external device.&lt;br /&gt;
&lt;br /&gt;
==== Luks ====&lt;br /&gt;
&lt;br /&gt;
Plausible deniability only works if you can demonstrate no existence of partitions 2, 3, 4 and no fingerprints/plaintext introduced by cfdisk and cryptsetup-luks.  Use something like TestDisk, fdisk -l, or gparted and a disk editor (hex editor for disks).&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;5&amp;quot; border=&amp;quot;1&amp;quot; class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!#&lt;br /&gt;
!Name&lt;br /&gt;
!Mount point&lt;br /&gt;
!Notes&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| facade&lt;br /&gt;
| /&lt;br /&gt;
| (optional) The facade partition contains a pristine normal operating system or Ubuntu Live CD image to lure the attacker in attempt to boost the confidence of the attacker convincing them that there is no encryption on the device.&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| swap&lt;br /&gt;
| &lt;br /&gt;
| It should be the same size as your ram for x86_64.  Rationale: it should contain the whole ram image.&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
| root&lt;br /&gt;
| /&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
| rescue&lt;br /&gt;
| /&lt;br /&gt;
| This should contain the Alpine image.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Plain dm-crypt ====&lt;br /&gt;
&lt;br /&gt;
Plausible deniability only works if you are able to present #2 as being unused space or untampered.  To check use something like TestDisk, gparted and a disk editor (hex editor for disks).&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;5&amp;quot; border=&amp;quot;1&amp;quot; class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!#&lt;br /&gt;
!Name&lt;br /&gt;
!Mount point&lt;br /&gt;
!Notes&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| facade&lt;br /&gt;
| /&lt;br /&gt;
| (optional) The facade partition contains a pristine normal operating system or Ubuntu Live CD image to lure the attacker in attempt to boost the confidence of the attacker convincing them that there is no encryption on the device.&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| vgroot&lt;br /&gt;
| &lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| 2_1&lt;br /&gt;
| vgroot-root&lt;br /&gt;
| /&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| 2_2&lt;br /&gt;
| vgroot-swap&lt;br /&gt;
| &lt;br /&gt;
| It should be the same size as your ram for x86_64.  Rationale: it should contain the whole ram image.&lt;br /&gt;
|-&lt;br /&gt;
| 2_3&lt;br /&gt;
| vgroot-rescue&lt;br /&gt;
| /&lt;br /&gt;
| This should contain the Alpine image.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Installing cryptsetup ===&lt;br /&gt;
&lt;br /&gt;
To install cryptsetup you need the package below&lt;br /&gt;
&lt;br /&gt;
  apk add cryptsetup&lt;br /&gt;
&lt;br /&gt;
=== Choosing ciphers ===&lt;br /&gt;
&lt;br /&gt;
When you create your luks drives, you need to decide on the type of ciphers and hashing techniques to use.  The ciphers that you want to use are ones are up to you, but it should be one that is hasn&#039;t been cracked yet or has not suffered a lot of cryptanalysis attacks.  The ones that you might want to use is AES which is hardware accelerated in some Intel CPUs that have the AES-NI cpuflag which you can check by &amp;lt;code&amp;gt;cat /proc/cpuinfo&amp;lt;/code&amp;gt;.  Also consider the ciphers that are SIMD optimized such as serpent and twofish that are available in the Linux kernel.  Also consider ciphers that are unpopular but known to be secure such as Blowfish (which Wikipedia claims to be attacked and the author recommended Twofish).[https://en.wikipedia.org/wiki/Cipher_security_summary]  If it is hardware accelerated, it will save battery life and minimize CPU usage.&lt;br /&gt;
&lt;br /&gt;
For some ciphers weakness also see [https://en.wikipedia.org/wiki/Cipher_security_summary Cipher security summary (Wikipedia)].&lt;br /&gt;
&lt;br /&gt;
For some hash function weaknesses also see [https://en.wikipedia.org/wiki/Hash_function_security_summary Hash function security summary (Wikipedia)].&lt;br /&gt;
&lt;br /&gt;
Generally speaking, the swap partition should use a fast cipher.  You want to lower the latency or delay of the memory subsystem as a consequence of being encrypted.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;IMPORTANT:&#039;&#039;&#039; Please read the [[Setting_up_a_laptop#Important_notes | Important notes]] section for details about the problems with AES encryption.&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t trust AES shills and endorsed by the NSA, you can try another different one.  Another advantage of using a public vetted cipher is that it provides confidence that it works.&lt;br /&gt;
&lt;br /&gt;
Something like KHAZAD wouldn&#039;t work on &amp;lt;code&amp;gt;cryptsetup benchmark&amp;lt;/code&amp;gt;.  KHAZAD itself is insecure.  Wikipedia reported 5 out of 8 rounds been cracked.[https://en.wikipedia.org/wiki/KHAZAD]&lt;br /&gt;
&lt;br /&gt;
For AES-128 7 out of 10, AES-192 8 out of 12, AES-256-bit 9 out 14 rounds have been cracked according to Wikipedia.[https://en.wikipedia.org/wiki/Advanced_Encryption_Standard]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;IMPORTANT: Do not use sha1 as the hashing algorithm.&#039;&#039;&#039;  It already has already been compromised.&lt;br /&gt;
&lt;br /&gt;
=== Getting the available ciphers ===&lt;br /&gt;
&lt;br /&gt;
To check the availability of a cipher or hash function use:&lt;br /&gt;
  find $(find /lib/modules -name &amp;quot;crypto&amp;quot; -type d) -type f -name &amp;quot;*.ko&amp;quot; | sort&lt;br /&gt;
&lt;br /&gt;
To check if a cipher is loaded and passed its own tests use:&lt;br /&gt;
  cat /proc/crypto&lt;br /&gt;
&lt;br /&gt;
To test some popular ciphers and hashes do:&lt;br /&gt;
&lt;br /&gt;
  cryptsetup benchmark&lt;br /&gt;
&lt;br /&gt;
The top set is associated with the hashing algorithms.  The bottom set are the ciphers.  Use the commands below but replace the cipher and/or hash algorithm with your preferences.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;cryptsetup benchmark&amp;lt;/code&amp;gt; actually doesn&#039;t show all the ciphers like Anubis.  The cipher should also have CBC and/or XTS block cipher mode of operation to encrypt larger block sizes.  AES for example has a block size of 128.  &lt;br /&gt;
&lt;br /&gt;
To test if the unpopular but uncracked cipher works use sometime like:&lt;br /&gt;
  cryptsetup benchmark --cipher anubis&lt;br /&gt;
&lt;br /&gt;
=== General steps for cryptsetup ===&lt;br /&gt;
&lt;br /&gt;
==== Original method with fdisk with no plausible deniability ====&lt;br /&gt;
&lt;br /&gt;
In this method &amp;lt;code&amp;gt;--type luks&amp;lt;/code&amp;gt; is implied which generates metadata.&lt;br /&gt;
&lt;br /&gt;
If you want plausible deniability for luks, you need to pass &amp;lt;code&amp;gt;--header &amp;lt;path&amp;gt;&amp;lt;/code&amp;gt; to all the luks commands, where &amp;lt;code&amp;gt;&amp;lt;path&amp;gt;&amp;lt;/code&amp;gt; is a unix path like /mnt/usb/d6ae10eda66704c8.  The random name comes from &amp;lt;code&amp;gt;openssl rand -hex 8&amp;lt;/code&amp;gt;.  The header is transferred to the external device (but no mention of the key slot area but ciphertext being transferred) in the man page.  The information in that file should be obfuscated with encryption if there is plaintext or fingerprint in it just in case. Then, it should be decrypted when reused.&lt;br /&gt;
&lt;br /&gt;
You need to install cfdisk if you prefer the interactive ncurses console method:&lt;br /&gt;
&lt;br /&gt;
  apk add cfdisk&lt;br /&gt;
&lt;br /&gt;
{|| cellpadding=&amp;quot;5&amp;quot; border=&amp;quot;1&amp;quot; class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!#&lt;br /&gt;
!Step&lt;br /&gt;
!Command&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| Use cfdisk to create partitions.  Make two partitions--a system partition and a swap partition&lt;br /&gt;
| &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;cfdisk&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| Create and format the luks device&lt;br /&gt;
| &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;cryptsetup --cipher aes-cbc-essiv:sha256 --key-size 256 luksFormat /dev/sda1 /mnt/usb/$(ls)&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
| Open the luks device&lt;br /&gt;
| &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;cryptsetup --key-file /mnt/usb/$(ls) luksOpen /dev/sda1 root&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
| Format the decrypted drive with filesystem&lt;br /&gt;
| &amp;lt;code&amp;gt;mkfs.ext4 /dev/mapper/root&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
| Create the mount point&lt;br /&gt;
| &amp;lt;code&amp;gt;mkdir -p /mnt/root&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 6&lt;br /&gt;
| Mount the root partition&lt;br /&gt;
| &amp;lt;code&amp;gt;mount /dev/mapper/root /mnt/root&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 7&lt;br /&gt;
| Create swap&lt;br /&gt;
| cryptsetup -c blowfish -h sha256 -d /dev/urandom --key-file /mnt/usb/59022506d9f4a714 create swap /dev/sda2 &lt;br /&gt;
|-&lt;br /&gt;
| 8&lt;br /&gt;
| Use swap&lt;br /&gt;
| mkswap /dev/mapper/swap &amp;amp;&amp;amp; swapon /dev/mapper/swap&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Improved method with plausible deniability ====&lt;br /&gt;
&lt;br /&gt;
This method requires lvm2.  To install:&lt;br /&gt;
&lt;br /&gt;
  apk add lvm2&lt;br /&gt;
&lt;br /&gt;
{|| cellpadding=&amp;quot;5&amp;quot; border=&amp;quot;1&amp;quot; class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!#&lt;br /&gt;
!Step&lt;br /&gt;
!Command&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| Open the &#039;&#039;plain dm-crypt&#039;&#039; device generating no metadata&lt;br /&gt;
| &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;cryptsetup open --type plain --cipher aes-cbc-essiv:sha256 --key-size 256 --key-file /mnt/usb/$(ls) /dev/sda pvroot&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| Physical volume create with LVM&lt;br /&gt;
| &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;pvcreate /dev/mapper/pvroot&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
| Volume group create with LVM&lt;br /&gt;
| &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;vgcreate vgroot /dev/mapper/pvroot&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
| Logical volume create the swap volume with LVM&lt;br /&gt;
| &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;lvcreate -L 4G vgroot -n swap&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
| Logical volume create the root volume with LVM&lt;br /&gt;
| &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;lvcreate -L 2T vgroot -n root&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 6&lt;br /&gt;
| Logical volume create the rescue volume with LVM&lt;br /&gt;
| &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;lvcreate -L 110M vgroot -n rescue&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 7&lt;br /&gt;
| Format the root volume with filesystem&lt;br /&gt;
| &amp;lt;code&amp;gt;mkfs.ext4 /dev/mapper/vgroot-root&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 8&lt;br /&gt;
| Format the swap volume and activate it&lt;br /&gt;
| &amp;lt;code&amp;gt;mkswap /dev/mapper/vgroot-swap &amp;amp;&amp;amp; swapon /dev/mapper/vgroot-swap&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 9&lt;br /&gt;
| Format the rescue volume with filesystem&lt;br /&gt;
| &amp;lt;code&amp;gt;mkfs.ext4 /dev/mapper/vgroot-rescue&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 10&lt;br /&gt;
| Create mount point for root volume&lt;br /&gt;
| &amp;lt;code&amp;gt;mkdir -p /mnt/root&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 11&lt;br /&gt;
| Mount the root volume&lt;br /&gt;
| &amp;lt;code&amp;gt;mount /dev/mapper/vgroot-root /mnt/root&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Configuring OpenRC dmcrypt and setting up fstab ===&lt;br /&gt;
&lt;br /&gt;
You need to tell OpenRC init scripts to decrypt the volumes.  See &amp;lt;code&amp;gt;/etc/conf.d/dmcrypt&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
You need to add the service to boot well because it needs to decrypt the root volume before OpenRC starts running commands from it.  So you need to do:&lt;br /&gt;
&lt;br /&gt;
  rc-update add dmcrypt boot&lt;br /&gt;
&lt;br /&gt;
==== /etc/init.d/dmcrypt ====&lt;br /&gt;
The dmcrypt OpenRC service will attempt to decrypt the drive using information provided in &#039;&#039;/etc/conf.d/dmcrypt&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
For &#039;&#039;luks&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
{{Cat|/etc/conf.d/dmcrypt|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
  # Mounting root may not be necessary since it is already mounted.&lt;br /&gt;
  target=root&lt;br /&gt;
  source=&#039;/dev/sda1&#039;&lt;br /&gt;
  key=&#039;/mnt/usb/2a667ec72774b0d5&#039;&lt;br /&gt;
&lt;br /&gt;
  swap=swap&lt;br /&gt;
  source=&#039;/dev/sda2&#039;&lt;br /&gt;
  key=&#039;/mnt/usb/59022506d9f4a714&#039;&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
For &#039;&#039;plain dm-crypt&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
{{Cat|/etc/conf.d/dmcrypt|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
  # Mounting root is likely not required since you already mounted it before OpenRC starts to do its thing.&lt;br /&gt;
  target=root&lt;br /&gt;
  source=&#039;/dev/sda&#039;&lt;br /&gt;
  key=&#039;/mnt/usb/2a667ec72774b0d5&#039;&lt;br /&gt;
  options=&#039;--type plain --cipher aes-cbc-essiv:sha256 --key-size 256&#039;&lt;br /&gt;
&lt;br /&gt;
  swap=swap&lt;br /&gt;
  source=&#039;/dev/sda2&#039;&lt;br /&gt;
  key=&#039;/mnt/usb/59022506d9f4a714&#039;&lt;br /&gt;
  pre_mount=&#039;vgchange -ay vgroot ; lvchange -ay vgroot/swap&#039;&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
dm-crypt will just mount the encrypted &#039;&#039;plain dm-crypt&#039;&#039; drive or the &#039;&#039;luks&#039;&#039; partition.  What you need to do next is set up fstab located at /etc/fstab.  Examples are shown below.&lt;br /&gt;
&lt;br /&gt;
==== /etc/fstab ====&lt;br /&gt;
&lt;br /&gt;
To mount &#039;&#039;plain dm-crypt&#039;&#039; device with fstab:&lt;br /&gt;
&lt;br /&gt;
{{Cat|/etc/fstab|&lt;br /&gt;
  /dev/sdb                  /boot	ext4	defaults  0 0&lt;br /&gt;
  /dev/mapper/root          /		ext4	defaults  0 1&lt;br /&gt;
  /dev/mapper/swap          none	swap	sw        0 0&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
To mount &#039;&#039;lvm&#039;&#039; volumes with fstab:&lt;br /&gt;
&lt;br /&gt;
{{Cat|/etc/fstab|&lt;br /&gt;
  /dev/sdb                  /boot	ext4	defaults  0 0&lt;br /&gt;
  /dev/mapper/vgroot-root   /		ext4	defaults  0 1&lt;br /&gt;
  /dev/mapper/vgroot-swap   none	swap	sw        0 0&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== How to recover from a bad setup ===&lt;br /&gt;
&lt;br /&gt;
Many times you will not get it right perfectly the first try.  To recover from this situation, you need to reopen the &#039;&#039;plain dm-crypt&#039;&#039; drive or the &#039;&#039;luks&#039;&#039; drive and then remount everything back.&lt;br /&gt;
&lt;br /&gt;
To recover from &#039;&#039;luks&#039;&#039;:&lt;br /&gt;
  cryptsetup --key-file /mnt/usb/2a667ec72774b0d5 luksOpen /dev/sda1 root&lt;br /&gt;
  mkdir -p /mnt/root&lt;br /&gt;
  mount /dev/mapper/root /mnt/root&lt;br /&gt;
&lt;br /&gt;
To recover from the &#039;&#039;plain dm-crypt&#039;&#039;:&lt;br /&gt;
  cryptsetup open --type plain --cipher aes-cbc-essiv:sha256 --key-size 256 --key-file /mnt/usb/$(ls) /dev/sda root&lt;br /&gt;
  vgchange -ay vgroot&lt;br /&gt;
  lvchange -ay vgroot/root&lt;br /&gt;
  mkdir -p /mnt/root&lt;br /&gt;
  mount /dev/mapper/vgroot-swap /mnt/root&lt;br /&gt;
&lt;br /&gt;
== Next step: Full blown Alpine installation ==&lt;br /&gt;
&lt;br /&gt;
We will setup the /mnt/root encrypted partition:&lt;br /&gt;
  apk add --root=/mnt/root --initdb $(cat /etc/apk/world) --keys-dir /etc/apk/keys --repositories-file /etc/apk/repositories&lt;br /&gt;
&lt;br /&gt;
Then, enable edge repositories in both files including community and testing:&lt;br /&gt;
  nano /etc/apk/repositories /mnt/root/etc/apk/repositories&lt;br /&gt;
&lt;br /&gt;
Then, copy the necessary files:&lt;br /&gt;
  cp /etc/resolv.conf /mnt/root/etc&lt;br /&gt;
&lt;br /&gt;
Then, install the basic utils:&lt;br /&gt;
  apk add --root=/mnt/root dhcpcd chrony networkmanager wireless-tools wpa_supplicant&lt;br /&gt;
  apk add --root=/mnt/root grub mkinitfs e2fsprogs grub-bios grub-efi&lt;br /&gt;
  apk add --root=/mnt/root sudo nano&lt;br /&gt;
  apk add --root=/mnt/root linux-lts&lt;br /&gt;
&lt;br /&gt;
Then, you need to mount your usb on to /boot:&lt;br /&gt;
  mount /dev/sdb /boot&lt;br /&gt;
&lt;br /&gt;
Edit grub:&lt;br /&gt;
  nano /boot/grub/grub.cfg&lt;br /&gt;
&lt;br /&gt;
Then, install grub on the usb:&lt;br /&gt;
  grub-install --force /dev/sdb&lt;br /&gt;
&lt;br /&gt;
Then, prepare chroot:&lt;br /&gt;
  mount --bind /dev /mnt/root/dev&lt;br /&gt;
  mount --bind /sys /mnt/root/sys&lt;br /&gt;
  cp /etc/reslov.conf /mnt/root/etc&lt;br /&gt;
&lt;br /&gt;
Then, chroot:&lt;br /&gt;
  chroot /mnt/root /bin/sh&lt;br /&gt;
&lt;br /&gt;
Set the root administrator password:&lt;br /&gt;
  passwd&lt;br /&gt;
&lt;br /&gt;
The root password should be very difficult to deter you from using it and force you to use sudo&lt;br /&gt;
&lt;br /&gt;
Edit sudo so that wheel group has administrative :&lt;br /&gt;
  EDITOR=nano visudo&lt;br /&gt;
&lt;br /&gt;
Set:&lt;br /&gt;
  ## Uncomment to allow members of group wheel to execute any command       &lt;br /&gt;
  %wheel ALL=(ALL) ALL                                                 &lt;br /&gt;
&lt;br /&gt;
Then, add wheel (administrator) user:&lt;br /&gt;
  useradd -m myname&lt;br /&gt;
  usermod -a -G video,audio,wheel myname&lt;br /&gt;
&lt;br /&gt;
log in that user:&lt;br /&gt;
  su myname&lt;br /&gt;
&lt;br /&gt;
Then, update and upgrade it&lt;br /&gt;
  sudo apk update&lt;br /&gt;
  sudo apk upgrade&lt;br /&gt;
&lt;br /&gt;
Then, setup xorg:&lt;br /&gt;
  sudo setup-xorg-base&lt;br /&gt;
  sudo apk search xf86-video | sort&lt;br /&gt;
  # pick your video driver&lt;br /&gt;
  sudo apk add xf86-video-adi&lt;br /&gt;
  # pick your opengl driver&lt;br /&gt;
  sudo apk search mesa-dri* | sort&lt;br /&gt;
  sudo apk add mesa-dri-ati  &lt;br /&gt;
&lt;br /&gt;
Then, keep piling on:&lt;br /&gt;
  sudo apk add firefox dwm xfce4-terminal alsa-utils keepassx xfce4 xchat&lt;br /&gt;
  sudo apk add font-noto-emoji terminus-font leafpad xsetroot # See [[Emojis]] to complete installation&lt;br /&gt;
  sudo apk add xf86-input-mouse xf86-input-keyboard&lt;br /&gt;
&lt;br /&gt;
Then, set the desktop:&lt;br /&gt;
  nano .xinitrc&lt;br /&gt;
&lt;br /&gt;
Put both but comment with a # one of them if you don&#039;t want it,&lt;br /&gt;
  #while true; do xsetroot -name &amp;quot;$( date +&amp;quot;%a %b %d %I:%M:%S %Y&amp;quot; )&amp;quot; ; sleep 1; done &amp;amp;&lt;br /&gt;
  #exec dwm&lt;br /&gt;
  exec xfce4-session&lt;br /&gt;
&lt;br /&gt;
For the above xsetroot statement used to provide information in the statusbar for dwm, consider adding information about the battery level.  This information can be found in sysfs at /sys/class/power_supply/BAT0/.&lt;br /&gt;
&lt;br /&gt;
  sync&lt;br /&gt;
  sudo reboot&lt;br /&gt;
&lt;br /&gt;
== Hacking mkinitfs to support cryptsetup with GPG keys ==&lt;br /&gt;
&lt;br /&gt;
This section describes how to assemble a custom initscript chain in multiple parts.  It could be extended with three-factor authentication which adds biometrics along side with mind and physical object.&lt;br /&gt;
&lt;br /&gt;
Most entry to secure systems are not fully automated or do not allow things to quickly pass through freely and often guarded.  This process may seem like a hassle, but it should dissuade the rubberhosers from jumping to the conclusion of the possibility of the existence of a encrypted drive.&lt;br /&gt;
&lt;br /&gt;
Here is the steps required so that the facade initscripts and dependencies are free from encryption.&lt;br /&gt;
* You will separate and archive cryptsetup, ciphers kernel modules, hash function kernel modules, and any additional obfuscation dependencies, and another continuation initscript discussed below.  You need to make sure that you copy /etc/mkinitfs/mkinitfs.conf to your home directory and strip out those features without those modules.&lt;br /&gt;
* You will hide this archive in a mp3 file with another tool you will package or you can use steghide&#039;s .au/.wav support, but .au seems too conspicuous or strange by current trends.&lt;br /&gt;
&lt;br /&gt;
Here we try to clean up the facade so that it presents itself as free without cryptography.  You need the following changes to your initramfs to avoid a sensitive rubberhoser:&lt;br /&gt;
* You will delete everything in the custom initramfs-init referring to encryption.  This includes cryptroot, cryptdm, crypt-anything, etc init options.&lt;br /&gt;
* You need to delete references in nlplug-findfs to cryptsetup and recompile the mkinitfs package.&lt;br /&gt;
* You could program the init script to boot into a facade partition but drop into sh if a hidden special keypress sequence is met.&lt;br /&gt;
&lt;br /&gt;
You need to create a custom init continuation script:&lt;br /&gt;
* Your initscript should drop into single mode which you will mount the encrypted path manually. &lt;br /&gt;
* You will manually steg-unhide the encrypted archive hidden in the mp3 file and extract it to the ramdisk.&lt;br /&gt;
* You will run the custom init continuation script manually.&lt;br /&gt;
* This custom init continuation will automate the process of extracting the gpg keys from another device and image files into the ramdisk.  This will then automate the mounting of the encrypted drive.  This resume continuation script should handle both cold boot and hibernate.&lt;br /&gt;
* You will finish resuming running the other half of mkinitfs-init or specifically where the points after where it typically will mount cryptsetup and hibernate devices.&lt;br /&gt;
&lt;br /&gt;
If you use a USB keyboard, you will unlock the encrypted devices in early userspace. You will need to either compile the USB keyboard drivers in the kernel or you need to add additional modules when generating the mkinitfs.  You will need the hid, hid-generic, ehci-hcd, uhci-hcd, usbcore driver and add those paths in a customized &amp;lt;code&amp;gt;/etc/mkinitfs/features.d/usb-keyboard.modules&amp;lt;/code&amp;gt;.  It should be separate from usb.modules because apk updates may overwrite it.  Use the &amp;lt;code&amp;gt;lsmod&amp;lt;/code&amp;gt; utility from the kmod package to find what drivers your USB keyboard uses.&lt;br /&gt;
&lt;br /&gt;
You need to generate the final mkinitfs.&lt;br /&gt;
First you need the kernelversion to pass into mkinitfs.  To obtain that information do &amp;lt;code&amp;gt;ls /lib/modules&amp;lt;/code&amp;gt; which will show some folders.  Once you found it pass it to mkinitrafs by doing and replacing kernelversion below:&lt;br /&gt;
&lt;br /&gt;
  sudo mkinitramfs -i $HOMEDIR/initramfs-init -c &amp;quot;$HOMEDIR&amp;quot;/mkinitfs.conf kernelversion&lt;br /&gt;
&lt;br /&gt;
The $HOMEDIR should be replaced with the full path if you are not root.&lt;br /&gt;
&lt;br /&gt;
==  Install the bootloader in the USB thumb drive ==&lt;br /&gt;
&lt;br /&gt;
To install grub, you need to install grub on the ramdisk first on the host.  &lt;br /&gt;
&lt;br /&gt;
  apk add grub&lt;br /&gt;
&lt;br /&gt;
To get a list of partitions&lt;br /&gt;
&lt;br /&gt;
  fdisk -l&lt;br /&gt;
&lt;br /&gt;
Mount the boot partition in /boot&lt;br /&gt;
&lt;br /&gt;
  mount /dev/sdb /boot&lt;br /&gt;
&lt;br /&gt;
Make changes to grub&#039;s configuration &lt;br /&gt;
&lt;br /&gt;
  nano /boot/grub/grub.cfg&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;You need to customize the initramfs in order to use GPG keys since there is no support from it.&#039;&#039;&#039;  &lt;br /&gt;
&lt;br /&gt;
The steps here below assumes that these custom initramfs features have been implemented.  &lt;br /&gt;
&lt;br /&gt;
The following boot loader settings is &#039;&#039;&#039;not sufficient&#039;&#039;&#039; for deniable encryption because it exposes the fact that an encrypted drive exists because an attacker can discover that encryption was used through the edit option of the grub menu.  To protect yourself from a rubberhose attack, you really need to customize the initramfs so that references to anything mentioning encryption, ciphers, hashing are not explicitly mentioned.  These configurations should be considered an intermediate form for used in debugging purposes.  In addition, the attacker just can inspect grub.cfg files directly.&lt;br /&gt;
&lt;br /&gt;
The following are just examples to just get it working but should be modified so that it doesn&#039;t hint to the rubberhoser of a hidden partition or encrypted partitions.&lt;br /&gt;
&lt;br /&gt;
The entry should look like:&lt;br /&gt;
&lt;br /&gt;
For &#039;luks&#039;&lt;br /&gt;
&lt;br /&gt;
{{cat|/boot/grub/grub.cfg|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
default=0&lt;br /&gt;
timeout=0&lt;br /&gt;
&lt;br /&gt;
menuentry &#039;Windows 10&#039; {&lt;br /&gt;
	set root=(hd0,2)&lt;br /&gt;
        chainloader +1&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
menuentry &#039;Alpine Linux&#039; {&lt;br /&gt;
	set root=(hd1,1)&lt;br /&gt;
	linux /vmlinuz-hardened root=/dev/mapper/root rw modules=sd-mod,usb-storage,ext4,dm-crypt,aes-x86_64,sha256-mb cryptroot=/dev/sda1 cryptdm=root&lt;br /&gt;
	initrd /initramfs-hardened&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
menuentry &#039;Alpine Linux (Rescue)&#039; {&lt;br /&gt;
	set root=(hd1,1)&lt;br /&gt;
	linux /vmlinuz-hardened root=/dev/mapper/root rw modules=sd-mod,usb-storage,ext4,dm-crypt,aes-x86_64,sha256-mb cryptroot=/dev/sda4 cryptdm=root&lt;br /&gt;
	initrd /initramfs-hardened&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
if keystatus; then&lt;br /&gt;
  if keystatus --ctrl; then&lt;br /&gt;
    set timeout=-1&lt;br /&gt;
  else&lt;br /&gt;
    set timeout=0&lt;br /&gt;
  fi&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
For &#039;plain dm-crypt&#039;:&lt;br /&gt;
&lt;br /&gt;
The stock mkinitfs may not support plain dm-crypt.  It looks like it only supports luks.  Customization of the initramfs is required.&lt;br /&gt;
&lt;br /&gt;
{{cat|/boot/grub/grub.cfg|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
default=0&lt;br /&gt;
timeout=0&lt;br /&gt;
&lt;br /&gt;
menuentry &#039;Windows 10&#039; {&lt;br /&gt;
	set root=(hd0,2)&lt;br /&gt;
        chainloader +1&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
menuentry &#039;Alpine Linux&#039; {&lt;br /&gt;
	set root=(hd1,1)&lt;br /&gt;
	linux /vmlinuz-hardened root=/dev/mapper/vgroot-root rw modules=sd-mod,usb-storage,ext4,dm-crypt,dm-mod,dm-snapshot,aes-x86_64,sha256-mb cryptroot=/dev/sda cryptdm=root&lt;br /&gt;
	initrd /initramfs-hardened&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
menuentry &#039;Alpine Linux (Rescue)&#039; {&lt;br /&gt;
	set root=(hd1,1)&lt;br /&gt;
	linux /vmlinuz-hardened root=/dev/mapper/vgroot-rescue rw modules=sd-mod,usb-storage,ext4,dm-crypt,dm-mod,dm-snapshot,aes-x86_64,sha256-mb cryptroot=/dev/sda cryptdm=rescue&lt;br /&gt;
	initrd /initramfs-hardened&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
if keystatus; then&lt;br /&gt;
  if keystatus --ctrl; then&lt;br /&gt;
    set timeout=-1&lt;br /&gt;
  else&lt;br /&gt;
    set timeout=0&lt;br /&gt;
  fi&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
The source code of grub could possibly be modified and recompiled to use other non-standard keys.  See [https://github.com/lemenkov/grub2/blob/master/grub-core/commands/keystatus.c].  Ideally, it should be not so obvious or accessible for the attacker.&lt;br /&gt;
&lt;br /&gt;
The above grub.cfg is applied to the USB bootloader.  For the facade bootloader, you just want the Windows 10 or Ubuntu entry, nothing more.&lt;br /&gt;
&lt;br /&gt;
For the modules parameter, you need to add your crypto modules.&lt;br /&gt;
Use &amp;lt;code&amp;gt;find /lib/modules/ -name &amp;quot;*aes*&amp;quot;&amp;lt;/code&amp;gt; where aes is the basename for your cipher or hash algorithm&lt;br /&gt;
Use &amp;lt;code&amp;gt;blkid&amp;lt;/code&amp;gt; to obtain the UUID of your device&lt;br /&gt;
&lt;br /&gt;
Install it to your USB thumb drive&lt;br /&gt;
&lt;br /&gt;
  grub-install /dev/sdb&lt;br /&gt;
&lt;br /&gt;
== Home mounting with eCryptfs ==&lt;br /&gt;
&lt;br /&gt;
We use eCryptfs to encrypt home.  The rationale for having another encrypted file system is that if you leave your laptop unattended on break or accidentally leave your USB key in, your data will not be accessible.  The other rationale is that if another person wants to use your computer, you can just log off and the data will be kept hidden and encrypted.  When you log off due to inactivity, your home directory will be unmounted and encrypted.  eCryptfs will encrypt/decrypt the filename and the contents and will sit on top of ext4 which sits on top of luks.&lt;br /&gt;
&lt;br /&gt;
To install ecryptfs-utils:&lt;br /&gt;
&lt;br /&gt;
  sudo apk add ecryptfs-utils&lt;br /&gt;
&lt;br /&gt;
This does one factor authentication mostly with just the password, but it should be modified to use the USB key too.  You need to reconfigure pam with the pam_usb.so which is not in Alpine aports.&lt;br /&gt;
&lt;br /&gt;
You need to use the pam_ecryptfs PAM module.&lt;br /&gt;
&lt;br /&gt;
== Locking it down ==&lt;br /&gt;
&lt;br /&gt;
Many times you will leave your laptop behind with people you trust.  The following tools will help lock down the system.&lt;br /&gt;
&lt;br /&gt;
=== physlock ===&lt;br /&gt;
&lt;br /&gt;
This will auto lock the tty and when you return will prompt for password.&lt;br /&gt;
&lt;br /&gt;
To install physlock:&lt;br /&gt;
&lt;br /&gt;
  sudo apk add physlock&lt;br /&gt;
&lt;br /&gt;
It is currently bugged.  See [https://bugs.alpinelinux.org/issues/3282].  physlock likely doesn&#039;t do two-factor authentication but it should.&lt;br /&gt;
&lt;br /&gt;
You need to create custom script that will monitor idle time in TTY then call physlock.  You load this script when you log on.&lt;br /&gt;
&lt;br /&gt;
=== xscreensaver ===&lt;br /&gt;
&lt;br /&gt;
This will lock you out of xserver&lt;br /&gt;
&lt;br /&gt;
To install xscreensaver:&lt;br /&gt;
&lt;br /&gt;
  sudo apk add xscreensaver&lt;br /&gt;
&lt;br /&gt;
=== USB key udev rule ===&lt;br /&gt;
&lt;br /&gt;
You need to add a new udev rule that will suspend-to-ram or hibernate and log off once you pull the USB key.  When you come back on, you should do 2 factor authentication to restore back everything.  Hibernation and suspend-to-ram might mitigate cold-boot attack (but unlikely see notes at the bottom of the page) to extract plaintext private data and encryption keys in memory.&lt;br /&gt;
&lt;br /&gt;
To find out the details of your USB do:&lt;br /&gt;
&lt;br /&gt;
  udevadm monitor --udev -p&lt;br /&gt;
&lt;br /&gt;
The output should look like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UDEV  [181762.722853] add      /devices/pci0000:00/0000:00:13.2/usb2/2-5/2-5:1.0/host6/target6:0:0/6:0:0:0/block/sdc (block)&lt;br /&gt;
ACTION=add&lt;br /&gt;
DEVLINKS=/dev/disk/by-id/usb-Kingston_MSFT_NORB_MSFTLAKDA300EB3021790009-0:0 /dev/disk/by-path/pci-0000:00:13.2-usb-0:5:1.0-scsi-0:0:0:0 /dev/disk/by-uuid/5A96-03E4&lt;br /&gt;
DEVNAME=/dev/sdc&lt;br /&gt;
DEVPATH=/devices/pci0000:00/0000:00:13.2/usb2/2-5/2-5:1.0/host6/target6:0:0/6:0:0:0/block/sdc&lt;br /&gt;
DEVTYPE=disk&lt;br /&gt;
ID_BUS=usb&lt;br /&gt;
ID_FS_TYPE=vfat&lt;br /&gt;
ID_FS_USAGE=filesystem&lt;br /&gt;
ID_FS_UUID=5A96-03E4&lt;br /&gt;
ID_FS_UUID_ENC=5A96-03E4&lt;br /&gt;
ID_FS_VERSION=FAT32&lt;br /&gt;
ID_INSTANCE=0:0&lt;br /&gt;
ID_MODEL=MSFT_NORB&lt;br /&gt;
ID_MODEL_ENC=MSFT\x20NORB\x20\x20\x20\x20\x20\x20\x20&lt;br /&gt;
ID_MODEL_ID=1645&lt;br /&gt;
ID_PATH=pci-0000:00:13.2-usb-0:5:1.0-scsi-0:0:0:0&lt;br /&gt;
ID_PATH_TAG=pci-0000_00_13_2-usb-0_5_1_0-scsi-0_0_0_0&lt;br /&gt;
ID_REVISION=PMAP&lt;br /&gt;
ID_SERIAL=Kingston_MSFT_NORB_MSFTLAKDA300EB3021790009-0:0&lt;br /&gt;
ID_SERIAL_SHORT=MSFTLAKDA300EB3021790009&lt;br /&gt;
ID_TYPE=disk&lt;br /&gt;
ID_USB_DRIVER=usb-storage&lt;br /&gt;
ID_USB_INTERFACES=:080650:&lt;br /&gt;
ID_USB_INTERFACE_NUM=00&lt;br /&gt;
ID_VENDOR=Kingston&lt;br /&gt;
ID_VENDOR_ENC=Kingston&lt;br /&gt;
ID_VENDOR_ID=0951&lt;br /&gt;
MAJOR=8&lt;br /&gt;
MINOR=32&lt;br /&gt;
SEQNUM=2027&lt;br /&gt;
SUBSYSTEM=block&lt;br /&gt;
USEC_INITIALIZED=1762722168&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You want to extract the &amp;lt;code&amp;gt;ID_SERIAL_SHORT=MSFTLAKDA300EB3021790009&amp;lt;/code&amp;gt; or whatever is associated with your USB thumb drive.&lt;br /&gt;
&lt;br /&gt;
You need pm-utils for ps-suspend.  So to install it do:&lt;br /&gt;
&lt;br /&gt;
  sudo apk add pm-utils&lt;br /&gt;
&lt;br /&gt;
You will create a udev rules so that when you pull out the USB, it will suspend-to-ram or you can use your own script.  To do that create a file with the following contents:&lt;br /&gt;
&lt;br /&gt;
{{Cat|/etc/udev/rules.d/50-usb-thumb-drive.rules|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ACTION==&amp;quot;remove&amp;quot;, SUBSYSTEM==&amp;quot;usb&amp;quot;, ENV{ID_SERIAL_SHORT}==&amp;quot;MSFTLAKDA300EB3021790009&amp;quot;, RUN+=&amp;quot;/usr/sbin/pm-suspend&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
== Extending battery life ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;WARNING: If you do not use the proper mitigation for cold boot attack, you are better off auto-shutdowning the laptop instead of using suspend or hibernate.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== ACPI ===&lt;br /&gt;
&lt;br /&gt;
ACPI is a good daemon to use to execute certain scripts when laptop events are triggered.&lt;br /&gt;
&lt;br /&gt;
To install ACPI do:&lt;br /&gt;
&lt;br /&gt;
  apk add acpi&lt;br /&gt;
&lt;br /&gt;
The events to pay attention to are:&lt;br /&gt;
&lt;br /&gt;
{|  cellpadding=&amp;quot;5&amp;quot; border=&amp;quot;1&amp;quot; class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Event&lt;br /&gt;
! ACPI Event&lt;br /&gt;
! What your script should do&lt;br /&gt;
|-&lt;br /&gt;
| lid close&lt;br /&gt;
|&lt;br /&gt;
| log off ttys and suspend-to-ram.  ALSA should either set the volume to 0 for the sound card or the sound driver be unloaded.  It might be a good idea to kill or mute any music or movie players if the sound loops loudly after lid open.&lt;br /&gt;
|-&lt;br /&gt;
| lid open&lt;br /&gt;
|&lt;br /&gt;
| lock all ttys and all xservers should be locked, possibly reinitialize ALSA and the sound system.&lt;br /&gt;
|-&lt;br /&gt;
| tapped power button&lt;br /&gt;
|&lt;br /&gt;
| lock all ttys and suspend-to-ram&lt;br /&gt;
|-&lt;br /&gt;
| held power button&lt;br /&gt;
|&lt;br /&gt;
| hibernate&lt;br /&gt;
|-&lt;br /&gt;
| unplugged power&lt;br /&gt;
|&lt;br /&gt;
| should switch to &#039;conservative&#039; cpufreq governor at above 25% power ; &#039;powersave&#039; governor at 25%.  set hdparam spindown rate lower.&lt;br /&gt;
|-&lt;br /&gt;
| plugged power&lt;br /&gt;
|&lt;br /&gt;
| should switch to &#039;performance&#039; governor.  disable hdparam spindown.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The purpose of the power governor is to regulate the running frequency (GHz) of the processor.&lt;br /&gt;
&lt;br /&gt;
Certain event handlers are are managed through laptop-mode-tools.  If you don&#039;t want the dependency, then you could write ACPI handler scripts.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;acpi_listen&amp;lt;/code&amp;gt; can be used to retrieve the event name.&lt;br /&gt;
&lt;br /&gt;
TODO: put scripts below&lt;br /&gt;
&lt;br /&gt;
=== Adjusting the backlight dynamically ===&lt;br /&gt;
&lt;br /&gt;
The backlight may be controlled using sysfs.  The setting is a descendant of &amp;lt;code&amp;gt;/sys/class/backlight/&amp;lt;/code&amp;gt;.  The feature may allow you to echo a value to it.  Use trial and error to discover the values.&lt;br /&gt;
&lt;br /&gt;
The adjustment of the backlight should be function of battery life.  So if it is like 33% battery life, you want to run it near lowest settings but readable.  For 50 percent battery energy maybe 40% light.  For 90% battery maybe 75% light.&lt;br /&gt;
&lt;br /&gt;
=== hdparm ===&lt;br /&gt;
&lt;br /&gt;
To install hdparam do:&lt;br /&gt;
&lt;br /&gt;
  sudo apk add hdparm&lt;br /&gt;
&lt;br /&gt;
The settings that laptop-mode-tools messes with is the &amp;lt;code&amp;gt;-S&amp;lt;/code&amp;gt; or the spindown timeout.  It was also hinted that acoustic setting &amp;lt;code&amp;gt;-M&amp;lt;/code&amp;gt; is associated with the speed meaning that louder is faster and quieter is slower which could contribute to the amount of energy used or reduced.&lt;br /&gt;
&lt;br /&gt;
Again you want something like laptop-mode-tools or ACPI to dynamically adjust the settings based on ACPI events.&lt;br /&gt;
&lt;br /&gt;
=== laptop-mode-tools ===&lt;br /&gt;
&lt;br /&gt;
This is currently not in aports but worthy mentioning.  It should really be packaged.  This is a set of scripts to define a power policies.  You can manage all the settings in one place here like the hard drive idle spindown time, CPU governor control, dynamic LCD backlight behavior based on running on battery or AC power supply.&lt;br /&gt;
&lt;br /&gt;
=== cpufreqd ===&lt;br /&gt;
&lt;br /&gt;
This is a useful daemon for regulating power.&lt;br /&gt;
&lt;br /&gt;
To install cpufreqd do:&lt;br /&gt;
&lt;br /&gt;
  sudo apk add cpufreqd&lt;br /&gt;
&lt;br /&gt;
Make sure you add the service:&lt;br /&gt;
&lt;br /&gt;
  sudo rc-update add cpufreqd&lt;br /&gt;
&lt;br /&gt;
=== LCD screen refresh rate ===&lt;br /&gt;
&lt;br /&gt;
The refresh rate sets the maximum framerate.  The more frames pushed the more energy consumed on the battery.  You want this adjusted dynamically per certain events.  For gaming, you want it to be the highest as possible for the laptop and vsync off.  For battery use and traveling, you want it capped at 60 FPS/60 Hz or lower but dynamically adjust when you plug in the AC power supply.  You can adjust the framerate with xrandr.  For movies and YouTube, you want 60FPS and vsync on.&lt;br /&gt;
&lt;br /&gt;
== Hacking the kernel ==&lt;br /&gt;
&lt;br /&gt;
You should refer to the [[Custom Kernel]] page for details.&lt;br /&gt;
&lt;br /&gt;
== Hibernation ==&lt;br /&gt;
&lt;br /&gt;
See [[Custom_Kernel#Hibernation_to_prevent_data_loss|Hibernation to prevent data loss]].&lt;br /&gt;
&lt;br /&gt;
== WiFi management ==&lt;br /&gt;
&lt;br /&gt;
Since you are using WiFi, you need a better WiFi management to quickly find open access WiFi access points.  We don&#039;t have all day to debug complexities of WiFi settings while away from home.&lt;br /&gt;
&lt;br /&gt;
To install NetworkManager do:&lt;br /&gt;
&lt;br /&gt;
  sudo apk add networkmanager&lt;br /&gt;
&lt;br /&gt;
To find WiFi access points use the &amp;lt;code&amp;gt;nmtui&amp;lt;/code&amp;gt; ncurses interface.&lt;br /&gt;
&lt;br /&gt;
You also need other programs so install them as well:&lt;br /&gt;
&lt;br /&gt;
  apk add wpa-supplicant dhcpcd chrony macchanger wireless-tools iputils&lt;br /&gt;
&lt;br /&gt;
What these programs do:&lt;br /&gt;
&lt;br /&gt;
* wpa-supplicant -- for WPA encryption&lt;br /&gt;
* dhcpcd -- for getting a dynamic IP address&lt;br /&gt;
* chrony -- for fixing the time with the atomic clock&lt;br /&gt;
* wireless-tools -- for additional information&lt;br /&gt;
* macchanger -- for protecting against WiFi access discrimination or increased anonymity.  (optional)&lt;br /&gt;
* iputils -- for the ping command (optional)&lt;br /&gt;
&lt;br /&gt;
You also need to add those services:&lt;br /&gt;
&lt;br /&gt;
  rc-update add chrony&lt;br /&gt;
  rc-update add wpa-supplicant&lt;br /&gt;
  rc-update add dhcpcd&lt;br /&gt;
  rc-update add networkmanager&lt;br /&gt;
&lt;br /&gt;
To start the services manually (or just reboot):&lt;br /&gt;
&lt;br /&gt;
  /etc/init.d/chrony start&lt;br /&gt;
  /etc/init.d/wpa-supplicant start&lt;br /&gt;
  /etc/init.d/dhcpcd start&lt;br /&gt;
  /etc/init.d networkmanager start&lt;br /&gt;
&lt;br /&gt;
== Additional tools ==&lt;br /&gt;
&lt;br /&gt;
=== actkbd ===&lt;br /&gt;
&lt;br /&gt;
To control the sound with fn function keys, you need this daemon.  It is currently not in aports.  You could override the design and meaning of those keys with your own scripts and utilities.  This daemon gives you that freedom.&lt;br /&gt;
&lt;br /&gt;
If your laptop contains a brightness key, you want to set that up with this program.  See also [[Setting_up_a_laptop#Adjusting_the_backlight_dynamically | Adjusting the backlight dynamically]].&lt;br /&gt;
&lt;br /&gt;
=== secure-delete ===&lt;br /&gt;
&lt;br /&gt;
Want to prevent cold-boot attack or decrypted keys in memory falling in the wrong hands?  This maybe could work who knows?  From research from cold boot attack, the data can actually stay in memory in minutes, just enough time for a hacker to copy the contents of the memory to a USB thumb drive.&lt;br /&gt;
&lt;br /&gt;
To install secure-delete do:&lt;br /&gt;
&lt;br /&gt;
  sudo apk add secure-delete&lt;br /&gt;
&lt;br /&gt;
smem only works for unused ram.[https://github.com/gordonrs/thc-secure-delete]  If you use the vanilla kernel, this may work.  If you use grsecurity, it will automatically sanitize memory if you enable it (but not enabled by default in the Alpine hardened kernel) when the memory page is freed.[https://en.wikibooks.org/wiki/Grsecurity/Appendix/Grsecurity_and_PaX_Configuration_Options#Sanitize_all_freed_memory]&lt;br /&gt;
&lt;br /&gt;
Close all important programs then call smem.&lt;br /&gt;
&lt;br /&gt;
You call smem in your shutdown script or auto-logoff script.&lt;br /&gt;
&lt;br /&gt;
You can call create a OpenRC shutdown script to run smem when most programs and services are closed.  This will erase all your sensitive plaintext private data just in case.&lt;br /&gt;
&lt;br /&gt;
You may want to create a wrapper script to call smem after your program closes.&lt;br /&gt;
&lt;br /&gt;
You need to write a custom script that does the following:&lt;br /&gt;
  * kill all running processes associated with your user account&lt;br /&gt;
  * auto logoff terminals&lt;br /&gt;
  * for the last terminal closed including all idle xservers, unmount your user home&lt;br /&gt;
  * (optional) use smem to wipe all your plaintext private data in memory after all closed programs in case of cold boot attack&lt;br /&gt;
&lt;br /&gt;
=== Sharing presentations over HDMI ===&lt;br /&gt;
&lt;br /&gt;
If you want to use your laptop to share presentation over HDMI connection, you need libxinerama and xrandr.&lt;br /&gt;
&lt;br /&gt;
To install libxinerama and xrandr do:&lt;br /&gt;
&lt;br /&gt;
  sudo apk add libxinerama xrandr&lt;br /&gt;
&lt;br /&gt;
== Important notes ==&lt;br /&gt;
&lt;br /&gt;
If you lose or break your USB key, that is it and you cannot decrypt your drive.  It would be wise to make a backup of it.&lt;br /&gt;
&lt;br /&gt;
By default, suspend-to-ram or hibernate will not sufficiently clear the AES encryption keys off ram in those phases which would invite a cold boot attack.  This has been covered by the TRESOR kernel patch.[https://en.wikipedia.org/wiki/TRESOR][https://www1.cs.fau.de/tresor]  This patch hasn&#039;t been updated since the 4.x kernel series.[https://www1.cs.fau.de/tresor].  This patch currently only works on 32-bit x86 Linux with SSE and MMX, and on processors with the AES-NI instruction set for x86_64 Linux.  TRESOR doesn&#039;t work with DMA attack, but it can be mitigated by disabling DMA.[https://old.iseclab.org/papers/acsac2012dma.pdf]  The 32-bit version of TRESOR has only a key size of 128.  The AES-NI version of TRESOR has a largest key size of 256 bit.  See [[Setting_up_a_laptop#Choosing_ciphers | Choosing ciphers]] for the number of rounds cracked.&lt;br /&gt;
&lt;br /&gt;
Loop-Amnesia works with LoopAES and is only for 64 bit Linux and only supports 128 bit keys but can result in data loss if their recommendations are not followed. [http://moongate.ydns.eu/amnesia.html]&lt;br /&gt;
&lt;br /&gt;
Please read the Wikipedia article on Cold Boot Attack especially the mitigation section.[https://en.wikipedia.org/wiki/Cold_boot_attack] Full disk encryption will not protect your data especially for older hardware if you do not have the proper mitigation (implying not full proof) prerequisites such as a patched kernel, memory scrambling, permanent memory module mounting for example.&lt;br /&gt;
&lt;br /&gt;
If you have a different but fully encrypted device like iPad, you still can be rubberhosed or interrogated with a perfect deniable encrypted laptop.  This guide doesn&#039;t protect you from that possibility.  If you do not want to be rubberhosed, don&#039;t possess those devices.&lt;br /&gt;
&lt;br /&gt;
Additional tips to mitigate against a DMA Attack to exfiltrate encryption keys:&lt;br /&gt;
&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;
&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;
You may need a custom (or customize a) BIOS or use Intel TXT or TPM which will authenticate the boot devices or boot from specific serial numbers not just any.  For cold boot attack, it is not required to remove the RAM but to to slow down the rate of decay of the RAM module with liquid air in addition an USB thumb drive containing an encryption key retriever bypassing the operating system.[https://youtu.be/XfUlRsE3ymQ]&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation]]&lt;br /&gt;
[[category: desktop]]&lt;/div&gt;</summary>
		<author><name>Vlp</name></author>
	</entry>
</feed>