<?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=Mmhiro</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=Mmhiro"/>
	<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/wiki/Special:Contributions/Mmhiro"/>
	<updated>2026-04-29T20:23:40Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.40.0</generator>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Installation&amp;diff=26677</id>
		<title>Installation</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Installation&amp;diff=26677"/>
		<updated>2024-05-04T15:53:50Z</updated>

		<summary type="html">&lt;p&gt;Mmhiro: change ordering to reflect installation and add clarification to warning&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:hdd_mount.png|left|link=]]&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This page exists to provide a basic overview to get started. Before actually installing, it can help to skim through the [[Alpine_Linux:FAQ| Frequently Asked Questions (FAQ)]], as well as to refer to the official installation guide at [https://docs.alpinelinux.org/ docs.alpinelinux.org].&lt;br /&gt;
&lt;br /&gt;
{{Tip|This is a wiki!&lt;br /&gt;
If something isn&#039;t correct, or is incomplete, you will have to figure it out, or ask for the correct solution in the [https://alpinelinux.org/community/ community].&lt;br /&gt;
&lt;br /&gt;
And then carefully edit the wiki page.&lt;br /&gt;
&lt;br /&gt;
Just as those before who did it for you.}}&lt;br /&gt;
&lt;br /&gt;
== Minimal Hardware Requirements ==&lt;br /&gt;
{{Main|Requirements}}&lt;br /&gt;
* At least 128 MB of RAM. [A graphical desktop system may require up to 512 minimum.]. Note that an installation itself (from ISO) generally requires at least 320 MB during installation.&lt;br /&gt;
* At least 0-700 MB space on a writable storage device. [Only required in &amp;quot;sys&amp;quot; or &amp;quot;data&amp;quot; mode installations (explained below). It is optional in &amp;quot;diskless&amp;quot; mode, where it may be used to save newer data and configurations states of a running system.]&lt;br /&gt;
&lt;br /&gt;
== Installation Overview ==&lt;br /&gt;
&lt;br /&gt;
=== The general course of action ===&lt;br /&gt;
{{Note|&lt;br /&gt;
* For single-board-computer (SBC) architectures which can not boot .iso images, see [[Alpine_on_ARM|Alpine on ARM]] for peculiarities.&lt;br /&gt;
* For headless system, initial network setup may be fed by pre-built &amp;lt;code&amp;gt;apkovl&amp;lt;/code&amp;gt; overlay file, custom-made or via [https://github.com/macmpi/alpine-linux-headless-bootstrap/ 3rd party]}}&lt;br /&gt;
&lt;br /&gt;
As usual, starting an installation procedure requires some basic steps (additional details for all the steps follow [[Installation#Basic Installation Step Details|below]]):&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Downloading and verifying the proper [https://alpinelinux.org/downloads/ stable-release ISO installation image-file] for the target computer&#039;s architecture with their corresponding &amp;lt;code&amp;gt;sha256&amp;lt;/code&amp;gt; (checksum) and &amp;lt;code&amp;gt;GPG&amp;lt;/code&amp;gt; (signature) files. &lt;br /&gt;
# Preparing the installation media (e.g.: CD, DVD, USB drive, SD Card, etc).&lt;br /&gt;
# Optionally, custom-made headless apkovl can be done by first booting the install media on some computer with a display and keyboard attached, or in a virtual machine, and doing an intermediate &amp;quot;diskless&amp;quot; setup of just the boot media (more details below), i.e. using the offical &amp;lt;code&amp;gt;[[Alpine_setup_scripts#setup-alpine|setup-alpine]]&amp;lt;/code&amp;gt; to configure the system&#039;s network, possibly for dhcp if needed, a ssh server, and a login user. Choosing &amp;quot;disks=none&amp;quot; for now, yet, configure to store configs on the boot media (if it is writable, otherwise on a separate storage media). And afterwards calling &amp;lt;code&amp;gt;[[Alpine_local_backup|lbu commit]]&amp;lt;/code&amp;gt; to store the configs as local backup. Then your completed setup, including its securely created own private keys, will readily get (re)loaded on every subsequent (headless) boot from your custom-build &amp;lt;code&amp;gt;&amp;lt;hostname&amp;gt;.apkovl.tar.gz&amp;lt;/code&amp;gt; stored on the boot media (or on an auxilary media or server location, in case the boot media is read-only).&lt;br /&gt;
# Booting the target computer from the prepared disk or storage device.&lt;br /&gt;
&lt;br /&gt;
The boot process of the alpine installation image first copies the entire operating system into the RAM memory, and then already starts a complete Alpine Linux system from there. It will initially only provide a basic command line environment that does not depend on reading from any (possibly slow) initial boot media, anymore.&lt;br /&gt;
&lt;br /&gt;
Local log-in is possible as the user &amp;lt;code&amp;gt;root&amp;lt;/code&amp;gt;. Initially, the root user has no password.&lt;br /&gt;
&lt;br /&gt;
At the command prompt, an interactive script named &amp;lt;code&amp;gt;setup-alpine&amp;lt;/code&amp;gt; is available to configure and install the initial Alpine Linux system.&lt;br /&gt;
&lt;br /&gt;
The question-and-answer dialog of &amp;lt;code&amp;gt;setup-alpine&amp;lt;/code&amp;gt; takes care of the base configuration and allows to configure the system to boot into one of three different &#039;&#039;&#039;Alpine Linux &amp;quot;disk&amp;quot; modes&#039;&#039;&#039;: &#039;&#039;&#039;&amp;quot;diskless&amp;quot;&#039;&#039;&#039;(none), &#039;&#039;&#039;&amp;quot;data&amp;quot;&#039;&#039;&#039;, or &#039;&#039;&#039;&amp;quot;sys&amp;quot;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
These modes are explained in more detail in the following subsections.&lt;br /&gt;
&lt;br /&gt;
{{Note|It is really helpful for many cases that it is possible to first only complete a basic setup of the initial &amp;quot;diskless&amp;quot; installation media in order to prepare for the installation of the target system. For example, also to download and install some specific driver or software tool. And to possibly use more specific [[Alpine_setup_scripts|setup-scripts]] afterwards in order to proceed with the final installation in a custom way. A most basic pre-setup of just the &amp;quot;diskless&amp;quot; system may be completed by running &amp;lt;code&amp;gt;setup-alpine&amp;lt;/code&amp;gt; and answering &amp;quot;none&amp;quot; when asked for the disk to use, for where to store configs, and for the location of the package cache.&lt;br /&gt;
&lt;br /&gt;
Examples of preparation options:&lt;br /&gt;
&lt;br /&gt;
* Preparing a custom partitioning or filesystem scheme that avoids to use and/or overwrite an entire disk ([[Installation#Custom_partitioning_of_the_harddisk|details below]]).&lt;br /&gt;
* Installing something that may be missing in the live system to configure the hardware, e.g. by using the alpine package manager &amp;lt;code&amp;gt;[[Alpine_Package_Keeper|apk]]&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Examples of proceeding options:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;[[Alpine_setup_scripts#setup-lbu|setup-lbu]]&amp;lt;/code&amp;gt; to configure a &amp;quot;local backup&amp;quot; location for the diskless system, and &amp;lt;code&amp;gt;[[Alpine_local_backup|lbu commit]]&amp;lt;/code&amp;gt; to then save the local configuration state.&lt;br /&gt;
* &amp;lt;code&amp;gt;[[Alpine_setup_scripts#setup-apkcache|setup-apkcache]]&amp;lt;/code&amp;gt; to configure a local package cache storage location.&lt;br /&gt;
* &amp;lt;code&amp;gt;[[Alpine_setup_scripts#setup-disk|setup-disk]]&amp;lt;/code&amp;gt; to add a &amp;quot;data&amp;quot; mode partition, or do a classic full install of the &amp;quot;diskless&amp;quot; system onto a &amp;quot;sys&amp;quot; disk or partition.&lt;br /&gt;
&lt;br /&gt;
There are many more [[Alpine_setup_scripts|setup-scripts]] available. All these tools may also be run later to adjust specific configurations. For example, to set up a graphical environment as covered under [[Installation#Post-Installation|Post-Installation]] below.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
===&#039;&#039;&#039;Diskless Mode&#039;&#039;&#039;=== &lt;br /&gt;
This means the entire operating system with all applications are first loaded into RAM and then only run from there. This is the method already used to boot the .iso installation images, however &amp;lt;code&amp;gt;[[Alpine_setup_scripts#setup-alpine|setup-alpine]]&amp;lt;/code&amp;gt; can also configure the installed system to continue to boot like this if &amp;quot;disk=none&amp;quot; is specified. The mode is extremely fast and can save on unnecessary disk spin-ups, power, and wear. It is similar to what other linux distributions may call a &amp;quot;frugal&amp;quot; install or boot into with a &amp;quot;toram&amp;quot; option. &lt;br /&gt;
&lt;br /&gt;
Custom configurations and package installations may optionally still be preserved or &amp;quot;persist&amp;quot; across reboots by using the Alpine local backup tool &amp;lt;code&amp;gt;[[Alpine_local_backup|lbu]]&amp;lt;/code&amp;gt;. It enables committing and reverting system states by using .apkovl files that are saved to writable storage and loaded when booting. If additional or updated packages have been added to the system, these may also be made available for automatic (re)installation during the boot phase without any (re)downloading, by enabling a [[Alpine_Package_Keeper#Local_Cache|local package cache]] on the writable storage.&lt;br /&gt;
&lt;br /&gt;
[[https://gitlab.alpinelinux.org/alpine/alpine-conf/-/issues/10473 FIXME-1]: Storing local configs and the package cache on &#039;&#039;&#039;internal disks still require&#039;&#039;&#039; [[Alpine_local_backup#Saving_and_loading_ISO_image_customizations|some manual steps]] to have the partition listed, i.e. making a /etc/fstab entry, mountpoint, and mount, *before* running setup-alpine. The linked workaround also still requires to commit these configurations to disk manually before rebooting.]&lt;br /&gt;
&lt;br /&gt;
If a writable partition is available, &amp;lt;code&amp;gt;setup-alpine&amp;lt;/code&amp;gt; can be told to store the configs and the package cache on that writable partition. (Later, another directory on that same partition or another available partition may also be mounted as /home, or for example, for selected important applications to keep their run-time and user data on it.)&lt;br /&gt;
&lt;br /&gt;
The boot device of the newly configured local &amp;quot;diskless&amp;quot; system may remain the initial (and possibly read-only) installation media. But it is also possible to copy the boot system to a partition (e.g. /dev/sdXY) with &amp;lt;code&amp;gt;[[Alpine_setup_scripts#setup-bootable|setup-bootable]]&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===&#039;&#039;&#039;Data Disk Mode&#039;&#039;&#039;=== &lt;br /&gt;
This mode also runs from system RAM, thus it enjoys the same accelerated operation speed as &amp;quot;diskless&amp;quot; mode. However, swap storage and the entire {{Path|/var}} directory tree get mounted from a persistent storage device (two newly created partitions). The directory {{Path|/var}} holds e.g. all log files, mailspools, databases, etc., as well as &amp;lt;code&amp;gt;[[Alpine_local_backup|lbu]]&amp;lt;/code&amp;gt; backup commits and the package cache. This mode is useful for having RAM accelerated servers with variable amounts of user-data that exceed the available RAM size. It enables the entire current system state (not just the boot state) to survive a system crash in accordance with the particular filesystem guarantees. &lt;br /&gt;
&lt;br /&gt;
[[https://gitlab.alpinelinux.org/alpine/alpine-conf/-/issues/10474 FIXME-2]]: Setup-alpine will create the data partition and mount it as /var, but &#039;&#039;&#039;setup-alpine&#039;s &amp;quot;data&amp;quot; disk mode can not yet configure lbu config storage settings automatically&#039;&#039;&#039;. The &#039;&#039;&#039;current workaround&#039;&#039;&#039;, is to select &amp;quot;none&amp;quot; at the &#039;where to store configs&#039; prompt (as the new data partition is not listed anyway) and configure lbu manually after &amp;lt;code&amp;gt;[[Alpine_setup_scripts#setup-alpine|setup-alpine]]&amp;lt;/code&amp;gt; exits, and before rebooting:&lt;br /&gt;
&lt;br /&gt;
# Identify the created data partition, e.g. &amp;lt;code&amp;gt;/dev/sd&#039;&#039;XY&#039;&#039;&amp;lt;/code&amp;gt;, and its filesystemtype, e.g. using &amp;lt;code&amp;gt;&#039;&#039;lsblk&#039;&#039;&amp;lt;/code&amp;gt;&lt;br /&gt;
# Manually edit the lbu backups location in &amp;lt;code&amp;gt;/etc/lbu/lbu.conf&amp;lt;/code&amp;gt; and configure &amp;lt;code&amp;gt;LBU_MEDIA=sd&#039;&#039;XY&#039;&#039;&amp;lt;/code&amp;gt; (according to the previous findings).&lt;br /&gt;
# Save the configuration on that partition for the next boot with &amp;lt;code&amp;gt;lbu commit&amp;lt;/code&amp;gt;.&lt;br /&gt;
# If (a new) partition fails to get mounted, execute: &amp;lt;code&amp;gt;mkdir /media/&#039;&#039;sdXY&#039;&#039; ; echo &amp;quot;/dev/sd&#039;&#039;XY&#039;&#039; /media/sd&#039;&#039;XY&#039;&#039; &#039;&#039;fstype&#039;&#039; noauto,rw 0 0&amp;quot; &amp;gt;&amp;gt; /etc/fstab&amp;lt;/code&amp;gt;, and try &amp;lt;code&amp;gt;lbu commit&amp;lt;/code&amp;gt; again.&lt;br /&gt;
&lt;br /&gt;
In data disk mode, the boot device may also remain the initial (and possibly read-only) installation media, or be copied to a partition (e.g. /dev/sdXY) with &amp;lt;code&amp;gt;[[Alpine_setup_scripts#setup-bootable|setup-bootable]]&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===&#039;&#039;&#039;System Disk Mode&#039;&#039;&#039;=== &lt;br /&gt;
This is a traditional hard-disk install.&lt;br /&gt;
&lt;br /&gt;
If this mode is selected, the &amp;lt;code&amp;gt;[[Alpine_setup_scripts#setup-alpine|setup-alpine]]&amp;lt;/code&amp;gt; script creates three partitions on the selected storage device, {{Path|/boot}}, {{Path|swap}} and {{Path|/}} (the filesystem root). This mode may, for example, be used for generic [[:Category:Desktop|desktop]] and development machines.&lt;br /&gt;
&lt;br /&gt;
For custom partitioning, see [[Setting up disks manually]].&lt;br /&gt;
&lt;br /&gt;
To install along side another operating systems, see [[Dualbooting]].&lt;br /&gt;
&lt;br /&gt;
== Preparing for the installation ==&lt;br /&gt;
&lt;br /&gt;
{{Note|This &amp;quot;Additional Details&amp;quot; section needs to be consolidated with the work at &#039;&#039;&#039;[https://docs.alpinelinux.org https://docs.alpinelinux.org] (not finished)&#039;&#039;&#039; &lt;br /&gt;
(Restructuring things there, moving and linking from here or there?).}} &lt;br /&gt;
&lt;br /&gt;
=== Verifying the downloaded image-file ===&lt;br /&gt;
&lt;br /&gt;
{|  class=&amp;quot;wikitable&amp;quot; style=&amp;quot;width:95%; align=center&amp;quot;&lt;br /&gt;
|+ Commands to verify the checksum and GPG signature of a downloaded image-file on different systems.&lt;br /&gt;
|-&lt;br /&gt;
! width=100px |  OS type&lt;br /&gt;
!  &amp;lt;code&amp;gt;SHA256&amp;lt;/code&amp;gt; check !! &amp;lt;code&amp;gt;SHA256&amp;lt;/code&amp;gt; calculation (to be compared manually) !! &amp;lt;code&amp;gt;GPG&amp;lt;/code&amp;gt; signature verification&lt;br /&gt;
|-&lt;br /&gt;
! Linux&lt;br /&gt;
| &amp;lt;code&amp;gt;sha256sum -c alpine-*.iso.sha256&amp;lt;/code&amp;gt; ||        || &amp;lt;code&amp;gt;curl https://alpinelinux.org/keys/ncopa.asc &amp;amp;#124; gpg --import ;&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt; gpg --verify alpine-&amp;lt;version&amp;gt;.iso.asc alpine-&amp;lt;version&amp;gt;.iso&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! MACOS  &lt;br /&gt;
| - ? -  || &amp;lt;code&amp;gt;shasum -a 256 alpine-*.iso&amp;lt;/code&amp;gt; || - ? -&lt;br /&gt;
|-&lt;br /&gt;
! OpenBSD  &lt;br /&gt;
| &amp;lt;code&amp;gt;sha256 -C alpine-*.sha256 alpine-*.iso&amp;lt;/code&amp;gt; ||        || &amp;lt;code&amp;gt;doas pkg_add gnupg;&lt;br /&gt;
ftp -o - https://alpinelinux.org/keys/ncopa.asc &amp;amp;#124; gpg --import ;&lt;br /&gt;
gpg --verify alpine-&amp;lt;version&amp;gt;.iso.asc alpine-&amp;lt;version&amp;gt;.iso&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! FreeBSD  &lt;br /&gt;
| - ? - || &amp;lt;code&amp;gt;/usr/local/bin/shasum -a 256 alpine-*.iso&amp;lt;/code&amp;gt; || - ? -&lt;br /&gt;
|-&lt;br /&gt;
! NetBSD  &lt;br /&gt;
| - ? - || &amp;lt;code&amp;gt;/usr/local/bin/shasum -a 256 alpine-*.iso&amp;lt;/code&amp;gt; || - ? -&lt;br /&gt;
|-&lt;br /&gt;
! Windows&lt;br /&gt;
|                 - ? -             || &amp;lt;code&amp;gt;certutil -hashfile alpine-*.iso SHA256&amp;lt;/code&amp;gt; || - ? -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Flashing (direct data writing) the installation image-file onto a device or media  ===&lt;br /&gt;
{{Seealso|Burning ISOs}}&lt;br /&gt;
&lt;br /&gt;
{{Note|These instructions are exclusively for x86_64 and x86. For ARM boards, see [[Alpine on ARM#Preparing installation media]].}}&lt;br /&gt;
&lt;br /&gt;
==== Unix/Linux ====&lt;br /&gt;
&lt;br /&gt;
Under Unix (and thus Linux), &amp;quot;everything is a file&amp;quot; and the data in the image-file can be written to a device or media with the &amp;lt;code&amp;gt;dd&amp;lt;/code&amp;gt; command. Afterward, executing the &amp;lt;code&amp;gt;eject&amp;lt;/code&amp;gt; command removes the target device from the system and ensures the write cache is completely flushed.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|dd if{{=}}&amp;lt;iso-file-to-read-in&amp;gt; of{{=}}&amp;lt;target-device-node-to-write-out-to&amp;gt; bs{{=}}4M; eject &amp;lt;target-device-node-to-write-to&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Be careful to correctly identify the target device as any data on it &#039;&#039;&#039;will&#039;&#039;&#039; be lost! All connected &amp;quot;bulk storage devices&amp;quot; can be listed with &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;lsblk&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;blkid&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
 # lsblk&lt;br /&gt;
 NAME            MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT&lt;br /&gt;
 sdX               0:0    0  64,0G  0 disk  &lt;br /&gt;
 ├─sdX1            0:1    0     2G  0 part  &lt;br /&gt;
 └─sdX2            0:2    0    30G  0 part  /mnt/sdX2&lt;br /&gt;
 &lt;br /&gt;
 # blkid&lt;br /&gt;
 /dev/sdX1: LABEL=&amp;quot;some&amp;quot; UUID=&amp;quot;...&amp;quot; TYPE=&amp;quot;vfat&amp;quot;&lt;br /&gt;
 /dev/sdX2: LABEL=&amp;quot;other&amp;quot; UUID=&amp;quot;...&amp;quot; TYPE=&amp;quot;ext4&amp;quot;&lt;br /&gt;
&lt;br /&gt;
For example, if /dev/sdX is the desired target device, first make sure you un-mount all mounted partitions of the target device. For example sdX1 and sdX2:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|umount /dev/sdX1 /dev/sdX2}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For &amp;lt;code&amp;gt;dd&amp;lt;/code&amp;gt;&#039;s output-file (&amp;lt;code&amp;gt;of=&amp;lt;/code&amp;gt;), however, do &#039;&#039;&#039;not&#039;&#039;&#039; specify a partition number. For example, write to sdX, &#039;&#039;&#039;not&#039;&#039;&#039; sdX1:&lt;br /&gt;
&lt;br /&gt;
Warning: &#039;&#039;&#039;This will overwrite the target device /dev/sdX&#039;&#039;&#039;, so before executing, make sure you have a backup of the data if you can&#039;t afford to lose it.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|dd if{{=}}~/Downloads/alpine-standard-3.00.0-x86_64.iso of{{=}}/dev/sdX bs{{=}}4M; eject /dev/sdX}}&lt;br /&gt;
&lt;br /&gt;
==== Windows ====&lt;br /&gt;
&lt;br /&gt;
For example, there is the [https://rufus.ie/ Rufus] program. Rufus will enable you to create bootable USB flash drives under Windows. &lt;br /&gt;
&lt;br /&gt;
Rufus has been tested and works for Alpine Linux 3.12.x with the following settings:&lt;br /&gt;
* &#039;&#039;&#039;Partition scheme&#039;&#039;&#039;: &amp;lt;code&amp;gt;MBR&amp;lt;/code&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Target system&#039;&#039;&#039;: &amp;lt;code&amp;gt;BIOS or UEFI&amp;lt;/code&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;File system&#039;&#039;&#039;: &amp;lt;code&amp;gt;FAT32&amp;lt;/code&amp;gt;&lt;br /&gt;
* &#039;&#039;&#039;Cluster size&#039;&#039;&#039;: &amp;lt;code&amp;gt;4096 bytes (default)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===  Verifying the written installation media ===&lt;br /&gt;
&lt;br /&gt;
After detaching and re-attaching the device, a bit-wise comparison can verify the data written to the device (instead of just data buffered in RAM). If the comparison terminates with an end-of-file error on the .iso file side, all the contents from the image have been written (and re-read) successfully:&lt;br /&gt;
&lt;br /&gt;
 # cmp ~/Downloads/alpine-standard-3.00.0-x86_64.iso /dev/sdX&lt;br /&gt;
 cmp: EOF on alpine-standard-3.00.0-x86_64.iso&lt;br /&gt;
&lt;br /&gt;
=== Booting from external devices ===&lt;br /&gt;
&lt;br /&gt;
Insert the boot media to a proper drive or port of the computer and turn the machine on, or restart it, if already running.&lt;br /&gt;
&lt;br /&gt;
If the computer does not automatically boot from the desired device, one needs to bring up the boot menu and choose the media to boot from. Depending on the computer, the menu may be accessed by repeatedly pressing a key quickly when booting starts. Some computers require that you press the button &#039;&#039;before&#039;&#039; starting the computer and hold it down while the computer boots. Typical keys are:  {{key|F9}}-{{key|F12}}, sometimes {{key|F7}} or {{key|F8}}. If these don&#039;t bring up the boot menu, it may be necessary to enter the BIOS configuration and adjust the boot settings, for which typical keys are: {{key|Del}} {{key|F1}} {{key|F2}} {{key|F6}} or {{key|Esc}}.&lt;br /&gt;
&lt;br /&gt;
== Installation Step Details ==&lt;br /&gt;
&lt;br /&gt;
=== Custom partitioning of the harddisk ===&lt;br /&gt;
&lt;br /&gt;
It is possible to specify configurations for RAID, encryption, LVM, etc. as well as manual partitioning.&lt;br /&gt;
&lt;br /&gt;
For &amp;quot;diskless&amp;quot; or &amp;quot;data disk&amp;quot; mode installs, manual partitioning may be needed to prepare the harddisk for committing local backups of the system state with &amp;lt;code&amp;gt;[[Alpine_local_backup|lbu commit]]&amp;lt;/code&amp;gt;, to have a place for a package cache, or to use it for a /var mount. &lt;br /&gt;
&lt;br /&gt;
For a &amp;quot;sys&amp;quot; install, custom partitioning is needed only if the desired scheme differs from overwriting an entire disk, or using the default set of a /boot, swap and root partition on the disk.&lt;br /&gt;
&lt;br /&gt;
See [[Setting up disks manually]] for the alpine options for RAID, encryption, LVM, etc. and manual partitioning.&lt;br /&gt;
&lt;br /&gt;
=== Questions asked by &amp;lt;code&amp;gt;setup-alpine&amp;lt;/code&amp;gt; ===&lt;br /&gt;
[[File:Installation-alpine-alpine-setup-3-setup-scripts.png|350px|thumb|right|Example &amp;lt;code&amp;gt;[[Alpine_setup_scripts#setup-alpine|setup-alpine]]&amp;lt;/code&amp;gt; session]]&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;[[Alpine_setup_scripts#setup-alpine|setup-alpine]]&amp;lt;/code&amp;gt; script offers the following configuration options:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;Keyboard Layout&#039;&#039;&#039; (Local keyboard language and usage mode, e.g. &#039;&#039;us&#039;&#039; and variant of &#039;&#039;us-nodeadkeys&#039;&#039;.)&lt;br /&gt;
* &#039;&#039;&#039;Hostname&#039;&#039;&#039; (The name for the computer.)&lt;br /&gt;
* &#039;&#039;&#039;Network&#039;&#039;&#039; (For example, automatic IP address discovery with the &amp;quot;DHCP&amp;quot; protocol.)&lt;br /&gt;
* &#039;&#039;&#039;DNS Servers&#039;&#039;&#039; (Domain Name Servers to query. If unsure, leave DNS domain name blank and using &amp;lt;code&amp;gt;[https://quad9.net/ 9.9.9.9 2620:fe::fe]&amp;lt;/code&amp;gt; for DNS is typically adequate.)&lt;br /&gt;
* &#039;&#039;&#039;Root password&#039;&#039;&#039; (the password used to login to the root account)&lt;br /&gt;
* &#039;&#039;&#039;Timezone&#039;&#039;&#039; (Optionally display times/dates in your local time zone)&lt;br /&gt;
* &#039;&#039;&#039;HTTP/FTP Proxy&#039;&#039;&#039; (Proxy server to use for accessing the web/ftp. Use &amp;quot;none&amp;quot; for direct connections to websites and FTP servers.)&lt;br /&gt;
* &#039;&#039;&#039;Mirror&#039;&#039;&#039; (From where to download packages. Choose the organization you trust giving your usage patterns to.)&lt;br /&gt;
* &#039;&#039;&#039;Setup a user&#039;&#039;&#039; (Setting up a regular user account)&lt;br /&gt;
* &#039;&#039;&#039;NTP&#039;&#039;&#039; (Network Time Protocol client used for keeping the system clock in sync with a time server. Package &amp;quot;chrony&amp;quot; is part of the default install image.)&lt;br /&gt;
* &#039;&#039;&#039;SSH&#039;&#039;&#039; (Secure SHell remote access server. &amp;quot;OpenSSH&amp;quot; is part of the default install image. Use &amp;quot;none&amp;quot; to disable remote login, e.g. on laptops.)&lt;br /&gt;
* &#039;&#039;&#039;Disk Mode&#039;&#039;&#039; (Select between diskless (disk=&amp;quot;none&amp;quot;), &amp;quot;data&amp;quot; or &amp;quot;sys&amp;quot;, as described above.) &lt;br /&gt;
{{Warning|After this step, the data on the chosen device will be overwritten!}}&lt;br /&gt;
&lt;br /&gt;
=== Preparing for the first boot ===&lt;br /&gt;
&lt;br /&gt;
If &amp;lt;code&amp;gt;[[Alpine_setup_scripts#setup-alpine|setup-alpine]]&amp;lt;/code&amp;gt; has finished configuring the &amp;quot;sys&amp;quot; disk mode, the system should be ready to reboot right away (see next subsection).&lt;br /&gt;
&lt;br /&gt;
If the new local system was configured to run in &amp;quot;diskless&amp;quot; or &amp;quot;data&amp;quot; mode, and you do not want keep booting from the initial (and possibly read-only) installation media, the boot system needs to be copied to another device or partition.&lt;br /&gt;
&lt;br /&gt;
The target partition may be identified using {{ic|lsblk}} (after installing it with {{ic|apk add {{pkg|lsblk}}}}) and/or {{ic|blkid}}, similar to previously identifying the initial installation media device.&lt;br /&gt;
&lt;br /&gt;
The procedure to copy the boot system is explained at [[Alpine_setup_scripts#setup-bootable|setup-bootable]]&lt;br /&gt;
&lt;br /&gt;
Once everything is in place, save your customized configuration with {{ic|lbu commit}} before rebooting.&lt;br /&gt;
&lt;br /&gt;
=== Rebooting and testing the new system ===&lt;br /&gt;
&lt;br /&gt;
First, remove the initial installation media from the boot drive, or detach it from the port it&#039;s connected to.&lt;br /&gt;
&lt;br /&gt;
The system may now be power-cycled or rebooted to confirm everything is working correctly.&lt;br /&gt;
&lt;br /&gt;
The relevant commands for this are {{ic|poweroff}} or {{ic|reboot}}.&lt;br /&gt;
&lt;br /&gt;
=== Completing the installation ===&lt;br /&gt;
&lt;br /&gt;
The installation script installs only the base operating system. &#039;&#039;&#039;No&#039;&#039;&#039; applications e.g. web server, mail server, desktop environment, or web browsers are installed.&lt;br /&gt;
&lt;br /&gt;
Please look under [[Installation#Post-Installation|Post-Installation]] below, for some common things to do after installation.&lt;br /&gt;
&lt;br /&gt;
= Further Installation Instructions =&lt;br /&gt;
&lt;br /&gt;
{{Note| Specific topics should be kept on separate, individually manageable topic-pages and only get listed with a direct reference (link) on this general page.}}&lt;br /&gt;
&lt;br /&gt;
=== Installation ===&lt;br /&gt;
&lt;br /&gt;
* [[Kernels]] &#039;&#039;(kernel selection, e.g. for VMs or RPi)&#039;&#039;&lt;br /&gt;
* [[How to make a custom ISO image with mkimage]] &#039;&#039;(installation media with its own configuration)&#039;&#039;&lt;br /&gt;
* [[Directly booting an ISO file]] &#039;&#039;(without flashing it to a disk or device)&#039;&#039;&lt;br /&gt;
* [[Dualbooting|Dual/multi-boot install to HDD partition]]&lt;br /&gt;
* [[Netboot Alpine Linux using iPXE]]&lt;br /&gt;
Also see other [[:Category:Installation|Installation Category]] pages.&lt;br /&gt;
&lt;br /&gt;
=== Post-Installation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- COMMENT FOR EDITORS&lt;br /&gt;
&lt;br /&gt;
If you edit Post-Install,&lt;br /&gt;
&lt;br /&gt;
  * Consider that there are already [[Tutorials_and_Howtos#Post-Install]], [[Developer_Documentation#Package_management]] and the Handbook, please work towards reducing duplication and providing an overview, and maintaining topic details of considerable size on their own pages.&lt;br /&gt;
  * Here, only the most relevant jumping off points are listed, not exact list duplicates!!!&lt;br /&gt;
  * Keep short-list of links here, as overview to more detailed topic specific pages.&lt;br /&gt;
  * Don&#039;t aggregate different topics at yet another place.&lt;br /&gt;
&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [[Setting up a new user]] &#039;&#039;(to allow remote, console, or graphical logins)&#039;&#039;&lt;br /&gt;
* [[Tutorials_and_Howtos#Networking_2|Setting up Networking]] &#039;&#039;(including non-standard configurations)&#039;&#039;&lt;br /&gt;
* [[Alpine_Package_Keeper|Package Management (apk)]] &#039;&#039;(how to search/add/del packages etc.)&#039;&#039;&lt;br /&gt;
** [[Alpine_Package_Keeper#Upgrade_a_Running_System|Upgrading Alpine]] &#039;&#039;(checking for and installing updates)&#039;&#039;&lt;br /&gt;
** [[Repositories#Managing_repositories|Enable the community repository]] &#039;&#039;(access to additional packages)&#039;&#039;&lt;br /&gt;
* [[Alpine_Linux:FAQ#Why_don.27t_I_have_man_pages_or_where_is_the_.27man.27_command.3F|man command/man pages]]&lt;br /&gt;
* [[Change default shell]]&lt;br /&gt;
* [[Running glibc programs]] &#039;&#039;(installation and development)&#039;&#039;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[Alpine_local_backup|Local backup utility &amp;lt;code&amp;gt;lbu&amp;lt;/code&amp;gt;]] &#039;&#039;(persisting RAM system configurations)&#039;&#039;&lt;br /&gt;
** [[Back Up a Flash Memory Installation]] &#039;&#039;(&amp;quot;diskless mode&amp;quot; systems)&#039;&#039;&lt;br /&gt;
** [[Manually editing a existing apkovl]] &#039;&#039;(the stored custom configs)&#039;&#039;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[OpenRC|Init System (OpenRC)]] &#039;&#039;(configure a service to automatically boot at next reboot)&#039;&#039;&lt;br /&gt;
** [[Writing Init Scripts]]&lt;br /&gt;
** [[Multiple Instances of Services]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[Alpine setup scripts#setup-xorg-base|&amp;lt;code&amp;gt;setup-xorg-base&amp;lt;/code&amp;gt;]] &#039;&#039;(setup graphical base environment)&#039;&#039;&lt;br /&gt;
** [[Tutorials_and_Howtos#Desktop|Desktop Environments]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[Hosting services on Alpine]] &#039;&#039;(links to several mail/web/ssh server setup pages)&#039;&#039;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[How to get regular stuff working]] &#039;&#039;(things one may miss in a too lightweight installation )&#039;&#039;&lt;br /&gt;
* Running applications and services in their own [[Firejail Security Sandbox]]&lt;br /&gt;
&lt;br /&gt;
=== Broader Usage Guides ===&lt;br /&gt;
&lt;br /&gt;
* See: [[Tutorials and Howtos]]&lt;br /&gt;
&lt;br /&gt;
= General Documentation =&lt;br /&gt;
&lt;br /&gt;
{{Tip| Alpine Linux packages stay close to the upstream design. Therefore, all upstream documentation about configuring a software package, as well as good configuration guides from other distributions that stay close to upstream, e.g. those in the [https://wiki.archlinux.org/ ArchWiki], are to a large degree, also applicable to configuring the software on Alpine Linux, thus can be very useful.}}&lt;br /&gt;
&lt;br /&gt;
* [[Alpine_Linux:FAQ|FAQs]]&lt;br /&gt;
* [[Alpine_Linux:Contribute|How to Contribute]]&lt;br /&gt;
* [[Developer Documentation]]&lt;br /&gt;
* [[Alpine_Linux:Wiki_etiquette|Wiki etiquette]] &#039;&#039;(to collaborate on this documentation)&#039;&#039;&lt;br /&gt;
* [[Comparison with other distros]] &#039;&#039;(how common things are done on Alpine)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
[[Category:Installation]]&lt;/div&gt;</summary>
		<author><name>Mmhiro</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=LVM_on_LUKS&amp;diff=26676</id>
		<title>LVM on LUKS</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=LVM_on_LUKS&amp;diff=26676"/>
		<updated>2024-05-04T15:45:38Z</updated>

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

		<summary type="html">&lt;p&gt;Mmhiro: Alpine Linux installer now has encryption option&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[https://en.wikipedia.org/wiki/Linux%20Unified%20Key%20Setup LUKS] allows encrypting a partition and mapping it as a virtual block device, which can then be used as a normal partition. Guides for other Linux distributions should serve as a general references for installing Alpine onto a LUKS encrypted disk.&lt;br /&gt;
&lt;br /&gt;
The installer has built-in support for encryption. The default installer will not encrypt the swap partition and the boot partition. To setup Alpine Linux with an encrypted swap partition, refer to [[LVM on LUKS]]. The GRUB bootloader supports BIOS and EFI boot with an encrypted boot partition.&lt;br /&gt;
&lt;br /&gt;
== mkinitfs and LUKS ==&lt;br /&gt;
&lt;br /&gt;
For those familiar with setting up FDE on other Linux distributions, this section contains only Alpine-specific knowledge required is understanding [[mkinitfs]].&lt;br /&gt;
&lt;br /&gt;
First of all, the &amp;lt;code&amp;gt;cryptsetup&amp;lt;/code&amp;gt; feature needs to be added to &amp;lt;code&amp;gt;/etc/mkinitfs/mkinitfs.conf&amp;lt;/code&amp;gt;. Additionally, the following kernel parameters are required:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;cryptroot&amp;lt;/code&amp;gt; kernel parameter should point to the encrypted block device. &lt;br /&gt;
* &amp;lt;code&amp;gt;root&amp;lt;/code&amp;gt; kernel parameter should point to the mapped block device (e.g.: the &amp;lt;code&amp;gt;ext4&amp;lt;/code&amp;gt;/&amp;lt;code&amp;gt;btrfs&amp;lt;/code&amp;gt; volume that is exposed once the encrypted partition is unlocked).&lt;br /&gt;
* &amp;lt;code&amp;gt;rootfstype&amp;lt;/code&amp;gt;: The filesystem type of the root partition (e.g.: &amp;lt;code&amp;gt;btrfs&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [https://wiki.archlinux.org/index.php/Dm-crypt dm-crypt on ArchWiki]&lt;br /&gt;
&lt;br /&gt;
[[Category:Storage]]&lt;br /&gt;
[[Category:Security]]&lt;/div&gt;</summary>
		<author><name>Mmhiro</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Migrating_from_whirlpool_hash_for_LUKS_partitions&amp;diff=22713</id>
		<title>Migrating from whirlpool hash for LUKS partitions</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Migrating_from_whirlpool_hash_for_LUKS_partitions&amp;diff=22713"/>
		<updated>2022-12-02T08:10:40Z</updated>

		<summary type="html">&lt;p&gt;Mmhiro: Created page with &amp;quot;{{Draft}}  See: https://gitlab.alpinelinux.org/alpine/aports/-/issues/13004  OpenSSL 3.0 has desginated the whirlpool hash as [https://wiki.openssl.org/index.php/OpenSSL_3.0#Provider_implemented_digests legacy]. This means it may not be loaded by default by OpenSSL so you cannot decrypt partitions using whirlpool. This is an issue for Alpine users because since v3.17 OpenSSL 3.0 is default, and multiple articles on this wiki recommended the use of whirlpool. In some case...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Draft}}&lt;br /&gt;
&lt;br /&gt;
See: https://gitlab.alpinelinux.org/alpine/aports/-/issues/13004&lt;br /&gt;
&lt;br /&gt;
OpenSSL 3.0 has desginated the whirlpool hash as [https://wiki.openssl.org/index.php/OpenSSL_3.0#Provider_implemented_digests legacy]. This means it may not be loaded by default by OpenSSL so you cannot decrypt partitions using whirlpool. This is an issue for Alpine users because since v3.17 OpenSSL 3.0 is default, and multiple articles on this wiki recommended the use of whirlpool. In some cases (i.e. with an encrypted boot partition) a user may not be able to boot their system at all.&lt;br /&gt;
&lt;br /&gt;
== Migrate Away from Whirlpool ==&lt;br /&gt;
&lt;br /&gt;
This has been tested on a LUKS1 partition. I am not responsible if you lose all your data.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;If you suffer a power failure, kernel panic, or any interruption during the reencryption step, your data may be permanently lost.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
First, get a LiveCD with cryptsetup (I used Fedora 37). Older versions of cryptsetup require &amp;lt;code&amp;gt;cryptsetup-reencrypt&amp;lt;/code&amp;gt; to modify LUKS1 partitions, while newer versions (2.5.0 or 2.6.0 or later) use &amp;lt;code&amp;gt;cryptsetup reencrypt&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Then backup your drive. At the minimum, dump the headers using&lt;br /&gt;
&amp;lt;pre&amp;gt;cryptsetup --header-backup-file=backup_file_location.bin luksHeaderBackup /dev/partition&amp;lt;/pre&amp;gt;&lt;br /&gt;
You should store the header on a USB stick or some other form of persistent media.&lt;br /&gt;
&lt;br /&gt;
If you have keys that cannot be typed in (i.e. keyfiles) then you will have to either&lt;br /&gt;
# find &#039;&#039;&#039;one&#039;&#039;&#039; key that you want to preserve (you must know the keyslot, in this document it will be called N)&lt;br /&gt;
# or remove all keyfiles using &amp;lt;code&amp;gt;luksRemoveKey&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I removed my keyfile slot using &amp;lt;code&amp;gt;luksRemoveKey&amp;lt;/code&amp;gt; and then confirmed that my password still worked using &amp;lt;code&amp;gt;cryptsetup luksOpen --test-passphrase /dev/partition&amp;lt;/code&amp;gt;. If you mess up, you can try recovering your keys using &amp;lt;code&amp;gt;luksHeaderRestore&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Make sure that the device is not opened (if you had to get files off of it, run &amp;lt;code&amp;gt;cryptsetup luksClose device_name&amp;lt;/code&amp;gt;). If you are preserving keyslot N, run&lt;br /&gt;
&amp;lt;pre&amp;gt;cryptsetup reencrypt --keep-key --key-slot N --key-file keyfile.bin --hash sha512 /dev/partition&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
If you are not specifying a keyfile, run&lt;br /&gt;
&amp;lt;pre&amp;gt;cryptsetup reencrypt --keep-key --key-slot N --hash sha512 /dev/partition&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and enter all passwords into the prompts. You can specify another hash if you want to, but sha512 is probably your best choice right now.&lt;br /&gt;
&lt;br /&gt;
Once the command is done (should take a few seconds), verify that you can successfully open and mount your partition.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;If you use an encrypted boot&#039;&#039;&#039;, then you must also reinstall grub. Open your partition with cryptsetup and mount it. Enter the directory and run&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mount -t proc /proc proc/&lt;br /&gt;
mount -t sysfs /sys sys/&lt;br /&gt;
mount --rbind /dev dev/&lt;br /&gt;
chroot . /bin/ash&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Then run &amp;lt;code&amp;gt;grub-install&amp;lt;/code&amp;gt;. The command line will differ depending on your setup (EFI vs. MBR). On MBR run&lt;br /&gt;
&amp;lt;pre&amp;gt; grub-install /dev/sdX &amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Mmhiro</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=LVM_on_LUKS&amp;diff=22709</id>
		<title>LVM on LUKS</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=LVM_on_LUKS&amp;diff=22709"/>
		<updated>2022-12-02T07:27:23Z</updated>

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

		<summary type="html">&lt;p&gt;Mmhiro: whirlpool is a legacy hash in OpenSSL 3.0, used in Alpine 3.17. This breaks decryption in initramfs.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Native Encryption =&lt;br /&gt;
&lt;br /&gt;
ZFS now has native support for encryption.  This has many advantages over ZFS on LUKS including multi-disk, encrypted zfs send, portable across *BSD/Linux and others.&lt;br /&gt;
&lt;br /&gt;
For a Root on ZFS guide with native encryption, see [https://openzfs.github.io/openzfs-docs/Getting%20Started/Alpine%20Linux/Root%20on%20ZFS/1-preparation.html here].&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
This documentation describes how to set up Alpine Linux using ZFS with a pool that is located in an encrypted partition. To encrypt the partition the Device Mapper crypt (dm-crypt) module and Linux Unified Key Setup (LUKS) is used.&lt;br /&gt;
&lt;br /&gt;
Note that you must install the &amp;lt;code&amp;gt;/boot/&amp;lt;/code&amp;gt; directory on an unecrypted partition to boot correctly.&lt;br /&gt;
&lt;br /&gt;
We&#039;ll be using the syslinux bootloader and traditional BIOS booting.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
* An instance Alpine on a medium other than the one you&#039;ll boot from, see [[Installation|official installation guide.]]&lt;br /&gt;
{{Note|We can&#039;t use the live environment from the installation isos, because we&#039;ll install the ZFS kernel module and that isn&#039;t possible with a read-only /boot (as provided by the iso).}}&lt;br /&gt;
&lt;br /&gt;
== Hard Disk Device Name ==&lt;br /&gt;
&lt;br /&gt;
The following documentation uses the &amp;lt;code&amp;gt;/dev/sda&amp;lt;/code&amp;gt; device as the installation destination. If your environment uses a different device name for your hard disk, use the corresponding device name in the examples.&lt;br /&gt;
&lt;br /&gt;
= Setting up Alpine Linux Using ZFS on Top of a LUKS Partition =&lt;br /&gt;
&lt;br /&gt;
To install Alpine Linux in a ZFS pool on top of a LUKS encrypted partition, you cannot use the [[Installation|official installation]] procedure. The installation requires several manual steps you must run in the Alpine Linux Live CD environment.&lt;br /&gt;
&lt;br /&gt;
== Preparing the Installation Environment ==&lt;br /&gt;
&lt;br /&gt;
Before you begin to install Alpine Linux on the medium you intend to boot from, prepare the installation you already have:&lt;br /&gt;
&lt;br /&gt;
* Update the &amp;lt;code&amp;gt;apk&amp;lt;/code&amp;gt; cache:&lt;br /&gt;
&lt;br /&gt;
 # apk update&lt;br /&gt;
&lt;br /&gt;
* Install the following packages required to set up ZFS and LUKS:&lt;br /&gt;
&lt;br /&gt;
 # apk add haveged cryptsetup e2fsprogs syslinux zfs zfs-$(uname -r | rev | cut -d&#039;-&#039; -f1 | rev)&lt;br /&gt;
 # modprobe zfs&lt;br /&gt;
&lt;br /&gt;
* Optionally, start the &amp;lt;code&amp;gt;haveged&amp;lt;/code&amp;gt; service for unpredictable random numbers used for encryption:&lt;br /&gt;
&lt;br /&gt;
 # rc-service haveged start&lt;br /&gt;
&lt;br /&gt;
== Creating the Partition Layout ==&lt;br /&gt;
&lt;br /&gt;
Linux requires an unencrypted &amp;lt;code&amp;gt;/boot/&amp;lt;/code&amp;gt; partition to boot. You can assign the remaining space for the encrypted ZFS pool.&lt;br /&gt;
&lt;br /&gt;
* Start the &amp;lt;code&amp;gt;fdisk&amp;lt;/code&amp;gt; utility to set up partitions:&lt;br /&gt;
&lt;br /&gt;
 # fdisk /dev/sda&lt;br /&gt;
&lt;br /&gt;
:* Create the &amp;lt;code&amp;gt;/boot/&amp;lt;/code&amp;gt; partition:&lt;br /&gt;
::* Enter &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; &amp;amp;rarr; &amp;lt;code&amp;gt;p&amp;lt;/code&amp;gt; &amp;amp;rarr; &amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt; &amp;amp;rarr; &amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt; &amp;amp;rarr; &amp;lt;code&amp;gt;100m&amp;lt;/code&amp;gt; to create a new 100 MB primary partition.&lt;br /&gt;
&lt;br /&gt;
:* Set the &amp;lt;code&amp;gt;/boot/&amp;lt;/code&amp;gt; partition active:&lt;br /&gt;
::* Enter &amp;lt;code&amp;gt;a&amp;lt;/code&amp;gt; &amp;amp;rarr; &amp;lt;code&amp;gt;1&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
:* Create the LUKS partition:&lt;br /&gt;
::* Enter &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; &amp;amp;rarr; &amp;lt;code&amp;gt;p&amp;lt;/code&amp;gt; &amp;amp;rarr; &amp;lt;code&amp;gt;2&amp;lt;/code&amp;gt; to start creating the next partition. Press &amp;lt;code&amp;gt;Enter&amp;lt;/code&amp;gt; to select the default start cylinder. Enter the partition size. For example, &amp;lt;code&amp;gt;512m&amp;lt;/code&amp;gt; for 512 MB or &amp;lt;code&amp;gt;5g&amp;lt;/code&amp;gt; for 5 GB. Alternatively, press &amp;lt;code&amp;gt;Enter&amp;lt;/code&amp;gt; to set the maximum available size.&lt;br /&gt;
&lt;br /&gt;
:* To verify the settings, press &amp;lt;code&amp;gt;p&amp;lt;/code&amp;gt;. The output should look similar to this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Device     Boot  Start      End  Sectors  Size Id Type&lt;br /&gt;
/dev/sda1  *      2048   206847   204800  100M 83 Linux&lt;br /&gt;
/dev/sda2       206848 41943039 41736192 19.9G 83 Linux&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Press &amp;lt;code&amp;gt;w&amp;lt;/code&amp;gt; to save the changes.&lt;br /&gt;
&lt;br /&gt;
* Optionally, fill the LUKS partition with random values:&lt;br /&gt;
&lt;br /&gt;
 # haveged -n 0 | dd of=/dev/sda2&lt;br /&gt;
&lt;br /&gt;
{{Note|Depending on the size of the partition, this process can take from several minutes to many hours.}}&lt;br /&gt;
&lt;br /&gt;
== Encrypting the ZFS Partition == &lt;br /&gt;
&lt;br /&gt;
* To encrypt the partition which will later contain the LVM PV:&lt;br /&gt;
&lt;br /&gt;
 # cryptsetup luksFormat /dev/sda2&lt;br /&gt;
&lt;br /&gt;
:{{Note|Alpine Linux uses the &amp;lt;code&amp;gt;en-us&amp;lt;/code&amp;gt; keyboard mapping when prompting for the password to encrypt the partition at boot time. If you changed the keyboard map in the temporary environment, the password you enter during encrypting the partition in this step, may not match the password you will enter during the system boots.}}&lt;br /&gt;
: If you prefer setting an individual hashing algorithm and hashing schema:&lt;br /&gt;
:* To run a benchmark:&lt;br /&gt;
&lt;br /&gt;
 # cryptsetup benchmark&lt;br /&gt;
&lt;br /&gt;
:* To encrypt the partition using individual settings, enter, for example:&lt;br /&gt;
&lt;br /&gt;
 # cryptsetup -v -c serpent-xts-plain64 -s 512 --hash sha512 --iter-time 5000 --use-random luksFormat /dev/sda2&lt;br /&gt;
&lt;br /&gt;
== Creating the filesystems ==&lt;br /&gt;
&lt;br /&gt;
* Open the LUKS partition:&lt;br /&gt;
&lt;br /&gt;
 # cryptsetup open --type luks /dev/sda2 crypt&lt;br /&gt;
&lt;br /&gt;
=== Creating the ZFS pool ===&lt;br /&gt;
&lt;br /&gt;
 # zpool create -o ashift=12 -O normalization=formD -O atime=off -m none -R /mnt -O compression=lz4 tank /dev/mapper/crypt&lt;br /&gt;
&lt;br /&gt;
Meaning of the &amp;lt;code&amp;gt;zpool create&amp;lt;/code&amp;gt; options:&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;5&amp;quot; border=&amp;quot;1&amp;quot; class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|- &lt;br /&gt;
! Option&lt;br /&gt;
! Meaning&lt;br /&gt;
|-&lt;br /&gt;
| zpool create&lt;br /&gt;
| Creating the zpool&lt;br /&gt;
|-&lt;br /&gt;
| -o ashift=12&lt;br /&gt;
| 4K blocks&lt;br /&gt;
|-&lt;br /&gt;
| -O normalization=formD&lt;br /&gt;
| Set the default Unicode (UTF-8) normalization to &#039;formD&#039;&lt;br /&gt;
|-&lt;br /&gt;
| -O atime=off&lt;br /&gt;
| Disabling updates to file access time. This reduces writes to disk, but might cause issues with mailers, like &amp;lt;code&amp;gt;mutt&amp;lt;/code&amp;gt;.&lt;br /&gt;
|-&lt;br /&gt;
| -m none&lt;br /&gt;
| No mountpoint, as we&#039;ll handle this later.&lt;br /&gt;
|-&lt;br /&gt;
| -R /mnt&lt;br /&gt;
| Set the altroot to &amp;lt;code&amp;gt;/mnt&amp;lt;/code&amp;gt;. It&#039;s like a temporary mountpoint for the pool.&lt;br /&gt;
|-&lt;br /&gt;
| -O compression=lz4&lt;br /&gt;
| Use lz4 compression for the pool. Is generally recommended.&lt;br /&gt;
|-&lt;br /&gt;
| tank&lt;br /&gt;
| The pool name. &amp;lt;code&amp;gt;tank&amp;lt;/code&amp;gt; will be used in throughout this guide.&lt;br /&gt;
|-&lt;br /&gt;
| /dev/mapper/crypt&lt;br /&gt;
| The path to the block device ZFS will use.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
After completing this, confirm that the pool has been created:&lt;br /&gt;
&lt;br /&gt;
 # zpool status&lt;br /&gt;
&lt;br /&gt;
Should return something like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  pool: tank&lt;br /&gt;
 state: ONLINE&lt;br /&gt;
  scan: none requested&lt;br /&gt;
config:&lt;br /&gt;
&lt;br /&gt;
	NAME         STATE     READ WRITE CKSUM&lt;br /&gt;
	tank         ONLINE       0     0     0&lt;br /&gt;
	  crypt      ONLINE       0     0     0&lt;br /&gt;
&lt;br /&gt;
errors: No known data errors&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Creating the required datasets ===&lt;br /&gt;
&lt;br /&gt;
 # zfs create -o mountpoint=none -o canmount=off tank/ROOT&lt;br /&gt;
 # zfs create -o mountpoint=/ tank/ROOT/alpine&lt;br /&gt;
&lt;br /&gt;
=== Creating optional datasets (feel free to add your own) ===&lt;br /&gt;
&lt;br /&gt;
 # zfs create -o mountpoint=/home tank/HOME&lt;br /&gt;
 # zfs create -o mountpoint=/var/log tank/LOG&lt;br /&gt;
&lt;br /&gt;
== Creating the &amp;lt;code&amp;gt;/boot&amp;lt;/code&amp;gt; filesystem ==&lt;br /&gt;
&lt;br /&gt;
 # mkfs.ext4 /dev/sda1&lt;br /&gt;
&lt;br /&gt;
== Mounting the &amp;lt;code&amp;gt;/boot&amp;lt;/code&amp;gt; filesystem ==&lt;br /&gt;
&lt;br /&gt;
* Create &amp;lt;code&amp;gt;/mnt/boot/&amp;lt;/code&amp;gt; directory and mount the &amp;lt;code&amp;gt;/dev/sda1&amp;lt;/code&amp;gt; partition in this directory:&lt;br /&gt;
&lt;br /&gt;
 # mkdir /mnt/boot/&lt;br /&gt;
 # mount -t ext4 /dev/sda1 /mnt/boot/&lt;br /&gt;
&lt;br /&gt;
== Installing Alpine Linux ==&lt;br /&gt;
&lt;br /&gt;
In this step you will install Alpine Linux in the &amp;lt;code&amp;gt;/mnt/&amp;lt;/code&amp;gt; directory, which contains the mounted file system structure.&lt;br /&gt;
&lt;br /&gt;
* Install Alpine Linux:&lt;br /&gt;
&lt;br /&gt;
 # setup-disk -m sys /mnt/&lt;br /&gt;
&lt;br /&gt;
: The installer downloads the latest packages to install the base installation. Additionally, the installer automatically creates the entries for the mount points in the &amp;lt;code&amp;gt;fstab&amp;lt;/code&amp;gt; file (but we&#039;ll have to edit it manually later), which are currently mounted in the &amp;lt;code&amp;gt;/mnt/&amp;lt;/code&amp;gt; directory.&lt;br /&gt;
&lt;br /&gt;
: {{Note|The automatic writing of the master boot record (MBR) fails in this step. Later, you&#039;ll write the MBR to the disk manually.}}&lt;br /&gt;
&lt;br /&gt;
* To enable the operating system to decrypt the LUKS partition at boot time, create the &amp;lt;code&amp;gt;/mnt/etc/crypttab&amp;lt;/code&amp;gt; file. Enter the following line into the file to decrypt the &amp;lt;code&amp;gt;/dev/sda2&amp;lt;/code&amp;gt; partition using the &amp;lt;code&amp;gt;luks&amp;lt;/code&amp;gt; module and map it to the &amp;lt;code&amp;gt;lvmcrypt&amp;lt;/code&amp;gt; name:&lt;br /&gt;
&lt;br /&gt;
 crypt    /dev/sda2    none    luks&lt;br /&gt;
&lt;br /&gt;
* Delete the zfs entries in &amp;lt;code&amp;gt;/mnt/etc/fstab&amp;lt;/code&amp;gt; as ZFS mounts them automagically. Your fstab should look similar to this:&lt;br /&gt;
&lt;br /&gt;
  UUID=6b4f2c9c-0a0f-4a8c-a73b-d2b47920ad6f	/boot	ext4	rw,relatime,stripe=4,data=ordered	0 2&lt;br /&gt;
&lt;br /&gt;
* Edit the &amp;lt;code&amp;gt;/mnt/etc/mkinitfs/mkinitfs.conf&amp;lt;/code&amp;gt; file and append the &amp;lt;code&amp;gt;cryptsetup&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;zfs&amp;lt;/code&amp;gt; module to the &amp;lt;code&amp;gt;features&amp;lt;/code&amp;gt; parameter:&lt;br /&gt;
&lt;br /&gt;
 features=&amp;quot;ata base ide scsi usb virtio ext4 lvm &amp;lt;u&amp;gt;cryptsetup zfs&amp;lt;/u&amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Rebuild the initial RAM disk:&lt;br /&gt;
&lt;br /&gt;
 # mkinitfs -c /mnt/etc/mkinitfs/mkinitfs.conf -b /mnt/ $(ls /mnt/lib/modules/)&lt;br /&gt;
&lt;br /&gt;
: The command uses the settings from the &amp;lt;code&amp;gt;mkinitfs.conf&amp;lt;/code&amp;gt; file set in the &amp;lt;code&amp;gt;-c&amp;lt;/code&amp;gt; parameter to generate the RAM disk. The command is executed in the &amp;lt;code&amp;gt;/mnt/&amp;lt;/code&amp;gt; directory and the RAM disk is generated using the modules for the installed kernel. Without setting the kernel version using the &amp;lt;code&amp;gt;$(ls /mnt/lib/modules/&amp;lt;/code&amp;gt;) option, &amp;lt;code&amp;gt;mkinitfs&amp;lt;/code&amp;gt; tries to generate the RAM disk using the kernel version installed in the temporary environment, which can differ from the latest one installed by the &amp;lt;code&amp;gt;setup-disk&amp;lt;/code&amp;gt; utility.&lt;br /&gt;
&lt;br /&gt;
* Edit the &amp;lt;code&amp;gt;/mnt/etc/update-extlinux.conf&amp;lt;/code&amp;gt; file, set the root ZFS dataset and append the following kernel options to the &amp;lt;code&amp;gt;default_kernel_opts&amp;lt;/code&amp;gt; parameter:&lt;br /&gt;
&lt;br /&gt;
 root=tank/ROOT/alpine&lt;br /&gt;
 default_kernel_opts=&amp;quot;... &amp;lt;u&amp;gt;cryptroot=/dev/sda2 cryptdm=crypt rootfstype=zfs&amp;lt;/u&amp;gt;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
: The &amp;lt;code&amp;gt;cryptroot&amp;lt;/code&amp;gt; parameter sets the name of the device that contains the root file system. The &amp;lt;code&amp;gt;cryptdm&amp;lt;/code&amp;gt; parameter sets the name of the mapping previously set in the &amp;lt;code&amp;gt;crypttab&amp;lt;/code&amp;gt; file. The &amp;lt;code&amp;gt;rootfstype&amp;lt;/code&amp;gt; option sets the root filesystem type to zfs.&lt;br /&gt;
&lt;br /&gt;
* Because the &amp;lt;code&amp;gt;update-extlinux&amp;lt;/code&amp;gt; utility operates only on the &amp;lt;code&amp;gt;/boot/&amp;lt;/code&amp;gt; directory, temporarily change the root to the &amp;lt;code&amp;gt;/mnt/&amp;lt;/code&amp;gt; directory and update the boot loader configuration:&lt;br /&gt;
&lt;br /&gt;
 # chroot /mnt/&lt;br /&gt;
 # update-extlinux&lt;br /&gt;
 # exit&lt;br /&gt;
&lt;br /&gt;
: Ignore the errors the &amp;lt;code&amp;gt;update-extlinux&amp;lt;/code&amp;gt; utility displays.&lt;br /&gt;
&lt;br /&gt;
* Write the MBR to the &amp;lt;code&amp;gt;/dev/sda&amp;lt;/code&amp;gt; device:&lt;br /&gt;
&lt;br /&gt;
 # dd bs=440 count=1 conv=notrunc if=/mnt/usr/share/syslinux/mbr.bin of=/dev/sda&lt;br /&gt;
&lt;br /&gt;
== Unmounting the filesystems ==&lt;br /&gt;
&lt;br /&gt;
* Unmount &amp;lt;code&amp;gt;/mnt/boot/&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 # umount /mnt/boot/&lt;br /&gt;
&lt;br /&gt;
* Unmount all zfs filesystems:&lt;br /&gt;
&lt;br /&gt;
 # zfs unmount -a&lt;br /&gt;
&lt;br /&gt;
* Export all zfs pools:&lt;br /&gt;
&lt;br /&gt;
 # zpool export -a&lt;br /&gt;
&lt;br /&gt;
* Close the &amp;lt;code&amp;gt;lvmcrypt&amp;lt;/code&amp;gt; device:&lt;br /&gt;
&lt;br /&gt;
 # cryptsetup luksClose crypt&lt;br /&gt;
&lt;br /&gt;
* Reboot the system:&lt;br /&gt;
&lt;br /&gt;
 # reboot&lt;br /&gt;
&lt;br /&gt;
= Troubleshooting =&lt;br /&gt;
&lt;br /&gt;
== General Procedure ==&lt;br /&gt;
&lt;br /&gt;
In case your system fails to boot, you can verify the settings and fix incorrect configurations:&lt;br /&gt;
&lt;br /&gt;
* [[#Preparing_the_Temporary_Installation_Environment|Prepare the temporary installation environment]]&lt;br /&gt;
&lt;br /&gt;
* Load the ZFS kernel module:&lt;br /&gt;
&lt;br /&gt;
 # modprobe zfs&lt;br /&gt;
&lt;br /&gt;
* [[#Mounting_the_File_Systems|Mount the file systems]]&lt;br /&gt;
&lt;br /&gt;
 # zpool import -R /mnt tank&lt;br /&gt;
 # mount -t ext4 /dev/sda1 /mnt/boot&lt;br /&gt;
&lt;br /&gt;
* Verify that you run the steps described in the [[#Installing_Alpine_Linux|Installing Alpine Linux]] section correctly. Update the configuration if necessary.&lt;br /&gt;
&lt;br /&gt;
* [[#Unmounting_the_Volumes_and_Partitions|Unmount the volumes and partitions]]&lt;br /&gt;
&lt;br /&gt;
{{Todo|Multiple Disk ZFS on LUKS?}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Storage]]&lt;br /&gt;
[[Category:Security]]&lt;/div&gt;</summary>
		<author><name>Mmhiro</name></author>
	</entry>
</feed>