<?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=Llnu</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=Llnu"/>
	<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/wiki/Special:Contributions/Llnu"/>
	<updated>2026-04-27T14:28:41Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.40.0</generator>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=LXC&amp;diff=16957</id>
		<title>LXC</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=LXC&amp;diff=16957"/>
		<updated>2020-03-01T13:58:18Z</updated>

		<summary type="html">&lt;p&gt;Llnu: /* Installation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[https://linuxcontainers.org/ Linux Containers (LXC)] provides containers similar BSD Jails, Linux VServer and Solaris Zones. It gives the impression of virtualization, but shares the kernel and resources with the &amp;quot;host&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
Install the required packages:&lt;br /&gt;
{{Cmd|apk add lxc bridge lxcfs}}&lt;br /&gt;
&lt;br /&gt;
If you want to create containers other than alpine you will need lxc-templates:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk add lxc-templates}}&lt;br /&gt;
&lt;br /&gt;
== Upgrading from 2.x ==&lt;br /&gt;
&lt;br /&gt;
Since Alpine 3.9 we ship LXC version 3.1.&lt;br /&gt;
LXC 3.x has major changes which will/can break your current setup.&lt;br /&gt;
LXC 3.x will NOT ship with legacy container templates. Check your current container configs to see if you have any includes pointing to files that don&#039;t exist (shipped by legacy templates).&lt;br /&gt;
For example if you use Alpine containers created with the alpine template you will need to install:&lt;br /&gt;
&lt;br /&gt;
 apk add lxc-templates-legacy-alpine&lt;br /&gt;
&lt;br /&gt;
Also make sure you convert your LXC config files to the new 2.x format (this is now required).&lt;br /&gt;
&lt;br /&gt;
 lxc-update-config -c /var/lib/lxc/container-name/config&lt;br /&gt;
&lt;br /&gt;
Make sure you have removed &#039;&#039;&#039;cgroup_enable&#039;&#039;&#039; from your cmdline as this will fail to mount cgroups and fail LXC service.&lt;br /&gt;
&lt;br /&gt;
== Prepare network on host ==&lt;br /&gt;
Set up a [[bridge]] on the host. Example &#039;&#039;/etc/network/interfaces&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
auto br0&lt;br /&gt;
iface br0 inet dhcp&lt;br /&gt;
    bridge-ports eth0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a network configuration template for the guests, &#039;&#039;/etc/lxc/default.conf&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
lxc.net.0.type = veth&lt;br /&gt;
lxc.net.0.link = br0&lt;br /&gt;
lxc.net.0.flags = up&lt;br /&gt;
lxc.net.0.hwaddr = fe:xx:xx:xx:xx:xx&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Grsecurity restrictions ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE&#039;&#039;&#039;: since alpine 3.8 we no longer ship grsecurity and it should not be used in lxc setup.&lt;br /&gt;
&lt;br /&gt;
Some restrictions will be applied when using a grsecurity kernel (Alpine Linux default kernel).&lt;br /&gt;
The most notable is the use of lxc-attach which will not be allowed because of GRKERNSEC_CHROOT_CAPS.&lt;br /&gt;
To solve this we will have to disable this grsec restriction by creating a sysctl profile for lxc.&lt;br /&gt;
Create the following file &#039;&#039;/etc/sysctl.d/10-lxc.conf&#039;&#039; and add:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
kernel.grsecurity.chroot_caps = 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are a few other restrictions that can prevent proper container functionality. &lt;br /&gt;
When things do not work as expected always check the kernel log with dmesg to see if grsec prevented things from happening.&lt;br /&gt;
&lt;br /&gt;
Other possible restrictions are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
kernel.grsecurity.chroot_deny_chroot = 0&lt;br /&gt;
kernel.grsecurity.chroot_deny_mount = 0&lt;br /&gt;
kernel.grsecurity.chroot_deny_mknod = 0&lt;br /&gt;
kernel.grsecurity.chroot_deny_chmod = 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When you finished creating your new sysctl profile you can apply it by restarting sysctl service&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
rc-service sysctl restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NOTE: Always consult the [https://en.wikibooks.org/wiki/Grsecurity/Appendix/Grsecurity_and_PaX_Configuration_Options Grsecurity documentation] before applying these settings.&lt;br /&gt;
&lt;br /&gt;
== Create a guest ==&lt;br /&gt;
&lt;br /&gt;
=== Alpine Template ===&lt;br /&gt;
&lt;br /&gt;
{{Cmd|lxc-create -n guest1 -f /etc/lxc/lxc.conf -t alpine}}&lt;br /&gt;
&lt;br /&gt;
This will create a &#039;&#039;/var/lib/lxc/guest1&#039;&#039; directory with a &#039;&#039;config&#039;&#039; file and a &#039;&#039;rootfs&#039;&#039; directory.&lt;br /&gt;
&lt;br /&gt;
Note that by default alpine template &#039;&#039;&#039;does not have networking service on&#039;&#039;&#039;, you will need to add it using lxc-console&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If running on x86_64 architecture, it is possible to create a 32bit guest:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|lxc-create -n guest1 -f /etc/lxc/lxc.conf -t alpine -- --arch x86}}&lt;br /&gt;
&lt;br /&gt;
=== Debian template ===&lt;br /&gt;
&lt;br /&gt;
In order to create a debian template container you will need to install some packages:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk add debootstrap rsync}}&lt;br /&gt;
&lt;br /&gt;
Also you will need to turn off some grsecurity chroot options otherwise the debootstrap will fail:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|echo 0 &amp;gt; /proc/sys/kernel/grsecurity/chroot_caps&lt;br /&gt;
echo 0 &amp;gt; /proc/sys/kernel/grsecurity/chroot_deny_chroot&lt;br /&gt;
echo 0 &amp;gt; /proc/sys/kernel/grsecurity/chroot_deny_mount&lt;br /&gt;
echo 0 &amp;gt; /proc/sys/kernel/grsecurity/chroot_deny_mknod&lt;br /&gt;
echo 0 &amp;gt; /proc/sys/kernel/grsecurity/chroot_deny_chmod&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Please remember to turn them back on, or just simply reboot the system.&lt;br /&gt;
&lt;br /&gt;
Now you can run:&lt;br /&gt;
{{Cmd|SUITE{{=}}wheezy lxc-create -n guest1 -f /etc/lxc/lxc.conf -t debian}}&lt;br /&gt;
&lt;br /&gt;
=== Ubuntu template ===&lt;br /&gt;
&lt;br /&gt;
In order to create an ubuntu template container you will need to turn off some grsecurity chroot options:&lt;br /&gt;
&lt;br /&gt;
{{Cmd|echo 0 &amp;gt; /proc/sys/kernel/grsecurity/chroot_caps&lt;br /&gt;
echo 0 &amp;gt; /proc/sys/kernel/grsecurity/chroot_deny_chroot&lt;br /&gt;
echo 0 &amp;gt; /proc/sys/kernel/grsecurity/chroot_deny_mount&lt;br /&gt;
echo 0 &amp;gt; /proc/sys/kernel/grsecurity/chroot_deny_mknod&lt;br /&gt;
echo 0 &amp;gt; /proc/sys/kernel/grsecurity/chroot_deny_chmod&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Please remember to turn them back on, or just simply reboot the system.&lt;br /&gt;
&lt;br /&gt;
Now you can run (replace %MIRROR% with the actual hostname, for example: http://us.archive.ubuntu.com/ubuntu/)&lt;br /&gt;
&lt;br /&gt;
{{Cmd|lxc-create -n guest2 -f /etc/lxc/default.conf -t ubuntu -- -r xenial -a amd64 -u user --password secretpassword --mirror $MIRROR  }}&lt;br /&gt;
&lt;br /&gt;
{{Warning|Be sure to set systemd_container to yes in /etc/conf.d/lxc.CONTAINER.  Otherwise most functionality will be broken}}&lt;br /&gt;
&lt;br /&gt;
=== Unprivileged LXC images (Debian / Ubuntu / Centos etc..) ===&lt;br /&gt;
&lt;br /&gt;
{{Cmd|apk add gnupg xz&lt;br /&gt;
lxc-create -n container-name -t download}}&lt;br /&gt;
&amp;amp; choose the Distribution | Release | Architecture.&lt;br /&gt;
&lt;br /&gt;
To be able to login to a Debian container you currently need to:&lt;br /&gt;
{{Cmd|rm /lib/systemd/system/container-getty\@.service}}&lt;br /&gt;
&lt;br /&gt;
You can also [http://without-systemd.org/wiki/index.php/How_to_remove_systemd_from_a_Debian_jessie/sid_installationers remove Systemd from the container].&lt;br /&gt;
&lt;br /&gt;
== Starting/Stopping the guest ==&lt;br /&gt;
Create a symlink to the &#039;&#039;/etc/init.d/lxc&#039;&#039; script for your guest.&lt;br /&gt;
{{Cmd|ln -s lxc /etc/init.d/lxc.guest1}}&lt;br /&gt;
&lt;br /&gt;
You can start your guest with:&lt;br /&gt;
{{Cmd|/etc/init.d/lxc.guest1 start}}&lt;br /&gt;
&lt;br /&gt;
Stop it with:&lt;br /&gt;
{{Cmd|/etc/init.d/lxc.guest1 stop}}&lt;br /&gt;
&lt;br /&gt;
Make it autostart on boot up with:&lt;br /&gt;
{{Cmd| rc-update add lxc.guest1}}&lt;br /&gt;
&lt;br /&gt;
You can also add to the container config: &amp;lt;code&amp;gt;lxc.start.auto = 1&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp; {{Cmd|rc-update add lxc}}&lt;br /&gt;
&lt;br /&gt;
to autostart containers by the lxc service only.&lt;br /&gt;
&lt;br /&gt;
== Connecting to the guest ==&lt;br /&gt;
By default sshd is not installed, so you will have to attach to the container or connect to the virtual console. This is done with:&lt;br /&gt;
&lt;br /&gt;
=== Attach to container ===&lt;br /&gt;
&lt;br /&gt;
{{Cmd|lxc-attach -n guest1}}&lt;br /&gt;
&lt;br /&gt;
Just type exit to detach the container again (please do check the grsec notes above)&lt;br /&gt;
&lt;br /&gt;
=== Connect to virtual console ===&lt;br /&gt;
&lt;br /&gt;
{{Cmd|lxc-console -n guest1}}&lt;br /&gt;
&lt;br /&gt;
To disconnect from it, press {{key|Ctrl}}+{{key|a}} {{key|q}}&lt;br /&gt;
&lt;br /&gt;
== Deleting a guest ==&lt;br /&gt;
Make sure the guest is stopped and run:&lt;br /&gt;
{{Cmd|lxc-destroy -n guest1}}&lt;br /&gt;
This will erase everything, without asking any questions. It is equivalent to: {{Cmd|rm -r /var/lib/lxc/guest1}}&lt;br /&gt;
&lt;br /&gt;
== Advanced ==&lt;br /&gt;
&lt;br /&gt;
=== Creating a LXC container without modifying your network interfaces ===&lt;br /&gt;
&lt;br /&gt;
The problem with bridging is that the interface you bridge gets replaced with your new bridge interface.&lt;br /&gt;
That is to say that say you have an interface eth0 that you want to bridge, your eth0 interface gets replaced with the br0 interface that you create. It also means that the interface you use needs to be placed into promiscuous mode to catch all the traffic that could de destined to the other side of the bridge, which again may not be what you want.&lt;br /&gt;
&lt;br /&gt;
The solution is to create a dummy network interface, bridge that, and set up NAT so that traffic out of your bridge interface gets pushed through the interface of your choice.&lt;br /&gt;
&lt;br /&gt;
So, first, lets create that dummy interface (thanks to ncopa for talking me out of macvlan and pointing out the dummy interface kernel module)&lt;br /&gt;
&lt;br /&gt;
{{Cmd|modprobe dummy}}&lt;br /&gt;
&lt;br /&gt;
This will create a dummy interface called dummy0 on your host. To create this interface on every boot, you may need to create a /etc/modprobe.d/dummy.conf with:&lt;br /&gt;
{{Cmd |# Load dummy.ko at boot&lt;br /&gt;
dummy }}&lt;br /&gt;
&lt;br /&gt;
Now we will create a bridge called br0&lt;br /&gt;
&lt;br /&gt;
{{Cmd |brctl addbr br0&lt;br /&gt;
brctl setfd br0 0 }}&lt;br /&gt;
&lt;br /&gt;
and then make that dummy interface one end of the bridge&lt;br /&gt;
&lt;br /&gt;
{{Cmd | brctl addif br0 dummy0 }}&lt;br /&gt;
&lt;br /&gt;
Next, let&#039;s give that bridged interface a reason to exists&lt;br /&gt;
&lt;br /&gt;
{{ Cmd | ifconfig br0 192.168.1.1 netmask 255.255.255.0 up}}&lt;br /&gt;
&lt;br /&gt;
Create a file for your container, let&#039;s say /etc/lxc/bridgenat.conf, with the following settings.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
lxc.net.0.type = veth&lt;br /&gt;
lxc.net.0.flags = up&lt;br /&gt;
lxc.net.0.link = br0&lt;br /&gt;
lxc.net.0.name = eth1&lt;br /&gt;
lxc.net.0.ipv4.address = 192.168.1.2/24 192.168.1.255&lt;br /&gt;
lxc.net.0.ipv4.gateway = 192.168.1.1&lt;br /&gt;
lxc.net.0.veth.pair = veth-if-0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and build your container with that file&lt;br /&gt;
&lt;br /&gt;
{{ Cmd | lxc-create -n alpine -f /etc/lxc/bridgenat.conf -t alpine }}&lt;br /&gt;
&lt;br /&gt;
You should now be able to ping your container from your hosts, and your host from your container.&lt;br /&gt;
&lt;br /&gt;
Your container needs to know where to push traffic that isn&#039;t within it&#039;s subnet. To do so, we tell the container to route through the bridge interface br0&lt;br /&gt;
From inside the container run&lt;br /&gt;
&lt;br /&gt;
{{ Cmd | route add default gw 192.168.1.1 }}&lt;br /&gt;
&lt;br /&gt;
The next step is you push the traffic coming from your private subnet over br0 out through your internet facing interface, or any interface you chose&lt;br /&gt;
&lt;br /&gt;
We are messing with your IP tables here, so make sure these settings don&#039;t conflict with anything you may have already set up, obviously.&lt;br /&gt;
&lt;br /&gt;
Say eth0 was your internet facing network interface, and br0 is the name of the bridge you made earlier, we&#039;d do this:&lt;br /&gt;
&lt;br /&gt;
{{ Cmd | echo 1 &amp;gt; /proc/sys/net/ipv4/ip_forward&lt;br /&gt;
iptables --table nat --append POSTROUTING --out-interface eth0 -j MASQUERADE&lt;br /&gt;
iptables --append FORWARD --in-interface br0 -j ACCEPT&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Now you should be able to route through your bridge interface to the internet facing interface of your host from your container, just like at home!&lt;br /&gt;
&lt;br /&gt;
You could also have a dhcp server running on your host, and set it up to give IP addresses from your private subnet to any container that requests it, and then have one template for multiple alpine LXC containers, perfect for alpine development :)&lt;br /&gt;
&lt;br /&gt;
=== Using static IP ===&lt;br /&gt;
&lt;br /&gt;
If you&#039;re using static IP, you need to configure this properly on guest&#039;s /etc/network/interfaces. To stay on the above example, modify &#039;&#039;/var/lib/lxc/guest1/rootfs/etc/network/interfaces&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
from&lt;br /&gt;
&lt;br /&gt;
 #auto lo&lt;br /&gt;
     iface lo inet loopback&lt;br /&gt;
 auto eth0&lt;br /&gt;
     iface eth0 inet &#039;&#039;&#039;dhcp&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
to &lt;br /&gt;
&lt;br /&gt;
 #auto lo&lt;br /&gt;
     iface lo inet loopback&lt;br /&gt;
 auto eth0&lt;br /&gt;
     iface eth0 inet &#039;&#039;&#039;static&#039;&#039;&#039;&lt;br /&gt;
     address &amp;lt;lxc-container-ip&amp;gt;   # IP which the lxc container should use&lt;br /&gt;
     gateway &amp;lt;gateway-ip&amp;gt;         # IP of gateway to use, mostly same as on lxc-host&lt;br /&gt;
     netmask &amp;lt;netmask&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== mem and swap ===&lt;br /&gt;
&lt;br /&gt;
{{Cmd|vim /boot/extlinux.conf}}&lt;br /&gt;
&lt;br /&gt;
{{Cmd|&lt;br /&gt;
  APPEND initrd{{=}}initramfs-3.10.13-1-grsec root{{=}}UUID{{=}}7cd8789f-5659-40f8-9548-ae8f89c918ab modules{{=}}sd-mod,usb-storage,ext4 quiet cgroup_enable{{=}}memory swapaccount{{=}}1&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== checkconfig ===&lt;br /&gt;
{{Cmd|lxc-checkconfig}}&lt;br /&gt;
&lt;br /&gt;
{{Cmd|&lt;br /&gt;
Kernel configuration not found at /proc/config.gz; searching...&lt;br /&gt;
Kernel configuration found at /boot/config-3.10.13-1-grsec&lt;br /&gt;
--- Namespaces ---&lt;br /&gt;
Namespaces: enabled&lt;br /&gt;
Utsname namespace: enabled&lt;br /&gt;
Ipc namespace: enabled&lt;br /&gt;
Pid namespace: enabled&lt;br /&gt;
User namespace: missing&lt;br /&gt;
Network namespace: enabled&lt;br /&gt;
Multiple /dev/pts instances: enabled&lt;br /&gt;
&lt;br /&gt;
--- Control groups ---&lt;br /&gt;
Cgroup: enabled&lt;br /&gt;
Cgroup clone_children flag: enabled&lt;br /&gt;
Cgroup device: enabled&lt;br /&gt;
Cgroup sched: enabled&lt;br /&gt;
Cgroup cpu account: enabled&lt;br /&gt;
Cgroup memory controller: missing&lt;br /&gt;
Cgroup cpuset: enabled&lt;br /&gt;
&lt;br /&gt;
--- Misc ---&lt;br /&gt;
Veth pair device: enabled&lt;br /&gt;
Macvlan: enabled&lt;br /&gt;
Vlan: enabled&lt;br /&gt;
File capabilities: enabled&lt;br /&gt;
&lt;br /&gt;
Note : Before booting a new kernel, you can check its configuration&lt;br /&gt;
usage : CONFIG{{=}}/path/to/config /usr/bin/lxc-checkconfig&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== VirtualBox ===&lt;br /&gt;
&lt;br /&gt;
In order for network to work on containers you need to set &amp;quot;Promiscuous Mode&amp;quot; to &amp;quot;Allow All&amp;quot; in VirtualBox settings for the network adapter.&lt;br /&gt;
&lt;br /&gt;
[[File:VirtualBoxNetworkAdapter.jpg]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Virtualization]]&lt;br /&gt;
&lt;br /&gt;
=== postgreSQL ===&lt;br /&gt;
&lt;br /&gt;
Inside the container run: {{Cmd|chmod go+w /dev/null}} to fix {{Cmd|rc-service postgresql start}}&lt;br /&gt;
&lt;br /&gt;
=== openVPN ===&lt;br /&gt;
&lt;br /&gt;
see [[Setting_up_a_OpenVPN_server#openVPN_and_LXC]]&lt;br /&gt;
&lt;br /&gt;
== LXC 1.0 Additional information ==&lt;br /&gt;
&lt;br /&gt;
Some info regarding new features in LXC 1.0&lt;br /&gt;
 &lt;br /&gt;
https://www.stgraber.org/2013/12/20/lxc-1-0-blog-post-series/&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Howto-lxc-simple]]&lt;/div&gt;</summary>
		<author><name>Llnu</name></author>
	</entry>
	<entry>
		<id>https://wiki.alpinelinux.org/w/index.php?title=Setting_up_ZFS_on_LUKS&amp;diff=16248</id>
		<title>Setting up ZFS on LUKS</title>
		<link rel="alternate" type="text/html" href="https://wiki.alpinelinux.org/w/index.php?title=Setting_up_ZFS_on_LUKS&amp;diff=16248"/>
		<updated>2019-08-23T20:56:08Z</updated>

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

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