<?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=Harpia</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=Harpia"/>
	<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/wiki/Special:Contributions/Harpia"/>
	<updated>2026-04-30T11:43:54Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.40.0</generator>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Raspberry_Pi_LVM_on_LUKS&amp;diff=32349</id>
		<title>Raspberry Pi LVM on LUKS</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Raspberry_Pi_LVM_on_LUKS&amp;diff=32349"/>
		<updated>2026-04-30T01:20:10Z</updated>

		<summary type="html">&lt;p&gt;Harpia: Clarify the &amp;quot;Boot the Installer&amp;quot; instructions&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Installing Alpine on an encrypted root article complements the existing installation instructions for Raspberry Pi, providing only the needed changes that enable booting from an encrypted media. Use it only as a reference, not as a complete walk-through for installation.&lt;br /&gt;
&lt;br /&gt;
==Prepare the Installation Media==&lt;br /&gt;
Write the downloaded image or tarball to a disk. In this example, this bootable disk (referred to as &#039;&#039;/dev/sda&#039;&#039;) will be used as a read-only installation media. The target root disk is referred to as &#039;&#039;/dev/sdb&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Boot the Installer==&lt;br /&gt;
Insert the installation disk into the pi and turn it on. To make sure it boots the right device, unplug any other storage media.&lt;br /&gt;
&lt;br /&gt;
Once Alpine is initialized, log in and perform a &amp;quot;diskless installation&amp;quot; with &amp;lt;code&amp;gt;setup-alpine&amp;lt;/code&amp;gt;. Next, we will setup the disk manually.&lt;br /&gt;
&lt;br /&gt;
==Disk Setup==&lt;br /&gt;
Plug in the disk to be used as the encrypted root. A tool such as &amp;lt;code&amp;gt;lsblk&amp;lt;/code&amp;gt; gives you an overview of all disks available. In this example, the new disk becomes &#039;&#039;/dev/sdb&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Create a bootable FAT32 partition (&#039;&#039;/dev/sdb1&#039;&#039;) that will hold the unencrypted &#039;&#039;/boot&#039;&#039;, and then a larger Linux partition (&#039;&#039;/dev/sdb2&#039;&#039;) that will hold the LVM physical volume. Important: if you plan to [[Raspberry_Pi_LVM_on_LUKS#Optional:_Decrypt_with_a_Keyfile|decrypt with a keydisk]], create the &#039;&#039;/boot&#039;&#039; partition on the keydisk instead.&lt;br /&gt;
&lt;br /&gt;
Install the necessary packages:&lt;br /&gt;
{{cmd|apk add cryptsetup lvm2}}&lt;br /&gt;
&lt;br /&gt;
Encrypt the Linux partition with one of the following:&lt;br /&gt;
{{cmd|cryptsetup luksFormat /dev/sdb2    # Raspberry Pi 5}}&lt;br /&gt;
{{cmd|cryptsetup luksFormat -c xchacha12,aes-adiantum-plain64 /dev/sdb2    # Raspberry Pi 4 and older}}&lt;br /&gt;
&lt;br /&gt;
At this point you can follow the [[LVM_on_LUKS#Creating_the_Logical_Volumes_and_File_Systems|LVM on LUKS page]] to create and format the LVM volumes.&lt;br /&gt;
&lt;br /&gt;
Mount the new root partition at &#039;&#039;/mnt&#039;&#039;, the boot partition at &#039;&#039;/mnt/boot&#039;&#039; (after creating the directory), then run &#039;&#039;setup-disk&#039;&#039; like this:&lt;br /&gt;
{{cmd|setup-disk -m sys /mnt}}&lt;br /&gt;
&lt;br /&gt;
==Verify the Installation==&lt;br /&gt;
&#039;&#039;setup-disk&#039;&#039; should setup most things for us, but it&#039;s a good idea to inspect some critical files to avoid ending up with a system that won&#039;t boot.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a list of files to check:&lt;br /&gt;
* &#039;&#039;/etc/mkinitfs/mkinitfs.conf&#039;&#039; should have the features &amp;lt;code&amp;gt;lvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;cryptsetup&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &#039;&#039;/boot/cmdline.txt&#039;&#039; should contain the following options: &amp;lt;code&amp;gt;root=/dev/vg0/root cryptroot=UUID=&amp;lt;encrypted_disk_uuid&amp;gt; cryptdm=root&amp;lt;/code&amp;gt;&lt;br /&gt;
* &#039;&#039;/etc/fstab&#039;&#039; should have a line for &amp;lt;code&amp;gt;/dev/vg0/root&amp;lt;/code&amp;gt; (and any other LVM volumes), and &amp;lt;code&amp;gt;/boot&amp;lt;/code&amp;gt; (by UUID).&lt;br /&gt;
&lt;br /&gt;
Finally, a friendly reminder: save a backup of that LUKS header (see &amp;lt;code&amp;gt;cryptsetup-luksHeaderBackup(8)&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
==Optional: Decrypt with a Keyfile==&lt;br /&gt;
The &amp;quot;keydisk&amp;quot; — a storage device used as a decryption key — is a convenient method to enable full-disk encryption, especially for a headless server. Unfortunately, &#039;&#039;mkinitfs&#039;&#039; does not yet support decryption keys on external devices, but there is a [https://gitlab.alpinelinux.org/alpine/mkinitfs/-/merge_requests/108 pending merge request] to implement it, as well as a decent workaround: move the entire &#039;&#039;/boot&#039;&#039; partition onto a separate device.&lt;br /&gt;
&lt;br /&gt;
This assumes you&#039;ve already booted a passphrase-encrypted Alpine installation, but you can include this as part of the installation procedure.&lt;br /&gt;
&lt;br /&gt;
===Create the keyfile===&lt;br /&gt;
&lt;br /&gt;
A keyfile can be created with &#039;&#039;dd&#039;&#039;:&lt;br /&gt;
{{cmd|dd if{{=}}/dev/urandom of{{=}}/crypto_keyfile.bin bs{{=}}1M count{{=}}1}}&lt;br /&gt;
&lt;br /&gt;
Make it read-only, owner only:&lt;br /&gt;
{{cmd|chmod 400 /crypto_keyfile.bin}}&lt;br /&gt;
&lt;br /&gt;
Add the keyfile to the LUKS header:&lt;br /&gt;
{{cmd|cryptsetup luksAddKey /dev/sdb2 /crypto_keyfile.bin}}&lt;br /&gt;
&lt;br /&gt;
===Prepare the Initramfs===&lt;br /&gt;
&lt;br /&gt;
The root disk decryption takes place in the temporary environment called &#039;&#039;initramfs&#039;&#039;. &#039;&#039;mkinitfs&#039;&#039; will copy your keyfile into the initramfs filesystem, and place it in the exact same path it was copied from (e.g. &#039;&#039;/boot/cryptkey&#039;&#039;, &#039;&#039;/var/root.key&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
The default path is &amp;lt;code&amp;gt;/crypto_keyfile.bin&amp;lt;/code&amp;gt;, but you can change it by editing &amp;lt;code&amp;gt;/etc/mkinitfs/features.d/cryptkey.files&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The path to the keyfile must also be passed as a kernel command-line option in &amp;lt;code&amp;gt;/boot/cmdline.txt&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cryptkey=/crypto_keyfile.bin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Enable the necessary features in &amp;lt;code&amp;gt;/etc/mkinitfs/mkinitfs.conf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
features=&amp;quot;... cryptsetup cryptkey&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Regenerate the [[Initramfs_init|initramfs]]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkinitfs -c /etc/mkinitfs/mkinitfs.conf -b /&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [[Raspberry Pi|Raspberry Pi - Installation]] &#039;&#039;(diskless-mode installation)&#039;&#039;&lt;br /&gt;
* [[Classic install or sys mode on Raspberry Pi|Raspberry Pi - Sys mode install]] &#039;&#039;(sys-mode installation)&#039;&#039;&lt;br /&gt;
* [[LVM_on_LUKS|LVM on LUKS]] &#039;&#039;(encryption and LVM, but beware not everything applies to the pi)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[[Category:Storage]]&lt;br /&gt;
[[Category:Security]]&lt;br /&gt;
[[Category:Raspberry]]&lt;/div&gt;</summary>
		<author><name>Harpia</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Raspberry_Pi_LVM_on_LUKS&amp;diff=32348</id>
		<title>Raspberry Pi LVM on LUKS</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Raspberry_Pi_LVM_on_LUKS&amp;diff=32348"/>
		<updated>2026-04-29T21:37:33Z</updated>

		<summary type="html">&lt;p&gt;Harpia: Fix &amp;quot;em dash&amp;quot; character&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Installing Alpine on an encrypted root article complements the existing installation instructions for Raspberry Pi, providing only the needed changes that enable booting from an encrypted media. Use it only as a reference, not as a complete walk-through for installation.&lt;br /&gt;
&lt;br /&gt;
==Prepare the Installation Media==&lt;br /&gt;
Write the downloaded image or tarball to a disk. In this example, this bootable disk (referred to as &#039;&#039;/dev/sda&#039;&#039;) will be used as a read-only installation media. The target root disk is referred to as &#039;&#039;/dev/sdb&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Boot the Installer==&lt;br /&gt;
Insert the bootable disk we created earlier into the pi, and boot from it. Login and perform a &amp;quot;diskless installation&amp;quot; with &amp;lt;code&amp;gt;setup-alpine&amp;lt;/code&amp;gt;. We will setup the disk manually.&lt;br /&gt;
&lt;br /&gt;
==Disk setup==&lt;br /&gt;
Plug in the disk to be used as the encrypted root. A tool such as &amp;lt;code&amp;gt;lsblk&amp;lt;/code&amp;gt; gives you an overview of all disks available. In this example, the new disk becomes &#039;&#039;/dev/sdb&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Create a bootable FAT32 partition (&#039;&#039;/dev/sdb1&#039;&#039;) that will hold the unencrypted &#039;&#039;/boot&#039;&#039;, and then a larger Linux partition (&#039;&#039;/dev/sdb2&#039;&#039;) that will hold the LVM physical volume. Important: if you plan to [[Raspberry_Pi_LVM_on_LUKS#Optional:_Decrypt_with_a_Keyfile|decrypt with a keydisk]], create the &#039;&#039;/boot&#039;&#039; partition on the keydisk instead.&lt;br /&gt;
&lt;br /&gt;
Install the necessary packages:&lt;br /&gt;
{{cmd|apk add cryptsetup lvm2}}&lt;br /&gt;
&lt;br /&gt;
Encrypt the Linux partition with one of the following:&lt;br /&gt;
{{cmd|cryptsetup luksFormat /dev/sdb2    # Raspberry Pi 5}}&lt;br /&gt;
{{cmd|cryptsetup luksFormat -c xchacha12,aes-adiantum-plain64 /dev/sdb2    # Raspberry Pi 4 and older}}&lt;br /&gt;
&lt;br /&gt;
At this point you can follow the [[LVM_on_LUKS#Creating_the_Logical_Volumes_and_File_Systems|LVM on LUKS page]] to create and format the LVM volumes.&lt;br /&gt;
&lt;br /&gt;
Mount the new root partition at &#039;&#039;/mnt&#039;&#039;, the boot partition at &#039;&#039;/mnt/boot&#039;&#039; (after creating the directory), then run &#039;&#039;setup-disk&#039;&#039; like this:&lt;br /&gt;
{{cmd|setup-disk -m sys /mnt}}&lt;br /&gt;
&lt;br /&gt;
==Verify the Installation==&lt;br /&gt;
&#039;&#039;setup-disk&#039;&#039; should setup most things for us, but it&#039;s a good idea to inspect some critical files to avoid ending up with a system that won&#039;t boot.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a list of files to check:&lt;br /&gt;
* &#039;&#039;/etc/mkinitfs/mkinitfs.conf&#039;&#039; should have the features &amp;lt;code&amp;gt;lvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;cryptsetup&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &#039;&#039;/boot/cmdline.txt&#039;&#039; should contain the following options: &amp;lt;code&amp;gt;root=/dev/vg0/root cryptroot=UUID=&amp;lt;encrypted_disk_uuid&amp;gt; cryptdm=root&amp;lt;/code&amp;gt;&lt;br /&gt;
* &#039;&#039;/etc/fstab&#039;&#039; should have a line for &amp;lt;code&amp;gt;/dev/vg0/root&amp;lt;/code&amp;gt; (and any other LVM volumes), and &amp;lt;code&amp;gt;/boot&amp;lt;/code&amp;gt; (by UUID).&lt;br /&gt;
&lt;br /&gt;
Finally, a friendly reminder: save a backup of that LUKS header (see &amp;lt;code&amp;gt;cryptsetup-luksHeaderBackup(8)&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
==Optional: Decrypt with a Keyfile==&lt;br /&gt;
The &amp;quot;keydisk&amp;quot; — a storage device used as a decryption key — is a convenient method to enable full-disk encryption, especially for a headless server. Unfortunately, &#039;&#039;mkinitfs&#039;&#039; does not yet support decryption keys on external devices, but there is a [https://gitlab.alpinelinux.org/alpine/mkinitfs/-/merge_requests/108 pending merge request] to implement it, as well as a decent workaround: move the entire &#039;&#039;/boot&#039;&#039; partition onto a separate device.&lt;br /&gt;
&lt;br /&gt;
This assumes you&#039;ve already booted a passphrase-encrypted Alpine installation, but you can include this as part of the installation procedure.&lt;br /&gt;
&lt;br /&gt;
===Create the keyfile===&lt;br /&gt;
&lt;br /&gt;
A keyfile can be created with &#039;&#039;dd&#039;&#039;:&lt;br /&gt;
{{cmd|dd if{{=}}/dev/urandom of{{=}}/crypto_keyfile.bin bs{{=}}1M count{{=}}1}}&lt;br /&gt;
&lt;br /&gt;
Make it read-only, owner only:&lt;br /&gt;
{{cmd|chmod 400 /crypto_keyfile.bin}}&lt;br /&gt;
&lt;br /&gt;
Add the keyfile to the LUKS header:&lt;br /&gt;
{{cmd|cryptsetup luksAddKey /dev/sdb2 /crypto_keyfile.bin}}&lt;br /&gt;
&lt;br /&gt;
===Prepare the Initramfs===&lt;br /&gt;
&lt;br /&gt;
The root disk decryption takes place in the temporary environment called &#039;&#039;initramfs&#039;&#039;. &#039;&#039;mkinitfs&#039;&#039; will copy your keyfile into the initramfs filesystem, and place it in the exact same path it was copied from (e.g. &#039;&#039;/boot/cryptkey&#039;&#039;, &#039;&#039;/var/root.key&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
The default path is &amp;lt;code&amp;gt;/crypto_keyfile.bin&amp;lt;/code&amp;gt;, but you can change it by editing &amp;lt;code&amp;gt;/etc/mkinitfs/features.d/cryptkey.files&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The path to the keyfile must also be passed as a kernel command-line option in &amp;lt;code&amp;gt;/boot/cmdline.txt&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cryptkey=/crypto_keyfile.bin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Enable the necessary features in &amp;lt;code&amp;gt;/etc/mkinitfs/mkinitfs.conf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
features=&amp;quot;... cryptsetup cryptkey&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Regenerate the [[Initramfs_init|initramfs]]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkinitfs -c /etc/mkinitfs/mkinitfs.conf -b /&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [[Raspberry Pi|Raspberry Pi - Installation]] &#039;&#039;(diskless-mode installation)&#039;&#039;&lt;br /&gt;
* [[Classic install or sys mode on Raspberry Pi|Raspberry Pi - Sys mode install]] &#039;&#039;(sys-mode installation)&#039;&#039;&lt;br /&gt;
* [[LVM_on_LUKS|LVM on LUKS]] &#039;&#039;(encryption and LVM, but beware not everything applies to the pi)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[[Category:Storage]]&lt;br /&gt;
[[Category:Security]]&lt;br /&gt;
[[Category:Raspberry]]&lt;/div&gt;</summary>
		<author><name>Harpia</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Raspberry_Pi_LVM_on_LUKS&amp;diff=32347</id>
		<title>Raspberry Pi LVM on LUKS</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Raspberry_Pi_LVM_on_LUKS&amp;diff=32347"/>
		<updated>2026-04-29T21:31:38Z</updated>

		<summary type="html">&lt;p&gt;Harpia: Add link to the section for keydisk decryption&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Installing Alpine on an encrypted root article complements the existing installation instructions for Raspberry Pi, providing only the needed changes that enable booting from an encrypted media. Use it only as a reference, not as a complete walk-through for installation.&lt;br /&gt;
&lt;br /&gt;
==Prepare the Installation Media==&lt;br /&gt;
Write the downloaded image or tarball to a disk. In this example, this bootable disk (referred to as &#039;&#039;/dev/sda&#039;&#039;) will be used as a read-only installation media. The target root disk is referred to as &#039;&#039;/dev/sdb&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Boot the Installer==&lt;br /&gt;
Insert the bootable disk we created earlier into the pi, and boot from it. Login and perform a &amp;quot;diskless installation&amp;quot; with &amp;lt;code&amp;gt;setup-alpine&amp;lt;/code&amp;gt;. We will setup the disk manually.&lt;br /&gt;
&lt;br /&gt;
==Disk setup==&lt;br /&gt;
Plug in the disk to be used as the encrypted root. A tool such as &amp;lt;code&amp;gt;lsblk&amp;lt;/code&amp;gt; gives you an overview of all disks available. In this example, the new disk becomes &#039;&#039;/dev/sdb&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Create a bootable FAT32 partition (&#039;&#039;/dev/sdb1&#039;&#039;) that will hold the unencrypted &#039;&#039;/boot&#039;&#039;, and then a larger Linux partition (&#039;&#039;/dev/sdb2&#039;&#039;) that will hold the LVM physical volume. Important: if you plan to [[Raspberry_Pi_LVM_on_LUKS#Optional:_Decrypt_with_a_Keyfile|decrypt with a keydisk]], create the &#039;&#039;/boot&#039;&#039; partition on the keydisk instead.&lt;br /&gt;
&lt;br /&gt;
Install the necessary packages:&lt;br /&gt;
{{cmd|apk add cryptsetup lvm2}}&lt;br /&gt;
&lt;br /&gt;
Encrypt the Linux partition with one of the following:&lt;br /&gt;
{{cmd|cryptsetup luksFormat /dev/sdb2    # Raspberry Pi 5}}&lt;br /&gt;
{{cmd|cryptsetup luksFormat -c xchacha12,aes-adiantum-plain64 /dev/sdb2    # Raspberry Pi 4 and older}}&lt;br /&gt;
&lt;br /&gt;
At this point you can follow the [[LVM_on_LUKS#Creating_the_Logical_Volumes_and_File_Systems|LVM on LUKS page]] to create and format the LVM volumes.&lt;br /&gt;
&lt;br /&gt;
Mount the new root partition at &#039;&#039;/mnt&#039;&#039;, the boot partition at &#039;&#039;/mnt/boot&#039;&#039; (after creating the directory), then run &#039;&#039;setup-disk&#039;&#039; like this:&lt;br /&gt;
{{cmd|setup-disk -m sys /mnt}}&lt;br /&gt;
&lt;br /&gt;
==Verify the Installation==&lt;br /&gt;
&#039;&#039;setup-disk&#039;&#039; should setup most things for us, but it&#039;s a good idea to inspect some critical files to avoid ending up with a system that won&#039;t boot.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a list of files to check:&lt;br /&gt;
* &#039;&#039;/etc/mkinitfs/mkinitfs.conf&#039;&#039; should have the features &amp;lt;code&amp;gt;lvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;cryptsetup&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &#039;&#039;/boot/cmdline.txt&#039;&#039; should contain the following options: &amp;lt;code&amp;gt;root=/dev/vg0/root cryptroot=UUID=&amp;lt;encrypted_disk_uuid&amp;gt; cryptdm=root&amp;lt;/code&amp;gt;&lt;br /&gt;
* &#039;&#039;/etc/fstab&#039;&#039; should have a line for &amp;lt;code&amp;gt;/dev/vg0/root&amp;lt;/code&amp;gt; (and any other LVM volumes), and &amp;lt;code&amp;gt;/boot&amp;lt;/code&amp;gt; (by UUID).&lt;br /&gt;
&lt;br /&gt;
Finally, a friendly reminder: save a backup of that LUKS header (see &amp;lt;code&amp;gt;cryptsetup-luksHeaderBackup(8)&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
==Optional: Decrypt with a Keyfile==&lt;br /&gt;
The &amp;quot;keydisk&amp;quot; - a storage device used as a decryption key — is a convenient method to enable full-disk encryption, especially for a headless server. Unfortunately, &#039;&#039;mkinitfs&#039;&#039; does not yet support decryption keys on external devices, but there is a [https://gitlab.alpinelinux.org/alpine/mkinitfs/-/merge_requests/108 pending merge request] to implement it, as well as a decent workaround: move the entire &#039;&#039;/boot&#039;&#039; partition onto a separate device.&lt;br /&gt;
&lt;br /&gt;
This assumes you&#039;ve already booted a passphrase-encrypted Alpine installation, but you can include this as part of the installation procedure.&lt;br /&gt;
&lt;br /&gt;
===Create the keyfile===&lt;br /&gt;
&lt;br /&gt;
A keyfile can be created with &#039;&#039;dd&#039;&#039;:&lt;br /&gt;
{{cmd|dd if{{=}}/dev/urandom of{{=}}/crypto_keyfile.bin bs{{=}}1M count{{=}}1}}&lt;br /&gt;
&lt;br /&gt;
Make it read-only, owner only:&lt;br /&gt;
{{cmd|chmod 400 /crypto_keyfile.bin}}&lt;br /&gt;
&lt;br /&gt;
Add the keyfile to the LUKS header:&lt;br /&gt;
{{cmd|cryptsetup luksAddKey /dev/sdb2 /crypto_keyfile.bin}}&lt;br /&gt;
&lt;br /&gt;
===Prepare the Initramfs===&lt;br /&gt;
&lt;br /&gt;
The root disk decryption takes place in the temporary environment called &#039;&#039;initramfs&#039;&#039;. &#039;&#039;mkinitfs&#039;&#039; will copy your keyfile into the initramfs filesystem, and place it in the exact same path it was copied from (e.g. &#039;&#039;/boot/cryptkey&#039;&#039;, &#039;&#039;/var/root.key&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
The default path is &amp;lt;code&amp;gt;/crypto_keyfile.bin&amp;lt;/code&amp;gt;, but you can change it by editing &amp;lt;code&amp;gt;/etc/mkinitfs/features.d/cryptkey.files&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The path to the keyfile must also be passed as a kernel command-line option in &amp;lt;code&amp;gt;/boot/cmdline.txt&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cryptkey=/crypto_keyfile.bin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Enable the necessary features in &amp;lt;code&amp;gt;/etc/mkinitfs/mkinitfs.conf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
features=&amp;quot;... cryptsetup cryptkey&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Regenerate the [[Initramfs_init|initramfs]]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkinitfs -c /etc/mkinitfs/mkinitfs.conf -b /&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [[Raspberry Pi|Raspberry Pi - Installation]] &#039;&#039;(diskless-mode installation)&#039;&#039;&lt;br /&gt;
* [[Classic install or sys mode on Raspberry Pi|Raspberry Pi - Sys mode install]] &#039;&#039;(sys-mode installation)&#039;&#039;&lt;br /&gt;
* [[LVM_on_LUKS|LVM on LUKS]] &#039;&#039;(encryption and LVM, but beware not everything applies to the pi)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[[Category:Storage]]&lt;br /&gt;
[[Category:Security]]&lt;br /&gt;
[[Category:Raspberry]]&lt;/div&gt;</summary>
		<author><name>Harpia</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Raspberry_Pi_LVM_on_LUKS&amp;diff=32346</id>
		<title>Raspberry Pi LVM on LUKS</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Raspberry_Pi_LVM_on_LUKS&amp;diff=32346"/>
		<updated>2026-04-29T21:24:21Z</updated>

		<summary type="html">&lt;p&gt;Harpia: Rephrase and clarify some lines regarding keydisks&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Installing Alpine on an encrypted root article complements the existing installation instructions for Raspberry Pi, providing only the needed changes that enable booting from an encrypted media. Use it only as a reference, not as a complete walk-through for installation.&lt;br /&gt;
&lt;br /&gt;
==Prepare the Installation Media==&lt;br /&gt;
Write the downloaded image or tarball to a disk. In this example, this bootable disk (referred to as &#039;&#039;/dev/sda&#039;&#039;) will be used as a read-only installation media. The target root disk is referred to as &#039;&#039;/dev/sdb&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Boot the Installer==&lt;br /&gt;
Insert the bootable disk we created earlier into the pi, and boot from it. Login and perform a &amp;quot;diskless installation&amp;quot; with &amp;lt;code&amp;gt;setup-alpine&amp;lt;/code&amp;gt;. We will setup the disk manually.&lt;br /&gt;
&lt;br /&gt;
==Disk setup==&lt;br /&gt;
Plug in the disk to be used as the encrypted root. A tool such as &amp;lt;code&amp;gt;lsblk&amp;lt;/code&amp;gt; gives you an overview of all disks available. In this example, the new disk becomes &#039;&#039;/dev/sdb&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Create a bootable FAT32 partition (&#039;&#039;/dev/sdb1&#039;&#039;) that will hold the unencrypted &#039;&#039;/boot&#039;&#039;, and then a larger Linux partition (&#039;&#039;/dev/sdb2&#039;&#039;) that will hold the LVM physical volume. Important: if you plan to decrypt with a keydisk, create the &#039;&#039;/boot&#039;&#039; partition on the keydisk instead.&lt;br /&gt;
&lt;br /&gt;
Install the necessary packages:&lt;br /&gt;
{{cmd|apk add cryptsetup lvm2}}&lt;br /&gt;
&lt;br /&gt;
Encrypt the Linux partition with one of the following:&lt;br /&gt;
{{cmd|cryptsetup luksFormat /dev/sdb2    # Raspberry Pi 5}}&lt;br /&gt;
{{cmd|cryptsetup luksFormat -c xchacha12,aes-adiantum-plain64 /dev/sdb2    # Raspberry Pi 4 and older}}&lt;br /&gt;
&lt;br /&gt;
At this point you can follow the [[LVM_on_LUKS#Creating_the_Logical_Volumes_and_File_Systems|LVM on LUKS page]] to create and format the LVM volumes.&lt;br /&gt;
&lt;br /&gt;
Mount the new root partition at &#039;&#039;/mnt&#039;&#039;, the boot partition at &#039;&#039;/mnt/boot&#039;&#039; (after creating the directory), then run &#039;&#039;setup-disk&#039;&#039; like this:&lt;br /&gt;
{{cmd|setup-disk -m sys /mnt}}&lt;br /&gt;
&lt;br /&gt;
==Verify the Installation==&lt;br /&gt;
&#039;&#039;setup-disk&#039;&#039; should setup most things for us, but it&#039;s a good idea to inspect some critical files to avoid ending up with a system that won&#039;t boot.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a list of files to check:&lt;br /&gt;
* &#039;&#039;/etc/mkinitfs/mkinitfs.conf&#039;&#039; should have the features &amp;lt;code&amp;gt;lvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;cryptsetup&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &#039;&#039;/boot/cmdline.txt&#039;&#039; should contain the following options: &amp;lt;code&amp;gt;root=/dev/vg0/root cryptroot=UUID=&amp;lt;encrypted_disk_uuid&amp;gt; cryptdm=root&amp;lt;/code&amp;gt;&lt;br /&gt;
* &#039;&#039;/etc/fstab&#039;&#039; should have a line for &amp;lt;code&amp;gt;/dev/vg0/root&amp;lt;/code&amp;gt; (and any other LVM volumes), and &amp;lt;code&amp;gt;/boot&amp;lt;/code&amp;gt; (by UUID).&lt;br /&gt;
&lt;br /&gt;
Finally, a friendly reminder: save a backup of that LUKS header (see &amp;lt;code&amp;gt;cryptsetup-luksHeaderBackup(8)&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
==Optional: Decrypt with a Keyfile==&lt;br /&gt;
The &amp;quot;keydisk&amp;quot; - a storage device used as a decryption key — is a convenient method to enable full-disk encryption, especially for a headless server. Unfortunately, &#039;&#039;mkinitfs&#039;&#039; does not yet support decryption keys on external devices, but there is a [https://gitlab.alpinelinux.org/alpine/mkinitfs/-/merge_requests/108 pending merge request] to implement it, as well as a decent workaround: move the entire &#039;&#039;/boot&#039;&#039; partition onto a separate device.&lt;br /&gt;
&lt;br /&gt;
This assumes you&#039;ve already booted a passphrase-encrypted Alpine installation, but you can include this as part of the installation procedure.&lt;br /&gt;
&lt;br /&gt;
===Create the keyfile===&lt;br /&gt;
&lt;br /&gt;
A keyfile can be created with &#039;&#039;dd&#039;&#039;:&lt;br /&gt;
{{cmd|dd if{{=}}/dev/urandom of{{=}}/crypto_keyfile.bin bs{{=}}1M count{{=}}1}}&lt;br /&gt;
&lt;br /&gt;
Make it read-only, owner only:&lt;br /&gt;
{{cmd|chmod 400 /crypto_keyfile.bin}}&lt;br /&gt;
&lt;br /&gt;
Add the keyfile to the LUKS header:&lt;br /&gt;
{{cmd|cryptsetup luksAddKey /dev/sdb2 /crypto_keyfile.bin}}&lt;br /&gt;
&lt;br /&gt;
===Prepare the Initramfs===&lt;br /&gt;
&lt;br /&gt;
The root disk decryption takes place in the temporary environment called &#039;&#039;initramfs&#039;&#039;. &#039;&#039;mkinitfs&#039;&#039; will copy your keyfile into the initramfs filesystem, and place it in the exact same path it was copied from (e.g. &#039;&#039;/boot/cryptkey&#039;&#039;, &#039;&#039;/var/root.key&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
The default path is &amp;lt;code&amp;gt;/crypto_keyfile.bin&amp;lt;/code&amp;gt;, but you can change it by editing &amp;lt;code&amp;gt;/etc/mkinitfs/features.d/cryptkey.files&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The path to the keyfile must also be passed as a kernel command-line option in &amp;lt;code&amp;gt;/boot/cmdline.txt&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cryptkey=/crypto_keyfile.bin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Enable the necessary features in &amp;lt;code&amp;gt;/etc/mkinitfs/mkinitfs.conf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
features=&amp;quot;... cryptsetup cryptkey&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Regenerate the [[Initramfs_init|initramfs]]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkinitfs -c /etc/mkinitfs/mkinitfs.conf -b /&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [[Raspberry Pi|Raspberry Pi - Installation]] &#039;&#039;(diskless-mode installation)&#039;&#039;&lt;br /&gt;
* [[Classic install or sys mode on Raspberry Pi|Raspberry Pi - Sys mode install]] &#039;&#039;(sys-mode installation)&#039;&#039;&lt;br /&gt;
* [[LVM_on_LUKS|LVM on LUKS]] &#039;&#039;(encryption and LVM, but beware not everything applies to the pi)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[[Category:Storage]]&lt;br /&gt;
[[Category:Security]]&lt;br /&gt;
[[Category:Raspberry]]&lt;/div&gt;</summary>
		<author><name>Harpia</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Raspberry_Pi_LVM_on_LUKS&amp;diff=32345</id>
		<title>Raspberry Pi LVM on LUKS</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Raspberry_Pi_LVM_on_LUKS&amp;diff=32345"/>
		<updated>2026-04-29T19:30:13Z</updated>

		<summary type="html">&lt;p&gt;Harpia: Remove detailed bootable disk creation from a tarball, as writing an .img works and is easier. Fix section header indentation in the keyfile instructions.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Installing Alpine on an encrypted root article complements the existing installation instructions for Raspberry Pi, providing only the needed changes that enable booting from an encrypted media. Use it only as a reference, not as a complete walk-through for installation.&lt;br /&gt;
&lt;br /&gt;
==Prepare the Installation Media==&lt;br /&gt;
Write the downloaded image or tarball to a disk. In this example, this bootable disk (referred to as &#039;&#039;/dev/sda&#039;&#039;) will be used as a read-only installation media. The target root disk is referred to as &#039;&#039;/dev/sdb&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Boot the Installer==&lt;br /&gt;
Insert the bootable disk we created earlier into the pi, and boot from it. Login and perform a &amp;quot;diskless installation&amp;quot; with &amp;lt;code&amp;gt;setup-alpine&amp;lt;/code&amp;gt;. We will setup the disk manually.&lt;br /&gt;
&lt;br /&gt;
==Disk setup==&lt;br /&gt;
Plug in the disk to be used as the encrypted root. A tool such as &amp;lt;code&amp;gt;lsblk&amp;lt;/code&amp;gt; gives you an overview of all disks available. In this example, the new disk becomes &#039;&#039;/dev/sdb&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Create a bootable FAT32 partition (&#039;&#039;/dev/sdb1&#039;&#039;) that will hold the unencrypted &#039;&#039;/boot&#039;&#039;, and then a larger Linux partition (&#039;&#039;/dev/sdb2&#039;&#039;) that will hold the LVM physical volume.&lt;br /&gt;
&lt;br /&gt;
Install the necessary packages:&lt;br /&gt;
{{cmd|apk add cryptsetup lvm2}}&lt;br /&gt;
&lt;br /&gt;
Encrypt the Linux partition with one of the following:&lt;br /&gt;
{{cmd|cryptsetup luksFormat /dev/sdb2    # Raspberry Pi 5}}&lt;br /&gt;
{{cmd|cryptsetup luksFormat -c xchacha12,aes-adiantum-plain64 /dev/sdb2    # Raspberry Pi 4 and older}}&lt;br /&gt;
&lt;br /&gt;
At this point you can follow the [[LVM_on_LUKS#Creating_the_Logical_Volumes_and_File_Systems|LVM on LUKS page]] to create and format the LVM volumes.&lt;br /&gt;
&lt;br /&gt;
Mount the new root partition at &#039;&#039;/mnt&#039;&#039;, the boot partition at &#039;&#039;/mnt/boot&#039;&#039; (after creating the directory), then run &#039;&#039;setup-disk&#039;&#039; like this:&lt;br /&gt;
{{cmd|setup-disk -m sys /mnt}}&lt;br /&gt;
&lt;br /&gt;
==Verify the Installation==&lt;br /&gt;
&#039;&#039;setup-disk&#039;&#039; should setup most things for us, but it&#039;s a good idea to inspect some critical files to avoid ending up with a system that won&#039;t boot.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a list of files to check:&lt;br /&gt;
* &#039;&#039;/etc/mkinitfs/mkinitfs.conf&#039;&#039; should have the features &amp;lt;code&amp;gt;lvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;cryptsetup&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &#039;&#039;/boot/cmdline.txt&#039;&#039; should contain the following options: &amp;lt;code&amp;gt;root=/dev/vg0/root cryptroot=UUID=&amp;lt;encrypted_disk_uuid&amp;gt; cryptdm=root&amp;lt;/code&amp;gt;&lt;br /&gt;
* &#039;&#039;/etc/fstab&#039;&#039; should have a line for &amp;lt;code&amp;gt;/dev/vg0/root&amp;lt;/code&amp;gt; (and any other LVM volumes), and &amp;lt;code&amp;gt;/boot&amp;lt;/code&amp;gt; (by UUID).&lt;br /&gt;
&lt;br /&gt;
Finally, a friendly reminder: save a backup of that LUKS header (see &amp;lt;code&amp;gt;cryptsetup-luksHeaderBackup(8)&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
==Optional: Decrypt with a Keyfile==&lt;br /&gt;
The &amp;quot;keydisk&amp;quot; - a storage device used as a decryption key — is a convenient method to enable full-disk encryption, especially for a headless server. Unfortunately, this functionality is not yet supported, but there is a [https://gitlab.alpinelinux.org/alpine/mkinitfs/-/merge_requests/108 pending merge request] to implement it.&lt;br /&gt;
&lt;br /&gt;
For now, we can achieve the same by moving the entire &#039;&#039;/boot&#039;&#039; partition to a separate device.&lt;br /&gt;
&lt;br /&gt;
This assumes you&#039;ve already booted a passphrase-encrypted Alpine installation, but you can include this as part of the installation procedure, and even use a keyfile alone instead of a passphrase.&lt;br /&gt;
&lt;br /&gt;
===Create the keyfile===&lt;br /&gt;
&lt;br /&gt;
A keyfile can be created with &#039;&#039;dd&#039;&#039;:&lt;br /&gt;
{{cmd|dd if{{=}}/dev/urandom of{{=}}/crypto_keyfile.bin bs{{=}}1M count{{=}}1}}&lt;br /&gt;
&lt;br /&gt;
Make it read-only, owner only:&lt;br /&gt;
{{cmd|chmod 400 /crypto_keyfile.bin}}&lt;br /&gt;
&lt;br /&gt;
Add the keyfile to the LUKS header:&lt;br /&gt;
{{cmd|cryptsetup luksAddKey /dev/sdb2 /crypto_keyfile.bin}}&lt;br /&gt;
&lt;br /&gt;
===Prepare the Initramfs===&lt;br /&gt;
&lt;br /&gt;
The root disk decryption takes place in the temporary environment called &#039;&#039;initramfs&#039;&#039;. &#039;&#039;mkinitfs&#039;&#039; will copy your keyfile into the initramfs filesystem, and place it in the exact same path it was copied from (e.g. &#039;&#039;/boot/cryptkey&#039;&#039;, &#039;&#039;/var/root.key&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
The default path is &amp;lt;code&amp;gt;/crypto_keyfile.bin&amp;lt;/code&amp;gt;, but you can change it by editing &amp;lt;code&amp;gt;/etc/mkinitfs/features.d/cryptkey.files&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The path to the keyfile must also be passed as a kernel command-line option in &amp;lt;code&amp;gt;/boot/cmdline.txt&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cryptkey=/crypto_keyfile.bin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Enable the necessary features in &amp;lt;code&amp;gt;/etc/mkinitfs/mkinitfs.conf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
features=&amp;quot;... cryptsetup cryptkey&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Regenerate the [[Initramfs_init|initramfs]]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkinitfs -c /etc/mkinitfs/mkinitfs.conf -b /&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [[Raspberry Pi|Raspberry Pi - Installation]] &#039;&#039;(diskless-mode installation)&#039;&#039;&lt;br /&gt;
* [[Classic install or sys mode on Raspberry Pi|Raspberry Pi - Sys mode install]] &#039;&#039;(sys-mode installation)&#039;&#039;&lt;br /&gt;
* [[LVM_on_LUKS|LVM on LUKS]] &#039;&#039;(encryption and LVM, but beware not everything applies to the pi)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[[Category:Storage]]&lt;br /&gt;
[[Category:Security]]&lt;br /&gt;
[[Category:Raspberry]]&lt;/div&gt;</summary>
		<author><name>Harpia</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=User_talk:Zcrayfish&amp;diff=26799</id>
		<title>User talk:Zcrayfish</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=User_talk:Zcrayfish&amp;diff=26799"/>
		<updated>2024-05-29T02:25:34Z</updated>

		<summary type="html">&lt;p&gt;Harpia: /* About &amp;quot;undo revision 26759&amp;quot; */ new section&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=== thanks for the help ===&lt;br /&gt;
thanks for the formatting help [https://wiki.alpinelinux.org/w/index.php?title=Setting_up_disks_manually&amp;amp;diff=prev&amp;amp;oldid=26562]&lt;br /&gt;
[[User:Alpinetony|&amp;lt;small style=&amp;quot;border:2px solid;border-radius:4px;padding:0 4px&amp;quot;&amp;gt;Alpinetony&amp;lt;/small&amp;gt;]] [[User talk:Alpinetony|💬]]  22:24, 4 March 2024 (UTC)&lt;br /&gt;
:any time! \o/ &amp;amp;ndash;[[User:zcrayfish|zcrayfish]] &amp;lt;small&amp;gt;([[User talk:zcrayfish|talk]]•[[Special:Contributions/zcrayfish|contribs]]•[[Special:EmailUser/zcrayfish|send email]])&amp;lt;/small&amp;gt; 08:43, 7 March 2024 (UTC)&lt;br /&gt;
&lt;br /&gt;
== About &amp;quot;undo revision 26759&amp;quot; ==&lt;br /&gt;
&lt;br /&gt;
:Revision comment does not match what was done with the page. Most content removed. Accident?&lt;br /&gt;
&lt;br /&gt;
Yes, thanks for fixing that. Damn... I pressed the &amp;quot;edit section&amp;quot; button instead of &amp;quot;edit page&amp;quot;. I thought I was editing just the section, and that the rest of the page would be untouched.&lt;/div&gt;</summary>
		<author><name>Harpia</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Raspberry_Pi_LVM_on_LUKS&amp;diff=26779</id>
		<title>Raspberry Pi LVM on LUKS</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Raspberry_Pi_LVM_on_LUKS&amp;diff=26779"/>
		<updated>2024-05-24T21:00:45Z</updated>

		<summary type="html">&lt;p&gt;Harpia: Remove unnecessary &amp;quot;run as root&amp;quot; note&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Installing Alpine on an encrypted root=&lt;br /&gt;
&lt;br /&gt;
This article complements the existing installation instructions for Raspberry Pi,&lt;br /&gt;
providing only the needed changes that enable booting from an encrypted media. Use it only as a reference, not as a complete walk-through for installation.&lt;br /&gt;
&lt;br /&gt;
==Prepare the Installation Media==&lt;br /&gt;
[[Create_a_Bootable_Device#Manually_copying_Alpine_files|Create a bootable disk]]. Basically, you&#039;ll create and format a FAT32 partition in an MBR partition table, set the boot flag on it, mount it and extract the downloaded tarball into it. You may skip those bootloader steps, because the tarball already has everything you need to boot.&lt;br /&gt;
&lt;br /&gt;
As a preference of the author, this bootable disk (referred to as &#039;&#039;/dev/sda&#039;&#039;) is just an installer, and will not be changed during the installation. The target root disk is referred to as &#039;&#039;/dev/sdb&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Boot the Installer==&lt;br /&gt;
Insert the bootable disk we created earlier into the pi, and boot from it. Login and perform a diskless installation with &amp;lt;code&amp;gt;setup-alpine&amp;lt;/code&amp;gt;. Next, we&#039;ll setup the disk.&lt;br /&gt;
&lt;br /&gt;
==Disk setup==&lt;br /&gt;
Plug in the disk to be used as the encrypted root. A tool such as &amp;lt;code&amp;gt;lsblk&amp;lt;/code&amp;gt; gives you an overview of all disks available. In this example, the new disk becomes &#039;&#039;/dev/sdb&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Create a bootable FAT32 partition (&#039;&#039;/dev/sdb1&#039;&#039;) that will hold the unencrypted &#039;&#039;/boot&#039;&#039;, and then a larger Linux partition (&#039;&#039;/dev/sdb2&#039;&#039;) that will hold the LVM physical volume.&lt;br /&gt;
&lt;br /&gt;
Install the necessary packages:&lt;br /&gt;
{{cmd|apk add cryptsetup lvm2}}&lt;br /&gt;
&lt;br /&gt;
Encrypt the Linux partition with one of the following:&lt;br /&gt;
{{cmd|cryptsetup luksFormat /dev/sdb2    # Raspberry Pi 5}}&lt;br /&gt;
{{cmd|cryptsetup luksFormat -c xchacha12,aes-adiantum-plain64 /dev/sdb2    # Raspberry Pi 4 and older}}&lt;br /&gt;
&lt;br /&gt;
At this point you can follow the [[LVM_on_LUKS#Creating_the_Logical_Volumes_and_File_Systems|LVM on LUKS page]] to create and format the LVM volumes.&lt;br /&gt;
&lt;br /&gt;
Mount the new root partition at &#039;&#039;/mnt&#039;&#039;, the boot partition at &#039;&#039;/mnt/boot&#039;&#039; (after creating the directory), then run &#039;&#039;setup-disk&#039;&#039; like this:&lt;br /&gt;
{{cmd|setup-disk -m sys /mnt}}&lt;br /&gt;
&lt;br /&gt;
==Verify the Installation==&lt;br /&gt;
&#039;&#039;setup-disk&#039;&#039; should setup most things for us, but it&#039;s a good idea to inspect some critical files to avoid ending up with a system that won&#039;t boot.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a list of files to check:&lt;br /&gt;
* &#039;&#039;/etc/mkinitfs/mkinitfs.conf&#039;&#039; should have the features &amp;lt;code&amp;gt;lvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;cryptsetup&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &#039;&#039;/boot/cmdline.txt&#039;&#039; should contain the following options: &amp;lt;code&amp;gt;root=/dev/vg0/root cryptroot=UUID=&amp;lt;encrypted_disk_uuid&amp;gt; cryptdm=root&amp;lt;/code&amp;gt;&lt;br /&gt;
* &#039;&#039;/etc/fstab&#039;&#039; should have a line for &amp;lt;code&amp;gt;/dev/vg0/root&amp;lt;/code&amp;gt; (and any other LVM volumes), and &amp;lt;code&amp;gt;/boot&amp;lt;/code&amp;gt; (by UUID).&lt;br /&gt;
&lt;br /&gt;
Finally, a friendly reminder: save a backup of that LUKS header (see &amp;lt;code&amp;gt;cryptsetup-luksHeaderBackup(8)&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=Decrypt with a Keyfile=&lt;br /&gt;
The &amp;quot;keydisk&amp;quot; - a storage device used as a decryption key — is a convenient method to enable full-disk encryption, especially for a headless server. Unfortunately, this functionality is not yet supported, but there is a [https://gitlab.alpinelinux.org/alpine/mkinitfs/-/merge_requests/108 pending merge request] to implement it.&lt;br /&gt;
&lt;br /&gt;
For now, we can achieve the same by moving the entire &#039;&#039;/boot&#039;&#039; partition to a separate device.&lt;br /&gt;
&lt;br /&gt;
This assumes you&#039;ve already booted a passphrase-encrypted Alpine installation, but you can include this as part of the installation procedure, and even use a keyfile alone instead of a passphrase.&lt;br /&gt;
&lt;br /&gt;
==Create the keyfile==&lt;br /&gt;
&lt;br /&gt;
A keyfile can be created with &#039;&#039;dd&#039;&#039;:&lt;br /&gt;
{{cmd|dd if{{=}}/dev/urandom of{{=}}/crypto_keyfile.bin bs{{=}}1M count{{=}}1}}&lt;br /&gt;
&lt;br /&gt;
Make it read-only, owner only:&lt;br /&gt;
{{cmd|chmod 400 /crypto_keyfile.bin}}&lt;br /&gt;
&lt;br /&gt;
Add the keyfile to the LUKS header:&lt;br /&gt;
{{cmd|cryptsetup luksAddKey /dev/sdb2 /crypto_keyfile.bin}}&lt;br /&gt;
&lt;br /&gt;
==Prepare the Initramfs==&lt;br /&gt;
&lt;br /&gt;
The root disk decryption takes place in the temporary environment called &#039;&#039;initramfs&#039;&#039;. &#039;&#039;mkinitfs&#039;&#039; will copy your keyfile into the initramfs filesystem, and place it in the exact same path it was copied from (e.g. &#039;&#039;/boot/cryptkey&#039;&#039;, &#039;&#039;/var/root.key&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
The default path is &amp;lt;code&amp;gt;/crypto_keyfile.bin&amp;lt;/code&amp;gt;, but you can change it by editing &amp;lt;code&amp;gt;/etc/mkinitfs/features.d/cryptkey.files&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The path to the keyfile must also be passed as a kernel command-line option in &amp;lt;code&amp;gt;/boot/cmdline.txt&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cryptkey=/crypto_keyfile.bin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Enable the necessary features in &amp;lt;code&amp;gt;/etc/mkinitfs/mkinitfs.conf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
features=&amp;quot;... cryptsetup cryptkey&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Regenerate the [[Initramfs_init|initramfs]]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkinitfs -c /etc/mkinitfs/mkinitfs.conf -b /&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=See Also=&lt;br /&gt;
* [[Raspberry Pi|Raspberry Pi - Installation]] &#039;&#039;(diskless-mode installation)&#039;&#039;&lt;br /&gt;
* [[Classic install or sys mode on Raspberry Pi|Raspberry Pi - Sys mode install]] &#039;&#039;(sys-mode installation)&#039;&#039;&lt;br /&gt;
* [[LVM_on_LUKS|LVM on LUKS]] &#039;&#039;(encryption and LVM, but beware not everything applies to the pi)&#039;&#039;&lt;/div&gt;</summary>
		<author><name>Harpia</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Raspberry_Pi_LVM_on_LUKS&amp;diff=26778</id>
		<title>Raspberry Pi LVM on LUKS</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Raspberry_Pi_LVM_on_LUKS&amp;diff=26778"/>
		<updated>2024-05-24T20:55:12Z</updated>

		<summary type="html">&lt;p&gt;Harpia: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Installing Alpine on an encrypted root=&lt;br /&gt;
&lt;br /&gt;
This article complements the existing installation instructions for Raspberry Pi,&lt;br /&gt;
providing only the needed changes that enable booting from an encrypted media. Use it only as a reference, not as a complete walk-through for installation.&lt;br /&gt;
&lt;br /&gt;
==Prepare the Installation Media==&lt;br /&gt;
[[Create_a_Bootable_Device#Manually_copying_Alpine_files|Create a bootable disk]]. Basically, you&#039;ll create and format a FAT32 partition in an MBR partition table, set the boot flag on it, mount it and extract the downloaded tarball into it. You may skip those bootloader steps, because the tarball already has everything you need to boot.&lt;br /&gt;
&lt;br /&gt;
As a preference of the author, this bootable disk (referred to as &#039;&#039;/dev/sda&#039;&#039;) is just an installer, and will not be changed during the installation. The target root disk is referred to as &#039;&#039;/dev/sdb&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Most commands here — if not all — must be run as root.&lt;br /&gt;
&lt;br /&gt;
==Boot the Installer==&lt;br /&gt;
Insert the bootable disk we created earlier into the pi, and boot from it. Login and perform a diskless installation with &amp;lt;code&amp;gt;setup-alpine&amp;lt;/code&amp;gt;. Next, we&#039;ll setup the disk.&lt;br /&gt;
&lt;br /&gt;
==Disk setup==&lt;br /&gt;
Plug in the disk to be used as the encrypted root. A tool such as &amp;lt;code&amp;gt;lsblk&amp;lt;/code&amp;gt; gives you an overview of all disks available. In this example, the new disk becomes &#039;&#039;/dev/sdb&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Create a bootable FAT32 partition (&#039;&#039;/dev/sdb1&#039;&#039;) that will hold the unencrypted &#039;&#039;/boot&#039;&#039;, and then a larger Linux partition (&#039;&#039;/dev/sdb2&#039;&#039;) that will hold the LVM physical volume.&lt;br /&gt;
&lt;br /&gt;
Install the necessary packages:&lt;br /&gt;
{{cmd|apk add cryptsetup lvm2}}&lt;br /&gt;
&lt;br /&gt;
Encrypt the Linux partition with one of the following:&lt;br /&gt;
{{cmd|cryptsetup luksFormat /dev/sdb2    # Raspberry Pi 5}}&lt;br /&gt;
{{cmd|cryptsetup luksFormat -c xchacha12,aes-adiantum-plain64 /dev/sdb2    # Raspberry Pi 4 and older}}&lt;br /&gt;
&lt;br /&gt;
At this point you can follow the [[LVM_on_LUKS#Creating_the_Logical_Volumes_and_File_Systems|LVM on LUKS page]] to create and format the LVM volumes.&lt;br /&gt;
&lt;br /&gt;
Mount the new root partition at &#039;&#039;/mnt&#039;&#039;, the boot partition at &#039;&#039;/mnt/boot&#039;&#039; (after creating the directory), then run &#039;&#039;setup-disk&#039;&#039; like this:&lt;br /&gt;
{{cmd|setup-disk -m sys /mnt}}&lt;br /&gt;
&lt;br /&gt;
==Verify the Installation==&lt;br /&gt;
&#039;&#039;setup-disk&#039;&#039; should setup most things for us, but it&#039;s a good idea to inspect some critical files to avoid ending up with a system that won&#039;t boot.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a list of files to check:&lt;br /&gt;
* &#039;&#039;/etc/mkinitfs/mkinitfs.conf&#039;&#039; should have the features &amp;lt;code&amp;gt;lvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;cryptsetup&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &#039;&#039;/boot/cmdline.txt&#039;&#039; should contain the following options: &amp;lt;code&amp;gt;root=/dev/vg0/root cryptroot=UUID=&amp;lt;encrypted_disk_uuid&amp;gt; cryptdm=root&amp;lt;/code&amp;gt;&lt;br /&gt;
* &#039;&#039;/etc/fstab&#039;&#039; should have a line for &amp;lt;code&amp;gt;/dev/vg0/root&amp;lt;/code&amp;gt; (and any other LVM volumes), and &amp;lt;code&amp;gt;/boot&amp;lt;/code&amp;gt; (by UUID).&lt;br /&gt;
&lt;br /&gt;
Finally, a friendly reminder: save a backup of that LUKS header (see &amp;lt;code&amp;gt;cryptsetup-luksHeaderBackup(8)&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=Decrypt with a Keyfile=&lt;br /&gt;
The &amp;quot;keydisk&amp;quot; - a storage device used as a decryption key — is a convenient method to enable full-disk encryption, especially for a headless server. Unfortunately, this functionality is not yet supported, but there is a [https://gitlab.alpinelinux.org/alpine/mkinitfs/-/merge_requests/108 pending merge request] to implement it.&lt;br /&gt;
&lt;br /&gt;
For now, we can achieve the same by moving the entire &#039;&#039;/boot&#039;&#039; partition to a separate device.&lt;br /&gt;
&lt;br /&gt;
This assumes you&#039;ve already booted a passphrase-encrypted Alpine installation, but you can include this as part of the installation procedure, and even use a keyfile alone instead of a passphrase.&lt;br /&gt;
&lt;br /&gt;
==Create the keyfile==&lt;br /&gt;
&lt;br /&gt;
A keyfile can be created with &#039;&#039;dd&#039;&#039;:&lt;br /&gt;
{{cmd|dd if{{=}}/dev/urandom of{{=}}/crypto_keyfile.bin bs{{=}}1M count{{=}}1}}&lt;br /&gt;
&lt;br /&gt;
Make it read-only, owner only:&lt;br /&gt;
{{cmd|chmod 400 /crypto_keyfile.bin}}&lt;br /&gt;
&lt;br /&gt;
Add the keyfile to the LUKS header:&lt;br /&gt;
{{cmd|cryptsetup luksAddKey /dev/sdb2 /crypto_keyfile.bin}}&lt;br /&gt;
&lt;br /&gt;
==Prepare the Initramfs==&lt;br /&gt;
&lt;br /&gt;
The root disk decryption takes place in the temporary environment called &#039;&#039;initramfs&#039;&#039;. &#039;&#039;mkinitfs&#039;&#039; will copy your keyfile into the initramfs filesystem, and place it in the exact same path it was copied from (e.g. &#039;&#039;/boot/cryptkey&#039;&#039;, &#039;&#039;/var/root.key&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
The default path is &amp;lt;code&amp;gt;/crypto_keyfile.bin&amp;lt;/code&amp;gt;, but you can change it by editing &amp;lt;code&amp;gt;/etc/mkinitfs/features.d/cryptkey.files&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The path to the keyfile must also be passed as a kernel command-line option in &amp;lt;code&amp;gt;/boot/cmdline.txt&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cryptkey=/crypto_keyfile.bin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Enable the necessary features in &amp;lt;code&amp;gt;/etc/mkinitfs/mkinitfs.conf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
features=&amp;quot;... cryptsetup cryptkey&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Regenerate the [[Initramfs_init|initramfs]]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkinitfs -c /etc/mkinitfs/mkinitfs.conf -b /&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=See Also=&lt;br /&gt;
* [[Raspberry Pi|Raspberry Pi - Installation]] &#039;&#039;(diskless-mode installation)&#039;&#039;&lt;br /&gt;
* [[Classic install or sys mode on Raspberry Pi|Raspberry Pi - Sys mode install]] &#039;&#039;(sys-mode installation)&#039;&#039;&lt;br /&gt;
* [[LVM_on_LUKS|LVM on LUKS]] &#039;&#039;(encryption and LVM, but beware not everything applies to the pi)&#039;&#039;&lt;/div&gt;</summary>
		<author><name>Harpia</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Tutorials_and_Howtos&amp;diff=26759</id>
		<title>Tutorials and Howtos</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Tutorials_and_Howtos&amp;diff=26759"/>
		<updated>2024-05-22T17:26:59Z</updated>

		<summary type="html">&lt;p&gt;Harpia: Add new page - Sys-mode installation, LVM on LUKS, Raspberry Pi&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==== Raspberry Pi ====&lt;br /&gt;
&lt;br /&gt;
* [[Raspberry Pi Bluetooth Speaker|Raspberry Pi - Bluetooth Speaker]]&lt;br /&gt;
* [[Raspberry Pi|Raspberry Pi - Installation]]&lt;br /&gt;
* [[Linux Router with VPN on a Raspberry Pi|Raspberry Pi - Router with VPN]]&lt;br /&gt;
* [[Linux Router with VPN on a Raspberry Pi (IPv6)|Raspberry Pi - Router with VPN (IPv6)]]&lt;br /&gt;
* [[Classic install or sys mode on Raspberry Pi|Raspberry Pi - Sys mode install]]&lt;br /&gt;
* [[Raspberry Pi LVM on LUKS|Raspberry Pi - Sys mode install - LVM on LUKS]]&lt;br /&gt;
* [[RPI Video Receiver|Raspberry Pi - Video Receiver]] &#039;&#039;(network video decoder using Rasperry Pi and omxplayer)&#039;&#039;&lt;br /&gt;
* [[Raspberry Pi 3 - Browser Client]] - kiosk or digital sign&lt;br /&gt;
* [[Raspberry Pi 3 - Configuring it as wireless access point -AP Mode]]&lt;br /&gt;
* [[Raspberry Pi 3 - Setting Up Bluetooth]]&lt;br /&gt;
* [[Raspberry Pi 4 - Persistent system acting as a NAS and Time Machine]]&lt;br /&gt;
* [[How to set up Alpine as a wireless router|Raspberry Pi Zero W - Wireless router]] &#039;&#039;(Setting up a firewalled, Wireless AP with wired network on a Pi Zero W)&#039;&#039;&lt;/div&gt;</summary>
		<author><name>Harpia</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Raspberry_Pi_LVM_on_LUKS&amp;diff=26758</id>
		<title>Raspberry Pi LVM on LUKS</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Raspberry_Pi_LVM_on_LUKS&amp;diff=26758"/>
		<updated>2024-05-22T17:23:27Z</updated>

		<summary type="html">&lt;p&gt;Harpia: Document all particularities of booting the pi from encrypted root, plus cryptkey usage; Motivation came from my difficulties getting it done - many things are not obvious and not documented.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Installing Alpine on an encrypted root=&lt;br /&gt;
&lt;br /&gt;
This article complements the existing installation instructions for Raspberry Pi,&lt;br /&gt;
providing only the needed changes that enable booting from an encrypted media. Use it only as a reference, not as a complete walk-through for installation.&lt;br /&gt;
&lt;br /&gt;
==Preparation==&lt;br /&gt;
[[Create_a_Bootable_Device#Manually_copying_Alpine_files|Create a bootable disk]]. Basically, you&#039;ll create and format a FAT32 partition in an MBR partition table, set the boot flag on it, mount it and extract the downloaded tarball into it. You may skip those bootloader steps, because the tarball already has everything you need to boot.&lt;br /&gt;
&lt;br /&gt;
As a preference of the author, this bootable disk (referred to as &#039;&#039;/dev/sda&#039;&#039;) is just an installer, and will not be changed during the installation. The target root disk is referred to as &#039;&#039;/dev/sdb&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Most commands here — if not all — must be run as root.&lt;br /&gt;
&lt;br /&gt;
==Boot the Installer==&lt;br /&gt;
Insert the bootable disk we created earlier into the pi, and boot from it. Login and perform a diskless installation with &amp;lt;code&amp;gt;setup-alpine&amp;lt;/code&amp;gt;. Next, we&#039;ll setup the disk.&lt;br /&gt;
&lt;br /&gt;
==Disk setup==&lt;br /&gt;
Plug in the disk to be used as the encrypted root. A tool such as &amp;lt;code&amp;gt;lsblk&amp;lt;/code&amp;gt; gives you an overview of all disks available. In this example, the new disk becomes &#039;&#039;/dev/sdb&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Create a bootable FAT32 partition (&#039;&#039;/dev/sdb1&#039;&#039;) that will hold the unencrypted &#039;&#039;/boot&#039;&#039;, and then a larger Linux partition (&#039;&#039;/dev/sdb2&#039;&#039;) that will hold the LVM physical volume.&lt;br /&gt;
&lt;br /&gt;
Install the necessary packages:&lt;br /&gt;
{{cmd|apk add cryptsetup lvm2}}&lt;br /&gt;
&lt;br /&gt;
Encrypt the Linux partition with one of the following:&lt;br /&gt;
{{cmd|cryptsetup luksFormat /dev/sdb2    # Raspberry Pi 5}}&lt;br /&gt;
{{cmd|cryptsetup luksFormat -c xchacha12,aes-adiantum-plain64 /dev/sdb2    # Raspberry Pi 4 and older}}&lt;br /&gt;
&lt;br /&gt;
At this point you can follow the [[LVM_on_LUKS#Creating_the_Logical_Volumes_and_File_Systems|LVM on LUKS page]] to create and format the LVM volumes.&lt;br /&gt;
&lt;br /&gt;
Mount the new root partition at &#039;&#039;/mnt&#039;&#039;, the boot partition at &#039;&#039;/mnt/boot&#039;&#039; (after creating the directory), then run &#039;&#039;setup-disk&#039;&#039; like this:&lt;br /&gt;
{{cmd|setup-disk -m sys /mnt}}&lt;br /&gt;
&lt;br /&gt;
==Verify the Installation==&lt;br /&gt;
&#039;&#039;setup-disk&#039;&#039; should setup most things for us, but it&#039;s a good idea to inspect some critical files to avoid ending up with a system that won&#039;t boot.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a list of files to check:&lt;br /&gt;
* &#039;&#039;/etc/mkinitfs/mkinitfs.conf&#039;&#039; should have the features &amp;lt;code&amp;gt;lvm&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;cryptsetup&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &#039;&#039;/boot/cmdline.txt&#039;&#039; should contain the following options: &amp;lt;code&amp;gt;root=/dev/vg0/root cryptroot=UUID=&amp;lt;encrypted_disk_uuid&amp;gt; cryptdm=root&amp;lt;/code&amp;gt;&lt;br /&gt;
* &#039;&#039;/etc/fstab&#039;&#039; should have a line for &amp;lt;code&amp;gt;/dev/vg0/root&amp;lt;/code&amp;gt; (and any other LVM volumes), and &amp;lt;code&amp;gt;/boot&amp;lt;/code&amp;gt; (by UUID).&lt;br /&gt;
&lt;br /&gt;
Finally, a friendly reminder: save a backup of that LUKS header (see &amp;lt;code&amp;gt;cryptsetup-luksHeaderBackup(8)&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=Decrypt with a Keyfile=&lt;br /&gt;
The &amp;quot;keydisk&amp;quot; - a storage device used as a decryption key — is a convenient method to enable full-disk encryption, especially for a headless server. Unfortunately, this functionality is not yet supported, but there is a [https://gitlab.alpinelinux.org/alpine/mkinitfs/-/merge_requests/108 pending merge request] to implement it.&lt;br /&gt;
&lt;br /&gt;
For now, we can achieve the same by moving the entire &#039;&#039;/boot&#039;&#039; partition to a separate device.&lt;br /&gt;
&lt;br /&gt;
This assumes you&#039;ve already booted a passphrase-encrypted Alpine installation, but you can include this as part of the installation procedure, and even use a keyfile alone instead of a passphrase.&lt;br /&gt;
&lt;br /&gt;
==Create the keyfile==&lt;br /&gt;
&lt;br /&gt;
A keyfile can be created with &#039;&#039;dd&#039;&#039;:&lt;br /&gt;
{{cmd|dd if{{=}}/dev/urandom of{{=}}/crypto_keyfile.bin bs{{=}}1M count{{=}}1}}&lt;br /&gt;
&lt;br /&gt;
Make it read-only, owner only:&lt;br /&gt;
{{cmd|chmod 400 /crypto_keyfile.bin}}&lt;br /&gt;
&lt;br /&gt;
Add the keyfile to the LUKS header:&lt;br /&gt;
{{cmd|cryptsetup luksAddKey /dev/sdb2 /crypto_keyfile.bin}}&lt;br /&gt;
&lt;br /&gt;
==Prepare the Initramfs==&lt;br /&gt;
&lt;br /&gt;
The root disk decryption takes place in the temporary environment called &#039;&#039;initramfs&#039;&#039;. &#039;&#039;mkinitfs&#039;&#039; will copy your keyfile into the initramfs filesystem, and place it in the exact same path it was copied from (e.g. &#039;&#039;/boot/cryptkey&#039;&#039;, &#039;&#039;/var/root.key&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
The default path is &amp;lt;code&amp;gt;/crypto_keyfile.bin&amp;lt;/code&amp;gt;, but you can change it by editing &amp;lt;code&amp;gt;/etc/mkinitfs/features.d/cryptkey.files&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The path to the keyfile must also be passed as a kernel command-line option in &amp;lt;code&amp;gt;/boot/cmdline.txt&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cryptkey=/crypto_keyfile.bin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Enable the necessary features in &amp;lt;code&amp;gt;/etc/mkinitfs/mkinitfs.conf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
features=&amp;quot;... cryptsetup cryptkey&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Regenerate the [[Initramfs_init|initramfs]]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkinitfs -c /etc/mkinitfs/mkinitfs.conf -b /&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=See Also=&lt;br /&gt;
* [[Raspberry Pi|Raspberry Pi - Installation]] &#039;&#039;(diskless-mode installation)&#039;&#039;&lt;br /&gt;
* [[Classic install or sys mode on Raspberry Pi|Raspberry Pi - Sys mode install]] &#039;&#039;(sys-mode installation)&#039;&#039;&lt;br /&gt;
* [[LVM_on_LUKS|LVM on LUKS]] &#039;&#039;(encryption and LVM, but beware not everything applies to the pi)&#039;&#039;&lt;/div&gt;</summary>
		<author><name>Harpia</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Raspberry_Pi&amp;diff=26753</id>
		<title>Raspberry Pi</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Raspberry_Pi&amp;diff=26753"/>
		<updated>2024-05-21T15:30:43Z</updated>

		<summary type="html">&lt;p&gt;Harpia: Add a section explaining how to enable and connect to the serial console&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{warning | 11 Feb 2021 - There is currently a known bug upstream &amp;lt;br /&amp;gt;[https://github.com/raspberrypi/firmware/issues/1529 kernel/initramfs cannot be loaded from subdirectory with same name as volume label]. Since the kernel is installed to &amp;lt;code&amp;gt;boot/&amp;lt;/code&amp;gt;, you must not use a label named &amp;lt;code&amp;gt;boot&amp;lt;/code&amp;gt; for the fat32 partition. }}&lt;br /&gt;
&lt;br /&gt;
{{TOC right}}&lt;br /&gt;
&lt;br /&gt;
This tutorial explains how to install Alpine Linux on a Raspberry Pi. Alpine Linux will be installed in [[Installation#Diskless_Mode|diskless mode]], hence, [[Alpine local backup|Alpine Local Backup (lbu)]] is required to save modifications between reboots.&lt;br /&gt;
&lt;br /&gt;
For scenarios where there is not expected to be significant changes to disk after setup (like running a static HTTP server), this is likely preferable, as running the entire system from memory will improve performance (by avoiding the slow SD card) and improve the SD card life (by reducing the writes to the card, as all logging will happen in RAM). Diskless installations still allow you to install packages, save local files, and tune the system to your needs.&lt;br /&gt;
&lt;br /&gt;
If any of the following apply, then installation in [[Classic install or sys mode on Raspberry Pi|sys-mode installation]] is likely more appropriate.&lt;br /&gt;
&lt;br /&gt;
* There will be constant changes to the disk after initial setup (for example, if you expect people to login and save files to their home directories)&lt;br /&gt;
* Logs should persists across reboots&lt;br /&gt;
* Plan to install packages which consume more space than can be loaded into RAM&lt;br /&gt;
* Plan to install kernel modules (such as ZFS)&lt;br /&gt;
&lt;br /&gt;
== Compability list ==&lt;br /&gt;
As of Alpine 3.19:&lt;br /&gt;
* &#039;&#039;&#039;armhf&#039;&#039;&#039; (defconfig bcmrpi) - Raspberry Pi 1, Zero, ZeroW, cm1&lt;br /&gt;
* &#039;&#039;&#039;armv7&#039;&#039;&#039; (defconfig bcm2709) - Raspberry Pi 2, 3, 3+, Zero2W, cm3, cm3+&lt;br /&gt;
* &#039;&#039;&#039;aarch64&#039;&#039;&#039; (defconfig bcm2711) - Raspberry Pi 3, 3+, 4, 400, Zero2W, cm3, cm3+, cm4, 5&lt;br /&gt;
&lt;br /&gt;
== Preparation ==&lt;br /&gt;
&lt;br /&gt;
# [https://alpinelinux.org/downloads/ Download] the Alpine for Raspberry Pi tarball. Use the compability list above when choosing image/file to download. &lt;br /&gt;
# [[Create_a_Bootable_Device#Manually_copying_Alpine_files|Create a bootable FAT32 partition on your SD card.]] The partitioning and formatting part of the instructions on the linked page could be done using a graphical partitioning tool such as [https://en.wikipedia.org/wiki/GNOME_Disks gnome-disks], just make sure the partition type is &amp;lt;code&amp;gt;W95 FAT32 (LBA)&amp;lt;/code&amp;gt;. (The current type can be found in the &amp;quot;Type&amp;quot; column in the output of &amp;lt;code&amp;gt;fdisk -l&amp;lt;/code&amp;gt;.)&lt;br /&gt;
# Extract the tarball to the root of the bootable FAT32 partition.&lt;br /&gt;
&lt;br /&gt;
To setup a headless system, a bootstrapping configuration overlay file [https://github.com/macmpi/alpine-linux-headless-bootstrap  headless.apkovl.tar.gz] may be added to enable basic networking, so that following configuration steps can be performed under &amp;lt;code&amp;gt;ssh&amp;lt;/code&amp;gt;. Pi Zero may be configured with simple USB ethernet-gadget networking with another computer sharing its internet connection.&lt;br /&gt;
&lt;br /&gt;
It is recommended to create a &#039;&#039;&#039;usercfg.txt&#039;&#039;&#039; file on boot partition to configure low-level system settings, as &#039;&#039;&#039;config.txt&#039;&#039;&#039; may be replaced during bootloader/system upgrades: details can be found [https://www.raspberrypi.com/documentation/computers/config_txt.html here].&amp;lt;br&amp;gt;&lt;br /&gt;
However, note some [https://www.raspberrypi.com/documentation/computers/config_txt.html#include settings] can only be set in &#039;&#039;&#039;config.txt&#039;&#039;&#039;, and will have no effect when specified in &#039;&#039;&#039;usercfg.txt&#039;&#039;&#039; (e.g. &amp;lt;code&amp;gt;gpu_mem&amp;lt;/code&amp;gt;). Some interesting values include:&lt;br /&gt;
* To enable the UART console: &amp;lt;code&amp;gt;enable_uart=1&amp;lt;/code&amp;gt;&lt;br /&gt;
* To enable audio: &amp;lt;code&amp;gt;dtparam=audio=on&amp;lt;/code&amp;gt;&lt;br /&gt;
* By default system will use legacy video driver: some [https://www.raspberrypi.com/documentation/computers/legacy_config_txt.html#legacy-video-options options] may be used to adjust displays modes (e.g. if you see black edges around your screen after booting the Pi, you can add &amp;lt;code&amp;gt;disable_overscan=1&amp;lt;/code&amp;gt;). Alternatively Linux DRM-KMS driver may be used (see below).&lt;br /&gt;
* If you plan to install on a Pi Compute Module 4 with I/O board, you may need to add: &amp;lt;code&amp;gt;otg_mode=1&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Recent versions include Broadcom firmware files. If you&#039;re using an older Alpine version, see [[#Wireless_support_with_older_Alpine_images|section below]].&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
Follow these steps to install Alpine Linux in Diskless Mode:&lt;br /&gt;
&lt;br /&gt;
# Insert the SD card into the Raspberry Pi and power it on&lt;br /&gt;
# Login into the Alpine system as root.  Leave the password empty.&lt;br /&gt;
# Type &amp;lt;code&amp;gt;setup-alpine&amp;lt;/code&amp;gt;&lt;br /&gt;
# Once the installation is complete, commit the changes by typing &amp;lt;code&amp;gt;lbu commit -d&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Type &amp;lt;code&amp;gt;reboot&amp;lt;/code&amp;gt; to verify that the installation was indeed successful.&lt;br /&gt;
&lt;br /&gt;
== Post Installation ==&lt;br /&gt;
&lt;br /&gt;
=== Update the System ===&lt;br /&gt;
&lt;br /&gt;
After installation, make sure your system is up-to-date:&lt;br /&gt;
&lt;br /&gt;
{{cmd|apk update&lt;br /&gt;
apk upgrade}}&lt;br /&gt;
&lt;br /&gt;
Don&#039;t forget to save the changes:&lt;br /&gt;
&lt;br /&gt;
{{cmd|lbu commit -d}}&lt;br /&gt;
&lt;br /&gt;
Note: this does not upgrade the kernel. In order to upgrade the kernel, a full upgrade of the Alpine Linux version must be performed as described in [[Upgrading Alpine#Upgrading Alpine Linux on other removable media (such as CF/USB)|upgrading Alpine Linux for removable media]].&lt;br /&gt;
&lt;br /&gt;
=== Linux Kernel Graphics Modes ===&lt;br /&gt;
By default system configuration will use legacy video driver: this driver has some limitations and is lacking support.&amp;lt;br&amp;gt;&lt;br /&gt;
It is recommended to enable Linux DRM-KMS driver by adding the following to &#039;&#039;&#039;usercfg.txt&#039;&#039;&#039;:&lt;br /&gt;
 # Enable DRM VC4 V3D driver&lt;br /&gt;
 dtoverlay=vc4-kms-v3d&lt;br /&gt;
 max_framebuffers=2&lt;br /&gt;
 &lt;br /&gt;
 # Don&#039;t have the firmware create an initial video= setting in cmdline.txt.&lt;br /&gt;
 # Use the kernel&#039;s default instead.&lt;br /&gt;
 disable_fw_kms_setup=1&lt;br /&gt;
Note: This overlay disables legacy video [https://www.raspberrypi.com/documentation/computers/legacy_config_txt.html#legacy-video-options options].&lt;br /&gt;
&lt;br /&gt;
Install the Mesa drivers (Pi4 and Pi5):&lt;br /&gt;
&lt;br /&gt;
{{cmd|apk add {{pkg|mesa-dri-gallium|arch=a*}}}}&lt;br /&gt;
&lt;br /&gt;
Then reboot:&lt;br /&gt;
&lt;br /&gt;
{{cmd|lbu_commit -d; reboot}}&lt;br /&gt;
&lt;br /&gt;
=== Wireless drivers ===&lt;br /&gt;
As of Alpine 3.17, Wifi and Bluetooth drivers are available within install image: they are part of &amp;lt;code&amp;gt;linux-firmware-brcm&amp;lt;/code&amp;gt; (and linked dependencies).&amp;lt;br&amp;gt;&lt;br /&gt;
Since kernel 6.1.25 (i.e. Alpine 3.18), onboard bluetooth is enabled &amp;amp; autoprobed by default (it may be disabled by setting [https://github.com/raspberrypi/rpi-firmware/tree/master/overlays krnbt] off).&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&amp;lt;code&amp;gt;raspinfo&amp;lt;/code&amp;gt; utility can be used as a first step to diagnose issues: it will make a log report of essential Pi system configuration, and is often used as a reference to submit questions or bug reports within Raspberry Pi community (Forums, Github, etc).&amp;lt;br&amp;gt;&lt;br /&gt;
It can be installed with &amp;lt;code&amp;gt;raspberrypi-utils-raspinfo&amp;lt;/code&amp;gt; subpackage.&lt;br /&gt;
&lt;br /&gt;
=== Long boot time when running headless ===&lt;br /&gt;
&lt;br /&gt;
If no peripherals are connected, the system might hang for an exceptionally long period of time while it attempts to accumulate entropy.&lt;br /&gt;
&lt;br /&gt;
If this is the case, simply plugging in any USB device should work around this issue, since it increases the amount of entropy available to the kernel via interrupts.&lt;br /&gt;
&lt;br /&gt;
=== apk indicating &#039;No space left on device&#039; ===&lt;br /&gt;
&lt;br /&gt;
Note some models of the Raspberry Pi such as the 3A+ only have 512M of RAM, which on fresh Alpine deployment will only leave around 200M for tmpfs root. It&#039;s important to keep this limitation in mind when using these boards.&lt;br /&gt;
&lt;br /&gt;
=== Clock-related error messages ===&lt;br /&gt;
&lt;br /&gt;
During the booting time, you might notice errors related to the hardware clock.  Many Raspberry Pi does not have a hardware clock, thus you need to disable the hwclock daemon and enable swclock:&lt;br /&gt;
&lt;br /&gt;
{{cmd|rc-update add swclock boot    # enable the software clock&lt;br /&gt;
rc-update del hwclock boot    # disable the hardware clock}}&lt;br /&gt;
&lt;br /&gt;
== Persistent storage ==&lt;br /&gt;
=== Traditional disk-based (sys) installation ===&lt;br /&gt;
{{Merge|Classic install or sys mode on Raspberry Pi|There&#039;s an existing page for sys-installations on RasPi.}}&lt;br /&gt;
&lt;br /&gt;
It is also possible to switch to a fully disk-based installation. This is not yet formally supported, but can be done somewhat manually. This frees all the memory otherwise needed for the root filesystem, allowing more installed packages.&lt;br /&gt;
&lt;br /&gt;
Split your SD card into two partitions: the FAT32 boot partition described above (in this example it&#039;ll be &amp;lt;code&amp;gt;mmcblk0p1&amp;lt;/code&amp;gt;) , and a second partition to hold the root filesystem (here it&#039;ll be &amp;lt;code&amp;gt;mmcblk0p2&amp;lt;/code&amp;gt;). Boot and configure your diskless system as above, then create a root filesystem:&lt;br /&gt;
&lt;br /&gt;
{{cmd|apk add {{pkg|e2fsprogs|arch=a*}}&lt;br /&gt;
mkfs.ext4 /dev/mmcblk0p2}}&lt;br /&gt;
&lt;br /&gt;
Now do a disk install via a mountpoint. The &amp;lt;code&amp;gt;setup-disk&amp;lt;/code&amp;gt; script will give some errors about syslinux/extlinux, but you can ignore them.&lt;br /&gt;
The Raspberry Pi doesn&#039;t need them to boot.&lt;br /&gt;
&lt;br /&gt;
{{cmd|&amp;lt;nowiki&amp;gt;mkdir /stage&lt;br /&gt;
mount /dev/mmcblk0p2 /stage&lt;br /&gt;
setup-disk -o /media/mmcblk0p1/MYHOSTNAME.apkovl.tar.gz /stage&lt;br /&gt;
# (ignore errors about syslinux/extlinux)&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Add a line to &amp;lt;code&amp;gt;/stage/etc/fstab&amp;lt;/code&amp;gt; to mount the Pi&#039;s boot partition again:&lt;br /&gt;
&lt;br /&gt;
{{cmd|/dev/mmcblk0p1 /media/mmcblk0p1 vfat defaults 0 0}}&lt;br /&gt;
&lt;br /&gt;
Now add a &amp;lt;code&amp;gt;root=/dev/mmcblk0p2&amp;lt;/code&amp;gt; parameter to the Pi&#039;s boot command line, either &amp;lt;code&amp;gt;cmdline-rpi2.txt&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;cmdline-rpi.txt&amp;lt;/code&amp;gt; depending on model:&lt;br /&gt;
&lt;br /&gt;
{{cmd|&amp;lt;nowiki&amp;gt;mount -o remount,rw /media/mmcblk0p1&lt;br /&gt;
sed -i &#039;$ s/$/ root=\/dev\/mmcblk0p2/&#039; /media/mmcblk0p1/cmdline-rpi2.txt&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
You might also consider &amp;lt;code&amp;gt;overlaytmpfs=yes&amp;lt;/code&amp;gt; here, which will cause the underlying SD card root filesystem to be mounted read-only, with an overlayed tmpfs for modifications which will be discarded at shutdown.&lt;br /&gt;
&lt;br /&gt;
N.B. &amp;lt;b&amp;gt;the contents of /boot will be ignored when the Pi boots&amp;lt;/b&amp;gt;. It will use the kernel, initramfs, and modloop images from the FAT32 boot partition. To update the kernel, initfs or modules, you will need to manually (generate and) copy these to the boot partition or you could use bind mount, in which case,&lt;br /&gt;
copying the files to boot partition manually, is not needed.&lt;br /&gt;
&lt;br /&gt;
{{cmd|&amp;lt;nowiki&amp;gt;echo /media/mmcblk0p1/boot /boot none defaults,bind 0 0 &amp;gt;&amp;gt; /etc/fstab&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
=== Loopback image with overlayfs ===&lt;br /&gt;
&lt;br /&gt;
When you install Alpine in diskless mode, the entire system is loaded into memory at boot. If you want additional storage (for example, if you need more space than offered by your RAM) we need to create loop-back storage onto the SD card mounted with overlayfs.&lt;br /&gt;
&lt;br /&gt;
First, make the SD card writable again and change fstab to always do so:&lt;br /&gt;
{{cmd|mount /media/mmcblk0p1 -o rw,remount&lt;br /&gt;
sed -i &#039;s/vfat\ ro,/vfat\ rw,/&#039; /etc/fstab}}&lt;br /&gt;
&lt;br /&gt;
Create the loop-back file, this example is 1 GB:&lt;br /&gt;
&lt;br /&gt;
{{cmd|dd if&amp;amp;#61;/dev/zero of&amp;amp;#61;/media/mmcblk0p1/persist.img bs&amp;amp;#61;1024 count&amp;amp;#61;0 seek&amp;amp;#61;1048576}}&lt;br /&gt;
&lt;br /&gt;
Install the ext utilities:&lt;br /&gt;
&lt;br /&gt;
{{cmd|apk add e2fsprogs}}&lt;br /&gt;
&lt;br /&gt;
Format the loop-back file:&lt;br /&gt;
&lt;br /&gt;
{{cmd|mkfs.ext4 /media/mmcblk0p1/persist.img}}&lt;br /&gt;
&lt;br /&gt;
Mount the storage: &lt;br /&gt;
&lt;br /&gt;
{{cmd|echo &amp;quot;/media/mmcblk0p1/persist.img /media/persist ext4 rw,relatime,errors&amp;amp;#61;remount-ro 0 0&amp;quot; &amp;gt;&amp;gt; /etc/fstab&lt;br /&gt;
mkdir /media/persist &lt;br /&gt;
mount -a}}&lt;br /&gt;
&lt;br /&gt;
Make the overlay folders, we are using the /usr directory here, but you can use /home or anything else. &lt;br /&gt;
{{Warning|Overlay workdir needs to be an empty directory on the same filesystem mount as the upper directory. So each overlay must use its own workdir.}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{cmd|mkdir /media/persist/usr &lt;br /&gt;
mkdir /media/persist/.work_usr &lt;br /&gt;
echo &amp;quot;overlay /usr overlay lowerdir&amp;amp;#61;/usr,upperdir&amp;amp;#61;/media/persist/usr,workdir&amp;amp;#61;/media/persist/.work_usr 0 0&amp;quot; &amp;gt;&amp;gt; /etc/fstab &lt;br /&gt;
mount -a}}&lt;br /&gt;
&lt;br /&gt;
Your /etc/fstab should look something like this:&lt;br /&gt;
{{Cmd|/dev/cdrom      /media/cdrom    iso9660 noauto,ro 0 0&lt;br /&gt;
/dev/usbdisk    /media/usb      vfat    noauto,ro 0 0&lt;br /&gt;
/dev/mmcblk0p1 /media/mmcblk0p1 vfat rw,relatime,fmask&amp;amp;#61;0022,dmask&amp;amp;#61;0022,errors&amp;amp;#61;remount-ro 0 0&lt;br /&gt;
/media/mmcblk0p1/persist.img /media/persist ext4 rw,relatime,errors&amp;amp;#61;remount-ro 0 0&lt;br /&gt;
overlay /usr overlay lowerdir&amp;amp;#61;/usr,upperdir&amp;amp;#61;/media/persist/usr,workdir&amp;amp;#61;/media/persist/.work_usr 0 0}}&lt;br /&gt;
&lt;br /&gt;
Now commit the changes: (optionally remove the e2fsprogs, but it does contain repair tools)&lt;br /&gt;
{{cmd|lbu_commit -d}}&lt;br /&gt;
&lt;br /&gt;
Remember, with this setup if you install things and you have done this overlay for /usr, you must not commit the &#039;apk add&#039;, otherwise, while it boots it will try and install it to memory, not to the persistent storage.&lt;br /&gt;
&lt;br /&gt;
If you do want to install something small at boot, you can use &amp;lt;code&amp;gt;apk add&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;lbu commit -d&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If it is something a bit bigger, then you can use &amp;lt;code&amp;gt;apk add&amp;lt;/code&amp;gt; but then not commit it. It will be persistent (in &amp;lt;code&amp;gt;/user&amp;lt;/code&amp;gt;), but be sure to check everything you need is in that directory and not in folders you have not made persistent.&lt;br /&gt;
&lt;br /&gt;
== Netboot ==&lt;br /&gt;
&lt;br /&gt;
=== Netbooting Raspberry Pi 4 ===&lt;br /&gt;
&lt;br /&gt;
The Raspberry Pi 4 bootloader can be configured to boot from the network [https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#raspberry-pi-4-bootloader-configuration]. Configure the bootloader with at least&lt;br /&gt;
&lt;br /&gt;
{{cmd|&amp;lt;nowiki&amp;gt;BOOT_ORDER=0xf142&lt;br /&gt;
TFTP_PREFIX=1&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
and optionally also {{cmd|&amp;lt;nowiki&amp;gt;TFTP_IP=x.x.x.x&amp;lt;/nowiki&amp;gt;}} where &amp;lt;code&amp;gt;x.x.x.x&amp;lt;/code&amp;gt; is the IP address of your TFTP server.&lt;br /&gt;
&lt;br /&gt;
If not configuring &amp;lt;code&amp;gt;TFTP_IP&amp;lt;/code&amp;gt; in the bootloader, you&#039;ll need to configure your DHCP server to advertise the TFTP server IP address. This varies depending on your DHCP server; use the following details if applicable:&lt;br /&gt;
&lt;br /&gt;
# Vendor class: &amp;lt;code&amp;gt;PXEClient:Arch:00000:UNDI:002001&amp;lt;/code&amp;gt;&lt;br /&gt;
# Filename: &amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The minimal set of files that your TFTP server needs to host are:&lt;br /&gt;
&lt;br /&gt;
# &amp;lt;code&amp;gt;bcm2711-rpi-4-b.dtb&amp;lt;/code&amp;gt; (from [https://raw.githubusercontent.com/raspberrypi/firmware/master/boot/bcm2711-rpi-4-b.dtb raspberrypi/firmware/master/boot/bcm2711-rpi-4-b.dtb])&lt;br /&gt;
# &amp;lt;code&amp;gt;cmdline.txt&amp;lt;/code&amp;gt; (see below)&lt;br /&gt;
# &amp;lt;code&amp;gt;config.txt&amp;lt;/code&amp;gt; (see below)&lt;br /&gt;
# &amp;lt;code&amp;gt;fixup4.dat&amp;lt;/code&amp;gt; (from [https://raw.githubusercontent.com/raspberrypi/firmware/master/boot/fixup4.dat raspberrypi/firmware/master/boot/fixup4.dat], alternatively &amp;lt;code&amp;gt;fixup4cd.dat&amp;lt;/code&amp;gt; for the cut down version)&lt;br /&gt;
# &amp;lt;code&amp;gt;initramfs-rpi4&amp;lt;/code&amp;gt; (from [https://dl-cdn.alpinelinux.org/alpine/edge/releases/aarch64/netboot/initramfs-rpi4 alpine/edge/releases/aarch64/netboot/initramfs-rpi4])&lt;br /&gt;
# &amp;lt;code&amp;gt;start4.elf&amp;lt;/code&amp;gt; (from [https://raw.githubusercontent.com/raspberrypi/firmware/master/boot/start4.elf raspberrypi/firmware/master/boot/start4.elf], alternatively &amp;lt;code&amp;gt;start4cd.elf&amp;lt;/code&amp;gt; for the cut down version)&lt;br /&gt;
# &amp;lt;code&amp;gt;vmlinuz-rpi4&amp;lt;/code&amp;gt; (from [https://dl-cdn.alpinelinux.org/alpine/edge/releases/aarch64/netboot/vmlinuz-rpi4 alpine/edge/releases/aarch64/netboot/vmlinuz-rpi4])&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;config.txt&amp;lt;/code&amp;gt;:&lt;br /&gt;
{{cmd|&amp;lt;nowiki&amp;gt;[pi4]&lt;br /&gt;
kernel=vmlinuz-rpi4&lt;br /&gt;
initramfs initramfs-rpi4&lt;br /&gt;
arm_64bit=1&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;cmdline.txt&amp;lt;/code&amp;gt;:&lt;br /&gt;
{{cmd|&amp;lt;nowiki&amp;gt;modules=loop,squashfs console=ttyAMA0,115200 ip=dhcp alpine_repo=http://dl-cdn.alpinelinux.org/alpine/edge/main modloop=http://dl-cdn.alpinelinux.org/alpine/edge/releases/aarch64/netboot/modloop-rpi4&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Instead of using the &amp;lt;nowiki&amp;gt;http://dl-cdn.alpinelinux.org/alpine/edge/releases/aarch64/netboot/&amp;lt;/nowiki&amp;gt; base URL above, pinning to a specific point in time is preferred. Raspberry Pi 4 netboot files are available from https://dl-cdn.alpinelinux.org/alpine/edge/releases/aarch64/netboot-20230329/ onward.&lt;br /&gt;
&lt;br /&gt;
With the above configured the Raspberry Pi 4 should be able to boot from the network without an SD card.&lt;br /&gt;
&lt;br /&gt;
=== Wireless support with older Alpine images ===&lt;br /&gt;
&lt;br /&gt;
In Alpine 3.14, the WiFi drivers for the Raspberry Pi were moved from &amp;lt;code&amp;gt;linux-firmware-brcm&amp;lt;/code&amp;gt; to the &amp;lt;code&amp;gt;linux-firmware-cypress&amp;lt;/code&amp;gt; package (source?). Since the images seem to be an outdated version of the former, Wi-Fi will work during installation, but after the first update it will break.&lt;br /&gt;
Use the ethernet interface to download the required packages:&lt;br /&gt;
&lt;br /&gt;
{{cmd|apk add {{pkg|linux-firmware-cypress|arch=a*}}}}&lt;br /&gt;
&lt;br /&gt;
And reboot.&lt;br /&gt;
&lt;br /&gt;
If you need Wi-Fi, you&#039;ll need to [https://github.com/RPi-Distro/firmware-nonfree/tree/master/brcm download] the latest Broadcom drivers to your SD card.&lt;br /&gt;
(Replace /mnt/sdcard with the correct mount point.)&lt;br /&gt;
&lt;br /&gt;
  git clone --depth 1 https://github.com/RPi-Distro/firmware-nonfree.git&lt;br /&gt;
  cp firmware-nonfree/brcm/* /mnt/sdcard/firmware/brcm&lt;br /&gt;
&lt;br /&gt;
== Enable the Serial Console ==&lt;br /&gt;
Besides having &amp;lt;code&amp;gt;enable_uart=1&amp;lt;/code&amp;gt; in &#039;&#039;usercfg.txt&#039;&#039;, the kernel command-line option &amp;lt;var&amp;gt;console&amp;lt;/var&amp;gt; needs to be changed to &amp;lt;code&amp;gt;console=serial0,115200&amp;lt;/code&amp;gt; in &#039;&#039;cmdline.txt&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
From a Linux desktop, connect to it with something like this:&lt;br /&gt;
&lt;br /&gt;
{{cmd|cu -l /dev/ttyUSB0 -s 115200}}&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
* [[Classic install or sys mode on Raspberry Pi]] - a variant.&lt;br /&gt;
* [[Raspberry Pi 3 - Setting Up Bluetooth]]&lt;br /&gt;
* [[Raspberry Pi 3 - Configuring it as wireless access point -AP Mode]]&lt;br /&gt;
* [[Raspberry Pi 3 - Browser Client]]&lt;br /&gt;
* [[Linux Router with VPN on a Raspberry Pi]]&lt;br /&gt;
* [[Create a bootable SDHC from a Mac]]&lt;br /&gt;
* Build custom Raspberry Pi images based on Alpine via [https://github.com/tolstoyevsky/pieman Pieman]&lt;br /&gt;
* [[Tutorials and Howtos#Raspberry Pi]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation]]&lt;br /&gt;
[[Category: Raspberry]]&lt;/div&gt;</summary>
		<author><name>Harpia</name></author>
	</entry>
</feed>