<?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=Pursuable1652</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=Pursuable1652"/>
	<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/wiki/Special:Contributions/Pursuable1652"/>
	<updated>2026-05-01T12:44:35Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.40.0</generator>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=DM-verity&amp;diff=28859</id>
		<title>DM-verity</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=DM-verity&amp;diff=28859"/>
		<updated>2025-01-21T21:23:20Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{todo| Add a non-initramfs dm-verity implementation, which should use kernel to do dm-verity checking instead of initramfs, which is better for embedded devices, and faster to boot (but hard to implement because of kernel customizations, might need to compile kernel again.)}}&lt;br /&gt;
&lt;br /&gt;
== Why DM-Verity? ==&lt;br /&gt;
Possibly you want to continue the RoT ([https://en.wikipedia.org/wiki/Chain_of_trust Root of Trust] [1]) - from the hardware (Hardware TPM as Root of Trust, which ensures only the hardware with the correct secret cryptographic key in the TPM to decrypt the disk/file encryption) -&amp;gt; secure boot (Secure Boot to only run approved signed EFIStub/signed Bootloader) -&amp;gt; &amp;lt;u&amp;gt;To NOW DM-Verity rootfs&amp;lt;/u&amp;gt; (which ensures your root-image/root-parition has not been tampered with) -&amp;gt; Mandatory Access Control (AppArmor or SELinux - SELinux is disabled on default linux-lts btw) -&amp;gt; Sandboxed/Virtual-Machined Applications.&lt;br /&gt;
&lt;br /&gt;
=== What&#039;s the difference between me just setting the root partition as read-only (basically just an Immutable Root Partition) vs this? ===&lt;br /&gt;
DM-Verity COMPLETELY disallows modifying any files in the root-partition/root-image, or even disallow a part of a root-image/root-partition (the root-image/root-partition needs to be INTACT and match the signed cryptography verified by DM-Verity on a different partition), and with this consideration, you may use ERO-FS or SquashFS to generate Read-Only Root-Paritition/File Images. If you set your EXT4 file system to writable, and DM-Verity were to use it, it would be seen as &amp;quot;corrupted&amp;quot; and not boot anymore, because even just ONE tiny data change to the root image/partition would render it &amp;quot;corrupted&amp;quot;. This is the same technology used in Android and Chrome OS Devices. Also related to use in A/B root, also used by Fedora.&lt;br /&gt;
&lt;br /&gt;
{{tip| To keep the security reasonable, you would ideally want to work on the whole RoT, if not then anybody else can attack the non-verifed boot process that ISN&#039;T the root-partition/root-image that is enforced by DM-Verity.&lt;br /&gt;
* This following guide will use dracut to make a signed secureboot-able EFIStub.&lt;br /&gt;
* If you haven&#039;t, you may follow [https://wiki.alpinelinux.org/wiki/LVM_on_LUKS the Alpine Linux disk encryption setup] [2] with DM-Crypt LUKS and LVM&lt;br /&gt;
* You may choose to decrypt the image with TPM when generating with Dracut Modules with &amp;lt;code&amp;gt;add_dracutdrivers+{{=}}&amp;quot; ... tpm2-tss ... &amp;quot;&amp;lt;/code&amp;gt; and [https://github.com/latchset/clevis?tab{{=}}readme-ov-file#pin-tpm2 Clevis] [3]&lt;br /&gt;
* Apply AppArmor using [https://wiki.alpinelinux.org/wiki/AppArmor Alpine Linux AppArmor Wiki] (Docker does use AppArmor already, but you may apply an AppArmor profile on any application that should not have access to specific directories (AppArmor is a PATH based MAC)) [4]&lt;br /&gt;
* Use [https://gvisor.dev/docs/user_guide/install/ GVisor] [5] with Docker ([https://github.com/google/gvisor?tab{{=}}readme-ov-file#why-does-gvisor-exist Docker is NOT a sandbox] [6] (Because docker uses native kernel compared to Gvisor using its own kernel reimplementation)) for sandboxing on servers}}&lt;br /&gt;
&lt;br /&gt;
=== What is ERO-FS? ===&lt;br /&gt;
[https://pocketnow.com/erofs-android-13-explained/ Google thought about implementing ERO-FS with DM-Verity] [7]. Google was reported to be using it in Android 13, and ERO-FS is an excellent and fast compressed read-only filesystem.&lt;br /&gt;
&lt;br /&gt;
Here is an excerpt about &amp;lt;code&amp;gt;mkfs.erofs&amp;lt;/code&amp;gt; on [[https://wiki.archlinux.org/title/Dm-verity Arch Linux Wiki]] [8]:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039; mkfs.erofs(1) offers an attractive alternative to ext4 or squashfs on the root partition. EROFS, like squashfs, does not allow writes by design and has better performance in many cases than comparable filesystems on flash and solid-state media. It uses lz4 compression by default and was designed for Android phones by Huawei, which make extensive use of dm-verity. &#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Installing ===&lt;br /&gt;
&lt;br /&gt;
==== Working with ERO-FS ====&lt;br /&gt;
&lt;br /&gt;
{{warning| This wiki will be using Alpine Linux Edge Version. (Alpine Linux Non-Edge Versions may not contain these packages in the following rest of the wiki page) (Use Alpine Linux Edge Testing Repository in &amp;lt;code&amp;gt;/etc/apk/repositories&amp;lt;/code&amp;gt; as well)}}&lt;br /&gt;
&lt;br /&gt;
{{note| To not be confused, ERO-FS generates a &amp;quot;root image&amp;quot;, but you can replace the words &amp;quot;root partition&amp;quot; with &amp;quot;root image&amp;quot; and vice versa.}}&lt;br /&gt;
&lt;br /&gt;
First, some considerations, you may use a strictly READ-ONLY file system, such as SquashFS or ERO-FS, this wiki will be using ERO-FS (if you use a custom kernel, make sure it supports a file system such as ERO-FS, the default linux-lts does). [[https://github.com/erofs/erofs-utils ERO-FS Github]] [9] contains some information about how to compress and make your own read-only root image.&lt;br /&gt;
&lt;br /&gt;
{{cmd| $ apk install erofs-utils}}&lt;br /&gt;
{{cmd| $ mkdir image &amp;amp;&amp;amp; cd image }}&lt;br /&gt;
{{cmd| $ wget https://dl-cdn.alpinelinux.org/alpine/v3.21/releases/x86_64/alpine-minirootfs-3.21.0-x86_64.tar.gz}}&lt;br /&gt;
{{cmd| $ tar -xvf alpine-minirootfs-3.21.0-x86_64.tar.gz &amp;amp;&amp;amp; rm alpine-minirootfs-3.21.0-x86_64.tar.gz}}&lt;br /&gt;
Command below will generate an ERO-FS Image compressed with lz4 as ./erofs.img (erofs.img would be the root-partition file to use for dracut)&lt;br /&gt;
{{cmd| $ cd .. &amp;amp;&amp;amp; mkfs.erofs -zlz4hc erofs.img ./image}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Choose between a file or a partition ====&lt;br /&gt;
{{todo | wip}}&lt;br /&gt;
&lt;br /&gt;
You can verify the integrity of your erofs/squashfs image, by comparing the hashtable. The hashtable can be a &amp;lt;b&amp;gt;file&amp;lt;/b&amp;gt; or a &amp;lt;b&amp;gt;partition&amp;lt;/b&amp;gt;. &lt;br /&gt;
* The partition should be at least 10 percent the size of the final root-image squashfs/erofs. &lt;br /&gt;
* When making a hashtable, running veritysetup should also provide a root hash. Keep this roothash for later use when unlocking the device via a kernel parameter/in the initramfs.&lt;br /&gt;
&lt;br /&gt;
==== Working with mkinitfs/kernel-hooks/secureboot-hooks ====&lt;br /&gt;
{{todo| wip}}&lt;br /&gt;
&lt;br /&gt;
Using mkinitfs, it is possible to force veritysetup in initramfs generation. It is recommended to make a chroot or docker so you don&#039;t mess with your system files, and by adding these files:&lt;br /&gt;
&lt;br /&gt;
{{todo| The init script is too big to put in wiki, I just acquired it from initramfs generation and decompression (read the tip below)}}&lt;br /&gt;
{{note| the APK package &amp;quot;cryptsetup&amp;quot; comes with veritysetup&lt;br /&gt;
{{cmd| apk add cryptsetup}}&lt;br /&gt;
}}&lt;br /&gt;
{{note| make sure the chroot has a linux-kernel}}&lt;br /&gt;
&lt;br /&gt;
Edit /sbin/mkinitfs (put &amp;quot;# Copy custom init&amp;quot; before &amp;quot;# copy modloop signature&amp;quot;):&lt;br /&gt;
{{cat| /etc/mkinitfs|...&lt;br /&gt;
        # Copy custom init &lt;br /&gt;
        cp /initramfs/init &amp;quot;$tmpdir&amp;quot;/init &lt;br /&gt;
        &lt;br /&gt;
        # copy modloop signature&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
PUT &amp;quot;# Call custom script&amp;quot; before &amp;quot;if [ &amp;quot;$SINGLEMODE&amp;quot; = &amp;quot;yes&amp;quot; ]; then&amp;quot;&lt;br /&gt;
{{cat| /initramfs/init|...&lt;br /&gt;
                # Call custom script&lt;br /&gt;
                /etc/scripts/my-custom-script.sh&lt;br /&gt;
                &lt;br /&gt;
        if [ &amp;quot;$SINGLEMODE&amp;quot; {{=}} &amp;quot;yes&amp;quot; ]; then&lt;br /&gt;
...&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/my-custom-script.files|&lt;br /&gt;
/etc/scripts/my-custom-script.sh&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/veritysetup.files|&lt;br /&gt;
/sbin/veritysetup&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/veritysetup.modules|&lt;br /&gt;
kernel/drivers/md/dm-verity.ko*&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/erofs.modules|&lt;br /&gt;
kernel/fs/erofs&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/mkinitfs.conf|...&lt;br /&gt;
features{{=}}&amp;quot;... erofs my-custom-script veritysetup&amp;quot;&lt;br /&gt;
MODULES{{=}}&amp;quot;veritysetup erofs&amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
{{cat| /etc/scripts/my-custom-script.sh|&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
mount /dev/mapper/root /root&lt;br /&gt;
mount /root/var/root/erofs.img /sysroot&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Then just do:&lt;br /&gt;
{{cmd| apk add secureboot-hook gummiboot gummiboot-efistub efibootmgr kernel-hooks secureboot-hook}}&lt;br /&gt;
&lt;br /&gt;
{{tip|To make sure initramfs has the scripts needed, do:&lt;br /&gt;
{{cmd|mkinitfs -c /etc/mkinitfs/mkinitfs.conf -b / $(uname -r)}}&lt;br /&gt;
Decompress:&lt;br /&gt;
{{cmd|mkdir /tmp/initramfs&lt;br /&gt;
cd /tmp/initramfs&lt;br /&gt;
&amp;lt;nowiki&amp;gt;zcat /boot/initramfs-$KERNEL | cpio -idmv&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Test if &amp;quot;init&amp;quot; works by just executing it and see how it runs:&lt;br /&gt;
{{cmd|./init}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Working with Dracut ====&lt;br /&gt;
&lt;br /&gt;
Remember, mount your &amp;lt;code&amp;gt;$ROOT_PARTITION&amp;lt;/code&amp;gt; as read only (assuming you use EXT4, if using ERO-FS or SquashFS, ignore this), since any changes will cause DM-Verity to detect it as &amp;quot;corrupt&amp;quot;&lt;br /&gt;
&lt;br /&gt;
{{warning| The following guide was done with FULL disk encryption, so this might not work perfectly on Non encrypted disk setup, also done on UEFI using gummiboot (now called systemd-boot - yes, systemd-boot is a separate project from the systemd init system) EFIStub and generating a UKI (Unified Kernel Image)}}&lt;br /&gt;
&lt;br /&gt;
===== Install basic stuff: =====&lt;br /&gt;
&lt;br /&gt;
{{cmd| apk add dracut dracut-core cryptsetup gummiboot gummiboot-efistub tpm2-tools clevis tpm2-tss tpm2-tss-tcti-device}}&lt;br /&gt;
&lt;br /&gt;
===== Using Clevis for TPM =====&lt;br /&gt;
&lt;br /&gt;
{{cmd| clevis luks bind -d /$ENCRYPTED_ROOT_PARTITION tpm2 &#039;{&amp;quot;pcr_ids&amp;quot;:&amp;quot;1,7&amp;quot;}&#039;}}&lt;br /&gt;
Input LUKS passphrase, remember that yes now it has tpm, but if possible remove old luks passphrase and use keyfile or different passphrase to unlock because tpm is better, and so if your computer breaks, you won&#039;t be locked out of your data!&lt;br /&gt;
&lt;br /&gt;
===== Create a new partition for your DM-Verity: =====&lt;br /&gt;
&lt;br /&gt;
Replace /dev/sdX with your actual device name.&lt;br /&gt;
{{cmd| sudo fdisk /dev/sdX}}&lt;br /&gt;
&lt;br /&gt;
Once in the fdisk interface:&lt;br /&gt;
# Press n to create a new partition&lt;br /&gt;
# Choose p for primary partition&lt;br /&gt;
# Select the partition number (e.g., 4)&lt;br /&gt;
# For the first sector, press Enter to use the default&lt;br /&gt;
# For the last sector, calculate 10% of your root partition size and use +SIZE format. For example, if your root partition is 100GB, enter +10G&lt;br /&gt;
# Press t to change the partition type&lt;br /&gt;
# Enter the partition number you just created&lt;br /&gt;
# Type 8e for Linux LVM type (closest to verity)&lt;br /&gt;
# Press w to write changes and exit&lt;br /&gt;
&lt;br /&gt;
===== Adding custom lines for full disk decryption =====&lt;br /&gt;
&lt;br /&gt;
Edit &amp;quot;&amp;lt;code&amp;gt;/usr/lib/dracut/modules.d/90crypt/cryptroot-ask.sh&amp;lt;/code&amp;gt;&amp;quot; and add these lines right BEFORE &amp;quot;&amp;lt;code&amp;gt;exit 0&amp;lt;/code&amp;gt;&amp;quot; (add your &amp;lt;code&amp;gt;$ROOT_PARTITION&amp;lt;/code&amp;gt; directory and &amp;lt;code&amp;gt;$VERITY_PARTITION&amp;lt;/code&amp;gt; directory):&lt;br /&gt;
&lt;br /&gt;
{{cat| /usr/lib/dracut/modules.d/90crypt/cryptroot-ask.sh|...&lt;br /&gt;
### DM-Verity&lt;br /&gt;
mount /dev/mapper/$ROOT_PARTITION /var/tmp&lt;br /&gt;
cryptsetup open --key-file /var/tmp/$KEYFILE_DIR /dev/$VERITY_PARTITION $VERITY_DM_NAME&lt;br /&gt;
umount /var/tmp&lt;br /&gt;
veritysetup open /dev/$ROOT_PARTITION /dev/$VERITY_PARTITION $(cat /usr/lib/dracut/roothash.txt)&lt;br /&gt;
###&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
===== Generating an EFIStub with Dracut + DM-Verity =====&lt;br /&gt;
&lt;br /&gt;
To setup DM-Verity (borrowed from [https://wiki.archlinux.org/title/Dm-verity Arch Linux Wiki]):&lt;br /&gt;
&lt;br /&gt;
{{cmd| veritysetup format /dev/$ROOT_PARTITION /dev/$VERITY_PARTITION | grep Root | cut -f2 &amp;gt;&amp;gt; /usr/lib/dracut/roothash.txt}}&lt;br /&gt;
&lt;br /&gt;
/etc/dracut.conf (put whatever your boot parameters are in &amp;quot;&amp;lt;code&amp;gt;kernel_cmdline&amp;lt;/code&amp;gt;&amp;quot;):&lt;br /&gt;
&lt;br /&gt;
{{cat| /etc/dracut.conf|...&lt;br /&gt;
kernel_cmdline{{=}}&amp;quot;&amp;quot;&lt;br /&gt;
add_dracutdrivers+{{=}}&amp;quot; busybox crypt crypt-gpg dm rootfs-block kernel-modules kernel-modules-extra tpm2-tss &amp;quot;&lt;br /&gt;
/etc/dracut.conf.d/secureboot.conf&lt;br /&gt;
&lt;br /&gt;
# Do the 3 lines below this if you have your own secureboot keys, or want to use secureboot:&lt;br /&gt;
uefi_secureboot_cert{{=}}&amp;quot;/$SECUREBOOT_KEYS_DIR/db.crt&amp;quot;&lt;br /&gt;
uefi_secureboot_key{{=}}&amp;quot;/$SECUREBOOT_KEYS_DIR/db.key&amp;quot;&lt;br /&gt;
/etc/dracut.conf.d/files.conf&lt;br /&gt;
&lt;br /&gt;
# This is what will import veritysetup binary file into dracut initramfs&lt;br /&gt;
install_items+{{=}}&amp;quot; /sbin/veritysetup &amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
Finally, generate UKI using dracut (replace &amp;lt;code&amp;gt;6.X.X-X-lts&amp;lt;/code&amp;gt; with your kernel &amp;lt;code&amp;gt;$VERSION&amp;lt;/code&amp;gt;) (also replace &amp;lt;code&amp;gt;/boot/efi/EFI/Linux/alpine-linux.efi&amp;lt;/code&amp;gt; with your mount efi partition):&lt;br /&gt;
&lt;br /&gt;
{{cmd| export DRACUT_KMODDIR_OVERRIDE{{=}}1}}&lt;br /&gt;
{{cmd| dracut --include /usr/lib/dracut/roothash.txt /usr/lib/dracut/roothash.txt --host-only --kernel-image /boot/vmlinuz-lts --kmoddir /lib/modules/6.X.X-X-lts --kver 6.X.X-X-lts --uefi --uefi-stub /usr/lib/gummiboot/linuxx64.efi.stub --force --compress lz4 /boot/efi/EFI/Linux/alpine-linux.efi /boot/efi/EFI/Linux/alpine-linux.efi}}&lt;br /&gt;
{{cmd| efibootmgr --create --disk /dev/$EFI_PARTITION --part 1 --label alpine-linux --loader EFI/Linux/alpine-linux.efi}}&lt;br /&gt;
&lt;br /&gt;
Unfortunately, using the default Alpine Linux kernel (&amp;lt;code&amp;gt;linux-lts&amp;lt;/code&amp;gt;) didn&#039;t work so download another distributions root system (like debians or devuan), and replace &amp;lt;code&amp;gt;/lib/modules/6.X.X-X-lts&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;/boot/vmlinuz-lts&amp;lt;/code&amp;gt; with anothers distributions kernel modules and kernel image (Or consider compiling your [https://wiki.alpinelinux.org/wiki/Hardened_linux own linux-hardened kernel] [11]).&lt;br /&gt;
&lt;br /&gt;
{{tip| If you want to test if DM-Verity fully works, change the &amp;lt;code&amp;gt;$ROOT_PARTITION&amp;lt;/code&amp;gt;&#039;s files and it should say it is &amp;quot;corrupt&amp;quot;, and not continue the boot process (only if you use EXT4).}}&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
==== Root of Trust/Chain of Trust ====&lt;br /&gt;
* [https://en.wikipedia.org/wiki/Chain_of_trust https://en.wikipedia.org/wiki/Chain_of_trust] [1]&lt;br /&gt;
==== Full disk encryption with LVM and LUKS (AlpineWiki): ====&lt;br /&gt;
* [https://wiki.alpinelinux.org/wiki/LVM_on_LUKS LVM_on_LUKS] [2]&lt;br /&gt;
==== Clevis Github ====&lt;br /&gt;
* [https://github.com/latchset/clevis?tab=readme-ov-file#pin-tpm2 https://github.com/latchset/clevis?tab=readme-ov-file#pin-tpm2] [3]&lt;br /&gt;
==== AppArmor Wiki (AlpineWiki) ====&lt;br /&gt;
* [https://wiki.alpinelinux.org/wiki/AppArmor AppArmor] [4]&lt;br /&gt;
==== GVisor ====&lt;br /&gt;
* [https://gvisor.dev/docs/user_guide/install/ https://gvisor.dev/docs/user_guide/install/] [5]&lt;br /&gt;
==== Gvisor Github stating docker is not a sandbox ====&lt;br /&gt;
* [https://github.com/google/gvisor?tab=readme-ov-file#why-does-gvisor-exist https://github.com/google/gvisor?tab=readme-ov-file#why-does-gvisor-exist] [6]&lt;br /&gt;
==== Android-13 Possibility of using ERO-FS: ====&lt;br /&gt;
* [https://pocketnow.com/erofs-android-13-explained/ https://pocketnow.com/erofs-android-13-explained/] [7]&lt;br /&gt;
==== DM-Verity (Arch Wiki): ====&lt;br /&gt;
* [https://wiki.archlinux.org/title/Dm-verity https://wiki.archlinux.org/title/Dm-verity] [8]&lt;br /&gt;
==== ERO-FS Github ====&lt;br /&gt;
* [https://github.com/erofs/erofs-utils https://github.com/erofs/erofs-utils] [9]&lt;br /&gt;
==== Dracut (Arch Wiki): ====&lt;br /&gt;
* [https://wiki.archlinux.org/title/Dracut https://wiki.archlinux.org/title/Dracut] [10]&lt;br /&gt;
==== Linux-Hardened Kernel (AlpineWiki): ====&lt;br /&gt;
* [https://wiki.alpinelinux.org/wiki/Hardened_linux Hardened_linux] [11]&lt;br /&gt;
==== My old post on how it worked ====&lt;br /&gt;
* [https://www.reddit.com/r/AlpineLinux/comments/15oibcc/comment/k1l7jv0/ https://www.reddit.com/r/AlpineLinux/comments/15oibcc/comment/k1l7jv0/] [12]&lt;br /&gt;
&lt;br /&gt;
[[Category:Security]] [[Category:Booting]]&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=DM-verity&amp;diff=28858</id>
		<title>DM-verity</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=DM-verity&amp;diff=28858"/>
		<updated>2025-01-21T21:21:42Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{todo| Add a non-initramfs dm-verity implementation, which should use kernel to do dm-verity checking instead of initramfs, which is better for embedded devices, and faster to boot (but hard to implement because of kernel customizations, might need to compile kernel again.)}}&lt;br /&gt;
&lt;br /&gt;
== Why DM-Verity? ==&lt;br /&gt;
Possibly you want to continue the RoT ([https://en.wikipedia.org/wiki/Chain_of_trust Root of Trust] [1]) - from the hardware (Hardware TPM as Root of Trust, which ensures only the hardware with the correct secret cryptographic key in the TPM to decrypt the disk/file encryption) -&amp;gt; secure boot (Secure Boot to only run approved signed EFIStub/signed Bootloader) -&amp;gt; &amp;lt;u&amp;gt;To NOW DM-Verity rootfs&amp;lt;/u&amp;gt; (which ensures your root-image/root-parition has not been tampered with) -&amp;gt; Mandatory Access Control (AppArmor or SELinux - SELinux is disabled on default linux-lts btw) -&amp;gt; Sandboxed/Virtual-Machined Applications.&lt;br /&gt;
&lt;br /&gt;
=== What&#039;s the difference between me just setting the root partition as read-only (basically just an Immutable Root Partition) vs this? ===&lt;br /&gt;
DM-Verity COMPLETELY disallows modifying any files in the root-partition/root-image, or even disallow a part of a root-image/root-partition (the root-image/root-partition needs to be INTACT and match the signed cryptography verified by DM-Verity on a different partition), and with this consideration, you may use ERO-FS or SquashFS to generate Read-Only Root-Paritition/File Images. If you set your EXT4 file system to writable, and DM-Verity were to use it, it would be seen as &amp;quot;corrupted&amp;quot; and not boot anymore, because even just ONE tiny data change to the root image/partition would render it &amp;quot;corrupted&amp;quot;. This is the same technology used in Android and Chrome OS Devices. Also related to use in A/B root, also used by Fedora.&lt;br /&gt;
&lt;br /&gt;
{{tip| To keep the security reasonable, you would ideally want to work on the whole RoT, if not then anybody else can attack the non-verifed boot process that ISN&#039;T the root-partition/root-image that is enforced by DM-Verity.&lt;br /&gt;
* This following guide will use dracut to make a signed secureboot-able EFIStub.&lt;br /&gt;
* If you haven&#039;t, you may follow [https://wiki.alpinelinux.org/wiki/LVM_on_LUKS the Alpine Linux disk encryption setup] [2] with DM-Crypt LUKS and LVM&lt;br /&gt;
* You may choose to decrypt the image with TPM when generating with Dracut Modules with &amp;lt;code&amp;gt;add_dracutdrivers+{{=}}&amp;quot; ... tpm2-tss ... &amp;quot;&amp;lt;/code&amp;gt; and [https://github.com/latchset/clevis?tab{{=}}readme-ov-file#pin-tpm2 Clevis] [3]&lt;br /&gt;
* Apply AppArmor using [https://wiki.alpinelinux.org/wiki/AppArmor Alpine Linux AppArmor Wiki] (Docker does use AppArmor already, but you may apply an AppArmor profile on any application that should not have access to specific directories (AppArmor is a PATH based MAC)) [4]&lt;br /&gt;
* Use [https://gvisor.dev/docs/user_guide/install/ GVisor] [5] with Docker ([https://github.com/google/gvisor?tab{{=}}readme-ov-file#why-does-gvisor-exist Docker is NOT a sandbox] [6] (Because docker uses native kernel compared to Gvisor using its own kernel reimplementation)) for sandboxing on servers}}&lt;br /&gt;
&lt;br /&gt;
=== What is ERO-FS? ===&lt;br /&gt;
[https://pocketnow.com/erofs-android-13-explained/ Google thought about implementing ERO-FS with DM-Verity] [7]. Google was reported to be using it in Android 13, and ERO-FS is an excellent and fast compressed read-only filesystem.&lt;br /&gt;
&lt;br /&gt;
Here is an excerpt about &amp;lt;code&amp;gt;mkfs.erofs&amp;lt;/code&amp;gt; on [[https://wiki.archlinux.org/title/Dm-verity Arch Linux Wiki]] [8]:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039; mkfs.erofs(1) offers an attractive alternative to ext4 or squashfs on the root partition. EROFS, like squashfs, does not allow writes by design and has better performance in many cases than comparable filesystems on flash and solid-state media. It uses lz4 compression by default and was designed for Android phones by Huawei, which make extensive use of dm-verity. &#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Installing ===&lt;br /&gt;
&lt;br /&gt;
==== Working with ERO-FS ====&lt;br /&gt;
&lt;br /&gt;
{{warning| This wiki will be using Alpine Linux Edge Version. (Alpine Linux Non-Edge Versions may not contain these packages in the following rest of the wiki page) (Use Alpine Linux Edge Testing Repository in &amp;lt;code&amp;gt;/etc/apk/repositories&amp;lt;/code&amp;gt; as well)}}&lt;br /&gt;
&lt;br /&gt;
{{note| To not be confused, ERO-FS generates a &amp;quot;root image&amp;quot;, but you can replace the words &amp;quot;root partition&amp;quot; with &amp;quot;root image&amp;quot; and vice versa.}}&lt;br /&gt;
&lt;br /&gt;
First, some considerations, you may use a strictly READ-ONLY file system, such as SquashFS or ERO-FS, this wiki will be using ERO-FS (if you use a custom kernel, make sure it supports a file system such as ERO-FS, the default linux-lts does). [[https://github.com/erofs/erofs-utils ERO-FS Github]] [9] contains some information about how to compress and make your own read-only root image.&lt;br /&gt;
&lt;br /&gt;
{{cmd| $ apk install erofs-utils}}&lt;br /&gt;
{{cmd| $ mkdir image &amp;amp;&amp;amp; cd image }}&lt;br /&gt;
{{cmd| $ wget https://dl-cdn.alpinelinux.org/alpine/v3.21/releases/x86_64/alpine-minirootfs-3.21.0-x86_64.tar.gz}}&lt;br /&gt;
{{cmd| $ tar -xvf alpine-minirootfs-3.21.0-x86_64.tar.gz &amp;amp;&amp;amp; rm alpine-minirootfs-3.21.0-x86_64.tar.gz}}&lt;br /&gt;
Command below will generate an ERO-FS Image compressed with lz4 as ./erofs.img (erofs.img would be the root-partition file to use for dracut)&lt;br /&gt;
{{cmd| $ cd .. &amp;amp;&amp;amp; mkfs.erofs -zlz4hc erofs.img ./image}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Choose between a file or a partition ====&lt;br /&gt;
{{todo | wip}}&lt;br /&gt;
You can verify the integrity of your erofs/squashfs image, by comparing the hashtable. the hashtable can be a &amp;lt;b&amp;gt;file&amp;lt;/b&amp;gt; or a &amp;lt;b&amp;gt;partition&amp;lt;/b&amp;gt;. The partition should be at least 10 percent the size of the final root-image squashfs/erofs. &lt;br /&gt;
&lt;br /&gt;
==== Working with mkinitfs/kernel-hooks/secureboot-hooks ====&lt;br /&gt;
{{todo| wip}}&lt;br /&gt;
&lt;br /&gt;
Using mkinitfs, it is possible to force veritysetup in initramfs generation. It is recommended to make a chroot or docker so you don&#039;t mess with your system files, and by adding these files:&lt;br /&gt;
&lt;br /&gt;
{{todo| The init script is too big to put in wiki, I just acquired it from initramfs generation and decompression (read the tip below)}}&lt;br /&gt;
{{note| the APK package &amp;quot;cryptsetup&amp;quot; comes with veritysetup&lt;br /&gt;
{{cmd| apk add cryptsetup}}&lt;br /&gt;
}}&lt;br /&gt;
{{note| make sure the chroot has a linux-kernel}}&lt;br /&gt;
&lt;br /&gt;
Edit /sbin/mkinitfs (put &amp;quot;# Copy custom init&amp;quot; before &amp;quot;# copy modloop signature&amp;quot;):&lt;br /&gt;
{{cat| /etc/mkinitfs|...&lt;br /&gt;
        # Copy custom init &lt;br /&gt;
        cp /initramfs/init &amp;quot;$tmpdir&amp;quot;/init &lt;br /&gt;
        &lt;br /&gt;
        # copy modloop signature&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
PUT &amp;quot;# Call custom script&amp;quot; before &amp;quot;if [ &amp;quot;$SINGLEMODE&amp;quot; = &amp;quot;yes&amp;quot; ]; then&amp;quot;&lt;br /&gt;
{{cat| /initramfs/init|...&lt;br /&gt;
                # Call custom script&lt;br /&gt;
                /etc/scripts/my-custom-script.sh&lt;br /&gt;
                &lt;br /&gt;
        if [ &amp;quot;$SINGLEMODE&amp;quot; {{=}} &amp;quot;yes&amp;quot; ]; then&lt;br /&gt;
...&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/my-custom-script.files|&lt;br /&gt;
/etc/scripts/my-custom-script.sh&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/veritysetup.files|&lt;br /&gt;
/sbin/veritysetup&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/veritysetup.modules|&lt;br /&gt;
kernel/drivers/md/dm-verity.ko*&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/erofs.modules|&lt;br /&gt;
kernel/fs/erofs&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/mkinitfs.conf|...&lt;br /&gt;
features{{=}}&amp;quot;... erofs my-custom-script veritysetup&amp;quot;&lt;br /&gt;
MODULES{{=}}&amp;quot;veritysetup erofs&amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
{{cat| /etc/scripts/my-custom-script.sh|&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
mount /dev/mapper/root /root&lt;br /&gt;
mount /root/var/root/erofs.img /sysroot&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Then just do:&lt;br /&gt;
{{cmd| apk add secureboot-hook gummiboot gummiboot-efistub efibootmgr kernel-hooks secureboot-hook}}&lt;br /&gt;
&lt;br /&gt;
{{tip|To make sure initramfs has the scripts needed, do:&lt;br /&gt;
{{cmd|mkinitfs -c /etc/mkinitfs/mkinitfs.conf -b / $(uname -r)}}&lt;br /&gt;
Decompress:&lt;br /&gt;
{{cmd|mkdir /tmp/initramfs&lt;br /&gt;
cd /tmp/initramfs&lt;br /&gt;
&amp;lt;nowiki&amp;gt;zcat /boot/initramfs-$KERNEL | cpio -idmv&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Test if &amp;quot;init&amp;quot; works by just executing it and see how it runs:&lt;br /&gt;
{{cmd|./init}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Working with Dracut ====&lt;br /&gt;
&lt;br /&gt;
Remember, mount your &amp;lt;code&amp;gt;$ROOT_PARTITION&amp;lt;/code&amp;gt; as read only (assuming you use EXT4, if using ERO-FS or SquashFS, ignore this), since any changes will cause DM-Verity to detect it as &amp;quot;corrupt&amp;quot;&lt;br /&gt;
&lt;br /&gt;
{{warning| The following guide was done with FULL disk encryption, so this might not work perfectly on Non encrypted disk setup, also done on UEFI using gummiboot (now called systemd-boot - yes, systemd-boot is a separate project from the systemd init system) EFIStub and generating a UKI (Unified Kernel Image)}}&lt;br /&gt;
&lt;br /&gt;
===== Install basic stuff: =====&lt;br /&gt;
&lt;br /&gt;
{{cmd| apk add dracut dracut-core cryptsetup gummiboot gummiboot-efistub tpm2-tools clevis tpm2-tss tpm2-tss-tcti-device}}&lt;br /&gt;
&lt;br /&gt;
===== Using Clevis for TPM =====&lt;br /&gt;
&lt;br /&gt;
{{cmd| clevis luks bind -d /$ENCRYPTED_ROOT_PARTITION tpm2 &#039;{&amp;quot;pcr_ids&amp;quot;:&amp;quot;1,7&amp;quot;}&#039;}}&lt;br /&gt;
Input LUKS passphrase, remember that yes now it has tpm, but if possible remove old luks passphrase and use keyfile or different passphrase to unlock because tpm is better, and so if your computer breaks, you won&#039;t be locked out of your data!&lt;br /&gt;
&lt;br /&gt;
===== Create a new partition for your DM-Verity: =====&lt;br /&gt;
&lt;br /&gt;
Replace /dev/sdX with your actual device name.&lt;br /&gt;
{{cmd| sudo fdisk /dev/sdX}}&lt;br /&gt;
&lt;br /&gt;
Once in the fdisk interface:&lt;br /&gt;
# Press n to create a new partition&lt;br /&gt;
# Choose p for primary partition&lt;br /&gt;
# Select the partition number (e.g., 4)&lt;br /&gt;
# For the first sector, press Enter to use the default&lt;br /&gt;
# For the last sector, calculate 10% of your root partition size and use +SIZE format. For example, if your root partition is 100GB, enter +10G&lt;br /&gt;
# Press t to change the partition type&lt;br /&gt;
# Enter the partition number you just created&lt;br /&gt;
# Type 8e for Linux LVM type (closest to verity)&lt;br /&gt;
# Press w to write changes and exit&lt;br /&gt;
&lt;br /&gt;
===== Adding custom lines for full disk decryption =====&lt;br /&gt;
&lt;br /&gt;
Edit &amp;quot;&amp;lt;code&amp;gt;/usr/lib/dracut/modules.d/90crypt/cryptroot-ask.sh&amp;lt;/code&amp;gt;&amp;quot; and add these lines right BEFORE &amp;quot;&amp;lt;code&amp;gt;exit 0&amp;lt;/code&amp;gt;&amp;quot; (add your &amp;lt;code&amp;gt;$ROOT_PARTITION&amp;lt;/code&amp;gt; directory and &amp;lt;code&amp;gt;$VERITY_PARTITION&amp;lt;/code&amp;gt; directory):&lt;br /&gt;
&lt;br /&gt;
{{cat| /usr/lib/dracut/modules.d/90crypt/cryptroot-ask.sh|...&lt;br /&gt;
### DM-Verity&lt;br /&gt;
mount /dev/mapper/$ROOT_PARTITION /var/tmp&lt;br /&gt;
cryptsetup open --key-file /var/tmp/$KEYFILE_DIR /dev/$VERITY_PARTITION $VERITY_DM_NAME&lt;br /&gt;
umount /var/tmp&lt;br /&gt;
veritysetup open /dev/$ROOT_PARTITION /dev/$VERITY_PARTITION $(cat /usr/lib/dracut/roothash.txt)&lt;br /&gt;
###&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
===== Generating an EFIStub with Dracut + DM-Verity =====&lt;br /&gt;
&lt;br /&gt;
To setup DM-Verity (borrowed from [https://wiki.archlinux.org/title/Dm-verity Arch Linux Wiki]):&lt;br /&gt;
&lt;br /&gt;
{{cmd| veritysetup format /dev/$ROOT_PARTITION /dev/$VERITY_PARTITION | grep Root | cut -f2 &amp;gt;&amp;gt; /usr/lib/dracut/roothash.txt}}&lt;br /&gt;
&lt;br /&gt;
/etc/dracut.conf (put whatever your boot parameters are in &amp;quot;&amp;lt;code&amp;gt;kernel_cmdline&amp;lt;/code&amp;gt;&amp;quot;):&lt;br /&gt;
&lt;br /&gt;
{{cat| /etc/dracut.conf|...&lt;br /&gt;
kernel_cmdline{{=}}&amp;quot;&amp;quot;&lt;br /&gt;
add_dracutdrivers+{{=}}&amp;quot; busybox crypt crypt-gpg dm rootfs-block kernel-modules kernel-modules-extra tpm2-tss &amp;quot;&lt;br /&gt;
/etc/dracut.conf.d/secureboot.conf&lt;br /&gt;
&lt;br /&gt;
# Do the 3 lines below this if you have your own secureboot keys, or want to use secureboot:&lt;br /&gt;
uefi_secureboot_cert{{=}}&amp;quot;/$SECUREBOOT_KEYS_DIR/db.crt&amp;quot;&lt;br /&gt;
uefi_secureboot_key{{=}}&amp;quot;/$SECUREBOOT_KEYS_DIR/db.key&amp;quot;&lt;br /&gt;
/etc/dracut.conf.d/files.conf&lt;br /&gt;
&lt;br /&gt;
# This is what will import veritysetup binary file into dracut initramfs&lt;br /&gt;
install_items+{{=}}&amp;quot; /sbin/veritysetup &amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
Finally, generate UKI using dracut (replace &amp;lt;code&amp;gt;6.X.X-X-lts&amp;lt;/code&amp;gt; with your kernel &amp;lt;code&amp;gt;$VERSION&amp;lt;/code&amp;gt;) (also replace &amp;lt;code&amp;gt;/boot/efi/EFI/Linux/alpine-linux.efi&amp;lt;/code&amp;gt; with your mount efi partition):&lt;br /&gt;
&lt;br /&gt;
{{cmd| export DRACUT_KMODDIR_OVERRIDE{{=}}1}}&lt;br /&gt;
{{cmd| dracut --include /usr/lib/dracut/roothash.txt /usr/lib/dracut/roothash.txt --host-only --kernel-image /boot/vmlinuz-lts --kmoddir /lib/modules/6.X.X-X-lts --kver 6.X.X-X-lts --uefi --uefi-stub /usr/lib/gummiboot/linuxx64.efi.stub --force --compress lz4 /boot/efi/EFI/Linux/alpine-linux.efi /boot/efi/EFI/Linux/alpine-linux.efi}}&lt;br /&gt;
{{cmd| efibootmgr --create --disk /dev/$EFI_PARTITION --part 1 --label alpine-linux --loader EFI/Linux/alpine-linux.efi}}&lt;br /&gt;
&lt;br /&gt;
Unfortunately, using the default Alpine Linux kernel (&amp;lt;code&amp;gt;linux-lts&amp;lt;/code&amp;gt;) didn&#039;t work so download another distributions root system (like debians or devuan), and replace &amp;lt;code&amp;gt;/lib/modules/6.X.X-X-lts&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;/boot/vmlinuz-lts&amp;lt;/code&amp;gt; with anothers distributions kernel modules and kernel image (Or consider compiling your [https://wiki.alpinelinux.org/wiki/Hardened_linux own linux-hardened kernel] [11]).&lt;br /&gt;
&lt;br /&gt;
{{tip| If you want to test if DM-Verity fully works, change the &amp;lt;code&amp;gt;$ROOT_PARTITION&amp;lt;/code&amp;gt;&#039;s files and it should say it is &amp;quot;corrupt&amp;quot;, and not continue the boot process (only if you use EXT4).}}&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
==== Root of Trust/Chain of Trust ====&lt;br /&gt;
* [https://en.wikipedia.org/wiki/Chain_of_trust https://en.wikipedia.org/wiki/Chain_of_trust] [1]&lt;br /&gt;
==== Full disk encryption with LVM and LUKS (AlpineWiki): ====&lt;br /&gt;
* [https://wiki.alpinelinux.org/wiki/LVM_on_LUKS LVM_on_LUKS] [2]&lt;br /&gt;
==== Clevis Github ====&lt;br /&gt;
* [https://github.com/latchset/clevis?tab=readme-ov-file#pin-tpm2 https://github.com/latchset/clevis?tab=readme-ov-file#pin-tpm2] [3]&lt;br /&gt;
==== AppArmor Wiki (AlpineWiki) ====&lt;br /&gt;
* [https://wiki.alpinelinux.org/wiki/AppArmor AppArmor] [4]&lt;br /&gt;
==== GVisor ====&lt;br /&gt;
* [https://gvisor.dev/docs/user_guide/install/ https://gvisor.dev/docs/user_guide/install/] [5]&lt;br /&gt;
==== Gvisor Github stating docker is not a sandbox ====&lt;br /&gt;
* [https://github.com/google/gvisor?tab=readme-ov-file#why-does-gvisor-exist https://github.com/google/gvisor?tab=readme-ov-file#why-does-gvisor-exist] [6]&lt;br /&gt;
==== Android-13 Possibility of using ERO-FS: ====&lt;br /&gt;
* [https://pocketnow.com/erofs-android-13-explained/ https://pocketnow.com/erofs-android-13-explained/] [7]&lt;br /&gt;
==== DM-Verity (Arch Wiki): ====&lt;br /&gt;
* [https://wiki.archlinux.org/title/Dm-verity https://wiki.archlinux.org/title/Dm-verity] [8]&lt;br /&gt;
==== ERO-FS Github ====&lt;br /&gt;
* [https://github.com/erofs/erofs-utils https://github.com/erofs/erofs-utils] [9]&lt;br /&gt;
==== Dracut (Arch Wiki): ====&lt;br /&gt;
* [https://wiki.archlinux.org/title/Dracut https://wiki.archlinux.org/title/Dracut] [10]&lt;br /&gt;
==== Linux-Hardened Kernel (AlpineWiki): ====&lt;br /&gt;
* [https://wiki.alpinelinux.org/wiki/Hardened_linux Hardened_linux] [11]&lt;br /&gt;
==== My old post on how it worked ====&lt;br /&gt;
* [https://www.reddit.com/r/AlpineLinux/comments/15oibcc/comment/k1l7jv0/ https://www.reddit.com/r/AlpineLinux/comments/15oibcc/comment/k1l7jv0/] [12]&lt;br /&gt;
&lt;br /&gt;
[[Category:Security]] [[Category:Booting]]&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=DM-verity&amp;diff=28857</id>
		<title>DM-verity</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=DM-verity&amp;diff=28857"/>
		<updated>2025-01-21T21:21:00Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{todo| Add a non-initramfs dm-verity implementation, which should use kernel to do dm-verity checking instead of initramfs, which is better for embedded devices, and faster to boot (but hard to implement because of kernel customizations, might need to compile kernel again.)}}&lt;br /&gt;
&lt;br /&gt;
== Why DM-Verity? ==&lt;br /&gt;
Possibly you want to continue the RoT ([https://en.wikipedia.org/wiki/Chain_of_trust Root of Trust] [1]) - from the hardware (Hardware TPM as Root of Trust, which ensures only the hardware with the correct secret cryptographic key in the TPM to decrypt the disk/file encryption) -&amp;gt; secure boot (Secure Boot to only run approved signed EFIStub/signed Bootloader) -&amp;gt; &amp;lt;u&amp;gt;To NOW DM-Verity rootfs&amp;lt;/u&amp;gt; (which ensures your root-image/root-parition has not been tampered with) -&amp;gt; Mandatory Access Control (AppArmor or SELinux - SELinux is disabled on default linux-lts btw) -&amp;gt; Sandboxed/Virtual-Machined Applications.&lt;br /&gt;
&lt;br /&gt;
=== What&#039;s the difference between me just setting the root partition as read-only (basically just an Immutable Root Partition) vs this? ===&lt;br /&gt;
DM-Verity COMPLETELY disallows modifying any files in the root-partition/root-image, or even disallow a part of a root-image/root-partition (the root-image/root-partition needs to be INTACT and match the signed cryptography verified by DM-Verity on a different partition), and with this consideration, you may use ERO-FS or SquashFS to generate Read-Only Root-Paritition/File Images. If you set your EXT4 file system to writable, and DM-Verity were to use it, it would be seen as &amp;quot;corrupted&amp;quot; and not boot anymore, because even just ONE tiny data change to the root image/partition would render it &amp;quot;corrupted&amp;quot;. This is the same technology used in Android and Chrome OS Devices. Also related to use in A/B root, also used by Fedora.&lt;br /&gt;
&lt;br /&gt;
{{tip| To keep the security reasonable, you would ideally want to work on the whole RoT, if not then anybody else can attack the non-verifed boot process that ISN&#039;T the root-partition/root-image that is enforced by DM-Verity.&lt;br /&gt;
* This following guide will use dracut to make a signed secureboot-able EFIStub.&lt;br /&gt;
* If you haven&#039;t, you may follow [https://wiki.alpinelinux.org/wiki/LVM_on_LUKS the Alpine Linux disk encryption setup] [2] with DM-Crypt LUKS and LVM&lt;br /&gt;
* You may choose to decrypt the image with TPM when generating with Dracut Modules with &amp;lt;code&amp;gt;add_dracutdrivers+{{=}}&amp;quot; ... tpm2-tss ... &amp;quot;&amp;lt;/code&amp;gt; and [https://github.com/latchset/clevis?tab{{=}}readme-ov-file#pin-tpm2 Clevis] [3]&lt;br /&gt;
* Apply AppArmor using [https://wiki.alpinelinux.org/wiki/AppArmor Alpine Linux AppArmor Wiki] (Docker does use AppArmor already, but you may apply an AppArmor profile on any application that should not have access to specific directories (AppArmor is a PATH based MAC)) [4]&lt;br /&gt;
* Use [https://gvisor.dev/docs/user_guide/install/ GVisor] [5] with Docker ([https://github.com/google/gvisor?tab{{=}}readme-ov-file#why-does-gvisor-exist Docker is NOT a sandbox] [6] (Because docker uses native kernel compared to Gvisor using its own kernel reimplementation)) for sandboxing on servers}}&lt;br /&gt;
&lt;br /&gt;
=== What is ERO-FS? ===&lt;br /&gt;
[https://pocketnow.com/erofs-android-13-explained/ Google thought about implementing ERO-FS with DM-Verity] [7]. Google was reported to be using it in Android 13, and ERO-FS is an excellent and fast compressed read-only filesystem.&lt;br /&gt;
&lt;br /&gt;
Here is an excerpt about &amp;lt;code&amp;gt;mkfs.erofs&amp;lt;/code&amp;gt; on [[https://wiki.archlinux.org/title/Dm-verity Arch Linux Wiki]] [8]:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039; mkfs.erofs(1) offers an attractive alternative to ext4 or squashfs on the root partition. EROFS, like squashfs, does not allow writes by design and has better performance in many cases than comparable filesystems on flash and solid-state media. It uses lz4 compression by default and was designed for Android phones by Huawei, which make extensive use of dm-verity. &#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Installing ===&lt;br /&gt;
&lt;br /&gt;
==== Working with ERO-FS ====&lt;br /&gt;
&lt;br /&gt;
{{warning| This wiki will be using Alpine Linux Edge Version. (Alpine Linux Non-Edge Versions may not contain these packages in the following rest of the wiki page) (Use Alpine Linux Edge Testing Repository in &amp;lt;code&amp;gt;/etc/apk/repositories&amp;lt;/code&amp;gt; as well)}}&lt;br /&gt;
&lt;br /&gt;
{{note| To not be confused, ERO-FS generates a &amp;quot;root image&amp;quot;, but you can replace the words &amp;quot;root partition&amp;quot; with &amp;quot;root image&amp;quot; and vice versa.}}&lt;br /&gt;
&lt;br /&gt;
First, some considerations, you may use a strictly READ-ONLY file system, such as SquashFS or ERO-FS, this wiki will be using ERO-FS (if you use a custom kernel, make sure it supports a file system such as ERO-FS, the default linux-lts does). [[https://github.com/erofs/erofs-utils ERO-FS Github]] [9] contains some information about how to compress and make your own read-only root image.&lt;br /&gt;
&lt;br /&gt;
{{cmd| $ apk install erofs-utils}}&lt;br /&gt;
{{cmd| $ mkdir image &amp;amp;&amp;amp; cd image }}&lt;br /&gt;
{{cmd| $ wget https://dl-cdn.alpinelinux.org/alpine/v3.21/releases/x86_64/alpine-minirootfs-3.21.0-x86_64.tar.gz}}&lt;br /&gt;
{{cmd| $ tar -xvf alpine-minirootfs-3.21.0-x86_64.tar.gz &amp;amp;&amp;amp; rm alpine-minirootfs-3.21.0-x86_64.tar.gz}}&lt;br /&gt;
Command below will generate an ERO-FS Image compressed with lz4 as ./erofs.img (erofs.img would be the root-partition file to use for dracut)&lt;br /&gt;
{{cmd| $ cd .. &amp;amp;&amp;amp; mkfs.erofs -zlz4hc erofs.img ./image}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Choose between a file or a partition ====&lt;br /&gt;
{{ todo | wip}}&lt;br /&gt;
You can verify the integrity of your erofs/squashfs image, by comparing the hashtable. the hashtable can be a &amp;lt;b&amp;gt;file&amp;lt;/b&amp;gt; or a &amp;lt;b&amp;gt;partition&amp;lt;/b&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== Working with mkinitfs/kernel-hooks/secureboot-hooks ====&lt;br /&gt;
{{todo| wip}}&lt;br /&gt;
&lt;br /&gt;
Using mkinitfs, it is possible to force veritysetup in initramfs generation. It is recommended to make a chroot or docker so you don&#039;t mess with your system files, and by adding these files:&lt;br /&gt;
&lt;br /&gt;
{{todo| The init script is too big to put in wiki, I just acquired it from initramfs generation and decompression (read the tip below)}}&lt;br /&gt;
{{note| the APK package &amp;quot;cryptsetup&amp;quot; comes with veritysetup&lt;br /&gt;
{{cmd| apk add cryptsetup}}&lt;br /&gt;
}}&lt;br /&gt;
{{note| make sure the chroot has a linux-kernel}}&lt;br /&gt;
&lt;br /&gt;
Edit /sbin/mkinitfs (put &amp;quot;# Copy custom init&amp;quot; before &amp;quot;# copy modloop signature&amp;quot;):&lt;br /&gt;
{{cat| /etc/mkinitfs|...&lt;br /&gt;
        # Copy custom init &lt;br /&gt;
        cp /initramfs/init &amp;quot;$tmpdir&amp;quot;/init &lt;br /&gt;
        &lt;br /&gt;
        # copy modloop signature&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
PUT &amp;quot;# Call custom script&amp;quot; before &amp;quot;if [ &amp;quot;$SINGLEMODE&amp;quot; = &amp;quot;yes&amp;quot; ]; then&amp;quot;&lt;br /&gt;
{{cat| /initramfs/init|...&lt;br /&gt;
                # Call custom script&lt;br /&gt;
                /etc/scripts/my-custom-script.sh&lt;br /&gt;
                &lt;br /&gt;
        if [ &amp;quot;$SINGLEMODE&amp;quot; {{=}} &amp;quot;yes&amp;quot; ]; then&lt;br /&gt;
...&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/my-custom-script.files|&lt;br /&gt;
/etc/scripts/my-custom-script.sh&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/veritysetup.files|&lt;br /&gt;
/sbin/veritysetup&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/veritysetup.modules|&lt;br /&gt;
kernel/drivers/md/dm-verity.ko*&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/erofs.modules|&lt;br /&gt;
kernel/fs/erofs&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/mkinitfs.conf|...&lt;br /&gt;
features{{=}}&amp;quot;... erofs my-custom-script veritysetup&amp;quot;&lt;br /&gt;
MODULES{{=}}&amp;quot;veritysetup erofs&amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
{{cat| /etc/scripts/my-custom-script.sh|&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
mount /dev/mapper/root /root&lt;br /&gt;
mount /root/var/root/erofs.img /sysroot&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Then just do:&lt;br /&gt;
{{cmd| apk add secureboot-hook gummiboot gummiboot-efistub efibootmgr kernel-hooks secureboot-hook}}&lt;br /&gt;
&lt;br /&gt;
{{tip|To make sure initramfs has the scripts needed, do:&lt;br /&gt;
{{cmd|mkinitfs -c /etc/mkinitfs/mkinitfs.conf -b / $(uname -r)}}&lt;br /&gt;
Decompress:&lt;br /&gt;
{{cmd|mkdir /tmp/initramfs&lt;br /&gt;
cd /tmp/initramfs&lt;br /&gt;
&amp;lt;nowiki&amp;gt;zcat /boot/initramfs-$KERNEL | cpio -idmv&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Test if &amp;quot;init&amp;quot; works by just executing it and see how it runs:&lt;br /&gt;
{{cmd|./init}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Working with Dracut ====&lt;br /&gt;
&lt;br /&gt;
Remember, mount your &amp;lt;code&amp;gt;$ROOT_PARTITION&amp;lt;/code&amp;gt; as read only (assuming you use EXT4, if using ERO-FS or SquashFS, ignore this), since any changes will cause DM-Verity to detect it as &amp;quot;corrupt&amp;quot;&lt;br /&gt;
&lt;br /&gt;
{{warning| The following guide was done with FULL disk encryption, so this might not work perfectly on Non encrypted disk setup, also done on UEFI using gummiboot (now called systemd-boot - yes, systemd-boot is a separate project from the systemd init system) EFIStub and generating a UKI (Unified Kernel Image)}}&lt;br /&gt;
&lt;br /&gt;
===== Install basic stuff: =====&lt;br /&gt;
&lt;br /&gt;
{{cmd| apk add dracut dracut-core cryptsetup gummiboot gummiboot-efistub tpm2-tools clevis tpm2-tss tpm2-tss-tcti-device}}&lt;br /&gt;
&lt;br /&gt;
===== Using Clevis for TPM =====&lt;br /&gt;
&lt;br /&gt;
{{cmd| clevis luks bind -d /$ENCRYPTED_ROOT_PARTITION tpm2 &#039;{&amp;quot;pcr_ids&amp;quot;:&amp;quot;1,7&amp;quot;}&#039;}}&lt;br /&gt;
Input LUKS passphrase, remember that yes now it has tpm, but if possible remove old luks passphrase and use keyfile or different passphrase to unlock because tpm is better, and so if your computer breaks, you won&#039;t be locked out of your data!&lt;br /&gt;
&lt;br /&gt;
===== Create a new partition for your DM-Verity: =====&lt;br /&gt;
&lt;br /&gt;
Replace /dev/sdX with your actual device name.&lt;br /&gt;
{{cmd| sudo fdisk /dev/sdX}}&lt;br /&gt;
&lt;br /&gt;
Once in the fdisk interface:&lt;br /&gt;
# Press n to create a new partition&lt;br /&gt;
# Choose p for primary partition&lt;br /&gt;
# Select the partition number (e.g., 4)&lt;br /&gt;
# For the first sector, press Enter to use the default&lt;br /&gt;
# For the last sector, calculate 10% of your root partition size and use +SIZE format. For example, if your root partition is 100GB, enter +10G&lt;br /&gt;
# Press t to change the partition type&lt;br /&gt;
# Enter the partition number you just created&lt;br /&gt;
# Type 8e for Linux LVM type (closest to verity)&lt;br /&gt;
# Press w to write changes and exit&lt;br /&gt;
&lt;br /&gt;
===== Adding custom lines for full disk decryption =====&lt;br /&gt;
&lt;br /&gt;
Edit &amp;quot;&amp;lt;code&amp;gt;/usr/lib/dracut/modules.d/90crypt/cryptroot-ask.sh&amp;lt;/code&amp;gt;&amp;quot; and add these lines right BEFORE &amp;quot;&amp;lt;code&amp;gt;exit 0&amp;lt;/code&amp;gt;&amp;quot; (add your &amp;lt;code&amp;gt;$ROOT_PARTITION&amp;lt;/code&amp;gt; directory and &amp;lt;code&amp;gt;$VERITY_PARTITION&amp;lt;/code&amp;gt; directory):&lt;br /&gt;
&lt;br /&gt;
{{cat| /usr/lib/dracut/modules.d/90crypt/cryptroot-ask.sh|...&lt;br /&gt;
### DM-Verity&lt;br /&gt;
mount /dev/mapper/$ROOT_PARTITION /var/tmp&lt;br /&gt;
cryptsetup open --key-file /var/tmp/$KEYFILE_DIR /dev/$VERITY_PARTITION $VERITY_DM_NAME&lt;br /&gt;
umount /var/tmp&lt;br /&gt;
veritysetup open /dev/$ROOT_PARTITION /dev/$VERITY_PARTITION $(cat /usr/lib/dracut/roothash.txt)&lt;br /&gt;
###&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
===== Generating an EFIStub with Dracut + DM-Verity =====&lt;br /&gt;
&lt;br /&gt;
To setup DM-Verity (borrowed from [https://wiki.archlinux.org/title/Dm-verity Arch Linux Wiki]):&lt;br /&gt;
&lt;br /&gt;
{{cmd| veritysetup format /dev/$ROOT_PARTITION /dev/$VERITY_PARTITION | grep Root | cut -f2 &amp;gt;&amp;gt; /usr/lib/dracut/roothash.txt}}&lt;br /&gt;
&lt;br /&gt;
/etc/dracut.conf (put whatever your boot parameters are in &amp;quot;&amp;lt;code&amp;gt;kernel_cmdline&amp;lt;/code&amp;gt;&amp;quot;):&lt;br /&gt;
&lt;br /&gt;
{{cat| /etc/dracut.conf|...&lt;br /&gt;
kernel_cmdline{{=}}&amp;quot;&amp;quot;&lt;br /&gt;
add_dracutdrivers+{{=}}&amp;quot; busybox crypt crypt-gpg dm rootfs-block kernel-modules kernel-modules-extra tpm2-tss &amp;quot;&lt;br /&gt;
/etc/dracut.conf.d/secureboot.conf&lt;br /&gt;
&lt;br /&gt;
# Do the 3 lines below this if you have your own secureboot keys, or want to use secureboot:&lt;br /&gt;
uefi_secureboot_cert{{=}}&amp;quot;/$SECUREBOOT_KEYS_DIR/db.crt&amp;quot;&lt;br /&gt;
uefi_secureboot_key{{=}}&amp;quot;/$SECUREBOOT_KEYS_DIR/db.key&amp;quot;&lt;br /&gt;
/etc/dracut.conf.d/files.conf&lt;br /&gt;
&lt;br /&gt;
# This is what will import veritysetup binary file into dracut initramfs&lt;br /&gt;
install_items+{{=}}&amp;quot; /sbin/veritysetup &amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
Finally, generate UKI using dracut (replace &amp;lt;code&amp;gt;6.X.X-X-lts&amp;lt;/code&amp;gt; with your kernel &amp;lt;code&amp;gt;$VERSION&amp;lt;/code&amp;gt;) (also replace &amp;lt;code&amp;gt;/boot/efi/EFI/Linux/alpine-linux.efi&amp;lt;/code&amp;gt; with your mount efi partition):&lt;br /&gt;
&lt;br /&gt;
{{cmd| export DRACUT_KMODDIR_OVERRIDE{{=}}1}}&lt;br /&gt;
{{cmd| dracut --include /usr/lib/dracut/roothash.txt /usr/lib/dracut/roothash.txt --host-only --kernel-image /boot/vmlinuz-lts --kmoddir /lib/modules/6.X.X-X-lts --kver 6.X.X-X-lts --uefi --uefi-stub /usr/lib/gummiboot/linuxx64.efi.stub --force --compress lz4 /boot/efi/EFI/Linux/alpine-linux.efi /boot/efi/EFI/Linux/alpine-linux.efi}}&lt;br /&gt;
{{cmd| efibootmgr --create --disk /dev/$EFI_PARTITION --part 1 --label alpine-linux --loader EFI/Linux/alpine-linux.efi}}&lt;br /&gt;
&lt;br /&gt;
Unfortunately, using the default Alpine Linux kernel (&amp;lt;code&amp;gt;linux-lts&amp;lt;/code&amp;gt;) didn&#039;t work so download another distributions root system (like debians or devuan), and replace &amp;lt;code&amp;gt;/lib/modules/6.X.X-X-lts&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;/boot/vmlinuz-lts&amp;lt;/code&amp;gt; with anothers distributions kernel modules and kernel image (Or consider compiling your [https://wiki.alpinelinux.org/wiki/Hardened_linux own linux-hardened kernel] [11]).&lt;br /&gt;
&lt;br /&gt;
{{tip| If you want to test if DM-Verity fully works, change the &amp;lt;code&amp;gt;$ROOT_PARTITION&amp;lt;/code&amp;gt;&#039;s files and it should say it is &amp;quot;corrupt&amp;quot;, and not continue the boot process (only if you use EXT4).}}&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
==== Root of Trust/Chain of Trust ====&lt;br /&gt;
* [https://en.wikipedia.org/wiki/Chain_of_trust https://en.wikipedia.org/wiki/Chain_of_trust] [1]&lt;br /&gt;
==== Full disk encryption with LVM and LUKS (AlpineWiki): ====&lt;br /&gt;
* [https://wiki.alpinelinux.org/wiki/LVM_on_LUKS LVM_on_LUKS] [2]&lt;br /&gt;
==== Clevis Github ====&lt;br /&gt;
* [https://github.com/latchset/clevis?tab=readme-ov-file#pin-tpm2 https://github.com/latchset/clevis?tab=readme-ov-file#pin-tpm2] [3]&lt;br /&gt;
==== AppArmor Wiki (AlpineWiki) ====&lt;br /&gt;
* [https://wiki.alpinelinux.org/wiki/AppArmor AppArmor] [4]&lt;br /&gt;
==== GVisor ====&lt;br /&gt;
* [https://gvisor.dev/docs/user_guide/install/ https://gvisor.dev/docs/user_guide/install/] [5]&lt;br /&gt;
==== Gvisor Github stating docker is not a sandbox ====&lt;br /&gt;
* [https://github.com/google/gvisor?tab=readme-ov-file#why-does-gvisor-exist https://github.com/google/gvisor?tab=readme-ov-file#why-does-gvisor-exist] [6]&lt;br /&gt;
==== Android-13 Possibility of using ERO-FS: ====&lt;br /&gt;
* [https://pocketnow.com/erofs-android-13-explained/ https://pocketnow.com/erofs-android-13-explained/] [7]&lt;br /&gt;
==== DM-Verity (Arch Wiki): ====&lt;br /&gt;
* [https://wiki.archlinux.org/title/Dm-verity https://wiki.archlinux.org/title/Dm-verity] [8]&lt;br /&gt;
==== ERO-FS Github ====&lt;br /&gt;
* [https://github.com/erofs/erofs-utils https://github.com/erofs/erofs-utils] [9]&lt;br /&gt;
==== Dracut (Arch Wiki): ====&lt;br /&gt;
* [https://wiki.archlinux.org/title/Dracut https://wiki.archlinux.org/title/Dracut] [10]&lt;br /&gt;
==== Linux-Hardened Kernel (AlpineWiki): ====&lt;br /&gt;
* [https://wiki.alpinelinux.org/wiki/Hardened_linux Hardened_linux] [11]&lt;br /&gt;
==== My old post on how it worked ====&lt;br /&gt;
* [https://www.reddit.com/r/AlpineLinux/comments/15oibcc/comment/k1l7jv0/ https://www.reddit.com/r/AlpineLinux/comments/15oibcc/comment/k1l7jv0/] [12]&lt;br /&gt;
&lt;br /&gt;
[[Category:Security]] [[Category:Booting]]&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=DM-verity&amp;diff=28856</id>
		<title>DM-verity</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=DM-verity&amp;diff=28856"/>
		<updated>2025-01-21T21:20:24Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{todo| Add a non-initramfs dm-verity implementation, which should use kernel to do dm-verity checking instead of initramfs, which is better for embedded devices, and faster to boot (but hard to implement because of kernel customizations, might need to compile kernel again.)}}&lt;br /&gt;
&lt;br /&gt;
== Why DM-Verity? ==&lt;br /&gt;
Possibly you want to continue the RoT ([https://en.wikipedia.org/wiki/Chain_of_trust Root of Trust] [1]) - from the hardware (Hardware TPM as Root of Trust, which ensures only the hardware with the correct secret cryptographic key in the TPM to decrypt the disk/file encryption) -&amp;gt; secure boot (Secure Boot to only run approved signed EFIStub/signed Bootloader) -&amp;gt; &amp;lt;u&amp;gt;To NOW DM-Verity rootfs&amp;lt;/u&amp;gt; (which ensures your root-image/root-parition has not been tampered with) -&amp;gt; Mandatory Access Control (AppArmor or SELinux - SELinux is disabled on default linux-lts btw) -&amp;gt; Sandboxed/Virtual-Machined Applications.&lt;br /&gt;
&lt;br /&gt;
=== What&#039;s the difference between me just setting the root partition as read-only (basically just an Immutable Root Partition) vs this? ===&lt;br /&gt;
DM-Verity COMPLETELY disallows modifying any files in the root-partition/root-image, or even disallow a part of a root-image/root-partition (the root-image/root-partition needs to be INTACT and match the signed cryptography verified by DM-Verity on a different partition), and with this consideration, you may use ERO-FS or SquashFS to generate Read-Only Root-Paritition/File Images. If you set your EXT4 file system to writable, and DM-Verity were to use it, it would be seen as &amp;quot;corrupted&amp;quot; and not boot anymore, because even just ONE tiny data change to the root image/partition would render it &amp;quot;corrupted&amp;quot;. This is the same technology used in Android and Chrome OS Devices. Also related to use in A/B root, also used by Fedora.&lt;br /&gt;
&lt;br /&gt;
{{tip| To keep the security reasonable, you would ideally want to work on the whole RoT, if not then anybody else can attack the non-verifed boot process that ISN&#039;T the root-partition/root-image that is enforced by DM-Verity.&lt;br /&gt;
* This following guide will use dracut to make a signed secureboot-able EFIStub.&lt;br /&gt;
* If you haven&#039;t, you may follow [https://wiki.alpinelinux.org/wiki/LVM_on_LUKS the Alpine Linux disk encryption setup] [2] with DM-Crypt LUKS and LVM&lt;br /&gt;
* You may choose to decrypt the image with TPM when generating with Dracut Modules with &amp;lt;code&amp;gt;add_dracutdrivers+{{=}}&amp;quot; ... tpm2-tss ... &amp;quot;&amp;lt;/code&amp;gt; and [https://github.com/latchset/clevis?tab{{=}}readme-ov-file#pin-tpm2 Clevis] [3]&lt;br /&gt;
* Apply AppArmor using [https://wiki.alpinelinux.org/wiki/AppArmor Alpine Linux AppArmor Wiki] (Docker does use AppArmor already, but you may apply an AppArmor profile on any application that should not have access to specific directories (AppArmor is a PATH based MAC)) [4]&lt;br /&gt;
* Use [https://gvisor.dev/docs/user_guide/install/ GVisor] [5] with Docker ([https://github.com/google/gvisor?tab{{=}}readme-ov-file#why-does-gvisor-exist Docker is NOT a sandbox] [6] (Because docker uses native kernel compared to Gvisor using its own kernel reimplementation)) for sandboxing on servers}}&lt;br /&gt;
&lt;br /&gt;
=== What is ERO-FS? ===&lt;br /&gt;
[https://pocketnow.com/erofs-android-13-explained/ Google thought about implementing ERO-FS with DM-Verity] [7]. Google was reported to be using it in Android 13, and ERO-FS is an excellent and fast compressed read-only filesystem.&lt;br /&gt;
&lt;br /&gt;
Here is an excerpt about &amp;lt;code&amp;gt;mkfs.erofs&amp;lt;/code&amp;gt; on [[https://wiki.archlinux.org/title/Dm-verity Arch Linux Wiki]] [8]:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039; mkfs.erofs(1) offers an attractive alternative to ext4 or squashfs on the root partition. EROFS, like squashfs, does not allow writes by design and has better performance in many cases than comparable filesystems on flash and solid-state media. It uses lz4 compression by default and was designed for Android phones by Huawei, which make extensive use of dm-verity. &#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Installing ===&lt;br /&gt;
&lt;br /&gt;
==== Working with ERO-FS ====&lt;br /&gt;
&lt;br /&gt;
{{warning| This wiki will be using Alpine Linux Edge Version. (Alpine Linux Non-Edge Versions may not contain these packages in the following rest of the wiki page) (Use Alpine Linux Edge Testing Repository in &amp;lt;code&amp;gt;/etc/apk/repositories&amp;lt;/code&amp;gt; as well)}}&lt;br /&gt;
&lt;br /&gt;
{{note| To not be confused, ERO-FS generates a &amp;quot;root image&amp;quot;, but you can replace the words &amp;quot;root partition&amp;quot; with &amp;quot;root image&amp;quot; and vice versa.}}&lt;br /&gt;
&lt;br /&gt;
First, some considerations, you may use a strictly READ-ONLY file system, such as SquashFS or ERO-FS, this wiki will be using ERO-FS (if you use a custom kernel, make sure it supports a file system such as ERO-FS, the default linux-lts does). [[https://github.com/erofs/erofs-utils ERO-FS Github]] [9] contains some information about how to compress and make your own read-only root image.&lt;br /&gt;
&lt;br /&gt;
{{cmd| $ apk install erofs-utils}}&lt;br /&gt;
{{cmd| $ mkdir image &amp;amp;&amp;amp; cd image }}&lt;br /&gt;
{{cmd| $ wget https://dl-cdn.alpinelinux.org/alpine/v3.21/releases/x86_64/alpine-minirootfs-3.21.0-x86_64.tar.gz}}&lt;br /&gt;
{{cmd| $ tar -xvf alpine-minirootfs-3.21.0-x86_64.tar.gz &amp;amp;&amp;amp; rm alpine-minirootfs-3.21.0-x86_64.tar.gz}}&lt;br /&gt;
Command below will generate an ERO-FS Image compressed with lz4 as ./erofs.img (erofs.img would be the root-partition file to use for dracut)&lt;br /&gt;
{{cmd| $ cd .. &amp;amp;&amp;amp; mkfs.erofs -zlz4hc erofs.img ./image}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Choose between a file or a partition ====&lt;br /&gt;
{{ todo | wip}}&lt;br /&gt;
You can verify the integrity of your erofs/squashfs image, by comparing the hashtable. the hashtable can be a &amp;lt;b&amp;gt;file&amp;lt;/b&amp;gt; or a &amp;lt;b&amp;gt;partition&amp;lt;b&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== Working with mkinitfs/kernel-hooks/secureboot-hooks ====&lt;br /&gt;
{{todo| wip}}&lt;br /&gt;
&lt;br /&gt;
Using mkinitfs, it is possible to force veritysetup in initramfs generation. It is recommended to make a chroot or docker so you don&#039;t mess with your system files, and by adding these files:&lt;br /&gt;
&lt;br /&gt;
{{todo| The init script is too big to put in wiki, I just acquired it from initramfs generation and decompression (read the tip below)}}&lt;br /&gt;
{{note| the APK package &amp;quot;cryptsetup&amp;quot; comes with veritysetup&lt;br /&gt;
{{cmd| apk add cryptsetup}}&lt;br /&gt;
}}&lt;br /&gt;
{{note| make sure the chroot has a linux-kernel}}&lt;br /&gt;
&lt;br /&gt;
Edit /sbin/mkinitfs (put &amp;quot;# Copy custom init&amp;quot; before &amp;quot;# copy modloop signature&amp;quot;):&lt;br /&gt;
{{cat| /etc/mkinitfs|...&lt;br /&gt;
        # Copy custom init &lt;br /&gt;
        cp /initramfs/init &amp;quot;$tmpdir&amp;quot;/init &lt;br /&gt;
        &lt;br /&gt;
        # copy modloop signature&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
PUT &amp;quot;# Call custom script&amp;quot; before &amp;quot;if [ &amp;quot;$SINGLEMODE&amp;quot; = &amp;quot;yes&amp;quot; ]; then&amp;quot;&lt;br /&gt;
{{cat| /initramfs/init|...&lt;br /&gt;
                # Call custom script&lt;br /&gt;
                /etc/scripts/my-custom-script.sh&lt;br /&gt;
                &lt;br /&gt;
        if [ &amp;quot;$SINGLEMODE&amp;quot; {{=}} &amp;quot;yes&amp;quot; ]; then&lt;br /&gt;
...&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/my-custom-script.files|&lt;br /&gt;
/etc/scripts/my-custom-script.sh&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/veritysetup.files|&lt;br /&gt;
/sbin/veritysetup&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/veritysetup.modules|&lt;br /&gt;
kernel/drivers/md/dm-verity.ko*&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/erofs.modules|&lt;br /&gt;
kernel/fs/erofs&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/mkinitfs.conf|...&lt;br /&gt;
features{{=}}&amp;quot;... erofs my-custom-script veritysetup&amp;quot;&lt;br /&gt;
MODULES{{=}}&amp;quot;veritysetup erofs&amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
{{cat| /etc/scripts/my-custom-script.sh|&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
mount /dev/mapper/root /root&lt;br /&gt;
mount /root/var/root/erofs.img /sysroot&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Then just do:&lt;br /&gt;
{{cmd| apk add secureboot-hook gummiboot gummiboot-efistub efibootmgr kernel-hooks secureboot-hook}}&lt;br /&gt;
&lt;br /&gt;
{{tip|To make sure initramfs has the scripts needed, do:&lt;br /&gt;
{{cmd|mkinitfs -c /etc/mkinitfs/mkinitfs.conf -b / $(uname -r)}}&lt;br /&gt;
Decompress:&lt;br /&gt;
{{cmd|mkdir /tmp/initramfs&lt;br /&gt;
cd /tmp/initramfs&lt;br /&gt;
&amp;lt;nowiki&amp;gt;zcat /boot/initramfs-$KERNEL | cpio -idmv&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Test if &amp;quot;init&amp;quot; works by just executing it and see how it runs:&lt;br /&gt;
{{cmd|./init}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Working with Dracut ====&lt;br /&gt;
&lt;br /&gt;
Remember, mount your &amp;lt;code&amp;gt;$ROOT_PARTITION&amp;lt;/code&amp;gt; as read only (assuming you use EXT4, if using ERO-FS or SquashFS, ignore this), since any changes will cause DM-Verity to detect it as &amp;quot;corrupt&amp;quot;&lt;br /&gt;
&lt;br /&gt;
{{warning| The following guide was done with FULL disk encryption, so this might not work perfectly on Non encrypted disk setup, also done on UEFI using gummiboot (now called systemd-boot - yes, systemd-boot is a separate project from the systemd init system) EFIStub and generating a UKI (Unified Kernel Image)}}&lt;br /&gt;
&lt;br /&gt;
===== Install basic stuff: =====&lt;br /&gt;
&lt;br /&gt;
{{cmd| apk add dracut dracut-core cryptsetup gummiboot gummiboot-efistub tpm2-tools clevis tpm2-tss tpm2-tss-tcti-device}}&lt;br /&gt;
&lt;br /&gt;
===== Using Clevis for TPM =====&lt;br /&gt;
&lt;br /&gt;
{{cmd| clevis luks bind -d /$ENCRYPTED_ROOT_PARTITION tpm2 &#039;{&amp;quot;pcr_ids&amp;quot;:&amp;quot;1,7&amp;quot;}&#039;}}&lt;br /&gt;
Input LUKS passphrase, remember that yes now it has tpm, but if possible remove old luks passphrase and use keyfile or different passphrase to unlock because tpm is better, and so if your computer breaks, you won&#039;t be locked out of your data!&lt;br /&gt;
&lt;br /&gt;
===== Create a new partition for your DM-Verity: =====&lt;br /&gt;
&lt;br /&gt;
Replace /dev/sdX with your actual device name.&lt;br /&gt;
{{cmd| sudo fdisk /dev/sdX}}&lt;br /&gt;
&lt;br /&gt;
Once in the fdisk interface:&lt;br /&gt;
# Press n to create a new partition&lt;br /&gt;
# Choose p for primary partition&lt;br /&gt;
# Select the partition number (e.g., 4)&lt;br /&gt;
# For the first sector, press Enter to use the default&lt;br /&gt;
# For the last sector, calculate 10% of your root partition size and use +SIZE format. For example, if your root partition is 100GB, enter +10G&lt;br /&gt;
# Press t to change the partition type&lt;br /&gt;
# Enter the partition number you just created&lt;br /&gt;
# Type 8e for Linux LVM type (closest to verity)&lt;br /&gt;
# Press w to write changes and exit&lt;br /&gt;
&lt;br /&gt;
===== Adding custom lines for full disk decryption =====&lt;br /&gt;
&lt;br /&gt;
Edit &amp;quot;&amp;lt;code&amp;gt;/usr/lib/dracut/modules.d/90crypt/cryptroot-ask.sh&amp;lt;/code&amp;gt;&amp;quot; and add these lines right BEFORE &amp;quot;&amp;lt;code&amp;gt;exit 0&amp;lt;/code&amp;gt;&amp;quot; (add your &amp;lt;code&amp;gt;$ROOT_PARTITION&amp;lt;/code&amp;gt; directory and &amp;lt;code&amp;gt;$VERITY_PARTITION&amp;lt;/code&amp;gt; directory):&lt;br /&gt;
&lt;br /&gt;
{{cat| /usr/lib/dracut/modules.d/90crypt/cryptroot-ask.sh|...&lt;br /&gt;
### DM-Verity&lt;br /&gt;
mount /dev/mapper/$ROOT_PARTITION /var/tmp&lt;br /&gt;
cryptsetup open --key-file /var/tmp/$KEYFILE_DIR /dev/$VERITY_PARTITION $VERITY_DM_NAME&lt;br /&gt;
umount /var/tmp&lt;br /&gt;
veritysetup open /dev/$ROOT_PARTITION /dev/$VERITY_PARTITION $(cat /usr/lib/dracut/roothash.txt)&lt;br /&gt;
###&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
===== Generating an EFIStub with Dracut + DM-Verity =====&lt;br /&gt;
&lt;br /&gt;
To setup DM-Verity (borrowed from [https://wiki.archlinux.org/title/Dm-verity Arch Linux Wiki]):&lt;br /&gt;
&lt;br /&gt;
{{cmd| veritysetup format /dev/$ROOT_PARTITION /dev/$VERITY_PARTITION | grep Root | cut -f2 &amp;gt;&amp;gt; /usr/lib/dracut/roothash.txt}}&lt;br /&gt;
&lt;br /&gt;
/etc/dracut.conf (put whatever your boot parameters are in &amp;quot;&amp;lt;code&amp;gt;kernel_cmdline&amp;lt;/code&amp;gt;&amp;quot;):&lt;br /&gt;
&lt;br /&gt;
{{cat| /etc/dracut.conf|...&lt;br /&gt;
kernel_cmdline{{=}}&amp;quot;&amp;quot;&lt;br /&gt;
add_dracutdrivers+{{=}}&amp;quot; busybox crypt crypt-gpg dm rootfs-block kernel-modules kernel-modules-extra tpm2-tss &amp;quot;&lt;br /&gt;
/etc/dracut.conf.d/secureboot.conf&lt;br /&gt;
&lt;br /&gt;
# Do the 3 lines below this if you have your own secureboot keys, or want to use secureboot:&lt;br /&gt;
uefi_secureboot_cert{{=}}&amp;quot;/$SECUREBOOT_KEYS_DIR/db.crt&amp;quot;&lt;br /&gt;
uefi_secureboot_key{{=}}&amp;quot;/$SECUREBOOT_KEYS_DIR/db.key&amp;quot;&lt;br /&gt;
/etc/dracut.conf.d/files.conf&lt;br /&gt;
&lt;br /&gt;
# This is what will import veritysetup binary file into dracut initramfs&lt;br /&gt;
install_items+{{=}}&amp;quot; /sbin/veritysetup &amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
Finally, generate UKI using dracut (replace &amp;lt;code&amp;gt;6.X.X-X-lts&amp;lt;/code&amp;gt; with your kernel &amp;lt;code&amp;gt;$VERSION&amp;lt;/code&amp;gt;) (also replace &amp;lt;code&amp;gt;/boot/efi/EFI/Linux/alpine-linux.efi&amp;lt;/code&amp;gt; with your mount efi partition):&lt;br /&gt;
&lt;br /&gt;
{{cmd| export DRACUT_KMODDIR_OVERRIDE{{=}}1}}&lt;br /&gt;
{{cmd| dracut --include /usr/lib/dracut/roothash.txt /usr/lib/dracut/roothash.txt --host-only --kernel-image /boot/vmlinuz-lts --kmoddir /lib/modules/6.X.X-X-lts --kver 6.X.X-X-lts --uefi --uefi-stub /usr/lib/gummiboot/linuxx64.efi.stub --force --compress lz4 /boot/efi/EFI/Linux/alpine-linux.efi /boot/efi/EFI/Linux/alpine-linux.efi}}&lt;br /&gt;
{{cmd| efibootmgr --create --disk /dev/$EFI_PARTITION --part 1 --label alpine-linux --loader EFI/Linux/alpine-linux.efi}}&lt;br /&gt;
&lt;br /&gt;
Unfortunately, using the default Alpine Linux kernel (&amp;lt;code&amp;gt;linux-lts&amp;lt;/code&amp;gt;) didn&#039;t work so download another distributions root system (like debians or devuan), and replace &amp;lt;code&amp;gt;/lib/modules/6.X.X-X-lts&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;/boot/vmlinuz-lts&amp;lt;/code&amp;gt; with anothers distributions kernel modules and kernel image (Or consider compiling your [https://wiki.alpinelinux.org/wiki/Hardened_linux own linux-hardened kernel] [11]).&lt;br /&gt;
&lt;br /&gt;
{{tip| If you want to test if DM-Verity fully works, change the &amp;lt;code&amp;gt;$ROOT_PARTITION&amp;lt;/code&amp;gt;&#039;s files and it should say it is &amp;quot;corrupt&amp;quot;, and not continue the boot process (only if you use EXT4).}}&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
==== Root of Trust/Chain of Trust ====&lt;br /&gt;
* [https://en.wikipedia.org/wiki/Chain_of_trust https://en.wikipedia.org/wiki/Chain_of_trust] [1]&lt;br /&gt;
==== Full disk encryption with LVM and LUKS (AlpineWiki): ====&lt;br /&gt;
* [https://wiki.alpinelinux.org/wiki/LVM_on_LUKS LVM_on_LUKS] [2]&lt;br /&gt;
==== Clevis Github ====&lt;br /&gt;
* [https://github.com/latchset/clevis?tab=readme-ov-file#pin-tpm2 https://github.com/latchset/clevis?tab=readme-ov-file#pin-tpm2] [3]&lt;br /&gt;
==== AppArmor Wiki (AlpineWiki) ====&lt;br /&gt;
* [https://wiki.alpinelinux.org/wiki/AppArmor AppArmor] [4]&lt;br /&gt;
==== GVisor ====&lt;br /&gt;
* [https://gvisor.dev/docs/user_guide/install/ https://gvisor.dev/docs/user_guide/install/] [5]&lt;br /&gt;
==== Gvisor Github stating docker is not a sandbox ====&lt;br /&gt;
* [https://github.com/google/gvisor?tab=readme-ov-file#why-does-gvisor-exist https://github.com/google/gvisor?tab=readme-ov-file#why-does-gvisor-exist] [6]&lt;br /&gt;
==== Android-13 Possibility of using ERO-FS: ====&lt;br /&gt;
* [https://pocketnow.com/erofs-android-13-explained/ https://pocketnow.com/erofs-android-13-explained/] [7]&lt;br /&gt;
==== DM-Verity (Arch Wiki): ====&lt;br /&gt;
* [https://wiki.archlinux.org/title/Dm-verity https://wiki.archlinux.org/title/Dm-verity] [8]&lt;br /&gt;
==== ERO-FS Github ====&lt;br /&gt;
* [https://github.com/erofs/erofs-utils https://github.com/erofs/erofs-utils] [9]&lt;br /&gt;
==== Dracut (Arch Wiki): ====&lt;br /&gt;
* [https://wiki.archlinux.org/title/Dracut https://wiki.archlinux.org/title/Dracut] [10]&lt;br /&gt;
==== Linux-Hardened Kernel (AlpineWiki): ====&lt;br /&gt;
* [https://wiki.alpinelinux.org/wiki/Hardened_linux Hardened_linux] [11]&lt;br /&gt;
==== My old post on how it worked ====&lt;br /&gt;
* [https://www.reddit.com/r/AlpineLinux/comments/15oibcc/comment/k1l7jv0/ https://www.reddit.com/r/AlpineLinux/comments/15oibcc/comment/k1l7jv0/] [12]&lt;br /&gt;
&lt;br /&gt;
[[Category:Security]] [[Category:Booting]]&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Silent_boot&amp;diff=28807</id>
		<title>Silent boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Silent_boot&amp;diff=28807"/>
		<updated>2025-01-13T19:30:12Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What is silent boot? ==&lt;br /&gt;
Silent boot means to almost completely remove all kernel and OpenRC messages on boot from your system. This may make it harder to debug issues when booting your computer, but it is also relatively &amp;lt;u&amp;gt;simple&amp;lt;/u&amp;gt; to get back a verbose message boot, with this following wiki page guide.&lt;br /&gt;
&lt;br /&gt;
This wiki page guide will remove all OpenRC messages, except login prompt. This will also remove kernel messages at boot.&lt;br /&gt;
&lt;br /&gt;
{{note| This wiki guide is done without any frame buffers. You may use frame buffers to add a gui boot (such as adding a logo) when booting linux.}}&lt;br /&gt;
&lt;br /&gt;
== Setting up silent-boot ==&lt;br /&gt;
&lt;br /&gt;
=== Disable kernel messages: ===&lt;br /&gt;
&lt;br /&gt;
==== Grub ====&lt;br /&gt;
Edit /etc/default/grub and add quiet to the GRUB_CMDLINE_LINUX variable:&lt;br /&gt;
{{cat|/etc/default/grub|&lt;br /&gt;
GRUB_CMDLINE_LINUX{{=}}&amp;quot;... quiet ...&amp;quot;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==== Kernel-hooks ====&lt;br /&gt;
Modify /etc/kernel-hooks.d/secureboot.conf and add quiet to cmdline:&lt;br /&gt;
{{cat|/etc/kernel-hooks.d/secureboot.conf|&lt;br /&gt;
cmdline{{=}}&amp;quot;... quiet ...&amp;quot;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Disable OpenRC Boot messages: ===&lt;br /&gt;
Make your &amp;lt;code&amp;gt;/etc/inittab&amp;lt;/code&amp;gt; similar to this:&lt;br /&gt;
{{cat|/etc/inittab|&lt;br /&gt;
# /etc/inittab&lt;br /&gt;
&lt;br /&gt;
::sysinit:/sbin/openrc sysinit &amp;amp;&amp;gt; /dev/null&lt;br /&gt;
::sysinit:/sbin/openrc boot &amp;amp;&amp;gt; /dev/null&lt;br /&gt;
::wait:/sbin/openrc default &amp;amp;&amp;gt; /dev/null&lt;br /&gt;
&lt;br /&gt;
# Set up one getty&lt;br /&gt;
tty1::respawn:/sbin/getty 38400 tty1&lt;br /&gt;
&lt;br /&gt;
# Stuff to do before rebooting&lt;br /&gt;
::shutdown:/sbin/openrc shutdown &amp;amp;&amp;gt; /dev/null&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Remove the &amp;quot;&amp;lt;code&amp;gt;&amp;amp;&amp;gt; /dev/null&amp;lt;/code&amp;gt;&amp;quot; on each line to see OpenRC boot messages again.&lt;br /&gt;
&lt;br /&gt;
=== Logging OpenRC while still keeping a silent boot ===&lt;br /&gt;
Enable this option in &amp;lt;code&amp;gt;/etc/rc.conf&amp;lt;/code&amp;gt;&lt;br /&gt;
{{cat|/etc/rc.conf|...&lt;br /&gt;
rc_logger{{=}}&amp;quot;YES&amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
This will produce a file &amp;lt;code&amp;gt;/var/log/rc.log&amp;lt;/code&amp;gt; so you can read the OpenRC logs&lt;br /&gt;
while keeping a clean and silent boot &lt;br /&gt;
&lt;br /&gt;
==== External sources ====&lt;br /&gt;
Alpine Linux Silent Boot with cmatrix (youtube) (not mine)&lt;br /&gt;
* [https://www.youtube.com/watch?v=HoltBFnu0yo https://www.youtube.com/watch?v=HoltBFnu0yo] [1]&lt;br /&gt;
&lt;br /&gt;
[[Category:Security]] [[Category:Booting]]&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Silent_boot&amp;diff=28806</id>
		<title>Silent boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Silent_boot&amp;diff=28806"/>
		<updated>2025-01-13T19:29:36Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What is silent boot? ==&lt;br /&gt;
Silent boot means to almost completely remove all kernel and OpenRC messages on boot from your system. This may make it harder to debug issues when booting your computer, but it is also relatively &amp;lt;u&amp;gt;simple&amp;lt;/u&amp;gt; to get back a verbose message boot, with this following wiki page guide.&lt;br /&gt;
&lt;br /&gt;
This wiki page guide will remove all OpenRC messages, except login prompt. This will also remove kernel messages at boot.&lt;br /&gt;
&lt;br /&gt;
{{note| This wiki guide is done without any frame buffers. You may use frame buffers to add a gui boot (such as adding a logo) when booting linux.}}&lt;br /&gt;
&lt;br /&gt;
== Setting up silent-boot ==&lt;br /&gt;
&lt;br /&gt;
=== Disable kernel messages: ===&lt;br /&gt;
&lt;br /&gt;
==== Grub ====&lt;br /&gt;
Edit /etc/default/grub and add quiet to the GRUB_CMDLINE_LINUX variable:&lt;br /&gt;
{{cat|/etc/default/grub|&lt;br /&gt;
GRUB_CMDLINE_LINUX{{=}}&amp;quot;... quiet ...&amp;quot;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==== Kernel-hooks ====&lt;br /&gt;
Modify /etc/kernel-hooks.d/secureboot.conf and add quiet to cmdline:&lt;br /&gt;
{{cat|/etc/kernel-hooks.d/secureboot.conf|&lt;br /&gt;
cmdline{{=}}&amp;quot;... quiet ...&amp;quot;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Disable OpenRC Boot messages: ===&lt;br /&gt;
Make your &amp;lt;code&amp;gt;/etc/inittab&amp;lt;/code&amp;gt; similar to this:&lt;br /&gt;
{{cat|/etc/inittab|&lt;br /&gt;
# /etc/inittab&lt;br /&gt;
&lt;br /&gt;
::sysinit:/sbin/openrc sysinit &amp;amp;&amp;gt; /dev/null&lt;br /&gt;
::sysinit:/sbin/openrc boot &amp;amp;&amp;gt; /dev/null&lt;br /&gt;
::wait:/sbin/openrc default &amp;amp;&amp;gt; /dev/null&lt;br /&gt;
&lt;br /&gt;
# Set up one getty&lt;br /&gt;
tty1::respawn:/sbin/getty 38400 tty1&lt;br /&gt;
&lt;br /&gt;
# Stuff to do before rebooting&lt;br /&gt;
::shutdown:/sbin/openrc shutdown &amp;amp;&amp;gt; /dev/null&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Remove the &amp;quot;&amp;lt;code&amp;gt;&amp;amp;&amp;gt; /dev/null&amp;lt;/code&amp;gt;&amp;quot; on each line to see OpenRC boot messages again.&lt;br /&gt;
&lt;br /&gt;
=== Logging OpenRC while still keeping a silent boot ===&lt;br /&gt;
Enable this option in &amp;lt;code&amp;gt;/etc/rc.conf&amp;lt;/code&amp;gt;&lt;br /&gt;
{{cat|/etc/rc.conf|...&lt;br /&gt;
rc_logger{{=}}&amp;quot;YES&amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
This will produce a file &amp;lt;code&amp;gt;/var/log/rc.conf&amp;lt;/code&amp;gt; so you can read the OpenRC logs&lt;br /&gt;
while keeping a clean and silent boot &lt;br /&gt;
&lt;br /&gt;
==== External sources ====&lt;br /&gt;
Alpine Linux Silent Boot with cmatrix (youtube) (not mine)&lt;br /&gt;
* [https://www.youtube.com/watch?v=HoltBFnu0yo https://www.youtube.com/watch?v=HoltBFnu0yo] [1]&lt;br /&gt;
&lt;br /&gt;
[[Category:Security]] [[Category:Booting]]&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Silent_boot&amp;diff=28805</id>
		<title>Silent boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Silent_boot&amp;diff=28805"/>
		<updated>2025-01-13T19:29:00Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What is silent boot? ==&lt;br /&gt;
Silent boot means to almost completely remove all kernel and OpenRC messages on boot from your system. This may make it harder to debug issues when booting your computer, but it is also relatively &amp;lt;u&amp;gt;simple&amp;lt;/u&amp;gt; to get back a verbose message boot, with this following wiki page guide.&lt;br /&gt;
&lt;br /&gt;
This wiki page guide will remove all OpenRC messages, except login prompt. This will also remove kernel messages at boot.&lt;br /&gt;
&lt;br /&gt;
{{note| This wiki guide is done without any frame buffers. You may use frame buffers to add a gui boot (such as adding a logo) when booting linux.}}&lt;br /&gt;
&lt;br /&gt;
== Setting up silent-boot ==&lt;br /&gt;
&lt;br /&gt;
=== Disable kernel messages: ===&lt;br /&gt;
&lt;br /&gt;
==== Grub ====&lt;br /&gt;
Edit /etc/default/grub and add quiet to the GRUB_CMDLINE_LINUX variable:&lt;br /&gt;
{{cat|/etc/default/grub|&lt;br /&gt;
GRUB_CMDLINE_LINUX{{=}}&amp;quot;... quiet ...&amp;quot;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==== Kernel-hooks ====&lt;br /&gt;
Modify /etc/kernel-hooks.d/secureboot.conf and add quiet to cmdline:&lt;br /&gt;
{{cat|/etc/kernel-hooks.d/secureboot.conf|&lt;br /&gt;
cmdline{{=}}&amp;quot;... quiet ...&amp;quot;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Disable OpenRC Boot messages: ===&lt;br /&gt;
Make your &amp;lt;code&amp;gt;/etc/inittab&amp;lt;/code&amp;gt; similar to this:&lt;br /&gt;
{{cat|/etc/inittab|&lt;br /&gt;
# /etc/inittab&lt;br /&gt;
&lt;br /&gt;
::sysinit:/sbin/openrc sysinit &amp;amp;&amp;gt; /dev/null&lt;br /&gt;
::sysinit:/sbin/openrc boot &amp;amp;&amp;gt; /dev/null&lt;br /&gt;
::wait:/sbin/openrc default &amp;amp;&amp;gt; /dev/null&lt;br /&gt;
&lt;br /&gt;
# Set up one getty&lt;br /&gt;
tty1::respawn:/sbin/getty 38400 tty1&lt;br /&gt;
&lt;br /&gt;
# Stuff to do before rebooting&lt;br /&gt;
::shutdown:/sbin/openrc shutdown &amp;amp;&amp;gt; /dev/null&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Remove the &amp;quot;&amp;lt;code&amp;gt;&amp;amp;&amp;gt; /dev/null&amp;lt;/code&amp;gt;&amp;quot; on each line to see OpenRC boot messages again.&lt;br /&gt;
&lt;br /&gt;
=== Logging OpenRC while still keeping a silent boot ===&lt;br /&gt;
Enable this option in &amp;lt;code&amp;gt;/etc/rc.conf&amp;lt;/code&amp;gt;&lt;br /&gt;
{{cat|/etc/rc.conf|&lt;br /&gt;
rc_logger{{=}}&amp;quot;YES&amp;quot;  &lt;br /&gt;
}}&lt;br /&gt;
This will produce a file &amp;lt;code&amp;gt;/var/log/rc.conf&amp;lt;/code&amp;gt; so you can read the OpenRC logs&lt;br /&gt;
while keeping a clean and silent boot &lt;br /&gt;
&lt;br /&gt;
==== External sources ====&lt;br /&gt;
Alpine Linux Silent Boot with cmatrix (youtube) (not mine)&lt;br /&gt;
* [https://www.youtube.com/watch?v=HoltBFnu0yo https://www.youtube.com/watch?v=HoltBFnu0yo] [1]&lt;br /&gt;
&lt;br /&gt;
[[Category:Security]] [[Category:Booting]]&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Silent_boot&amp;diff=28804</id>
		<title>Silent boot</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Silent_boot&amp;diff=28804"/>
		<updated>2025-01-13T19:28:23Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: Add logging for openrc&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What is silent boot? ==&lt;br /&gt;
Silent boot means to almost completely remove all kernel and OpenRC messages on boot from your system. This may make it harder to debug issues when booting your computer, but it is also relatively &amp;lt;u&amp;gt;simple&amp;lt;/u&amp;gt; to get back a verbose message boot, with this following wiki page guide.&lt;br /&gt;
&lt;br /&gt;
This wiki page guide will remove all OpenRC messages, except login prompt. This will also remove kernel messages at boot.&lt;br /&gt;
&lt;br /&gt;
{{note| This wiki guide is done without any frame buffers. You may use frame buffers to add a gui boot (such as adding a logo) when booting linux.}}&lt;br /&gt;
&lt;br /&gt;
== Setting up silent-boot ==&lt;br /&gt;
&lt;br /&gt;
=== Disable kernel messages: ===&lt;br /&gt;
&lt;br /&gt;
==== Grub ====&lt;br /&gt;
Edit /etc/default/grub and add quiet to the GRUB_CMDLINE_LINUX variable:&lt;br /&gt;
{{cat|/etc/default/grub|&lt;br /&gt;
GRUB_CMDLINE_LINUX{{=}}&amp;quot;... quiet ...&amp;quot;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==== Kernel-hooks ====&lt;br /&gt;
Modify /etc/kernel-hooks.d/secureboot.conf and add quiet to cmdline:&lt;br /&gt;
{{cat|/etc/kernel-hooks.d/secureboot.conf|&lt;br /&gt;
cmdline{{=}}&amp;quot;... quiet ...&amp;quot;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Disable OpenRC Boot messages: ===&lt;br /&gt;
Make your &amp;lt;code&amp;gt;/etc/inittab&amp;lt;/code&amp;gt; similar to this:&lt;br /&gt;
{{cat|/etc/inittab|&lt;br /&gt;
# /etc/inittab&lt;br /&gt;
&lt;br /&gt;
::sysinit:/sbin/openrc sysinit &amp;amp;&amp;gt; /dev/null&lt;br /&gt;
::sysinit:/sbin/openrc boot &amp;amp;&amp;gt; /dev/null&lt;br /&gt;
::wait:/sbin/openrc default &amp;amp;&amp;gt; /dev/null&lt;br /&gt;
&lt;br /&gt;
# Set up one getty&lt;br /&gt;
tty1::respawn:/sbin/getty 38400 tty1&lt;br /&gt;
&lt;br /&gt;
# Stuff to do before rebooting&lt;br /&gt;
::shutdown:/sbin/openrc shutdown &amp;amp;&amp;gt; /dev/null&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Remove the &amp;quot;&amp;lt;code&amp;gt;&amp;amp;&amp;gt; /dev/null&amp;lt;/code&amp;gt;&amp;quot; on each line to see OpenRC boot messages again.&lt;br /&gt;
&lt;br /&gt;
=== Logging openrc while still keeping a silent boot ===&lt;br /&gt;
Enable this option in &amp;lt;code&amp;gt;/etc/rc.conf&amp;lt;/code&amp;gt;&lt;br /&gt;
{{cat|/etc/rc.conf|&lt;br /&gt;
rc_logger{{=}}&amp;quot;YES&amp;quot;  &lt;br /&gt;
}}&lt;br /&gt;
This will produce a file &amp;lt;code&amp;gt;/var/log/rc.conf&amp;lt;/code&amp;gt; so you can read the OpenRC logs&lt;br /&gt;
while keeping a clean and silent boot &lt;br /&gt;
&lt;br /&gt;
==== External sources ====&lt;br /&gt;
Alpine Linux Silent Boot with cmatrix (youtube) (not mine)&lt;br /&gt;
* [https://www.youtube.com/watch?v=HoltBFnu0yo https://www.youtube.com/watch?v=HoltBFnu0yo] [1]&lt;br /&gt;
&lt;br /&gt;
[[Category:Security]] [[Category:Booting]]&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=User:Pursuable1652&amp;diff=28785</id>
		<title>User:Pursuable1652</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=User:Pursuable1652&amp;diff=28785"/>
		<updated>2025-01-13T05:00:46Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hello, I&#039;m Pursuable1652, I like scripting, some different types of development, modifying hardware/software, like learning about home-servers or networking (or general server administration)/(homelabbing), also like learning some security and privacy, and more (I&#039;m very passionate about computers), and I helped make these wiki pages:&lt;br /&gt;
&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Hardened_linux&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/DM-verity&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Silent_boot&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Hardened_malloc&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Clevis (clevis + tang auto decryption for servers)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/GVisor&lt;br /&gt;
&lt;br /&gt;
Working on apparmor profiles for init-services for openrc, MUST be ran in initramfs or at least before running openrc as PID1... (There is systemd service apparmor profiles available here: https://github.com/roddhjav/apparmor.d, but I do not see openrc init service apparmor profiles publicly available anywhere...)&lt;br /&gt;
&lt;br /&gt;
It is possible to run a read-only image (immutable?) (since it is immutable, must upgrade using an server providing upgrade files, and updating init script to call to update system.) Linux system without root access (use system without doas, sudo, or becoming root in any other way), by setting your user a part of docker group (AND possibly a lot more). But it is challenging since I had to create a power service (because I want to control power of server without root) ran as an init service, and call back to it (using a non-root user) to a /run/*.socket, since I don&#039;t have root access. &lt;br /&gt;
&lt;br /&gt;
Possible to run system with dm-verity enforcing a read only system. The read only image ideally should have [usr,sbin,bin,lib] as read-only. everything else (kernel virtual filesystems: [dev,proc,sys,tmp,run]) and (user writable directories  [var,etc,home]) are just empty directories in the erofs image. (They&#039;re empty because you&#039;re supposed to mount the file systems to those directories..)&lt;br /&gt;
&lt;br /&gt;
Using dm-verity and read-only images (basically immutable distro?), would benefit from an upgrade server. Basically a server that provides the read-only images, and any other files needed to upgrade a Linux system. This could be similar to setting up an APK repo for alpine Linux, but instead just putting your compressed (tar&#039;ed?) readonly images plus other files in the web directory, so other servers/devices can upgrade from it.&lt;br /&gt;
&lt;br /&gt;
My main goal is to secure Linux more, and better (and as a side-effect, very different) than traditional Linux distros. My guide is more suited to a server use-case, rather than desktop.&lt;br /&gt;
&lt;br /&gt;
The guides still apply to both server and desktop, but desktop has a bigger attack surface usually, because an app ecosystem must be incorporated with security as its designed (compared to server which could just be dockerized + gvisored + apparmored/selinuxed or virtualized).&lt;br /&gt;
&lt;br /&gt;
Flatpak on desktop is somewhat flawed because it&#039;s allow-permission first, rather than deny-permission first.&lt;br /&gt;
&lt;br /&gt;
It might be thought of as, you compile the software, the software is open-source, so it must be secure, right? (That is not true, because software, especially software with bigger LOC (lines of code), will be more complex, thus may have more bugs that are hard to detect from the human-eye, and these bugs may do any rogue things to your system.)&lt;br /&gt;
&lt;br /&gt;
Desktop may have a more harder way of controlling the security of software, since you need the support of an app ecosystem already working on a predefined-security focused platform, so not all apps are just running without a sandbox/vm (ideally without a VM (run all in sandbox) or maybe just one, because using virtual machines has a performance loss).&lt;br /&gt;
&lt;br /&gt;
To be honest, I recommend using Android/AOSP and ChromeOS/ChromiumOS for a secure OS based on Linux kernel, since they already have a huge app ecosystem built with Java and Kotlin, based on an SELinux&#039;ed platform with Verified Boot enabled by default, and root disallowed by default.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Some wikis I did not write, but may help with security of Alpine Linux (or just miscellaneous):&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/AppArmor (or possibly SELinux if your kernel supports it, default linux-lts doesn&#039;t. But if using selinux, must compile an SELinux aware BusyBox... or you could use coreutils? just because you would need &amp;quot;ls -Z&amp;quot; to see file labels)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Docker (if you use docker, also use GVisor for full sandboxing)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Securing_Alpine_Linux&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Sysctl.conf#Security (can also use kernel-hardening-checker for suggestions on sysctl and boot parameter secure options)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/CPU_Microcode (&amp;lt;code&amp;gt;cat /sys/devices/system/cpu/vulnerabilities/*&amp;lt;/code&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
Some more info about securing Alpine Linux:&lt;br /&gt;
&lt;br /&gt;
Reduce procfs information to non-root users by appending &amp;lt;code&amp;gt;hidepid&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;proc&amp;lt;/code&amp;gt;:&lt;br /&gt;
{{cat|/etc/fstab|...&lt;br /&gt;
proc    /proc   proc    nosuid,nodev,noexec,hidepid{{=}}2 0 0&lt;br /&gt;
...}}&lt;br /&gt;
Reduce procfs and sysfs information by removing read access to some files (may break your system):&lt;br /&gt;
{{cmd|&lt;br /&gt;
chmod 400 /proc/$FILE&lt;br /&gt;
chmod 400 /sys&lt;br /&gt;
chmod 400 /sys/$ANY_FILE_IN_DIR&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Set as many directories and files as possible as non-executable, read-only. And mount file-systems as non-executable and read-only.&lt;br /&gt;
&lt;br /&gt;
Consider between AppArmor and SELinux. AppArmor is more convenient to work with, but not as granular since it&#039;s path-based. SELinux is label-based, and it is more granular, obvious trade-off is it&#039;s more difficult to work with (for most people). linux-lts package only enables AppArmor.&lt;br /&gt;
&lt;br /&gt;
Apply [https://en.wikipedia.org/wiki/Principle_of_least_privilege PoLP] (Principle of Least Privilege) wherever possible.&lt;br /&gt;
&lt;br /&gt;
Have as little packages as possible on your system, minimalize amount of software on your system.&lt;br /&gt;
&lt;br /&gt;
Get rid of debugging tools.&lt;br /&gt;
&lt;br /&gt;
Use &amp;lt;code&amp;gt;doas&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;doasedit&amp;lt;/code&amp;gt; if root is needed. (I believe &amp;lt;code&amp;gt;doasedit&amp;lt;/code&amp;gt; is in the testing repo.)&lt;br /&gt;
&lt;br /&gt;
There is the obvious, which is DISABLE internet access to specific sandboxed/virtualized applications, or disable internet as a whole for a device if practical. (Basically firewalling/VLAN&#039;ing)&lt;br /&gt;
&lt;br /&gt;
Obvious make full backups&lt;br /&gt;
&lt;br /&gt;
File encryption can be used in tandem with FDE, for granular encryption.&lt;br /&gt;
&lt;br /&gt;
Same could be said for read-only integrity for files/directories.&lt;br /&gt;
&lt;br /&gt;
Always use HTTPS to download repository packages for your system.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Unfortunately, there is way too much for securing a traditional Linux server. Not impossible, just a lot left out that could have been done securing traditional Linux based OS&#039;. (BTW it&#039;s the same for traditional Unix based OS&#039;...)&lt;br /&gt;
&lt;br /&gt;
Security should be done by default, if not, while you configure your operating system for security, you are already compromised from the start. And more secure users is better than less, for example as you communicate with other secure users you are protected as well, protecting your communications with others.&lt;br /&gt;
&lt;br /&gt;
Follow [https://wiki.alpinelinux.org/wiki/DM-verity DM-Verity] wiki for an attempt at full verified/trusted boot on Alpine Linux.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
At this point, it would be it&#039;s own Linux distro&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=User:Pursuable1652&amp;diff=28784</id>
		<title>User:Pursuable1652</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=User:Pursuable1652&amp;diff=28784"/>
		<updated>2025-01-13T04:58:06Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hello, I&#039;m Pursuable1652, I like scripting, some different types of development, modifying hardware/software, like learning about home-servers or networking (or general server administration)/(homelabbing), also like learning some security and privacy, and more (I&#039;m very passionate about computers), and I helped make these wiki pages:&lt;br /&gt;
&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Hardened_linux&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/DM-verity&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Silent_boot&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Hardened_malloc&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Clevis (clevis + tang auto decryption for servers)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/GVisor&lt;br /&gt;
&lt;br /&gt;
Working on apparmor profiles for init-services for openrc, MUST be ran in initramfs or at least before running openrc as PID1..&lt;br /&gt;
&lt;br /&gt;
It is possible to run a read-only image (immutable?) (since it is immutable, must upgrade using an server providing upgrade files, and updating init script to call to update system.) Linux system without root access (use system without doas, sudo, or becoming root in any other way), by setting your user a part of docker group (AND possibly a lot more). But it is challenging since I had to create a power service (because I want to control power of server without root) ran as an init service, and call back to it (using a non-root user) to a /run/*.socket, since I don&#039;t have root access. &lt;br /&gt;
&lt;br /&gt;
Possible to run system with dm-verity enforcing a read only system. The read only image ideally should have [usr,sbin,bin,lib] as read-only. everything else (kernel virtual filesystems: [dev,proc,sys,tmp,run]) and (user writable directories  [var,etc,home]) are just empty directories in the erofs image. (They&#039;re empty because you&#039;re supposed to mount the file systems to those directories..)&lt;br /&gt;
&lt;br /&gt;
Using dm-verity and read-only images (basically immutable distro?), would benefit from an upgrade server. Basically a server that provides the read-only images, and any other files needed to upgrade a Linux system. This could be similar to setting up an APK repo for alpine Linux, but instead just putting your compressed (tar&#039;ed?) readonly images plus other files in the web directory, so other servers/devices can upgrade from it.&lt;br /&gt;
&lt;br /&gt;
My main goal is to secure Linux more, and better (and as a side-effect, very different) than traditional Linux distros. My guide is more suited to a server use-case, rather than desktop.&lt;br /&gt;
&lt;br /&gt;
The guides still apply to both server and desktop, but desktop has a bigger attack surface usually, because an app ecosystem must be incorporated with security as its designed (compared to server which could just be dockerized + gvisored + apparmored/selinuxed or virtualized).&lt;br /&gt;
&lt;br /&gt;
Flatpak on desktop is somewhat flawed because it&#039;s allow-permission first, rather than deny-permission first.&lt;br /&gt;
&lt;br /&gt;
It might be thought of as, you compile the software, the software is open-source, so it must be secure, right? (That is not true, because software, especially software with bigger LOC (lines of code), will be more complex, thus may have more bugs that are hard to detect from the human-eye, and these bugs may do any rogue things to your system.)&lt;br /&gt;
&lt;br /&gt;
Desktop may have a more harder way of controlling the security of software, since you need the support of an app ecosystem already working on a predefined-security focused platform, so not all apps are just running without a sandbox/vm (ideally without a VM (run all in sandbox) or maybe just one, because using virtual machines has a performance loss).&lt;br /&gt;
&lt;br /&gt;
To be honest, I recommend using Android/AOSP and ChromeOS/ChromiumOS for a secure OS based on Linux kernel, since they already have a huge app ecosystem built with Java and Kotlin, based on an SELinux&#039;ed platform with Verified Boot enabled by default, and root disallowed by default.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Some wikis I did not write, but may help with security of Alpine Linux (or just miscellaneous):&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/AppArmor (or possibly SELinux if your kernel supports it, default linux-lts doesn&#039;t. But if using selinux, must compile an SELinux aware BusyBox... or you could use coreutils? just because you would need &amp;quot;ls -Z&amp;quot; to see file labels)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Docker (if you use docker, also use GVisor for full sandboxing)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Securing_Alpine_Linux&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Sysctl.conf#Security (can also use kernel-hardening-checker for suggestions on sysctl and boot parameter secure options)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/CPU_Microcode (&amp;lt;code&amp;gt;cat /sys/devices/system/cpu/vulnerabilities/*&amp;lt;/code&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
Some more info about securing Alpine Linux:&lt;br /&gt;
&lt;br /&gt;
Reduce procfs information to non-root users by appending &amp;lt;code&amp;gt;hidepid&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;proc&amp;lt;/code&amp;gt;:&lt;br /&gt;
{{cat|/etc/fstab|...&lt;br /&gt;
proc    /proc   proc    nosuid,nodev,noexec,hidepid{{=}}2 0 0&lt;br /&gt;
...}}&lt;br /&gt;
Reduce procfs and sysfs information by removing read access to some files (may break your system):&lt;br /&gt;
{{cmd|&lt;br /&gt;
chmod 400 /proc/$FILE&lt;br /&gt;
chmod 400 /sys&lt;br /&gt;
chmod 400 /sys/$ANY_FILE_IN_DIR&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Set as many directories and files as possible as non-executable, read-only. And mount file-systems as non-executable and read-only.&lt;br /&gt;
&lt;br /&gt;
Consider between AppArmor and SELinux. AppArmor is more convenient to work with, but not as granular since it&#039;s path-based. SELinux is label-based, and it is more granular, obvious trade-off is it&#039;s more difficult to work with (for most people). linux-lts package only enables AppArmor.&lt;br /&gt;
&lt;br /&gt;
Apply [https://en.wikipedia.org/wiki/Principle_of_least_privilege PoLP] (Principle of Least Privilege) wherever possible.&lt;br /&gt;
&lt;br /&gt;
Have as little packages as possible on your system, minimalize amount of software on your system.&lt;br /&gt;
&lt;br /&gt;
Get rid of debugging tools.&lt;br /&gt;
&lt;br /&gt;
Use &amp;lt;code&amp;gt;doas&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;doasedit&amp;lt;/code&amp;gt; if root is needed. (I believe &amp;lt;code&amp;gt;doasedit&amp;lt;/code&amp;gt; is in the testing repo.)&lt;br /&gt;
&lt;br /&gt;
There is the obvious, which is DISABLE internet access to specific sandboxed/virtualized applications, or disable internet as a whole for a device if practical. (Basically firewalling/VLAN&#039;ing)&lt;br /&gt;
&lt;br /&gt;
Obvious make full backups&lt;br /&gt;
&lt;br /&gt;
File encryption can be used in tandem with FDE, for granular encryption.&lt;br /&gt;
&lt;br /&gt;
Same could be said for read-only integrity for files/directories.&lt;br /&gt;
&lt;br /&gt;
Always use HTTPS to download repository packages for your system.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Unfortunately, there is way too much for securing a traditional Linux server. Not impossible, just a lot left out that could have been done securing traditional Linux based OS&#039;. (BTW it&#039;s the same for traditional Unix based OS&#039;...)&lt;br /&gt;
&lt;br /&gt;
Security should be done by default, if not, while you configure your operating system for security, you are already compromised from the start. And more secure users is better than less, for example as you communicate with other secure users you are protected as well, protecting your communications with others.&lt;br /&gt;
&lt;br /&gt;
Follow [https://wiki.alpinelinux.org/wiki/DM-verity DM-Verity] wiki for an attempt at full verified/trusted boot on Alpine Linux.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
At this point, it would be it&#039;s own Linux distro&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=User:Pursuable1652&amp;diff=28783</id>
		<title>User:Pursuable1652</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=User:Pursuable1652&amp;diff=28783"/>
		<updated>2025-01-13T04:54:43Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hello, I&#039;m Pursuable1652, I like scripting, some different types of development, modifying hardware/software, like learning about home-servers or networking (or general server administration)/(homelabbing), also like learning some security and privacy, and more (I&#039;m very passionate about computers), and I helped make these wiki pages:&lt;br /&gt;
&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Hardened_linux&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/DM-verity&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Silent_boot&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Hardened_malloc&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Clevis (clevis + tang auto decryption for servers)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/GVisor&lt;br /&gt;
&lt;br /&gt;
Working on apparmor profiles for init-services for openrc, MUST be ran in initramfs or at least before running openrc as PID1..&lt;br /&gt;
&lt;br /&gt;
It is possible to run a read-only image (immutable?) (since it is immutable, must upgrade using an server providing upgrade files, and updating init script to call to update system.) Linux system without root access (use system without doas, sudo, or becoming root in any other way), by setting your user a part of docker group (AND possibly a lot more). But it is challenging since I had to create a power service (because I want to control power of server without root) ran as an init service, and call back to it (using a non-root user) to a /run/*.socket, since I don&#039;t have root access. &lt;br /&gt;
&lt;br /&gt;
Possible to run system with dm-verity enforcing a read only system. The read only image ideally should have [usr,sbin,bin,lib] as read-only. everything else (kernel virtual filesystems: [dev,proc,sys,tmp,run]) and (user writable directories  [var,etc,home]) are just empty directories in the erofs image.&lt;br /&gt;
&lt;br /&gt;
Using dm-verity and read-only images (basically immutable distro?), would benefit from an upgrade server. Basically a server that provides the read-only images, and any other files needed to upgrade a Linux system. This could be similar to setting up an APK repo for alpine Linux, but instead just putting your compressed (tar&#039;ed?) readonly images plus other files in the web directory, so other servers/devices can upgrade from it.&lt;br /&gt;
&lt;br /&gt;
My main goal is to secure Linux more, and better (and as a side-effect, very different) than traditional Linux distros. My guide is more suited to a server use-case, rather than desktop.&lt;br /&gt;
&lt;br /&gt;
The guides still apply to both server and desktop, but desktop has a bigger attack surface usually, because an app ecosystem must be incorporated with security as its designed (compared to server which could just be dockerized + gvisored + apparmored/selinuxed or virtualized).&lt;br /&gt;
&lt;br /&gt;
Flatpak on desktop is somewhat flawed because it&#039;s allow-permission first, rather than deny-permission first.&lt;br /&gt;
&lt;br /&gt;
It might be thought of as, you compile the software, the software is open-source, so it must be secure, right? (That is not true, because software, especially software with bigger LOC (lines of code), will be more complex, thus may have more bugs that are hard to detect from the human-eye, and these bugs may do any rogue things to your system.)&lt;br /&gt;
&lt;br /&gt;
Desktop may have a more harder way of controlling the security of software, since you need the support of an app ecosystem already working on a predefined-security focused platform, so not all apps are just running without a sandbox/vm (ideally without a VM (run all in sandbox) or maybe just one, because using virtual machines has a performance loss).&lt;br /&gt;
&lt;br /&gt;
To be honest, I recommend using Android/AOSP and ChromeOS/ChromiumOS for a secure OS based on Linux kernel, since they already have a huge app ecosystem built with Java and Kotlin, based on an SELinux&#039;ed platform with Verified Boot enabled by default, and root disallowed by default.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Some wikis I did not write, but may help with security of Alpine Linux (or just miscellaneous):&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/AppArmor (or possibly SELinux if your kernel supports it, default linux-lts doesn&#039;t. But if using selinux, must compile an SELinux aware BusyBox... or you could use coreutils? just because you would need &amp;quot;ls -Z&amp;quot; to see file labels)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Docker (if you use docker, also use GVisor for full sandboxing)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Securing_Alpine_Linux&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Sysctl.conf#Security (can also use kernel-hardening-checker for suggestions on sysctl and boot parameter secure options)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/CPU_Microcode (&amp;lt;code&amp;gt;cat /sys/devices/system/cpu/vulnerabilities/*&amp;lt;/code&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
Some more info about securing Alpine Linux:&lt;br /&gt;
&lt;br /&gt;
Reduce procfs information to non-root users by appending &amp;lt;code&amp;gt;hidepid&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;proc&amp;lt;/code&amp;gt;:&lt;br /&gt;
{{cat|/etc/fstab|...&lt;br /&gt;
proc    /proc   proc    nosuid,nodev,noexec,hidepid{{=}}2 0 0&lt;br /&gt;
...}}&lt;br /&gt;
Reduce procfs and sysfs information by removing read access to some files (may break your system):&lt;br /&gt;
{{cmd|&lt;br /&gt;
chmod 400 /proc/$FILE&lt;br /&gt;
chmod 400 /sys&lt;br /&gt;
chmod 400 /sys/$ANY_FILE_IN_DIR&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Set as many directories and files as possible as non-executable, read-only. And mount file-systems as non-executable and read-only.&lt;br /&gt;
&lt;br /&gt;
Consider between AppArmor and SELinux. AppArmor is more convenient to work with, but not as granular since it&#039;s path-based. SELinux is label-based, and it is more granular, obvious trade-off is it&#039;s more difficult to work with (for most people). linux-lts package only enables AppArmor.&lt;br /&gt;
&lt;br /&gt;
Apply [https://en.wikipedia.org/wiki/Principle_of_least_privilege PoLP] (Principle of Least Privilege) wherever possible.&lt;br /&gt;
&lt;br /&gt;
Have as little packages as possible on your system, minimalize amount of software on your system.&lt;br /&gt;
&lt;br /&gt;
Get rid of debugging tools.&lt;br /&gt;
&lt;br /&gt;
Use &amp;lt;code&amp;gt;doas&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;doasedit&amp;lt;/code&amp;gt; if root is needed. (I believe &amp;lt;code&amp;gt;doasedit&amp;lt;/code&amp;gt; is in the testing repo.)&lt;br /&gt;
&lt;br /&gt;
There is the obvious, which is DISABLE internet access to specific sandboxed/virtualized applications, or disable internet as a whole for a device if practical. (Basically firewalling/VLAN&#039;ing)&lt;br /&gt;
&lt;br /&gt;
Obvious make full backups&lt;br /&gt;
&lt;br /&gt;
File encryption can be used in tandem with FDE, for granular encryption.&lt;br /&gt;
&lt;br /&gt;
Same could be said for read-only integrity for files/directories.&lt;br /&gt;
&lt;br /&gt;
Always use HTTPS to download repository packages for your system.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Unfortunately, there is way too much for securing a traditional Linux server. Not impossible, just a lot left out that could have been done securing traditional Linux based OS&#039;. (BTW it&#039;s the same for traditional Unix based OS&#039;...)&lt;br /&gt;
&lt;br /&gt;
Security should be done by default, if not, while you configure your operating system for security, you are already compromised from the start. And more secure users is better than less, for example as you communicate with other secure users you are protected as well, protecting your communications with others.&lt;br /&gt;
&lt;br /&gt;
Follow [https://wiki.alpinelinux.org/wiki/DM-verity DM-Verity] wiki for an attempt at full verified/trusted boot on Alpine Linux.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
At this point, it would be it&#039;s own Linux distro&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=User:Pursuable1652&amp;diff=28782</id>
		<title>User:Pursuable1652</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=User:Pursuable1652&amp;diff=28782"/>
		<updated>2025-01-13T04:51:35Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hello, I&#039;m Pursuable1652, I like scripting, some different types of development, modifying hardware/software, like learning about home-servers or networking (or general server administration)/(homelabbing), also like learning some security and privacy, and more (I&#039;m very passionate about computers), and I helped make these wiki pages:&lt;br /&gt;
&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Hardened_linux&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/DM-verity&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Silent_boot&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Hardened_malloc&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Clevis (clevis + tang auto decryption for servers)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/GVisor&lt;br /&gt;
&lt;br /&gt;
Working on apparmor profiles for init-services for openrc, MUST be ran in initramfs or at least before running openrc as PID1..&lt;br /&gt;
&lt;br /&gt;
It is possible to run a read-only image (immutable?) (since it is immutable, must upgrade using an server providing upgrade files, and updating init script to call to update system.) Linux system without root access (use system without doas, sudo, or becoming root in any other way), by setting your user a part of docker group (AND possibly a lot more). But it is challenging since I had to create a power service (because I want to control power of server without root) ran as an init service, and call back to it (using a non-root user) to a /run/*.socket, since I don&#039;t have root access. &lt;br /&gt;
&lt;br /&gt;
Possible to run system with dm-verity enforcing a read only system. The read only image ideally should have [usr,sbin,bin,lib] as read-only. everything else (kernel virtual filesystems: [dev,proc,sys,tmp,run]) and (user writable directories  [var,etc,home]) are just empty directories in the erofs image.&lt;br /&gt;
&lt;br /&gt;
Using dm-verity and read-only images (basically immutable distro?), would benefit from an upgrade server. Basically a server that provides the read-only images, and any other files needed to upgrade a Linux system. This could be similar to setting up an APK repo for alpine Linux, but instead just putting your compressed (tar&#039;ed?) readonly images plus other files in the web directory, so other servers/devices can upgrade from it.&lt;br /&gt;
&lt;br /&gt;
My main goal is to secure Linux more, and better (and as a side-effect, very different) than traditional Linux distros. My guide is more suited to a server use-case, rather than desktop.&lt;br /&gt;
&lt;br /&gt;
The guides still apply to both server and desktop, but desktop has a bigger attack surface usually, because an app ecosystem must be incorporated with security as its designed (compared to server which could just be dockerized + gvisored + apparmored/selinuxed or virtualized).&lt;br /&gt;
&lt;br /&gt;
Flatpak on desktop is somewhat flawed because it&#039;s allow-permission first, rather than deny-permission first.&lt;br /&gt;
&lt;br /&gt;
It might be thought of as, you compile the software, the software is open-source, so it must be secure, right? (That is not true, because software, especially software with bigger LOC (lines of code), will be more complex, thus may have more bugs that are hard to detect from the human-eye, and these bugs may do any rogue things to your system.)&lt;br /&gt;
&lt;br /&gt;
Desktop may have a more harder way of controlling the security of software, since you need the support of an app ecosystem already working on a predefined-security focused platform, so not all apps are just running without a sandbox/vm (ideally without a VM (run all in sandbox) or maybe just one, because using virtual machines has a performance loss).&lt;br /&gt;
&lt;br /&gt;
To be honest, I recommend using Android/AOSP and ChromeOS/ChromiumOS for a secure OS based on Linux kernel, since they already have a huge app ecosystem built with Java and Kotlin, based on an SELinux&#039;ed platform with Verified Boot enabled by default, and root disallowed by default.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Some wikis I did not write, but may help with security of Alpine Linux (or just miscellaneous):&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/AppArmor (or possibly SELinux if your kernel supports it, default linux-lts doesn&#039;t)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Docker (if you use docker, also use GVisor for full sandboxing)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Securing_Alpine_Linux&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Sysctl.conf#Security (can also use kernel-hardening-checker for suggestions on sysctl and boot parameter secure options)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/CPU_Microcode (&amp;lt;code&amp;gt;cat /sys/devices/system/cpu/vulnerabilities/*&amp;lt;/code&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
Some more info about securing Alpine Linux:&lt;br /&gt;
&lt;br /&gt;
Reduce procfs information to non-root users by appending &amp;lt;code&amp;gt;hidepid&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;proc&amp;lt;/code&amp;gt;:&lt;br /&gt;
{{cat|/etc/fstab|...&lt;br /&gt;
proc    /proc   proc    nosuid,nodev,noexec,hidepid{{=}}2 0 0&lt;br /&gt;
...}}&lt;br /&gt;
Reduce procfs and sysfs information by removing read access to some files (may break your system):&lt;br /&gt;
{{cmd|&lt;br /&gt;
chmod 400 /proc/$FILE&lt;br /&gt;
chmod 400 /sys&lt;br /&gt;
chmod 400 /sys/$ANY_FILE_IN_DIR&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Set as many directories and files as possible as non-executable, read-only. And mount file-systems as non-executable and read-only.&lt;br /&gt;
&lt;br /&gt;
Consider between AppArmor and SELinux. AppArmor is more convenient to work with, but not as granular since it&#039;s path-based. SELinux is label-based, and it is more granular, obvious trade-off is it&#039;s more difficult to work with (for most people). linux-lts package only enables AppArmor.&lt;br /&gt;
&lt;br /&gt;
Apply [https://en.wikipedia.org/wiki/Principle_of_least_privilege PoLP] (Principle of Least Privilege) wherever possible.&lt;br /&gt;
&lt;br /&gt;
Have as little packages as possible on your system, minimalize amount of software on your system.&lt;br /&gt;
&lt;br /&gt;
Get rid of debugging tools.&lt;br /&gt;
&lt;br /&gt;
Use &amp;lt;code&amp;gt;doas&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;doasedit&amp;lt;/code&amp;gt; if root is needed. (I believe &amp;lt;code&amp;gt;doasedit&amp;lt;/code&amp;gt; is in the testing repo.)&lt;br /&gt;
&lt;br /&gt;
There is the obvious, which is DISABLE internet access to specific sandboxed/virtualized applications, or disable internet as a whole for a device if practical. (Basically firewalling/VLAN&#039;ing)&lt;br /&gt;
&lt;br /&gt;
Obvious make full backups&lt;br /&gt;
&lt;br /&gt;
File encryption can be used in tandem with FDE, for granular encryption.&lt;br /&gt;
&lt;br /&gt;
Same could be said for read-only integrity for files/directories.&lt;br /&gt;
&lt;br /&gt;
Always use HTTPS to download repository packages for your system.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Unfortunately, there is way too much for securing a traditional Linux server. Not impossible, just a lot left out that could have been done securing traditional Linux based OS&#039;. (BTW it&#039;s the same for traditional Unix based OS&#039;...)&lt;br /&gt;
&lt;br /&gt;
Security should be done by default, if not, while you configure your operating system for security, you are already compromised from the start. And more secure users is better than less, for example as you communicate with other secure users you are protected as well, protecting your communications with others.&lt;br /&gt;
&lt;br /&gt;
Follow [https://wiki.alpinelinux.org/wiki/DM-verity DM-Verity] wiki for an attempt at full verified/trusted boot on Alpine Linux.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
At this point, it would be it&#039;s own Linux distro&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=User:Pursuable1652&amp;diff=28781</id>
		<title>User:Pursuable1652</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=User:Pursuable1652&amp;diff=28781"/>
		<updated>2025-01-13T04:50:45Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hello, I&#039;m Pursuable1652, I like scripting, some different types of development, modifying hardware/software, like learning about home-servers or networking (or general server administration)/(homelabbing), also like learning some security and privacy, and more (I&#039;m very passionate about computers), and I helped make these wiki pages:&lt;br /&gt;
&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Hardened_linux&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/DM-verity&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Silent_boot&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Hardened_malloc&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Clevis (clevis + tang auto decryption for servers)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/GVisor&lt;br /&gt;
&lt;br /&gt;
Working on apparmor profiles for init-services for openrc, MUST be ran in initramfs or at least before running openrc as PID1..&lt;br /&gt;
&lt;br /&gt;
It is possible to run a read-only image (immutable?) (upgrade using an server providing upgrade files) Linux system without root access (use system without doas, sudo, or becoming root in any other way), by setting your user a part of docker group (AND possibly a lot more). But it is challenging since I had to create a power service (because I want to control power of server without root) ran as an init service, and call back to it (using a non-root user) to a /run/*.socket, since I don&#039;t have root access. &lt;br /&gt;
&lt;br /&gt;
Possible to run system with dm-verity enforcing a read only system. The read only image ideally should have [usr,sbin,bin,lib] as read-only. everything else (kernel virtual filesystems: [dev,proc,sys,tmp,run]) and (user writable directories  [var,etc,home]) are just empty directories in the erofs image.&lt;br /&gt;
&lt;br /&gt;
Using dm-verity and read-only images (basically immutable distro?), would benefit from an upgrade server. Basically a server that provides the read-only images, and any other files needed to upgrade a Linux system. This could be similar to setting up an APK repo for alpine Linux, but instead just putting your compressed (tar&#039;ed?) readonly images plus other files in the web directory, so other servers/devices can upgrade from it.&lt;br /&gt;
&lt;br /&gt;
My main goal is to secure Linux more, and better (and as a side-effect, very different) than traditional Linux distros. My guide is more suited to a server use-case, rather than desktop.&lt;br /&gt;
&lt;br /&gt;
The guides still apply to both server and desktop, but desktop has a bigger attack surface usually, because an app ecosystem must be incorporated with security as its designed (compared to server which could just be dockerized + gvisored + apparmored/selinuxed or virtualized).&lt;br /&gt;
&lt;br /&gt;
Flatpak on desktop is somewhat flawed because it&#039;s allow-permission first, rather than deny-permission first.&lt;br /&gt;
&lt;br /&gt;
It might be thought of as, you compile the software, the software is open-source, so it must be secure, right? (That is not true, because software, especially software with bigger LOC (lines of code), will be more complex, thus may have more bugs that are hard to detect from the human-eye, and these bugs may do any rogue things to your system.)&lt;br /&gt;
&lt;br /&gt;
Desktop may have a more harder way of controlling the security of software, since you need the support of an app ecosystem already working on a predefined-security focused platform, so not all apps are just running without a sandbox/vm (ideally without a VM (run all in sandbox) or maybe just one, because using virtual machines has a performance loss).&lt;br /&gt;
&lt;br /&gt;
To be honest, I recommend using Android/AOSP and ChromeOS/ChromiumOS for a secure OS based on Linux kernel, since they already have a huge app ecosystem built with Java and Kotlin, based on an SELinux&#039;ed platform with Verified Boot enabled by default, and root disallowed by default.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Some wikis I did not write, but may help with security of Alpine Linux (or just miscellaneous):&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/AppArmor (or possibly SELinux if your kernel supports it, default linux-lts doesn&#039;t)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Docker (if you use docker, also use GVisor for full sandboxing)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Securing_Alpine_Linux&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Sysctl.conf#Security (can also use kernel-hardening-checker for suggestions on sysctl and boot parameter secure options)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/CPU_Microcode (&amp;lt;code&amp;gt;cat /sys/devices/system/cpu/vulnerabilities/*&amp;lt;/code&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
Some more info about securing Alpine Linux:&lt;br /&gt;
&lt;br /&gt;
Reduce procfs information to non-root users by appending &amp;lt;code&amp;gt;hidepid&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;proc&amp;lt;/code&amp;gt;:&lt;br /&gt;
{{cat|/etc/fstab|...&lt;br /&gt;
proc    /proc   proc    nosuid,nodev,noexec,hidepid{{=}}2 0 0&lt;br /&gt;
...}}&lt;br /&gt;
Reduce procfs and sysfs information by removing read access to some files (may break your system):&lt;br /&gt;
{{cmd|&lt;br /&gt;
chmod 400 /proc/$FILE&lt;br /&gt;
chmod 400 /sys&lt;br /&gt;
chmod 400 /sys/$ANY_FILE_IN_DIR&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Set as many directories and files as possible as non-executable, read-only. And mount file-systems as non-executable and read-only.&lt;br /&gt;
&lt;br /&gt;
Consider between AppArmor and SELinux. AppArmor is more convenient to work with, but not as granular since it&#039;s path-based. SELinux is label-based, and it is more granular, obvious trade-off is it&#039;s more difficult to work with (for most people). linux-lts package only enables AppArmor.&lt;br /&gt;
&lt;br /&gt;
Apply [https://en.wikipedia.org/wiki/Principle_of_least_privilege PoLP] (Principle of Least Privilege) wherever possible.&lt;br /&gt;
&lt;br /&gt;
Have as little packages as possible on your system, minimalize amount of software on your system.&lt;br /&gt;
&lt;br /&gt;
Get rid of debugging tools.&lt;br /&gt;
&lt;br /&gt;
Use &amp;lt;code&amp;gt;doas&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;doasedit&amp;lt;/code&amp;gt; if root is needed. (I believe &amp;lt;code&amp;gt;doasedit&amp;lt;/code&amp;gt; is in the testing repo.)&lt;br /&gt;
&lt;br /&gt;
There is the obvious, which is DISABLE internet access to specific sandboxed/virtualized applications, or disable internet as a whole for a device if practical. (Basically firewalling/VLAN&#039;ing)&lt;br /&gt;
&lt;br /&gt;
Obvious make full backups&lt;br /&gt;
&lt;br /&gt;
File encryption can be used in tandem with FDE, for granular encryption.&lt;br /&gt;
&lt;br /&gt;
Same could be said for read-only integrity for files/directories.&lt;br /&gt;
&lt;br /&gt;
Always use HTTPS to download repository packages for your system.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Unfortunately, there is way too much for securing a traditional Linux server. Not impossible, just a lot left out that could have been done securing traditional Linux based OS&#039;. (BTW it&#039;s the same for traditional Unix based OS&#039;...)&lt;br /&gt;
&lt;br /&gt;
Security should be done by default, if not, while you configure your operating system for security, you are already compromised from the start. And more secure users is better than less, for example as you communicate with other secure users you are protected as well, protecting your communications with others.&lt;br /&gt;
&lt;br /&gt;
Follow [https://wiki.alpinelinux.org/wiki/DM-verity DM-Verity] wiki for an attempt at full verified/trusted boot on Alpine Linux.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
At this point, it would be it&#039;s own Linux distro&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=User:Pursuable1652&amp;diff=28780</id>
		<title>User:Pursuable1652</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=User:Pursuable1652&amp;diff=28780"/>
		<updated>2025-01-13T04:49:43Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hello, I&#039;m Pursuable1652, I like scripting, some different types of development, modifying hardware/software, like learning about home-servers or networking (or general server administration)/(homelabbing), also like learning some security and privacy, and more (I&#039;m very passionate about computers), and I helped make these wiki pages:&lt;br /&gt;
&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Hardened_linux&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/DM-verity&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Silent_boot&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Hardened_malloc&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Clevis (clevis + tang auto decryption for servers)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/GVisor&lt;br /&gt;
&lt;br /&gt;
Working on apparmor profiles for init-services for openrc, MUST be ran in initramfs or at least before running openrc as PID1..&lt;br /&gt;
&lt;br /&gt;
It is possible to run a Linux system without root access (use system without doas, sudo, or becoming root in any other way), by setting your user a part of docker group (AND possibly a lot more). But it is challenging since I had to create a power service (because I want to control power of server without root) ran as an init service, and call back to it (using a non-root user) to a /run/*.socket, since I don&#039;t have root access. &lt;br /&gt;
&lt;br /&gt;
Possible to run system with dm-verity enforcing a read only system. The read only image ideally should have [usr,sbin,bin,lib] as read-only. everything else (kernel virtual filesystems: [dev,proc,sys,tmp,run]) and (user writable directories  [var,etc,home]) are just empty directories in the erofs image.&lt;br /&gt;
&lt;br /&gt;
Using dm-verity and read-only images (basically immutable distro?), would benefit from an upgrade server. Basically a server that provides the read-only images, and any other files needed to upgrade a Linux system. This could be similar to setting up an APK repo for alpine Linux, but instead just putting your compressed (tar&#039;ed?) readonly images plus other files in the web directory, so other servers/devices can upgrade from it.&lt;br /&gt;
&lt;br /&gt;
My main goal is to secure Linux more, and better (and as a side-effect, very different) than traditional Linux distros. My guide is more suited to a server use-case, rather than desktop.&lt;br /&gt;
&lt;br /&gt;
The guides still apply to both server and desktop, but desktop has a bigger attack surface usually, because an app ecosystem must be incorporated with security as its designed (compared to server which could just be dockerized + gvisored + apparmored/selinuxed or virtualized).&lt;br /&gt;
&lt;br /&gt;
Flatpak on desktop is somewhat flawed because it&#039;s allow-permission first, rather than deny-permission first.&lt;br /&gt;
&lt;br /&gt;
It might be thought of as, you compile the software, the software is open-source, so it must be secure, right? (That is not true, because software, especially software with bigger LOC (lines of code), will be more complex, thus may have more bugs that are hard to detect from the human-eye, and these bugs may do any rogue things to your system.)&lt;br /&gt;
&lt;br /&gt;
Desktop may have a more harder way of controlling the security of software, since you need the support of an app ecosystem already working on a predefined-security focused platform, so not all apps are just running without a sandbox/vm (ideally without a VM (run all in sandbox) or maybe just one, because using virtual machines has a performance loss).&lt;br /&gt;
&lt;br /&gt;
To be honest, I recommend using Android/AOSP and ChromeOS/ChromiumOS for a secure OS based on Linux kernel, since they already have a huge app ecosystem built with Java and Kotlin, based on an SELinux&#039;ed platform with Verified Boot enabled by default, and root disallowed by default.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Some wikis I did not write, but may help with security of Alpine Linux (or just miscellaneous):&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/AppArmor (or possibly SELinux if your kernel supports it, default linux-lts doesn&#039;t)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Docker (if you use docker, also use GVisor for full sandboxing)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Securing_Alpine_Linux&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Sysctl.conf#Security (can also use kernel-hardening-checker for suggestions on sysctl and boot parameter secure options)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/CPU_Microcode (&amp;lt;code&amp;gt;cat /sys/devices/system/cpu/vulnerabilities/*&amp;lt;/code&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
Some more info about securing Alpine Linux:&lt;br /&gt;
&lt;br /&gt;
Reduce procfs information to non-root users by appending &amp;lt;code&amp;gt;hidepid&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;proc&amp;lt;/code&amp;gt;:&lt;br /&gt;
{{cat|/etc/fstab|...&lt;br /&gt;
proc    /proc   proc    nosuid,nodev,noexec,hidepid{{=}}2 0 0&lt;br /&gt;
...}}&lt;br /&gt;
Reduce procfs and sysfs information by removing read access to some files (may break your system):&lt;br /&gt;
{{cmd|&lt;br /&gt;
chmod 400 /proc/$FILE&lt;br /&gt;
chmod 400 /sys&lt;br /&gt;
chmod 400 /sys/$ANY_FILE_IN_DIR&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Set as many directories and files as possible as non-executable, read-only. And mount file-systems as non-executable and read-only.&lt;br /&gt;
&lt;br /&gt;
Consider between AppArmor and SELinux. AppArmor is more convenient to work with, but not as granular since it&#039;s path-based. SELinux is label-based, and it is more granular, obvious trade-off is it&#039;s more difficult to work with (for most people). linux-lts package only enables AppArmor.&lt;br /&gt;
&lt;br /&gt;
Apply [https://en.wikipedia.org/wiki/Principle_of_least_privilege PoLP] (Principle of Least Privilege) wherever possible.&lt;br /&gt;
&lt;br /&gt;
Have as little packages as possible on your system, minimalize amount of software on your system.&lt;br /&gt;
&lt;br /&gt;
Get rid of debugging tools.&lt;br /&gt;
&lt;br /&gt;
Use &amp;lt;code&amp;gt;doas&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;doasedit&amp;lt;/code&amp;gt; if root is needed. (I believe &amp;lt;code&amp;gt;doasedit&amp;lt;/code&amp;gt; is in the testing repo.)&lt;br /&gt;
&lt;br /&gt;
There is the obvious, which is DISABLE internet access to specific sandboxed/virtualized applications, or disable internet as a whole for a device if practical. (Basically firewalling/VLAN&#039;ing)&lt;br /&gt;
&lt;br /&gt;
Obvious make full backups&lt;br /&gt;
&lt;br /&gt;
File encryption can be used in tandem with FDE, for granular encryption.&lt;br /&gt;
&lt;br /&gt;
Same could be said for read-only integrity for files/directories.&lt;br /&gt;
&lt;br /&gt;
Always use HTTPS to download repository packages for your system.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Unfortunately, there is way too much for securing a traditional Linux server. Not impossible, just a lot left out that could have been done securing traditional Linux based OS&#039;. (BTW it&#039;s the same for traditional Unix based OS&#039;...)&lt;br /&gt;
&lt;br /&gt;
Security should be done by default, if not, while you configure your operating system for security, you are already compromised from the start. And more secure users is better than less, for example as you communicate with other secure users you are protected as well, protecting your communications with others.&lt;br /&gt;
&lt;br /&gt;
Follow [https://wiki.alpinelinux.org/wiki/DM-verity DM-Verity] wiki for an attempt at full verified/trusted boot on Alpine Linux.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
At this point, it would be it&#039;s own Linux distro&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=User:Pursuable1652&amp;diff=28779</id>
		<title>User:Pursuable1652</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=User:Pursuable1652&amp;diff=28779"/>
		<updated>2025-01-13T04:47:09Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hello, I&#039;m Pursuable1652, I like scripting, some different types of development, modifying hardware/software, like learning about home-servers or networking (or general server administration)/(homelabbing), also like learning some security and privacy, and more (I&#039;m very passionate about computers), and I helped make these wiki pages:&lt;br /&gt;
&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Hardened_linux&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/DM-verity&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Silent_boot&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Hardened_malloc&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Clevis (clevis + tang auto decryption for servers)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/GVisor&lt;br /&gt;
&lt;br /&gt;
Working on apparmor profiles for init-services for openrc, MUST be ran in initramfs or at least before running openrc as PID1..&lt;br /&gt;
&lt;br /&gt;
It is possible to run a traditional Linux system without root access (use system without doas, sudo, or becoming root in any other way), by setting your user a part of docker group (AND possibly a lot more). But it is challenging since I had to create a power service (because I want to control power of server without root) ran as an init service, and call back to it (using a non-root user) to a /run/*.socket, since I don&#039;t have root access. &lt;br /&gt;
&lt;br /&gt;
Possible to run system with dm-verity enforcing a read only system. The read only image ideally should have [usr,sbin,bin,lib] as read-only. everything else (kernel virtual filesystems: [dev,proc,sys,tmp,run]) and (user writable directories  [var,etc,home]) are just empty directories in the erofs image.&lt;br /&gt;
&lt;br /&gt;
Using dm-verity and read-only images (basically immutable distro?), would benefit from an upgrade server. Basically a server that provides the read-only images, and any other files needed to upgrade a Linux system. This could be similar to setting up an APK repo for alpine Linux, but instead just putting your compressed (tar&#039;ed?) readonly images plus other files in the web directory, so other servers/devices can upgrade from it.&lt;br /&gt;
&lt;br /&gt;
My main goal is to secure Linux more, and better (and as a side-effect, very different) than traditional Linux distros. My guide is more suited to a server use-case, rather than desktop.&lt;br /&gt;
&lt;br /&gt;
The guides still apply to both server and desktop, but desktop has a bigger attack surface usually, because an app ecosystem must be incorporated with security as its designed (compared to server which could just be dockerized + gvisored + apparmored/selinuxed or virtualized).&lt;br /&gt;
&lt;br /&gt;
Flatpak on desktop is somewhat flawed because it&#039;s allow-permission first, rather than deny-permission first.&lt;br /&gt;
&lt;br /&gt;
It might be thought of as, you compile the software, the software is open-source, so it must be secure, right? (That is not true, because software, especially software with bigger LOC (lines of code), will be more complex, thus may have more bugs that are hard to detect from the human-eye, and these bugs may do any rogue things to your system.)&lt;br /&gt;
&lt;br /&gt;
Desktop may have a more harder way of controlling the security of software, since you need the support of an app ecosystem already working on a predefined-security focused platform, so not all apps are just running without a sandbox/vm (ideally without a VM (run all in sandbox) or maybe just one, because using virtual machines has a performance loss).&lt;br /&gt;
&lt;br /&gt;
To be honest, I recommend using Android/AOSP and ChromeOS/ChromiumOS for a secure OS based on Linux kernel, since they already have a huge app ecosystem built with Java and Kotlin, based on an SELinux&#039;ed platform with Verified Boot enabled by default, and root disallowed by default.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Some wikis I did not write, but may help with security of Alpine Linux (or just miscellaneous):&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/AppArmor (or possibly SELinux if your kernel supports it, default linux-lts doesn&#039;t)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Docker (if you use docker, also use GVisor for full sandboxing)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Securing_Alpine_Linux&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Sysctl.conf#Security (can also use kernel-hardening-checker for suggestions on sysctl and boot parameter secure options)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/CPU_Microcode (&amp;lt;code&amp;gt;cat /sys/devices/system/cpu/vulnerabilities/*&amp;lt;/code&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
Some more info about securing Alpine Linux:&lt;br /&gt;
&lt;br /&gt;
Reduce procfs information to non-root users by appending &amp;lt;code&amp;gt;hidepid&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;proc&amp;lt;/code&amp;gt;:&lt;br /&gt;
{{cat|/etc/fstab|...&lt;br /&gt;
proc    /proc   proc    nosuid,nodev,noexec,hidepid{{=}}2 0 0&lt;br /&gt;
...}}&lt;br /&gt;
Reduce procfs and sysfs information by removing read access to some files (may break your system):&lt;br /&gt;
{{cmd|&lt;br /&gt;
chmod 400 /proc/$FILE&lt;br /&gt;
chmod 400 /sys&lt;br /&gt;
chmod 400 /sys/$ANY_FILE_IN_DIR&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Set as many directories and files as possible as non-executable, read-only. And mount file-systems as non-executable and read-only.&lt;br /&gt;
&lt;br /&gt;
Consider between AppArmor and SELinux. AppArmor is more convenient to work with, but not as granular since it&#039;s path-based. SELinux is label-based, and it is more granular, obvious trade-off is it&#039;s more difficult to work with (for most people). linux-lts package only enables AppArmor.&lt;br /&gt;
&lt;br /&gt;
Apply [https://en.wikipedia.org/wiki/Principle_of_least_privilege PoLP] (Principle of Least Privilege) wherever possible.&lt;br /&gt;
&lt;br /&gt;
Have as little packages as possible on your system, minimalize amount of software on your system.&lt;br /&gt;
&lt;br /&gt;
Get rid of debugging tools.&lt;br /&gt;
&lt;br /&gt;
Use &amp;lt;code&amp;gt;doas&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;doasedit&amp;lt;/code&amp;gt; if root is needed. (I believe &amp;lt;code&amp;gt;doasedit&amp;lt;/code&amp;gt; is in the testing repo.)&lt;br /&gt;
&lt;br /&gt;
There is the obvious, which is DISABLE internet access to specific sandboxed/virtualized applications, or disable internet as a whole for a device if practical. (Basically firewalling/VLAN&#039;ing)&lt;br /&gt;
&lt;br /&gt;
Obvious make full backups&lt;br /&gt;
&lt;br /&gt;
File encryption can be used in tandem with FDE, for granular encryption.&lt;br /&gt;
&lt;br /&gt;
Same could be said for read-only integrity for files/directories.&lt;br /&gt;
&lt;br /&gt;
Always use HTTPS to download repository packages for your system.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Unfortunately, there is way too much for securing a traditional Linux server. Not impossible, just a lot left out that could have been done securing traditional Linux based OS&#039;. (BTW it&#039;s the same for traditional Unix based OS&#039;...)&lt;br /&gt;
&lt;br /&gt;
Security should be done by default, if not, while you configure your operating system for security, you are already compromised from the start. And more secure users is better than less, for example as you communicate with other secure users you are protected as well, protecting your communications with others.&lt;br /&gt;
&lt;br /&gt;
Follow [https://wiki.alpinelinux.org/wiki/DM-verity DM-Verity] wiki for an attempt at full verified/trusted boot on Alpine Linux.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
At this point, it would be it&#039;s own Linux distro&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=User:Pursuable1652&amp;diff=28778</id>
		<title>User:Pursuable1652</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=User:Pursuable1652&amp;diff=28778"/>
		<updated>2025-01-13T04:42:50Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hello, I&#039;m Pursuable1652, I like scripting, some different types of development, modifying hardware/software, like learning about home-servers or networking (or general server administration)/(homelabbing), also like learning some security and privacy, and more (I&#039;m very passionate about computers), and I helped make these wiki pages:&lt;br /&gt;
&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Hardened_linux&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/DM-verity&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Silent_boot&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Hardened_malloc&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Clevis (clevis + tang auto decryption for servers)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/GVisor&lt;br /&gt;
&lt;br /&gt;
Working on apparmor profiles for init-services for openrc, MUST be ran in initramfs or at least before running openrc as PID1..&lt;br /&gt;
&lt;br /&gt;
It is possible to run a traditional Linux system without root access (use system without doas, sudo, or becoming root in any other way), by setting your user a part of docker group (AND possibly a lot more). But it is challenging since I had to create a power service (because I want to control power of server without root) ran as an init service, and call back to it (using a non-root user) to a /run/*.socket, since I don&#039;t have root access. &lt;br /&gt;
&lt;br /&gt;
Possible to run system with dm-verity enforcing a read only system. The read only image ideally should have [usr,sbin,bin,lib] as read-only. everything else (kernel virtual filesystems: [dev,proc,sys,tmp,run]) and (user writable directories  [var,etc,home]) are just empty directories in the erofs image.&lt;br /&gt;
&lt;br /&gt;
My main goal is to secure Linux more, and better (and as a side-effect, very different) than traditional Linux distros. My guide is more suited to a server use-case, rather than desktop.&lt;br /&gt;
&lt;br /&gt;
The guides still apply to both server and desktop, but desktop has a bigger attack surface usually, because an app ecosystem must be incorporated with security as its designed (compared to server which could just be dockerized + gvisored + apparmored/selinuxed or virtualized).&lt;br /&gt;
&lt;br /&gt;
Flatpak on desktop is somewhat flawed because it&#039;s allow-permission first, rather than deny-permission first.&lt;br /&gt;
&lt;br /&gt;
It might be thought of as, you compile the software, the software is open-source, so it must be secure, right? (That is not true, because software, especially software with bigger LOC (lines of code), will be more complex, thus may have more bugs that are hard to detect from the human-eye, and these bugs may do any rogue things to your system.)&lt;br /&gt;
&lt;br /&gt;
Desktop may have a more harder way of controlling the security of software, since you need the support of an app ecosystem already working on a predefined-security focused platform, so not all apps are just running without a sandbox/vm (ideally without a VM (run all in sandbox) or maybe just one, because using virtual machines has a performance loss).&lt;br /&gt;
&lt;br /&gt;
To be honest, I recommend using Android/AOSP and ChromeOS/ChromiumOS for a secure OS based on Linux kernel, since they already have a huge app ecosystem built with Java and Kotlin, based on an SELinux&#039;ed platform with Verified Boot enabled by default, and root disallowed by default.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Some wikis I did not write, but may help with security of Alpine Linux (or just miscellaneous):&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/AppArmor (or possibly SELinux if your kernel supports it, default linux-lts doesn&#039;t)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Docker (if you use docker, also use GVisor for full sandboxing)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Securing_Alpine_Linux&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Sysctl.conf#Security (can also use kernel-hardening-checker for suggestions on sysctl and boot parameter secure options)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/CPU_Microcode (&amp;lt;code&amp;gt;cat /sys/devices/system/cpu/vulnerabilities/*&amp;lt;/code&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
Some more info about securing Alpine Linux:&lt;br /&gt;
&lt;br /&gt;
Reduce procfs information to non-root users by appending &amp;lt;code&amp;gt;hidepid&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;proc&amp;lt;/code&amp;gt;:&lt;br /&gt;
{{cat|/etc/fstab|...&lt;br /&gt;
proc    /proc   proc    nosuid,nodev,noexec,hidepid{{=}}2 0 0&lt;br /&gt;
...}}&lt;br /&gt;
Reduce procfs and sysfs information by removing read access to some files (may break your system):&lt;br /&gt;
{{cmd|&lt;br /&gt;
chmod 400 /proc/$FILE&lt;br /&gt;
chmod 400 /sys&lt;br /&gt;
chmod 400 /sys/$ANY_FILE_IN_DIR&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Set as many directories and files as possible as non-executable, read-only. And mount file-systems as non-executable and read-only.&lt;br /&gt;
&lt;br /&gt;
Consider between AppArmor and SELinux. AppArmor is more convenient to work with, but not as granular since it&#039;s path-based. SELinux is label-based, and it is more granular, obvious trade-off is it&#039;s more difficult to work with (for most people). linux-lts package only enables AppArmor.&lt;br /&gt;
&lt;br /&gt;
Apply [https://en.wikipedia.org/wiki/Principle_of_least_privilege PoLP] (Principle of Least Privilege) wherever possible.&lt;br /&gt;
&lt;br /&gt;
Have as little packages as possible on your system, minimalize amount of software on your system.&lt;br /&gt;
&lt;br /&gt;
Get rid of debugging tools.&lt;br /&gt;
&lt;br /&gt;
Use &amp;lt;code&amp;gt;doas&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;doasedit&amp;lt;/code&amp;gt; if root is needed. (I believe &amp;lt;code&amp;gt;doasedit&amp;lt;/code&amp;gt; is in the testing repo.)&lt;br /&gt;
&lt;br /&gt;
There is the obvious, which is DISABLE internet access to specific sandboxed/virtualized applications, or disable internet as a whole for a device if practical. (Basically firewalling/VLAN&#039;ing)&lt;br /&gt;
&lt;br /&gt;
Obvious make full backups&lt;br /&gt;
&lt;br /&gt;
File encryption can be used in tandem with FDE, for granular encryption.&lt;br /&gt;
&lt;br /&gt;
Same could be said for read-only integrity for files/directories.&lt;br /&gt;
&lt;br /&gt;
Always use HTTPS to download repository packages for your system.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Unfortunately, there is way too much for securing a traditional Linux server. Not impossible, just a lot left out that could have been done securing traditional Linux based OS&#039;. (BTW it&#039;s the same for traditional Unix based OS&#039;...)&lt;br /&gt;
&lt;br /&gt;
Security should be done by default, if not, while you configure your operating system for security, you are already compromised from the start. And more secure users is better than less, for example as you communicate with other secure users you are protected as well, protecting your communications with others.&lt;br /&gt;
&lt;br /&gt;
Follow [https://wiki.alpinelinux.org/wiki/DM-verity DM-Verity] wiki for an attempt at full verified/trusted boot on Alpine Linux.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
At this point, it would be it&#039;s own Linux distro&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=User:Pursuable1652&amp;diff=28777</id>
		<title>User:Pursuable1652</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=User:Pursuable1652&amp;diff=28777"/>
		<updated>2025-01-13T04:40:35Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hello, I&#039;m Pursuable1652, I like scripting, some different types of development, modifying hardware/software, like learning about home-servers or networking (or general server administration)/(homelabbing), also like learning some security and privacy, and more (I&#039;m very passionate about computers), and I helped make these wiki pages:&lt;br /&gt;
&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Hardened_linux&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/DM-verity&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Silent_boot&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Hardened_malloc&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Clevis (clevis + tang auto decryption for servers)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/GVisor&lt;br /&gt;
&lt;br /&gt;
Working on apparmor profiles for init-services for openrc, MUST be ran in initramfs or at least before running openrc as PID1..&lt;br /&gt;
&lt;br /&gt;
It is possible to run a traditional Linux system without root access (use system without doas, sudo, or becoming root in any other way), by setting your user a part of docker group. But it is challenging since I had to run some things as init services, and call back to it (using a non-root user) to a /run/*.socket where I wouldn&#039;t be able to use root access. &lt;br /&gt;
&lt;br /&gt;
Possible to run system with dm-verity enforcing a read only system. The read only image ideally should have [usr,sbin,bin,lib] as read-only. everything else (kernel virtual filesystems: [dev,proc,sys,tmp,run]) and (user writable directories  [var,etc,home]) are just empty directories in the erofs image.&lt;br /&gt;
&lt;br /&gt;
My main goal is to secure Linux more, and better (and as a side-effect, very different) than traditional Linux distros. My guide is more suited to a server use-case, rather than desktop.&lt;br /&gt;
&lt;br /&gt;
The guides still apply to both server and desktop, but desktop has a bigger attack surface usually, because an app ecosystem must be incorporated with security as its designed (compared to server which could just be dockerized + gvisored + apparmored/selinuxed or virtualized).&lt;br /&gt;
&lt;br /&gt;
Flatpak on desktop is somewhat flawed because it&#039;s allow-permission first, rather than deny-permission first.&lt;br /&gt;
&lt;br /&gt;
It might be thought of as, you compile the software, the software is open-source, so it must be secure, right? (That is not true, because software, especially software with bigger LOC (lines of code), will be more complex, thus may have more bugs that are hard to detect from the human-eye, and these bugs may do any rogue things to your system.)&lt;br /&gt;
&lt;br /&gt;
Desktop may have a more harder way of controlling the security of software, since you need the support of an app ecosystem already working on a predefined-security focused platform, so not all apps are just running without a sandbox/vm (ideally without a VM (run all in sandbox) or maybe just one, because using virtual machines has a performance loss).&lt;br /&gt;
&lt;br /&gt;
To be honest, I recommend using Android/AOSP and ChromeOS/ChromiumOS for a secure OS based on Linux kernel, since they already have a huge app ecosystem built with Java and Kotlin, based on an SELinux&#039;ed platform with Verified Boot enabled by default, and root disallowed by default.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Some wikis I did not write, but may help with security of Alpine Linux (or just miscellaneous):&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/AppArmor (or possibly SELinux if your kernel supports it, default linux-lts doesn&#039;t)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Docker (if you use docker, also use GVisor for full sandboxing)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Securing_Alpine_Linux&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Sysctl.conf#Security (can also use kernel-hardening-checker for suggestions on sysctl and boot parameter secure options)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/CPU_Microcode (&amp;lt;code&amp;gt;cat /sys/devices/system/cpu/vulnerabilities/*&amp;lt;/code&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
Some more info about securing Alpine Linux:&lt;br /&gt;
&lt;br /&gt;
Reduce procfs information to non-root users by appending &amp;lt;code&amp;gt;hidepid&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;proc&amp;lt;/code&amp;gt;:&lt;br /&gt;
{{cat|/etc/fstab|...&lt;br /&gt;
proc    /proc   proc    nosuid,nodev,noexec,hidepid{{=}}2 0 0&lt;br /&gt;
...}}&lt;br /&gt;
Reduce procfs and sysfs information by removing read access to some files (may break your system):&lt;br /&gt;
{{cmd|&lt;br /&gt;
chmod 400 /proc/$FILE&lt;br /&gt;
chmod 400 /sys&lt;br /&gt;
chmod 400 /sys/$ANY_FILE_IN_DIR&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Set as many directories and files as possible as non-executable, read-only. And mount file-systems as non-executable and read-only.&lt;br /&gt;
&lt;br /&gt;
Consider between AppArmor and SELinux. AppArmor is more convenient to work with, but not as granular since it&#039;s path-based. SELinux is label-based, and it is more granular, obvious trade-off is it&#039;s more difficult to work with (for most people). linux-lts package only enables AppArmor.&lt;br /&gt;
&lt;br /&gt;
Apply [https://en.wikipedia.org/wiki/Principle_of_least_privilege PoLP] (Principle of Least Privilege) wherever possible.&lt;br /&gt;
&lt;br /&gt;
Have as little packages as possible on your system, minimalize amount of software on your system.&lt;br /&gt;
&lt;br /&gt;
Get rid of debugging tools.&lt;br /&gt;
&lt;br /&gt;
Use &amp;lt;code&amp;gt;doas&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;doasedit&amp;lt;/code&amp;gt; if root is needed. (I believe &amp;lt;code&amp;gt;doasedit&amp;lt;/code&amp;gt; is in the testing repo.)&lt;br /&gt;
&lt;br /&gt;
There is the obvious, which is DISABLE internet access to specific sandboxed/virtualized applications, or disable internet as a whole for a device if practical. (Basically firewalling/VLAN&#039;ing)&lt;br /&gt;
&lt;br /&gt;
Obvious make full backups&lt;br /&gt;
&lt;br /&gt;
File encryption can be used in tandem with FDE, for granular encryption.&lt;br /&gt;
&lt;br /&gt;
Same could be said for read-only integrity for files/directories.&lt;br /&gt;
&lt;br /&gt;
Always use HTTPS to download repository packages for your system.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Unfortunately, there is way too much for securing a traditional Linux server. Not impossible, just a lot left out that could have been done securing traditional Linux based OS&#039;. (BTW it&#039;s the same for traditional Unix based OS&#039;...)&lt;br /&gt;
&lt;br /&gt;
Security should be done by default, if not, while you configure your operating system for security, you are already compromised from the start. And more secure users is better than less, for example as you communicate with other secure users you are protected as well, protecting your communications with others.&lt;br /&gt;
&lt;br /&gt;
Follow [https://wiki.alpinelinux.org/wiki/DM-verity DM-Verity] wiki for an attempt at full verified/trusted boot on Alpine Linux.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
At this point, it would be it&#039;s own Linux distro&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=User:Pursuable1652&amp;diff=28656</id>
		<title>User:Pursuable1652</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=User:Pursuable1652&amp;diff=28656"/>
		<updated>2025-01-08T23:51:00Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hello, I&#039;m Pursuable1652, I like scripting, some different types of development, modifying hardware/software, like learning about home-servers or networking (or general server administration)/(homelabbing), also like learning some security and privacy, and more (I&#039;m very passionate about computers), and I helped make these wiki pages:&lt;br /&gt;
&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Hardened_linux&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/DM-verity&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Silent_boot&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Hardened_malloc&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Clevis (clevis + tang auto decryption for servers)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/GVisor&lt;br /&gt;
&lt;br /&gt;
My main goal is to secure Linux more, and better (and as a side-effect, very different) than traditional Linux distros. My guide is more suited to a server use-case, rather than desktop.&lt;br /&gt;
&lt;br /&gt;
The guides still apply to both server and desktop, but desktop has a bigger attack surface usually, because an app ecosystem must be incorporated with security as its designed (compared to server which could just be dockerized + gvisored + apparmored/selinuxed or virtualized).&lt;br /&gt;
&lt;br /&gt;
Flatpak on desktop is somewhat flawed because it&#039;s allow-permission first, rather than deny-permission first.&lt;br /&gt;
&lt;br /&gt;
It might be thought of as, you compile the software, the software is open-source, so it must be secure, right? (That is not true, because software, especially software with bigger LOC (lines of code), will be more complex, thus may have more bugs that are hard to detect from the human-eye, and these bugs may do any rogue things to your system.)&lt;br /&gt;
&lt;br /&gt;
Desktop may have a more harder way of controlling the security of software, since you need the support of an app ecosystem already working on a predefined-security focused platform, so not all apps are just running without a sandbox/vm (ideally without a VM (run all in sandbox) or maybe just one, because using virtual machines has a performance loss).&lt;br /&gt;
&lt;br /&gt;
To be honest, I recommend using Android/AOSP and ChromeOS/ChromiumOS for a secure OS based on Linux kernel, since they already have a huge app ecosystem built with Java and Kotlin, based on an SELinux&#039;ed platform with Verified Boot enabled by default, and root disallowed by default.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Some wikis I did not write, but may help with security of Alpine Linux (or just miscellaneous):&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/AppArmor (or possibly SELinux if your kernel supports it, default linux-lts doesn&#039;t)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Docker (if you use docker, also use GVisor for full sandboxing)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Securing_Alpine_Linux&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Sysctl.conf#Security (can also use kernel-hardening-checker for suggestions on sysctl and boot parameter secure options)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/CPU_Microcode (&amp;lt;code&amp;gt;cat /sys/devices/system/cpu/vulnerabilities/*&amp;lt;/code&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
Some more info about securing Alpine Linux:&lt;br /&gt;
&lt;br /&gt;
Reduce procfs information to non-root users by appending &amp;lt;code&amp;gt;hidepid&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;proc&amp;lt;/code&amp;gt;:&lt;br /&gt;
{{cat|/etc/fstab|...&lt;br /&gt;
proc    /proc   proc    nosuid,nodev,noexec,hidepid{{=}}2 0 0&lt;br /&gt;
...}}&lt;br /&gt;
Reduce procfs and sysfs information by removing read access to some files (may break your system):&lt;br /&gt;
{{cmd|&lt;br /&gt;
chmod 400 /proc/$FILE&lt;br /&gt;
chmod 400 /sys&lt;br /&gt;
chmod 400 /sys/$ANY_FILE_IN_DIR&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Set as many directories and files as possible as non-executable, read-only. And mount file-systems as non-executable and read-only.&lt;br /&gt;
&lt;br /&gt;
Consider between AppArmor and SELinux. AppArmor is more convenient to work with, but not as granular since it&#039;s path-based. SELinux is label-based, and it is more granular, obvious trade-off is it&#039;s more difficult to work with (for most people). linux-lts package only enables AppArmor.&lt;br /&gt;
&lt;br /&gt;
Apply [https://en.wikipedia.org/wiki/Principle_of_least_privilege PoLP] (Principle of Least Privilege) wherever possible.&lt;br /&gt;
&lt;br /&gt;
Have as little packages as possible on your system, minimalize amount of software on your system.&lt;br /&gt;
&lt;br /&gt;
Get rid of debugging tools.&lt;br /&gt;
&lt;br /&gt;
Use &amp;lt;code&amp;gt;doas&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;doasedit&amp;lt;/code&amp;gt; if root is needed. (I believe &amp;lt;code&amp;gt;doasedit&amp;lt;/code&amp;gt; is in the testing repo.)&lt;br /&gt;
&lt;br /&gt;
There is the obvious, which is DISABLE internet access to specific sandboxed/virtualized applications, or disable internet as a whole for a device if practical. (Basically firewalling/VLAN&#039;ing)&lt;br /&gt;
&lt;br /&gt;
Obvious make full backups&lt;br /&gt;
&lt;br /&gt;
File encryption can be used in tandem with FDE, for granular encryption.&lt;br /&gt;
&lt;br /&gt;
Same could be said for read-only integrity for files/directories.&lt;br /&gt;
&lt;br /&gt;
Always use HTTPS to download repository packages for your system.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Unfortunately, there is way too much for securing a traditional Linux server. Not impossible, just a lot left out that could have been done securing traditional Linux based OS&#039;. (BTW it&#039;s the same for traditional Unix based OS&#039;...)&lt;br /&gt;
&lt;br /&gt;
Security should be done by default, if not, while you configure your operating system for security, you are already compromised from the start. And more secure users is better than less, for example as you communicate with other secure users you are protected as well, protecting your communications with others.&lt;br /&gt;
&lt;br /&gt;
Follow [https://wiki.alpinelinux.org/wiki/DM-verity DM-Verity] wiki for an attempt at full verified/trusted boot on Alpine Linux.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
At this point, it would be it&#039;s own Linux distro&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=GVisor&amp;diff=28629</id>
		<title>GVisor</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=GVisor&amp;diff=28629"/>
		<updated>2024-12-31T01:34:10Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What is gVisor? ==&lt;br /&gt;
It is a kernel syscall implementation in the language Go. It helps isolate the kernel from the container.&lt;br /&gt;
&lt;br /&gt;
== How to implement gVisor ==&lt;br /&gt;
Run instructions on here: [https://gvisor.dev/docs/user_guide/install/ https://gvisor.dev/docs/user_guide/install/]&lt;br /&gt;
&lt;br /&gt;
{{cmd| &amp;lt;nowiki&amp;gt;(&lt;br /&gt;
  set -e&lt;br /&gt;
  ARCH=$(uname -m)&lt;br /&gt;
  URL=https://storage.googleapis.com/gvisor/releases/release/latest/${ARCH}&lt;br /&gt;
  wget ${URL}/runsc ${URL}/runsc.sha512 \&lt;br /&gt;
    ${URL}/containerd-shim-runsc-v1 ${URL}/containerd-shim-runsc-v1.sha512&lt;br /&gt;
  sha512sum -c runsc.sha512 \&lt;br /&gt;
    -c containerd-shim-runsc-v1.sha512&lt;br /&gt;
  rm -f *.sha512&lt;br /&gt;
  chmod a+rx runsc containerd-shim-runsc-v1&lt;br /&gt;
  doas mv runsc containerd-shim-runsc-v1 /usr/local/bin&lt;br /&gt;
)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{cmd| &lt;br /&gt;
/usr/local/bin/runsc install&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Set sysctl to disable Yama ptrace scoping and increase max amount of namespaces (may increase surface of attack):&lt;br /&gt;
{{cat|/etc/sysctl.conf|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
user.max_user_namespaces=7182 # Set however amount needed...&lt;br /&gt;
kernel.yama.ptrace_scope=0&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Now append, for &amp;lt;code&amp;gt;docker run&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;--runtime=runsc&amp;lt;/code&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Or for &amp;lt;code&amp;gt;compose.yml&amp;lt;/code&amp;gt;, do &amp;lt;code&amp;gt;runtime: runsc&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Security]]&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=User:Pursuable1652&amp;diff=28628</id>
		<title>User:Pursuable1652</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=User:Pursuable1652&amp;diff=28628"/>
		<updated>2024-12-31T01:31:07Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hello, I&#039;m Pursuable1652, I like scripting, some different types of development, modifying hardware/software, like learning about home-servers or networking (or general server administration)/(homelabbing), also like learning some security and privacy, I know soldering and repairing, and more (I&#039;m very passionate about computers), and I helped make these wiki pages:&lt;br /&gt;
&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Hardened_linux&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/DM-verity&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Silent_boot&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Hardened_malloc&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Clevis (clevis + tang auto decryption for servers)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/GVisor&lt;br /&gt;
&lt;br /&gt;
My main goal is to secure Linux more, and better (and as a side-effect, very different) than traditional Linux distros. My guide is more suited to a server use-case, rather than desktop.&lt;br /&gt;
&lt;br /&gt;
The guides still apply to both server and desktop, but desktop has a bigger attack surface usually, because an app ecosystem must be incorporated with security as its designed (compared to server which could just be dockerized + gvisored + apparmored/selinuxed or virtualized).&lt;br /&gt;
&lt;br /&gt;
Flatpak on desktop is somewhat flawed because it&#039;s allow-permission first, rather than deny-permission first.&lt;br /&gt;
&lt;br /&gt;
It might be thought of as, you compile the software, the software is open-source, so it must be secure, right? (That is not true, because software, especially software with bigger LOC (lines of code), will be more complex, thus may have more bugs that are hard to detect from the human-eye, and these bugs may do any rogue things to your system.)&lt;br /&gt;
&lt;br /&gt;
Desktop may have a more harder way of controlling the security of software, since you need the support of an app ecosystem already working on a predefined-security focused platform, so not all apps are just running without a sandbox/vm (ideally without a VM (run all in sandbox) or maybe just one, because using virtual machines has a performance loss).&lt;br /&gt;
&lt;br /&gt;
To be honest, I recommend using Android/AOSP and ChromeOS/ChromiumOS for a secure OS based on Linux kernel, since they already have a huge app ecosystem built with Java and Kotlin, based on an SELinux&#039;ed platform with Verified Boot enabled by default, and root disallowed by default.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Some wikis I did not write, but may help with security of Alpine Linux (or just miscellaneous):&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/AppArmor (or possibly SELinux if your kernel supports it, default linux-lts doesn&#039;t)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Docker (if you use docker, also use GVisor for full sandboxing)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Securing_Alpine_Linux&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Sysctl.conf#Security (can also use kernel-hardening-checker for suggestions on sysctl and boot parameter secure options)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/CPU_Microcode (&amp;lt;code&amp;gt;cat /sys/devices/system/cpu/vulnerabilities/*&amp;lt;/code&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
Some more info about securing Alpine Linux:&lt;br /&gt;
&lt;br /&gt;
Reduce procfs information to non-root users by appending &amp;lt;code&amp;gt;hidepid&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;proc&amp;lt;/code&amp;gt;:&lt;br /&gt;
{{cat|/etc/fstab|...&lt;br /&gt;
proc    /proc   proc    nosuid,nodev,noexec,hidepid{{=}}2 0 0&lt;br /&gt;
...}}&lt;br /&gt;
Reduce procfs and sysfs information by removing read access to some files (may break your system):&lt;br /&gt;
{{cmd|&lt;br /&gt;
chmod 400 /proc/$FILE&lt;br /&gt;
chmod 400 /sys&lt;br /&gt;
chmod 400 /sys/$ANY_FILE_IN_DIR&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Set as many directories and files as possible as non-executable, read-only. And mount file-systems as non-executable and read-only.&lt;br /&gt;
&lt;br /&gt;
Consider between AppArmor and SELinux. AppArmor is more convenient to work with, but not as granular since it&#039;s path-based. SELinux is label-based, and it is more granular, obvious trade-off is it&#039;s more difficult to work with (for most people). linux-lts package only enables AppArmor.&lt;br /&gt;
&lt;br /&gt;
Apply [https://en.wikipedia.org/wiki/Principle_of_least_privilege PoLP] (Principle of Least Privilege) wherever possible.&lt;br /&gt;
&lt;br /&gt;
Have as little packages as possible on your system, minimalize amount of software on your system.&lt;br /&gt;
&lt;br /&gt;
Get rid of debugging tools.&lt;br /&gt;
&lt;br /&gt;
Use &amp;lt;code&amp;gt;doas&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;doasedit&amp;lt;/code&amp;gt; if root is needed. (I believe &amp;lt;code&amp;gt;doasedit&amp;lt;/code&amp;gt; is in the testing repo.)&lt;br /&gt;
&lt;br /&gt;
There is the obvious, which is DISABLE internet access to specific sandboxed/virtualized applications, or disable internet as a whole for a device if practical. (Basically firewalling/VLAN&#039;ing)&lt;br /&gt;
&lt;br /&gt;
Obvious make full backups&lt;br /&gt;
&lt;br /&gt;
File encryption can be used in tandem with FDE, for granular encryption.&lt;br /&gt;
&lt;br /&gt;
Same could be said for read-only integrity for files/directories.&lt;br /&gt;
&lt;br /&gt;
Always use HTTPS to download repository packages for your system.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Unfortunately, there is way too much for securing a traditional Linux server. Not impossible, just a lot left out that could have been done securing traditional Linux based OS&#039;. (BTW it&#039;s the same for traditional Unix based OS&#039;...)&lt;br /&gt;
&lt;br /&gt;
Security should be done by default, if not, while you configure your operating system for security, you are already compromised from the start. And more secure users is better than less, for example as you communicate with other secure users you are protected as well, protecting your communications with others.&lt;br /&gt;
&lt;br /&gt;
Follow [https://wiki.alpinelinux.org/wiki/DM-verity DM-Verity] wiki for an attempt at full verified/trusted boot on Alpine Linux.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
At this point, it would be it&#039;s own Linux distro&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=GVisor&amp;diff=28627</id>
		<title>GVisor</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=GVisor&amp;diff=28627"/>
		<updated>2024-12-31T01:30:41Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: Created page with &amp;quot;== What is gVisor? == It is a kernel syscall implementation in the language Go. It helps isolate the kernel from the container.  == How to implement gVisor == Run instructions on here: [https://gvisor.dev/docs/user_guide/install/ https://gvisor.dev/docs/user_guide/install/]  {{cmd| &amp;lt;nowiki&amp;gt;(   set -e   ARCH=$(uname -m)   URL=https://storage.googleapis.com/gvisor/releases/release/latest/${ARCH}   wget ${URL}/runsc ${URL}/runsc.sha512 \     ${URL}/containerd-shim-runsc-v1...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What is gVisor? ==&lt;br /&gt;
It is a kernel syscall implementation in the language Go. It helps isolate the kernel from the container.&lt;br /&gt;
&lt;br /&gt;
== How to implement gVisor ==&lt;br /&gt;
Run instructions on here: [https://gvisor.dev/docs/user_guide/install/ https://gvisor.dev/docs/user_guide/install/]&lt;br /&gt;
&lt;br /&gt;
{{cmd| &amp;lt;nowiki&amp;gt;(&lt;br /&gt;
  set -e&lt;br /&gt;
  ARCH=$(uname -m)&lt;br /&gt;
  URL=https://storage.googleapis.com/gvisor/releases/release/latest/${ARCH}&lt;br /&gt;
  wget ${URL}/runsc ${URL}/runsc.sha512 \&lt;br /&gt;
    ${URL}/containerd-shim-runsc-v1 ${URL}/containerd-shim-runsc-v1.sha512&lt;br /&gt;
  sha512sum -c runsc.sha512 \&lt;br /&gt;
    -c containerd-shim-runsc-v1.sha512&lt;br /&gt;
  rm -f *.sha512&lt;br /&gt;
  chmod a+rx runsc containerd-shim-runsc-v1&lt;br /&gt;
  doas mv runsc containerd-shim-runsc-v1 /usr/local/bin&lt;br /&gt;
)&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{cmd| &lt;br /&gt;
/usr/local/bin/runsc install&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Set sysctl to disable Yama ptrace scoping and increase max amount of namespaces (may increase surface of attack):&lt;br /&gt;
{{cat|/etc/sysctl.conf|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
user.max_user_namespaces=7182 # Set however amount needed...&lt;br /&gt;
kernel.yama.ptrace_scope=0&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Security]]&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=User:Pursuable1652&amp;diff=28600</id>
		<title>User:Pursuable1652</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=User:Pursuable1652&amp;diff=28600"/>
		<updated>2024-12-30T01:16:17Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hello, I&#039;m Pursuable1652, I like scripting, some different types of development, modifying hardware/software, like learning about home-servers or networking (or general server administration)/(homelabbing), also like learning some security and privacy, I know soldering and repairing, and more (I&#039;m very passionate about computers), and I helped make these wiki pages:&lt;br /&gt;
&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Hardened_linux&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/DM-verity&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Silent_boot&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Hardened_malloc&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Clevis (clevis + tang auto decryption for servers)&lt;br /&gt;
&lt;br /&gt;
My main goal is to secure Linux more, and better (and as a side-effect, very different) than traditional Linux distros. My guide is more suited to a server use-case, rather than desktop.&lt;br /&gt;
&lt;br /&gt;
The guides still apply to both server and desktop, but desktop has a bigger attack surface usually, because an app ecosystem must be incorporated with security as its designed (compared to server which could just be dockerized + gvisored + apparmored/selinuxed or virtualized).&lt;br /&gt;
&lt;br /&gt;
Flatpak on desktop is somewhat flawed because it&#039;s allow-permission first, rather than deny-permission first.&lt;br /&gt;
&lt;br /&gt;
It might be thought of as, you compile the software, the software is open-source, so it must be secure, right? (That is not true, because software, especially software with bigger LOC (lines of code), will be more complex, thus may have more bugs that are hard to detect from the human-eye, and these bugs may do any rogue things to your system.)&lt;br /&gt;
&lt;br /&gt;
Desktop may have a more harder way of controlling the security of software, since you need the support of an app ecosystem already working on a predefined-security focused platform, so not all apps are just running without a sandbox/vm (ideally without a VM (run all in sandbox) or maybe just one, because using virtual machines has a performance loss).&lt;br /&gt;
&lt;br /&gt;
To be honest, I recommend using Android/AOSP and ChromeOS/ChromiumOS for a secure OS based on Linux kernel, since they already have a huge app ecosystem built with Java and Kotlin, based on an SELinux&#039;ed platform with Verified Boot enabled by default, and root disallowed by default.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Some wikis I did not write, but may help with security of Alpine Linux (or just miscellaneous):&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/AppArmor (or possibly SELinux if your kernel supports it, default linux-lts doesn&#039;t)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Docker (if you use docker, also use GVisor for full sandboxing)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Securing_Alpine_Linux&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Sysctl.conf#Security (can also use kernel-hardening-checker for suggestions on sysctl and boot parameter secure options)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/CPU_Microcode (&amp;lt;code&amp;gt;cat /sys/devices/system/cpu/vulnerabilities/*&amp;lt;/code&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
Some more info about securing Alpine Linux:&lt;br /&gt;
&lt;br /&gt;
Reduce procfs information to non-root users by appending &amp;lt;code&amp;gt;hidepid&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;proc&amp;lt;/code&amp;gt;:&lt;br /&gt;
{{cat|/etc/fstab|...&lt;br /&gt;
proc    /proc   proc    nosuid,nodev,noexec,hidepid{{=}}2 0 0&lt;br /&gt;
...}}&lt;br /&gt;
Reduce procfs and sysfs information by removing read access to some files (may break your system):&lt;br /&gt;
{{cmd|&lt;br /&gt;
chmod 400 /proc/$FILE&lt;br /&gt;
chmod 400 /sys&lt;br /&gt;
chmod 400 /sys/$ANY_FILE_IN_DIR&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Set as many directories and files as possible as non-executable, read-only. And mount file-systems as non-executable and read-only.&lt;br /&gt;
&lt;br /&gt;
Consider between AppArmor and SELinux. AppArmor is more convenient to work with, but not as granular since it&#039;s path-based. SELinux is label-based, and it is more granular, obvious trade-off is it&#039;s more difficult to work with (for most people). linux-lts package only enables AppArmor.&lt;br /&gt;
&lt;br /&gt;
Apply [https://en.wikipedia.org/wiki/Principle_of_least_privilege PoLP] (Principle of Least Privilege) wherever possible.&lt;br /&gt;
&lt;br /&gt;
Have as little packages as possible on your system, minimalize amount of software on your system.&lt;br /&gt;
&lt;br /&gt;
Get rid of debugging tools.&lt;br /&gt;
&lt;br /&gt;
Use &amp;lt;code&amp;gt;doas&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;doasedit&amp;lt;/code&amp;gt; if root is needed. (I believe &amp;lt;code&amp;gt;doasedit&amp;lt;/code&amp;gt; is in the testing repo.)&lt;br /&gt;
&lt;br /&gt;
There is the obvious, which is DISABLE internet access to specific sandboxed/virtualized applications, or disable internet as a whole for a device if practical. (Basically firewalling/VLAN&#039;ing)&lt;br /&gt;
&lt;br /&gt;
Obvious make full backups&lt;br /&gt;
&lt;br /&gt;
File encryption can be used in tandem with FDE, for granular encryption.&lt;br /&gt;
&lt;br /&gt;
Same could be said for read-only integrity for files/directories.&lt;br /&gt;
&lt;br /&gt;
Always use HTTPS to download repository packages for your system.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Unfortunately, there is way too much for securing a traditional Linux server. Not impossible, just a lot left out that could have been done securing traditional Linux based OS&#039;. (BTW it&#039;s the same for traditional Unix based OS&#039;...)&lt;br /&gt;
&lt;br /&gt;
Security should be done by default, if not, while you configure your operating system for security, you are already compromised from the start. And more secure users is better than less, for example as you communicate with other secure users you are protected as well, protecting your communications with others.&lt;br /&gt;
&lt;br /&gt;
Follow [https://wiki.alpinelinux.org/wiki/DM-verity DM-Verity] wiki for an attempt at full verified/trusted boot on Alpine Linux.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
At this point, it would be it&#039;s own Linux distro&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=CPU_Microcode&amp;diff=28599</id>
		<title>CPU Microcode</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=CPU_Microcode&amp;diff=28599"/>
		<updated>2024-12-30T01:14:20Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CPU &#039;&#039;&#039;microcode&#039;&#039;&#039; is a form of firmware that controls the processor&#039;s internals. &lt;br /&gt;
&lt;br /&gt;
In modern processors, the microcode handles execution of complex and highly specialized instructions. Parts of the microcode also act as firmware for the processor&#039;s embedded controllers, and it is even used to fix or to mitigate &#039;&#039;&#039;processor design/implementation errata/bugs&#039;&#039;&#039;. Given the complexity of modern processors, a CPU may have over a hundred such errata.&lt;br /&gt;
&lt;br /&gt;
Recently, microcode updates have become mandatory for security due to [https://en.wikipedia.org/wiki/Side-channel_attack side-channel attacks] against CPUs.&lt;br /&gt;
&lt;br /&gt;
== Obtaining microcode updates on Alpine ==&lt;br /&gt;
&lt;br /&gt;
{{Warning| Certain Intel CPUs, such Intel Atom with PSE errata, and Intel Haswell + Broadwell with TSX errata, can only be fixed via BIOS or UEFI update (which includes microcode); if you are using one of these CPUs, please do not use the instructions below}}&lt;br /&gt;
&lt;br /&gt;
On Alpine Linux, CPU microcode is loaded early via initrd images, premade images are available from packages:&lt;br /&gt;
&lt;br /&gt;
To obtain the microcode update package for AMD processors:&lt;br /&gt;
{{cmd|apk add {{pkg|amd-ucode}}}}&lt;br /&gt;
&lt;br /&gt;
To obtain the microcode update package for Intel processors:&lt;br /&gt;
{{cmd|apk add {{pkg|intel-ucode}}}}&lt;br /&gt;
&lt;br /&gt;
If you are using syslinux or grub in a typical setup, the packages will automatically append your {{path|extlinux.conf}} or {{path|grub.conf}} file and merely a reboot will be required to run the new microcode. Users using UEFI&#039;s built-in boot manager will have to use efibootmgr to add a second initrd line. Likewise if you are using the limine bootoader will need to add a 2nd MODULE_PATH directive in {{path|limine.cfg}} pointing to the ucode file.&lt;br /&gt;
&lt;br /&gt;
== Verifying that the microcode image has loaded ==&lt;br /&gt;
Run the command:&lt;br /&gt;
{{cmd|dmesg &amp;amp;#124; grep microcode}}&lt;br /&gt;
If the microcode initrd image was loaded, the microcode update driver will print a signature and revision&lt;br /&gt;
&lt;br /&gt;
Example for Intel:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[ 2.198775 ] microcode&amp;amp;#58; sig&amp;amp;#61;0x6fd, pf&amp;amp;#61;0x80, revision&amp;amp;#61;0xa4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example for AMD:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[   11.442146] microcode: Current revision: 0x0a0011d5&lt;br /&gt;
[   11.447027] microcode: Updated early from: 0x0a0011d3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Todo|Example needed for VIA CPUs, they seem to print slightly differently.}}&lt;br /&gt;
&lt;br /&gt;
== Check if CPU mitigation is working ==&lt;br /&gt;
This command not only shows if microcode is working, but other CPU vulnerabilities affected:&lt;br /&gt;
{{cmd|cat /sys/devices/system/cpu/vulnerabilities/*}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Security]]&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Clevis&amp;diff=28598</id>
		<title>Clevis</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Clevis&amp;diff=28598"/>
		<updated>2024-12-30T01:02:58Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{draft}}&lt;br /&gt;
&lt;br /&gt;
== What is clevis ==&lt;br /&gt;
It is a software that allows to encrypt/decrypt a disk by bounding to tang (network bound encryption/decryption) or a TPM (hardware chip encryption/decryption).&lt;br /&gt;
&lt;br /&gt;
It is in use in redhat fedora systems&lt;br /&gt;
&lt;br /&gt;
== Why use clevis ==&lt;br /&gt;
With tang, you may automatically decrypt device block/files for convenience, it is encrypted and built to prevent man-in-the-middle attacks as well, since nobody gets private key, only an always changing advertised timed key.&lt;br /&gt;
* It is recommended to use a tang docker with this, you can use this for example: [https://github.com/padhi-homelab/services/blob/master/tang/docker-compose.yml github] or [https://gitlab.com/AdrianKoshka/tang-docker-container/ gitlab]&lt;br /&gt;
&lt;br /&gt;
== Auto Disk decryption using clevis + tang ==&lt;br /&gt;
&lt;br /&gt;
You need to run tang in a separate server, from the one you want to decrypt. I recommend running a tang server on a docker.&lt;br /&gt;
&lt;br /&gt;
=== mkinitfs + kernel-hooks + secureboot-hook ===&lt;br /&gt;
{{todo| write guide}}&lt;br /&gt;
&lt;br /&gt;
Using mkinitfs, it is possible to force tang/clevis in initramfs generation. It is recommended to make a chroot or docker so you don&#039;t mess with your system files, and by adding these files:&lt;br /&gt;
&lt;br /&gt;
{{todo| The init script is too big to put in wiki, I just acquired it from initramfs generation and decompression (read the tip below)}}&lt;br /&gt;
&lt;br /&gt;
{{note| the APK package &amp;quot;cryptsetup&amp;quot; comes with veritysetup&lt;br /&gt;
{{cmd| apk add cryptsetup}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{note| make sure the chroot has a linux-kernel}}&lt;br /&gt;
&lt;br /&gt;
Edit /sbin/mkinitfs (put &amp;quot;# Copy custom init&amp;quot; before &amp;quot;# copy modloop signature&amp;quot;):&lt;br /&gt;
{{cat| /etc/mkinitfs|...&lt;br /&gt;
        # Copy custom init &lt;br /&gt;
        cp /initramfs/init &amp;quot;$tmpdir&amp;quot;/init &lt;br /&gt;
        &lt;br /&gt;
        # copy modloop signature&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
PUT &amp;quot;# Clevis + tang script&amp;quot; AFTER &amp;quot;ebegin &amp;quot;Mounting root&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
{{cat| /initramfs/init|...&lt;br /&gt;
        ebegin &amp;quot;Mounting root&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        # Clevis + tang script # work in progress&lt;br /&gt;
...&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/curl.files|&lt;br /&gt;
/usr/bin/curl&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/clevis.files|&lt;br /&gt;
/usr/bin/clevis*&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/mkinitfs.conf|...&lt;br /&gt;
features{{=}}&amp;quot;... curl clevis&amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
Then just do:&lt;br /&gt;
{{cmd| apk add secureboot-hook gummiboot gummiboot-efistub efibootmgr kernel-hooks secureboot-hook}}&lt;br /&gt;
&lt;br /&gt;
{{tip|To make sure initramfs has the scripts needed, do:&lt;br /&gt;
{{cmd|mkinitfs -c /etc/mkinitfs/mkinitfs.conf -b / $(uname -r)}}&lt;br /&gt;
Decompress:&lt;br /&gt;
{{cmd|mkdir /tmp/initramfs&lt;br /&gt;
cd /tmp/initramfs&lt;br /&gt;
&amp;lt;nowiki&amp;gt;zcat /boot/initramfs-$KERNEL | cpio -idmv&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Test if &amp;quot;init&amp;quot; works by just executing it and see how it runs:&lt;br /&gt;
{{cmd|./init}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=== dracut ===&lt;br /&gt;
{{todo| write guide}}&lt;br /&gt;
&lt;br /&gt;
== External sources ==&lt;br /&gt;
* [https://fedoramagazine.org/using-linux-system-roles-to-implement-clevis-and-tang-for-automated-luks-volume-unlocking/ https://fedoramagazine.org/using-linux-system-roles-to-implement-clevis-and-tang-for-automated-luks-volume-unlocking/]&lt;br /&gt;
* [https://www.admin-magazine.com/Archive/2018/43/Automatic-data-encryption-and-decryption-with-Clevis-and-Tang https://www.admin-magazine.com/Archive/2018/43/Automatic-data-encryption-and-decryption-with-Clevis-and-Tang]&lt;br /&gt;
* [https://wiki.archlinux.org/title/Clevis https://wiki.archlinux.org/title/Clevis]&lt;br /&gt;
* [https://man.archlinux.org/man/clevis-encrypt-tang.1.en https://man.archlinux.org/man/clevis-encrypt-tang.1.en]&lt;br /&gt;
* [https://github.com/latchset/clevis/blob/master/src/pins/tang/clevis-encrypt-tang.1.adoc https://github.com/latchset/clevis/blob/master/src/pins/tang/clevis-encrypt-tang.1.adoc]&lt;br /&gt;
&lt;br /&gt;
[[Category:Security]] [[Category:Booting]]&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Clevis&amp;diff=28597</id>
		<title>Clevis</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Clevis&amp;diff=28597"/>
		<updated>2024-12-30T01:02:08Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{draft}}&lt;br /&gt;
&lt;br /&gt;
== What is clevis ==&lt;br /&gt;
It is a software that allows to encrypt/decrypt a disk by bounding to tang (network bound encryption/decryption) or a TPM (hardware chip encryption/decryption).&lt;br /&gt;
&lt;br /&gt;
It is in use in redhat fedora systems&lt;br /&gt;
&lt;br /&gt;
== Why use clevis ==&lt;br /&gt;
With tang, you may automatically decrypt device block/files for convenience, it is encrypted and built to prevent man-in-the-middle attacks as well, since nobody gets private key, only an always changing advertised timed key.&lt;br /&gt;
* It is recommended to use a tang docker with this, you can use this for example: [https://github.com/padhi-homelab/services/blob/master/tang/docker-compose.yml github]&lt;br /&gt;
&lt;br /&gt;
== Auto Disk decryption using clevis + tang ==&lt;br /&gt;
&lt;br /&gt;
You need to run tang in a separate server, from the one you want to decrypt. I recommend running a tang server on a docker.&lt;br /&gt;
&lt;br /&gt;
=== mkinitfs + kernel-hooks + secureboot-hook ===&lt;br /&gt;
{{todo| write guide}}&lt;br /&gt;
&lt;br /&gt;
Using mkinitfs, it is possible to force tang/clevis in initramfs generation. It is recommended to make a chroot or docker so you don&#039;t mess with your system files, and by adding these files:&lt;br /&gt;
&lt;br /&gt;
{{todo| The init script is too big to put in wiki, I just acquired it from initramfs generation and decompression (read the tip below)}}&lt;br /&gt;
&lt;br /&gt;
{{note| the APK package &amp;quot;cryptsetup&amp;quot; comes with veritysetup&lt;br /&gt;
{{cmd| apk add cryptsetup}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{note| make sure the chroot has a linux-kernel}}&lt;br /&gt;
&lt;br /&gt;
Edit /sbin/mkinitfs (put &amp;quot;# Copy custom init&amp;quot; before &amp;quot;# copy modloop signature&amp;quot;):&lt;br /&gt;
{{cat| /etc/mkinitfs|...&lt;br /&gt;
        # Copy custom init &lt;br /&gt;
        cp /initramfs/init &amp;quot;$tmpdir&amp;quot;/init &lt;br /&gt;
        &lt;br /&gt;
        # copy modloop signature&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
PUT &amp;quot;# Clevis + tang script&amp;quot; AFTER &amp;quot;ebegin &amp;quot;Mounting root&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
{{cat| /initramfs/init|...&lt;br /&gt;
        ebegin &amp;quot;Mounting root&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        # Clevis + tang script # work in progress&lt;br /&gt;
...&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/curl.files|&lt;br /&gt;
/usr/bin/curl&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/clevis.files|&lt;br /&gt;
/usr/bin/clevis*&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/mkinitfs.conf|...&lt;br /&gt;
features{{=}}&amp;quot;... curl clevis&amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
Then just do:&lt;br /&gt;
{{cmd| apk add secureboot-hook gummiboot gummiboot-efistub efibootmgr kernel-hooks secureboot-hook}}&lt;br /&gt;
&lt;br /&gt;
{{tip|To make sure initramfs has the scripts needed, do:&lt;br /&gt;
{{cmd|mkinitfs -c /etc/mkinitfs/mkinitfs.conf -b / $(uname -r)}}&lt;br /&gt;
Decompress:&lt;br /&gt;
{{cmd|mkdir /tmp/initramfs&lt;br /&gt;
cd /tmp/initramfs&lt;br /&gt;
&amp;lt;nowiki&amp;gt;zcat /boot/initramfs-$KERNEL | cpio -idmv&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Test if &amp;quot;init&amp;quot; works by just executing it and see how it runs:&lt;br /&gt;
{{cmd|./init}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=== dracut ===&lt;br /&gt;
{{todo| write guide}}&lt;br /&gt;
&lt;br /&gt;
== External sources ==&lt;br /&gt;
* [https://fedoramagazine.org/using-linux-system-roles-to-implement-clevis-and-tang-for-automated-luks-volume-unlocking/ https://fedoramagazine.org/using-linux-system-roles-to-implement-clevis-and-tang-for-automated-luks-volume-unlocking/]&lt;br /&gt;
* [https://www.admin-magazine.com/Archive/2018/43/Automatic-data-encryption-and-decryption-with-Clevis-and-Tang https://www.admin-magazine.com/Archive/2018/43/Automatic-data-encryption-and-decryption-with-Clevis-and-Tang]&lt;br /&gt;
* [https://wiki.archlinux.org/title/Clevis https://wiki.archlinux.org/title/Clevis]&lt;br /&gt;
* [https://man.archlinux.org/man/clevis-encrypt-tang.1.en https://man.archlinux.org/man/clevis-encrypt-tang.1.en]&lt;br /&gt;
* [https://github.com/latchset/clevis/blob/master/src/pins/tang/clevis-encrypt-tang.1.adoc https://github.com/latchset/clevis/blob/master/src/pins/tang/clevis-encrypt-tang.1.adoc]&lt;br /&gt;
&lt;br /&gt;
[[Category:Security]] [[Category:Booting]]&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Clevis&amp;diff=28596</id>
		<title>Clevis</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Clevis&amp;diff=28596"/>
		<updated>2024-12-30T01:00:03Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{draft}}&lt;br /&gt;
&lt;br /&gt;
== What is clevis ==&lt;br /&gt;
It is a software that allows to encrypt/decrypt a disk by bounding to tang (network bound encryption/decryption) or a TPM (hardware chip encryption/decryption).&lt;br /&gt;
&lt;br /&gt;
It is in use in redhat fedora systems&lt;br /&gt;
&lt;br /&gt;
== Why use clevis ==&lt;br /&gt;
With tang, you may automatically decrypt device block/files for convenience, it is encrypted and built to prevent man-in-the-middle attacks as well, since nobody gets private key, only an always changing advertised timed key.&lt;br /&gt;
* It is recommended to use a tang docker with this&lt;br /&gt;
&lt;br /&gt;
== Auto Disk decryption using clevis + tang ==&lt;br /&gt;
&lt;br /&gt;
You need to run tang in a separate server, from the one you want to decrypt. I recommend running a tang server on a docker.&lt;br /&gt;
&lt;br /&gt;
=== mkinitfs + kernel-hooks + secureboot-hook ===&lt;br /&gt;
{{todo| write guide}}&lt;br /&gt;
&lt;br /&gt;
Using mkinitfs, it is possible to force tang/clevis in initramfs generation. It is recommended to make a chroot or docker so you don&#039;t mess with your system files, and by adding these files:&lt;br /&gt;
&lt;br /&gt;
{{todo| The init script is too big to put in wiki, I just acquired it from initramfs generation and decompression (read the tip below)}}&lt;br /&gt;
&lt;br /&gt;
{{note| the APK package &amp;quot;cryptsetup&amp;quot; comes with veritysetup&lt;br /&gt;
{{cmd| apk add cryptsetup}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{note| make sure the chroot has a linux-kernel}}&lt;br /&gt;
&lt;br /&gt;
Edit /sbin/mkinitfs (put &amp;quot;# Copy custom init&amp;quot; before &amp;quot;# copy modloop signature&amp;quot;):&lt;br /&gt;
{{cat| /etc/mkinitfs|...&lt;br /&gt;
        # Copy custom init &lt;br /&gt;
        cp /initramfs/init &amp;quot;$tmpdir&amp;quot;/init &lt;br /&gt;
        &lt;br /&gt;
        # copy modloop signature&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
PUT &amp;quot;# Clevis + tang script&amp;quot; AFTER &amp;quot;ebegin &amp;quot;Mounting root&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
{{cat| /initramfs/init|...&lt;br /&gt;
        ebegin &amp;quot;Mounting root&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        # Clevis + tang script # work in progress&lt;br /&gt;
...&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/curl.files|&lt;br /&gt;
/usr/bin/curl&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/clevis.files|&lt;br /&gt;
/usr/bin/clevis*&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/mkinitfs.conf|...&lt;br /&gt;
features{{=}}&amp;quot;... curl clevis&amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
Then just do:&lt;br /&gt;
{{cmd| apk add secureboot-hook gummiboot gummiboot-efistub efibootmgr kernel-hooks secureboot-hook}}&lt;br /&gt;
&lt;br /&gt;
{{tip|To make sure initramfs has the scripts needed, do:&lt;br /&gt;
{{cmd|mkinitfs -c /etc/mkinitfs/mkinitfs.conf -b / $(uname -r)}}&lt;br /&gt;
Decompress:&lt;br /&gt;
{{cmd|mkdir /tmp/initramfs&lt;br /&gt;
cd /tmp/initramfs&lt;br /&gt;
&amp;lt;nowiki&amp;gt;zcat /boot/initramfs-$KERNEL | cpio -idmv&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Test if &amp;quot;init&amp;quot; works by just executing it and see how it runs:&lt;br /&gt;
{{cmd|./init}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=== dracut ===&lt;br /&gt;
{{todo| write guide}}&lt;br /&gt;
&lt;br /&gt;
== External sources ==&lt;br /&gt;
* [https://fedoramagazine.org/using-linux-system-roles-to-implement-clevis-and-tang-for-automated-luks-volume-unlocking/ https://fedoramagazine.org/using-linux-system-roles-to-implement-clevis-and-tang-for-automated-luks-volume-unlocking/]&lt;br /&gt;
* [https://www.admin-magazine.com/Archive/2018/43/Automatic-data-encryption-and-decryption-with-Clevis-and-Tang https://www.admin-magazine.com/Archive/2018/43/Automatic-data-encryption-and-decryption-with-Clevis-and-Tang]&lt;br /&gt;
* [https://wiki.archlinux.org/title/Clevis https://wiki.archlinux.org/title/Clevis]&lt;br /&gt;
* [https://man.archlinux.org/man/clevis-encrypt-tang.1.en https://man.archlinux.org/man/clevis-encrypt-tang.1.en]&lt;br /&gt;
* [https://github.com/latchset/clevis/blob/master/src/pins/tang/clevis-encrypt-tang.1.adoc https://github.com/latchset/clevis/blob/master/src/pins/tang/clevis-encrypt-tang.1.adoc]&lt;br /&gt;
&lt;br /&gt;
[[Category:Security]] [[Category:Booting]]&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Clevis&amp;diff=28595</id>
		<title>Clevis</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Clevis&amp;diff=28595"/>
		<updated>2024-12-30T00:59:17Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{draft}}&lt;br /&gt;
&lt;br /&gt;
== What is clevis ==&lt;br /&gt;
It is a software that allows to encrypt/decrypt a disk by bounding to tang (network bound encryption/decryption) or a TPM (hardware chip encryption/decryption).&lt;br /&gt;
&lt;br /&gt;
It is in use in redhat fedora systems&lt;br /&gt;
&lt;br /&gt;
== Why use clevis ==&lt;br /&gt;
With tang, you may automatically decrypt device block/files for convenience, it is encrypted and built to prevent man-in-the-middle attacks as well, since nobody gets private key, only an always changing advertised timed key.&lt;br /&gt;
* It is recommended to use a tang docker with this&lt;br /&gt;
&lt;br /&gt;
== Auto Disk decryption using clevis + tang ==&lt;br /&gt;
&lt;br /&gt;
You need to run tang in a separate server, from the one you want to decrypt. I recommend running a tang server on a docker.&lt;br /&gt;
&lt;br /&gt;
=== mkinitfs + kernel-hooks + secureboot-hook ===&lt;br /&gt;
{{todo| write guide}}&lt;br /&gt;
&lt;br /&gt;
Using mkinitfs, it is possible to force tang/clevis in initramfs generation. It is recommended to make a chroot or docker so you don&#039;t mess with your system files, and by adding these files:&lt;br /&gt;
&lt;br /&gt;
{{todo| The init script is too big to put in wiki, I just acquired it from initramfs generation and decompression (read the tip below)}}&lt;br /&gt;
&lt;br /&gt;
{{note| the APK package &amp;quot;cryptsetup&amp;quot; comes with veritysetup&lt;br /&gt;
{{cmd| apk add cryptsetup}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{note| make sure the chroot has a linux-kernel}}&lt;br /&gt;
&lt;br /&gt;
Edit /sbin/mkinitfs (put &amp;quot;# Copy custom init&amp;quot; before &amp;quot;# copy modloop signature&amp;quot;):&lt;br /&gt;
{{cat| /etc/mkinitfs|...&lt;br /&gt;
        # Copy custom init &lt;br /&gt;
        cp /initramfs/init &amp;quot;$tmpdir&amp;quot;/init &lt;br /&gt;
        &lt;br /&gt;
        # copy modloop signature&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
PUT &amp;quot;# Clevis + tang script&amp;quot; AFTER &amp;quot;ebegin &amp;quot;Mounting root&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
{{cat| /initramfs/init|...&lt;br /&gt;
        ebegin &amp;quot;Mounting root&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        # Clevis + tang script # work in progress&lt;br /&gt;
...&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/curl.files|&lt;br /&gt;
/usr/bin/curl&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/clevis.files|&lt;br /&gt;
/usr/bin/clevis*&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/mkinitfs.conf|...&lt;br /&gt;
features{{=}}&amp;quot;... curl clevis&amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
Then just do:&lt;br /&gt;
{{cmd| apk add secureboot-hook gummiboot gummiboot-efistub efibootmgr kernel-hooks secureboot-hook}}&lt;br /&gt;
&lt;br /&gt;
{{tip|To make sure initramfs has the scripts needed, do:&lt;br /&gt;
{{cmd|mkinitfs -c /etc/mkinitfs/mkinitfs.conf -b / $(uname -r)}}&lt;br /&gt;
Decompress:&lt;br /&gt;
{{cmd|mkdir /tmp/initramfs&lt;br /&gt;
cd /tmp/initramfs&lt;br /&gt;
&amp;lt;nowiki&amp;gt;zcat /boot/initramfs-$KERNEL | cpio -idmv&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Test if &amp;quot;init&amp;quot; works by just executing it and see how it runs:&lt;br /&gt;
{{cmd|./init}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=== dracut ===&lt;br /&gt;
{{todo| write guide}}&lt;br /&gt;
&lt;br /&gt;
== External sources ==&lt;br /&gt;
* [https://fedoramagazine.org/using-linux-system-roles-to-implement-clevis-and-tang-for-automated-luks-volume-unlocking/ https://fedoramagazine.org/using-linux-system-roles-to-implement-clevis-and-tang-for-automated-luks-volume-unlocking/]&lt;br /&gt;
* [https://www.admin-magazine.com/Archive/2018/43/Automatic-data-encryption-and-decryption-with-Clevis-and-Tang https://www.admin-magazine.com/Archive/2018/43/Automatic-data-encryption-and-decryption-with-Clevis-and-Tang]&lt;br /&gt;
* [https://wiki.archlinux.org/title/Clevis https://wiki.archlinux.org/title/Clevis]&lt;br /&gt;
* [https://man.archlinux.org/man/clevis-encrypt-tang.1.en https://man.archlinux.org/man/clevis-encrypt-tang.1.en]&lt;br /&gt;
&lt;br /&gt;
[[Category:Security]] [[Category:Booting]]&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Clevis&amp;diff=28594</id>
		<title>Clevis</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Clevis&amp;diff=28594"/>
		<updated>2024-12-30T00:58:23Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{draft}}&lt;br /&gt;
&lt;br /&gt;
== What is clevis ==&lt;br /&gt;
It is a software that allows to encrypt/decrypt a disk by bounding to tang (network bound encryption/decryption) or a TPM (hardware chip encryption/decryption).&lt;br /&gt;
&lt;br /&gt;
It is in use in redhat fedora systems&lt;br /&gt;
&lt;br /&gt;
== Why use clevis ==&lt;br /&gt;
With tang, you may automatically decrypt device block/files for convenience, it is encrypted and built to prevent man-in-the-middle attacks as well, since nobody gets private key, only an always changing advertised timed key.&lt;br /&gt;
* It is recommended to use a tang docker with this&lt;br /&gt;
&lt;br /&gt;
== Auto Disk decryption using clevis + tang ==&lt;br /&gt;
&lt;br /&gt;
You need to run tang in a separate server, from the one you want to decrypt. I recommend running a tang server on a docker.&lt;br /&gt;
&lt;br /&gt;
=== mkinitfs + kernel-hooks + secureboot-hook ===&lt;br /&gt;
{{todo| write guide}}&lt;br /&gt;
&lt;br /&gt;
Using mkinitfs, it is possible to force tang/clevis in initramfs generation. It is recommended to make a chroot or docker so you don&#039;t mess with your system files, and by adding these files:&lt;br /&gt;
&lt;br /&gt;
{{todo| The init script is too big to put in wiki, I just acquired it from initramfs generation and decompression (read the tip below)}}&lt;br /&gt;
&lt;br /&gt;
{{note| the APK package &amp;quot;cryptsetup&amp;quot; comes with veritysetup&lt;br /&gt;
{{cmd| apk add cryptsetup}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{note| make sure the chroot has a linux-kernel}}&lt;br /&gt;
&lt;br /&gt;
Edit /sbin/mkinitfs (put &amp;quot;# Copy custom init&amp;quot; before &amp;quot;# copy modloop signature&amp;quot;):&lt;br /&gt;
{{cat| /etc/mkinitfs|...&lt;br /&gt;
        # Copy custom init &lt;br /&gt;
        cp /initramfs/init &amp;quot;$tmpdir&amp;quot;/init &lt;br /&gt;
        &lt;br /&gt;
        # copy modloop signature&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
PUT &amp;quot;# Clevis + tang script&amp;quot; AFTER &amp;quot;ebegin &amp;quot;Mounting root&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
{{cat| /initramfs/init|...&lt;br /&gt;
        ebegin &amp;quot;Mounting root&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        # Clevis + tang script # work in progress&lt;br /&gt;
...&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/curl.files|&lt;br /&gt;
/usr/bin/curl&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/clevis.files|&lt;br /&gt;
/usr/bin/clevis*&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/mkinitfs.conf|...&lt;br /&gt;
features{{=}}&amp;quot;... curl clevis&amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
Then just do:&lt;br /&gt;
{{cmd| apk add secureboot-hook gummiboot gummiboot-efistub efibootmgr kernel-hooks secureboot-hook}}&lt;br /&gt;
&lt;br /&gt;
{{tip|To make sure initramfs has the scripts needed, do:&lt;br /&gt;
{{cmd|mkinitfs -c /etc/mkinitfs/mkinitfs.conf -b / $(uname -r)}}&lt;br /&gt;
Decompress:&lt;br /&gt;
{{cmd|mkdir /tmp/initramfs&lt;br /&gt;
cd /tmp/initramfs&lt;br /&gt;
&amp;lt;nowiki&amp;gt;zcat /boot/initramfs-$KERNEL | cpio -idmv&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Test if &amp;quot;init&amp;quot; works by just executing it and see how it runs:&lt;br /&gt;
{{cmd|./init}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=== dracut ===&lt;br /&gt;
{{todo| write guide}}&lt;br /&gt;
&lt;br /&gt;
== External sources ==&lt;br /&gt;
* [https://fedoramagazine.org/using-linux-system-roles-to-implement-clevis-and-tang-for-automated-luks-volume-unlocking/ https://fedoramagazine.org/using-linux-system-roles-to-implement-clevis-and-tang-for-automated-luks-volume-unlocking/]&lt;br /&gt;
* [https://www.admin-magazine.com/Archive/2018/43/Automatic-data-encryption-and-decryption-with-Clevis-and-Tang https://www.admin-magazine.com/Archive/2018/43/Automatic-data-encryption-and-decryption-with-Clevis-and-Tang]&lt;br /&gt;
* [https://wiki.archlinux.org/title/Clevis https://wiki.archlinux.org/title/Clevis]&lt;br /&gt;
&lt;br /&gt;
[[Category:Security]] [[Category:Booting]]&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Clevis&amp;diff=28593</id>
		<title>Clevis</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Clevis&amp;diff=28593"/>
		<updated>2024-12-30T00:55:32Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{draft}}&lt;br /&gt;
&lt;br /&gt;
== What is clevis ==&lt;br /&gt;
It is a software that allows to encrypt/decrypt a disk by bounding to tang (network bound encryption/decryption) or a TPM (hardware chip encryption/decryption).&lt;br /&gt;
&lt;br /&gt;
== Why use clevis ==&lt;br /&gt;
With tang, you may automatically decrypt device block/files for convenience, it is encrypted and built to prevent man-in-the-middle attacks as well.&lt;br /&gt;
* It is recommended to use a tang docker with this&lt;br /&gt;
&lt;br /&gt;
== Auto Disk decryption using clevis + tang ==&lt;br /&gt;
&lt;br /&gt;
You need to run tang in a separate server, from the one you want to decrypt. I recommend running a tang server on a docker.&lt;br /&gt;
&lt;br /&gt;
=== mkinitfs + kernel-hooks + secureboot-hook ===&lt;br /&gt;
{{todo| write guide}}&lt;br /&gt;
&lt;br /&gt;
Using mkinitfs, it is possible to force tang/clevis in initramfs generation. It is recommended to make a chroot or docker so you don&#039;t mess with your system files, and by adding these files:&lt;br /&gt;
&lt;br /&gt;
{{todo| The init script is too big to put in wiki, I just acquired it from initramfs generation and decompression (read the tip below)}}&lt;br /&gt;
&lt;br /&gt;
{{note| the APK package &amp;quot;cryptsetup&amp;quot; comes with veritysetup&lt;br /&gt;
{{cmd| apk add cryptsetup}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{note| make sure the chroot has a linux-kernel}}&lt;br /&gt;
&lt;br /&gt;
Edit /sbin/mkinitfs (put &amp;quot;# Copy custom init&amp;quot; before &amp;quot;# copy modloop signature&amp;quot;):&lt;br /&gt;
{{cat| /etc/mkinitfs|...&lt;br /&gt;
        # Copy custom init &lt;br /&gt;
        cp /initramfs/init &amp;quot;$tmpdir&amp;quot;/init &lt;br /&gt;
        &lt;br /&gt;
        # copy modloop signature&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
PUT &amp;quot;# Clevis + tang script&amp;quot; AFTER &amp;quot;ebegin &amp;quot;Mounting root&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
{{cat| /initramfs/init|...&lt;br /&gt;
        ebegin &amp;quot;Mounting root&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        # Clevis + tang script # work in progress&lt;br /&gt;
...&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/curl.files|&lt;br /&gt;
/usr/bin/curl&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/clevis.files|&lt;br /&gt;
/usr/bin/clevis*&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/mkinitfs.conf|...&lt;br /&gt;
features{{=}}&amp;quot;... curl clevis&amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
Then just do:&lt;br /&gt;
{{cmd| apk add secureboot-hook gummiboot gummiboot-efistub efibootmgr kernel-hooks secureboot-hook}}&lt;br /&gt;
&lt;br /&gt;
{{tip|To make sure initramfs has the scripts needed, do:&lt;br /&gt;
{{cmd|mkinitfs -c /etc/mkinitfs/mkinitfs.conf -b / $(uname -r)}}&lt;br /&gt;
Decompress:&lt;br /&gt;
{{cmd|mkdir /tmp/initramfs&lt;br /&gt;
cd /tmp/initramfs&lt;br /&gt;
&amp;lt;nowiki&amp;gt;zcat /boot/initramfs-$KERNEL | cpio -idmv&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Test if &amp;quot;init&amp;quot; works by just executing it and see how it runs:&lt;br /&gt;
{{cmd|./init}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=== dracut ===&lt;br /&gt;
{{todo| write guide}}&lt;br /&gt;
&lt;br /&gt;
== External sources ==&lt;br /&gt;
* [https://fedoramagazine.org/using-linux-system-roles-to-implement-clevis-and-tang-for-automated-luks-volume-unlocking/ https://fedoramagazine.org/using-linux-system-roles-to-implement-clevis-and-tang-for-automated-luks-volume-unlocking/]&lt;br /&gt;
* [https://www.admin-magazine.com/Archive/2018/43/Automatic-data-encryption-and-decryption-with-Clevis-and-Tang https://www.admin-magazine.com/Archive/2018/43/Automatic-data-encryption-and-decryption-with-Clevis-and-Tang]&lt;br /&gt;
* [https://wiki.archlinux.org/title/Clevis https://wiki.archlinux.org/title/Clevis]&lt;br /&gt;
&lt;br /&gt;
[[Category:Security]] [[Category:Booting]]&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Clevis&amp;diff=28583</id>
		<title>Clevis</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Clevis&amp;diff=28583"/>
		<updated>2024-12-25T16:46:50Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{draft}}&lt;br /&gt;
&lt;br /&gt;
== What is clevis ==&lt;br /&gt;
It is a software that allows to encrypt/decrypt a disk by bounding to tang (network bound encryption/decryption) or a TPM (hardware chip encryption/decryption).&lt;br /&gt;
&lt;br /&gt;
== Auto Disk decryption using clevis + tang ==&lt;br /&gt;
&lt;br /&gt;
You need to run tang in a separate server, from the one you want to decrypt. I recommend running a tang server on a docker.&lt;br /&gt;
&lt;br /&gt;
=== mkinitfs + kernel-hooks + secureboot-hook ===&lt;br /&gt;
{{todo| write guide}}&lt;br /&gt;
&lt;br /&gt;
Using mkinitfs, it is possible to force tang/clevis in initramfs generation. It is recommended to make a chroot or docker so you don&#039;t mess with your system files, and by adding these files:&lt;br /&gt;
&lt;br /&gt;
{{todo| The init script is too big to put in wiki, I just acquired it from initramfs generation and decompression (read the tip below)}}&lt;br /&gt;
&lt;br /&gt;
{{note| the APK package &amp;quot;cryptsetup&amp;quot; comes with veritysetup&lt;br /&gt;
{{cmd| apk add cryptsetup}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{note| make sure the chroot has a linux-kernel}}&lt;br /&gt;
&lt;br /&gt;
Edit /sbin/mkinitfs (put &amp;quot;# Copy custom init&amp;quot; before &amp;quot;# copy modloop signature&amp;quot;):&lt;br /&gt;
{{cat| /etc/mkinitfs|...&lt;br /&gt;
        # Copy custom init &lt;br /&gt;
        cp /initramfs/init &amp;quot;$tmpdir&amp;quot;/init &lt;br /&gt;
        &lt;br /&gt;
        # copy modloop signature&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
PUT &amp;quot;# Clevis + tang script&amp;quot; AFTER &amp;quot;ebegin &amp;quot;Mounting root&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
{{cat| /initramfs/init|...&lt;br /&gt;
        ebegin &amp;quot;Mounting root&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        # Clevis + tang script # work in progress&lt;br /&gt;
...&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/curl.files|&lt;br /&gt;
/usr/bin/curl&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/clevis.files|&lt;br /&gt;
/usr/bin/clevis*&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/mkinitfs.conf|...&lt;br /&gt;
features{{=}}&amp;quot;... curl clevis&amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
Then just do:&lt;br /&gt;
{{cmd| apk add secureboot-hook gummiboot gummiboot-efistub efibootmgr kernel-hooks secureboot-hook}}&lt;br /&gt;
&lt;br /&gt;
{{tip|To make sure initramfs has the scripts needed, do:&lt;br /&gt;
{{cmd|mkinitfs -c /etc/mkinitfs/mkinitfs.conf -b / $(uname -r)}}&lt;br /&gt;
Decompress:&lt;br /&gt;
{{cmd|mkdir /tmp/initramfs&lt;br /&gt;
cd /tmp/initramfs&lt;br /&gt;
&amp;lt;nowiki&amp;gt;zcat /boot/initramfs-$KERNEL | cpio -idmv&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Test if &amp;quot;init&amp;quot; works by just executing it and see how it runs:&lt;br /&gt;
{{cmd|./init}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=== dracut ===&lt;br /&gt;
{{todo| write guide}}&lt;br /&gt;
&lt;br /&gt;
== External sources ==&lt;br /&gt;
* [https://fedoramagazine.org/using-linux-system-roles-to-implement-clevis-and-tang-for-automated-luks-volume-unlocking/ https://fedoramagazine.org/using-linux-system-roles-to-implement-clevis-and-tang-for-automated-luks-volume-unlocking/]&lt;br /&gt;
* [https://www.admin-magazine.com/Archive/2018/43/Automatic-data-encryption-and-decryption-with-Clevis-and-Tang https://www.admin-magazine.com/Archive/2018/43/Automatic-data-encryption-and-decryption-with-Clevis-and-Tang]&lt;br /&gt;
* [https://wiki.archlinux.org/title/Clevis https://wiki.archlinux.org/title/Clevis]&lt;br /&gt;
&lt;br /&gt;
[[Category:Security]] [[Category:Booting]]&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Clevis&amp;diff=28582</id>
		<title>Clevis</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Clevis&amp;diff=28582"/>
		<updated>2024-12-25T16:46:18Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{draft}}&lt;br /&gt;
&lt;br /&gt;
==== What is clevis ====&lt;br /&gt;
It is a software that allows to encrypt/decrypt a disk by bounding to tang (network bound encryption/decryption) or a TPM (hardware chip encryption/decryption).&lt;br /&gt;
&lt;br /&gt;
==== Auto Disk decryption using clevis + tang ====&lt;br /&gt;
&lt;br /&gt;
You need to run tang in a separate server, from the one you want to decrypt. I recommend running a tang server on a docker.&lt;br /&gt;
&lt;br /&gt;
=== mkinitfs + kernel-hooks + secureboot-hook ===&lt;br /&gt;
{{todo| write guide}}&lt;br /&gt;
&lt;br /&gt;
Using mkinitfs, it is possible to force tang/clevis in initramfs generation. It is recommended to make a chroot or docker so you don&#039;t mess with your system files, and by adding these files:&lt;br /&gt;
&lt;br /&gt;
{{todo| The init script is too big to put in wiki, I just acquired it from initramfs generation and decompression (read the tip below)}}&lt;br /&gt;
&lt;br /&gt;
{{note| the APK package &amp;quot;cryptsetup&amp;quot; comes with veritysetup&lt;br /&gt;
{{cmd| apk add cryptsetup}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{note| make sure the chroot has a linux-kernel}}&lt;br /&gt;
&lt;br /&gt;
Edit /sbin/mkinitfs (put &amp;quot;# Copy custom init&amp;quot; before &amp;quot;# copy modloop signature&amp;quot;):&lt;br /&gt;
{{cat| /etc/mkinitfs|...&lt;br /&gt;
        # Copy custom init &lt;br /&gt;
        cp /initramfs/init &amp;quot;$tmpdir&amp;quot;/init &lt;br /&gt;
        &lt;br /&gt;
        # copy modloop signature&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
PUT &amp;quot;# Clevis + tang script&amp;quot; AFTER &amp;quot;ebegin &amp;quot;Mounting root&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
{{cat| /initramfs/init|...&lt;br /&gt;
        ebegin &amp;quot;Mounting root&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        # Clevis + tang script # work in progress&lt;br /&gt;
...&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/curl.files|&lt;br /&gt;
/usr/bin/curl&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/clevis.files|&lt;br /&gt;
/usr/bin/clevis*&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/mkinitfs.conf|...&lt;br /&gt;
features{{=}}&amp;quot;... curl clevis&amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
Then just do:&lt;br /&gt;
{{cmd| apk add secureboot-hook gummiboot gummiboot-efistub efibootmgr kernel-hooks secureboot-hook}}&lt;br /&gt;
&lt;br /&gt;
{{tip|To make sure initramfs has the scripts needed, do:&lt;br /&gt;
{{cmd|mkinitfs -c /etc/mkinitfs/mkinitfs.conf -b / $(uname -r)}}&lt;br /&gt;
Decompress:&lt;br /&gt;
{{cmd|mkdir /tmp/initramfs&lt;br /&gt;
cd /tmp/initramfs&lt;br /&gt;
&amp;lt;nowiki&amp;gt;zcat /boot/initramfs-$KERNEL | cpio -idmv&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Test if &amp;quot;init&amp;quot; works by just executing it and see how it runs:&lt;br /&gt;
{{cmd|./init}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=== dracut ===&lt;br /&gt;
{{todo| write guide}}&lt;br /&gt;
&lt;br /&gt;
==== External sources ====&lt;br /&gt;
* [https://fedoramagazine.org/using-linux-system-roles-to-implement-clevis-and-tang-for-automated-luks-volume-unlocking/ https://fedoramagazine.org/using-linux-system-roles-to-implement-clevis-and-tang-for-automated-luks-volume-unlocking/]&lt;br /&gt;
* [https://www.admin-magazine.com/Archive/2018/43/Automatic-data-encryption-and-decryption-with-Clevis-and-Tang https://www.admin-magazine.com/Archive/2018/43/Automatic-data-encryption-and-decryption-with-Clevis-and-Tang]&lt;br /&gt;
* [https://wiki.archlinux.org/title/Clevis https://wiki.archlinux.org/title/Clevis]&lt;br /&gt;
&lt;br /&gt;
[[Category:Security]] [[Category:Booting]]&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Clevis&amp;diff=28581</id>
		<title>Clevis</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Clevis&amp;diff=28581"/>
		<updated>2024-12-25T16:29:34Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{draft}}&lt;br /&gt;
&lt;br /&gt;
==== What is clevis ====&lt;br /&gt;
It is a software that allows to encrypt/decrypt a disk by bounding to tang (network bound encryption/decryption) or a TPM (hardware chip encryption/decryption).&lt;br /&gt;
&lt;br /&gt;
==== Auto Disk decryption using clevis + tang ====&lt;br /&gt;
&lt;br /&gt;
You need to run tang in a separate server, from the one you want to decrypt. I recommend running a tang server on a docker.&lt;br /&gt;
&lt;br /&gt;
=== mkinitfs + kernel-hooks + secureboot-hook ===&lt;br /&gt;
{{todo| write guide}}&lt;br /&gt;
&lt;br /&gt;
Using mkinitfs, it is possible to force tang/clevis in initramfs generation. It is recommended to make a chroot or docker so you don&#039;t mess with your system files, and by adding these files:&lt;br /&gt;
&lt;br /&gt;
{{todo| The init script is too big to put in wiki, I just acquired it from initramfs generation and decompression (read the tip below)}}&lt;br /&gt;
&lt;br /&gt;
{{note| the APK package &amp;quot;cryptsetup&amp;quot; comes with veritysetup&lt;br /&gt;
{{cmd| apk add cryptsetup}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{note| make sure the chroot has a linux-kernel}}&lt;br /&gt;
&lt;br /&gt;
Edit /sbin/mkinitfs (put &amp;quot;# Copy custom init&amp;quot; before &amp;quot;# copy modloop signature&amp;quot;):&lt;br /&gt;
{{cat| /etc/mkinitfs|...&lt;br /&gt;
        # Copy custom init &lt;br /&gt;
        cp /initramfs/init &amp;quot;$tmpdir&amp;quot;/init &lt;br /&gt;
        &lt;br /&gt;
        # copy modloop signature&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
PUT &amp;quot;# Clevis + tang script&amp;quot; AFTER &amp;quot;ebegin &amp;quot;Mounting root&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
{{cat| /initramfs/init|...&lt;br /&gt;
        ebegin &amp;quot;Mounting root&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        # Clevis + tang script # work in progress&lt;br /&gt;
...&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/curl.files|&lt;br /&gt;
/usr/bin/curl&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/clevis.files|&lt;br /&gt;
/usr/bin/clevis*&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/mkinitfs.conf|...&lt;br /&gt;
features{{=}}&amp;quot;... curl clevis&amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
Then just do:&lt;br /&gt;
{{cmd| apk add secureboot-hook gummiboot gummiboot-efistub efibootmgr kernel-hooks secureboot-hook}}&lt;br /&gt;
&lt;br /&gt;
{{tip|To make sure initramfs has the scripts needed, do:&lt;br /&gt;
{{cmd|mkinitfs -c /etc/mkinitfs/mkinitfs.conf -b / $(uname -r)}}&lt;br /&gt;
Decompress:&lt;br /&gt;
{{cmd|mkdir /tmp/initramfs&lt;br /&gt;
cd /tmp/initramfs&lt;br /&gt;
&amp;lt;nowiki&amp;gt;zcat /boot/initramfs-$KERNEL | cpio -idmv&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Test if &amp;quot;init&amp;quot; works by just executing it and see how it runs:&lt;br /&gt;
{{cmd|./init}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=== dracut ===&lt;br /&gt;
{{todo| write guide}}&lt;br /&gt;
&lt;br /&gt;
==== External sources ====&lt;br /&gt;
* [https://fedoramagazine.org/using-linux-system-roles-to-implement-clevis-and-tang-for-automated-luks-volume-unlocking/ https://fedoramagazine.org/using-linux-system-roles-to-implement-clevis-and-tang-for-automated-luks-volume-unlocking/]&lt;br /&gt;
* [https://www.admin-magazine.com/Archive/2018/43/Automatic-data-encryption-and-decryption-with-Clevis-and-Tang https://www.admin-magazine.com/Archive/2018/43/Automatic-data-encryption-and-decryption-with-Clevis-and-Tang]&lt;br /&gt;
&lt;br /&gt;
[[Category:Security]] [[Category:Booting]]&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=User:Pursuable1652&amp;diff=28580</id>
		<title>User:Pursuable1652</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=User:Pursuable1652&amp;diff=28580"/>
		<updated>2024-12-25T16:24:17Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hello, I&#039;m Pursuable1652, I like scripting, some different types of development, modifying hardware/software, like learning about home-servers or networking (or general server administration)/(homelabbing), also like learning some security and privacy, I know soldering and repairing, and more (I&#039;m very passionate about computers), and I helped make these wiki pages:&lt;br /&gt;
&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Hardened_linux&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/DM-verity&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Silent_boot&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Hardened_malloc&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Clevis (clevis + tang auto decryption for servers)&lt;br /&gt;
&lt;br /&gt;
My main goal is to secure Linux more, and better (and as a side-effect, very different) than traditional Linux distros. My guide is more suited to a server use-case, rather than desktop.&lt;br /&gt;
&lt;br /&gt;
The guides still apply to both server and desktop, but desktop has a bigger attack surface usually, because an app ecosystem must be incorporated with security as its designed (compared to server which could just be dockerized + gvisored + apparmored/selinuxed or virtualized).&lt;br /&gt;
&lt;br /&gt;
Flatpak on desktop is somewhat flawed because it&#039;s allow-permission first, rather than deny-permission first.&lt;br /&gt;
&lt;br /&gt;
It might be thought of as, you compile the software, the software is open-source, so it must be secure, right? (That is not true, because software, especially software with bigger LOC (lines of code), will be more complex, thus may have more bugs that are hard to detect from the human-eye, and these bugs may do any rogue things to your system.)&lt;br /&gt;
&lt;br /&gt;
Desktop may have a more harder way of controlling the security of software, since you need the support of an app ecosystem already working on a predefined-security focused platform, so not all apps are just running without a sandbox/vm (ideally without a VM (run all in sandbox) or maybe just one, because using virtual machines has a performance loss).&lt;br /&gt;
&lt;br /&gt;
To be honest, I recommend using Android/AOSP and ChromeOS/ChromiumOS for a secure OS based on Linux kernel, since they already have a huge app ecosystem built with Java and Kotlin, based on an SELinux&#039;ed platform with Verified Boot enabled by default, and root disallowed by default.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Some wikis I did not write, but may help with security of Alpine Linux (or just miscellaneous):&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/AppArmor (or possibly SELinux if your kernel supports it, default linux-lts doesn&#039;t)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Docker (if you use docker, also use GVisor for full sandboxing)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Securing_Alpine_Linux&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Sysctl.conf#Security (can also use kernel-hardening-checker for suggestions on sysctl and boot parameter secure options)&lt;br /&gt;
&lt;br /&gt;
Some more info about securing Alpine Linux:&lt;br /&gt;
&lt;br /&gt;
Reduce procfs information to non-root users by appending &amp;lt;code&amp;gt;hidepid&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;proc&amp;lt;/code&amp;gt;:&lt;br /&gt;
{{cat|/etc/fstab|...&lt;br /&gt;
proc    /proc   proc    nosuid,nodev,noexec,hidepid{{=}}2 0 0&lt;br /&gt;
...}}&lt;br /&gt;
Reduce procfs and sysfs information by removing read access to some files (may break your system):&lt;br /&gt;
{{cmd|&lt;br /&gt;
chmod 400 /proc/$FILE&lt;br /&gt;
chmod 400 /sys&lt;br /&gt;
chmod 400 /sys/$ANY_FILE_IN_DIR&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Set as many directories and files as possible as non-executable, read-only. And mount file-systems as non-executable and read-only.&lt;br /&gt;
&lt;br /&gt;
Consider between AppArmor and SELinux. AppArmor is more convenient to work with, but not as granular since it&#039;s path-based. SELinux is label-based, and it is more granular, obvious trade-off is it&#039;s more difficult to work with (for most people). linux-lts package only enables AppArmor.&lt;br /&gt;
&lt;br /&gt;
Apply [https://en.wikipedia.org/wiki/Principle_of_least_privilege PoLP] (Principle of Least Privilege) wherever possible.&lt;br /&gt;
&lt;br /&gt;
Have as little packages as possible on your system, minimalize amount of software on your system.&lt;br /&gt;
&lt;br /&gt;
Get rid of debugging tools.&lt;br /&gt;
&lt;br /&gt;
Use &amp;lt;code&amp;gt;doas&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;doasedit&amp;lt;/code&amp;gt; if root is needed. (I believe &amp;lt;code&amp;gt;doasedit&amp;lt;/code&amp;gt; is in the testing repo.)&lt;br /&gt;
&lt;br /&gt;
There is the obvious, which is DISABLE internet access to specific sandboxed/virtualized applications, or disable internet as a whole for a device if practical. (Basically firewalling/VLAN&#039;ing)&lt;br /&gt;
&lt;br /&gt;
Obvious make full backups&lt;br /&gt;
&lt;br /&gt;
File encryption can be used in tandem with FDE, for granular encryption.&lt;br /&gt;
&lt;br /&gt;
Same could be said for read-only integrity for files/directories.&lt;br /&gt;
&lt;br /&gt;
Always use HTTPS to download repository packages for your system.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Unfortunately, there is way too much for securing a traditional Linux server. Not impossible, just a lot left out that could have been done securing traditional Linux based OS&#039;. (BTW it&#039;s the same for traditional Unix based OS&#039;...)&lt;br /&gt;
&lt;br /&gt;
Security should be done by default, if not, while you configure your operating system for security, you are already compromised from the start. And more secure users is better than less, for example as you communicate with other secure users you are protected as well, protecting your communications with others.&lt;br /&gt;
&lt;br /&gt;
Follow [https://wiki.alpinelinux.org/wiki/DM-verity DM-Verity] wiki for an attempt at full verified/trusted boot on Alpine Linux.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
At this point, it would be it&#039;s own Linux distro&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=User:Pursuable1652&amp;diff=28579</id>
		<title>User:Pursuable1652</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=User:Pursuable1652&amp;diff=28579"/>
		<updated>2024-12-25T16:23:51Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hello, I&#039;m Pursuable1652, I like scripting, some different types of development, modifying hardware/software, like learning about home-servers or networking (or general server administration)/(homelabbing), also like learning some security and privacy, I know soldering and repairing, and more (I&#039;m very passionate about computers), and I helped make these wiki pages:&lt;br /&gt;
&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Hardened_linux&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/DM-verity&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Silent_boot&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Hardened_malloc&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Clevis&lt;br /&gt;
&lt;br /&gt;
My main goal is to secure Linux more, and better (and as a side-effect, very different) than traditional Linux distros. My guide is more suited to a server use-case, rather than desktop.&lt;br /&gt;
&lt;br /&gt;
The guides still apply to both server and desktop, but desktop has a bigger attack surface usually, because an app ecosystem must be incorporated with security as its designed (compared to server which could just be dockerized + gvisored + apparmored/selinuxed or virtualized).&lt;br /&gt;
&lt;br /&gt;
Flatpak on desktop is somewhat flawed because it&#039;s allow-permission first, rather than deny-permission first.&lt;br /&gt;
&lt;br /&gt;
It might be thought of as, you compile the software, the software is open-source, so it must be secure, right? (That is not true, because software, especially software with bigger LOC (lines of code), will be more complex, thus may have more bugs that are hard to detect from the human-eye, and these bugs may do any rogue things to your system.)&lt;br /&gt;
&lt;br /&gt;
Desktop may have a more harder way of controlling the security of software, since you need the support of an app ecosystem already working on a predefined-security focused platform, so not all apps are just running without a sandbox/vm (ideally without a VM (run all in sandbox) or maybe just one, because using virtual machines has a performance loss).&lt;br /&gt;
&lt;br /&gt;
To be honest, I recommend using Android/AOSP and ChromeOS/ChromiumOS for a secure OS based on Linux kernel, since they already have a huge app ecosystem built with Java and Kotlin, based on an SELinux&#039;ed platform with Verified Boot enabled by default, and root disallowed by default.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Some wikis I did not write, but may help with security of Alpine Linux (or just miscellaneous):&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/AppArmor (or possibly SELinux if your kernel supports it, default linux-lts doesn&#039;t)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Docker (if you use docker, also use GVisor for full sandboxing)&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Securing_Alpine_Linux&lt;br /&gt;
* https://wiki.alpinelinux.org/wiki/Sysctl.conf#Security (can also use kernel-hardening-checker for suggestions on sysctl and boot parameter secure options)&lt;br /&gt;
&lt;br /&gt;
Some more info about securing Alpine Linux:&lt;br /&gt;
&lt;br /&gt;
Reduce procfs information to non-root users by appending &amp;lt;code&amp;gt;hidepid&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;proc&amp;lt;/code&amp;gt;:&lt;br /&gt;
{{cat|/etc/fstab|...&lt;br /&gt;
proc    /proc   proc    nosuid,nodev,noexec,hidepid{{=}}2 0 0&lt;br /&gt;
...}}&lt;br /&gt;
Reduce procfs and sysfs information by removing read access to some files (may break your system):&lt;br /&gt;
{{cmd|&lt;br /&gt;
chmod 400 /proc/$FILE&lt;br /&gt;
chmod 400 /sys&lt;br /&gt;
chmod 400 /sys/$ANY_FILE_IN_DIR&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Set as many directories and files as possible as non-executable, read-only. And mount file-systems as non-executable and read-only.&lt;br /&gt;
&lt;br /&gt;
Consider between AppArmor and SELinux. AppArmor is more convenient to work with, but not as granular since it&#039;s path-based. SELinux is label-based, and it is more granular, obvious trade-off is it&#039;s more difficult to work with (for most people). linux-lts package only enables AppArmor.&lt;br /&gt;
&lt;br /&gt;
Apply [https://en.wikipedia.org/wiki/Principle_of_least_privilege PoLP] (Principle of Least Privilege) wherever possible.&lt;br /&gt;
&lt;br /&gt;
Have as little packages as possible on your system, minimalize amount of software on your system.&lt;br /&gt;
&lt;br /&gt;
Get rid of debugging tools.&lt;br /&gt;
&lt;br /&gt;
Use &amp;lt;code&amp;gt;doas&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;doasedit&amp;lt;/code&amp;gt; if root is needed. (I believe &amp;lt;code&amp;gt;doasedit&amp;lt;/code&amp;gt; is in the testing repo.)&lt;br /&gt;
&lt;br /&gt;
There is the obvious, which is DISABLE internet access to specific sandboxed/virtualized applications, or disable internet as a whole for a device if practical. (Basically firewalling/VLAN&#039;ing)&lt;br /&gt;
&lt;br /&gt;
Obvious make full backups&lt;br /&gt;
&lt;br /&gt;
File encryption can be used in tandem with FDE, for granular encryption.&lt;br /&gt;
&lt;br /&gt;
Same could be said for read-only integrity for files/directories.&lt;br /&gt;
&lt;br /&gt;
Always use HTTPS to download repository packages for your system.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Unfortunately, there is way too much for securing a traditional Linux server. Not impossible, just a lot left out that could have been done securing traditional Linux based OS&#039;. (BTW it&#039;s the same for traditional Unix based OS&#039;...)&lt;br /&gt;
&lt;br /&gt;
Security should be done by default, if not, while you configure your operating system for security, you are already compromised from the start. And more secure users is better than less, for example as you communicate with other secure users you are protected as well, protecting your communications with others.&lt;br /&gt;
&lt;br /&gt;
Follow [https://wiki.alpinelinux.org/wiki/DM-verity DM-Verity] wiki for an attempt at full verified/trusted boot on Alpine Linux.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
At this point, it would be it&#039;s own Linux distro&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Clevis&amp;diff=28578</id>
		<title>Clevis</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Clevis&amp;diff=28578"/>
		<updated>2024-12-25T16:23:32Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{draft}}&lt;br /&gt;
&lt;br /&gt;
==== What is clevis ====&lt;br /&gt;
It is a software that allows to encrypt/decrypt a disk by bounding to tang (network bound encryption/decryption) or a TPM (hardware chip encryption/decryption).&lt;br /&gt;
&lt;br /&gt;
==== Auto Disk decryption using clevis + tang ====&lt;br /&gt;
&lt;br /&gt;
You need to run tang in a separate server, from the one you want to decrypt. I recommend running a tang server on a docker.&lt;br /&gt;
&lt;br /&gt;
=== mkinitfs + kernel-hooks + secureboot-hook ===&lt;br /&gt;
{{todo| write guide}}&lt;br /&gt;
&lt;br /&gt;
Using mkinitfs, it is possible to force tang/clevis in initramfs generation. It is recommended to make a chroot or docker so you don&#039;t mess with your system files, and by adding these files:&lt;br /&gt;
&lt;br /&gt;
{{todo| The init script is too big to put in wiki, I just acquired it from initramfs generation and decompression (read the tip below)}}&lt;br /&gt;
&lt;br /&gt;
{{note| the APK package &amp;quot;cryptsetup&amp;quot; comes with veritysetup&lt;br /&gt;
{{cmd| apk add cryptsetup}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{note| make sure the chroot has a linux-kernel}}&lt;br /&gt;
&lt;br /&gt;
Edit /sbin/mkinitfs (put &amp;quot;# Copy custom init&amp;quot; before &amp;quot;# copy modloop signature&amp;quot;):&lt;br /&gt;
{{cat| /etc/mkinitfs|...&lt;br /&gt;
        # Copy custom init &lt;br /&gt;
        cp /initramfs/init &amp;quot;$tmpdir&amp;quot;/init &lt;br /&gt;
        &lt;br /&gt;
        # copy modloop signature&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
PUT &amp;quot;# Clevis + tang script&amp;quot; AFTER &amp;quot;ebegin &amp;quot;Mounting root&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
{{cat| /initramfs/init|...&lt;br /&gt;
        ebegin &amp;quot;Mounting root&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        # Clevis + tang script # work in progress&lt;br /&gt;
...&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/curl.files|&lt;br /&gt;
/usr/bin/curl&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/clevis.files|&lt;br /&gt;
/usr/bin/clevis*&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/mkinitfs.conf|...&lt;br /&gt;
features{{=}}&amp;quot;... curl clevis&amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
Then just do:&lt;br /&gt;
{{cmd| apk add secureboot-hook gummiboot gummiboot-efistub efibootmgr kernel-hooks secureboot-hook}}&lt;br /&gt;
&lt;br /&gt;
{{tip|To make sure initramfs has the scripts needed, do:&lt;br /&gt;
{{cmd|mkinitfs -c /etc/mkinitfs/mkinitfs.conf -b / $(uname -r)}}&lt;br /&gt;
Decompress:&lt;br /&gt;
{{cmd|mkdir /tmp/initramfs&lt;br /&gt;
cd /tmp/initramfs&lt;br /&gt;
&amp;lt;nowiki&amp;gt;zcat /boot/initramfs-$KERNEL | cpio -idmv&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Test if &amp;quot;init&amp;quot; works by just executing it and see how it runs:&lt;br /&gt;
{{cmd|./init}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=== dracut ===&lt;br /&gt;
{{todo| write guide}}&lt;br /&gt;
&lt;br /&gt;
==== External sources ====&lt;br /&gt;
* [https://fedoramagazine.org/using-linux-system-roles-to-implement-clevis-and-tang-for-automated-luks-volume-unlocking/ https://fedoramagazine.org/using-linux-system-roles-to-implement-clevis-and-tang-for-automated-luks-volume-unlocking/]&lt;br /&gt;
* [https://www.admin-magazine.com/Archive/2018/43/Automatic-data-encryption-and-decryption-with-Clevis-and-Tang https://www.admin-magazine.com/Archive/2018/43/Automatic-data-encryption-and-decryption-with-Clevis-and-Tang]&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Clevis&amp;diff=28577</id>
		<title>Clevis</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Clevis&amp;diff=28577"/>
		<updated>2024-12-25T16:22:41Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: Created page with &amp;quot;{{draft}}  ==== What is clevis ==== It is a software that allows to encrypt/decrypt a disk by bounding to tang (network bound encryption/decryption) or a TPM (hardware chip encryption/decryption).  ==== Auto Disk decryption using clevis + tang ====  You need to run tang in a separate server, from the one you want to decrypt. I recommend running a tang server on a docker.  === mkinitfs + kernel-hooks + secureboot-hook === {{todo| write guide}}  Using mkinitfs, it is possi...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{draft}}&lt;br /&gt;
&lt;br /&gt;
==== What is clevis ====&lt;br /&gt;
It is a software that allows to encrypt/decrypt a disk by bounding to tang (network bound encryption/decryption) or a TPM (hardware chip encryption/decryption).&lt;br /&gt;
&lt;br /&gt;
==== Auto Disk decryption using clevis + tang ====&lt;br /&gt;
&lt;br /&gt;
You need to run tang in a separate server, from the one you want to decrypt. I recommend running a tang server on a docker.&lt;br /&gt;
&lt;br /&gt;
=== mkinitfs + kernel-hooks + secureboot-hook ===&lt;br /&gt;
{{todo| write guide}}&lt;br /&gt;
&lt;br /&gt;
Using mkinitfs, it is possible to force tang/clevis in initramfs generation. It is recommended to make a chroot or docker so you don&#039;t mess with your system files, and by adding these files:&lt;br /&gt;
&lt;br /&gt;
{{todo| The init script is too big to put in wiki, I just acquired it from initramfs generation and decompression (read the tip below)}}&lt;br /&gt;
&lt;br /&gt;
{{note| the APK package &amp;quot;cryptsetup&amp;quot; comes with veritysetup&lt;br /&gt;
{{cmd| apk add cryptsetup}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{note| make sure the chroot has a linux-kernel}}&lt;br /&gt;
&lt;br /&gt;
Edit /sbin/mkinitfs (put &amp;quot;# Copy custom init&amp;quot; before &amp;quot;# copy modloop signature&amp;quot;):&lt;br /&gt;
{{cat| /etc/mkinitfs|...&lt;br /&gt;
        # Copy custom init &lt;br /&gt;
        cp /initramfs/init &amp;quot;$tmpdir&amp;quot;/init &lt;br /&gt;
        &lt;br /&gt;
        # copy modloop signature&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
PUT &amp;quot;# Call custom script&amp;quot; AFTER &amp;quot;ebegin &amp;quot;Mounting root&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
{{cat| /initramfs/init|...&lt;br /&gt;
        ebegin &amp;quot;Mounting root&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        # Clevis + tang script # work in progress&lt;br /&gt;
...&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/curl.files|&lt;br /&gt;
/usr/bin/curl&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/clevis.files|&lt;br /&gt;
/usr/bin/clevis*&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/mkinitfs.conf|...&lt;br /&gt;
features{{=}}&amp;quot;... curl clevis&amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
{{cat| /etc/scripts/my-custom-script.sh|&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
mount /dev/mapper/root /root&lt;br /&gt;
mount /root/var/root/erofs.img /sysroot&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Then just do:&lt;br /&gt;
{{cmd| apk add secureboot-hook gummiboot gummiboot-efistub efibootmgr kernel-hooks secureboot-hook}}&lt;br /&gt;
&lt;br /&gt;
{{tip|To make sure initramfs has the scripts needed, do:&lt;br /&gt;
{{cmd|mkinitfs -c /etc/mkinitfs/mkinitfs.conf -b / $(uname -r)}}&lt;br /&gt;
Decompress:&lt;br /&gt;
{{cmd|mkdir /tmp/initramfs&lt;br /&gt;
cd /tmp/initramfs&lt;br /&gt;
&amp;lt;nowiki&amp;gt;zcat /boot/initramfs-$KERNEL | cpio -idmv&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Test if &amp;quot;init&amp;quot; works by just executing it and see how it runs:&lt;br /&gt;
{{cmd|./init}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=== dracut ===&lt;br /&gt;
{{todo| write guide}}&lt;br /&gt;
&lt;br /&gt;
==== External sources ====&lt;br /&gt;
* [https://fedoramagazine.org/using-linux-system-roles-to-implement-clevis-and-tang-for-automated-luks-volume-unlocking/ https://fedoramagazine.org/using-linux-system-roles-to-implement-clevis-and-tang-for-automated-luks-volume-unlocking/]&lt;br /&gt;
* [https://www.admin-magazine.com/Archive/2018/43/Automatic-data-encryption-and-decryption-with-Clevis-and-Tang https://www.admin-magazine.com/Archive/2018/43/Automatic-data-encryption-and-decryption-with-Clevis-and-Tang]&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Talk:Custom_Kernel&amp;diff=28573</id>
		<title>Talk:Custom Kernel</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Talk:Custom_Kernel&amp;diff=28573"/>
		<updated>2024-12-25T15:57:55Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Needs to be adjusted for other archs&lt;br /&gt;
&lt;br /&gt;
&amp;lt;small&amp;gt;&amp;lt;span class=&amp;quot;autosigned&amp;quot;&amp;gt;—&amp;amp;nbsp;Preceding [[Help:Signature|unsigned]] comment added by [[User:Orson Teodoro|Orson Teodoro]] ([[User talk:Orson Teodoro|{{int:talkpagelinktext}}]] • [[Special:Contributions/Orson Teodoro|{{int:contribslink}}]]) 03:36, 4 March 2018&amp;lt;/span&amp;gt;&amp;lt;/small&amp;gt;‎&lt;br /&gt;
&lt;br /&gt;
== Locations/paths of build config files ==&lt;br /&gt;
&lt;br /&gt;
My goal is to build the Virt (not Standard/LTS) kernel using the defaults for Virt, and I don&#039;t understand which files are needed in exactly which paths.&lt;br /&gt;
&lt;br /&gt;
I had difficulty understanding the excerpt below. Is anyone willing to assist me in understanding it? For example, where/what is the &amp;quot;linux-4.15&amp;quot; folder?&lt;br /&gt;
&lt;br /&gt;
:&#039;&#039;When you are done with your edits either by editing directly the APKBUILD and copying the lts.ARCH.config as .config in the linux-4.15 folder. You will then move the .config back overriding the lts.ARCH.config generated by make menuconfig.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;small&amp;gt;&amp;lt;span class=&amp;quot;autosigned&amp;quot;&amp;gt;—&amp;amp;nbsp;Preceding [[Help:Signature|unsigned]] comment added by [[User:-anthumchris-|-anthumchris-]] ([[User talk:-anthumchris-|{{int:talkpagelinktext}}]] • [[Special:Contributions/-anthumchris-|{{int:contribslink}}]]) 17:34, 23 November 2024‎&amp;lt;/span&amp;gt;&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== build_NAME ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;After you are done using the menu in the build-NAME folder by doing make menuconfig&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It is really not clear what is meant by &amp;quot;the build-NAME folder&amp;quot; here.&lt;br /&gt;
&lt;br /&gt;
== Locations/paths of build config files Answer ==&lt;br /&gt;
&lt;br /&gt;
Usually these are the directories you would look for in linux-lts apk package development (replace &amp;quot;x86_64&amp;quot; with different $ARCH if needed) (replace $YOUR_WORK_DIR to which directory you downloaded aports to), &lt;br /&gt;
&lt;br /&gt;
Below should contain &amp;lt;code&amp;gt;APKBUILD&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;lts.x86_64.config&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;virt.x86_64.config&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;.patch&amp;lt;/code&amp;gt; files (and more $ARCH&#039;s by default, but to keep it simple, I will just state the x86_64 files)&lt;br /&gt;
{{cmd|$YOUR_WORK_DIR/aports/main/linux-lts}}&lt;br /&gt;
&lt;br /&gt;
ALL &amp;lt;code&amp;gt;.patch&amp;lt;/code&amp;gt; files that are in $YOUR_WORK_DIR/aports/main/linux-lts are also in below&lt;br /&gt;
{{cmd|$YOUR_WORK_DIR/aports/main/linux-lts/src}}&lt;br /&gt;
&lt;br /&gt;
Below is a tar compressed linux file that decompresses into linux-$VERSION&lt;br /&gt;
{{cmd|$YOUR_WORK_DIR/aports/main/linux-lts/src/linux-$VERSION.tar.gz}}&lt;br /&gt;
&lt;br /&gt;
{{cmd|$YOUR_WORK_DIR/aports/main/linux-lts/src/linux-$VERSION}}&lt;br /&gt;
{{cmd|$YOUR_WORK_DIR/aports/main/linux-lts/src/build-lts.x86_64}}&lt;br /&gt;
{{cmd|$YOUR_WORK_DIR/aports/main/linux-lts/src/build-virt.x86_64}}&lt;br /&gt;
&lt;br /&gt;
In the &amp;quot;&amp;lt;code&amp;gt;APKBUILD&amp;lt;/code&amp;gt;&amp;quot; file, change this &amp;quot;&amp;lt;code&amp;gt;source&amp;lt;/code&amp;gt;&amp;quot; line to this:&lt;br /&gt;
{{cat|$YOUR_WORK_DIR/aports/main/linux-lts/APKBUILD|...&lt;br /&gt;
source{{=}}&amp;quot;https://cdn.kernel.org/pub/linux/kernel/v${pkgver%%.*}.x/linux-$_kernver.tar.xz&lt;br /&gt;
    0001-powerpc-boot-wrapper-Add-z-notext-flag-for-ppc64le.patch&lt;br /&gt;
    0002-x86-Compress-vmlinux-with-zstd-19-instead-of-22.patch&lt;br /&gt;
    0003-kexec-add-kexec_load_disabled-boot-option.patch&lt;br /&gt;
    0004-objtool-respect-AWK-setting.patch&lt;br /&gt;
    0005-powerpc-config-defang-gcc-check-for-stack-protector-.patch&lt;br /&gt;
&lt;br /&gt;
    lts.x86_64.config&lt;br /&gt;
&lt;br /&gt;
    virt.x86_64.config&lt;br /&gt;
    &amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
do &amp;lt;code&amp;gt;make menuconfig&amp;lt;/code&amp;gt; within &amp;lt;code&amp;gt;$YOUR_WORK_DIR/aports/main/linux-lts/src/linux-$VERSION&amp;lt;/code&amp;gt; and copy the .config file to &amp;lt;code&amp;gt;$YOUR_WORK_DIR/aports/main/linux-lts/lts.x86_64.config&amp;lt;/code&amp;gt; and/or &amp;lt;code&amp;gt;$YOUR_WORK_DIR/aports/main/linux-lts/virt.x86_64.config&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;small&amp;gt;&amp;lt;span class=&amp;quot;autosigned&amp;quot;&amp;gt;—&amp;amp;nbsp;Preceding [[Help:Signature|unsigned]] comment added by [[User:Pursuable1652|Pursuable1652]] ([[User talk:Pursuable1652|{{int:talkpagelinktext}}]] • [[Special:Contributions/Pursuable1652|{{int:contribslink}}]]) 16:55, 25 December 2024‎&amp;lt;/span&amp;gt;&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== build_NAME Answer ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;After you are done using the menu in the build-NAME folder by doing make menuconfig&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
the &amp;quot;build-NAME&amp;quot; folder should actually be &amp;lt;code&amp;gt;$YOUR_WORK_DIR/aports/main/linux-lts/src/linux-$VERSION&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;small&amp;gt;&amp;lt;span class=&amp;quot;autosigned&amp;quot;&amp;gt;—&amp;amp;nbsp;Preceding [[Help:Signature|unsigned]] comment added by [[User:Pursuable1652|Pursuable1652]] ([[User talk:Pursuable1652|{{int:talkpagelinktext}}]] • [[Special:Contributions/Pursuable1652|{{int:contribslink}}]]) 16:55, 25 December 2024‎&amp;lt;/span&amp;gt;&amp;lt;/small&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Talk:Custom_Kernel&amp;diff=28572</id>
		<title>Talk:Custom Kernel</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Talk:Custom_Kernel&amp;diff=28572"/>
		<updated>2024-12-25T15:57:17Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Needs to be adjusted for other archs&lt;br /&gt;
&lt;br /&gt;
&amp;lt;small&amp;gt;&amp;lt;span class=&amp;quot;autosigned&amp;quot;&amp;gt;—&amp;amp;nbsp;Preceding [[Help:Signature|unsigned]] comment added by [[User:Orson Teodoro|Orson Teodoro]] ([[User talk:Orson Teodoro|{{int:talkpagelinktext}}]] • [[Special:Contributions/Orson Teodoro|{{int:contribslink}}]]) 03:36, 4 March 2018&amp;lt;/span&amp;gt;&amp;lt;/small&amp;gt;‎&lt;br /&gt;
&lt;br /&gt;
== Locations/paths of build config files ==&lt;br /&gt;
&lt;br /&gt;
My goal is to build the Virt (not Standard/LTS) kernel using the defaults for Virt, and I don&#039;t understand which files are needed in exactly which paths.&lt;br /&gt;
&lt;br /&gt;
I had difficulty understanding the excerpt below. Is anyone willing to assist me in understanding it? For example, where/what is the &amp;quot;linux-4.15&amp;quot; folder?&lt;br /&gt;
&lt;br /&gt;
:&#039;&#039;When you are done with your edits either by editing directly the APKBUILD and copying the lts.ARCH.config as .config in the linux-4.15 folder. You will then move the .config back overriding the lts.ARCH.config generated by make menuconfig.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;small&amp;gt;&amp;lt;span class=&amp;quot;autosigned&amp;quot;&amp;gt;—&amp;amp;nbsp;Preceding [[Help:Signature|unsigned]] comment added by [[User:-anthumchris-|-anthumchris-]] ([[User talk:-anthumchris-|{{int:talkpagelinktext}}]] • [[Special:Contributions/-anthumchris-|{{int:contribslink}}]]) 17:34, 23 November 2024‎&amp;lt;/span&amp;gt;&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== build_NAME ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;After you are done using the menu in the build-NAME folder by doing make menuconfig&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It is really not clear what is meant by &amp;quot;the build-NAME folder&amp;quot; here.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Locations/paths of build config files Answer ==&lt;br /&gt;
&lt;br /&gt;
Usually these are the directories you would look for in linux-lts apk package development (replace &amp;quot;x86_64&amp;quot; with different $ARCH if needed) (replace $YOUR_WORK_DIR to which directory you downloaded aports to), &lt;br /&gt;
&lt;br /&gt;
Below should contain &amp;lt;code&amp;gt;APKBUILD&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;lts.x86_64.config&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;virt.x86_64.config&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;.patch&amp;lt;/code&amp;gt; files (and more $ARCH&#039;s by default, but to keep it simple, I will just state the x86_64 files)&lt;br /&gt;
{{cmd|$YOUR_WORK_DIR/aports/main/linux-lts}}&lt;br /&gt;
&lt;br /&gt;
ALL &amp;lt;code&amp;gt;.patch&amp;lt;/code&amp;gt; files that are in $YOUR_WORK_DIR/aports/main/linux-lts are also in below&lt;br /&gt;
{{cmd|$YOUR_WORK_DIR/aports/main/linux-lts/src}}&lt;br /&gt;
&lt;br /&gt;
Below is a tar compressed linux file that decompresses into linux-$VERSION&lt;br /&gt;
{{cmd|$YOUR_WORK_DIR/aports/main/linux-lts/src/linux-$VERSION.tar.gz}}&lt;br /&gt;
&lt;br /&gt;
{{cmd|$YOUR_WORK_DIR/aports/main/linux-lts/src/linux-$VERSION}}&lt;br /&gt;
{{cmd|$YOUR_WORK_DIR/aports/main/linux-lts/src/build-lts.x86_64}}&lt;br /&gt;
{{cmd|$YOUR_WORK_DIR/aports/main/linux-lts/src/build-virt.x86_64}}&lt;br /&gt;
&lt;br /&gt;
In the &amp;quot;&amp;lt;code&amp;gt;APKBUILD&amp;lt;/code&amp;gt;&amp;quot; file, change this &amp;quot;&amp;lt;code&amp;gt;source&amp;lt;/code&amp;gt;&amp;quot; line to this:&lt;br /&gt;
{{cat|$YOUR_WORK_DIR/aports/main/linux-lts/APKBUILD|...&lt;br /&gt;
source{{=}}&amp;quot;https://cdn.kernel.org/pub/linux/kernel/v${pkgver%%.*}.x/linux-$_kernver.tar.xz&lt;br /&gt;
    0001-powerpc-boot-wrapper-Add-z-notext-flag-for-ppc64le.patch&lt;br /&gt;
    0002-x86-Compress-vmlinux-with-zstd-19-instead-of-22.patch&lt;br /&gt;
    0003-kexec-add-kexec_load_disabled-boot-option.patch&lt;br /&gt;
    0004-objtool-respect-AWK-setting.patch&lt;br /&gt;
    0005-powerpc-config-defang-gcc-check-for-stack-protector-.patch&lt;br /&gt;
&lt;br /&gt;
    lts.x86_64.config&lt;br /&gt;
&lt;br /&gt;
    virt.x86_64.config&lt;br /&gt;
    &amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
do &amp;lt;code&amp;gt;make menuconfig&amp;lt;/code&amp;gt; within &amp;lt;code&amp;gt;$YOUR_WORK_DIR/aports/main/linux-lts/src/linux-$VERSION&amp;lt;/code&amp;gt; and copy the .config file to &amp;lt;code&amp;gt;$YOUR_WORK_DIR/aports/main/linux-lts/lts.x86_64.config&amp;lt;/code&amp;gt; and/or &amp;lt;code&amp;gt;$YOUR_WORK_DIR/aports/main/linux-lts/virt.x86_64.config&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;small&amp;gt;&amp;lt;span class=&amp;quot;autosigned&amp;quot;&amp;gt;—&amp;amp;nbsp;Preceding [[Help:Signature|unsigned]] comment added by [[User:Pursuable1652|Pursuable1652]] ([[User talk:Pursuable1652|{{int:talkpagelinktext}}]] • [[Special:Contributions/Pursuable1652|{{int:contribslink}}]]) 16:55, 25 December 2024‎&amp;lt;/span&amp;gt;&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== build_NAME Answer ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;After you are done using the menu in the build-NAME folder by doing make menuconfig&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
the &amp;quot;build-NAME&amp;quot; folder should actually be &amp;lt;code&amp;gt;$YOUR_WORK_DIR/aports/main/linux-lts/src/linux-$VERSION&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;small&amp;gt;&amp;lt;span class=&amp;quot;autosigned&amp;quot;&amp;gt;—&amp;amp;nbsp;Preceding [[Help:Signature|unsigned]] comment added by [[User:Pursuable1652|Pursuable1652]] ([[User talk:Pursuable1652|{{int:talkpagelinktext}}]] • [[Special:Contributions/Pursuable1652|{{int:contribslink}}]]) 16:55, 25 December 2024‎&amp;lt;/span&amp;gt;&amp;lt;/small&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Talk:Custom_Kernel&amp;diff=28570</id>
		<title>Talk:Custom Kernel</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Talk:Custom_Kernel&amp;diff=28570"/>
		<updated>2024-12-25T15:55:06Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Needs to be adjusted for other archs&lt;br /&gt;
&lt;br /&gt;
&amp;lt;small&amp;gt;&amp;lt;span class=&amp;quot;autosigned&amp;quot;&amp;gt;—&amp;amp;nbsp;Preceding [[Help:Signature|unsigned]] comment added by [[User:Orson Teodoro|Orson Teodoro]] ([[User talk:Orson Teodoro|{{int:talkpagelinktext}}]] • [[Special:Contributions/Orson Teodoro|{{int:contribslink}}]]) 03:36, 4 March 2018&amp;lt;/span&amp;gt;&amp;lt;/small&amp;gt;‎&lt;br /&gt;
&lt;br /&gt;
== Locations/paths of build config files ==&lt;br /&gt;
&lt;br /&gt;
My goal is to build the Virt (not Standard/LTS) kernel using the defaults for Virt, and I don&#039;t understand which files are needed in exactly which paths.&lt;br /&gt;
&lt;br /&gt;
I had difficulty understanding the excerpt below. Is anyone willing to assist me in understanding it? For example, where/what is the &amp;quot;linux-4.15&amp;quot; folder?&lt;br /&gt;
&lt;br /&gt;
:&#039;&#039;When you are done with your edits either by editing directly the APKBUILD and copying the lts.ARCH.config as .config in the linux-4.15 folder. You will then move the .config back overriding the lts.ARCH.config generated by make menuconfig.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;small&amp;gt;&amp;lt;span class=&amp;quot;autosigned&amp;quot;&amp;gt;—&amp;amp;nbsp;Preceding [[Help:Signature|unsigned]] comment added by [[User:-anthumchris-|-anthumchris-]] ([[User talk:-anthumchris-|{{int:talkpagelinktext}}]] • [[Special:Contributions/-anthumchris-|{{int:contribslink}}]]) 17:34, 23 November 2024‎&amp;lt;/span&amp;gt;&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== build_NAME ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;After you are done using the menu in the build-NAME folder by doing make menuconfig&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It is really not clear what is meant by &amp;quot;the build-NAME folder&amp;quot; here.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
== Locations/paths of build config files Answer ==&lt;br /&gt;
&lt;br /&gt;
Usually these are the directories you would look for in linux-lts apk package development (replace &amp;quot;x86_64&amp;quot; with different $ARCH if needed) (replace $YOUR_WORK_DIR to which directory you downloaded aports to), &lt;br /&gt;
&lt;br /&gt;
Below should contain &amp;lt;code&amp;gt;APKBUILD&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;lts.x86_64.config&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;virt.x86_64.config&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;.patch&amp;lt;/code&amp;gt; files (and more $ARCH&#039;s by default, but to keep it simple, I will just state the x86_64 files)&lt;br /&gt;
{{cmd|$YOUR_WORK_DIR/aports/main/linux-lts}}&lt;br /&gt;
&lt;br /&gt;
ALL &amp;lt;code&amp;gt;.patch&amp;lt;/code&amp;gt; files that are in $YOUR_WORK_DIR/aports/main/linux-lts are also in below&lt;br /&gt;
{{cmd|$YOUR_WORK_DIR/aports/main/linux-lts/src}}&lt;br /&gt;
&lt;br /&gt;
Below is a tar compressed linux file that decompresses into linux-$VERSION&lt;br /&gt;
{{cmd|$YOUR_WORK_DIR/aports/main/linux-lts/src/linux-$VERSION.tar.gz}}&lt;br /&gt;
&lt;br /&gt;
{{cmd|$YOUR_WORK_DIR/aports/main/linux-lts/src/linux-$VERSION}}&lt;br /&gt;
{{cmd|$YOUR_WORK_DIR/aports/main/linux-lts/src/build-lts.x86_64}}&lt;br /&gt;
{{cmd|$YOUR_WORK_DIR/aports/main/linux-lts/src/build-virt.x86_64}}&lt;br /&gt;
&lt;br /&gt;
In the &amp;quot;&amp;lt;code&amp;gt;APKBUILD&amp;lt;/code&amp;gt;&amp;quot; file, change this &amp;quot;&amp;lt;code&amp;gt;source&amp;lt;/code&amp;gt;&amp;quot; line to this:&lt;br /&gt;
{{cat|$YOUR_WORK_DIR/aports/main/linux-lts/APKBUILD|...&lt;br /&gt;
source{{=}}&amp;quot;https://cdn.kernel.org/pub/linux/kernel/v${pkgver%%.*}.x/linux-$_kernver.tar.xz&lt;br /&gt;
    0001-powerpc-boot-wrapper-Add-z-notext-flag-for-ppc64le.patch&lt;br /&gt;
    0002-x86-Compress-vmlinux-with-zstd-19-instead-of-22.patch&lt;br /&gt;
    0003-kexec-add-kexec_load_disabled-boot-option.patch&lt;br /&gt;
    0004-objtool-respect-AWK-setting.patch&lt;br /&gt;
    0005-powerpc-config-defang-gcc-check-for-stack-protector-.patch&lt;br /&gt;
&lt;br /&gt;
    lts.x86_64.config&lt;br /&gt;
&lt;br /&gt;
    virt.x86_64.config&lt;br /&gt;
    &amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
do &amp;lt;code&amp;gt;make menuconfig&amp;lt;/code&amp;gt; within &amp;lt;code&amp;gt;$YOUR_WORK_DIR/aports/main/linux-lts/src/linux-$VERSION&amp;lt;/code&amp;gt; and copy the .config file to &amp;lt;code&amp;gt;$YOUR_WORK_DIR/aports/main/linux-lts/lts.x86_64.config&amp;lt;/code&amp;gt; and/or &amp;lt;code&amp;gt;$YOUR_WORK_DIR/aports/main/linux-lts/virt.x86_64.config&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
— Preceding unsigned comment added by -Pursuable1652- (talk • contribs) 16:53, 25 December 2024‎&lt;br /&gt;
&lt;br /&gt;
== build_NAME Answer ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;After you are done using the menu in the build-NAME folder by doing make menuconfig&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
the &amp;quot;build-NAME&amp;quot; folder should actually be &amp;lt;code&amp;gt;$YOUR_WORK_DIR/aports/main/linux-lts/src/linux-$VERSION&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
— Preceding unsigned comment added by -Pursuable1652- (talk • contribs) 16:53, 25 December 2024‎&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=DM-verity&amp;diff=28569</id>
		<title>DM-verity</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=DM-verity&amp;diff=28569"/>
		<updated>2024-12-23T23:40:13Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{todo| Add a non-initramfs dm-verity implementation, which should use kernel to do dm-verity checking instead of initramfs, which is better for embedded devices, and faster to boot (but hard to implement because of kernel customizations, might need to compile kernel again.)}}&lt;br /&gt;
&lt;br /&gt;
== Why DM-Verity? ==&lt;br /&gt;
Possibly you want to continue the RoT ([https://en.wikipedia.org/wiki/Chain_of_trust Root of Trust] [1]) - from the hardware (Hardware TPM as Root of Trust, which ensures only the hardware with the correct secret cryptographic key in the TPM to decrypt the disk/file encryption) -&amp;gt; secure boot (Secure Boot to only run approved signed EFIStub/signed Bootloader) -&amp;gt; &amp;lt;u&amp;gt;To NOW DM-Verity rootfs&amp;lt;/u&amp;gt; (which ensures your root-image/root-parition has not been tampered with) -&amp;gt; Mandatory Access Control (AppArmor or SELinux - SELinux is disabled on default linux-lts btw) -&amp;gt; Sandboxed/Virtual-Machined Applications.&lt;br /&gt;
&lt;br /&gt;
=== What&#039;s the difference between me just setting the root partition as read-only (basically just an Immutable Root Partition) vs this? ===&lt;br /&gt;
DM-Verity COMPLETELY disallows modifying any files in the root-partition/root-image, or even disallow a part of a root-image/root-partition (the root-image/root-partition needs to be INTACT and match the signed cryptography verified by DM-Verity on a different partition), and with this consideration, you may use ERO-FS or SquashFS to generate Read-Only Root-Paritition Images. If you set your EXT4 file system to writable, and DM-Verity were to use it, it would be seen as &amp;quot;corrupted&amp;quot; and not boot anymore, because even just ONE tiny data change to the root image/partition would render it &amp;quot;corrupted&amp;quot;. This is the same technology used in Android and Chrome OS Devices. Also related to use in A/B root, also used by Fedora.&lt;br /&gt;
&lt;br /&gt;
{{tip| To keep the security reasonable, you would ideally want to work on the whole RoT, if not then anybody else can attack the non-verifed boot process that ISN&#039;T the root-partition/root-image that is enforced by DM-Verity.&lt;br /&gt;
* This following guide will use dracut to make a signed secureboot-able EFIStub.&lt;br /&gt;
* If you haven&#039;t, you may follow [https://wiki.alpinelinux.org/wiki/LVM_on_LUKS the Alpine Linux disk encryption setup] [2] with DM-Crypt LUKS and LVM&lt;br /&gt;
* You may choose to decrypt the image with TPM when generating with Dracut Modules with &amp;lt;code&amp;gt;add_dracutdrivers+{{=}}&amp;quot; ... tpm2-tss ... &amp;quot;&amp;lt;/code&amp;gt; and [https://github.com/latchset/clevis?tab{{=}}readme-ov-file#pin-tpm2 Clevis] [3]&lt;br /&gt;
* Apply AppArmor using [https://wiki.alpinelinux.org/wiki/AppArmor Alpine Linux AppArmor Wiki] (Docker does use AppArmor already, but you may apply an AppArmor profile on any application that should not have access to specific directories (AppArmor is a PATH based MAC)) [4]&lt;br /&gt;
* Use [https://gvisor.dev/docs/user_guide/install/ GVisor] [5] with Docker ([https://github.com/google/gvisor?tab{{=}}readme-ov-file#why-does-gvisor-exist Docker is NOT a sandbox] [6] (Because docker uses native kernel compared to Gvisor using its own kernel reimplementation)) for sandboxing on servers}}&lt;br /&gt;
&lt;br /&gt;
=== What is ERO-FS? ===&lt;br /&gt;
[https://pocketnow.com/erofs-android-13-explained/ Google thought about implementing ERO-FS with DM-Verity] [7]. Google was reported to be using it in Android 13, and ERO-FS is an excellent and fast compressed read-only filesystem.&lt;br /&gt;
&lt;br /&gt;
Here is an excerpt about &amp;lt;code&amp;gt;mkfs.erofs&amp;lt;/code&amp;gt; on [[https://wiki.archlinux.org/title/Dm-verity Arch Linux Wiki]] [8]:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039; mkfs.erofs(1) offers an attractive alternative to ext4 or squashfs on the root partition. EROFS, like squashfs, does not allow writes by design and has better performance in many cases than comparable filesystems on flash and solid-state media. It uses lz4 compression by default and was designed for Android phones by Huawei, which make extensive use of dm-verity. &#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Installing ===&lt;br /&gt;
&lt;br /&gt;
==== Working with ERO-FS ====&lt;br /&gt;
&lt;br /&gt;
{{warning| This wiki will be using Alpine Linux Edge Version. (Alpine Linux Non-Edge Versions may not contain these packages in the following rest of the wiki page) (Use Alpine Linux Edge Testing Repository in &amp;lt;code&amp;gt;/etc/apk/repositories&amp;lt;/code&amp;gt; as well)}}&lt;br /&gt;
&lt;br /&gt;
{{note| To not be confused, ERO-FS generates a &amp;quot;root image&amp;quot;, but you can replace the words &amp;quot;root partition&amp;quot; with &amp;quot;root image&amp;quot; and vice versa.}}&lt;br /&gt;
&lt;br /&gt;
First, some considerations, you may use a strictly READ-ONLY file system, such as SquashFS or ERO-FS, this wiki will be using ERO-FS (if you use a custom kernel, make sure it supports a file system such as ERO-FS, the default linux-lts does). [[https://github.com/erofs/erofs-utils ERO-FS Github]] [9] contains some information about how to compress and make your own read-only root image.&lt;br /&gt;
&lt;br /&gt;
{{cmd| $ apk install erofs-utils}}&lt;br /&gt;
{{cmd| $ mkdir image &amp;amp;&amp;amp; cd image }}&lt;br /&gt;
{{cmd| $ wget https://dl-cdn.alpinelinux.org/alpine/v3.21/releases/x86_64/alpine-minirootfs-3.21.0-x86_64.tar.gz}}&lt;br /&gt;
{{cmd| $ tar -xvf alpine-minirootfs-3.21.0-x86_64.tar.gz &amp;amp;&amp;amp; rm alpine-minirootfs-3.21.0-x86_64.tar.gz}}&lt;br /&gt;
Command below will generate an ERO-FS Image compressed with lz4 as ./erofs.img (erofs.img would be the root-partition file to use for dracut)&lt;br /&gt;
{{cmd| $ cd .. &amp;amp;&amp;amp; mkfs.erofs -zlz4hc erofs.img ./image}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Working with mkinitfs/kernel-hooks/secureboot-hooks ====&lt;br /&gt;
{{todo| wip}}&lt;br /&gt;
&lt;br /&gt;
Using mkinitfs, it is possible to force veritysetup in initramfs generation. It is recommended to make a chroot or docker so you don&#039;t mess with your system files, and by adding these files:&lt;br /&gt;
&lt;br /&gt;
{{todo| The init script is too big to put in wiki, I just acquired it from initramfs generation and decompression (read the tip below)}}&lt;br /&gt;
{{note| the APK package &amp;quot;cryptsetup&amp;quot; comes with veritysetup&lt;br /&gt;
{{cmd| apk add cryptsetup}}&lt;br /&gt;
}}&lt;br /&gt;
{{note| make sure the chroot has a linux-kernel}}&lt;br /&gt;
&lt;br /&gt;
Edit /sbin/mkinitfs (put &amp;quot;# Copy custom init&amp;quot; before &amp;quot;# copy modloop signature&amp;quot;):&lt;br /&gt;
{{cat| /etc/mkinitfs|...&lt;br /&gt;
        # Copy custom init &lt;br /&gt;
        cp /initramfs/init &amp;quot;$tmpdir&amp;quot;/init &lt;br /&gt;
        &lt;br /&gt;
        # copy modloop signature&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
PUT &amp;quot;# Call custom script&amp;quot; before &amp;quot;if [ &amp;quot;$SINGLEMODE&amp;quot; = &amp;quot;yes&amp;quot; ]; then&amp;quot;&lt;br /&gt;
{{cat| /initramfs/init|...&lt;br /&gt;
                # Call custom script&lt;br /&gt;
                /etc/scripts/my-custom-script.sh&lt;br /&gt;
                &lt;br /&gt;
        if [ &amp;quot;$SINGLEMODE&amp;quot; {{=}} &amp;quot;yes&amp;quot; ]; then&lt;br /&gt;
...&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/my-custom-script.files|&lt;br /&gt;
/etc/scripts/my-custom-script.sh&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/veritysetup.files|&lt;br /&gt;
/sbin/veritysetup&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/veritysetup.modules|&lt;br /&gt;
kernel/drivers/md/dm-verity.ko*&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/erofs.modules|&lt;br /&gt;
kernel/fs/erofs&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/mkinitfs.conf|...&lt;br /&gt;
features{{=}}&amp;quot;... erofs my-custom-script veritysetup&amp;quot;&lt;br /&gt;
MODULES{{=}}&amp;quot;veritysetup erofs&amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
{{cat| /etc/scripts/my-custom-script.sh|&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
mount /dev/mapper/root /root&lt;br /&gt;
mount /root/var/root/erofs.img /sysroot&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Then just do:&lt;br /&gt;
{{cmd| apk add secureboot-hook gummiboot gummiboot-efistub efibootmgr kernel-hooks secureboot-hook}}&lt;br /&gt;
&lt;br /&gt;
{{tip|To make sure initramfs has the scripts needed, do:&lt;br /&gt;
{{cmd|mkinitfs -c /etc/mkinitfs/mkinitfs.conf -b / $(uname -r)}}&lt;br /&gt;
Decompress:&lt;br /&gt;
{{cmd|mkdir /tmp/initramfs&lt;br /&gt;
cd /tmp/initramfs&lt;br /&gt;
&amp;lt;nowiki&amp;gt;zcat /boot/initramfs-$KERNEL | cpio -idmv&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Test if &amp;quot;init&amp;quot; works by just executing it and see how it runs:&lt;br /&gt;
{{cmd|./init}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Working with Dracut ====&lt;br /&gt;
&lt;br /&gt;
Remember, mount your &amp;lt;code&amp;gt;$ROOT_PARTITION&amp;lt;/code&amp;gt; as read only (assuming you use EXT4, if using ERO-FS or SquashFS, ignore this), since any changes will cause DM-Verity to detect it as &amp;quot;corrupt&amp;quot;&lt;br /&gt;
&lt;br /&gt;
{{warning| The following guide was done with FULL disk encryption, so this might not work perfectly on Non encrypted disk setup, also done on UEFI using gummiboot (now called systemd-boot - yes, systemd-boot is a separate project from the systemd init system) EFIStub and generating a UKI (Unified Kernel Image)}}&lt;br /&gt;
&lt;br /&gt;
===== Install basic stuff: =====&lt;br /&gt;
&lt;br /&gt;
{{cmd| apk add dracut dracut-core cryptsetup gummiboot gummiboot-efistub tpm2-tools clevis tpm2-tss tpm2-tss-tcti-device}}&lt;br /&gt;
&lt;br /&gt;
===== Using Clevis for TPM =====&lt;br /&gt;
&lt;br /&gt;
{{cmd| clevis luks bind -d /$ENCRYPTED_ROOT_PARTITION tpm2 &#039;{&amp;quot;pcr_ids&amp;quot;:&amp;quot;1,7&amp;quot;}&#039;}}&lt;br /&gt;
Input LUKS passphrase, remember that yes now it has tpm, but if possible remove old luks passphrase and use keyfile or different passphrase to unlock because tpm is better, and so if your computer breaks, you won&#039;t be locked out of your data!&lt;br /&gt;
&lt;br /&gt;
===== Create a new partition for your DM-Verity: =====&lt;br /&gt;
&lt;br /&gt;
Replace /dev/sdX with your actual device name.&lt;br /&gt;
{{cmd| sudo fdisk /dev/sdX}}&lt;br /&gt;
&lt;br /&gt;
Once in the fdisk interface:&lt;br /&gt;
# Press n to create a new partition&lt;br /&gt;
# Choose p for primary partition&lt;br /&gt;
# Select the partition number (e.g., 4)&lt;br /&gt;
# For the first sector, press Enter to use the default&lt;br /&gt;
# For the last sector, calculate 10% of your root partition size and use +SIZE format. For example, if your root partition is 100GB, enter +10G&lt;br /&gt;
# Press t to change the partition type&lt;br /&gt;
# Enter the partition number you just created&lt;br /&gt;
# Type 8e for Linux LVM type (closest to verity)&lt;br /&gt;
# Press w to write changes and exit&lt;br /&gt;
&lt;br /&gt;
===== Adding custom lines for full disk decryption =====&lt;br /&gt;
&lt;br /&gt;
Edit &amp;quot;&amp;lt;code&amp;gt;/usr/lib/dracut/modules.d/90crypt/cryptroot-ask.sh&amp;lt;/code&amp;gt;&amp;quot; and add these lines right BEFORE &amp;quot;&amp;lt;code&amp;gt;exit 0&amp;lt;/code&amp;gt;&amp;quot; (add your &amp;lt;code&amp;gt;$ROOT_PARTITION&amp;lt;/code&amp;gt; directory and &amp;lt;code&amp;gt;$VERITY_PARTITION&amp;lt;/code&amp;gt; directory):&lt;br /&gt;
&lt;br /&gt;
{{cat| /usr/lib/dracut/modules.d/90crypt/cryptroot-ask.sh|...&lt;br /&gt;
### DM-Verity&lt;br /&gt;
mount /dev/mapper/$ROOT_PARTITION /var/tmp&lt;br /&gt;
cryptsetup open --key-file /var/tmp/$KEYFILE_DIR /dev/$VERITY_PARTITION $VERITY_DM_NAME&lt;br /&gt;
umount /var/tmp&lt;br /&gt;
veritysetup open /dev/$ROOT_PARTITION /dev/$VERITY_PARTITION $(cat /usr/lib/dracut/roothash.txt)&lt;br /&gt;
###&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
===== Generating an EFIStub with Dracut + DM-Verity =====&lt;br /&gt;
&lt;br /&gt;
To setup DM-Verity (borrowed from [https://wiki.archlinux.org/title/Dm-verity Arch Linux Wiki]):&lt;br /&gt;
&lt;br /&gt;
{{cmd| veritysetup format /dev/$ROOT_PARTITION /dev/$VERITY_PARTITION | grep Root | cut -f2 &amp;gt;&amp;gt; /usr/lib/dracut/roothash.txt}}&lt;br /&gt;
&lt;br /&gt;
/etc/dracut.conf (put whatever your boot parameters are in &amp;quot;&amp;lt;code&amp;gt;kernel_cmdline&amp;lt;/code&amp;gt;&amp;quot;):&lt;br /&gt;
&lt;br /&gt;
{{cat| /etc/dracut.conf|...&lt;br /&gt;
kernel_cmdline{{=}}&amp;quot;&amp;quot;&lt;br /&gt;
add_dracutdrivers+{{=}}&amp;quot; busybox crypt crypt-gpg dm rootfs-block kernel-modules kernel-modules-extra tpm2-tss &amp;quot;&lt;br /&gt;
/etc/dracut.conf.d/secureboot.conf&lt;br /&gt;
&lt;br /&gt;
# Do the 3 lines below this if you have your own secureboot keys, or want to use secureboot:&lt;br /&gt;
uefi_secureboot_cert{{=}}&amp;quot;/$SECUREBOOT_KEYS_DIR/db.crt&amp;quot;&lt;br /&gt;
uefi_secureboot_key{{=}}&amp;quot;/$SECUREBOOT_KEYS_DIR/db.key&amp;quot;&lt;br /&gt;
/etc/dracut.conf.d/files.conf&lt;br /&gt;
&lt;br /&gt;
# This is what will import veritysetup binary file into dracut initramfs&lt;br /&gt;
install_items+{{=}}&amp;quot; /sbin/veritysetup &amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
Finally, generate UKI using dracut (replace &amp;lt;code&amp;gt;6.X.X-X-lts&amp;lt;/code&amp;gt; with your kernel &amp;lt;code&amp;gt;$VERSION&amp;lt;/code&amp;gt;) (also replace &amp;lt;code&amp;gt;/boot/efi/EFI/Linux/alpine-linux.efi&amp;lt;/code&amp;gt; with your mount efi partition):&lt;br /&gt;
&lt;br /&gt;
{{cmd| export DRACUT_KMODDIR_OVERRIDE{{=}}1}}&lt;br /&gt;
{{cmd| dracut --include /usr/lib/dracut/roothash.txt /usr/lib/dracut/roothash.txt --host-only --kernel-image /boot/vmlinuz-lts --kmoddir /lib/modules/6.X.X-X-lts --kver 6.X.X-X-lts --uefi --uefi-stub /usr/lib/gummiboot/linuxx64.efi.stub --force --compress lz4 /boot/efi/EFI/Linux/alpine-linux.efi /boot/efi/EFI/Linux/alpine-linux.efi}}&lt;br /&gt;
{{cmd| efibootmgr --create --disk /dev/$EFI_PARTITION --part 1 --label alpine-linux --loader EFI/Linux/alpine-linux.efi}}&lt;br /&gt;
&lt;br /&gt;
Unfortunately, using the default Alpine Linux kernel (&amp;lt;code&amp;gt;linux-lts&amp;lt;/code&amp;gt;) didn&#039;t work so download another distributions root system (like debians or devuan), and replace &amp;lt;code&amp;gt;/lib/modules/6.X.X-X-lts&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;/boot/vmlinuz-lts&amp;lt;/code&amp;gt; with anothers distributions kernel modules and kernel image (Or consider compiling your [https://wiki.alpinelinux.org/wiki/Hardened_linux own linux-hardened kernel] [11]).&lt;br /&gt;
&lt;br /&gt;
{{tip| If you want to test if DM-Verity fully works, change the &amp;lt;code&amp;gt;$ROOT_PARTITION&amp;lt;/code&amp;gt;&#039;s files and it should say it is &amp;quot;corrupt&amp;quot;, and not continue the boot process (only if you use EXT4).}}&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
==== Root of Trust/Chain of Trust ====&lt;br /&gt;
* [https://en.wikipedia.org/wiki/Chain_of_trust https://en.wikipedia.org/wiki/Chain_of_trust] [1]&lt;br /&gt;
==== Full disk encryption with LVM and LUKS (AlpineWiki): ====&lt;br /&gt;
* [https://wiki.alpinelinux.org/wiki/LVM_on_LUKS LVM_on_LUKS] [2]&lt;br /&gt;
==== Clevis Github ====&lt;br /&gt;
* [https://github.com/latchset/clevis?tab=readme-ov-file#pin-tpm2 https://github.com/latchset/clevis?tab=readme-ov-file#pin-tpm2] [3]&lt;br /&gt;
==== AppArmor Wiki (AlpineWiki) ====&lt;br /&gt;
* [https://wiki.alpinelinux.org/wiki/AppArmor AppArmor] [4]&lt;br /&gt;
==== GVisor ====&lt;br /&gt;
* [https://gvisor.dev/docs/user_guide/install/ https://gvisor.dev/docs/user_guide/install/] [5]&lt;br /&gt;
==== Gvisor Github stating docker is not a sandbox ====&lt;br /&gt;
* [https://github.com/google/gvisor?tab=readme-ov-file#why-does-gvisor-exist https://github.com/google/gvisor?tab=readme-ov-file#why-does-gvisor-exist] [6]&lt;br /&gt;
==== Android-13 Possibility of using ERO-FS: ====&lt;br /&gt;
* [https://pocketnow.com/erofs-android-13-explained/ https://pocketnow.com/erofs-android-13-explained/] [7]&lt;br /&gt;
==== DM-Verity (Arch Wiki): ====&lt;br /&gt;
* [https://wiki.archlinux.org/title/Dm-verity https://wiki.archlinux.org/title/Dm-verity] [8]&lt;br /&gt;
==== ERO-FS Github ====&lt;br /&gt;
* [https://github.com/erofs/erofs-utils https://github.com/erofs/erofs-utils] [9]&lt;br /&gt;
==== Dracut (Arch Wiki): ====&lt;br /&gt;
* [https://wiki.archlinux.org/title/Dracut https://wiki.archlinux.org/title/Dracut] [10]&lt;br /&gt;
==== Linux-Hardened Kernel (AlpineWiki): ====&lt;br /&gt;
* [https://wiki.alpinelinux.org/wiki/Hardened_linux Hardened_linux] [11]&lt;br /&gt;
==== My old post on how it worked ====&lt;br /&gt;
* [https://www.reddit.com/r/AlpineLinux/comments/15oibcc/comment/k1l7jv0/ https://www.reddit.com/r/AlpineLinux/comments/15oibcc/comment/k1l7jv0/] [12]&lt;br /&gt;
&lt;br /&gt;
[[Category:Security]] [[Category:Booting]]&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=DM-verity&amp;diff=28568</id>
		<title>DM-verity</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=DM-verity&amp;diff=28568"/>
		<updated>2024-12-23T23:39:32Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{todo| Add a non-initramfs dm-verity implementation, which should use kernel to do dm-verity checking instead of initramfs, which is better for embedded devices, and faster to boot (but hard to implement because of kernel customizations, might need to compile kernel again.)}}&lt;br /&gt;
&lt;br /&gt;
== Why DM-Verity? ==&lt;br /&gt;
Possibly you want to continue the RoT ([https://en.wikipedia.org/wiki/Chain_of_trust Root of Trust] [1]) - from the hardware (Hardware TPM as Root of Trust, which ensures only the hardware with the correct secret cryptographic key in the TPM to decrypt the disk/file encryption) -&amp;gt; secure boot (Secure Boot to only run approved signed EFIStub/signed Bootloader) -&amp;gt; &amp;lt;u&amp;gt;To NOW DM-Verity rootfs&amp;lt;/u&amp;gt; (which ensures your root-image/root-parition has not been tampered with) -&amp;gt; Mandatory Access Control (AppArmor or SELinux - SELinux is disabled on default linux-lts btw) -&amp;gt; Sandboxed/Virtual-Machined Applications.&lt;br /&gt;
&lt;br /&gt;
=== What&#039;s the difference between me just setting the root partition as read-only (basically just an Immutable Root Partition) vs this? ===&lt;br /&gt;
DM-Verity COMPLETELY disallows modifying any files in the root-partition/root-image, or even disallow a part of a root-image/root-partition (the root-image/root-partition needs to be INTACT and match the signed cryptography verified by DM-Verity on a different partition), and with this consideration, you may use ERO-FS or SquashFS to generate Read-Only Root-Paritition Images. If you set your EXT4 file system to writable, and DM-Verity were to use it, it would be seen as &amp;quot;corrupted&amp;quot; and not boot anymore, because even just ONE tiny data change to the root image/partition would render it &amp;quot;corrupted&amp;quot;. This is the same technology used in Android and Chrome OS Devices. Also related to use in A/B root, also used by Fedora.&lt;br /&gt;
&lt;br /&gt;
{{tip| To keep the security reasonable, you would ideally want to work on the whole RoT, if not then anybody else can attack the non-verifed boot process that ISN&#039;T the root-partition/root-image that is enforced by DM-Verity.&lt;br /&gt;
* This following guide will use dracut to make a signed secureboot-able EFIStub.&lt;br /&gt;
* If you haven&#039;t, you may follow [https://wiki.alpinelinux.org/wiki/LVM_on_LUKS the Alpine Linux disk encryption setup] [2] with DM-Crypt LUKS and LVM&lt;br /&gt;
* You may choose to decrypt the image with TPM when generating with Dracut Modules with &amp;lt;code&amp;gt;add_dracutdrivers+{{=}}&amp;quot; ... tpm2-tss ... &amp;quot;&amp;lt;/code&amp;gt; and [https://github.com/latchset/clevis?tab{{=}}readme-ov-file#pin-tpm2 Clevis] [3]&lt;br /&gt;
* Apply AppArmor using [https://wiki.alpinelinux.org/wiki/AppArmor Alpine Linux AppArmor Wiki] (Docker does use AppArmor already, but you may apply an AppArmor profile on any application that should not have access to specific directories (AppArmor is a PATH based MAC)) [4]&lt;br /&gt;
* Use [https://gvisor.dev/docs/user_guide/install/ GVisor] [5] with Docker ([https://github.com/google/gvisor?tab{{=}}readme-ov-file#why-does-gvisor-exist Docker is NOT a sandbox] [6] (Because docker uses native kernel compared to Gvisor using its own kernel reimplementation)) for sandboxing on servers}}&lt;br /&gt;
&lt;br /&gt;
=== What is ERO-FS? ===&lt;br /&gt;
[https://pocketnow.com/erofs-android-13-explained/ Google thought about implementing ERO-FS with DM-Verity] [7]. Google was reported to be using it in Android 13, and ERO-FS is an excellent and fast compressed read-only filesystem.&lt;br /&gt;
&lt;br /&gt;
Here is an excerpt about &amp;lt;code&amp;gt;mkfs.erofs&amp;lt;/code&amp;gt; on [[https://wiki.archlinux.org/title/Dm-verity Arch Linux Wiki]] [8]:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039; mkfs.erofs(1) offers an attractive alternative to ext4 or squashfs on the root partition. EROFS, like squashfs, does not allow writes by design and has better performance in many cases than comparable filesystems on flash and solid-state media. It uses lz4 compression by default and was designed for Android phones by Huawei, which make extensive use of dm-verity. &#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Installing ===&lt;br /&gt;
&lt;br /&gt;
==== Working with ERO-FS ====&lt;br /&gt;
&lt;br /&gt;
{{warning| This wiki will be using Alpine Linux Edge Version. (Alpine Linux Non-Edge Versions may not contain these packages in the following rest of the wiki page) (Use Alpine Linux Edge Testing Repository in &amp;lt;code&amp;gt;/etc/apk/repositories&amp;lt;/code&amp;gt; as well)}}&lt;br /&gt;
&lt;br /&gt;
{{note| To not be confused, ERO-FS generates a &amp;quot;root image&amp;quot;, but you can replace the words &amp;quot;root partition&amp;quot; with &amp;quot;root image&amp;quot; and vice versa.}}&lt;br /&gt;
&lt;br /&gt;
First, some considerations, you may use a strictly READ-ONLY file system, such as SquashFS or ERO-FS, this wiki will be using ERO-FS (if you use a custom kernel, make sure it supports a file system such as ERO-FS, the default linux-lts does). [[https://github.com/erofs/erofs-utils ERO-FS Github]] [9] contains some information about how to compress and make your own read-only root image.&lt;br /&gt;
&lt;br /&gt;
{{cmd| $ apk install erofs-utils}}&lt;br /&gt;
{{cmd| $ mkdir image &amp;amp;&amp;amp; cd image }}&lt;br /&gt;
{{cmd| $ wget https://dl-cdn.alpinelinux.org/alpine/v3.21/releases/x86_64/alpine-minirootfs-3.21.0-x86_64.tar.gz}}&lt;br /&gt;
{{cmd| $ tar -xvf alpine-minirootfs-3.21.0-x86_64.tar.gz &amp;amp;&amp;amp; rm alpine-minirootfs-3.21.0-x86_64.tar.gz}}&lt;br /&gt;
Command below will generate an ERO-FS Image compressed with lz4 as ./erofs.img (erofs.img would be the root-partition file to use for dracut)&lt;br /&gt;
{{cmd| $ cd .. &amp;amp;&amp;amp; mkfs.erofs -zlz4hc erofs.img ./image}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Working with mkinitfs/kernel-hooks/secureboot-hooks ====&lt;br /&gt;
{{todo| wip}}&lt;br /&gt;
&lt;br /&gt;
Using mkinitfs, it is possible to force veritysetup in initramfs generation. It is recommended to make a chroot or docker so you don&#039;t mess with your system files, and by adding these files:&lt;br /&gt;
&lt;br /&gt;
{{todo| The init script is too big to put in wiki, I just acquired it from initramfs generation and decompression (read the tip below)}}&lt;br /&gt;
{{note| the APK package &amp;quot;cryptsetup&amp;quot; comes with veritysetup&lt;br /&gt;
{{cmd| apk add cryptsetup}}&lt;br /&gt;
}}&lt;br /&gt;
{{note| make sure the chroot has a linux-kernel}}&lt;br /&gt;
&lt;br /&gt;
Edit /sbin/mkinitfs (put &amp;quot;# Copy custom init&amp;quot; before &amp;quot;# copy modloop signature&amp;quot;):&lt;br /&gt;
{{cat| /etc/mkinitfs|...&lt;br /&gt;
        # Copy custom init &lt;br /&gt;
        cp /initramfs/init &amp;quot;$tmpdir&amp;quot;/init &lt;br /&gt;
        &lt;br /&gt;
        # copy modloop signature&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
PUT &amp;quot;# Call custom script&amp;quot; before &amp;quot;if [ &amp;quot;$SINGLEMODE&amp;quot; = &amp;quot;yes&amp;quot; ]; then&amp;quot;&lt;br /&gt;
{{cat| /initramfs/init|...&lt;br /&gt;
                # Call custom script&lt;br /&gt;
                /etc/scripts/my-custom-script.sh&lt;br /&gt;
                &lt;br /&gt;
        if [ &amp;quot;$SINGLEMODE&amp;quot; = &amp;quot;yes&amp;quot; ]; then&lt;br /&gt;
...&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/my-custom-script.files|&lt;br /&gt;
/etc/scripts/my-custom-script.sh&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/veritysetup.files|&lt;br /&gt;
/sbin/veritysetup&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/veritysetup.modules|&lt;br /&gt;
kernel/drivers/md/dm-verity.ko*&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/erofs.modules|&lt;br /&gt;
kernel/fs/erofs&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/mkinitfs.conf|...&lt;br /&gt;
features{{=}}&amp;quot;... erofs my-custom-script veritysetup&amp;quot;&lt;br /&gt;
MODULES{{=}}&amp;quot;veritysetup erofs&amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
{{cat| /etc/scripts/my-custom-script.sh|&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
mount /dev/mapper/root /root&lt;br /&gt;
mount /root/var/root/erofs.img /sysroot&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Then just do:&lt;br /&gt;
{{cmd| apk add secureboot-hook gummiboot gummiboot-efistub efibootmgr kernel-hooks secureboot-hook}}&lt;br /&gt;
&lt;br /&gt;
{{tip|To make sure initramfs has the scripts needed, do:&lt;br /&gt;
{{cmd|mkinitfs -c /etc/mkinitfs/mkinitfs.conf -b / $(uname -r)}}&lt;br /&gt;
Decompress:&lt;br /&gt;
{{cmd|mkdir /tmp/initramfs&lt;br /&gt;
cd /tmp/initramfs&lt;br /&gt;
&amp;lt;nowiki&amp;gt;zcat /boot/initramfs-$KERNEL | cpio -idmv&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Test if &amp;quot;init&amp;quot; works by just executing it and see how it runs:&lt;br /&gt;
{{cmd|./init}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Working with Dracut ====&lt;br /&gt;
&lt;br /&gt;
Remember, mount your &amp;lt;code&amp;gt;$ROOT_PARTITION&amp;lt;/code&amp;gt; as read only (assuming you use EXT4, if using ERO-FS or SquashFS, ignore this), since any changes will cause DM-Verity to detect it as &amp;quot;corrupt&amp;quot;&lt;br /&gt;
&lt;br /&gt;
{{warning| The following guide was done with FULL disk encryption, so this might not work perfectly on Non encrypted disk setup, also done on UEFI using gummiboot (now called systemd-boot - yes, systemd-boot is a separate project from the systemd init system) EFIStub and generating a UKI (Unified Kernel Image)}}&lt;br /&gt;
&lt;br /&gt;
===== Install basic stuff: =====&lt;br /&gt;
&lt;br /&gt;
{{cmd| apk add dracut dracut-core cryptsetup gummiboot gummiboot-efistub tpm2-tools clevis tpm2-tss tpm2-tss-tcti-device}}&lt;br /&gt;
&lt;br /&gt;
===== Using Clevis for TPM =====&lt;br /&gt;
&lt;br /&gt;
{{cmd| clevis luks bind -d /$ENCRYPTED_ROOT_PARTITION tpm2 &#039;{&amp;quot;pcr_ids&amp;quot;:&amp;quot;1,7&amp;quot;}&#039;}}&lt;br /&gt;
Input LUKS passphrase, remember that yes now it has tpm, but if possible remove old luks passphrase and use keyfile or different passphrase to unlock because tpm is better, and so if your computer breaks, you won&#039;t be locked out of your data!&lt;br /&gt;
&lt;br /&gt;
===== Create a new partition for your DM-Verity: =====&lt;br /&gt;
&lt;br /&gt;
Replace /dev/sdX with your actual device name.&lt;br /&gt;
{{cmd| sudo fdisk /dev/sdX}}&lt;br /&gt;
&lt;br /&gt;
Once in the fdisk interface:&lt;br /&gt;
# Press n to create a new partition&lt;br /&gt;
# Choose p for primary partition&lt;br /&gt;
# Select the partition number (e.g., 4)&lt;br /&gt;
# For the first sector, press Enter to use the default&lt;br /&gt;
# For the last sector, calculate 10% of your root partition size and use +SIZE format. For example, if your root partition is 100GB, enter +10G&lt;br /&gt;
# Press t to change the partition type&lt;br /&gt;
# Enter the partition number you just created&lt;br /&gt;
# Type 8e for Linux LVM type (closest to verity)&lt;br /&gt;
# Press w to write changes and exit&lt;br /&gt;
&lt;br /&gt;
===== Adding custom lines for full disk decryption =====&lt;br /&gt;
&lt;br /&gt;
Edit &amp;quot;&amp;lt;code&amp;gt;/usr/lib/dracut/modules.d/90crypt/cryptroot-ask.sh&amp;lt;/code&amp;gt;&amp;quot; and add these lines right BEFORE &amp;quot;&amp;lt;code&amp;gt;exit 0&amp;lt;/code&amp;gt;&amp;quot; (add your &amp;lt;code&amp;gt;$ROOT_PARTITION&amp;lt;/code&amp;gt; directory and &amp;lt;code&amp;gt;$VERITY_PARTITION&amp;lt;/code&amp;gt; directory):&lt;br /&gt;
&lt;br /&gt;
{{cat| /usr/lib/dracut/modules.d/90crypt/cryptroot-ask.sh|...&lt;br /&gt;
### DM-Verity&lt;br /&gt;
mount /dev/mapper/$ROOT_PARTITION /var/tmp&lt;br /&gt;
cryptsetup open --key-file /var/tmp/$KEYFILE_DIR /dev/$VERITY_PARTITION $VERITY_DM_NAME&lt;br /&gt;
umount /var/tmp&lt;br /&gt;
veritysetup open /dev/$ROOT_PARTITION /dev/$VERITY_PARTITION $(cat /usr/lib/dracut/roothash.txt)&lt;br /&gt;
###&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
===== Generating an EFIStub with Dracut + DM-Verity =====&lt;br /&gt;
&lt;br /&gt;
To setup DM-Verity (borrowed from [https://wiki.archlinux.org/title/Dm-verity Arch Linux Wiki]):&lt;br /&gt;
&lt;br /&gt;
{{cmd| veritysetup format /dev/$ROOT_PARTITION /dev/$VERITY_PARTITION | grep Root | cut -f2 &amp;gt;&amp;gt; /usr/lib/dracut/roothash.txt}}&lt;br /&gt;
&lt;br /&gt;
/etc/dracut.conf (put whatever your boot parameters are in &amp;quot;&amp;lt;code&amp;gt;kernel_cmdline&amp;lt;/code&amp;gt;&amp;quot;):&lt;br /&gt;
&lt;br /&gt;
{{cat| /etc/dracut.conf|...&lt;br /&gt;
kernel_cmdline{{=}}&amp;quot;&amp;quot;&lt;br /&gt;
add_dracutdrivers+{{=}}&amp;quot; busybox crypt crypt-gpg dm rootfs-block kernel-modules kernel-modules-extra tpm2-tss &amp;quot;&lt;br /&gt;
/etc/dracut.conf.d/secureboot.conf&lt;br /&gt;
&lt;br /&gt;
# Do the 3 lines below this if you have your own secureboot keys, or want to use secureboot:&lt;br /&gt;
uefi_secureboot_cert{{=}}&amp;quot;/$SECUREBOOT_KEYS_DIR/db.crt&amp;quot;&lt;br /&gt;
uefi_secureboot_key{{=}}&amp;quot;/$SECUREBOOT_KEYS_DIR/db.key&amp;quot;&lt;br /&gt;
/etc/dracut.conf.d/files.conf&lt;br /&gt;
&lt;br /&gt;
# This is what will import veritysetup binary file into dracut initramfs&lt;br /&gt;
install_items+{{=}}&amp;quot; /sbin/veritysetup &amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
Finally, generate UKI using dracut (replace &amp;lt;code&amp;gt;6.X.X-X-lts&amp;lt;/code&amp;gt; with your kernel &amp;lt;code&amp;gt;$VERSION&amp;lt;/code&amp;gt;) (also replace &amp;lt;code&amp;gt;/boot/efi/EFI/Linux/alpine-linux.efi&amp;lt;/code&amp;gt; with your mount efi partition):&lt;br /&gt;
&lt;br /&gt;
{{cmd| export DRACUT_KMODDIR_OVERRIDE{{=}}1}}&lt;br /&gt;
{{cmd| dracut --include /usr/lib/dracut/roothash.txt /usr/lib/dracut/roothash.txt --host-only --kernel-image /boot/vmlinuz-lts --kmoddir /lib/modules/6.X.X-X-lts --kver 6.X.X-X-lts --uefi --uefi-stub /usr/lib/gummiboot/linuxx64.efi.stub --force --compress lz4 /boot/efi/EFI/Linux/alpine-linux.efi /boot/efi/EFI/Linux/alpine-linux.efi}}&lt;br /&gt;
{{cmd| efibootmgr --create --disk /dev/$EFI_PARTITION --part 1 --label alpine-linux --loader EFI/Linux/alpine-linux.efi}}&lt;br /&gt;
&lt;br /&gt;
Unfortunately, using the default Alpine Linux kernel (&amp;lt;code&amp;gt;linux-lts&amp;lt;/code&amp;gt;) didn&#039;t work so download another distributions root system (like debians or devuan), and replace &amp;lt;code&amp;gt;/lib/modules/6.X.X-X-lts&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;/boot/vmlinuz-lts&amp;lt;/code&amp;gt; with anothers distributions kernel modules and kernel image (Or consider compiling your [https://wiki.alpinelinux.org/wiki/Hardened_linux own linux-hardened kernel] [11]).&lt;br /&gt;
&lt;br /&gt;
{{tip| If you want to test if DM-Verity fully works, change the &amp;lt;code&amp;gt;$ROOT_PARTITION&amp;lt;/code&amp;gt;&#039;s files and it should say it is &amp;quot;corrupt&amp;quot;, and not continue the boot process (only if you use EXT4).}}&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
==== Root of Trust/Chain of Trust ====&lt;br /&gt;
* [https://en.wikipedia.org/wiki/Chain_of_trust https://en.wikipedia.org/wiki/Chain_of_trust] [1]&lt;br /&gt;
==== Full disk encryption with LVM and LUKS (AlpineWiki): ====&lt;br /&gt;
* [https://wiki.alpinelinux.org/wiki/LVM_on_LUKS LVM_on_LUKS] [2]&lt;br /&gt;
==== Clevis Github ====&lt;br /&gt;
* [https://github.com/latchset/clevis?tab=readme-ov-file#pin-tpm2 https://github.com/latchset/clevis?tab=readme-ov-file#pin-tpm2] [3]&lt;br /&gt;
==== AppArmor Wiki (AlpineWiki) ====&lt;br /&gt;
* [https://wiki.alpinelinux.org/wiki/AppArmor AppArmor] [4]&lt;br /&gt;
==== GVisor ====&lt;br /&gt;
* [https://gvisor.dev/docs/user_guide/install/ https://gvisor.dev/docs/user_guide/install/] [5]&lt;br /&gt;
==== Gvisor Github stating docker is not a sandbox ====&lt;br /&gt;
* [https://github.com/google/gvisor?tab=readme-ov-file#why-does-gvisor-exist https://github.com/google/gvisor?tab=readme-ov-file#why-does-gvisor-exist] [6]&lt;br /&gt;
==== Android-13 Possibility of using ERO-FS: ====&lt;br /&gt;
* [https://pocketnow.com/erofs-android-13-explained/ https://pocketnow.com/erofs-android-13-explained/] [7]&lt;br /&gt;
==== DM-Verity (Arch Wiki): ====&lt;br /&gt;
* [https://wiki.archlinux.org/title/Dm-verity https://wiki.archlinux.org/title/Dm-verity] [8]&lt;br /&gt;
==== ERO-FS Github ====&lt;br /&gt;
* [https://github.com/erofs/erofs-utils https://github.com/erofs/erofs-utils] [9]&lt;br /&gt;
==== Dracut (Arch Wiki): ====&lt;br /&gt;
* [https://wiki.archlinux.org/title/Dracut https://wiki.archlinux.org/title/Dracut] [10]&lt;br /&gt;
==== Linux-Hardened Kernel (AlpineWiki): ====&lt;br /&gt;
* [https://wiki.alpinelinux.org/wiki/Hardened_linux Hardened_linux] [11]&lt;br /&gt;
==== My old post on how it worked ====&lt;br /&gt;
* [https://www.reddit.com/r/AlpineLinux/comments/15oibcc/comment/k1l7jv0/ https://www.reddit.com/r/AlpineLinux/comments/15oibcc/comment/k1l7jv0/] [12]&lt;br /&gt;
&lt;br /&gt;
[[Category:Security]] [[Category:Booting]]&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=DM-verity&amp;diff=28567</id>
		<title>DM-verity</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=DM-verity&amp;diff=28567"/>
		<updated>2024-12-23T23:22:48Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{todo| Add a non-initramfs dm-verity implementation, which should use kernel to do dm-verity checking instead of initramfs, which is better for embedded devices, and faster to boot (but hard to implement because of kernel customizations, might need to compile kernel again.)}}&lt;br /&gt;
&lt;br /&gt;
== Why DM-Verity? ==&lt;br /&gt;
Possibly you want to continue the RoT ([https://en.wikipedia.org/wiki/Chain_of_trust Root of Trust] [1]) - from the hardware (Hardware TPM as Root of Trust, which ensures only the hardware with the correct secret cryptographic key in the TPM to decrypt the disk/file encryption) -&amp;gt; secure boot (Secure Boot to only run approved signed EFIStub/signed Bootloader) -&amp;gt; &amp;lt;u&amp;gt;To NOW DM-Verity rootfs&amp;lt;/u&amp;gt; (which ensures your root-image/root-parition has not been tampered with) -&amp;gt; Mandatory Access Control (AppArmor or SELinux - SELinux is disabled on default linux-lts btw) -&amp;gt; Sandboxed/Virtual-Machined Applications.&lt;br /&gt;
&lt;br /&gt;
=== What&#039;s the difference between me just setting the root partition as read-only (basically just an Immutable Root Partition) vs this? ===&lt;br /&gt;
DM-Verity COMPLETELY disallows modifying any files in the root-partition/root-image, or even disallow a part of a root-image/root-partition (the root-image/root-partition needs to be INTACT and match the signed cryptography verified by DM-Verity on a different partition), and with this consideration, you may use ERO-FS or SquashFS to generate Read-Only Root-Paritition Images. If you set your EXT4 file system to writable, and DM-Verity were to use it, it would be seen as &amp;quot;corrupted&amp;quot; and not boot anymore, because even just ONE tiny data change to the root image/partition would render it &amp;quot;corrupted&amp;quot;. This is the same technology used in Android and Chrome OS Devices. Also related to use in A/B root, also used by Fedora.&lt;br /&gt;
&lt;br /&gt;
{{tip| To keep the security reasonable, you would ideally want to work on the whole RoT, if not then anybody else can attack the non-verifed boot process that ISN&#039;T the root-partition/root-image that is enforced by DM-Verity.&lt;br /&gt;
* This following guide will use dracut to make a signed secureboot-able EFIStub.&lt;br /&gt;
* If you haven&#039;t, you may follow [https://wiki.alpinelinux.org/wiki/LVM_on_LUKS the Alpine Linux disk encryption setup] [2] with DM-Crypt LUKS and LVM&lt;br /&gt;
* You may choose to decrypt the image with TPM when generating with Dracut Modules with &amp;lt;code&amp;gt;add_dracutdrivers+{{=}}&amp;quot; ... tpm2-tss ... &amp;quot;&amp;lt;/code&amp;gt; and [https://github.com/latchset/clevis?tab{{=}}readme-ov-file#pin-tpm2 Clevis] [3]&lt;br /&gt;
* Apply AppArmor using [https://wiki.alpinelinux.org/wiki/AppArmor Alpine Linux AppArmor Wiki] (Docker does use AppArmor already, but you may apply an AppArmor profile on any application that should not have access to specific directories (AppArmor is a PATH based MAC)) [4]&lt;br /&gt;
* Use [https://gvisor.dev/docs/user_guide/install/ GVisor] [5] with Docker ([https://github.com/google/gvisor?tab{{=}}readme-ov-file#why-does-gvisor-exist Docker is NOT a sandbox] [6] (Because docker uses native kernel compared to Gvisor using its own kernel reimplementation)) for sandboxing on servers}}&lt;br /&gt;
&lt;br /&gt;
=== What is ERO-FS? ===&lt;br /&gt;
[https://pocketnow.com/erofs-android-13-explained/ Google thought about implementing ERO-FS with DM-Verity] [7]. Google was reported to be using it in Android 13, and ERO-FS is an excellent and fast compressed read-only filesystem.&lt;br /&gt;
&lt;br /&gt;
Here is an excerpt about &amp;lt;code&amp;gt;mkfs.erofs&amp;lt;/code&amp;gt; on [[https://wiki.archlinux.org/title/Dm-verity Arch Linux Wiki]] [8]:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039; mkfs.erofs(1) offers an attractive alternative to ext4 or squashfs on the root partition. EROFS, like squashfs, does not allow writes by design and has better performance in many cases than comparable filesystems on flash and solid-state media. It uses lz4 compression by default and was designed for Android phones by Huawei, which make extensive use of dm-verity. &#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Installing ===&lt;br /&gt;
&lt;br /&gt;
==== Working with ERO-FS ====&lt;br /&gt;
&lt;br /&gt;
{{warning| This wiki will be using Alpine Linux Edge Version. (Alpine Linux Non-Edge Versions may not contain these packages in the following rest of the wiki page) (Use Alpine Linux Edge Testing Repository in &amp;lt;code&amp;gt;/etc/apk/repositories&amp;lt;/code&amp;gt; as well)}}&lt;br /&gt;
&lt;br /&gt;
{{note| To not be confused, ERO-FS generates a &amp;quot;root image&amp;quot;, but you can replace the words &amp;quot;root partition&amp;quot; with &amp;quot;root image&amp;quot; and vice versa.}}&lt;br /&gt;
&lt;br /&gt;
First, some considerations, you may use a strictly READ-ONLY file system, such as SquashFS or ERO-FS, this wiki will be using ERO-FS (if you use a custom kernel, make sure it supports a file system such as ERO-FS, the default linux-lts does). [[https://github.com/erofs/erofs-utils ERO-FS Github]] [9] contains some information about how to compress and make your own read-only root image.&lt;br /&gt;
&lt;br /&gt;
{{cmd| $ apk install erofs-utils}}&lt;br /&gt;
{{cmd| $ mkdir image &amp;amp;&amp;amp; cd image }}&lt;br /&gt;
{{cmd| $ wget https://dl-cdn.alpinelinux.org/alpine/v3.21/releases/x86_64/alpine-minirootfs-3.21.0-x86_64.tar.gz}}&lt;br /&gt;
{{cmd| $ tar -xvf alpine-minirootfs-3.21.0-x86_64.tar.gz &amp;amp;&amp;amp; rm alpine-minirootfs-3.21.0-x86_64.tar.gz}}&lt;br /&gt;
Command below will generate an ERO-FS Image compressed with lz4 as ./erofs.img (erofs.img would be the root-partition file to use for dracut)&lt;br /&gt;
{{cmd| $ cd .. &amp;amp;&amp;amp; mkfs.erofs -zlz4hc erofs.img ./image}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Working with mkinitfs/kernel-hooks/secureboot-hooks ====&lt;br /&gt;
{{todo| wip}}&lt;br /&gt;
&lt;br /&gt;
Using mkinitfs, it is possible to force veritysetup in initramfs generation. It is recommended to make a chroot or docker so you don&#039;t mess with your system files, and by adding these files:&lt;br /&gt;
&lt;br /&gt;
{{todo| The init script is too big to put in wiki, I just acquired it from initramfs generation and decompression (read the tip below)}}&lt;br /&gt;
{{note| the APK package &amp;quot;cryptsetup&amp;quot; comes with veritysetup&lt;br /&gt;
{{cmd| apk add cryptsetup}}&lt;br /&gt;
}}&lt;br /&gt;
{{note| make sure the chroot has a linux-kernel}}&lt;br /&gt;
&lt;br /&gt;
Edit /sbin/mkinitfs (put &amp;quot;# Copy custom init&amp;quot; before &amp;quot;# copy modloop signature&amp;quot;):&lt;br /&gt;
{{cat| /etc/mkinitfs|...&lt;br /&gt;
        # Copy custom init &lt;br /&gt;
        cp /initramfs/init &amp;quot;$tmpdir&amp;quot;/init &lt;br /&gt;
        &lt;br /&gt;
        # copy modloop signature&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
PUT &amp;quot;# Call custom script&amp;quot; before &amp;quot;# switch over to new root&amp;quot;&lt;br /&gt;
{{cat| /initramfs/init|...&lt;br /&gt;
# Call custom script&lt;br /&gt;
/etc/scripts/my-custom-script.sh&lt;br /&gt;
&lt;br /&gt;
# switch over to new root&lt;br /&gt;
...&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/my-custom-script.files|&lt;br /&gt;
/etc/scripts/my-custom-script.sh&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/veritysetup.files|&lt;br /&gt;
/sbin/veritysetup&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/veritysetup.modules|&lt;br /&gt;
kernel/drivers/md/dm-verity.ko*&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/erofs.modules|&lt;br /&gt;
kernel/fs/erofs&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/mkinitfs.conf|...&lt;br /&gt;
features{{=}}&amp;quot;... erofs my-custom-script veritysetup&amp;quot;&lt;br /&gt;
MODULES{{=}}&amp;quot;veritysetup erofs&amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
{{cat| /etc/scripts/my-custom-script.sh|&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
mount /dev/mapper/root /root&lt;br /&gt;
mount /root/var/root/erofs.img /sysroot&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Then just do:&lt;br /&gt;
{{cmd| apk add secureboot-hook gummiboot gummiboot-efistub efibootmgr kernel-hooks secureboot-hook}}&lt;br /&gt;
&lt;br /&gt;
{{tip|To make sure initramfs has the scripts needed, do:&lt;br /&gt;
{{cmd|mkinitfs -c /etc/mkinitfs/mkinitfs.conf -b / $(uname -r)}}&lt;br /&gt;
Decompress:&lt;br /&gt;
{{cmd|mkdir /tmp/initramfs&lt;br /&gt;
cd /tmp/initramfs&lt;br /&gt;
&amp;lt;nowiki&amp;gt;zcat /boot/initramfs-$KERNEL | cpio -idmv&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Test if &amp;quot;init&amp;quot; works by just executing it and see how it runs:&lt;br /&gt;
{{cmd|./init}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Working with Dracut ====&lt;br /&gt;
&lt;br /&gt;
Remember, mount your &amp;lt;code&amp;gt;$ROOT_PARTITION&amp;lt;/code&amp;gt; as read only (assuming you use EXT4, if using ERO-FS or SquashFS, ignore this), since any changes will cause DM-Verity to detect it as &amp;quot;corrupt&amp;quot;&lt;br /&gt;
&lt;br /&gt;
{{warning| The following guide was done with FULL disk encryption, so this might not work perfectly on Non encrypted disk setup, also done on UEFI using gummiboot (now called systemd-boot - yes, systemd-boot is a separate project from the systemd init system) EFIStub and generating a UKI (Unified Kernel Image)}}&lt;br /&gt;
&lt;br /&gt;
===== Install basic stuff: =====&lt;br /&gt;
&lt;br /&gt;
{{cmd| apk add dracut dracut-core cryptsetup gummiboot gummiboot-efistub tpm2-tools clevis tpm2-tss tpm2-tss-tcti-device}}&lt;br /&gt;
&lt;br /&gt;
===== Using Clevis for TPM =====&lt;br /&gt;
&lt;br /&gt;
{{cmd| clevis luks bind -d /$ENCRYPTED_ROOT_PARTITION tpm2 &#039;{&amp;quot;pcr_ids&amp;quot;:&amp;quot;1,7&amp;quot;}&#039;}}&lt;br /&gt;
Input LUKS passphrase, remember that yes now it has tpm, but if possible remove old luks passphrase and use keyfile or different passphrase to unlock because tpm is better, and so if your computer breaks, you won&#039;t be locked out of your data!&lt;br /&gt;
&lt;br /&gt;
===== Create a new partition for your DM-Verity: =====&lt;br /&gt;
&lt;br /&gt;
Replace /dev/sdX with your actual device name.&lt;br /&gt;
{{cmd| sudo fdisk /dev/sdX}}&lt;br /&gt;
&lt;br /&gt;
Once in the fdisk interface:&lt;br /&gt;
# Press n to create a new partition&lt;br /&gt;
# Choose p for primary partition&lt;br /&gt;
# Select the partition number (e.g., 4)&lt;br /&gt;
# For the first sector, press Enter to use the default&lt;br /&gt;
# For the last sector, calculate 10% of your root partition size and use +SIZE format. For example, if your root partition is 100GB, enter +10G&lt;br /&gt;
# Press t to change the partition type&lt;br /&gt;
# Enter the partition number you just created&lt;br /&gt;
# Type 8e for Linux LVM type (closest to verity)&lt;br /&gt;
# Press w to write changes and exit&lt;br /&gt;
&lt;br /&gt;
===== Adding custom lines for full disk decryption =====&lt;br /&gt;
&lt;br /&gt;
Edit &amp;quot;&amp;lt;code&amp;gt;/usr/lib/dracut/modules.d/90crypt/cryptroot-ask.sh&amp;lt;/code&amp;gt;&amp;quot; and add these lines right BEFORE &amp;quot;&amp;lt;code&amp;gt;exit 0&amp;lt;/code&amp;gt;&amp;quot; (add your &amp;lt;code&amp;gt;$ROOT_PARTITION&amp;lt;/code&amp;gt; directory and &amp;lt;code&amp;gt;$VERITY_PARTITION&amp;lt;/code&amp;gt; directory):&lt;br /&gt;
&lt;br /&gt;
{{cat| /usr/lib/dracut/modules.d/90crypt/cryptroot-ask.sh|...&lt;br /&gt;
### DM-Verity&lt;br /&gt;
mount /dev/mapper/$ROOT_PARTITION /var/tmp&lt;br /&gt;
cryptsetup open --key-file /var/tmp/$KEYFILE_DIR /dev/$VERITY_PARTITION $VERITY_DM_NAME&lt;br /&gt;
umount /var/tmp&lt;br /&gt;
veritysetup open /dev/$ROOT_PARTITION /dev/$VERITY_PARTITION $(cat /usr/lib/dracut/roothash.txt)&lt;br /&gt;
###&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
===== Generating an EFIStub with Dracut + DM-Verity =====&lt;br /&gt;
&lt;br /&gt;
To setup DM-Verity (borrowed from [https://wiki.archlinux.org/title/Dm-verity Arch Linux Wiki]):&lt;br /&gt;
&lt;br /&gt;
{{cmd| veritysetup format /dev/$ROOT_PARTITION /dev/$VERITY_PARTITION | grep Root | cut -f2 &amp;gt;&amp;gt; /usr/lib/dracut/roothash.txt}}&lt;br /&gt;
&lt;br /&gt;
/etc/dracut.conf (put whatever your boot parameters are in &amp;quot;&amp;lt;code&amp;gt;kernel_cmdline&amp;lt;/code&amp;gt;&amp;quot;):&lt;br /&gt;
&lt;br /&gt;
{{cat| /etc/dracut.conf|...&lt;br /&gt;
kernel_cmdline{{=}}&amp;quot;&amp;quot;&lt;br /&gt;
add_dracutdrivers+{{=}}&amp;quot; busybox crypt crypt-gpg dm rootfs-block kernel-modules kernel-modules-extra tpm2-tss &amp;quot;&lt;br /&gt;
/etc/dracut.conf.d/secureboot.conf&lt;br /&gt;
&lt;br /&gt;
# Do the 3 lines below this if you have your own secureboot keys, or want to use secureboot:&lt;br /&gt;
uefi_secureboot_cert{{=}}&amp;quot;/$SECUREBOOT_KEYS_DIR/db.crt&amp;quot;&lt;br /&gt;
uefi_secureboot_key{{=}}&amp;quot;/$SECUREBOOT_KEYS_DIR/db.key&amp;quot;&lt;br /&gt;
/etc/dracut.conf.d/files.conf&lt;br /&gt;
&lt;br /&gt;
# This is what will import veritysetup binary file into dracut initramfs&lt;br /&gt;
install_items+{{=}}&amp;quot; /sbin/veritysetup &amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
Finally, generate UKI using dracut (replace &amp;lt;code&amp;gt;6.X.X-X-lts&amp;lt;/code&amp;gt; with your kernel &amp;lt;code&amp;gt;$VERSION&amp;lt;/code&amp;gt;) (also replace &amp;lt;code&amp;gt;/boot/efi/EFI/Linux/alpine-linux.efi&amp;lt;/code&amp;gt; with your mount efi partition):&lt;br /&gt;
&lt;br /&gt;
{{cmd| export DRACUT_KMODDIR_OVERRIDE{{=}}1}}&lt;br /&gt;
{{cmd| dracut --include /usr/lib/dracut/roothash.txt /usr/lib/dracut/roothash.txt --host-only --kernel-image /boot/vmlinuz-lts --kmoddir /lib/modules/6.X.X-X-lts --kver 6.X.X-X-lts --uefi --uefi-stub /usr/lib/gummiboot/linuxx64.efi.stub --force --compress lz4 /boot/efi/EFI/Linux/alpine-linux.efi /boot/efi/EFI/Linux/alpine-linux.efi}}&lt;br /&gt;
{{cmd| efibootmgr --create --disk /dev/$EFI_PARTITION --part 1 --label alpine-linux --loader EFI/Linux/alpine-linux.efi}}&lt;br /&gt;
&lt;br /&gt;
Unfortunately, using the default Alpine Linux kernel (&amp;lt;code&amp;gt;linux-lts&amp;lt;/code&amp;gt;) didn&#039;t work so download another distributions root system (like debians or devuan), and replace &amp;lt;code&amp;gt;/lib/modules/6.X.X-X-lts&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;/boot/vmlinuz-lts&amp;lt;/code&amp;gt; with anothers distributions kernel modules and kernel image (Or consider compiling your [https://wiki.alpinelinux.org/wiki/Hardened_linux own linux-hardened kernel] [11]).&lt;br /&gt;
&lt;br /&gt;
{{tip| If you want to test if DM-Verity fully works, change the &amp;lt;code&amp;gt;$ROOT_PARTITION&amp;lt;/code&amp;gt;&#039;s files and it should say it is &amp;quot;corrupt&amp;quot;, and not continue the boot process (only if you use EXT4).}}&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
==== Root of Trust/Chain of Trust ====&lt;br /&gt;
* [https://en.wikipedia.org/wiki/Chain_of_trust https://en.wikipedia.org/wiki/Chain_of_trust] [1]&lt;br /&gt;
==== Full disk encryption with LVM and LUKS (AlpineWiki): ====&lt;br /&gt;
* [https://wiki.alpinelinux.org/wiki/LVM_on_LUKS LVM_on_LUKS] [2]&lt;br /&gt;
==== Clevis Github ====&lt;br /&gt;
* [https://github.com/latchset/clevis?tab=readme-ov-file#pin-tpm2 https://github.com/latchset/clevis?tab=readme-ov-file#pin-tpm2] [3]&lt;br /&gt;
==== AppArmor Wiki (AlpineWiki) ====&lt;br /&gt;
* [https://wiki.alpinelinux.org/wiki/AppArmor AppArmor] [4]&lt;br /&gt;
==== GVisor ====&lt;br /&gt;
* [https://gvisor.dev/docs/user_guide/install/ https://gvisor.dev/docs/user_guide/install/] [5]&lt;br /&gt;
==== Gvisor Github stating docker is not a sandbox ====&lt;br /&gt;
* [https://github.com/google/gvisor?tab=readme-ov-file#why-does-gvisor-exist https://github.com/google/gvisor?tab=readme-ov-file#why-does-gvisor-exist] [6]&lt;br /&gt;
==== Android-13 Possibility of using ERO-FS: ====&lt;br /&gt;
* [https://pocketnow.com/erofs-android-13-explained/ https://pocketnow.com/erofs-android-13-explained/] [7]&lt;br /&gt;
==== DM-Verity (Arch Wiki): ====&lt;br /&gt;
* [https://wiki.archlinux.org/title/Dm-verity https://wiki.archlinux.org/title/Dm-verity] [8]&lt;br /&gt;
==== ERO-FS Github ====&lt;br /&gt;
* [https://github.com/erofs/erofs-utils https://github.com/erofs/erofs-utils] [9]&lt;br /&gt;
==== Dracut (Arch Wiki): ====&lt;br /&gt;
* [https://wiki.archlinux.org/title/Dracut https://wiki.archlinux.org/title/Dracut] [10]&lt;br /&gt;
==== Linux-Hardened Kernel (AlpineWiki): ====&lt;br /&gt;
* [https://wiki.alpinelinux.org/wiki/Hardened_linux Hardened_linux] [11]&lt;br /&gt;
==== My old post on how it worked ====&lt;br /&gt;
* [https://www.reddit.com/r/AlpineLinux/comments/15oibcc/comment/k1l7jv0/ https://www.reddit.com/r/AlpineLinux/comments/15oibcc/comment/k1l7jv0/] [12]&lt;br /&gt;
&lt;br /&gt;
[[Category:Security]] [[Category:Booting]]&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=DM-verity&amp;diff=28566</id>
		<title>DM-verity</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=DM-verity&amp;diff=28566"/>
		<updated>2024-12-23T23:19:29Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{todo| Add a non-initramfs dm-verity implementation, which should use kernel to do dm-verity checking instead of initramfs, which is better for embedded devices, and faster to boot (but hard to implement because of kernel customizations, might need to compile kernel again.)}}&lt;br /&gt;
&lt;br /&gt;
== Why DM-Verity? ==&lt;br /&gt;
Possibly you want to continue the RoT ([https://en.wikipedia.org/wiki/Chain_of_trust Root of Trust] [1]) - from the hardware (Hardware TPM as Root of Trust, which ensures only the hardware with the correct secret cryptographic key in the TPM to decrypt the disk/file encryption) -&amp;gt; secure boot (Secure Boot to only run approved signed EFIStub/signed Bootloader) -&amp;gt; &amp;lt;u&amp;gt;To NOW DM-Verity rootfs&amp;lt;/u&amp;gt; (which ensures your root-image/root-parition has not been tampered with) -&amp;gt; Mandatory Access Control (AppArmor or SELinux - SELinux is disabled on default linux-lts btw) -&amp;gt; Sandboxed/Virtual-Machined Applications.&lt;br /&gt;
&lt;br /&gt;
=== What&#039;s the difference between me just setting the root partition as read-only (basically just an Immutable Root Partition) vs this? ===&lt;br /&gt;
DM-Verity COMPLETELY disallows modifying any files in the root-partition/root-image, or even disallow a part of a root-image/root-partition (the root-image/root-partition needs to be INTACT and match the signed cryptography verified by DM-Verity on a different partition), and with this consideration, you may use ERO-FS or SquashFS to generate Read-Only Root-Paritition Images. If you set your EXT4 file system to writable, and DM-Verity were to use it, it would be seen as &amp;quot;corrupted&amp;quot; and not boot anymore, because even just ONE tiny data change to the root image/partition would render it &amp;quot;corrupted&amp;quot;. This is the same technology used in Android and Chrome OS Devices. Also related to use in A/B root, also used by Fedora.&lt;br /&gt;
&lt;br /&gt;
{{tip| To keep the security reasonable, you would ideally want to work on the whole RoT, if not then anybody else can attack the non-verifed boot process that ISN&#039;T the root-partition/root-image that is enforced by DM-Verity.&lt;br /&gt;
* This following guide will use dracut to make a signed secureboot-able EFIStub.&lt;br /&gt;
* If you haven&#039;t, you may follow [https://wiki.alpinelinux.org/wiki/LVM_on_LUKS the Alpine Linux disk encryption setup] [2] with DM-Crypt LUKS and LVM&lt;br /&gt;
* You may choose to decrypt the image with TPM when generating with Dracut Modules with &amp;lt;code&amp;gt;add_dracutdrivers+{{=}}&amp;quot; ... tpm2-tss ... &amp;quot;&amp;lt;/code&amp;gt; and [https://github.com/latchset/clevis?tab{{=}}readme-ov-file#pin-tpm2 Clevis] [3]&lt;br /&gt;
* Apply AppArmor using [https://wiki.alpinelinux.org/wiki/AppArmor Alpine Linux AppArmor Wiki] (Docker does use AppArmor already, but you may apply an AppArmor profile on any application that should not have access to specific directories (AppArmor is a PATH based MAC)) [4]&lt;br /&gt;
* Use [https://gvisor.dev/docs/user_guide/install/ GVisor] [5] with Docker ([https://github.com/google/gvisor?tab{{=}}readme-ov-file#why-does-gvisor-exist Docker is NOT a sandbox] [6] (Because docker uses native kernel compared to Gvisor using its own kernel reimplementation)) for sandboxing on servers}}&lt;br /&gt;
&lt;br /&gt;
=== What is ERO-FS? ===&lt;br /&gt;
[https://pocketnow.com/erofs-android-13-explained/ Google thought about implementing ERO-FS with DM-Verity] [7]. Google was reported to be using it in Android 13, and ERO-FS is an excellent and fast compressed read-only filesystem.&lt;br /&gt;
&lt;br /&gt;
Here is an excerpt about &amp;lt;code&amp;gt;mkfs.erofs&amp;lt;/code&amp;gt; on [[https://wiki.archlinux.org/title/Dm-verity Arch Linux Wiki]] [8]:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039; mkfs.erofs(1) offers an attractive alternative to ext4 or squashfs on the root partition. EROFS, like squashfs, does not allow writes by design and has better performance in many cases than comparable filesystems on flash and solid-state media. It uses lz4 compression by default and was designed for Android phones by Huawei, which make extensive use of dm-verity. &#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Installing ===&lt;br /&gt;
&lt;br /&gt;
==== Working with ERO-FS ====&lt;br /&gt;
&lt;br /&gt;
{{warning| This wiki will be using Alpine Linux Edge Version. (Alpine Linux Non-Edge Versions may not contain these packages in the following rest of the wiki page) (Use Alpine Linux Edge Testing Repository in &amp;lt;code&amp;gt;/etc/apk/repositories&amp;lt;/code&amp;gt; as well)}}&lt;br /&gt;
&lt;br /&gt;
{{note| To not be confused, ERO-FS generates a &amp;quot;root image&amp;quot;, but you can replace the words &amp;quot;root partition&amp;quot; with &amp;quot;root image&amp;quot; and vice versa.}}&lt;br /&gt;
&lt;br /&gt;
First, some considerations, you may use a strictly READ-ONLY file system, such as SquashFS or ERO-FS, this wiki will be using ERO-FS (if you use a custom kernel, make sure it supports a file system such as ERO-FS, the default linux-lts does). [[https://github.com/erofs/erofs-utils ERO-FS Github]] [9] contains some information about how to compress and make your own read-only root image.&lt;br /&gt;
&lt;br /&gt;
{{cmd| $ apk install erofs-utils}}&lt;br /&gt;
{{cmd| $ mkdir image &amp;amp;&amp;amp; cd image }}&lt;br /&gt;
{{cmd| $ wget https://dl-cdn.alpinelinux.org/alpine/v3.21/releases/x86_64/alpine-minirootfs-3.21.0-x86_64.tar.gz}}&lt;br /&gt;
{{cmd| $ tar -xvf alpine-minirootfs-3.21.0-x86_64.tar.gz &amp;amp;&amp;amp; rm alpine-minirootfs-3.21.0-x86_64.tar.gz}}&lt;br /&gt;
Command below will generate an ERO-FS Image compressed with lz4 as ./erofs.img (erofs.img would be the root-partition file to use for dracut)&lt;br /&gt;
{{cmd| $ cd .. &amp;amp;&amp;amp; mkfs.erofs -zlz4hc erofs.img ./image}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Working with mkinitfs/kernel-hooks/secureboot-hooks ====&lt;br /&gt;
{{todo| wip}}&lt;br /&gt;
&lt;br /&gt;
Using mkinitfs, it is possible to force veritysetup in initramfs generation. It is recommended to make a chroot or docker so you don&#039;t mess with your system files, and by adding these files:&lt;br /&gt;
&lt;br /&gt;
{{todo| The init script is too big to put in wiki, I just acquired it from initramfs generation and decompression (read the tip below)}}&lt;br /&gt;
{{note| the APK package &amp;quot;cryptsetup&amp;quot; comes with veritysetup&lt;br /&gt;
{{cmd| apk add cryptsetup}}&lt;br /&gt;
}}&lt;br /&gt;
{{note| make sure the chroot has a linux-kernel}}&lt;br /&gt;
&lt;br /&gt;
Edit /sbin/mkinitfs (put &amp;quot;# Copy custom init&amp;quot; before &amp;quot;# copy modloop signature&amp;quot;):&lt;br /&gt;
{{cat| /etc/mkinitfs|...&lt;br /&gt;
        # Copy custom init &lt;br /&gt;
        cp /initramfs/init &amp;quot;$tmpdir&amp;quot;/init &lt;br /&gt;
        &lt;br /&gt;
        # copy modloop signature&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
PUT &amp;quot;# Call custom script&amp;quot; before &amp;quot;# switch over to new root&amp;quot;&lt;br /&gt;
{{cat| /initramfs/init|...&lt;br /&gt;
# Call custom script&lt;br /&gt;
/etc/scripts/my-custom-script.sh&lt;br /&gt;
&lt;br /&gt;
# switch over to new root&lt;br /&gt;
...&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/my-custom-script.files|&lt;br /&gt;
/etc/scripts/my-custom-script.sh&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/veritysetup.files|&lt;br /&gt;
/sbin/veritysetup&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/veritysetup.modules|&lt;br /&gt;
kernel/drivers/md/dm-verity.ko*&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/erofs.modules|&lt;br /&gt;
kernel/fs/erofs&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/mkinitfs.conf|...&lt;br /&gt;
features{{=}}&amp;quot;... erofs my-custom-script veritysetup&amp;quot;&lt;br /&gt;
MODULES{{=}}&amp;quot;veritysetup erofs&amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
{{cat| /etc/scripts/my-custom-script.sh|&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
mount /dev/mapper/root /root&lt;br /&gt;
mount /root/var/root/erofs.img /sysroot&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Then just do:&lt;br /&gt;
{{cmd| apk add secureboot-hook gummiboot gummiboot-efistub efibootmgr kernel-hooks secureboot-hook}}&lt;br /&gt;
&lt;br /&gt;
{{tip|To make sure initramfs has the scripts needed, do:&lt;br /&gt;
{{cmd|mkinitfs -c /etc/mkinitfs/mkinitfs.conf -b / $(uname -r)}}&lt;br /&gt;
Decompress:&lt;br /&gt;
{{cmd|mkdir /tmp/initramfs&lt;br /&gt;
cd /tmp/initramfs&lt;br /&gt;
&amp;lt;nowiki&amp;gt;zcat /boot/initramfs-$KERNEL | cpio -idmv&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Working with Dracut ====&lt;br /&gt;
&lt;br /&gt;
Remember, mount your &amp;lt;code&amp;gt;$ROOT_PARTITION&amp;lt;/code&amp;gt; as read only (assuming you use EXT4, if using ERO-FS or SquashFS, ignore this), since any changes will cause DM-Verity to detect it as &amp;quot;corrupt&amp;quot;&lt;br /&gt;
&lt;br /&gt;
{{warning| The following guide was done with FULL disk encryption, so this might not work perfectly on Non encrypted disk setup, also done on UEFI using gummiboot (now called systemd-boot - yes, systemd-boot is a separate project from the systemd init system) EFIStub and generating a UKI (Unified Kernel Image)}}&lt;br /&gt;
&lt;br /&gt;
===== Install basic stuff: =====&lt;br /&gt;
&lt;br /&gt;
{{cmd| apk add dracut dracut-core cryptsetup gummiboot gummiboot-efistub tpm2-tools clevis tpm2-tss tpm2-tss-tcti-device}}&lt;br /&gt;
&lt;br /&gt;
===== Using Clevis for TPM =====&lt;br /&gt;
&lt;br /&gt;
{{cmd| clevis luks bind -d /$ENCRYPTED_ROOT_PARTITION tpm2 &#039;{&amp;quot;pcr_ids&amp;quot;:&amp;quot;1,7&amp;quot;}&#039;}}&lt;br /&gt;
Input LUKS passphrase, remember that yes now it has tpm, but if possible remove old luks passphrase and use keyfile or different passphrase to unlock because tpm is better, and so if your computer breaks, you won&#039;t be locked out of your data!&lt;br /&gt;
&lt;br /&gt;
===== Create a new partition for your DM-Verity: =====&lt;br /&gt;
&lt;br /&gt;
Replace /dev/sdX with your actual device name.&lt;br /&gt;
{{cmd| sudo fdisk /dev/sdX}}&lt;br /&gt;
&lt;br /&gt;
Once in the fdisk interface:&lt;br /&gt;
# Press n to create a new partition&lt;br /&gt;
# Choose p for primary partition&lt;br /&gt;
# Select the partition number (e.g., 4)&lt;br /&gt;
# For the first sector, press Enter to use the default&lt;br /&gt;
# For the last sector, calculate 10% of your root partition size and use +SIZE format. For example, if your root partition is 100GB, enter +10G&lt;br /&gt;
# Press t to change the partition type&lt;br /&gt;
# Enter the partition number you just created&lt;br /&gt;
# Type 8e for Linux LVM type (closest to verity)&lt;br /&gt;
# Press w to write changes and exit&lt;br /&gt;
&lt;br /&gt;
===== Adding custom lines for full disk decryption =====&lt;br /&gt;
&lt;br /&gt;
Edit &amp;quot;&amp;lt;code&amp;gt;/usr/lib/dracut/modules.d/90crypt/cryptroot-ask.sh&amp;lt;/code&amp;gt;&amp;quot; and add these lines right BEFORE &amp;quot;&amp;lt;code&amp;gt;exit 0&amp;lt;/code&amp;gt;&amp;quot; (add your &amp;lt;code&amp;gt;$ROOT_PARTITION&amp;lt;/code&amp;gt; directory and &amp;lt;code&amp;gt;$VERITY_PARTITION&amp;lt;/code&amp;gt; directory):&lt;br /&gt;
&lt;br /&gt;
{{cat| /usr/lib/dracut/modules.d/90crypt/cryptroot-ask.sh|...&lt;br /&gt;
### DM-Verity&lt;br /&gt;
mount /dev/mapper/$ROOT_PARTITION /var/tmp&lt;br /&gt;
cryptsetup open --key-file /var/tmp/$KEYFILE_DIR /dev/$VERITY_PARTITION $VERITY_DM_NAME&lt;br /&gt;
umount /var/tmp&lt;br /&gt;
veritysetup open /dev/$ROOT_PARTITION /dev/$VERITY_PARTITION $(cat /usr/lib/dracut/roothash.txt)&lt;br /&gt;
###&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
===== Generating an EFIStub with Dracut + DM-Verity =====&lt;br /&gt;
&lt;br /&gt;
To setup DM-Verity (borrowed from [https://wiki.archlinux.org/title/Dm-verity Arch Linux Wiki]):&lt;br /&gt;
&lt;br /&gt;
{{cmd| veritysetup format /dev/$ROOT_PARTITION /dev/$VERITY_PARTITION | grep Root | cut -f2 &amp;gt;&amp;gt; /usr/lib/dracut/roothash.txt}}&lt;br /&gt;
&lt;br /&gt;
/etc/dracut.conf (put whatever your boot parameters are in &amp;quot;&amp;lt;code&amp;gt;kernel_cmdline&amp;lt;/code&amp;gt;&amp;quot;):&lt;br /&gt;
&lt;br /&gt;
{{cat| /etc/dracut.conf|...&lt;br /&gt;
kernel_cmdline{{=}}&amp;quot;&amp;quot;&lt;br /&gt;
add_dracutdrivers+{{=}}&amp;quot; busybox crypt crypt-gpg dm rootfs-block kernel-modules kernel-modules-extra tpm2-tss &amp;quot;&lt;br /&gt;
/etc/dracut.conf.d/secureboot.conf&lt;br /&gt;
&lt;br /&gt;
# Do the 3 lines below this if you have your own secureboot keys, or want to use secureboot:&lt;br /&gt;
uefi_secureboot_cert{{=}}&amp;quot;/$SECUREBOOT_KEYS_DIR/db.crt&amp;quot;&lt;br /&gt;
uefi_secureboot_key{{=}}&amp;quot;/$SECUREBOOT_KEYS_DIR/db.key&amp;quot;&lt;br /&gt;
/etc/dracut.conf.d/files.conf&lt;br /&gt;
&lt;br /&gt;
# This is what will import veritysetup binary file into dracut initramfs&lt;br /&gt;
install_items+{{=}}&amp;quot; /sbin/veritysetup &amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
Finally, generate UKI using dracut (replace &amp;lt;code&amp;gt;6.X.X-X-lts&amp;lt;/code&amp;gt; with your kernel &amp;lt;code&amp;gt;$VERSION&amp;lt;/code&amp;gt;) (also replace &amp;lt;code&amp;gt;/boot/efi/EFI/Linux/alpine-linux.efi&amp;lt;/code&amp;gt; with your mount efi partition):&lt;br /&gt;
&lt;br /&gt;
{{cmd| export DRACUT_KMODDIR_OVERRIDE{{=}}1}}&lt;br /&gt;
{{cmd| dracut --include /usr/lib/dracut/roothash.txt /usr/lib/dracut/roothash.txt --host-only --kernel-image /boot/vmlinuz-lts --kmoddir /lib/modules/6.X.X-X-lts --kver 6.X.X-X-lts --uefi --uefi-stub /usr/lib/gummiboot/linuxx64.efi.stub --force --compress lz4 /boot/efi/EFI/Linux/alpine-linux.efi /boot/efi/EFI/Linux/alpine-linux.efi}}&lt;br /&gt;
{{cmd| efibootmgr --create --disk /dev/$EFI_PARTITION --part 1 --label alpine-linux --loader EFI/Linux/alpine-linux.efi}}&lt;br /&gt;
&lt;br /&gt;
Unfortunately, using the default Alpine Linux kernel (&amp;lt;code&amp;gt;linux-lts&amp;lt;/code&amp;gt;) didn&#039;t work so download another distributions root system (like debians or devuan), and replace &amp;lt;code&amp;gt;/lib/modules/6.X.X-X-lts&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;/boot/vmlinuz-lts&amp;lt;/code&amp;gt; with anothers distributions kernel modules and kernel image (Or consider compiling your [https://wiki.alpinelinux.org/wiki/Hardened_linux own linux-hardened kernel] [11]).&lt;br /&gt;
&lt;br /&gt;
{{tip| If you want to test if DM-Verity fully works, change the &amp;lt;code&amp;gt;$ROOT_PARTITION&amp;lt;/code&amp;gt;&#039;s files and it should say it is &amp;quot;corrupt&amp;quot;, and not continue the boot process (only if you use EXT4).}}&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
==== Root of Trust/Chain of Trust ====&lt;br /&gt;
* [https://en.wikipedia.org/wiki/Chain_of_trust https://en.wikipedia.org/wiki/Chain_of_trust] [1]&lt;br /&gt;
==== Full disk encryption with LVM and LUKS (AlpineWiki): ====&lt;br /&gt;
* [https://wiki.alpinelinux.org/wiki/LVM_on_LUKS LVM_on_LUKS] [2]&lt;br /&gt;
==== Clevis Github ====&lt;br /&gt;
* [https://github.com/latchset/clevis?tab=readme-ov-file#pin-tpm2 https://github.com/latchset/clevis?tab=readme-ov-file#pin-tpm2] [3]&lt;br /&gt;
==== AppArmor Wiki (AlpineWiki) ====&lt;br /&gt;
* [https://wiki.alpinelinux.org/wiki/AppArmor AppArmor] [4]&lt;br /&gt;
==== GVisor ====&lt;br /&gt;
* [https://gvisor.dev/docs/user_guide/install/ https://gvisor.dev/docs/user_guide/install/] [5]&lt;br /&gt;
==== Gvisor Github stating docker is not a sandbox ====&lt;br /&gt;
* [https://github.com/google/gvisor?tab=readme-ov-file#why-does-gvisor-exist https://github.com/google/gvisor?tab=readme-ov-file#why-does-gvisor-exist] [6]&lt;br /&gt;
==== Android-13 Possibility of using ERO-FS: ====&lt;br /&gt;
* [https://pocketnow.com/erofs-android-13-explained/ https://pocketnow.com/erofs-android-13-explained/] [7]&lt;br /&gt;
==== DM-Verity (Arch Wiki): ====&lt;br /&gt;
* [https://wiki.archlinux.org/title/Dm-verity https://wiki.archlinux.org/title/Dm-verity] [8]&lt;br /&gt;
==== ERO-FS Github ====&lt;br /&gt;
* [https://github.com/erofs/erofs-utils https://github.com/erofs/erofs-utils] [9]&lt;br /&gt;
==== Dracut (Arch Wiki): ====&lt;br /&gt;
* [https://wiki.archlinux.org/title/Dracut https://wiki.archlinux.org/title/Dracut] [10]&lt;br /&gt;
==== Linux-Hardened Kernel (AlpineWiki): ====&lt;br /&gt;
* [https://wiki.alpinelinux.org/wiki/Hardened_linux Hardened_linux] [11]&lt;br /&gt;
==== My old post on how it worked ====&lt;br /&gt;
* [https://www.reddit.com/r/AlpineLinux/comments/15oibcc/comment/k1l7jv0/ https://www.reddit.com/r/AlpineLinux/comments/15oibcc/comment/k1l7jv0/] [12]&lt;br /&gt;
&lt;br /&gt;
[[Category:Security]] [[Category:Booting]]&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=DM-verity&amp;diff=28565</id>
		<title>DM-verity</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=DM-verity&amp;diff=28565"/>
		<updated>2024-12-23T20:47:07Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{todo| Add a non-initramfs dm-verity implementation, which should use kernel to do dm-verity checking instead of initramfs, which is better for embedded devices, and faster to boot (but hard to implement because of kernel customizations, might need to compile kernel again.)}}&lt;br /&gt;
&lt;br /&gt;
== Why DM-Verity? ==&lt;br /&gt;
Possibly you want to continue the RoT ([https://en.wikipedia.org/wiki/Chain_of_trust Root of Trust] [1]) - from the hardware (Hardware TPM as Root of Trust, which ensures only the hardware with the correct secret cryptographic key in the TPM to decrypt the disk/file encryption) -&amp;gt; secure boot (Secure Boot to only run approved signed EFIStub/signed Bootloader) -&amp;gt; &amp;lt;u&amp;gt;To NOW DM-Verity rootfs&amp;lt;/u&amp;gt; (which ensures your root-image/root-parition has not been tampered with) -&amp;gt; Mandatory Access Control (AppArmor or SELinux - SELinux is disabled on default linux-lts btw) -&amp;gt; Sandboxed/Virtual-Machined Applications.&lt;br /&gt;
&lt;br /&gt;
=== What&#039;s the difference between me just setting the root partition as read-only (basically just an Immutable Root Partition) vs this? ===&lt;br /&gt;
DM-Verity COMPLETELY disallows modifying any files in the root-partition/root-image, or even disallow a part of a root-image/root-partition (the root-image/root-partition needs to be INTACT and match the signed cryptography verified by DM-Verity on a different partition), and with this consideration, you may use ERO-FS or SquashFS to generate Read-Only Root-Paritition Images. If you set your EXT4 file system to writable, and DM-Verity were to use it, it would be seen as &amp;quot;corrupted&amp;quot; and not boot anymore, because even just ONE tiny data change to the root image/partition would render it &amp;quot;corrupted&amp;quot;. This is the same technology used in Android and Chrome OS Devices. Also related to use in A/B root, also used by Fedora.&lt;br /&gt;
&lt;br /&gt;
{{tip| To keep the security reasonable, you would ideally want to work on the whole RoT, if not then anybody else can attack the non-verifed boot process that ISN&#039;T the root-partition/root-image that is enforced by DM-Verity.&lt;br /&gt;
* This following guide will use dracut to make a signed secureboot-able EFIStub.&lt;br /&gt;
* If you haven&#039;t, you may follow [https://wiki.alpinelinux.org/wiki/LVM_on_LUKS the Alpine Linux disk encryption setup] [2] with DM-Crypt LUKS and LVM&lt;br /&gt;
* You may choose to decrypt the image with TPM when generating with Dracut Modules with &amp;lt;code&amp;gt;add_dracutdrivers+{{=}}&amp;quot; ... tpm2-tss ... &amp;quot;&amp;lt;/code&amp;gt; and [https://github.com/latchset/clevis?tab{{=}}readme-ov-file#pin-tpm2 Clevis] [3]&lt;br /&gt;
* Apply AppArmor using [https://wiki.alpinelinux.org/wiki/AppArmor Alpine Linux AppArmor Wiki] (Docker does use AppArmor already, but you may apply an AppArmor profile on any application that should not have access to specific directories (AppArmor is a PATH based MAC)) [4]&lt;br /&gt;
* Use [https://gvisor.dev/docs/user_guide/install/ GVisor] [5] with Docker ([https://github.com/google/gvisor?tab{{=}}readme-ov-file#why-does-gvisor-exist Docker is NOT a sandbox] [6] (Because docker uses native kernel compared to Gvisor using its own kernel reimplementation)) for sandboxing on servers}}&lt;br /&gt;
&lt;br /&gt;
=== What is ERO-FS? ===&lt;br /&gt;
[https://pocketnow.com/erofs-android-13-explained/ Google thought about implementing ERO-FS with DM-Verity] [7]. Google was reported to be using it in Android 13, and ERO-FS is an excellent and fast compressed read-only filesystem.&lt;br /&gt;
&lt;br /&gt;
Here is an excerpt about &amp;lt;code&amp;gt;mkfs.erofs&amp;lt;/code&amp;gt; on [[https://wiki.archlinux.org/title/Dm-verity Arch Linux Wiki]] [8]:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039; mkfs.erofs(1) offers an attractive alternative to ext4 or squashfs on the root partition. EROFS, like squashfs, does not allow writes by design and has better performance in many cases than comparable filesystems on flash and solid-state media. It uses lz4 compression by default and was designed for Android phones by Huawei, which make extensive use of dm-verity. &#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Installing ===&lt;br /&gt;
&lt;br /&gt;
==== Working with ERO-FS ====&lt;br /&gt;
&lt;br /&gt;
{{warning| This wiki will be using Alpine Linux Edge Version. (Alpine Linux Non-Edge Versions may not contain these packages in the following rest of the wiki page) (Use Alpine Linux Edge Testing Repository in &amp;lt;code&amp;gt;/etc/apk/repositories&amp;lt;/code&amp;gt; as well)}}&lt;br /&gt;
&lt;br /&gt;
{{note| To not be confused, ERO-FS generates a &amp;quot;root image&amp;quot;, but you can replace the words &amp;quot;root partition&amp;quot; with &amp;quot;root image&amp;quot; and vice versa.}}&lt;br /&gt;
&lt;br /&gt;
First, some considerations, you may use a strictly READ-ONLY file system, such as SquashFS or ERO-FS, this wiki will be using ERO-FS (if you use a custom kernel, make sure it supports a file system such as ERO-FS, the default linux-lts does). [[https://github.com/erofs/erofs-utils ERO-FS Github]] [9] contains some information about how to compress and make your own read-only root image.&lt;br /&gt;
&lt;br /&gt;
{{cmd| $ apk install erofs-utils}}&lt;br /&gt;
{{cmd| $ mkdir image &amp;amp;&amp;amp; cd image }}&lt;br /&gt;
{{cmd| $ wget https://dl-cdn.alpinelinux.org/alpine/v3.21/releases/x86_64/alpine-minirootfs-3.21.0-x86_64.tar.gz}}&lt;br /&gt;
{{cmd| $ tar -xvf alpine-minirootfs-3.21.0-x86_64.tar.gz &amp;amp;&amp;amp; rm alpine-minirootfs-3.21.0-x86_64.tar.gz}}&lt;br /&gt;
Command below will generate an ERO-FS Image compressed with lz4 as ./erofs.img (erofs.img would be the root-partition file to use for dracut)&lt;br /&gt;
{{cmd| $ cd .. &amp;amp;&amp;amp; mkfs.erofs -zlz4hc erofs.img ./image}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Working with mkinitfs/kernel-hooks/secureboot-hooks ====&lt;br /&gt;
{{todo| wip}}&lt;br /&gt;
&lt;br /&gt;
Using mkinitfs, it is possible to force veritysetup in initramfs generation. It is recommended to make a chroot or docker so you don&#039;t mess with your system files, and by adding these files:&lt;br /&gt;
&lt;br /&gt;
{{todo| The init script is too big to put in wiki, I just acquired it from initramfs generation and decompression (read the tip below)}}&lt;br /&gt;
{{note| the APK package &amp;quot;cryptsetup&amp;quot; comes with veritysetup&lt;br /&gt;
{{cmd| apk add cryptsetup}}&lt;br /&gt;
}}&lt;br /&gt;
{{note| make sure the chroot has a linux-kernel}}&lt;br /&gt;
&lt;br /&gt;
Edit /sbin/mkinitfs (put &amp;quot;# Copy custom init&amp;quot; before &amp;quot;# copy modloop signature&amp;quot;):&lt;br /&gt;
{{cat| /etc/mkinitfs|...&lt;br /&gt;
        # Copy custom init &lt;br /&gt;
        cp /initramfs/init &amp;quot;$tmpdir&amp;quot;/init &lt;br /&gt;
        &lt;br /&gt;
        # copy modloop signature&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
PUT &amp;quot;# Call custom script&amp;quot; before &amp;quot;# switch over to new root&amp;quot;&lt;br /&gt;
{{cat| /initramfs/init|...&lt;br /&gt;
# Call custom script&lt;br /&gt;
/etc/scripts/my-custom-script.sh&lt;br /&gt;
&lt;br /&gt;
# switch over to new root&lt;br /&gt;
...&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/my-custom-script.files|&lt;br /&gt;
/etc/scripts/my-custom-script.sh&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/veritysetup.files|&lt;br /&gt;
/sbin/veritysetup&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/veritysetup.modules|&lt;br /&gt;
kernel/drivers/md/dm-verity.ko*&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/erofs.modules|&lt;br /&gt;
kernel/fs/erofs&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/mkinitfs.conf|...&lt;br /&gt;
features{{=}}&amp;quot;... erofs my-custom-script&amp;quot;&lt;br /&gt;
MODULES{{=}}&amp;quot;veritysetup erofs&amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
{{cat| /etc/scripts/my-custom-script.sh|&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
mount /dev/mapper/root /root&lt;br /&gt;
mount /root/var/root/erofs.img /sysroot&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Then just do:&lt;br /&gt;
{{cmd| apk add secureboot-hook gummiboot gummiboot-efistub efibootmgr kernel-hooks secureboot-hook}}&lt;br /&gt;
&lt;br /&gt;
{{tip|To make sure initramfs has the scripts needed, do:&lt;br /&gt;
{{cmd|mkinitfs -c /etc/mkinitfs/mkinitfs.conf -b / $(uname -r)}}&lt;br /&gt;
Decompress:&lt;br /&gt;
{{cmd|mkdir /tmp/initramfs&lt;br /&gt;
cd /tmp/initramfs&lt;br /&gt;
&amp;lt;nowiki&amp;gt;zcat /boot/initramfs-$KERNEL | cpio -idmv&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Working with Dracut ====&lt;br /&gt;
&lt;br /&gt;
Remember, mount your &amp;lt;code&amp;gt;$ROOT_PARTITION&amp;lt;/code&amp;gt; as read only (assuming you use EXT4, if using ERO-FS or SquashFS, ignore this), since any changes will cause DM-Verity to detect it as &amp;quot;corrupt&amp;quot;&lt;br /&gt;
&lt;br /&gt;
{{warning| The following guide was done with FULL disk encryption, so this might not work perfectly on Non encrypted disk setup, also done on UEFI using gummiboot (now called systemd-boot - yes, systemd-boot is a separate project from the systemd init system) EFIStub and generating a UKI (Unified Kernel Image)}}&lt;br /&gt;
&lt;br /&gt;
===== Install basic stuff: =====&lt;br /&gt;
&lt;br /&gt;
{{cmd| apk add dracut dracut-core cryptsetup gummiboot gummiboot-efistub tpm2-tools clevis tpm2-tss tpm2-tss-tcti-device}}&lt;br /&gt;
&lt;br /&gt;
===== Using Clevis for TPM =====&lt;br /&gt;
&lt;br /&gt;
{{cmd| clevis luks bind -d /$ENCRYPTED_ROOT_PARTITION tpm2 &#039;{&amp;quot;pcr_ids&amp;quot;:&amp;quot;1,7&amp;quot;}&#039;}}&lt;br /&gt;
Input LUKS passphrase, remember that yes now it has tpm, but if possible remove old luks passphrase and use keyfile or different passphrase to unlock because tpm is better, and so if your computer breaks, you won&#039;t be locked out of your data!&lt;br /&gt;
&lt;br /&gt;
===== Create a new partition for your DM-Verity: =====&lt;br /&gt;
&lt;br /&gt;
Replace /dev/sdX with your actual device name.&lt;br /&gt;
{{cmd| sudo fdisk /dev/sdX}}&lt;br /&gt;
&lt;br /&gt;
Once in the fdisk interface:&lt;br /&gt;
# Press n to create a new partition&lt;br /&gt;
# Choose p for primary partition&lt;br /&gt;
# Select the partition number (e.g., 4)&lt;br /&gt;
# For the first sector, press Enter to use the default&lt;br /&gt;
# For the last sector, calculate 10% of your root partition size and use +SIZE format. For example, if your root partition is 100GB, enter +10G&lt;br /&gt;
# Press t to change the partition type&lt;br /&gt;
# Enter the partition number you just created&lt;br /&gt;
# Type 8e for Linux LVM type (closest to verity)&lt;br /&gt;
# Press w to write changes and exit&lt;br /&gt;
&lt;br /&gt;
===== Adding custom lines for full disk decryption =====&lt;br /&gt;
&lt;br /&gt;
Edit &amp;quot;&amp;lt;code&amp;gt;/usr/lib/dracut/modules.d/90crypt/cryptroot-ask.sh&amp;lt;/code&amp;gt;&amp;quot; and add these lines right BEFORE &amp;quot;&amp;lt;code&amp;gt;exit 0&amp;lt;/code&amp;gt;&amp;quot; (add your &amp;lt;code&amp;gt;$ROOT_PARTITION&amp;lt;/code&amp;gt; directory and &amp;lt;code&amp;gt;$VERITY_PARTITION&amp;lt;/code&amp;gt; directory):&lt;br /&gt;
&lt;br /&gt;
{{cat| /usr/lib/dracut/modules.d/90crypt/cryptroot-ask.sh|...&lt;br /&gt;
### DM-Verity&lt;br /&gt;
mount /dev/mapper/$ROOT_PARTITION /var/tmp&lt;br /&gt;
cryptsetup open --key-file /var/tmp/$KEYFILE_DIR /dev/$VERITY_PARTITION $VERITY_DM_NAME&lt;br /&gt;
umount /var/tmp&lt;br /&gt;
veritysetup open /dev/$ROOT_PARTITION /dev/$VERITY_PARTITION $(cat /usr/lib/dracut/roothash.txt)&lt;br /&gt;
###&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
===== Generating an EFIStub with Dracut + DM-Verity =====&lt;br /&gt;
&lt;br /&gt;
To setup DM-Verity (borrowed from [https://wiki.archlinux.org/title/Dm-verity Arch Linux Wiki]):&lt;br /&gt;
&lt;br /&gt;
{{cmd| veritysetup format /dev/$ROOT_PARTITION /dev/$VERITY_PARTITION | grep Root | cut -f2 &amp;gt;&amp;gt; /usr/lib/dracut/roothash.txt}}&lt;br /&gt;
&lt;br /&gt;
/etc/dracut.conf (put whatever your boot parameters are in &amp;quot;&amp;lt;code&amp;gt;kernel_cmdline&amp;lt;/code&amp;gt;&amp;quot;):&lt;br /&gt;
&lt;br /&gt;
{{cat| /etc/dracut.conf|...&lt;br /&gt;
kernel_cmdline{{=}}&amp;quot;&amp;quot;&lt;br /&gt;
add_dracutdrivers+{{=}}&amp;quot; busybox crypt crypt-gpg dm rootfs-block kernel-modules kernel-modules-extra tpm2-tss &amp;quot;&lt;br /&gt;
/etc/dracut.conf.d/secureboot.conf&lt;br /&gt;
&lt;br /&gt;
# Do the 3 lines below this if you have your own secureboot keys, or want to use secureboot:&lt;br /&gt;
uefi_secureboot_cert{{=}}&amp;quot;/$SECUREBOOT_KEYS_DIR/db.crt&amp;quot;&lt;br /&gt;
uefi_secureboot_key{{=}}&amp;quot;/$SECUREBOOT_KEYS_DIR/db.key&amp;quot;&lt;br /&gt;
/etc/dracut.conf.d/files.conf&lt;br /&gt;
&lt;br /&gt;
# This is what will import veritysetup binary file into dracut initramfs&lt;br /&gt;
install_items+{{=}}&amp;quot; /sbin/veritysetup &amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
Finally, generate UKI using dracut (replace &amp;lt;code&amp;gt;6.X.X-X-lts&amp;lt;/code&amp;gt; with your kernel &amp;lt;code&amp;gt;$VERSION&amp;lt;/code&amp;gt;) (also replace &amp;lt;code&amp;gt;/boot/efi/EFI/Linux/alpine-linux.efi&amp;lt;/code&amp;gt; with your mount efi partition):&lt;br /&gt;
&lt;br /&gt;
{{cmd| export DRACUT_KMODDIR_OVERRIDE{{=}}1}}&lt;br /&gt;
{{cmd| dracut --include /usr/lib/dracut/roothash.txt /usr/lib/dracut/roothash.txt --host-only --kernel-image /boot/vmlinuz-lts --kmoddir /lib/modules/6.X.X-X-lts --kver 6.X.X-X-lts --uefi --uefi-stub /usr/lib/gummiboot/linuxx64.efi.stub --force --compress lz4 /boot/efi/EFI/Linux/alpine-linux.efi /boot/efi/EFI/Linux/alpine-linux.efi}}&lt;br /&gt;
{{cmd| efibootmgr --create --disk /dev/$EFI_PARTITION --part 1 --label alpine-linux --loader EFI/Linux/alpine-linux.efi}}&lt;br /&gt;
&lt;br /&gt;
Unfortunately, using the default Alpine Linux kernel (&amp;lt;code&amp;gt;linux-lts&amp;lt;/code&amp;gt;) didn&#039;t work so download another distributions root system (like debians or devuan), and replace &amp;lt;code&amp;gt;/lib/modules/6.X.X-X-lts&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;/boot/vmlinuz-lts&amp;lt;/code&amp;gt; with anothers distributions kernel modules and kernel image (Or consider compiling your [https://wiki.alpinelinux.org/wiki/Hardened_linux own linux-hardened kernel] [11]).&lt;br /&gt;
&lt;br /&gt;
{{tip| If you want to test if DM-Verity fully works, change the &amp;lt;code&amp;gt;$ROOT_PARTITION&amp;lt;/code&amp;gt;&#039;s files and it should say it is &amp;quot;corrupt&amp;quot;, and not continue the boot process (only if you use EXT4).}}&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
==== Root of Trust/Chain of Trust ====&lt;br /&gt;
* [https://en.wikipedia.org/wiki/Chain_of_trust https://en.wikipedia.org/wiki/Chain_of_trust] [1]&lt;br /&gt;
==== Full disk encryption with LVM and LUKS (AlpineWiki): ====&lt;br /&gt;
* [https://wiki.alpinelinux.org/wiki/LVM_on_LUKS LVM_on_LUKS] [2]&lt;br /&gt;
==== Clevis Github ====&lt;br /&gt;
* [https://github.com/latchset/clevis?tab=readme-ov-file#pin-tpm2 https://github.com/latchset/clevis?tab=readme-ov-file#pin-tpm2] [3]&lt;br /&gt;
==== AppArmor Wiki (AlpineWiki) ====&lt;br /&gt;
* [https://wiki.alpinelinux.org/wiki/AppArmor AppArmor] [4]&lt;br /&gt;
==== GVisor ====&lt;br /&gt;
* [https://gvisor.dev/docs/user_guide/install/ https://gvisor.dev/docs/user_guide/install/] [5]&lt;br /&gt;
==== Gvisor Github stating docker is not a sandbox ====&lt;br /&gt;
* [https://github.com/google/gvisor?tab=readme-ov-file#why-does-gvisor-exist https://github.com/google/gvisor?tab=readme-ov-file#why-does-gvisor-exist] [6]&lt;br /&gt;
==== Android-13 Possibility of using ERO-FS: ====&lt;br /&gt;
* [https://pocketnow.com/erofs-android-13-explained/ https://pocketnow.com/erofs-android-13-explained/] [7]&lt;br /&gt;
==== DM-Verity (Arch Wiki): ====&lt;br /&gt;
* [https://wiki.archlinux.org/title/Dm-verity https://wiki.archlinux.org/title/Dm-verity] [8]&lt;br /&gt;
==== ERO-FS Github ====&lt;br /&gt;
* [https://github.com/erofs/erofs-utils https://github.com/erofs/erofs-utils] [9]&lt;br /&gt;
==== Dracut (Arch Wiki): ====&lt;br /&gt;
* [https://wiki.archlinux.org/title/Dracut https://wiki.archlinux.org/title/Dracut] [10]&lt;br /&gt;
==== Linux-Hardened Kernel (AlpineWiki): ====&lt;br /&gt;
* [https://wiki.alpinelinux.org/wiki/Hardened_linux Hardened_linux] [11]&lt;br /&gt;
==== My old post on how it worked ====&lt;br /&gt;
* [https://www.reddit.com/r/AlpineLinux/comments/15oibcc/comment/k1l7jv0/ https://www.reddit.com/r/AlpineLinux/comments/15oibcc/comment/k1l7jv0/] [12]&lt;br /&gt;
&lt;br /&gt;
[[Category:Security]] [[Category:Booting]]&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=DM-verity&amp;diff=28564</id>
		<title>DM-verity</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=DM-verity&amp;diff=28564"/>
		<updated>2024-12-23T20:31:19Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{todo| Add a non-initramfs dm-verity implementation, which should use kernel to do dm-verity checking instead of initramfs, which is better for embedded devices, and faster to boot (but hard to implement because of kernel customizations, might need to compile kernel again.)}}&lt;br /&gt;
&lt;br /&gt;
== Why DM-Verity? ==&lt;br /&gt;
Possibly you want to continue the RoT ([https://en.wikipedia.org/wiki/Chain_of_trust Root of Trust] [1]) - from the hardware (Hardware TPM as Root of Trust, which ensures only the hardware with the correct secret cryptographic key in the TPM to decrypt the disk/file encryption) -&amp;gt; secure boot (Secure Boot to only run approved signed EFIStub/signed Bootloader) -&amp;gt; &amp;lt;u&amp;gt;To NOW DM-Verity rootfs&amp;lt;/u&amp;gt; (which ensures your root-image/root-parition has not been tampered with) -&amp;gt; Mandatory Access Control (AppArmor or SELinux - SELinux is disabled on default linux-lts btw) -&amp;gt; Sandboxed/Virtual-Machined Applications.&lt;br /&gt;
&lt;br /&gt;
=== What&#039;s the difference between me just setting the root partition as read-only (basically just an Immutable Root Partition) vs this? ===&lt;br /&gt;
DM-Verity COMPLETELY disallows modifying any files in the root-partition/root-image, or even disallow a part of a root-image/root-partition (the root-image/root-partition needs to be INTACT and match the signed cryptography verified by DM-Verity on a different partition), and with this consideration, you may use ERO-FS or SquashFS to generate Read-Only Root-Paritition Images. If you set your EXT4 file system to writable, and DM-Verity were to use it, it would be seen as &amp;quot;corrupted&amp;quot; and not boot anymore, because even just ONE tiny data change to the root image/partition would render it &amp;quot;corrupted&amp;quot;. This is the same technology used in Android and Chrome OS Devices. Also related to use in A/B root, also used by Fedora.&lt;br /&gt;
&lt;br /&gt;
{{tip| To keep the security reasonable, you would ideally want to work on the whole RoT, if not then anybody else can attack the non-verifed boot process that ISN&#039;T the root-partition/root-image that is enforced by DM-Verity.&lt;br /&gt;
* This following guide will use dracut to make a signed secureboot-able EFIStub.&lt;br /&gt;
* If you haven&#039;t, you may follow [https://wiki.alpinelinux.org/wiki/LVM_on_LUKS the Alpine Linux disk encryption setup] [2] with DM-Crypt LUKS and LVM&lt;br /&gt;
* You may choose to decrypt the image with TPM when generating with Dracut Modules with &amp;lt;code&amp;gt;add_dracutdrivers+{{=}}&amp;quot; ... tpm2-tss ... &amp;quot;&amp;lt;/code&amp;gt; and [https://github.com/latchset/clevis?tab{{=}}readme-ov-file#pin-tpm2 Clevis] [3]&lt;br /&gt;
* Apply AppArmor using [https://wiki.alpinelinux.org/wiki/AppArmor Alpine Linux AppArmor Wiki] (Docker does use AppArmor already, but you may apply an AppArmor profile on any application that should not have access to specific directories (AppArmor is a PATH based MAC)) [4]&lt;br /&gt;
* Use [https://gvisor.dev/docs/user_guide/install/ GVisor] [5] with Docker ([https://github.com/google/gvisor?tab{{=}}readme-ov-file#why-does-gvisor-exist Docker is NOT a sandbox] [6] (Because docker uses native kernel compared to Gvisor using its own kernel reimplementation)) for sandboxing on servers}}&lt;br /&gt;
&lt;br /&gt;
=== What is ERO-FS? ===&lt;br /&gt;
[https://pocketnow.com/erofs-android-13-explained/ Google thought about implementing ERO-FS with DM-Verity] [7]. Google was reported to be using it in Android 13, and ERO-FS is an excellent and fast compressed read-only filesystem.&lt;br /&gt;
&lt;br /&gt;
Here is an excerpt about &amp;lt;code&amp;gt;mkfs.erofs&amp;lt;/code&amp;gt; on [[https://wiki.archlinux.org/title/Dm-verity Arch Linux Wiki]] [8]:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039; mkfs.erofs(1) offers an attractive alternative to ext4 or squashfs on the root partition. EROFS, like squashfs, does not allow writes by design and has better performance in many cases than comparable filesystems on flash and solid-state media. It uses lz4 compression by default and was designed for Android phones by Huawei, which make extensive use of dm-verity. &#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Installing ===&lt;br /&gt;
&lt;br /&gt;
==== Working with ERO-FS ====&lt;br /&gt;
&lt;br /&gt;
{{warning| This wiki will be using Alpine Linux Edge Version. (Alpine Linux Non-Edge Versions may not contain these packages in the following rest of the wiki page) (Use Alpine Linux Edge Testing Repository in &amp;lt;code&amp;gt;/etc/apk/repositories&amp;lt;/code&amp;gt; as well)}}&lt;br /&gt;
&lt;br /&gt;
{{note| To not be confused, ERO-FS generates a &amp;quot;root image&amp;quot;, but you can replace the words &amp;quot;root partition&amp;quot; with &amp;quot;root image&amp;quot; and vice versa.}}&lt;br /&gt;
&lt;br /&gt;
First, some considerations, you may use a strictly READ-ONLY file system, such as SquashFS or ERO-FS, this wiki will be using ERO-FS (if you use a custom kernel, make sure it supports a file system such as ERO-FS, the default linux-lts does). [[https://github.com/erofs/erofs-utils ERO-FS Github]] [9] contains some information about how to compress and make your own read-only root image.&lt;br /&gt;
&lt;br /&gt;
{{cmd| $ apk install erofs-utils}}&lt;br /&gt;
{{cmd| $ mkdir image &amp;amp;&amp;amp; cd image }}&lt;br /&gt;
{{cmd| $ wget https://dl-cdn.alpinelinux.org/alpine/v3.21/releases/x86_64/alpine-minirootfs-3.21.0-x86_64.tar.gz}}&lt;br /&gt;
{{cmd| $ tar -xvf alpine-minirootfs-3.21.0-x86_64.tar.gz &amp;amp;&amp;amp; rm alpine-minirootfs-3.21.0-x86_64.tar.gz}}&lt;br /&gt;
Command below will generate an ERO-FS Image compressed with lz4 as ./erofs.img (erofs.img would be the root-partition file to use for dracut)&lt;br /&gt;
{{cmd| $ cd .. &amp;amp;&amp;amp; mkfs.erofs -zlz4hc erofs.img ./image}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Working with mkinitfs/kernel-hooks/secureboot-hooks ====&lt;br /&gt;
{{todo| wip}}&lt;br /&gt;
&lt;br /&gt;
Using mkinitfs, it is possible to force veritysetup in initramfs generation. It is recommended to make a chroot or docker so you don&#039;t mess with your system files, and by adding these files:&lt;br /&gt;
&lt;br /&gt;
{{todo| The init script is too big to put in wiki, I just acquired it from initramfs generation and decompression (read the tip below)}}&lt;br /&gt;
{{note| the APK package &amp;quot;cryptsetup&amp;quot; comes with veritysetup}}&lt;br /&gt;
{{note| make sure the chroot has a linux-kernel}}&lt;br /&gt;
&lt;br /&gt;
Edit /sbin/mkinitfs (put &amp;quot;# Copy custom init&amp;quot; before &amp;quot;# copy modloop signature&amp;quot;):&lt;br /&gt;
{{cat| /etc/mkinitfs|...&lt;br /&gt;
        # Copy custom init &lt;br /&gt;
        cp /initramfs/init &amp;quot;$tmpdir&amp;quot;/init &lt;br /&gt;
        &lt;br /&gt;
        # copy modloop signature&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
PUT &amp;quot;# Call custom script&amp;quot; before &amp;quot;# switch over to new root&amp;quot;&lt;br /&gt;
{{cat| /initramfs/init|...&lt;br /&gt;
# Call custom script&lt;br /&gt;
/etc/scripts/my-custom-script.sh&lt;br /&gt;
&lt;br /&gt;
# switch over to new root&lt;br /&gt;
...&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/my-custom-script.files|&lt;br /&gt;
/etc/scripts/my-custom-script.sh&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/veritysetup.files|&lt;br /&gt;
/sbin/veritysetup&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/veritysetup.modules|&lt;br /&gt;
kernel/drivers/md/dm-verity.ko*&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/erofs.modules|&lt;br /&gt;
kernel/fs/erofs&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/mkinitfs.conf|...&lt;br /&gt;
features{{=}}&amp;quot;... erofs my-custom-script&amp;quot;&lt;br /&gt;
MODULES{{=}}&amp;quot;veritysetup erofs&amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
{{cat| /etc/scripts/my-custom-script.sh|&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
mount /dev/mapper/root /root&lt;br /&gt;
mount /root/var/root/erofs.img /sysroot&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Then just do:&lt;br /&gt;
{{cmd| apk add secureboot-hook gummiboot gummiboot-efistub efibootmgr kernel-hooks secureboot-hook}}&lt;br /&gt;
&lt;br /&gt;
{{tip|To make sure initramfs has the scripts needed, do:&lt;br /&gt;
{{cmd|mkinitfs -c /etc/mkinitfs/mkinitfs.conf -b / $(uname -r)}}&lt;br /&gt;
Decompress:&lt;br /&gt;
{{cmd|mkdir /tmp/initramfs&lt;br /&gt;
cd /tmp/initramfs&lt;br /&gt;
&amp;lt;nowiki&amp;gt;zcat /boot/initramfs-$KERNEL | cpio -idmv&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Working with Dracut ====&lt;br /&gt;
&lt;br /&gt;
Remember, mount your &amp;lt;code&amp;gt;$ROOT_PARTITION&amp;lt;/code&amp;gt; as read only (assuming you use EXT4, if using ERO-FS or SquashFS, ignore this), since any changes will cause DM-Verity to detect it as &amp;quot;corrupt&amp;quot;&lt;br /&gt;
&lt;br /&gt;
{{warning| The following guide was done with FULL disk encryption, so this might not work perfectly on Non encrypted disk setup, also done on UEFI using gummiboot (now called systemd-boot - yes, systemd-boot is a separate project from the systemd init system) EFIStub and generating a UKI (Unified Kernel Image)}}&lt;br /&gt;
&lt;br /&gt;
===== Install basic stuff: =====&lt;br /&gt;
&lt;br /&gt;
{{cmd| apk add dracut dracut-core cryptsetup gummiboot gummiboot-efistub tpm2-tools clevis tpm2-tss tpm2-tss-tcti-device}}&lt;br /&gt;
&lt;br /&gt;
===== Using Clevis for TPM =====&lt;br /&gt;
&lt;br /&gt;
{{cmd| clevis luks bind -d /$ENCRYPTED_ROOT_PARTITION tpm2 &#039;{&amp;quot;pcr_ids&amp;quot;:&amp;quot;1,7&amp;quot;}&#039;}}&lt;br /&gt;
Input LUKS passphrase, remember that yes now it has tpm, but if possible remove old luks passphrase and use keyfile or different passphrase to unlock because tpm is better, and so if your computer breaks, you won&#039;t be locked out of your data!&lt;br /&gt;
&lt;br /&gt;
===== Create a new partition for your DM-Verity: =====&lt;br /&gt;
&lt;br /&gt;
Replace /dev/sdX with your actual device name.&lt;br /&gt;
{{cmd| sudo fdisk /dev/sdX}}&lt;br /&gt;
&lt;br /&gt;
Once in the fdisk interface:&lt;br /&gt;
# Press n to create a new partition&lt;br /&gt;
# Choose p for primary partition&lt;br /&gt;
# Select the partition number (e.g., 4)&lt;br /&gt;
# For the first sector, press Enter to use the default&lt;br /&gt;
# For the last sector, calculate 10% of your root partition size and use +SIZE format. For example, if your root partition is 100GB, enter +10G&lt;br /&gt;
# Press t to change the partition type&lt;br /&gt;
# Enter the partition number you just created&lt;br /&gt;
# Type 8e for Linux LVM type (closest to verity)&lt;br /&gt;
# Press w to write changes and exit&lt;br /&gt;
&lt;br /&gt;
===== Adding custom lines for full disk decryption =====&lt;br /&gt;
&lt;br /&gt;
Edit &amp;quot;&amp;lt;code&amp;gt;/usr/lib/dracut/modules.d/90crypt/cryptroot-ask.sh&amp;lt;/code&amp;gt;&amp;quot; and add these lines right BEFORE &amp;quot;&amp;lt;code&amp;gt;exit 0&amp;lt;/code&amp;gt;&amp;quot; (add your &amp;lt;code&amp;gt;$ROOT_PARTITION&amp;lt;/code&amp;gt; directory and &amp;lt;code&amp;gt;$VERITY_PARTITION&amp;lt;/code&amp;gt; directory):&lt;br /&gt;
&lt;br /&gt;
{{cat| /usr/lib/dracut/modules.d/90crypt/cryptroot-ask.sh|...&lt;br /&gt;
### DM-Verity&lt;br /&gt;
mount /dev/mapper/$ROOT_PARTITION /var/tmp&lt;br /&gt;
cryptsetup open --key-file /var/tmp/$KEYFILE_DIR /dev/$VERITY_PARTITION $VERITY_DM_NAME&lt;br /&gt;
umount /var/tmp&lt;br /&gt;
veritysetup open /dev/$ROOT_PARTITION /dev/$VERITY_PARTITION $(cat /usr/lib/dracut/roothash.txt)&lt;br /&gt;
###&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
===== Generating an EFIStub with Dracut + DM-Verity =====&lt;br /&gt;
&lt;br /&gt;
To setup DM-Verity (borrowed from [https://wiki.archlinux.org/title/Dm-verity Arch Linux Wiki]):&lt;br /&gt;
&lt;br /&gt;
{{cmd| veritysetup format /dev/$ROOT_PARTITION /dev/$VERITY_PARTITION | grep Root | cut -f2 &amp;gt;&amp;gt; /usr/lib/dracut/roothash.txt}}&lt;br /&gt;
&lt;br /&gt;
/etc/dracut.conf (put whatever your boot parameters are in &amp;quot;&amp;lt;code&amp;gt;kernel_cmdline&amp;lt;/code&amp;gt;&amp;quot;):&lt;br /&gt;
&lt;br /&gt;
{{cat| /etc/dracut.conf|...&lt;br /&gt;
kernel_cmdline{{=}}&amp;quot;&amp;quot;&lt;br /&gt;
add_dracutdrivers+{{=}}&amp;quot; busybox crypt crypt-gpg dm rootfs-block kernel-modules kernel-modules-extra tpm2-tss &amp;quot;&lt;br /&gt;
/etc/dracut.conf.d/secureboot.conf&lt;br /&gt;
&lt;br /&gt;
# Do the 3 lines below this if you have your own secureboot keys, or want to use secureboot:&lt;br /&gt;
uefi_secureboot_cert{{=}}&amp;quot;/$SECUREBOOT_KEYS_DIR/db.crt&amp;quot;&lt;br /&gt;
uefi_secureboot_key{{=}}&amp;quot;/$SECUREBOOT_KEYS_DIR/db.key&amp;quot;&lt;br /&gt;
/etc/dracut.conf.d/files.conf&lt;br /&gt;
&lt;br /&gt;
# This is what will import veritysetup binary file into dracut initramfs&lt;br /&gt;
install_items+{{=}}&amp;quot; /sbin/veritysetup &amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
Finally, generate UKI using dracut (replace &amp;lt;code&amp;gt;6.X.X-X-lts&amp;lt;/code&amp;gt; with your kernel &amp;lt;code&amp;gt;$VERSION&amp;lt;/code&amp;gt;) (also replace &amp;lt;code&amp;gt;/boot/efi/EFI/Linux/alpine-linux.efi&amp;lt;/code&amp;gt; with your mount efi partition):&lt;br /&gt;
&lt;br /&gt;
{{cmd| export DRACUT_KMODDIR_OVERRIDE{{=}}1}}&lt;br /&gt;
{{cmd| dracut --include /usr/lib/dracut/roothash.txt /usr/lib/dracut/roothash.txt --host-only --kernel-image /boot/vmlinuz-lts --kmoddir /lib/modules/6.X.X-X-lts --kver 6.X.X-X-lts --uefi --uefi-stub /usr/lib/gummiboot/linuxx64.efi.stub --force --compress lz4 /boot/efi/EFI/Linux/alpine-linux.efi /boot/efi/EFI/Linux/alpine-linux.efi}}&lt;br /&gt;
{{cmd| efibootmgr --create --disk /dev/$EFI_PARTITION --part 1 --label alpine-linux --loader EFI/Linux/alpine-linux.efi}}&lt;br /&gt;
&lt;br /&gt;
Unfortunately, using the default Alpine Linux kernel (&amp;lt;code&amp;gt;linux-lts&amp;lt;/code&amp;gt;) didn&#039;t work so download another distributions root system (like debians or devuan), and replace &amp;lt;code&amp;gt;/lib/modules/6.X.X-X-lts&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;/boot/vmlinuz-lts&amp;lt;/code&amp;gt; with anothers distributions kernel modules and kernel image (Or consider compiling your [https://wiki.alpinelinux.org/wiki/Hardened_linux own linux-hardened kernel] [11]).&lt;br /&gt;
&lt;br /&gt;
{{tip| If you want to test if DM-Verity fully works, change the &amp;lt;code&amp;gt;$ROOT_PARTITION&amp;lt;/code&amp;gt;&#039;s files and it should say it is &amp;quot;corrupt&amp;quot;, and not continue the boot process (only if you use EXT4).}}&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
==== Root of Trust/Chain of Trust ====&lt;br /&gt;
* [https://en.wikipedia.org/wiki/Chain_of_trust https://en.wikipedia.org/wiki/Chain_of_trust] [1]&lt;br /&gt;
==== Full disk encryption with LVM and LUKS (AlpineWiki): ====&lt;br /&gt;
* [https://wiki.alpinelinux.org/wiki/LVM_on_LUKS LVM_on_LUKS] [2]&lt;br /&gt;
==== Clevis Github ====&lt;br /&gt;
* [https://github.com/latchset/clevis?tab=readme-ov-file#pin-tpm2 https://github.com/latchset/clevis?tab=readme-ov-file#pin-tpm2] [3]&lt;br /&gt;
==== AppArmor Wiki (AlpineWiki) ====&lt;br /&gt;
* [https://wiki.alpinelinux.org/wiki/AppArmor AppArmor] [4]&lt;br /&gt;
==== GVisor ====&lt;br /&gt;
* [https://gvisor.dev/docs/user_guide/install/ https://gvisor.dev/docs/user_guide/install/] [5]&lt;br /&gt;
==== Gvisor Github stating docker is not a sandbox ====&lt;br /&gt;
* [https://github.com/google/gvisor?tab=readme-ov-file#why-does-gvisor-exist https://github.com/google/gvisor?tab=readme-ov-file#why-does-gvisor-exist] [6]&lt;br /&gt;
==== Android-13 Possibility of using ERO-FS: ====&lt;br /&gt;
* [https://pocketnow.com/erofs-android-13-explained/ https://pocketnow.com/erofs-android-13-explained/] [7]&lt;br /&gt;
==== DM-Verity (Arch Wiki): ====&lt;br /&gt;
* [https://wiki.archlinux.org/title/Dm-verity https://wiki.archlinux.org/title/Dm-verity] [8]&lt;br /&gt;
==== ERO-FS Github ====&lt;br /&gt;
* [https://github.com/erofs/erofs-utils https://github.com/erofs/erofs-utils] [9]&lt;br /&gt;
==== Dracut (Arch Wiki): ====&lt;br /&gt;
* [https://wiki.archlinux.org/title/Dracut https://wiki.archlinux.org/title/Dracut] [10]&lt;br /&gt;
==== Linux-Hardened Kernel (AlpineWiki): ====&lt;br /&gt;
* [https://wiki.alpinelinux.org/wiki/Hardened_linux Hardened_linux] [11]&lt;br /&gt;
==== My old post on how it worked ====&lt;br /&gt;
* [https://www.reddit.com/r/AlpineLinux/comments/15oibcc/comment/k1l7jv0/ https://www.reddit.com/r/AlpineLinux/comments/15oibcc/comment/k1l7jv0/] [12]&lt;br /&gt;
&lt;br /&gt;
[[Category:Security]] [[Category:Booting]]&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=DM-verity&amp;diff=28563</id>
		<title>DM-verity</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=DM-verity&amp;diff=28563"/>
		<updated>2024-12-23T20:30:01Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{todo| Add a non-initramfs dm-verity implementation, which should use kernel to do dm-verity checking instead of initramfs, which is better for embedded devices, and faster to boot (but hard to implement because of kernel customizations, might need to compile kernel again.)}}&lt;br /&gt;
&lt;br /&gt;
== Why DM-Verity? ==&lt;br /&gt;
Possibly you want to continue the RoT ([https://en.wikipedia.org/wiki/Chain_of_trust Root of Trust] [1]) - from the hardware (Hardware TPM as Root of Trust, which ensures only the hardware with the correct secret cryptographic key in the TPM to decrypt the disk/file encryption) -&amp;gt; secure boot (Secure Boot to only run approved signed EFIStub/signed Bootloader) -&amp;gt; &amp;lt;u&amp;gt;To NOW DM-Verity rootfs&amp;lt;/u&amp;gt; (which ensures your root-image/root-parition has not been tampered with) -&amp;gt; Mandatory Access Control (AppArmor or SELinux - SELinux is disabled on default linux-lts btw) -&amp;gt; Sandboxed/Virtual-Machined Applications.&lt;br /&gt;
&lt;br /&gt;
=== What&#039;s the difference between me just setting the root partition as read-only (basically just an Immutable Root Partition) vs this? ===&lt;br /&gt;
DM-Verity COMPLETELY disallows modifying any files in the root-partition/root-image, or even disallow a part of a root-image/root-partition (the root-image/root-partition needs to be INTACT and match the signed cryptography verified by DM-Verity on a different partition), and with this consideration, you may use ERO-FS or SquashFS to generate Read-Only Root-Paritition Images. If you set your EXT4 file system to writable, and DM-Verity were to use it, it would be seen as &amp;quot;corrupted&amp;quot; and not boot anymore, because even just ONE tiny data change to the root image/partition would render it &amp;quot;corrupted&amp;quot;. This is the same technology used in Android and Chrome OS Devices. Also related to use in A/B root, also used by Fedora.&lt;br /&gt;
&lt;br /&gt;
{{tip| To keep the security reasonable, you would ideally want to work on the whole RoT, if not then anybody else can attack the non-verifed boot process that ISN&#039;T the root-partition/root-image that is enforced by DM-Verity.&lt;br /&gt;
* This following guide will use dracut to make a signed secureboot-able EFIStub.&lt;br /&gt;
* If you haven&#039;t, you may follow [https://wiki.alpinelinux.org/wiki/LVM_on_LUKS the Alpine Linux disk encryption setup] [2] with DM-Crypt LUKS and LVM&lt;br /&gt;
* You may choose to decrypt the image with TPM when generating with Dracut Modules with &amp;lt;code&amp;gt;add_dracutdrivers+{{=}}&amp;quot; ... tpm2-tss ... &amp;quot;&amp;lt;/code&amp;gt; and [https://github.com/latchset/clevis?tab{{=}}readme-ov-file#pin-tpm2 Clevis] [3]&lt;br /&gt;
* Apply AppArmor using [https://wiki.alpinelinux.org/wiki/AppArmor Alpine Linux AppArmor Wiki] (Docker does use AppArmor already, but you may apply an AppArmor profile on any application that should not have access to specific directories (AppArmor is a PATH based MAC)) [4]&lt;br /&gt;
* Use [https://gvisor.dev/docs/user_guide/install/ GVisor] [5] with Docker ([https://github.com/google/gvisor?tab{{=}}readme-ov-file#why-does-gvisor-exist Docker is NOT a sandbox] [6] (Because docker uses native kernel compared to Gvisor using its own kernel reimplementation)) for sandboxing on servers}}&lt;br /&gt;
&lt;br /&gt;
=== What is ERO-FS? ===&lt;br /&gt;
[https://pocketnow.com/erofs-android-13-explained/ Google thought about implementing ERO-FS with DM-Verity] [7]. Google was reported to be using it in Android 13, and ERO-FS is an excellent and fast compressed read-only filesystem.&lt;br /&gt;
&lt;br /&gt;
Here is an excerpt about &amp;lt;code&amp;gt;mkfs.erofs&amp;lt;/code&amp;gt; on [[https://wiki.archlinux.org/title/Dm-verity Arch Linux Wiki]] [8]:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039; mkfs.erofs(1) offers an attractive alternative to ext4 or squashfs on the root partition. EROFS, like squashfs, does not allow writes by design and has better performance in many cases than comparable filesystems on flash and solid-state media. It uses lz4 compression by default and was designed for Android phones by Huawei, which make extensive use of dm-verity. &#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Installing ===&lt;br /&gt;
&lt;br /&gt;
==== Working with ERO-FS ====&lt;br /&gt;
&lt;br /&gt;
{{warning| This wiki will be using Alpine Linux Edge Version. (Alpine Linux Non-Edge Versions may not contain these packages in the following rest of the wiki page) (Use Alpine Linux Edge Testing Repository in &amp;lt;code&amp;gt;/etc/apk/repositories&amp;lt;/code&amp;gt; as well)}}&lt;br /&gt;
&lt;br /&gt;
{{note| To not be confused, ERO-FS generates a &amp;quot;root image&amp;quot;, but you can replace the words &amp;quot;root partition&amp;quot; with &amp;quot;root image&amp;quot; and vice versa.}}&lt;br /&gt;
&lt;br /&gt;
First, some considerations, you may use a strictly READ-ONLY file system, such as SquashFS or ERO-FS, this wiki will be using ERO-FS (if you use a custom kernel, make sure it supports a file system such as ERO-FS, the default linux-lts does). [[https://github.com/erofs/erofs-utils ERO-FS Github]] [9] contains some information about how to compress and make your own read-only root image.&lt;br /&gt;
&lt;br /&gt;
{{cmd| $ apk install erofs-utils}}&lt;br /&gt;
{{cmd| $ mkdir image &amp;amp;&amp;amp; cd image }}&lt;br /&gt;
{{cmd| $ wget https://dl-cdn.alpinelinux.org/alpine/v3.21/releases/x86_64/alpine-minirootfs-3.21.0-x86_64.tar.gz}}&lt;br /&gt;
{{cmd| $ tar -xvf alpine-minirootfs-3.21.0-x86_64.tar.gz &amp;amp;&amp;amp; rm alpine-minirootfs-3.21.0-x86_64.tar.gz}}&lt;br /&gt;
Command below will generate an ERO-FS Image compressed with lz4 as ./erofs.img (erofs.img would be the root-partition file to use for dracut)&lt;br /&gt;
{{cmd| $ cd .. &amp;amp;&amp;amp; mkfs.erofs -zlz4hc erofs.img ./image}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Working with mkinitfs/kernel-hooks/secureboot-hooks ====&lt;br /&gt;
{{todo| wip}}&lt;br /&gt;
&lt;br /&gt;
Using mkinitfs, it is possible to force veritysetup in initramfs generation. It is recommended to make a chroot or docker so you don&#039;t mess with your system files, and by adding these files:&lt;br /&gt;
&lt;br /&gt;
{{todo| The init script is too big to put in wiki, I just acquired it from initramfs generation and decompression}}&lt;br /&gt;
{{note| the APK package &amp;quot;cryptsetup&amp;quot; comes with veritysetup}}&lt;br /&gt;
{{note| make sure the chroot has a linux-kernel}}&lt;br /&gt;
&lt;br /&gt;
Edit /sbin/mkinitfs (put &amp;quot;# Copy custom init&amp;quot; before &amp;quot;# copy modloop signature&amp;quot;):&lt;br /&gt;
{{cat| /etc/mkinitfs|...&lt;br /&gt;
        # Copy custom init &lt;br /&gt;
        cp /initramfs/init &amp;quot;$tmpdir&amp;quot;/init &lt;br /&gt;
        &lt;br /&gt;
        # copy modloop signature&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
PUT &amp;quot;# Call custom script&amp;quot; before &amp;quot;# switch over to new root&amp;quot;&lt;br /&gt;
{{cat| /initramfs/init|...&lt;br /&gt;
# Call custom script&lt;br /&gt;
/etc/scripts/my-custom-script.sh&lt;br /&gt;
&lt;br /&gt;
# switch over to new root&lt;br /&gt;
...&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/my-custom-script.files|&lt;br /&gt;
/etc/scripts/my-custom-script.sh&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/veritysetup.files|&lt;br /&gt;
/sbin/veritysetup&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/veritysetup.modules|&lt;br /&gt;
kernel/drivers/md/dm-verity.ko*&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/erofs.modules|&lt;br /&gt;
kernel/fs/erofs&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/mkinitfs.conf|...&lt;br /&gt;
features{{=}}&amp;quot;... erofs my-custom-script&amp;quot;&lt;br /&gt;
MODULES{{=}}&amp;quot;veritysetup erofs&amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
{{cat| /etc/scripts/my-custom-script.sh|&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
mount /dev/mapper/root /root&lt;br /&gt;
mount /root/var/root/erofs.img /sysroot&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Then just do:&lt;br /&gt;
{{cmd| apk add secureboot-hook gummiboot gummiboot-efistub efibootmgr kernel-hooks secureboot-hook}}&lt;br /&gt;
&lt;br /&gt;
{{tip|To make sure initramfs has the scripts needed, do:&lt;br /&gt;
{{cmd|mkinitfs -c /etc/mkinitfs/mkinitfs.conf -b / $(uname -r)}}&lt;br /&gt;
Decompress:&lt;br /&gt;
{{cmd|mkdir /tmp/initramfs&lt;br /&gt;
cd /tmp/initramfs&lt;br /&gt;
&amp;lt;nowiki&amp;gt;zcat /boot/initramfs-$KERNEL | cpio -idmv&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Working with Dracut ====&lt;br /&gt;
&lt;br /&gt;
Remember, mount your &amp;lt;code&amp;gt;$ROOT_PARTITION&amp;lt;/code&amp;gt; as read only (assuming you use EXT4, if using ERO-FS or SquashFS, ignore this), since any changes will cause DM-Verity to detect it as &amp;quot;corrupt&amp;quot;&lt;br /&gt;
&lt;br /&gt;
{{warning| The following guide was done with FULL disk encryption, so this might not work perfectly on Non encrypted disk setup, also done on UEFI using gummiboot (now called systemd-boot - yes, systemd-boot is a separate project from the systemd init system) EFIStub and generating a UKI (Unified Kernel Image)}}&lt;br /&gt;
&lt;br /&gt;
===== Install basic stuff: =====&lt;br /&gt;
&lt;br /&gt;
{{cmd| apk add dracut dracut-core cryptsetup gummiboot gummiboot-efistub tpm2-tools clevis tpm2-tss tpm2-tss-tcti-device}}&lt;br /&gt;
&lt;br /&gt;
===== Using Clevis for TPM =====&lt;br /&gt;
&lt;br /&gt;
{{cmd| clevis luks bind -d /$ENCRYPTED_ROOT_PARTITION tpm2 &#039;{&amp;quot;pcr_ids&amp;quot;:&amp;quot;1,7&amp;quot;}&#039;}}&lt;br /&gt;
Input LUKS passphrase, remember that yes now it has tpm, but if possible remove old luks passphrase and use keyfile or different passphrase to unlock because tpm is better, and so if your computer breaks, you won&#039;t be locked out of your data!&lt;br /&gt;
&lt;br /&gt;
===== Create a new partition for your DM-Verity: =====&lt;br /&gt;
&lt;br /&gt;
Replace /dev/sdX with your actual device name.&lt;br /&gt;
{{cmd| sudo fdisk /dev/sdX}}&lt;br /&gt;
&lt;br /&gt;
Once in the fdisk interface:&lt;br /&gt;
# Press n to create a new partition&lt;br /&gt;
# Choose p for primary partition&lt;br /&gt;
# Select the partition number (e.g., 4)&lt;br /&gt;
# For the first sector, press Enter to use the default&lt;br /&gt;
# For the last sector, calculate 10% of your root partition size and use +SIZE format. For example, if your root partition is 100GB, enter +10G&lt;br /&gt;
# Press t to change the partition type&lt;br /&gt;
# Enter the partition number you just created&lt;br /&gt;
# Type 8e for Linux LVM type (closest to verity)&lt;br /&gt;
# Press w to write changes and exit&lt;br /&gt;
&lt;br /&gt;
===== Adding custom lines for full disk decryption =====&lt;br /&gt;
&lt;br /&gt;
Edit &amp;quot;&amp;lt;code&amp;gt;/usr/lib/dracut/modules.d/90crypt/cryptroot-ask.sh&amp;lt;/code&amp;gt;&amp;quot; and add these lines right BEFORE &amp;quot;&amp;lt;code&amp;gt;exit 0&amp;lt;/code&amp;gt;&amp;quot; (add your &amp;lt;code&amp;gt;$ROOT_PARTITION&amp;lt;/code&amp;gt; directory and &amp;lt;code&amp;gt;$VERITY_PARTITION&amp;lt;/code&amp;gt; directory):&lt;br /&gt;
&lt;br /&gt;
{{cat| /usr/lib/dracut/modules.d/90crypt/cryptroot-ask.sh|...&lt;br /&gt;
### DM-Verity&lt;br /&gt;
mount /dev/mapper/$ROOT_PARTITION /var/tmp&lt;br /&gt;
cryptsetup open --key-file /var/tmp/$KEYFILE_DIR /dev/$VERITY_PARTITION $VERITY_DM_NAME&lt;br /&gt;
umount /var/tmp&lt;br /&gt;
veritysetup open /dev/$ROOT_PARTITION /dev/$VERITY_PARTITION $(cat /usr/lib/dracut/roothash.txt)&lt;br /&gt;
###&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
===== Generating an EFIStub with Dracut + DM-Verity =====&lt;br /&gt;
&lt;br /&gt;
To setup DM-Verity (borrowed from [https://wiki.archlinux.org/title/Dm-verity Arch Linux Wiki]):&lt;br /&gt;
&lt;br /&gt;
{{cmd| veritysetup format /dev/$ROOT_PARTITION /dev/$VERITY_PARTITION | grep Root | cut -f2 &amp;gt;&amp;gt; /usr/lib/dracut/roothash.txt}}&lt;br /&gt;
&lt;br /&gt;
/etc/dracut.conf (put whatever your boot parameters are in &amp;quot;&amp;lt;code&amp;gt;kernel_cmdline&amp;lt;/code&amp;gt;&amp;quot;):&lt;br /&gt;
&lt;br /&gt;
{{cat| /etc/dracut.conf|...&lt;br /&gt;
kernel_cmdline{{=}}&amp;quot;&amp;quot;&lt;br /&gt;
add_dracutdrivers+{{=}}&amp;quot; busybox crypt crypt-gpg dm rootfs-block kernel-modules kernel-modules-extra tpm2-tss &amp;quot;&lt;br /&gt;
/etc/dracut.conf.d/secureboot.conf&lt;br /&gt;
&lt;br /&gt;
# Do the 3 lines below this if you have your own secureboot keys, or want to use secureboot:&lt;br /&gt;
uefi_secureboot_cert{{=}}&amp;quot;/$SECUREBOOT_KEYS_DIR/db.crt&amp;quot;&lt;br /&gt;
uefi_secureboot_key{{=}}&amp;quot;/$SECUREBOOT_KEYS_DIR/db.key&amp;quot;&lt;br /&gt;
/etc/dracut.conf.d/files.conf&lt;br /&gt;
&lt;br /&gt;
# This is what will import veritysetup binary file into dracut initramfs&lt;br /&gt;
install_items+{{=}}&amp;quot; /sbin/veritysetup &amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
Finally, generate UKI using dracut (replace &amp;lt;code&amp;gt;6.X.X-X-lts&amp;lt;/code&amp;gt; with your kernel &amp;lt;code&amp;gt;$VERSION&amp;lt;/code&amp;gt;) (also replace &amp;lt;code&amp;gt;/boot/efi/EFI/Linux/alpine-linux.efi&amp;lt;/code&amp;gt; with your mount efi partition):&lt;br /&gt;
&lt;br /&gt;
{{cmd| export DRACUT_KMODDIR_OVERRIDE{{=}}1}}&lt;br /&gt;
{{cmd| dracut --include /usr/lib/dracut/roothash.txt /usr/lib/dracut/roothash.txt --host-only --kernel-image /boot/vmlinuz-lts --kmoddir /lib/modules/6.X.X-X-lts --kver 6.X.X-X-lts --uefi --uefi-stub /usr/lib/gummiboot/linuxx64.efi.stub --force --compress lz4 /boot/efi/EFI/Linux/alpine-linux.efi /boot/efi/EFI/Linux/alpine-linux.efi}}&lt;br /&gt;
{{cmd| efibootmgr --create --disk /dev/$EFI_PARTITION --part 1 --label alpine-linux --loader EFI/Linux/alpine-linux.efi}}&lt;br /&gt;
&lt;br /&gt;
Unfortunately, using the default Alpine Linux kernel (&amp;lt;code&amp;gt;linux-lts&amp;lt;/code&amp;gt;) didn&#039;t work so download another distributions root system (like debians or devuan), and replace &amp;lt;code&amp;gt;/lib/modules/6.X.X-X-lts&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;/boot/vmlinuz-lts&amp;lt;/code&amp;gt; with anothers distributions kernel modules and kernel image (Or consider compiling your [https://wiki.alpinelinux.org/wiki/Hardened_linux own linux-hardened kernel] [11]).&lt;br /&gt;
&lt;br /&gt;
{{tip| If you want to test if DM-Verity fully works, change the &amp;lt;code&amp;gt;$ROOT_PARTITION&amp;lt;/code&amp;gt;&#039;s files and it should say it is &amp;quot;corrupt&amp;quot;, and not continue the boot process (only if you use EXT4).}}&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
==== Root of Trust/Chain of Trust ====&lt;br /&gt;
* [https://en.wikipedia.org/wiki/Chain_of_trust https://en.wikipedia.org/wiki/Chain_of_trust] [1]&lt;br /&gt;
==== Full disk encryption with LVM and LUKS (AlpineWiki): ====&lt;br /&gt;
* [https://wiki.alpinelinux.org/wiki/LVM_on_LUKS LVM_on_LUKS] [2]&lt;br /&gt;
==== Clevis Github ====&lt;br /&gt;
* [https://github.com/latchset/clevis?tab=readme-ov-file#pin-tpm2 https://github.com/latchset/clevis?tab=readme-ov-file#pin-tpm2] [3]&lt;br /&gt;
==== AppArmor Wiki (AlpineWiki) ====&lt;br /&gt;
* [https://wiki.alpinelinux.org/wiki/AppArmor AppArmor] [4]&lt;br /&gt;
==== GVisor ====&lt;br /&gt;
* [https://gvisor.dev/docs/user_guide/install/ https://gvisor.dev/docs/user_guide/install/] [5]&lt;br /&gt;
==== Gvisor Github stating docker is not a sandbox ====&lt;br /&gt;
* [https://github.com/google/gvisor?tab=readme-ov-file#why-does-gvisor-exist https://github.com/google/gvisor?tab=readme-ov-file#why-does-gvisor-exist] [6]&lt;br /&gt;
==== Android-13 Possibility of using ERO-FS: ====&lt;br /&gt;
* [https://pocketnow.com/erofs-android-13-explained/ https://pocketnow.com/erofs-android-13-explained/] [7]&lt;br /&gt;
==== DM-Verity (Arch Wiki): ====&lt;br /&gt;
* [https://wiki.archlinux.org/title/Dm-verity https://wiki.archlinux.org/title/Dm-verity] [8]&lt;br /&gt;
==== ERO-FS Github ====&lt;br /&gt;
* [https://github.com/erofs/erofs-utils https://github.com/erofs/erofs-utils] [9]&lt;br /&gt;
==== Dracut (Arch Wiki): ====&lt;br /&gt;
* [https://wiki.archlinux.org/title/Dracut https://wiki.archlinux.org/title/Dracut] [10]&lt;br /&gt;
==== Linux-Hardened Kernel (AlpineWiki): ====&lt;br /&gt;
* [https://wiki.alpinelinux.org/wiki/Hardened_linux Hardened_linux] [11]&lt;br /&gt;
==== My old post on how it worked ====&lt;br /&gt;
* [https://www.reddit.com/r/AlpineLinux/comments/15oibcc/comment/k1l7jv0/ https://www.reddit.com/r/AlpineLinux/comments/15oibcc/comment/k1l7jv0/] [12]&lt;br /&gt;
&lt;br /&gt;
[[Category:Security]] [[Category:Booting]]&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=DM-verity&amp;diff=28562</id>
		<title>DM-verity</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=DM-verity&amp;diff=28562"/>
		<updated>2024-12-23T20:20:10Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{todo| Add a non-initramfs dm-verity implementation, which should use kernel to do dm-verity checking instead of initramfs, which is better for embedded devices, and faster to boot (but hard to implement because of kernel customizations, might need to compile kernel again.)}}&lt;br /&gt;
&lt;br /&gt;
== Why DM-Verity? ==&lt;br /&gt;
Possibly you want to continue the RoT ([https://en.wikipedia.org/wiki/Chain_of_trust Root of Trust] [1]) - from the hardware (Hardware TPM as Root of Trust, which ensures only the hardware with the correct secret cryptographic key in the TPM to decrypt the disk/file encryption) -&amp;gt; secure boot (Secure Boot to only run approved signed EFIStub/signed Bootloader) -&amp;gt; &amp;lt;u&amp;gt;To NOW DM-Verity rootfs&amp;lt;/u&amp;gt; (which ensures your root-image/root-parition has not been tampered with) -&amp;gt; Mandatory Access Control (AppArmor or SELinux - SELinux is disabled on default linux-lts btw) -&amp;gt; Sandboxed/Virtual-Machined Applications.&lt;br /&gt;
&lt;br /&gt;
=== What&#039;s the difference between me just setting the root partition as read-only (basically just an Immutable Root Partition) vs this? ===&lt;br /&gt;
DM-Verity COMPLETELY disallows modifying any files in the root-partition/root-image, or even disallow a part of a root-image/root-partition (the root-image/root-partition needs to be INTACT and match the signed cryptography verified by DM-Verity on a different partition), and with this consideration, you may use ERO-FS or SquashFS to generate Read-Only Root-Paritition Images. If you set your EXT4 file system to writable, and DM-Verity were to use it, it would be seen as &amp;quot;corrupted&amp;quot; and not boot anymore, because even just ONE tiny data change to the root image/partition would render it &amp;quot;corrupted&amp;quot;. This is the same technology used in Android and Chrome OS Devices. Also related to use in A/B root, also used by Fedora.&lt;br /&gt;
&lt;br /&gt;
{{tip| To keep the security reasonable, you would ideally want to work on the whole RoT, if not then anybody else can attack the non-verifed boot process that ISN&#039;T the root-partition/root-image that is enforced by DM-Verity.&lt;br /&gt;
* This following guide will use dracut to make a signed secureboot-able EFIStub.&lt;br /&gt;
* If you haven&#039;t, you may follow [https://wiki.alpinelinux.org/wiki/LVM_on_LUKS the Alpine Linux disk encryption setup] [2] with DM-Crypt LUKS and LVM&lt;br /&gt;
* You may choose to decrypt the image with TPM when generating with Dracut Modules with &amp;lt;code&amp;gt;add_dracutdrivers+{{=}}&amp;quot; ... tpm2-tss ... &amp;quot;&amp;lt;/code&amp;gt; and [https://github.com/latchset/clevis?tab{{=}}readme-ov-file#pin-tpm2 Clevis] [3]&lt;br /&gt;
* Apply AppArmor using [https://wiki.alpinelinux.org/wiki/AppArmor Alpine Linux AppArmor Wiki] (Docker does use AppArmor already, but you may apply an AppArmor profile on any application that should not have access to specific directories (AppArmor is a PATH based MAC)) [4]&lt;br /&gt;
* Use [https://gvisor.dev/docs/user_guide/install/ GVisor] [5] with Docker ([https://github.com/google/gvisor?tab{{=}}readme-ov-file#why-does-gvisor-exist Docker is NOT a sandbox] [6] (Because docker uses native kernel compared to Gvisor using its own kernel reimplementation)) for sandboxing on servers}}&lt;br /&gt;
&lt;br /&gt;
=== What is ERO-FS? ===&lt;br /&gt;
[https://pocketnow.com/erofs-android-13-explained/ Google thought about implementing ERO-FS with DM-Verity] [7]. Google was reported to be using it in Android 13, and ERO-FS is an excellent and fast compressed read-only filesystem.&lt;br /&gt;
&lt;br /&gt;
Here is an excerpt about &amp;lt;code&amp;gt;mkfs.erofs&amp;lt;/code&amp;gt; on [[https://wiki.archlinux.org/title/Dm-verity Arch Linux Wiki]] [8]:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039; mkfs.erofs(1) offers an attractive alternative to ext4 or squashfs on the root partition. EROFS, like squashfs, does not allow writes by design and has better performance in many cases than comparable filesystems on flash and solid-state media. It uses lz4 compression by default and was designed for Android phones by Huawei, which make extensive use of dm-verity. &#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Installing ===&lt;br /&gt;
&lt;br /&gt;
==== Working with ERO-FS ====&lt;br /&gt;
&lt;br /&gt;
{{warning| This wiki will be using Alpine Linux Edge Version. (Alpine Linux Non-Edge Versions may not contain these packages in the following rest of the wiki page) (Use Alpine Linux Edge Testing Repository in &amp;lt;code&amp;gt;/etc/apk/repositories&amp;lt;/code&amp;gt; as well)}}&lt;br /&gt;
&lt;br /&gt;
{{note| To not be confused, ERO-FS generates a &amp;quot;root image&amp;quot;, but you can replace the words &amp;quot;root partition&amp;quot; with &amp;quot;root image&amp;quot; and vice versa.}}&lt;br /&gt;
&lt;br /&gt;
First, some considerations, you may use a strictly READ-ONLY file system, such as SquashFS or ERO-FS, this wiki will be using ERO-FS (if you use a custom kernel, make sure it supports a file system such as ERO-FS, the default linux-lts does). [[https://github.com/erofs/erofs-utils ERO-FS Github]] [9] contains some information about how to compress and make your own read-only root image.&lt;br /&gt;
&lt;br /&gt;
{{cmd| $ apk install erofs-utils}}&lt;br /&gt;
{{cmd| $ mkdir image &amp;amp;&amp;amp; cd image }}&lt;br /&gt;
{{cmd| $ wget https://dl-cdn.alpinelinux.org/alpine/v3.21/releases/x86_64/alpine-minirootfs-3.21.0-x86_64.tar.gz}}&lt;br /&gt;
{{cmd| $ tar -xvf alpine-minirootfs-3.21.0-x86_64.tar.gz &amp;amp;&amp;amp; rm alpine-minirootfs-3.21.0-x86_64.tar.gz}}&lt;br /&gt;
Command below will generate an ERO-FS Image compressed with lz4 as ./erofs.img (erofs.img would be the root-partition file to use for dracut)&lt;br /&gt;
{{cmd| $ cd .. &amp;amp;&amp;amp; mkfs.erofs -zlz4hc erofs.img ./image}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Working with mkinitfs/kernel-hooks/secureboot-hooks ====&lt;br /&gt;
{{todo| wip}}&lt;br /&gt;
&lt;br /&gt;
Using mkinitfs, it is possible to force veritysetup in initramfs generation. You need to make a chroot (because init script in root!!!!), and by adding these files:&lt;br /&gt;
&lt;br /&gt;
{{todo| The init script is too big to put in wiki, I just acquired it from initramfs generation and decompression}}&lt;br /&gt;
{{note| the APK package &amp;quot;cryptsetup&amp;quot; comes with veritysetup}}&lt;br /&gt;
{{note| make sure the chroot has a linux-kernel}}&lt;br /&gt;
&lt;br /&gt;
Edit /sbin/mkinitfs (put &amp;quot;# Copy custom init&amp;quot; before &amp;quot;# copy modloop signature&amp;quot;):&lt;br /&gt;
{{cat| /etc/mkinitfs|...&lt;br /&gt;
        # Copy custom init &lt;br /&gt;
        cp /initramfs/init &amp;quot;$tmpdir&amp;quot;/init &lt;br /&gt;
        &lt;br /&gt;
        # copy modloop signature&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
PUT &amp;quot;# Call custom script&amp;quot; before &amp;quot;# switch over to new root&amp;quot;&lt;br /&gt;
{{cat| /initramfs/init|...&lt;br /&gt;
# Call custom script&lt;br /&gt;
/etc/scripts/my-custom-script.sh&lt;br /&gt;
&lt;br /&gt;
# switch over to new root&lt;br /&gt;
...&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/my-custom-script.files|&lt;br /&gt;
/etc/scripts/my-custom-script.sh&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/veritysetup.files|&lt;br /&gt;
/sbin/veritysetup&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/veritysetup.modules|&lt;br /&gt;
kernel/drivers/md/dm-verity.ko*&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/erofs.modules|&lt;br /&gt;
kernel/fs/erofs&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/mkinitfs.conf|...&lt;br /&gt;
features{{=}}&amp;quot;... erofs my-custom-script&amp;quot;&lt;br /&gt;
MODULES{{=}}&amp;quot;veritysetup erofs&amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
{{cat| /etc/scripts/my-custom-script.sh|&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
mount /dev/mapper/root /root&lt;br /&gt;
mount /root/var/root/erofs.img /sysroot&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Then just do:&lt;br /&gt;
{{cmd| apk add secureboot-hook gummiboot gummiboot-efistub efibootmgr kernel-hooks secureboot-hook}}&lt;br /&gt;
&lt;br /&gt;
{{tip|To make sure initramfs has the scripts needed, do:&lt;br /&gt;
{{cmd|mkinitfs -c /etc/mkinitfs/mkinitfs.conf -b / $(uname -r)}}&lt;br /&gt;
Decompress:&lt;br /&gt;
{{cmd|mkdir /tmp/initramfs&lt;br /&gt;
cd /tmp/initramfs&lt;br /&gt;
&amp;lt;nowiki&amp;gt;zcat /boot/initramfs-$KERNEL | cpio -idmv&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Working with Dracut ====&lt;br /&gt;
&lt;br /&gt;
Remember, mount your &amp;lt;code&amp;gt;$ROOT_PARTITION&amp;lt;/code&amp;gt; as read only (assuming you use EXT4, if using ERO-FS or SquashFS, ignore this), since any changes will cause DM-Verity to detect it as &amp;quot;corrupt&amp;quot;&lt;br /&gt;
&lt;br /&gt;
{{warning| The following guide was done with FULL disk encryption, so this might not work perfectly on Non encrypted disk setup, also done on UEFI using gummiboot (now called systemd-boot - yes, systemd-boot is a separate project from the systemd init system) EFIStub and generating a UKI (Unified Kernel Image)}}&lt;br /&gt;
&lt;br /&gt;
===== Install basic stuff: =====&lt;br /&gt;
&lt;br /&gt;
{{cmd| apk add dracut dracut-core cryptsetup gummiboot gummiboot-efistub tpm2-tools clevis tpm2-tss tpm2-tss-tcti-device}}&lt;br /&gt;
&lt;br /&gt;
===== Using Clevis for TPM =====&lt;br /&gt;
&lt;br /&gt;
{{cmd| clevis luks bind -d /$ENCRYPTED_ROOT_PARTITION tpm2 &#039;{&amp;quot;pcr_ids&amp;quot;:&amp;quot;1,7&amp;quot;}&#039;}}&lt;br /&gt;
Input LUKS passphrase, remember that yes now it has tpm, but if possible remove old luks passphrase and use keyfile or different passphrase to unlock because tpm is better, and so if your computer breaks, you won&#039;t be locked out of your data!&lt;br /&gt;
&lt;br /&gt;
===== Create a new partition for your DM-Verity: =====&lt;br /&gt;
&lt;br /&gt;
Replace /dev/sdX with your actual device name.&lt;br /&gt;
{{cmd| sudo fdisk /dev/sdX}}&lt;br /&gt;
&lt;br /&gt;
Once in the fdisk interface:&lt;br /&gt;
# Press n to create a new partition&lt;br /&gt;
# Choose p for primary partition&lt;br /&gt;
# Select the partition number (e.g., 4)&lt;br /&gt;
# For the first sector, press Enter to use the default&lt;br /&gt;
# For the last sector, calculate 10% of your root partition size and use +SIZE format. For example, if your root partition is 100GB, enter +10G&lt;br /&gt;
# Press t to change the partition type&lt;br /&gt;
# Enter the partition number you just created&lt;br /&gt;
# Type 8e for Linux LVM type (closest to verity)&lt;br /&gt;
# Press w to write changes and exit&lt;br /&gt;
&lt;br /&gt;
===== Adding custom lines for full disk decryption =====&lt;br /&gt;
&lt;br /&gt;
Edit &amp;quot;&amp;lt;code&amp;gt;/usr/lib/dracut/modules.d/90crypt/cryptroot-ask.sh&amp;lt;/code&amp;gt;&amp;quot; and add these lines right BEFORE &amp;quot;&amp;lt;code&amp;gt;exit 0&amp;lt;/code&amp;gt;&amp;quot; (add your &amp;lt;code&amp;gt;$ROOT_PARTITION&amp;lt;/code&amp;gt; directory and &amp;lt;code&amp;gt;$VERITY_PARTITION&amp;lt;/code&amp;gt; directory):&lt;br /&gt;
&lt;br /&gt;
{{cat| /usr/lib/dracut/modules.d/90crypt/cryptroot-ask.sh|...&lt;br /&gt;
### DM-Verity&lt;br /&gt;
mount /dev/mapper/$ROOT_PARTITION /var/tmp&lt;br /&gt;
cryptsetup open --key-file /var/tmp/$KEYFILE_DIR /dev/$VERITY_PARTITION $VERITY_DM_NAME&lt;br /&gt;
umount /var/tmp&lt;br /&gt;
veritysetup open /dev/$ROOT_PARTITION /dev/$VERITY_PARTITION $(cat /usr/lib/dracut/roothash.txt)&lt;br /&gt;
###&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
===== Generating an EFIStub with Dracut + DM-Verity =====&lt;br /&gt;
&lt;br /&gt;
To setup DM-Verity (borrowed from [https://wiki.archlinux.org/title/Dm-verity Arch Linux Wiki]):&lt;br /&gt;
&lt;br /&gt;
{{cmd| veritysetup format /dev/$ROOT_PARTITION /dev/$VERITY_PARTITION | grep Root | cut -f2 &amp;gt;&amp;gt; /usr/lib/dracut/roothash.txt}}&lt;br /&gt;
&lt;br /&gt;
/etc/dracut.conf (put whatever your boot parameters are in &amp;quot;&amp;lt;code&amp;gt;kernel_cmdline&amp;lt;/code&amp;gt;&amp;quot;):&lt;br /&gt;
&lt;br /&gt;
{{cat| /etc/dracut.conf|...&lt;br /&gt;
kernel_cmdline{{=}}&amp;quot;&amp;quot;&lt;br /&gt;
add_dracutdrivers+{{=}}&amp;quot; busybox crypt crypt-gpg dm rootfs-block kernel-modules kernel-modules-extra tpm2-tss &amp;quot;&lt;br /&gt;
/etc/dracut.conf.d/secureboot.conf&lt;br /&gt;
&lt;br /&gt;
# Do the 3 lines below this if you have your own secureboot keys, or want to use secureboot:&lt;br /&gt;
uefi_secureboot_cert{{=}}&amp;quot;/$SECUREBOOT_KEYS_DIR/db.crt&amp;quot;&lt;br /&gt;
uefi_secureboot_key{{=}}&amp;quot;/$SECUREBOOT_KEYS_DIR/db.key&amp;quot;&lt;br /&gt;
/etc/dracut.conf.d/files.conf&lt;br /&gt;
&lt;br /&gt;
# This is what will import veritysetup binary file into dracut initramfs&lt;br /&gt;
install_items+{{=}}&amp;quot; /sbin/veritysetup &amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
Finally, generate UKI using dracut (replace &amp;lt;code&amp;gt;6.X.X-X-lts&amp;lt;/code&amp;gt; with your kernel &amp;lt;code&amp;gt;$VERSION&amp;lt;/code&amp;gt;) (also replace &amp;lt;code&amp;gt;/boot/efi/EFI/Linux/alpine-linux.efi&amp;lt;/code&amp;gt; with your mount efi partition):&lt;br /&gt;
&lt;br /&gt;
{{cmd| export DRACUT_KMODDIR_OVERRIDE{{=}}1}}&lt;br /&gt;
{{cmd| dracut --include /usr/lib/dracut/roothash.txt /usr/lib/dracut/roothash.txt --host-only --kernel-image /boot/vmlinuz-lts --kmoddir /lib/modules/6.X.X-X-lts --kver 6.X.X-X-lts --uefi --uefi-stub /usr/lib/gummiboot/linuxx64.efi.stub --force --compress lz4 /boot/efi/EFI/Linux/alpine-linux.efi /boot/efi/EFI/Linux/alpine-linux.efi}}&lt;br /&gt;
{{cmd| efibootmgr --create --disk /dev/$EFI_PARTITION --part 1 --label alpine-linux --loader EFI/Linux/alpine-linux.efi}}&lt;br /&gt;
&lt;br /&gt;
Unfortunately, using the default Alpine Linux kernel (&amp;lt;code&amp;gt;linux-lts&amp;lt;/code&amp;gt;) didn&#039;t work so download another distributions root system (like debians or devuan), and replace &amp;lt;code&amp;gt;/lib/modules/6.X.X-X-lts&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;/boot/vmlinuz-lts&amp;lt;/code&amp;gt; with anothers distributions kernel modules and kernel image (Or consider compiling your [https://wiki.alpinelinux.org/wiki/Hardened_linux own linux-hardened kernel] [11]).&lt;br /&gt;
&lt;br /&gt;
{{tip| If you want to test if DM-Verity fully works, change the &amp;lt;code&amp;gt;$ROOT_PARTITION&amp;lt;/code&amp;gt;&#039;s files and it should say it is &amp;quot;corrupt&amp;quot;, and not continue the boot process (only if you use EXT4).}}&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
==== Root of Trust/Chain of Trust ====&lt;br /&gt;
* [https://en.wikipedia.org/wiki/Chain_of_trust https://en.wikipedia.org/wiki/Chain_of_trust] [1]&lt;br /&gt;
==== Full disk encryption with LVM and LUKS (AlpineWiki): ====&lt;br /&gt;
* [https://wiki.alpinelinux.org/wiki/LVM_on_LUKS LVM_on_LUKS] [2]&lt;br /&gt;
==== Clevis Github ====&lt;br /&gt;
* [https://github.com/latchset/clevis?tab=readme-ov-file#pin-tpm2 https://github.com/latchset/clevis?tab=readme-ov-file#pin-tpm2] [3]&lt;br /&gt;
==== AppArmor Wiki (AlpineWiki) ====&lt;br /&gt;
* [https://wiki.alpinelinux.org/wiki/AppArmor AppArmor] [4]&lt;br /&gt;
==== GVisor ====&lt;br /&gt;
* [https://gvisor.dev/docs/user_guide/install/ https://gvisor.dev/docs/user_guide/install/] [5]&lt;br /&gt;
==== Gvisor Github stating docker is not a sandbox ====&lt;br /&gt;
* [https://github.com/google/gvisor?tab=readme-ov-file#why-does-gvisor-exist https://github.com/google/gvisor?tab=readme-ov-file#why-does-gvisor-exist] [6]&lt;br /&gt;
==== Android-13 Possibility of using ERO-FS: ====&lt;br /&gt;
* [https://pocketnow.com/erofs-android-13-explained/ https://pocketnow.com/erofs-android-13-explained/] [7]&lt;br /&gt;
==== DM-Verity (Arch Wiki): ====&lt;br /&gt;
* [https://wiki.archlinux.org/title/Dm-verity https://wiki.archlinux.org/title/Dm-verity] [8]&lt;br /&gt;
==== ERO-FS Github ====&lt;br /&gt;
* [https://github.com/erofs/erofs-utils https://github.com/erofs/erofs-utils] [9]&lt;br /&gt;
==== Dracut (Arch Wiki): ====&lt;br /&gt;
* [https://wiki.archlinux.org/title/Dracut https://wiki.archlinux.org/title/Dracut] [10]&lt;br /&gt;
==== Linux-Hardened Kernel (AlpineWiki): ====&lt;br /&gt;
* [https://wiki.alpinelinux.org/wiki/Hardened_linux Hardened_linux] [11]&lt;br /&gt;
==== My old post on how it worked ====&lt;br /&gt;
* [https://www.reddit.com/r/AlpineLinux/comments/15oibcc/comment/k1l7jv0/ https://www.reddit.com/r/AlpineLinux/comments/15oibcc/comment/k1l7jv0/] [12]&lt;br /&gt;
&lt;br /&gt;
[[Category:Security]] [[Category:Booting]]&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=DM-verity&amp;diff=28561</id>
		<title>DM-verity</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=DM-verity&amp;diff=28561"/>
		<updated>2024-12-23T20:15:53Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{todo| Add a non-initramfs dm-verity implementation, which should use kernel to do dm-verity checking instead of initramfs, which is better for embedded devices, and faster to boot (but hard to implement because of kernel customizations, might need to compile kernel again.)}}&lt;br /&gt;
&lt;br /&gt;
== Why DM-Verity? ==&lt;br /&gt;
Possibly you want to continue the RoT ([https://en.wikipedia.org/wiki/Chain_of_trust Root of Trust] [1]) - from the hardware (Hardware TPM as Root of Trust, which ensures only the hardware with the correct secret cryptographic key in the TPM to decrypt the disk/file encryption) -&amp;gt; secure boot (Secure Boot to only run approved signed EFIStub/signed Bootloader) -&amp;gt; &amp;lt;u&amp;gt;To NOW DM-Verity rootfs&amp;lt;/u&amp;gt; (which ensures your root-image/root-parition has not been tampered with) -&amp;gt; Mandatory Access Control (AppArmor or SELinux - SELinux is disabled on default linux-lts btw) -&amp;gt; Sandboxed/Virtual-Machined Applications.&lt;br /&gt;
&lt;br /&gt;
=== What&#039;s the difference between me just setting the root partition as read-only (basically just an Immutable Root Partition) vs this? ===&lt;br /&gt;
DM-Verity COMPLETELY disallows modifying any files in the root-partition/root-image, or even disallow a part of a root-image/root-partition (the root-image/root-partition needs to be INTACT and match the signed cryptography verified by DM-Verity on a different partition), and with this consideration, you may use ERO-FS or SquashFS to generate Read-Only Root-Paritition Images. If you set your EXT4 file system to writable, and DM-Verity were to use it, it would be seen as &amp;quot;corrupted&amp;quot; and not boot anymore, because even just ONE tiny data change to the root image/partition would render it &amp;quot;corrupted&amp;quot;. This is the same technology used in Android and Chrome OS Devices. Also related to use in A/B root, also used by Fedora.&lt;br /&gt;
&lt;br /&gt;
{{tip| To keep the security reasonable, you would ideally want to work on the whole RoT, if not then anybody else can attack the non-verifed boot process that ISN&#039;T the root-partition/root-image that is enforced by DM-Verity.&lt;br /&gt;
* This following guide will use dracut to make a signed secureboot-able EFIStub.&lt;br /&gt;
* If you haven&#039;t, you may follow [https://wiki.alpinelinux.org/wiki/LVM_on_LUKS the Alpine Linux disk encryption setup] [2] with DM-Crypt LUKS and LVM&lt;br /&gt;
* You may choose to decrypt the image with TPM when generating with Dracut Modules with &amp;lt;code&amp;gt;add_dracutdrivers+{{=}}&amp;quot; ... tpm2-tss ... &amp;quot;&amp;lt;/code&amp;gt; and [https://github.com/latchset/clevis?tab{{=}}readme-ov-file#pin-tpm2 Clevis] [3]&lt;br /&gt;
* Apply AppArmor using [https://wiki.alpinelinux.org/wiki/AppArmor Alpine Linux AppArmor Wiki] (Docker does use AppArmor already, but you may apply an AppArmor profile on any application that should not have access to specific directories (AppArmor is a PATH based MAC)) [4]&lt;br /&gt;
* Use [https://gvisor.dev/docs/user_guide/install/ GVisor] [5] with Docker ([https://github.com/google/gvisor?tab{{=}}readme-ov-file#why-does-gvisor-exist Docker is NOT a sandbox] [6] (Because docker uses native kernel compared to Gvisor using its own kernel reimplementation)) for sandboxing on servers}}&lt;br /&gt;
&lt;br /&gt;
=== What is ERO-FS? ===&lt;br /&gt;
[https://pocketnow.com/erofs-android-13-explained/ Google thought about implementing ERO-FS with DM-Verity] [7]. Google was reported to be using it in Android 13, and ERO-FS is an excellent and fast compressed read-only filesystem.&lt;br /&gt;
&lt;br /&gt;
Here is an excerpt about &amp;lt;code&amp;gt;mkfs.erofs&amp;lt;/code&amp;gt; on [[https://wiki.archlinux.org/title/Dm-verity Arch Linux Wiki]] [8]:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039; mkfs.erofs(1) offers an attractive alternative to ext4 or squashfs on the root partition. EROFS, like squashfs, does not allow writes by design and has better performance in many cases than comparable filesystems on flash and solid-state media. It uses lz4 compression by default and was designed for Android phones by Huawei, which make extensive use of dm-verity. &#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Installing ===&lt;br /&gt;
&lt;br /&gt;
==== Working with ERO-FS ====&lt;br /&gt;
&lt;br /&gt;
{{warning| This wiki will be using Alpine Linux Edge Version. (Alpine Linux Non-Edge Versions may not contain these packages in the following rest of the wiki page) (Use Alpine Linux Edge Testing Repository in &amp;lt;code&amp;gt;/etc/apk/repositories&amp;lt;/code&amp;gt; as well)}}&lt;br /&gt;
&lt;br /&gt;
{{note| To not be confused, ERO-FS generates a &amp;quot;root image&amp;quot;, but you can replace the words &amp;quot;root partition&amp;quot; with &amp;quot;root image&amp;quot; and vice versa.}}&lt;br /&gt;
&lt;br /&gt;
First, some considerations, you may use a strictly READ-ONLY file system, such as SquashFS or ERO-FS, this wiki will be using ERO-FS (if you use a custom kernel, make sure it supports a file system such as ERO-FS, the default linux-lts does). [[https://github.com/erofs/erofs-utils ERO-FS Github]] [9] contains some information about how to compress and make your own read-only root image.&lt;br /&gt;
&lt;br /&gt;
{{cmd| $ apk install erofs-utils}}&lt;br /&gt;
{{cmd| $ mkdir image &amp;amp;&amp;amp; cd image }}&lt;br /&gt;
{{cmd| $ wget https://dl-cdn.alpinelinux.org/alpine/v3.21/releases/x86_64/alpine-minirootfs-3.21.0-x86_64.tar.gz}}&lt;br /&gt;
{{cmd| $ tar -xvf alpine-minirootfs-3.21.0-x86_64.tar.gz &amp;amp;&amp;amp; rm alpine-minirootfs-3.21.0-x86_64.tar.gz}}&lt;br /&gt;
Command below will generate an ERO-FS Image compressed with lz4 as ./erofs.img (erofs.img would be the root-partition file to use for dracut)&lt;br /&gt;
{{cmd| $ cd .. &amp;amp;&amp;amp; mkfs.erofs -zlz4hc erofs.img ./image}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Working with mkinitfs/kernel-hooks/secureboot-hooks ====&lt;br /&gt;
{{todo| wip}}&lt;br /&gt;
&lt;br /&gt;
Using mkinitfs, it is possible to force veritysetup in initramfs generation. You need to make a chroot (because init script in root!!!!), and by adding these files:&lt;br /&gt;
&lt;br /&gt;
{{todo| The init script is too big to put in wiki, I just acquired it from initramfs generation and decompression}}&lt;br /&gt;
{{note| the APK package &amp;quot;cryptsetup&amp;quot; comes with veritysetup}}&lt;br /&gt;
{{note| make sure the chroot has a linux-kernel}}&lt;br /&gt;
&lt;br /&gt;
Edit /sbin/mkinitfs (put &amp;quot;# Copy custom init&amp;quot; before &amp;quot;# copy modloop signature&amp;quot;):&lt;br /&gt;
{{cat| /etc/mkinitfs|...&lt;br /&gt;
        # Copy custom init &lt;br /&gt;
        cp /initramfs/init &amp;quot;$tmpdir&amp;quot;/init &lt;br /&gt;
        &lt;br /&gt;
        # copy modloop signature&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
PUT &amp;quot;# Call custom script&amp;quot; before &amp;quot;# switch over to new root&amp;quot;&lt;br /&gt;
{{cat| /init|...&lt;br /&gt;
# Call custom script&lt;br /&gt;
/etc/scripts/my-custom-script.sh&lt;br /&gt;
&lt;br /&gt;
# switch over to new root&lt;br /&gt;
...&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/my-custom-script.files|&lt;br /&gt;
/etc/scripts/my-custom-script.sh&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/veritysetup.files|&lt;br /&gt;
/sbin/veritysetup&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/veritysetup.modules|&lt;br /&gt;
kernel/drivers/md/dm-verity.ko*&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/erofs.modules|&lt;br /&gt;
kernel/fs/erofs&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/init.files|&lt;br /&gt;
/init&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/mkinitfs.conf|...&lt;br /&gt;
features{{=}}&amp;quot;... erofs my-custom-script init&amp;quot;&lt;br /&gt;
MODULES{{=}}&amp;quot;veritysetup erofs&amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
{{cat| /etc/scripts/my-custom-script.sh|&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
mount /dev/mapper/root /root&lt;br /&gt;
mount /root/var/root/erofs.img /sysroot&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Then just do:&lt;br /&gt;
{{cmd| apk add secureboot-hook gummiboot gummiboot-efistub efibootmgr kernel-hooks secureboot-hook}}&lt;br /&gt;
&lt;br /&gt;
{{tip|To make sure initramfs has the scripts needed, do:&lt;br /&gt;
{{cmd| mkinitfs -c /etc/mkinitfs/mkinitfs.conf -b / $(uname -r)}}&lt;br /&gt;
Decompress:&lt;br /&gt;
{{cmd|mkdir /tmp/initramfs&lt;br /&gt;
cd /tmp/initramfs&lt;br /&gt;
&amp;lt;nowiki&amp;gt;zcat /boot/initramfs-$KERNEL | cpio -idmv&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Working with Dracut ====&lt;br /&gt;
&lt;br /&gt;
Remember, mount your &amp;lt;code&amp;gt;$ROOT_PARTITION&amp;lt;/code&amp;gt; as read only (assuming you use EXT4, if using ERO-FS or SquashFS, ignore this), since any changes will cause DM-Verity to detect it as &amp;quot;corrupt&amp;quot;&lt;br /&gt;
&lt;br /&gt;
{{warning| The following guide was done with FULL disk encryption, so this might not work perfectly on Non encrypted disk setup, also done on UEFI using gummiboot (now called systemd-boot - yes, systemd-boot is a separate project from the systemd init system) EFIStub and generating a UKI (Unified Kernel Image)}}&lt;br /&gt;
&lt;br /&gt;
===== Install basic stuff: =====&lt;br /&gt;
&lt;br /&gt;
{{cmd| apk add dracut dracut-core cryptsetup gummiboot gummiboot-efistub tpm2-tools clevis tpm2-tss tpm2-tss-tcti-device}}&lt;br /&gt;
&lt;br /&gt;
===== Using Clevis for TPM =====&lt;br /&gt;
&lt;br /&gt;
{{cmd| clevis luks bind -d /$ENCRYPTED_ROOT_PARTITION tpm2 &#039;{&amp;quot;pcr_ids&amp;quot;:&amp;quot;1,7&amp;quot;}&#039;}}&lt;br /&gt;
Input LUKS passphrase, remember that yes now it has tpm, but if possible remove old luks passphrase and use keyfile or different passphrase to unlock because tpm is better, and so if your computer breaks, you won&#039;t be locked out of your data!&lt;br /&gt;
&lt;br /&gt;
===== Create a new partition for your DM-Verity: =====&lt;br /&gt;
&lt;br /&gt;
Replace /dev/sdX with your actual device name.&lt;br /&gt;
{{cmd| sudo fdisk /dev/sdX}}&lt;br /&gt;
&lt;br /&gt;
Once in the fdisk interface:&lt;br /&gt;
# Press n to create a new partition&lt;br /&gt;
# Choose p for primary partition&lt;br /&gt;
# Select the partition number (e.g., 4)&lt;br /&gt;
# For the first sector, press Enter to use the default&lt;br /&gt;
# For the last sector, calculate 10% of your root partition size and use +SIZE format. For example, if your root partition is 100GB, enter +10G&lt;br /&gt;
# Press t to change the partition type&lt;br /&gt;
# Enter the partition number you just created&lt;br /&gt;
# Type 8e for Linux LVM type (closest to verity)&lt;br /&gt;
# Press w to write changes and exit&lt;br /&gt;
&lt;br /&gt;
===== Adding custom lines for full disk decryption =====&lt;br /&gt;
&lt;br /&gt;
Edit &amp;quot;&amp;lt;code&amp;gt;/usr/lib/dracut/modules.d/90crypt/cryptroot-ask.sh&amp;lt;/code&amp;gt;&amp;quot; and add these lines right BEFORE &amp;quot;&amp;lt;code&amp;gt;exit 0&amp;lt;/code&amp;gt;&amp;quot; (add your &amp;lt;code&amp;gt;$ROOT_PARTITION&amp;lt;/code&amp;gt; directory and &amp;lt;code&amp;gt;$VERITY_PARTITION&amp;lt;/code&amp;gt; directory):&lt;br /&gt;
&lt;br /&gt;
{{cat| /usr/lib/dracut/modules.d/90crypt/cryptroot-ask.sh|...&lt;br /&gt;
### DM-Verity&lt;br /&gt;
mount /dev/mapper/$ROOT_PARTITION /var/tmp&lt;br /&gt;
cryptsetup open --key-file /var/tmp/$KEYFILE_DIR /dev/$VERITY_PARTITION $VERITY_DM_NAME&lt;br /&gt;
umount /var/tmp&lt;br /&gt;
veritysetup open /dev/$ROOT_PARTITION /dev/$VERITY_PARTITION $(cat /usr/lib/dracut/roothash.txt)&lt;br /&gt;
###&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
===== Generating an EFIStub with Dracut + DM-Verity =====&lt;br /&gt;
&lt;br /&gt;
To setup DM-Verity (borrowed from [https://wiki.archlinux.org/title/Dm-verity Arch Linux Wiki]):&lt;br /&gt;
&lt;br /&gt;
{{cmd| veritysetup format /dev/$ROOT_PARTITION /dev/$VERITY_PARTITION | grep Root | cut -f2 &amp;gt;&amp;gt; /usr/lib/dracut/roothash.txt}}&lt;br /&gt;
&lt;br /&gt;
/etc/dracut.conf (put whatever your boot parameters are in &amp;quot;&amp;lt;code&amp;gt;kernel_cmdline&amp;lt;/code&amp;gt;&amp;quot;):&lt;br /&gt;
&lt;br /&gt;
{{cat| /etc/dracut.conf|...&lt;br /&gt;
kernel_cmdline{{=}}&amp;quot;&amp;quot;&lt;br /&gt;
add_dracutdrivers+{{=}}&amp;quot; busybox crypt crypt-gpg dm rootfs-block kernel-modules kernel-modules-extra tpm2-tss &amp;quot;&lt;br /&gt;
/etc/dracut.conf.d/secureboot.conf&lt;br /&gt;
&lt;br /&gt;
# Do the 3 lines below this if you have your own secureboot keys, or want to use secureboot:&lt;br /&gt;
uefi_secureboot_cert{{=}}&amp;quot;/$SECUREBOOT_KEYS_DIR/db.crt&amp;quot;&lt;br /&gt;
uefi_secureboot_key{{=}}&amp;quot;/$SECUREBOOT_KEYS_DIR/db.key&amp;quot;&lt;br /&gt;
/etc/dracut.conf.d/files.conf&lt;br /&gt;
&lt;br /&gt;
# This is what will import veritysetup binary file into dracut initramfs&lt;br /&gt;
install_items+{{=}}&amp;quot; /sbin/veritysetup &amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
Finally, generate UKI using dracut (replace &amp;lt;code&amp;gt;6.X.X-X-lts&amp;lt;/code&amp;gt; with your kernel &amp;lt;code&amp;gt;$VERSION&amp;lt;/code&amp;gt;) (also replace &amp;lt;code&amp;gt;/boot/efi/EFI/Linux/alpine-linux.efi&amp;lt;/code&amp;gt; with your mount efi partition):&lt;br /&gt;
&lt;br /&gt;
{{cmd| export DRACUT_KMODDIR_OVERRIDE{{=}}1}}&lt;br /&gt;
{{cmd| dracut --include /usr/lib/dracut/roothash.txt /usr/lib/dracut/roothash.txt --host-only --kernel-image /boot/vmlinuz-lts --kmoddir /lib/modules/6.X.X-X-lts --kver 6.X.X-X-lts --uefi --uefi-stub /usr/lib/gummiboot/linuxx64.efi.stub --force --compress lz4 /boot/efi/EFI/Linux/alpine-linux.efi /boot/efi/EFI/Linux/alpine-linux.efi}}&lt;br /&gt;
{{cmd| efibootmgr --create --disk /dev/$EFI_PARTITION --part 1 --label alpine-linux --loader EFI/Linux/alpine-linux.efi}}&lt;br /&gt;
&lt;br /&gt;
Unfortunately, using the default Alpine Linux kernel (&amp;lt;code&amp;gt;linux-lts&amp;lt;/code&amp;gt;) didn&#039;t work so download another distributions root system (like debians or devuan), and replace &amp;lt;code&amp;gt;/lib/modules/6.X.X-X-lts&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;/boot/vmlinuz-lts&amp;lt;/code&amp;gt; with anothers distributions kernel modules and kernel image (Or consider compiling your [https://wiki.alpinelinux.org/wiki/Hardened_linux own linux-hardened kernel] [11]).&lt;br /&gt;
&lt;br /&gt;
{{tip| If you want to test if DM-Verity fully works, change the &amp;lt;code&amp;gt;$ROOT_PARTITION&amp;lt;/code&amp;gt;&#039;s files and it should say it is &amp;quot;corrupt&amp;quot;, and not continue the boot process (only if you use EXT4).}}&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
==== Root of Trust/Chain of Trust ====&lt;br /&gt;
* [https://en.wikipedia.org/wiki/Chain_of_trust https://en.wikipedia.org/wiki/Chain_of_trust] [1]&lt;br /&gt;
==== Full disk encryption with LVM and LUKS (AlpineWiki): ====&lt;br /&gt;
* [https://wiki.alpinelinux.org/wiki/LVM_on_LUKS LVM_on_LUKS] [2]&lt;br /&gt;
==== Clevis Github ====&lt;br /&gt;
* [https://github.com/latchset/clevis?tab=readme-ov-file#pin-tpm2 https://github.com/latchset/clevis?tab=readme-ov-file#pin-tpm2] [3]&lt;br /&gt;
==== AppArmor Wiki (AlpineWiki) ====&lt;br /&gt;
* [https://wiki.alpinelinux.org/wiki/AppArmor AppArmor] [4]&lt;br /&gt;
==== GVisor ====&lt;br /&gt;
* [https://gvisor.dev/docs/user_guide/install/ https://gvisor.dev/docs/user_guide/install/] [5]&lt;br /&gt;
==== Gvisor Github stating docker is not a sandbox ====&lt;br /&gt;
* [https://github.com/google/gvisor?tab=readme-ov-file#why-does-gvisor-exist https://github.com/google/gvisor?tab=readme-ov-file#why-does-gvisor-exist] [6]&lt;br /&gt;
==== Android-13 Possibility of using ERO-FS: ====&lt;br /&gt;
* [https://pocketnow.com/erofs-android-13-explained/ https://pocketnow.com/erofs-android-13-explained/] [7]&lt;br /&gt;
==== DM-Verity (Arch Wiki): ====&lt;br /&gt;
* [https://wiki.archlinux.org/title/Dm-verity https://wiki.archlinux.org/title/Dm-verity] [8]&lt;br /&gt;
==== ERO-FS Github ====&lt;br /&gt;
* [https://github.com/erofs/erofs-utils https://github.com/erofs/erofs-utils] [9]&lt;br /&gt;
==== Dracut (Arch Wiki): ====&lt;br /&gt;
* [https://wiki.archlinux.org/title/Dracut https://wiki.archlinux.org/title/Dracut] [10]&lt;br /&gt;
==== Linux-Hardened Kernel (AlpineWiki): ====&lt;br /&gt;
* [https://wiki.alpinelinux.org/wiki/Hardened_linux Hardened_linux] [11]&lt;br /&gt;
==== My old post on how it worked ====&lt;br /&gt;
* [https://www.reddit.com/r/AlpineLinux/comments/15oibcc/comment/k1l7jv0/ https://www.reddit.com/r/AlpineLinux/comments/15oibcc/comment/k1l7jv0/] [12]&lt;br /&gt;
&lt;br /&gt;
[[Category:Security]] [[Category:Booting]]&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=DM-verity&amp;diff=28560</id>
		<title>DM-verity</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=DM-verity&amp;diff=28560"/>
		<updated>2024-12-23T20:13:10Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{todo| Add a non-initramfs dm-verity implementation, which should use kernel to do dm-verity checking instead of initramfs, which is better for embedded devices, and faster to boot (but hard to implement because of kernel customizations, might need to compile kernel again.)}}&lt;br /&gt;
&lt;br /&gt;
== Why DM-Verity? ==&lt;br /&gt;
Possibly you want to continue the RoT ([https://en.wikipedia.org/wiki/Chain_of_trust Root of Trust] [1]) - from the hardware (Hardware TPM as Root of Trust, which ensures only the hardware with the correct secret cryptographic key in the TPM to decrypt the disk/file encryption) -&amp;gt; secure boot (Secure Boot to only run approved signed EFIStub/signed Bootloader) -&amp;gt; &amp;lt;u&amp;gt;To NOW DM-Verity rootfs&amp;lt;/u&amp;gt; (which ensures your root-image/root-parition has not been tampered with) -&amp;gt; Mandatory Access Control (AppArmor or SELinux - SELinux is disabled on default linux-lts btw) -&amp;gt; Sandboxed/Virtual-Machined Applications.&lt;br /&gt;
&lt;br /&gt;
=== What&#039;s the difference between me just setting the root partition as read-only (basically just an Immutable Root Partition) vs this? ===&lt;br /&gt;
DM-Verity COMPLETELY disallows modifying any files in the root-partition/root-image, or even disallow a part of a root-image/root-partition (the root-image/root-partition needs to be INTACT and match the signed cryptography verified by DM-Verity on a different partition), and with this consideration, you may use ERO-FS or SquashFS to generate Read-Only Root-Paritition Images. If you set your EXT4 file system to writable, and DM-Verity were to use it, it would be seen as &amp;quot;corrupted&amp;quot; and not boot anymore, because even just ONE tiny data change to the root image/partition would render it &amp;quot;corrupted&amp;quot;. This is the same technology used in Android and Chrome OS Devices. Also related to use in A/B root, also used by Fedora.&lt;br /&gt;
&lt;br /&gt;
{{tip| To keep the security reasonable, you would ideally want to work on the whole RoT, if not then anybody else can attack the non-verifed boot process that ISN&#039;T the root-partition/root-image that is enforced by DM-Verity.&lt;br /&gt;
* This following guide will use dracut to make a signed secureboot-able EFIStub.&lt;br /&gt;
* If you haven&#039;t, you may follow [https://wiki.alpinelinux.org/wiki/LVM_on_LUKS the Alpine Linux disk encryption setup] [2] with DM-Crypt LUKS and LVM&lt;br /&gt;
* You may choose to decrypt the image with TPM when generating with Dracut Modules with &amp;lt;code&amp;gt;add_dracutdrivers+{{=}}&amp;quot; ... tpm2-tss ... &amp;quot;&amp;lt;/code&amp;gt; and [https://github.com/latchset/clevis?tab{{=}}readme-ov-file#pin-tpm2 Clevis] [3]&lt;br /&gt;
* Apply AppArmor using [https://wiki.alpinelinux.org/wiki/AppArmor Alpine Linux AppArmor Wiki] (Docker does use AppArmor already, but you may apply an AppArmor profile on any application that should not have access to specific directories (AppArmor is a PATH based MAC)) [4]&lt;br /&gt;
* Use [https://gvisor.dev/docs/user_guide/install/ GVisor] [5] with Docker ([https://github.com/google/gvisor?tab{{=}}readme-ov-file#why-does-gvisor-exist Docker is NOT a sandbox] [6] (Because docker uses native kernel compared to Gvisor using its own kernel reimplementation)) for sandboxing on servers}}&lt;br /&gt;
&lt;br /&gt;
=== What is ERO-FS? ===&lt;br /&gt;
[https://pocketnow.com/erofs-android-13-explained/ Google thought about implementing ERO-FS with DM-Verity] [7]. Google was reported to be using it in Android 13, and ERO-FS is an excellent and fast compressed read-only filesystem.&lt;br /&gt;
&lt;br /&gt;
Here is an excerpt about &amp;lt;code&amp;gt;mkfs.erofs&amp;lt;/code&amp;gt; on [[https://wiki.archlinux.org/title/Dm-verity Arch Linux Wiki]] [8]:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039; mkfs.erofs(1) offers an attractive alternative to ext4 or squashfs on the root partition. EROFS, like squashfs, does not allow writes by design and has better performance in many cases than comparable filesystems on flash and solid-state media. It uses lz4 compression by default and was designed for Android phones by Huawei, which make extensive use of dm-verity. &#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Installing ===&lt;br /&gt;
&lt;br /&gt;
==== Working with ERO-FS ====&lt;br /&gt;
&lt;br /&gt;
{{warning| This wiki will be using Alpine Linux Edge Version. (Alpine Linux Non-Edge Versions may not contain these packages in the following rest of the wiki page) (Use Alpine Linux Edge Testing Repository in &amp;lt;code&amp;gt;/etc/apk/repositories&amp;lt;/code&amp;gt; as well)}}&lt;br /&gt;
&lt;br /&gt;
{{note| To not be confused, ERO-FS generates a &amp;quot;root image&amp;quot;, but you can replace the words &amp;quot;root partition&amp;quot; with &amp;quot;root image&amp;quot; and vice versa.}}&lt;br /&gt;
&lt;br /&gt;
First, some considerations, you may use a strictly READ-ONLY file system, such as SquashFS or ERO-FS, this wiki will be using ERO-FS (if you use a custom kernel, make sure it supports a file system such as ERO-FS, the default linux-lts does). [[https://github.com/erofs/erofs-utils ERO-FS Github]] [9] contains some information about how to compress and make your own read-only root image.&lt;br /&gt;
&lt;br /&gt;
{{cmd| $ apk install erofs-utils}}&lt;br /&gt;
{{cmd| $ mkdir image &amp;amp;&amp;amp; cd image }}&lt;br /&gt;
{{cmd| $ wget https://dl-cdn.alpinelinux.org/alpine/v3.21/releases/x86_64/alpine-minirootfs-3.21.0-x86_64.tar.gz}}&lt;br /&gt;
{{cmd| $ tar -xvf alpine-minirootfs-3.21.0-x86_64.tar.gz &amp;amp;&amp;amp; rm alpine-minirootfs-3.21.0-x86_64.tar.gz}}&lt;br /&gt;
Command below will generate an ERO-FS Image compressed with lz4 as ./erofs.img (erofs.img would be the root-partition file to use for dracut)&lt;br /&gt;
{{cmd| $ cd .. &amp;amp;&amp;amp; mkfs.erofs -zlz4hc erofs.img ./image}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Working with mkinitfs/kernel-hooks/secureboot-hooks ====&lt;br /&gt;
{{todo| wip}}&lt;br /&gt;
&lt;br /&gt;
Using mkinitfs, it is possible to force veritysetup in initramfs generation. You need to make a chroot (because init script in root!!!!), and by adding these files:&lt;br /&gt;
&lt;br /&gt;
{{todo| The init script is too big to put in wiki, I just acquired it from initramfs generation and decompression}}&lt;br /&gt;
{{note| the APK package &amp;quot;cryptsetup&amp;quot; comes with veritysetup}}&lt;br /&gt;
{{note| make sure the chroot has a linux-kernel}}&lt;br /&gt;
&lt;br /&gt;
Edit /sbin/mkinitfs (put &amp;quot;# custom init for custom user scripts&amp;quot; before &amp;quot;# copy init&amp;quot;):&lt;br /&gt;
{{cat| /etc/mkinitfs|...&lt;br /&gt;
        # CUSTOM INIT FOR CUSTOM USER SCRIPTS&lt;br /&gt;
        #cp -ra /initramfs/.modloop &amp;quot;$tmpdir&amp;quot; &lt;br /&gt;
        #cp -ra /initramfs/* &amp;quot;$tmpdir&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        # copy init&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
PUT &amp;quot;# Call custom script&amp;quot; before &amp;quot;# switch over to new root&amp;quot;&lt;br /&gt;
{{cat| /init|...&lt;br /&gt;
# Call custom script&lt;br /&gt;
/etc/scripts/my-custom-script.sh&lt;br /&gt;
&lt;br /&gt;
# switch over to new root&lt;br /&gt;
...&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/my-custom-script.files|&lt;br /&gt;
/etc/scripts/my-custom-script.sh&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/veritysetup.files|&lt;br /&gt;
/sbin/veritysetup&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/veritysetup.modules|&lt;br /&gt;
kernel/drivers/md/dm-verity.ko*&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/erofs.modules|&lt;br /&gt;
kernel/fs/erofs&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/init.files|&lt;br /&gt;
/init&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/mkinitfs.conf|...&lt;br /&gt;
features{{=}}&amp;quot;... erofs my-custom-script init&amp;quot;&lt;br /&gt;
MODULES{{=}}&amp;quot;veritysetup erofs&amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
{{cat| /etc/scripts/my-custom-script.sh|&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
mount /dev/mapper/root /root&lt;br /&gt;
mount /root/var/root/erofs.img /sysroot&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Then just do:&lt;br /&gt;
{{cmd| apk add secureboot-hook gummiboot gummiboot-efistub efibootmgr kernel-hooks secureboot-hook}}&lt;br /&gt;
&lt;br /&gt;
{{tip|To make sure initramfs has the scripts needed, do:&lt;br /&gt;
{{cmd| mkinitfs -c /etc/mkinitfs/mkinitfs.conf -b / $(uname -r)}}&lt;br /&gt;
Decompress:&lt;br /&gt;
{{cmd|mkdir /tmp/initramfs&lt;br /&gt;
cd /tmp/initramfs&lt;br /&gt;
&amp;lt;nowiki&amp;gt;zcat /boot/initramfs-$KERNEL | cpio -idmv&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Working with Dracut ====&lt;br /&gt;
&lt;br /&gt;
Remember, mount your &amp;lt;code&amp;gt;$ROOT_PARTITION&amp;lt;/code&amp;gt; as read only (assuming you use EXT4, if using ERO-FS or SquashFS, ignore this), since any changes will cause DM-Verity to detect it as &amp;quot;corrupt&amp;quot;&lt;br /&gt;
&lt;br /&gt;
{{warning| The following guide was done with FULL disk encryption, so this might not work perfectly on Non encrypted disk setup, also done on UEFI using gummiboot (now called systemd-boot - yes, systemd-boot is a separate project from the systemd init system) EFIStub and generating a UKI (Unified Kernel Image)}}&lt;br /&gt;
&lt;br /&gt;
===== Install basic stuff: =====&lt;br /&gt;
&lt;br /&gt;
{{cmd| apk add dracut dracut-core cryptsetup gummiboot gummiboot-efistub tpm2-tools clevis tpm2-tss tpm2-tss-tcti-device}}&lt;br /&gt;
&lt;br /&gt;
===== Using Clevis for TPM =====&lt;br /&gt;
&lt;br /&gt;
{{cmd| clevis luks bind -d /$ENCRYPTED_ROOT_PARTITION tpm2 &#039;{&amp;quot;pcr_ids&amp;quot;:&amp;quot;1,7&amp;quot;}&#039;}}&lt;br /&gt;
Input LUKS passphrase, remember that yes now it has tpm, but if possible remove old luks passphrase and use keyfile or different passphrase to unlock because tpm is better, and so if your computer breaks, you won&#039;t be locked out of your data!&lt;br /&gt;
&lt;br /&gt;
===== Create a new partition for your DM-Verity: =====&lt;br /&gt;
&lt;br /&gt;
Replace /dev/sdX with your actual device name.&lt;br /&gt;
{{cmd| sudo fdisk /dev/sdX}}&lt;br /&gt;
&lt;br /&gt;
Once in the fdisk interface:&lt;br /&gt;
# Press n to create a new partition&lt;br /&gt;
# Choose p for primary partition&lt;br /&gt;
# Select the partition number (e.g., 4)&lt;br /&gt;
# For the first sector, press Enter to use the default&lt;br /&gt;
# For the last sector, calculate 10% of your root partition size and use +SIZE format. For example, if your root partition is 100GB, enter +10G&lt;br /&gt;
# Press t to change the partition type&lt;br /&gt;
# Enter the partition number you just created&lt;br /&gt;
# Type 8e for Linux LVM type (closest to verity)&lt;br /&gt;
# Press w to write changes and exit&lt;br /&gt;
&lt;br /&gt;
===== Adding custom lines for full disk decryption =====&lt;br /&gt;
&lt;br /&gt;
Edit &amp;quot;&amp;lt;code&amp;gt;/usr/lib/dracut/modules.d/90crypt/cryptroot-ask.sh&amp;lt;/code&amp;gt;&amp;quot; and add these lines right BEFORE &amp;quot;&amp;lt;code&amp;gt;exit 0&amp;lt;/code&amp;gt;&amp;quot; (add your &amp;lt;code&amp;gt;$ROOT_PARTITION&amp;lt;/code&amp;gt; directory and &amp;lt;code&amp;gt;$VERITY_PARTITION&amp;lt;/code&amp;gt; directory):&lt;br /&gt;
&lt;br /&gt;
{{cat| /usr/lib/dracut/modules.d/90crypt/cryptroot-ask.sh|...&lt;br /&gt;
### DM-Verity&lt;br /&gt;
mount /dev/mapper/$ROOT_PARTITION /var/tmp&lt;br /&gt;
cryptsetup open --key-file /var/tmp/$KEYFILE_DIR /dev/$VERITY_PARTITION $VERITY_DM_NAME&lt;br /&gt;
umount /var/tmp&lt;br /&gt;
veritysetup open /dev/$ROOT_PARTITION /dev/$VERITY_PARTITION $(cat /usr/lib/dracut/roothash.txt)&lt;br /&gt;
###&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
===== Generating an EFIStub with Dracut + DM-Verity =====&lt;br /&gt;
&lt;br /&gt;
To setup DM-Verity (borrowed from [https://wiki.archlinux.org/title/Dm-verity Arch Linux Wiki]):&lt;br /&gt;
&lt;br /&gt;
{{cmd| veritysetup format /dev/$ROOT_PARTITION /dev/$VERITY_PARTITION | grep Root | cut -f2 &amp;gt;&amp;gt; /usr/lib/dracut/roothash.txt}}&lt;br /&gt;
&lt;br /&gt;
/etc/dracut.conf (put whatever your boot parameters are in &amp;quot;&amp;lt;code&amp;gt;kernel_cmdline&amp;lt;/code&amp;gt;&amp;quot;):&lt;br /&gt;
&lt;br /&gt;
{{cat| /etc/dracut.conf|...&lt;br /&gt;
kernel_cmdline{{=}}&amp;quot;&amp;quot;&lt;br /&gt;
add_dracutdrivers+{{=}}&amp;quot; busybox crypt crypt-gpg dm rootfs-block kernel-modules kernel-modules-extra tpm2-tss &amp;quot;&lt;br /&gt;
/etc/dracut.conf.d/secureboot.conf&lt;br /&gt;
&lt;br /&gt;
# Do the 3 lines below this if you have your own secureboot keys, or want to use secureboot:&lt;br /&gt;
uefi_secureboot_cert{{=}}&amp;quot;/$SECUREBOOT_KEYS_DIR/db.crt&amp;quot;&lt;br /&gt;
uefi_secureboot_key{{=}}&amp;quot;/$SECUREBOOT_KEYS_DIR/db.key&amp;quot;&lt;br /&gt;
/etc/dracut.conf.d/files.conf&lt;br /&gt;
&lt;br /&gt;
# This is what will import veritysetup binary file into dracut initramfs&lt;br /&gt;
install_items+{{=}}&amp;quot; /sbin/veritysetup &amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
Finally, generate UKI using dracut (replace &amp;lt;code&amp;gt;6.X.X-X-lts&amp;lt;/code&amp;gt; with your kernel &amp;lt;code&amp;gt;$VERSION&amp;lt;/code&amp;gt;) (also replace &amp;lt;code&amp;gt;/boot/efi/EFI/Linux/alpine-linux.efi&amp;lt;/code&amp;gt; with your mount efi partition):&lt;br /&gt;
&lt;br /&gt;
{{cmd| export DRACUT_KMODDIR_OVERRIDE{{=}}1}}&lt;br /&gt;
{{cmd| dracut --include /usr/lib/dracut/roothash.txt /usr/lib/dracut/roothash.txt --host-only --kernel-image /boot/vmlinuz-lts --kmoddir /lib/modules/6.X.X-X-lts --kver 6.X.X-X-lts --uefi --uefi-stub /usr/lib/gummiboot/linuxx64.efi.stub --force --compress lz4 /boot/efi/EFI/Linux/alpine-linux.efi /boot/efi/EFI/Linux/alpine-linux.efi}}&lt;br /&gt;
{{cmd| efibootmgr --create --disk /dev/$EFI_PARTITION --part 1 --label alpine-linux --loader EFI/Linux/alpine-linux.efi}}&lt;br /&gt;
&lt;br /&gt;
Unfortunately, using the default Alpine Linux kernel (&amp;lt;code&amp;gt;linux-lts&amp;lt;/code&amp;gt;) didn&#039;t work so download another distributions root system (like debians or devuan), and replace &amp;lt;code&amp;gt;/lib/modules/6.X.X-X-lts&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;/boot/vmlinuz-lts&amp;lt;/code&amp;gt; with anothers distributions kernel modules and kernel image (Or consider compiling your [https://wiki.alpinelinux.org/wiki/Hardened_linux own linux-hardened kernel] [11]).&lt;br /&gt;
&lt;br /&gt;
{{tip| If you want to test if DM-Verity fully works, change the &amp;lt;code&amp;gt;$ROOT_PARTITION&amp;lt;/code&amp;gt;&#039;s files and it should say it is &amp;quot;corrupt&amp;quot;, and not continue the boot process (only if you use EXT4).}}&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
==== Root of Trust/Chain of Trust ====&lt;br /&gt;
* [https://en.wikipedia.org/wiki/Chain_of_trust https://en.wikipedia.org/wiki/Chain_of_trust] [1]&lt;br /&gt;
==== Full disk encryption with LVM and LUKS (AlpineWiki): ====&lt;br /&gt;
* [https://wiki.alpinelinux.org/wiki/LVM_on_LUKS LVM_on_LUKS] [2]&lt;br /&gt;
==== Clevis Github ====&lt;br /&gt;
* [https://github.com/latchset/clevis?tab=readme-ov-file#pin-tpm2 https://github.com/latchset/clevis?tab=readme-ov-file#pin-tpm2] [3]&lt;br /&gt;
==== AppArmor Wiki (AlpineWiki) ====&lt;br /&gt;
* [https://wiki.alpinelinux.org/wiki/AppArmor AppArmor] [4]&lt;br /&gt;
==== GVisor ====&lt;br /&gt;
* [https://gvisor.dev/docs/user_guide/install/ https://gvisor.dev/docs/user_guide/install/] [5]&lt;br /&gt;
==== Gvisor Github stating docker is not a sandbox ====&lt;br /&gt;
* [https://github.com/google/gvisor?tab=readme-ov-file#why-does-gvisor-exist https://github.com/google/gvisor?tab=readme-ov-file#why-does-gvisor-exist] [6]&lt;br /&gt;
==== Android-13 Possibility of using ERO-FS: ====&lt;br /&gt;
* [https://pocketnow.com/erofs-android-13-explained/ https://pocketnow.com/erofs-android-13-explained/] [7]&lt;br /&gt;
==== DM-Verity (Arch Wiki): ====&lt;br /&gt;
* [https://wiki.archlinux.org/title/Dm-verity https://wiki.archlinux.org/title/Dm-verity] [8]&lt;br /&gt;
==== ERO-FS Github ====&lt;br /&gt;
* [https://github.com/erofs/erofs-utils https://github.com/erofs/erofs-utils] [9]&lt;br /&gt;
==== Dracut (Arch Wiki): ====&lt;br /&gt;
* [https://wiki.archlinux.org/title/Dracut https://wiki.archlinux.org/title/Dracut] [10]&lt;br /&gt;
==== Linux-Hardened Kernel (AlpineWiki): ====&lt;br /&gt;
* [https://wiki.alpinelinux.org/wiki/Hardened_linux Hardened_linux] [11]&lt;br /&gt;
==== My old post on how it worked ====&lt;br /&gt;
* [https://www.reddit.com/r/AlpineLinux/comments/15oibcc/comment/k1l7jv0/ https://www.reddit.com/r/AlpineLinux/comments/15oibcc/comment/k1l7jv0/] [12]&lt;br /&gt;
&lt;br /&gt;
[[Category:Security]] [[Category:Booting]]&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=DM-verity&amp;diff=28559</id>
		<title>DM-verity</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=DM-verity&amp;diff=28559"/>
		<updated>2024-12-23T20:12:34Z</updated>

		<summary type="html">&lt;p&gt;Pursuable1652: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{todo| Add a non-initramfs dm-verity implementation, which should use kernel to do dm-verity checking instead of initramfs, which is better for embedded devices, and faster to boot (but hard to implement because of kernel customizations, might need to compile kernel again.)}}&lt;br /&gt;
&lt;br /&gt;
== Why DM-Verity? ==&lt;br /&gt;
Possibly you want to continue the RoT ([https://en.wikipedia.org/wiki/Chain_of_trust Root of Trust] [1]) - from the hardware (Hardware TPM as Root of Trust, which ensures only the hardware with the correct secret cryptographic key in the TPM to decrypt the disk/file encryption) -&amp;gt; secure boot (Secure Boot to only run approved signed EFIStub/signed Bootloader) -&amp;gt; &amp;lt;u&amp;gt;To NOW DM-Verity rootfs&amp;lt;/u&amp;gt; (which ensures your root-image/root-parition has not been tampered with) -&amp;gt; Mandatory Access Control (AppArmor or SELinux - SELinux is disabled on default linux-lts btw) -&amp;gt; Sandboxed/Virtual-Machined Applications.&lt;br /&gt;
&lt;br /&gt;
=== What&#039;s the difference between me just setting the root partition as read-only (basically just an Immutable Root Partition) vs this? ===&lt;br /&gt;
DM-Verity COMPLETELY disallows modifying any files in the root-partition/root-image, or even disallow a part of a root-image/root-partition (the root-image/root-partition needs to be INTACT and match the signed cryptography verified by DM-Verity on a different partition), and with this consideration, you may use ERO-FS or SquashFS to generate Read-Only Root-Paritition Images. If you set your EXT4 file system to writable, and DM-Verity were to use it, it would be seen as &amp;quot;corrupted&amp;quot; and not boot anymore, because even just ONE tiny data change to the root image/partition would render it &amp;quot;corrupted&amp;quot;. This is the same technology used in Android and Chrome OS Devices. Also related to use in A/B root, also used by Fedora.&lt;br /&gt;
&lt;br /&gt;
{{tip| To keep the security reasonable, you would ideally want to work on the whole RoT, if not then anybody else can attack the non-verifed boot process that ISN&#039;T the root-partition/root-image that is enforced by DM-Verity.&lt;br /&gt;
* This following guide will use dracut to make a signed secureboot-able EFIStub.&lt;br /&gt;
* If you haven&#039;t, you may follow [https://wiki.alpinelinux.org/wiki/LVM_on_LUKS the Alpine Linux disk encryption setup] [2] with DM-Crypt LUKS and LVM&lt;br /&gt;
* You may choose to decrypt the image with TPM when generating with Dracut Modules with &amp;lt;code&amp;gt;add_dracutdrivers+{{=}}&amp;quot; ... tpm2-tss ... &amp;quot;&amp;lt;/code&amp;gt; and [https://github.com/latchset/clevis?tab{{=}}readme-ov-file#pin-tpm2 Clevis] [3]&lt;br /&gt;
* Apply AppArmor using [https://wiki.alpinelinux.org/wiki/AppArmor Alpine Linux AppArmor Wiki] (Docker does use AppArmor already, but you may apply an AppArmor profile on any application that should not have access to specific directories (AppArmor is a PATH based MAC)) [4]&lt;br /&gt;
* Use [https://gvisor.dev/docs/user_guide/install/ GVisor] [5] with Docker ([https://github.com/google/gvisor?tab{{=}}readme-ov-file#why-does-gvisor-exist Docker is NOT a sandbox] [6] (Because docker uses native kernel compared to Gvisor using its own kernel reimplementation)) for sandboxing on servers}}&lt;br /&gt;
&lt;br /&gt;
=== What is ERO-FS? ===&lt;br /&gt;
[https://pocketnow.com/erofs-android-13-explained/ Google thought about implementing ERO-FS with DM-Verity] [7]. Google was reported to be using it in Android 13, and ERO-FS is an excellent and fast compressed read-only filesystem.&lt;br /&gt;
&lt;br /&gt;
Here is an excerpt about &amp;lt;code&amp;gt;mkfs.erofs&amp;lt;/code&amp;gt; on [[https://wiki.archlinux.org/title/Dm-verity Arch Linux Wiki]] [8]:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039; mkfs.erofs(1) offers an attractive alternative to ext4 or squashfs on the root partition. EROFS, like squashfs, does not allow writes by design and has better performance in many cases than comparable filesystems on flash and solid-state media. It uses lz4 compression by default and was designed for Android phones by Huawei, which make extensive use of dm-verity. &#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== Installing ===&lt;br /&gt;
&lt;br /&gt;
==== Working with ERO-FS ====&lt;br /&gt;
&lt;br /&gt;
{{warning| This wiki will be using Alpine Linux Edge Version. (Alpine Linux Non-Edge Versions may not contain these packages in the following rest of the wiki page) (Use Alpine Linux Edge Testing Repository in &amp;lt;code&amp;gt;/etc/apk/repositories&amp;lt;/code&amp;gt; as well)}}&lt;br /&gt;
&lt;br /&gt;
{{note| To not be confused, ERO-FS generates a &amp;quot;root image&amp;quot;, but you can replace the words &amp;quot;root partition&amp;quot; with &amp;quot;root image&amp;quot; and vice versa.}}&lt;br /&gt;
&lt;br /&gt;
First, some considerations, you may use a strictly READ-ONLY file system, such as SquashFS or ERO-FS, this wiki will be using ERO-FS (if you use a custom kernel, make sure it supports a file system such as ERO-FS, the default linux-lts does). [[https://github.com/erofs/erofs-utils ERO-FS Github]] [9] contains some information about how to compress and make your own read-only root image.&lt;br /&gt;
&lt;br /&gt;
{{cmd| $ apk install erofs-utils}}&lt;br /&gt;
{{cmd| $ mkdir image &amp;amp;&amp;amp; cd image }}&lt;br /&gt;
{{cmd| $ wget https://dl-cdn.alpinelinux.org/alpine/v3.21/releases/x86_64/alpine-minirootfs-3.21.0-x86_64.tar.gz}}&lt;br /&gt;
{{cmd| $ tar -xvf alpine-minirootfs-3.21.0-x86_64.tar.gz &amp;amp;&amp;amp; rm alpine-minirootfs-3.21.0-x86_64.tar.gz}}&lt;br /&gt;
Command below will generate an ERO-FS Image compressed with lz4 as ./erofs.img (erofs.img would be the root-partition file to use for dracut)&lt;br /&gt;
{{cmd| $ cd .. &amp;amp;&amp;amp; mkfs.erofs -zlz4hc erofs.img ./image}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Working with mkinitfs/kernel-hooks/secureboot-hooks ====&lt;br /&gt;
{{todo| wip}}&lt;br /&gt;
&lt;br /&gt;
Using mkinitfs, it is possible to force veritysetup in initramfs generation. You need to make a chroot (because init script in root!!!!), and by adding these files:&lt;br /&gt;
&lt;br /&gt;
{{todo| The init script is too big to put in wiki, I just acquired it from initramfs generation and decompression}}&lt;br /&gt;
{{note| the APK package &amp;quot;cryptsetup&amp;quot; comes with veritysetup}}&lt;br /&gt;
{{note| make sure the chroot has a linux-kernel}}&lt;br /&gt;
&lt;br /&gt;
edit /sbin/mkinitfs:&lt;br /&gt;
{{cat| /etc/mkinitfs|...&lt;br /&gt;
        # CUSTOM INIT FOR CUSTOM USER SCRIPTS&lt;br /&gt;
        #cp -ra /initramfs/.modloop &amp;quot;$tmpdir&amp;quot; &lt;br /&gt;
        #cp -ra /initramfs/* &amp;quot;$tmpdir&amp;quot;&lt;br /&gt;
&lt;br /&gt;
        # copy init&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
PUT &amp;quot;# Call custom script&amp;quot; before &amp;quot;# switch over to new root&amp;quot;&lt;br /&gt;
{{cat| /init|...&lt;br /&gt;
# Call custom script&lt;br /&gt;
/etc/scripts/my-custom-script.sh&lt;br /&gt;
&lt;br /&gt;
# switch over to new root&lt;br /&gt;
...&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/my-custom-script.files|&lt;br /&gt;
/etc/scripts/my-custom-script.sh&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/veritysetup.files|&lt;br /&gt;
/sbin/veritysetup&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/veritysetup.modules|&lt;br /&gt;
kernel/drivers/md/dm-verity.ko*&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/erofs.modules|&lt;br /&gt;
kernel/fs/erofs&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/features.d/init.files|&lt;br /&gt;
/init&lt;br /&gt;
}}&lt;br /&gt;
{{cat| /etc/mkinitfs/mkinitfs.conf|...&lt;br /&gt;
features{{=}}&amp;quot;... erofs my-custom-script init&amp;quot;&lt;br /&gt;
MODULES{{=}}&amp;quot;veritysetup erofs&amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
{{cat| /etc/scripts/my-custom-script.sh|&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
mount /dev/mapper/root /root&lt;br /&gt;
mount /root/var/root/erofs.img /sysroot&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Then just do:&lt;br /&gt;
{{cmd| apk add secureboot-hook gummiboot gummiboot-efistub efibootmgr kernel-hooks secureboot-hook}}&lt;br /&gt;
&lt;br /&gt;
{{tip|To make sure initramfs has the scripts needed, do:&lt;br /&gt;
{{cmd| mkinitfs -c /etc/mkinitfs/mkinitfs.conf -b / $(uname -r)}}&lt;br /&gt;
Decompress:&lt;br /&gt;
{{cmd|mkdir /tmp/initramfs&lt;br /&gt;
cd /tmp/initramfs&lt;br /&gt;
&amp;lt;nowiki&amp;gt;zcat /boot/initramfs-$KERNEL | cpio -idmv&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Working with Dracut ====&lt;br /&gt;
&lt;br /&gt;
Remember, mount your &amp;lt;code&amp;gt;$ROOT_PARTITION&amp;lt;/code&amp;gt; as read only (assuming you use EXT4, if using ERO-FS or SquashFS, ignore this), since any changes will cause DM-Verity to detect it as &amp;quot;corrupt&amp;quot;&lt;br /&gt;
&lt;br /&gt;
{{warning| The following guide was done with FULL disk encryption, so this might not work perfectly on Non encrypted disk setup, also done on UEFI using gummiboot (now called systemd-boot - yes, systemd-boot is a separate project from the systemd init system) EFIStub and generating a UKI (Unified Kernel Image)}}&lt;br /&gt;
&lt;br /&gt;
===== Install basic stuff: =====&lt;br /&gt;
&lt;br /&gt;
{{cmd| apk add dracut dracut-core cryptsetup gummiboot gummiboot-efistub tpm2-tools clevis tpm2-tss tpm2-tss-tcti-device}}&lt;br /&gt;
&lt;br /&gt;
===== Using Clevis for TPM =====&lt;br /&gt;
&lt;br /&gt;
{{cmd| clevis luks bind -d /$ENCRYPTED_ROOT_PARTITION tpm2 &#039;{&amp;quot;pcr_ids&amp;quot;:&amp;quot;1,7&amp;quot;}&#039;}}&lt;br /&gt;
Input LUKS passphrase, remember that yes now it has tpm, but if possible remove old luks passphrase and use keyfile or different passphrase to unlock because tpm is better, and so if your computer breaks, you won&#039;t be locked out of your data!&lt;br /&gt;
&lt;br /&gt;
===== Create a new partition for your DM-Verity: =====&lt;br /&gt;
&lt;br /&gt;
Replace /dev/sdX with your actual device name.&lt;br /&gt;
{{cmd| sudo fdisk /dev/sdX}}&lt;br /&gt;
&lt;br /&gt;
Once in the fdisk interface:&lt;br /&gt;
# Press n to create a new partition&lt;br /&gt;
# Choose p for primary partition&lt;br /&gt;
# Select the partition number (e.g., 4)&lt;br /&gt;
# For the first sector, press Enter to use the default&lt;br /&gt;
# For the last sector, calculate 10% of your root partition size and use +SIZE format. For example, if your root partition is 100GB, enter +10G&lt;br /&gt;
# Press t to change the partition type&lt;br /&gt;
# Enter the partition number you just created&lt;br /&gt;
# Type 8e for Linux LVM type (closest to verity)&lt;br /&gt;
# Press w to write changes and exit&lt;br /&gt;
&lt;br /&gt;
===== Adding custom lines for full disk decryption =====&lt;br /&gt;
&lt;br /&gt;
Edit &amp;quot;&amp;lt;code&amp;gt;/usr/lib/dracut/modules.d/90crypt/cryptroot-ask.sh&amp;lt;/code&amp;gt;&amp;quot; and add these lines right BEFORE &amp;quot;&amp;lt;code&amp;gt;exit 0&amp;lt;/code&amp;gt;&amp;quot; (add your &amp;lt;code&amp;gt;$ROOT_PARTITION&amp;lt;/code&amp;gt; directory and &amp;lt;code&amp;gt;$VERITY_PARTITION&amp;lt;/code&amp;gt; directory):&lt;br /&gt;
&lt;br /&gt;
{{cat| /usr/lib/dracut/modules.d/90crypt/cryptroot-ask.sh|...&lt;br /&gt;
### DM-Verity&lt;br /&gt;
mount /dev/mapper/$ROOT_PARTITION /var/tmp&lt;br /&gt;
cryptsetup open --key-file /var/tmp/$KEYFILE_DIR /dev/$VERITY_PARTITION $VERITY_DM_NAME&lt;br /&gt;
umount /var/tmp&lt;br /&gt;
veritysetup open /dev/$ROOT_PARTITION /dev/$VERITY_PARTITION $(cat /usr/lib/dracut/roothash.txt)&lt;br /&gt;
###&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
===== Generating an EFIStub with Dracut + DM-Verity =====&lt;br /&gt;
&lt;br /&gt;
To setup DM-Verity (borrowed from [https://wiki.archlinux.org/title/Dm-verity Arch Linux Wiki]):&lt;br /&gt;
&lt;br /&gt;
{{cmd| veritysetup format /dev/$ROOT_PARTITION /dev/$VERITY_PARTITION | grep Root | cut -f2 &amp;gt;&amp;gt; /usr/lib/dracut/roothash.txt}}&lt;br /&gt;
&lt;br /&gt;
/etc/dracut.conf (put whatever your boot parameters are in &amp;quot;&amp;lt;code&amp;gt;kernel_cmdline&amp;lt;/code&amp;gt;&amp;quot;):&lt;br /&gt;
&lt;br /&gt;
{{cat| /etc/dracut.conf|...&lt;br /&gt;
kernel_cmdline{{=}}&amp;quot;&amp;quot;&lt;br /&gt;
add_dracutdrivers+{{=}}&amp;quot; busybox crypt crypt-gpg dm rootfs-block kernel-modules kernel-modules-extra tpm2-tss &amp;quot;&lt;br /&gt;
/etc/dracut.conf.d/secureboot.conf&lt;br /&gt;
&lt;br /&gt;
# Do the 3 lines below this if you have your own secureboot keys, or want to use secureboot:&lt;br /&gt;
uefi_secureboot_cert{{=}}&amp;quot;/$SECUREBOOT_KEYS_DIR/db.crt&amp;quot;&lt;br /&gt;
uefi_secureboot_key{{=}}&amp;quot;/$SECUREBOOT_KEYS_DIR/db.key&amp;quot;&lt;br /&gt;
/etc/dracut.conf.d/files.conf&lt;br /&gt;
&lt;br /&gt;
# This is what will import veritysetup binary file into dracut initramfs&lt;br /&gt;
install_items+{{=}}&amp;quot; /sbin/veritysetup &amp;quot;&lt;br /&gt;
...}}&lt;br /&gt;
&lt;br /&gt;
Finally, generate UKI using dracut (replace &amp;lt;code&amp;gt;6.X.X-X-lts&amp;lt;/code&amp;gt; with your kernel &amp;lt;code&amp;gt;$VERSION&amp;lt;/code&amp;gt;) (also replace &amp;lt;code&amp;gt;/boot/efi/EFI/Linux/alpine-linux.efi&amp;lt;/code&amp;gt; with your mount efi partition):&lt;br /&gt;
&lt;br /&gt;
{{cmd| export DRACUT_KMODDIR_OVERRIDE{{=}}1}}&lt;br /&gt;
{{cmd| dracut --include /usr/lib/dracut/roothash.txt /usr/lib/dracut/roothash.txt --host-only --kernel-image /boot/vmlinuz-lts --kmoddir /lib/modules/6.X.X-X-lts --kver 6.X.X-X-lts --uefi --uefi-stub /usr/lib/gummiboot/linuxx64.efi.stub --force --compress lz4 /boot/efi/EFI/Linux/alpine-linux.efi /boot/efi/EFI/Linux/alpine-linux.efi}}&lt;br /&gt;
{{cmd| efibootmgr --create --disk /dev/$EFI_PARTITION --part 1 --label alpine-linux --loader EFI/Linux/alpine-linux.efi}}&lt;br /&gt;
&lt;br /&gt;
Unfortunately, using the default Alpine Linux kernel (&amp;lt;code&amp;gt;linux-lts&amp;lt;/code&amp;gt;) didn&#039;t work so download another distributions root system (like debians or devuan), and replace &amp;lt;code&amp;gt;/lib/modules/6.X.X-X-lts&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;/boot/vmlinuz-lts&amp;lt;/code&amp;gt; with anothers distributions kernel modules and kernel image (Or consider compiling your [https://wiki.alpinelinux.org/wiki/Hardened_linux own linux-hardened kernel] [11]).&lt;br /&gt;
&lt;br /&gt;
{{tip| If you want to test if DM-Verity fully works, change the &amp;lt;code&amp;gt;$ROOT_PARTITION&amp;lt;/code&amp;gt;&#039;s files and it should say it is &amp;quot;corrupt&amp;quot;, and not continue the boot process (only if you use EXT4).}}&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
==== Root of Trust/Chain of Trust ====&lt;br /&gt;
* [https://en.wikipedia.org/wiki/Chain_of_trust https://en.wikipedia.org/wiki/Chain_of_trust] [1]&lt;br /&gt;
==== Full disk encryption with LVM and LUKS (AlpineWiki): ====&lt;br /&gt;
* [https://wiki.alpinelinux.org/wiki/LVM_on_LUKS LVM_on_LUKS] [2]&lt;br /&gt;
==== Clevis Github ====&lt;br /&gt;
* [https://github.com/latchset/clevis?tab=readme-ov-file#pin-tpm2 https://github.com/latchset/clevis?tab=readme-ov-file#pin-tpm2] [3]&lt;br /&gt;
==== AppArmor Wiki (AlpineWiki) ====&lt;br /&gt;
* [https://wiki.alpinelinux.org/wiki/AppArmor AppArmor] [4]&lt;br /&gt;
==== GVisor ====&lt;br /&gt;
* [https://gvisor.dev/docs/user_guide/install/ https://gvisor.dev/docs/user_guide/install/] [5]&lt;br /&gt;
==== Gvisor Github stating docker is not a sandbox ====&lt;br /&gt;
* [https://github.com/google/gvisor?tab=readme-ov-file#why-does-gvisor-exist https://github.com/google/gvisor?tab=readme-ov-file#why-does-gvisor-exist] [6]&lt;br /&gt;
==== Android-13 Possibility of using ERO-FS: ====&lt;br /&gt;
* [https://pocketnow.com/erofs-android-13-explained/ https://pocketnow.com/erofs-android-13-explained/] [7]&lt;br /&gt;
==== DM-Verity (Arch Wiki): ====&lt;br /&gt;
* [https://wiki.archlinux.org/title/Dm-verity https://wiki.archlinux.org/title/Dm-verity] [8]&lt;br /&gt;
==== ERO-FS Github ====&lt;br /&gt;
* [https://github.com/erofs/erofs-utils https://github.com/erofs/erofs-utils] [9]&lt;br /&gt;
==== Dracut (Arch Wiki): ====&lt;br /&gt;
* [https://wiki.archlinux.org/title/Dracut https://wiki.archlinux.org/title/Dracut] [10]&lt;br /&gt;
==== Linux-Hardened Kernel (AlpineWiki): ====&lt;br /&gt;
* [https://wiki.alpinelinux.org/wiki/Hardened_linux Hardened_linux] [11]&lt;br /&gt;
==== My old post on how it worked ====&lt;br /&gt;
* [https://www.reddit.com/r/AlpineLinux/comments/15oibcc/comment/k1l7jv0/ https://www.reddit.com/r/AlpineLinux/comments/15oibcc/comment/k1l7jv0/] [12]&lt;br /&gt;
&lt;br /&gt;
[[Category:Security]] [[Category:Booting]]&lt;/div&gt;</summary>
		<author><name>Pursuable1652</name></author>
	</entry>
</feed>