<?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=TakodaOS</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=TakodaOS"/>
	<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/wiki/Special:Contributions/TakodaOS"/>
	<updated>2026-05-03T01:11:26Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.40.0</generator>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Shell_management&amp;diff=31165</id>
		<title>Shell management</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Shell_management&amp;diff=31165"/>
		<updated>2025-10-05T22:13:47Z</updated>

		<summary type="html">&lt;p&gt;TakodaOS: Add /bin/sh section&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The default shell used by Alpine Linux is the [[BusyBox]] variant of the [[BusyBox#Ash_shell|ash]] shell. This page explains how to use the default shell and various ways to change the default shell in Alpine Linux. &lt;br /&gt;
&lt;br /&gt;
== Ash shell == &lt;br /&gt;
&lt;br /&gt;
Alpine Linux uses [[Busybox]] Ash shell for its default shell. It is a standard POSIX shell derived from Debian Ash variant. &lt;br /&gt;
&lt;br /&gt;
One&#039;s ~/.bashrc file (or, alternatively, a different shell alias file) could be considered as a basis, say, for an {{Path|~/.ashrc}} file, reviewing it carefully for syntax/cli variants against that of Ash shell. For non-login, interactive shells refer to [[#Setting alias|Setting alias]] section.&lt;br /&gt;
&lt;br /&gt;
{{Tip|Use {{pkg|checkbashisms}} script to perform basic checks for the presence of bashisms in scripts and help remove them.}}&lt;br /&gt;
&lt;br /&gt;
=== Setting alias ===&lt;br /&gt;
&lt;br /&gt;
For non-login shells, Busybox Ash and other POSIX shells do NOT automatically read a startup file like {{Path|~/.ashrc}}. To ensure that both login and non-login shells work consistently, use &#039;&#039;&#039;ENV&#039;&#039;&#039; environment variable in {{Path|~/.profile}} to refer {{Path|~/.ashrc}} file. &lt;br /&gt;
&lt;br /&gt;
# Edit the {{Path|~/.profile}} as follows: {{Cat|~/.profile|&amp;lt;nowiki&amp;gt;...&lt;br /&gt;
export ENV=&amp;quot;$HOME/.ashrc&amp;quot; &amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
# Now aliases can be added in the startup file {{Path|~/.ashrc}} as follows: {{Cat|~/.ashrc|&amp;lt;nowiki&amp;gt;# ~/.ashrc: interactive shell configuration for BusyBox Ash&lt;br /&gt;
&lt;br /&gt;
# Custom Aliases&lt;br /&gt;
alias ls=&#039;ls --color=auto&#039;&lt;br /&gt;
alias grep=&#039;grep --color=auto&#039;&lt;br /&gt;
&lt;br /&gt;
# You may want to put all your additions into a separate file like&lt;br /&gt;
# ~/.ash_aliases, instead of adding them here directly.&lt;br /&gt;
&lt;br /&gt;
if [ -f ~/.ash_aliases ]; then&lt;br /&gt;
    . ~/.ash_aliases&lt;br /&gt;
fi&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
== Available shells ==&lt;br /&gt;
&lt;br /&gt;
Most of the popular shells are available in Alpine Linux repositories as can be seen from the below list. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; align=&amp;quot;center&amp;quot; style=&amp;quot;width:100%; border:1px #0771a6 solid; background:#f9f9f9; text-align:left; border-collapse:collapse;&amp;quot;&lt;br /&gt;
|-style=&amp;quot;background:#333333; color:#ffffff; font-size: 1.2em; text-align:center;&amp;quot;&lt;br /&gt;
|width=&amp;quot;10%&amp;quot; | Name &lt;br /&gt;
|width=&amp;quot;36%&amp;quot; | URL &lt;br /&gt;
|Remarks&lt;br /&gt;
|-&lt;br /&gt;
|{{Pkg|bash}}|| https://www.gnu.org/software/bash/bash.html||The GNU Bourne Again shell&lt;br /&gt;
|-&lt;br /&gt;
|{{Pkg|zsh}} || https://www.zsh.org/||Very advanced and programmable command interpreter&lt;br /&gt;
|-&lt;br /&gt;
|{{Pkg|fish}} ||https://fishshell.com/||Modern interactive commandline shell&lt;br /&gt;
|-&lt;br /&gt;
|{{pkg|dash}} ||http://gondor.apana.org.au/~herbert/dash/||Small and fast POSIX-compliant shell&lt;br /&gt;
|-&lt;br /&gt;
|{{pkg|oksh}} ||https://github.com/ibara/oksh||Portable OpenBSD ksh, based on pdksh&lt;br /&gt;
|-&lt;br /&gt;
|{{pkg|loksh}} ||https://github.com/dimkr/loksh||A Linux port of OpenBSD&#039;s ksh&lt;br /&gt;
|-&lt;br /&gt;
|{{pkg|yash}} ||https://magicant.github.io/yash||Yet another shell&lt;br /&gt;
|-&lt;br /&gt;
|{{pkg|tcsh}} ||https://github.com/tcsh-org/tcsh||extended C-shell&lt;br /&gt;
|-&lt;br /&gt;
|{{pkg|nsh}} ||https://github.com/nuta/nsh||A command-line shell like fish, but POSIX compatible&lt;br /&gt;
|-&lt;br /&gt;
|{{pkg|elvish}} ||https://elv.sh||Friendly and expressive Unix shell&lt;br /&gt;
|-&lt;br /&gt;
|{{pkg|nushell}} ||https://www.nushell.sh||A new type of shell&lt;br /&gt;
|-&lt;br /&gt;
|{{pkg|murex}} ||https://murex.rocks/||Intuitive, typed and content aware shell&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
To install any of the above shells, say for eg: {{pkg|bash}} shell: {{Cmd|# apk add {{pkg|bash}} {{pkg|bash-completion}}}}&lt;br /&gt;
&lt;br /&gt;
== Change default shell == &lt;br /&gt;
&lt;br /&gt;
There are various ways to change the default user shell in Alpine Linux. You can revert back to [[#ash|ash]] shell at anytime with the same steps. &lt;br /&gt;
&lt;br /&gt;
{{Note|After performing the below step, you need to log out and login again for these changes to take effect.}}&lt;br /&gt;
&lt;br /&gt;
=== By hand ===&lt;br /&gt;
&lt;br /&gt;
Edit {{Path|/etc/passwd}} manually using an editor of your choice. An example line for a user named &amp;lt;code&amp;gt;user&amp;lt;/code&amp;gt; is: {{Cat|/etc/passwd|...&lt;br /&gt;
user:x:1000:1000:user:/home/user:/bin/ash&lt;br /&gt;
...&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Change {{Path|/bin/ash}} to point to the path of a shell from {{Path|/etc/shells}}. Take care to not delete/mangle the line, as it would make you unable to log in again. The &amp;lt;code&amp;gt;user&amp;lt;/code&amp;gt; should be the user you are changing the default login shell for.&lt;br /&gt;
&lt;br /&gt;
=== Using chsh command ===&lt;br /&gt;
&lt;br /&gt;
To use {{ic|chsh}} command, install the {{pkg|shadow}} package: {{Cmd|# apk add shadow}}&lt;br /&gt;
And use chsh: {{Cmd|# chsh username}}&lt;br /&gt;
Now enter the path for the shell you want to use (e.g {{Path|/bin/zsh}})&lt;br /&gt;
and press {{Key|Enter}} to confirm this change. The shell should exist in {{Path|/etc/shells}}.&lt;br /&gt;
&lt;br /&gt;
== /bin/sh ==&lt;br /&gt;
&lt;br /&gt;
Most applications expect a POSIX-compliant shell to be present in a standard location, {{Path|/bin/sh}}. In Alpine Linux, {{Path|/bin/sh}} is linked to busybox ash by default, however it is possible to change this by installing a different -binsh package (A list of -binsh packages can be found [https://pkgs.alpinelinux.org/packages?name=*-binsh here]). Changing {{Path|/bin/sh}} may lead to a difference in script execution speed.&lt;br /&gt;
&lt;br /&gt;
To use dash as {{Path|/bin/sh}}:&lt;br /&gt;
{{Cmd|# apk add {{pkg|dash-binsh}}}}&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [https://linux.die.net/man/1/dash dash Manual]&lt;br /&gt;
* [https://git.busybox.net/busybox/tree/shell/README Ash README]&lt;br /&gt;
* [https://git.busybox.net/busybox/tree/shell Ash source code]&lt;br /&gt;
* [https://pubs.opengroup.org/onlinepubs/9799919799/ POSIX standard]&lt;br /&gt;
* [https://stackoverflow.com/questions/38024160/how-to-get-etc-profile-to-run-automatically-in-alpine-docker/38025686#38025686 stackoverflow on ash shell]&lt;br /&gt;
&lt;br /&gt;
[[Category:Shell]]&lt;br /&gt;
[[Category:System Administration]]&lt;/div&gt;</summary>
		<author><name>TakodaOS</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Install_Alpine_in_QEMU&amp;diff=30860</id>
		<title>Install Alpine in QEMU</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Install_Alpine_in_QEMU&amp;diff=30860"/>
		<updated>2025-09-04T01:56:15Z</updated>

		<summary type="html">&lt;p&gt;TakodaOS: Adding nowiki tags because the template broke.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!--This is page is transcluded in [[QEMU]] page. So don&#039;t begin with Level2 heading here.. Use Level3 --&amp;gt;&lt;br /&gt;
===Before You Start===&lt;br /&gt;
&lt;br /&gt;
* Download the [https://alpinelinux.org/downloads latest Alpine image].&lt;br /&gt;
* Install QEMU on your system (e.g. &amp;lt;code&amp;gt;sudo apt install qemu&amp;lt;/code&amp;gt; on Ubuntu, &amp;lt;code&amp;gt;yum -y install qemu&amp;lt;/code&amp;gt; on Fedora)&lt;br /&gt;
&lt;br /&gt;
If you are using Alpine Linux, you can install:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|# apk add {{pkg|qemu|arch=}} {{pkg|qemu-img|arch=}} {{pkg|qemu-system-x86_64|arch=}} {{pkg|qemu-ui-gtk|arch=}}}}&lt;br /&gt;
&lt;br /&gt;
===Create the Virtual Machine===&lt;br /&gt;
&lt;br /&gt;
Create a disk image if you want to install Alpine Linux.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|qemu-img create -f qcow2 alpine.qcow2 8G}}&lt;br /&gt;
&lt;br /&gt;
The following command starts QEMU with the Alpine ISO image as CDROM, the default network configuration, 512MB RAM, the disk image that was created in the previous step, and CDROM as the boot device.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|1=qemu-system-x86_64 -m 512 -nic user -boot once=d -cdrom alpine-standard-{{AlpineLatest}}-x86_64.iso -drive file=alpine.qcow2 -display gtk -enable-kvm}}&lt;br /&gt;
&lt;br /&gt;
{{Tip|Remove option &amp;lt;code&amp;gt;-enable-kvm&amp;lt;/code&amp;gt; if your hardware does not support this.}}&lt;br /&gt;
&lt;br /&gt;
Log in as &amp;lt;code&amp;gt;root&amp;lt;/code&amp;gt; (no password) and run: {{Cmd|setup-alpine}}&lt;br /&gt;
Follow the [[Alpine_setup_scripts#setup-alpine|setup-alpine installation steps]].&lt;br /&gt;
&lt;br /&gt;
Run &amp;lt;code&amp;gt;poweroff&amp;lt;/code&amp;gt; to shut down the machine.&lt;br /&gt;
&lt;br /&gt;
=== Booting the Virtual Machine ===&lt;br /&gt;
After the installation, QEMU can be started from disk image (&amp;lt;code&amp;gt;-boot c&amp;lt;/code&amp;gt;) without CDROM.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|&amp;lt;nowiki&amp;gt;qemu-system-x86_64 -m 512 -nic user -drive file=alpine.qcow2&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Virtualization]]&lt;/div&gt;</summary>
		<author><name>TakodaOS</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Install_Alpine_in_QEMU&amp;diff=30859</id>
		<title>Install Alpine in QEMU</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Install_Alpine_in_QEMU&amp;diff=30859"/>
		<updated>2025-09-04T01:53:51Z</updated>

		<summary type="html">&lt;p&gt;TakodaOS: Rewriting the same legacy options with the last command.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!--This is page is transcluded in [[QEMU]] page. So don&#039;t begin with Level2 heading here.. Use Level3 --&amp;gt;&lt;br /&gt;
===Before You Start===&lt;br /&gt;
&lt;br /&gt;
* Download the [https://alpinelinux.org/downloads latest Alpine image].&lt;br /&gt;
* Install QEMU on your system (e.g. &amp;lt;code&amp;gt;sudo apt install qemu&amp;lt;/code&amp;gt; on Ubuntu, &amp;lt;code&amp;gt;yum -y install qemu&amp;lt;/code&amp;gt; on Fedora)&lt;br /&gt;
&lt;br /&gt;
If you are using Alpine Linux, you can install:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|# apk add {{pkg|qemu|arch=}} {{pkg|qemu-img|arch=}} {{pkg|qemu-system-x86_64|arch=}} {{pkg|qemu-ui-gtk|arch=}}}}&lt;br /&gt;
&lt;br /&gt;
===Create the Virtual Machine===&lt;br /&gt;
&lt;br /&gt;
Create a disk image if you want to install Alpine Linux.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|qemu-img create -f qcow2 alpine.qcow2 8G}}&lt;br /&gt;
&lt;br /&gt;
The following command starts QEMU with the Alpine ISO image as CDROM, the default network configuration, 512MB RAM, the disk image that was created in the previous step, and CDROM as the boot device.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|1=qemu-system-x86_64 -m 512 -nic user -boot once=d -cdrom alpine-standard-{{AlpineLatest}}-x86_64.iso -drive file=alpine.qcow2 -display gtk -enable-kvm}}&lt;br /&gt;
&lt;br /&gt;
{{Tip|Remove option &amp;lt;code&amp;gt;-enable-kvm&amp;lt;/code&amp;gt; if your hardware does not support this.}}&lt;br /&gt;
&lt;br /&gt;
Log in as &amp;lt;code&amp;gt;root&amp;lt;/code&amp;gt; (no password) and run: {{Cmd|setup-alpine}}&lt;br /&gt;
Follow the [[Alpine_setup_scripts#setup-alpine|setup-alpine installation steps]].&lt;br /&gt;
&lt;br /&gt;
Run &amp;lt;code&amp;gt;poweroff&amp;lt;/code&amp;gt; to shut down the machine.&lt;br /&gt;
&lt;br /&gt;
=== Booting the Virtual Machine ===&lt;br /&gt;
After the installation, QEMU can be started from disk image (&amp;lt;code&amp;gt;-boot c&amp;lt;/code&amp;gt;) without CDROM.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|qemu-system-x86_64 -m 512 -nic user -drive file=alpine.qcow2}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Virtualization]]&lt;/div&gt;</summary>
		<author><name>TakodaOS</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Install_Alpine_in_QEMU&amp;diff=30858</id>
		<title>Install Alpine in QEMU</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Install_Alpine_in_QEMU&amp;diff=30858"/>
		<updated>2025-09-04T01:50:32Z</updated>

		<summary type="html">&lt;p&gt;TakodaOS: As per the QEMU man pages, -boot drive and -hda are only kept for legacy purposes. I rewrote the command using the recommended options instead.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!--This is page is transcluded in [[QEMU]] page. So don&#039;t begin with Level2 heading here.. Use Level3 --&amp;gt;&lt;br /&gt;
===Before You Start===&lt;br /&gt;
&lt;br /&gt;
* Download the [https://alpinelinux.org/downloads latest Alpine image].&lt;br /&gt;
* Install QEMU on your system (e.g. &amp;lt;code&amp;gt;sudo apt install qemu&amp;lt;/code&amp;gt; on Ubuntu, &amp;lt;code&amp;gt;yum -y install qemu&amp;lt;/code&amp;gt; on Fedora)&lt;br /&gt;
&lt;br /&gt;
If you are using Alpine Linux, you can install:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|# apk add {{pkg|qemu|arch=}} {{pkg|qemu-img|arch=}} {{pkg|qemu-system-x86_64|arch=}} {{pkg|qemu-ui-gtk|arch=}}}}&lt;br /&gt;
&lt;br /&gt;
===Create the Virtual Machine===&lt;br /&gt;
&lt;br /&gt;
Create a disk image if you want to install Alpine Linux.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|qemu-img create -f qcow2 alpine.qcow2 8G}}&lt;br /&gt;
&lt;br /&gt;
The following command starts QEMU with the Alpine ISO image as CDROM, the default network configuration, 512MB RAM, the disk image that was created in the previous step, and CDROM as the boot device.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|1=qemu-system-x86_64 -m 512 -nic user -boot once=d -cdrom alpine-standard-{{AlpineLatest}}-x86_64.iso -drive file=alpine.qcow2 -display gtk -enable-kvm}}&lt;br /&gt;
&lt;br /&gt;
{{Tip|Remove option &amp;lt;code&amp;gt;-enable-kvm&amp;lt;/code&amp;gt; if your hardware does not support this.}}&lt;br /&gt;
&lt;br /&gt;
Log in as &amp;lt;code&amp;gt;root&amp;lt;/code&amp;gt; (no password) and run: {{Cmd|setup-alpine}}&lt;br /&gt;
Follow the [[Alpine_setup_scripts#setup-alpine|setup-alpine installation steps]].&lt;br /&gt;
&lt;br /&gt;
Run &amp;lt;code&amp;gt;poweroff&amp;lt;/code&amp;gt; to shut down the machine.&lt;br /&gt;
&lt;br /&gt;
=== Booting the Virtual Machine ===&lt;br /&gt;
After the installation, QEMU can be started from disk image (&amp;lt;code&amp;gt;-boot c&amp;lt;/code&amp;gt;) without CDROM.&lt;br /&gt;
&lt;br /&gt;
{{Cmd|qemu-system-x86_64 -m 512 -nic user -hda alpine.qcow2}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Virtualization]]&lt;/div&gt;</summary>
		<author><name>TakodaOS</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=LVM_on_LUKS&amp;diff=30795</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=30795"/>
		<updated>2025-08-26T22:04:48Z</updated>

		<summary type="html">&lt;p&gt;TakodaOS: Okay, this should probably use Alpine Linux version numbers instead of alpine-conf&amp;#039;s numbers. I didn&amp;#039;t realize they were different.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page 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 [[Setting up encrypted volumes with LUKS|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 Alpine v3.15, and automatically encrypts swap using LVM in v3.21. For a simplistic setup it is easy 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;
== 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, several manual steps must be carried out in the Alpine Linux Live CD environment.&lt;br /&gt;
&lt;br /&gt;
Follow the [[Installation#General_course_of_action|Installation guide]] to complete the [[Installation#Base_configuration|base configuration]] as a working [[Configure_Networking#Connectivity_testing|Internet access]] is mandatory to complete this installation.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;parted&amp;lt;/code&amp;gt; partition editor from {{pkg|parted}} package is needed for advanced partitioning and GPT disklabels. Install the following packages required to set up LVM and LUKS:{{Cmd|# apk add lvm2 cryptsetup e2fsprogs parted mkinitfs}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&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;
--&amp;gt;&lt;br /&gt;
=== Creating the Partition Layout ===&lt;br /&gt;
&lt;br /&gt;
Depending on your motherboard, bios features and configuration, we can either use partition table in MBR (legacy BIOS) or GUID Partition Table (GPT). We&#039;ll describe both with example layouts.&lt;br /&gt;
&lt;br /&gt;
{{Note|Instructions on this page uses {{path|&#039;&#039;&#039;/dev/sda&#039;&#039;&#039;}}  as storage device name. To find your storage device&#039;s name, you could either use the &amp;lt;code&amp;gt;lsblk&amp;lt;/code&amp;gt; command from the {{pkg|util-linux}} package 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.}}&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 [[Dualbooting|dual boot]], stop here and seek [[Support]].}}&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 [[Dualbooting|dual boot]], stop here and seek [[Support]].}}&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;
=== 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;
{{Tip|If your hard drive wasn&#039;t encrypted previously, overwrite LUKS Partition with Random Data . 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.{{ic|&amp;lt;nowiki&amp;gt;# dd if=/dev/urandom of=/dev/sda2 bs=1M&amp;lt;/nowiki&amp;gt;}}}}&lt;br /&gt;
&lt;br /&gt;
For Default settings:{{Cmd|# cryptsetup luksFormat /dev/sda2}}&lt;br /&gt;
&lt;br /&gt;
Luks1 Optimized for security: {{Cmd|# cryptsetup -v -c serpent-xts-plain64 -s 512 --hash sha512 --iter-time 5000 --use-random luksFormat --type luks1 /dev/sda2}}&lt;br /&gt;
&lt;br /&gt;
Luks2 Optimized for security:{{Cmd|# cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 5000 --use-random luksFormat /dev/sda2}}&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: {{Cmd|# cryptsetup luksHeaderBackup /dev/sda2 --header-backup-file sda2-luks-header-backup}}&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:{{Cmd|# cryptsetup luksAddKey --pbkdf pbkdf2 /dev/sda2}}&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 {{Cmd|# cryptsetup luksRemoveKey /dev/sda2}}. &lt;br /&gt;
You can check the key information using the command: {{Cmd|# cryptsetup luksDump /dev/sda2}}&lt;br /&gt;
&lt;br /&gt;
Now you can try the conversion, although it may not work. {{Cmd|# cryptsetup convert /dev/sda2 --type luks1}}&lt;br /&gt;
&lt;br /&gt;
=== Creating the Logical Volumes and File Systems ===&lt;br /&gt;
&lt;br /&gt;
Open the LUKS partition:{{Cmd|# cryptsetup luksOpen /dev/sda2 lvmcrypt}}&lt;br /&gt;
&lt;br /&gt;
Create the PV on &amp;lt;code&amp;gt;lvmcrypt&amp;lt;/code&amp;gt;: {{Cmd|# pvcreate /dev/mapper/lvmcrypt}}&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:{{Cmd|# vgcreate vg0 /dev/mapper/lvmcrypt}}&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;). {{Cmd|&amp;lt;nowiki&amp;gt;# lvcreate -L 2G vg0 -n swap&lt;br /&gt;
# lvcreate -l 100%FREE vg0 -n root&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
The LVs created in the previous steps are automatically marked active. To verify, enter:{{Cmd|# lvscan}}&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;).{{Cmd|&amp;lt;nowiki&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;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
The LVs created in the previous steps are automatically marked active. To verify, enter:{{Cmd|# lvscan}}&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: {{Cmd|# mkfs.ext4 /dev/vg0/root}}&lt;br /&gt;
&lt;br /&gt;
Format the swap LV: {{Cmd|# mkswap /dev/vg0/swap}}&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:{{Cmd|# mount -t ext4 /dev/vg0/root /mnt/}}&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: {{Cmd|&amp;lt;nowiki&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;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
* If you&#039;re using UEFI and GPT:{{Cmd|&amp;lt;nowiki&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;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Lastly, activate your swap partition:{{Cmd|# swapon /dev/vg0/swap}}&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: {{Cmd|# 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 {{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 as follows: {{Cat|/mnt/etc/fstab|/dev/vg0/swap    swap    swap    defaults    0 0}} &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:{{Path|/mnt/etc/mkinitfs/mkinitfs.conf|features=&amp;quot;... cryptsetup&amp;quot;}}&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:{{Cmd|# 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;
=== 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:{{Cmd|# blkid -s UUID -o value /dev/sda2 &amp;gt; ~/uuid}}&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: {{Cmd|# apk add syslinux}}&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; as follows:{{Cat|/mnt/etc/update-extlinux.conf|&amp;lt;nowiki&amp;gt;default_kernel_opts=&amp;quot;... cryptroot=UUID=&amp;lt;UUID of sda2&amp;gt; cryptdm=lvmcrypt&amp;quot;&amp;lt;/nowiki&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:{{Cmd|&amp;lt;nowiki&amp;gt;# chroot /mnt/&lt;br /&gt;
# update-extlinux&lt;br /&gt;
# exit&amp;lt;/nowiki&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:{{Cmd|&amp;lt;nowiki&amp;gt;# dd bs=440 count=1 conv=notrunc if=/mnt/usr/share/syslinux/mbr.bin of=/dev/sda&amp;lt;/nowiki&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.{{Cmd|&amp;lt;nowiki&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&amp;lt;/nowiki&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:{{Cmd|&amp;lt;nowiki&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;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Then run chroot:{{Cmd|&amp;lt;nowiki&amp;gt;# chroot /mnt&lt;br /&gt;
# source /etc/profile&lt;br /&gt;
# export PS1=&amp;quot;(chroot) $PS1&amp;quot;&amp;lt;/nowiki&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:{{Cmd|&amp;lt;nowiki&amp;gt;# apk add grub grub-efi efibootmgr&lt;br /&gt;
# apk del syslinux&amp;lt;/nowiki&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;
&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;
== 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;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
In case your system fails to boot, you can verify the settings and fix incorrect configurations. Reboot and follow the [[Installation#General_course_of_action|Installation guide]] to complete the [[Installation#Base_configuration|base configuration]] again.&lt;br /&gt;
&lt;br /&gt;
Setup the LUKS partition and activate the LVs: {{Cmd|&amp;lt;nowiki&amp;gt;# cryptsetup luksOpen /dev/sda2 lvmcrypt&lt;br /&gt;
# vgchange -ay&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Follow the steps in [[#Creating_and_Mounting_the_File Systems| Creating and Mounting 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 follow [[UEFI Secure Boot]] 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;
== See also ==&lt;br /&gt;
&lt;br /&gt;
*[[Setting up encrypted volumes with LUKS]]&lt;br /&gt;
*[[Bootloaders]]&lt;br /&gt;
*[[UEFI Secure Boot]]&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://rifux.dev/docs/alpine-linux/install-luks2/ Guide to Install Alpine Linux with LUKS2, BTRFS and GRUB]&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>TakodaOS</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=LVM_on_LUKS&amp;diff=30794</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=30794"/>
		<updated>2025-08-26T21:54:49Z</updated>

		<summary type="html">&lt;p&gt;TakodaOS: Changing v3.18 to v3.19; the feature was intended for v3.18 but a bug relating to the functionality wasn&amp;#039;t fixed until v3.19&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page 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 [[Setting up encrypted volumes with LUKS|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, and automatically encrypts swap using LVM in v3.19. For a simplistic setup it is easy 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;
== 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, several manual steps must be carried out in the Alpine Linux Live CD environment.&lt;br /&gt;
&lt;br /&gt;
Follow the [[Installation#General_course_of_action|Installation guide]] to complete the [[Installation#Base_configuration|base configuration]] as a working [[Configure_Networking#Connectivity_testing|Internet access]] is mandatory to complete this installation.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;parted&amp;lt;/code&amp;gt; partition editor from {{pkg|parted}} package is needed for advanced partitioning and GPT disklabels. Install the following packages required to set up LVM and LUKS:{{Cmd|# apk add lvm2 cryptsetup e2fsprogs parted mkinitfs}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&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;
--&amp;gt;&lt;br /&gt;
=== Creating the Partition Layout ===&lt;br /&gt;
&lt;br /&gt;
Depending on your motherboard, bios features and configuration, we can either use partition table in MBR (legacy BIOS) or GUID Partition Table (GPT). We&#039;ll describe both with example layouts.&lt;br /&gt;
&lt;br /&gt;
{{Note|Instructions on this page uses {{path|&#039;&#039;&#039;/dev/sda&#039;&#039;&#039;}}  as storage device name. To find your storage device&#039;s name, you could either use the &amp;lt;code&amp;gt;lsblk&amp;lt;/code&amp;gt; command from the {{pkg|util-linux}} package 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.}}&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 [[Dualbooting|dual boot]], stop here and seek [[Support]].}}&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 [[Dualbooting|dual boot]], stop here and seek [[Support]].}}&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;
=== 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;
{{Tip|If your hard drive wasn&#039;t encrypted previously, overwrite LUKS Partition with Random Data . 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.{{ic|&amp;lt;nowiki&amp;gt;# dd if=/dev/urandom of=/dev/sda2 bs=1M&amp;lt;/nowiki&amp;gt;}}}}&lt;br /&gt;
&lt;br /&gt;
For Default settings:{{Cmd|# cryptsetup luksFormat /dev/sda2}}&lt;br /&gt;
&lt;br /&gt;
Luks1 Optimized for security: {{Cmd|# cryptsetup -v -c serpent-xts-plain64 -s 512 --hash sha512 --iter-time 5000 --use-random luksFormat --type luks1 /dev/sda2}}&lt;br /&gt;
&lt;br /&gt;
Luks2 Optimized for security:{{Cmd|# cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 5000 --use-random luksFormat /dev/sda2}}&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: {{Cmd|# cryptsetup luksHeaderBackup /dev/sda2 --header-backup-file sda2-luks-header-backup}}&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:{{Cmd|# cryptsetup luksAddKey --pbkdf pbkdf2 /dev/sda2}}&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 {{Cmd|# cryptsetup luksRemoveKey /dev/sda2}}. &lt;br /&gt;
You can check the key information using the command: {{Cmd|# cryptsetup luksDump /dev/sda2}}&lt;br /&gt;
&lt;br /&gt;
Now you can try the conversion, although it may not work. {{Cmd|# cryptsetup convert /dev/sda2 --type luks1}}&lt;br /&gt;
&lt;br /&gt;
=== Creating the Logical Volumes and File Systems ===&lt;br /&gt;
&lt;br /&gt;
Open the LUKS partition:{{Cmd|# cryptsetup luksOpen /dev/sda2 lvmcrypt}}&lt;br /&gt;
&lt;br /&gt;
Create the PV on &amp;lt;code&amp;gt;lvmcrypt&amp;lt;/code&amp;gt;: {{Cmd|# pvcreate /dev/mapper/lvmcrypt}}&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:{{Cmd|# vgcreate vg0 /dev/mapper/lvmcrypt}}&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;). {{Cmd|&amp;lt;nowiki&amp;gt;# lvcreate -L 2G vg0 -n swap&lt;br /&gt;
# lvcreate -l 100%FREE vg0 -n root&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
The LVs created in the previous steps are automatically marked active. To verify, enter:{{Cmd|# lvscan}}&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;).{{Cmd|&amp;lt;nowiki&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;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
The LVs created in the previous steps are automatically marked active. To verify, enter:{{Cmd|# lvscan}}&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: {{Cmd|# mkfs.ext4 /dev/vg0/root}}&lt;br /&gt;
&lt;br /&gt;
Format the swap LV: {{Cmd|# mkswap /dev/vg0/swap}}&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:{{Cmd|# mount -t ext4 /dev/vg0/root /mnt/}}&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: {{Cmd|&amp;lt;nowiki&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;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
* If you&#039;re using UEFI and GPT:{{Cmd|&amp;lt;nowiki&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;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Lastly, activate your swap partition:{{Cmd|# swapon /dev/vg0/swap}}&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: {{Cmd|# 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 {{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 as follows: {{Cat|/mnt/etc/fstab|/dev/vg0/swap    swap    swap    defaults    0 0}} &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:{{Path|/mnt/etc/mkinitfs/mkinitfs.conf|features=&amp;quot;... cryptsetup&amp;quot;}}&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:{{Cmd|# 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;
=== 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:{{Cmd|# blkid -s UUID -o value /dev/sda2 &amp;gt; ~/uuid}}&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: {{Cmd|# apk add syslinux}}&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; as follows:{{Cat|/mnt/etc/update-extlinux.conf|&amp;lt;nowiki&amp;gt;default_kernel_opts=&amp;quot;... cryptroot=UUID=&amp;lt;UUID of sda2&amp;gt; cryptdm=lvmcrypt&amp;quot;&amp;lt;/nowiki&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:{{Cmd|&amp;lt;nowiki&amp;gt;# chroot /mnt/&lt;br /&gt;
# update-extlinux&lt;br /&gt;
# exit&amp;lt;/nowiki&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:{{Cmd|&amp;lt;nowiki&amp;gt;# dd bs=440 count=1 conv=notrunc if=/mnt/usr/share/syslinux/mbr.bin of=/dev/sda&amp;lt;/nowiki&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.{{Cmd|&amp;lt;nowiki&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&amp;lt;/nowiki&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:{{Cmd|&amp;lt;nowiki&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;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Then run chroot:{{Cmd|&amp;lt;nowiki&amp;gt;# chroot /mnt&lt;br /&gt;
# source /etc/profile&lt;br /&gt;
# export PS1=&amp;quot;(chroot) $PS1&amp;quot;&amp;lt;/nowiki&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:{{Cmd|&amp;lt;nowiki&amp;gt;# apk add grub grub-efi efibootmgr&lt;br /&gt;
# apk del syslinux&amp;lt;/nowiki&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;
&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;
== 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;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
In case your system fails to boot, you can verify the settings and fix incorrect configurations. Reboot and follow the [[Installation#General_course_of_action|Installation guide]] to complete the [[Installation#Base_configuration|base configuration]] again.&lt;br /&gt;
&lt;br /&gt;
Setup the LUKS partition and activate the LVs: {{Cmd|&amp;lt;nowiki&amp;gt;# cryptsetup luksOpen /dev/sda2 lvmcrypt&lt;br /&gt;
# vgchange -ay&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Follow the steps in [[#Creating_and_Mounting_the_File Systems| Creating and Mounting 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 follow [[UEFI Secure Boot]] 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;
== See also ==&lt;br /&gt;
&lt;br /&gt;
*[[Setting up encrypted volumes with LUKS]]&lt;br /&gt;
*[[Bootloaders]]&lt;br /&gt;
*[[UEFI Secure Boot]]&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://rifux.dev/docs/alpine-linux/install-luks2/ Guide to Install Alpine Linux with LUKS2, BTRFS and GRUB]&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>TakodaOS</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=LVM_on_LUKS&amp;diff=30793</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=30793"/>
		<updated>2025-08-26T21:48:46Z</updated>

		<summary type="html">&lt;p&gt;TakodaOS: Correction: Setup-disk automatically encrypts swap partitions since release 3.18 of alpine-conf&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page 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 [[Setting up encrypted volumes with LUKS|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, and automatically encrypts swap using LVM in v3.18. For a simplistic setup it is easy 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;
== 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, several manual steps must be carried out in the Alpine Linux Live CD environment.&lt;br /&gt;
&lt;br /&gt;
Follow the [[Installation#General_course_of_action|Installation guide]] to complete the [[Installation#Base_configuration|base configuration]] as a working [[Configure_Networking#Connectivity_testing|Internet access]] is mandatory to complete this installation.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;parted&amp;lt;/code&amp;gt; partition editor from {{pkg|parted}} package is needed for advanced partitioning and GPT disklabels. Install the following packages required to set up LVM and LUKS:{{Cmd|# apk add lvm2 cryptsetup e2fsprogs parted mkinitfs}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&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;
--&amp;gt;&lt;br /&gt;
=== Creating the Partition Layout ===&lt;br /&gt;
&lt;br /&gt;
Depending on your motherboard, bios features and configuration, we can either use partition table in MBR (legacy BIOS) or GUID Partition Table (GPT). We&#039;ll describe both with example layouts.&lt;br /&gt;
&lt;br /&gt;
{{Note|Instructions on this page uses {{path|&#039;&#039;&#039;/dev/sda&#039;&#039;&#039;}}  as storage device name. To find your storage device&#039;s name, you could either use the &amp;lt;code&amp;gt;lsblk&amp;lt;/code&amp;gt; command from the {{pkg|util-linux}} package 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.}}&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 [[Dualbooting|dual boot]], stop here and seek [[Support]].}}&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 [[Dualbooting|dual boot]], stop here and seek [[Support]].}}&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;
=== 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;
{{Tip|If your hard drive wasn&#039;t encrypted previously, overwrite LUKS Partition with Random Data . 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.{{ic|&amp;lt;nowiki&amp;gt;# dd if=/dev/urandom of=/dev/sda2 bs=1M&amp;lt;/nowiki&amp;gt;}}}}&lt;br /&gt;
&lt;br /&gt;
For Default settings:{{Cmd|# cryptsetup luksFormat /dev/sda2}}&lt;br /&gt;
&lt;br /&gt;
Luks1 Optimized for security: {{Cmd|# cryptsetup -v -c serpent-xts-plain64 -s 512 --hash sha512 --iter-time 5000 --use-random luksFormat --type luks1 /dev/sda2}}&lt;br /&gt;
&lt;br /&gt;
Luks2 Optimized for security:{{Cmd|# cryptsetup -v -c aes-xts-plain64 -s 512 --hash sha512 --pbkdf pbkdf2 --iter-time 5000 --use-random luksFormat /dev/sda2}}&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: {{Cmd|# cryptsetup luksHeaderBackup /dev/sda2 --header-backup-file sda2-luks-header-backup}}&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:{{Cmd|# cryptsetup luksAddKey --pbkdf pbkdf2 /dev/sda2}}&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 {{Cmd|# cryptsetup luksRemoveKey /dev/sda2}}. &lt;br /&gt;
You can check the key information using the command: {{Cmd|# cryptsetup luksDump /dev/sda2}}&lt;br /&gt;
&lt;br /&gt;
Now you can try the conversion, although it may not work. {{Cmd|# cryptsetup convert /dev/sda2 --type luks1}}&lt;br /&gt;
&lt;br /&gt;
=== Creating the Logical Volumes and File Systems ===&lt;br /&gt;
&lt;br /&gt;
Open the LUKS partition:{{Cmd|# cryptsetup luksOpen /dev/sda2 lvmcrypt}}&lt;br /&gt;
&lt;br /&gt;
Create the PV on &amp;lt;code&amp;gt;lvmcrypt&amp;lt;/code&amp;gt;: {{Cmd|# pvcreate /dev/mapper/lvmcrypt}}&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:{{Cmd|# vgcreate vg0 /dev/mapper/lvmcrypt}}&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;). {{Cmd|&amp;lt;nowiki&amp;gt;# lvcreate -L 2G vg0 -n swap&lt;br /&gt;
# lvcreate -l 100%FREE vg0 -n root&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
The LVs created in the previous steps are automatically marked active. To verify, enter:{{Cmd|# lvscan}}&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;).{{Cmd|&amp;lt;nowiki&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;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
The LVs created in the previous steps are automatically marked active. To verify, enter:{{Cmd|# lvscan}}&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: {{Cmd|# mkfs.ext4 /dev/vg0/root}}&lt;br /&gt;
&lt;br /&gt;
Format the swap LV: {{Cmd|# mkswap /dev/vg0/swap}}&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:{{Cmd|# mount -t ext4 /dev/vg0/root /mnt/}}&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: {{Cmd|&amp;lt;nowiki&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;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
* If you&#039;re using UEFI and GPT:{{Cmd|&amp;lt;nowiki&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;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Lastly, activate your swap partition:{{Cmd|# swapon /dev/vg0/swap}}&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: {{Cmd|# 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 {{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 as follows: {{Cat|/mnt/etc/fstab|/dev/vg0/swap    swap    swap    defaults    0 0}} &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:{{Path|/mnt/etc/mkinitfs/mkinitfs.conf|features=&amp;quot;... cryptsetup&amp;quot;}}&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:{{Cmd|# 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;
=== 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:{{Cmd|# blkid -s UUID -o value /dev/sda2 &amp;gt; ~/uuid}}&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: {{Cmd|# apk add syslinux}}&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; as follows:{{Cat|/mnt/etc/update-extlinux.conf|&amp;lt;nowiki&amp;gt;default_kernel_opts=&amp;quot;... cryptroot=UUID=&amp;lt;UUID of sda2&amp;gt; cryptdm=lvmcrypt&amp;quot;&amp;lt;/nowiki&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:{{Cmd|&amp;lt;nowiki&amp;gt;# chroot /mnt/&lt;br /&gt;
# update-extlinux&lt;br /&gt;
# exit&amp;lt;/nowiki&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:{{Cmd|&amp;lt;nowiki&amp;gt;# dd bs=440 count=1 conv=notrunc if=/mnt/usr/share/syslinux/mbr.bin of=/dev/sda&amp;lt;/nowiki&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.{{Cmd|&amp;lt;nowiki&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&amp;lt;/nowiki&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:{{Cmd|&amp;lt;nowiki&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;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Then run chroot:{{Cmd|&amp;lt;nowiki&amp;gt;# chroot /mnt&lt;br /&gt;
# source /etc/profile&lt;br /&gt;
# export PS1=&amp;quot;(chroot) $PS1&amp;quot;&amp;lt;/nowiki&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:{{Cmd|&amp;lt;nowiki&amp;gt;# apk add grub grub-efi efibootmgr&lt;br /&gt;
# apk del syslinux&amp;lt;/nowiki&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;
&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;
== 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;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
In case your system fails to boot, you can verify the settings and fix incorrect configurations. Reboot and follow the [[Installation#General_course_of_action|Installation guide]] to complete the [[Installation#Base_configuration|base configuration]] again.&lt;br /&gt;
&lt;br /&gt;
Setup the LUKS partition and activate the LVs: {{Cmd|&amp;lt;nowiki&amp;gt;# cryptsetup luksOpen /dev/sda2 lvmcrypt&lt;br /&gt;
# vgchange -ay&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Follow the steps in [[#Creating_and_Mounting_the_File Systems| Creating and Mounting 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 follow [[UEFI Secure Boot]] 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;
== See also ==&lt;br /&gt;
&lt;br /&gt;
*[[Setting up encrypted volumes with LUKS]]&lt;br /&gt;
*[[Bootloaders]]&lt;br /&gt;
*[[UEFI Secure Boot]]&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://rifux.dev/docs/alpine-linux/install-luks2/ Guide to Install Alpine Linux with LUKS2, BTRFS and GRUB]&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>TakodaOS</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Setting_up_encrypted_volumes_with_LUKS&amp;diff=30792</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=30792"/>
		<updated>2025-08-26T21:44:23Z</updated>

		<summary type="html">&lt;p&gt;TakodaOS: Correction: Setup-disk automatically encrypts swap partitions since release 3.18 of alpine-conf&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 following approaches are known to work:&lt;br /&gt;
&lt;br /&gt;
* Plain LUKS&lt;br /&gt;
* [[LVM on LUKS]]&lt;br /&gt;
&lt;br /&gt;
The installer has built-in support for encryption, and will automatically enable LVM to encrypt swap partitions, but it will not encrypt the boot partition. The [[Bootloaders#GRUB|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 and 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 {{path|/etc/mkinitfs/mkinitfs.conf}}. 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;cryptdm&amp;lt;/code&amp;gt;: the name that will be given to the device.&lt;br /&gt;
* &amp;lt;code&amp;gt;root&amp;lt;/code&amp;gt; kernel parameter should point to the mapped block device: &amp;lt;code&amp;gt;/dev/mapper/&amp;lt;name used in cryptdm&amp;gt;&amp;lt;/code&amp;gt;.&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;
For example, if you use grub with GPT partition table using ext4 without LVM the {{path|/etc/default/grub}} file will be as follows:{{Cat|/etc/default/grub|&amp;lt;nowiki&amp;gt;GRUB_TIMEOUT=2&lt;br /&gt;
GRUB_DISABLE_SUBMENU=y&lt;br /&gt;
GRUB_DISABLE_RECOVERY=true&lt;br /&gt;
GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;modules=sd-mod,usb-storage,ext4 quiet rootfstype=ext4 cryptroot=UUID=a7dc90c4-6746-417e-b25b-cb8769ee6334 cryptdm=alpine-rootfs  root=/dev/mapper/alpine-rootfs&amp;quot;&lt;br /&gt;
GRUB_PRELOAD_MODULES=&amp;quot;luks cryptodisk part_gpt&amp;quot;&lt;br /&gt;
GRUB_ENABLE_CRYPTODISK=y&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
== Decrypting non-root volumes during boot ==&lt;br /&gt;
{{Main|LVM on LUKS#Mounting additional encrypted filesystems at boot}}&lt;br /&gt;
To have an encrypted non-root volume be decrypted prior to automatically mounting it somewhere via &amp;lt;code&amp;gt;/etc/fstab&amp;lt;/code&amp;gt;,  configure &amp;lt;code&amp;gt;dmcrypt&amp;lt;/code&amp;gt; in the {{path|/etc/conf.d/dmcrypt}} file. The comments inside that file should guide you, but as a simple example, here&#039;s what you should include in that file to decrypt and map a partition to some volume named, say, “&amp;lt;code&amp;gt;myvolume&amp;lt;/code&amp;gt;”, given its UUID (here represented using a series of &amp;lt;code&amp;gt;X&amp;lt;/code&amp;gt;s), using a passphrase {{Cat|/etc/conf.d/dmcrypt|&amp;lt;nowiki&amp;gt;...&lt;br /&gt;
target=myvolume&lt;br /&gt;
source=UUID=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX&lt;br /&gt;
key=/etc/keys/myvolume.key  #not needed as passphrase is used in this example&lt;br /&gt;
...&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
In {{path|/etc/fstab}} file, then, you would include the following line as follows:{{Cat|/etc/fstab|&amp;lt;nowiki&amp;gt;...&lt;br /&gt;
/dev/mapper/myvolume	&amp;lt;path&amp;gt;	&amp;lt;fstype&amp;gt;	&amp;lt;options&amp;gt;&lt;br /&gt;
...&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
substituting in the proper parameters.&lt;br /&gt;
&lt;br /&gt;
Do not forget to enable the &amp;lt;code&amp;gt;localmount&amp;lt;/code&amp;gt; service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;rc-update add localmount&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Otherwise they will not be mounted automatically.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[LVM on LUKS]]&lt;br /&gt;
* [[mkinitfs|Initramfs init]]&lt;br /&gt;
* [[Full disk encryption secure boot]]&lt;br /&gt;
* [[Setting up a laptop|Setting up a secured laptop]]&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>TakodaOS</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Btrfs&amp;diff=30773</id>
		<title>Btrfs</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Btrfs&amp;diff=30773"/>
		<updated>2025-08-23T15:34:20Z</updated>

		<summary type="html">&lt;p&gt;TakodaOS: Adding a better introduction to Btrfs and easier instructions. Moving a link and adding another resource.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[https://wikipedia.org/wiki/Btrfs Btrfs] is a CoW (copy on write) filesystem with checksums, snapshots, compression and more.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&amp;lt;code&amp;gt;setup-disk&amp;lt;/code&amp;gt; can automatically set up a root filesystem with Btrfs using environment variables. Export &amp;lt;code&amp;gt;ROOTFS&amp;lt;/code&amp;gt; before running &amp;lt;code&amp;gt;setup-disk&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;setup-alpine&amp;lt;/code&amp;gt; like so:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|&amp;lt;nowiki&amp;gt;# export ROOTFS=btrfs&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
The filesystem utilities and modules will automatically be set up.&lt;br /&gt;
&lt;br /&gt;
=== Manual Installation ===&lt;br /&gt;
&lt;br /&gt;
Installing Btrfs is relatively straight forward. Install the package and tell Alpine to load the module on startup:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|# apk add {{pkg|btrfs-progs}}&lt;br /&gt;
&amp;lt;nowiki&amp;gt;# echo btrfs &amp;gt;&amp;gt; /etc/modules&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
To load the module immediately, you can use the following command:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|# modprobe btrfs}}&lt;br /&gt;
&lt;br /&gt;
If btrfs is used for root filesystem, ensure that the initramfs is generated with the btrfs module, otherwise the system may fail to boot. &lt;br /&gt;
&lt;br /&gt;
To do so edit the {{path|/etc/mkinitfs/mkinitfs.conf}} and ensure that &amp;quot;btrfs&amp;quot; is in the list of features as follows:{{Cat|/etc/mkinitfs/mkinitfs.conf|features{{=}}&amp;quot;ata base cdrom ext4 keymap kms mmc nvme raid scsi usb virtio btrfs&amp;quot;}}&lt;br /&gt;
&lt;br /&gt;
After making the above change, issue the command to regenerate the initramfs:{{Cmd|# mkinitfs}} &lt;br /&gt;
&lt;br /&gt;
== Configuration ==&lt;br /&gt;
&lt;br /&gt;
=== Mounting a subvolume ===&lt;br /&gt;
&lt;br /&gt;
To mount a subvolume {{ic|@alpine}} located in the btrfs partition {{Path|/dev/nvme0n1p3}}, the command is: {{Cmd|&amp;lt;nowiki&amp;gt;# mount -o subvol=@alpine /dev/nvme0n1p3 /mnt&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
=== Mounting a subvolume on boot ===&lt;br /&gt;
&lt;br /&gt;
To mount a volume on boot, add a new entry to your {{path|/etc/fstab}} file as follows: {{cat|/etc/fstab|&amp;lt;nowiki&amp;gt;...&lt;br /&gt;
UUID=abcdef-0055-4958-990f-1413ed1186ec  /var/data  btrfs   defaults,nofail,subvol=@  0  0&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
If you use more specific mounting options like for example:{{cat|/etc/fstab|&amp;lt;nowiki&amp;gt;...&lt;br /&gt;
UUID=005f5994-f51c-4360-8c9b-589fa59ea6fc  /mnt/hddext  btrfs  nofail,rw,noatime,commit=64,nossd,autodefrag,compress=zstd:10  0 2&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Do not forget to install additional dependencies. If you enabled on the fly compression you need to install zstd: {{cmd|# apk add {{pkg|zstd}}}}&lt;br /&gt;
&lt;br /&gt;
More information about mounting can be found in the official [https://btrfs.readthedocs.io Btrfs wiki]&lt;br /&gt;
&lt;br /&gt;
=== Enable btrfs-scan service ===&lt;br /&gt;
&lt;br /&gt;
To ensure that that btrfs partitions are cleanly mounted, enable the {{ic|btrfs-scan}} service from the {{pkg|btrfs-progs}}package: {{Cmd|# rc-update add btrfs-scan boot}}&lt;br /&gt;
&lt;br /&gt;
=== apk-snap  ===&lt;br /&gt;
&lt;br /&gt;
The {{ic|apk-snap}} script from {{pkg|apk-snap}} package triggers filesystem snapshots before and after every apk commit. &lt;br /&gt;
The {{pkg|apk-snap}} package is currently available in [[Repositories#Testing|testing]] repository. It can be safely installed by following the [[Repositories#Using_testing_repository|guidelines]]. &lt;br /&gt;
&lt;br /&gt;
This package autointalls {{pkg|snapper}} package and provides necessary apk hooks and script that causes {{ic|snapper}} to automatically take a pre and post snapshot before and after apk transactions, similar to how YaST does with OpenSuse. This provides a simple way to undo changes to a system after an apk transaction. &lt;br /&gt;
&lt;br /&gt;
By default the &#039;&#039;&#039;/&#039;&#039;&#039; (root) snapshots taken by snapper are saved in the &#039;&#039;&#039;/.snapshot&#039;&#039;&#039; folder. To make it easier to manage the snapshots created by snapper, it is better to mainain it outside of &#039;&#039;&#039;/(root)&#039;&#039;&#039; folder. To achieve this, create a subvolume {{ic|@snaps_root}} in the btrfs partition and mount the above subvolume on &#039;&#039;&#039;/.snapshot&#039;&#039;&#039; folder by having an entry in {{Path|etc/fstab}} file as follows: {{Cat|/etc/fstab|&amp;lt;nowiki&amp;gt;...&lt;br /&gt;
UUID=823a3283-30a7-4fef-b50b-8a2230c71b5b /.snapshots  btrfs compress=zlib:3,subvol=@snaps_root 0 0&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
=== Bootloader ===&lt;br /&gt;
&lt;br /&gt;
If the initrd and kernel are installed inside the btrfs root subvolume instead of EFI partition, configuring the bootloader properly is important. For sample configuration, refer to the following pages for [[Bootloaders#Manual_configuration|rEFInd]] and [[Immutable root with atomic upgrades#GRUB|GRUB]] bootloaders.&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
=== Mount failed ===&lt;br /&gt;
&lt;br /&gt;
If you try mounting a Btrfs volume via your {{path|/etc/fstab}} and if it doesn&#039;t show up, this is related to {{Issue|9539|Can&#039;t mount BTRFS volume using fstab}}. This could be because Btrfs does not know about the drives during boot. To avoid this issue [[#Enable btrfs-scan service|enable the btrfs-scan service]]. The volume should mount correctly after a reboot.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [https://btrfs.readthedocs.io Btrfs documentation]&lt;br /&gt;
* [https://garrit.xyz/posts/2021-12-31-btrfs-on-alpine BTRFS on Alpine Linux]&lt;br /&gt;
* [https://web.archive.org/web/20221127043947/https://nparsons.uk/blog/using-btrfs-on-alpine-linux Using BTRFS on Alpine Linux]&lt;br /&gt;
* [https://wiki.archlinux.org/title/Btrfs ArchWiki]&lt;br /&gt;
* [https://wiki.gentoo.org/wiki/Btrfs Gentoo Wiki]&lt;br /&gt;
* [[Install Alpine on a btrfs filesystem with refind as boot manager]]&lt;br /&gt;
* [[Immutable root with atomic upgrades|Immutable root with atomic upgrades using btrfs snapshots]]&lt;br /&gt;
[[Category:Filesystems]]&lt;/div&gt;</summary>
		<author><name>TakodaOS</name></author>
	</entry>
</feed>