Installing Parabola GNU/Linux with full disk encryption (including /boot)

Libreboot uses the GRUB payload by default, which means that the GRUB configuration file (where your GRUB menu comes from) is stored directly alongside libreboot and it's GRUB payload executable, inside the flash chip. In context, this means that installing distributions and managing them is handled slightly differently compared to traditional BIOS systems.

On most systems, the /boot partition has to be left unencrypted while the others are encrypted. This is so that GRUB, and therefore the kernel, can be loaded and executed since the firmware can't open a LUKS volume. Not so with libreboot! Since GRUB is already included directly as a payload, even /boot can be encrypted. This protects /boot from tampering by someone with physical access to the system.

Back to previous index

Boot Parabola's install environment. How to boot a GNU/Linux installer.

For this guide I used the 2015 08 01 image to boot the live installer and install the system. This is available at this page.

This guide will go through the installation steps taken at the time of writing, which may or may not change due to the volatile nature of Parabola (it changes all the time). In general most of it should remain the same. If you spot mistakes, please say so! This guide will be ported to the Parabola wiki at a later date. For up to date Parabola install guide, go to the Parabola wiki. This guide essentially cherry picks the useful information (valid at the time of writing: 2015-08-25).

This section deals with wiping the storage device on which you plan to install Parabola GNU/Linux. Follow these steps, but if you use an SSD, also:

- beware there are issues with TRIM (not enabled through luks) and security issues if you do enable it. See this page for more info.

- make sure it's brand-new (or barely used). Or, otherwise, be sure that it never previously contained plaintext copies of your data.

- make sure to read this article. Edit /etc/fstab later on when chrooted into your install. Also, read the whole article and keep all points in mind, adapting them for this guide.

Wipe the MBR (if you use MBR):
# lsblk
Your storage is probably /dev/sda, but be very sure to double check this or you WILL lose your data!
# dd if=/dev/zero of=/dev/sda bs=446 count=1; sync
Never use SeaBIOS! The MBR section can easily be changed with malicious code, which SeaBIOS will blindly execute. This guide is for libreboot with GRUB-as-payload only.

Securely wipe the drive:
# dd if=/dev/urandom of=/dev/sda; sync
NOTE: If you have an SSD, only do this the first time. If it was already LUKS-encrypted before, use the info below to wipe the LUKS header. Also, check online for your SSD what the recommended erase block size is. For example if it was 2MiB:
# dd if=/dev/urandom of=/dev/sda bs=2M; sync

If your drive was already LUKS encrypted (maybe you are re-installing your distro) then it is already 'wiped'. You should just wipe the LUKS header. https://www.lisenet.com/2013/luks-add-keys-backup-and-restore-volume-header/ showed me how to do this. It recommends doing the first 3MiB. Now, that guide is recommending putting zero there. I'm going to use urandom. Do this:
# head -c 3145728 /dev/urandom > /dev/sda; sync
(Wiping the LUKS header is important, since it has hashed passphrases and so on. It's 'secure', but 'potentially' a risk).

Change keyboard layout

Parabola live shell assumes US Qwerty. If you have something different, list the available keymaps and use yours:
# localectl list-keymaps
# loadkeys LAYOUT
For me, LAYOUT would have been dvorak-uk.

Establish an internet connection

Refer to this guide. Wired is recommended, but wireless is also explained there.

Getting started

The beginning is based on https://wiki.parabolagnulinux.org/Installation_Guide. Then I referred to https://wiki.archlinux.org/index.php/Partitioning at first.

dm-mod

device-mapper will be used - a lot. Make sure that the kernel module is loaded:
# modprobe dm-mod

Create LUKS partition

I am using MBR partitioning, so I use cfdisk:
# cfdisk /dev/sda

I create a single large sda1 filling the whole drive, leaving it as the default type 'Linux' (83).

Now I refer to https://wiki.archlinux.org/index.php/Dm-crypt/Drive_preparation#Partitioning:
I am then directed to https://wiki.archlinux.org/index.php/Dm-crypt/Device_encryption.

Parabola forces you to RTFM. Do that.

It tells me to run:
# cryptsetup benchmark (for making sure the list below is populated)
Then:
# cat /proc/crypto
This gives me crypto options that I can use. It also provides a representation of the best way to set up LUKS (in this case, security is a priority; speed, a distant second). To gain a better understanding, I am also reading:
# man cryptsetup

Following that page, based on my requirements, I do the following based on https://wiki.archlinux.org/index.php/Dm-crypt/Device_encryption#Encryption_options_for_LUKS_mode. Reading through, it seems like Serpent (encryption) and Whirlpool (hash) is the best option.

I am initializing LUKS with the following:
# cryptsetup -v --cipher serpent-xts-plain64 --key-size 512 --hash whirlpool --use-random --verify-passphrase luksFormat /dev/sda1 Choose a secure passphrase here. Ideally lots of lowercase/uppercase numbers, letters, symbols etc all in a random pattern. The password length should be as long as you are able to handle without writing it down or storing it anywhere.

Create LVM

Now I refer to https://wiki.archlinux.org/index.php/LVM.

Open the LUKS partition:
# cryptsetup luksOpen /dev/sda1 lvm
(it will be available at /dev/mapper/lvm)

Create LVM partition:
# pvcreate /dev/mapper/lvm
Show that you just created it:
# pvdisplay

Now I create the volume group, inside of which the logical volumes will be created:
# vgcreate matrix /dev/mapper/lvm
(volume group name is 'matrix' - choose your own name, if you like) Show that you created it:
# vgdisplay

Now create the logical volumes:
# lvcreate -L 2G matrix -n swapvol (2G swap partition, named swapvol)
Again, choose your own name if you like. Also, make sure to choose a swap size of your own needs. It basically depends on how much RAM you have installed. I refer to http://www.linux.com/news/software/applications/8208-all-about-linux-swap-space.
# lvcreate -l +100%FREE matrix -n rootvol (single large partition in the rest of the space, named rootvol)
You can also be flexible here, for example you can specify a /boot, a /, a /home, a /var, a /usr, etc. For example, if you will be running a web/mail server then you want /var in its own partition (so that if it fills up with logs, it won't crash your system). For a home/laptop system (typical use case), a root and a swap will do (really).

Verify that the logical volumes were created, using the following command:
# lvdisplay

Create / and swap partitions, and mount

For the swapvol LV I use:
# mkswap /dev/mapper/matrix-swapvol
Activate swap:
# swapon /dev/matrix/swapvol

For the rootvol LV I use:
# mkfs.ext4 /dev/mapper/matrix-rootvol

Mount the root (/) partition:
# mount /dev/matrix/rootvol /mnt

Continue with Parabola installation

This guide is really about GRUB, Parabola and cryptomount. I have to show how to install Parabola so that the guide can continue.

Now I am following the rest of https://wiki.parabolagnulinux.org/Installation_Guide. I also cross referenced https://wiki.archlinux.org/index.php/Installation_guide.

Create /home and /boot on rootvol mountpoint:
# mkdir -p /mnt/home
# mkdir -p /mnt/boot

Once all the remaining partitions, if any, have been mounted, the devices are ready to install Parabola.

In /etc/pacman.d/mirrorlist, comment out all lines except the Server line closest to where you are (I chose the UK Parabola server (main server)) and then did:
# pacman -Syy
# pacman -Syu
# pacman -Sy pacman (and then I did the other 2 steps above, again)
In my case I did the steps in the next paragraph, and followed the steps in this paragraph again.

<troubleshooting>
   The following is based on 'Verification of package signatures' in the Parabola install guide.
   Check there first to see if steps differ by now.
   Now you have to update the default Parabola keyring. This is used for signing and verifying packages:
   # pacman -Sy parabola-keyring
   It says that if you get GPG errors, then it's probably an expired key and, therefore, you should do:
   # pacman-key --populate parabola
   # pacman-key --refresh-keys
   # pacman -Sy parabola-keyring
   To be honest, you should do the above anyway. Parabola has a lot of maintainers, and a lot of keys. Really!
   If you get an error mentioning dirmngr, do:
   # dirmngr </dev/null
   Also, it says that if the clock is set incorrectly then you have to manually set the correct time
   (if keys are listed as expired because of it):
   # date MMDDhhmm[[CC]YY][.ss]
   I also had to install:
   # pacman -S archlinux-keyring
   # pacman-key --populate archlinux
   In my case I saw some conflicting files reported in pacman, stopping me from using it.
   I deleted the files that it mentioned and then it worked. Specifically, I had this error:
   licenses: /usr/share/licenses/common/MPS exists in filesystem
   I rm -Rf'd the file and then pacman worked. I'm told that the following would have also made it work:
   # pacman -Sf licenses
</troubleshooting>

I also like to install other packages (base-devel, compilers and so on) and wpa_supplicant/dialog/iw/wpa_actiond are needed for wireless after the install:
# pacstrap /mnt base base-devel wpa_supplicant dialog iw wpa_actiond

Configure the system

Generate an fstab - UUIDs are used because they have certain advantages (see https://wiki.parabola.nu/Fstab#Identifying_filesystems. If you prefer labels instead, replace the -U option with -L):
# genfstab -U -p /mnt >> /mnt/etc/fstab
Check the created file:
# cat /mnt/etc/fstab
(If there are any errors, edit the file. Do NOT run the genfstab command again!)

Chroot into new system:
# arch-chroot /mnt /bin/bash

It's a good idea to have this installed:
# pacman -S linux-libre-lts

It was also suggested that you should install this kernel (read up on what GRSEC is):
# pacman -S linux-libre-grsec

This is another kernel that sits inside /boot, which you can use. LTS means 'long-term support'. These are so-called 'stable' kernels that can be used as a fallback during updates, if a bad kernel causes issues for you.

Parabola does not have wget. This is sinister. Install it:
# pacman -S wget

Locale:
# nano /etc/locale.gen
Uncomment your needed localisations. For example en_GB.UTF-8 (UTF-8 is highly recommended over other options).
# locale-gen
# echo LANG=en_GB.UTF-8 > /etc/locale.conf
# export LANG=en_GB.UTF-8

Console font and keymap:
# nano /etc/vconsole.conf
In my case:

KEYMAP=dvorak-uk
FONT=Lat9w-16

Time zone:
# ln -s /usr/share/zoneinfo/Europe/London /etc/localtime
(Replace Zone and Subzone to your liking. See /usr/share/zoneinfo)

Hardware clock:
# hwclock --systohc --utc

Hostname: Write your hostname to /etc/hostname. For example, if your hostname is parabola:
# echo parabola > /etc/hostname
Add the same hostname to /etc/hosts:
# nano /etc/hosts

#<ip-address>	<hostname.domain.org>	<hostname>
127.0.0.1	localhost.localdomain	localhost	parabola
::1		localhost.localdomain	localhost	parabola

Configure the network: Refer to https://wiki.parabola.nu/Beginners%27_guide#Configure_the_network.

Mkinitcpio: Configure /etc/mkinitcpio.conf as needed (see https://wiki.parabola.nu/Mkinitcpio). Runtime modules can be found in /usr/lib/initcpio/hooks, and build hooks can be found in /usr/lib/initcpio/install. (# mkinitcpio -H hookname gives information about each hook.) Specifically, for this use case:
# nano /etc/mkinitcpio.conf
Then modify the file like so:

Now using mkinitcpio, you can create the kernel and ramdisk for booting with (this is different from Arch, specifying linux-libre instead of linux):
# mkinitcpio -p linux-libre
Also do it for linux-libre-lts:
# mkinitcpio -p linux-libre-lts
Also do it for linux-libre-grsec:
# mkinitcpio -p linux-libre-grsec

Set the root password: At the time of writing, Parabola used SHA512 by default for its password hashing. I referred to https://wiki.archlinux.org/index.php/SHA_password_hashes.
# nano /etc/pam.d/passwd
Add rounds=65536 at the end of the uncommented 'password' line.
# passwd root
Make sure to set a secure password! Also, it must never be the same as your LUKS password.

Extra security tweaks

Based on https://wiki.archlinux.org/index.php/Security.

Restrict access to important directories:
# chmod 700 /boot /etc/{iptables,arptables}

Lockout user after three failed login attempts:
Edit the file /etc/pam.d/system-login and comment out that line:
# auth required pam_tally.so onerr=succeed file=/var/log/faillog
Or just delete it. Above it, put:
auth required pam_tally.so deny=2 unlock_time=600 onerr=succeed file=/var/log/faillog
To unlock a user manually (if a password attempt is failed 3 times), do:
# pam_tally --user theusername --reset What the above configuration does is lock the user out for 10 minutes, if they make 3 failed login attempts.

Configure sudo - not covered here. Will be covered post-installation in another tutorial, at a later date. If this is a single-user system, you don't really need sudo.

Unmount, reboot!

Exit from chroot:
# exit

unmount:
# umount -R /mnt
# swapoff -a

deactivate the lvm lv's:
# lvchange -an /dev/matrix/rootvol
# lvchange -an /dev/matrix/swapvol

Lock the encrypted partition (close it):
# cryptsetup luksClose lvm

# shutdown -h now
Remove the installation media, then boot up again.

Booting from GRUB

Initially you will have to boot manually. Press C to get to the GRUB command line. The underlined parts are optional (using those 2 underlines will boot lts kernel instead of normal).

grub> cryptomount -a
grub> set root='lvm/matrix-rootvol'
grub> linux /boot/vmlinuz-linux-libre-lts root=/dev/matrix/rootvol cryptdevice=/dev/sda1:root
grub> initrd /boot/initramfs-linux-libre-lts.img
grub> boot

You could also make it load /boot/vmlinuz-linux-libre-grsec and /boot/initramfs-linux-libre-grsec.img

Modify grub.cfg inside the ROM

Now you need to modify the ROM, so that Parabola can boot automatically with this configuration. grub_cbfs.html shows you how. Follow that guide, using the configuration details below.

Inside the 'Load Operating System' menu entry, change the contents to:
cryptomount -a
set root='lvm/matrix-rootvol'
linux /boot/vmlinuz-linux-libre-lts root=/dev/matrix/rootvol cryptdevice=/dev/sda1:root
initrd /boot/initramfs-linux-libre-lts.img

Note: the underlined parts above (-lts) can also be removed, to boot the latest kernel instead of LTS (long-term support) kernels. You could also copy the menu entry and in one have -lts, and without in the other menuentry. You could also create a menu entry to load /boot/vmlinuz-linux-libre-grsec and /boot/initramfs-linux-libre-grsec.img

Without specifying a device, the -a parameter tries to unlock all detected LUKS volumes. You can also specify -u UUID or -a (device).

Personally, I opted to have the entry for linux-libre-grsec at the top, so that it would load by default.

Start dhcp on ethernet:
# systemctl start dhcpcd.service This is just for the step below. I won't cover network configuration here. That is for another Parabola article.

The password below (it's password, by the way) after 'password_pbkdf2 root' should be changed and is created by the grub-mkpasswd-pbkdf2 utility, which you need to install or otherwise compile, like so:
# pacman -S grub

GRUB isn't needed for booting, since it's already included as a payload in libreboot. This is only so that the utility needed becomes available. Get your hash by entering your chosen password at the prompt, when running this command:
# grub-mkpasswd-pbkdf2

It will output the hash for the password that you entered. Make sure to specify a password that is different from both your LUKS *and* your root/user password. Use it to replace the default hash mentioned above.

Above the 'Load Operating System' menu entry you should also add a GRUB password, like so (this example uses password as the password):


set superusers="root"
password_pbkdf2 root grub.pbkdf2.sha512.10000.711F186347156BC105CD83A2ED7AF1EB971AA2B1EB2640172F34B0DEFFC97E654AF48E5F0C3B7622502B76458DA494270CC0EA6504411D676E6752FD1651E749.8DD11178EB8D1F633308FD8FCC64D0B243F949B9B99CCEADE2ECA11657A757D22025986B0FA116F1D5191E0A22677674C994EDBFADE62240E9D161688266A711
	

MAKE SURE TO DO THIS ON grubtest.cfg *BEFORE* DOING IT ON grub.cfg. Then select the menu entry that says Switch to grubtest.cfg and test that it works. Then copy that to grub.cfg once you're satisfied. WHY? BECAUSE AN INCORRECTLY SET PASSWORD CONFIG MEANS YOU CAN'T AUTHENTICATE, WHICH MEANS 'BRICK'.

(emphasis added, because it's needed. This is a common roadblock for users)

Note that the above entry specifies user 'root'; this is just a username for GRUB. You don't even need to use root. Change root on both of those 2 lines to whatever you want.

With this configuration, you will have to enter a password at boot time, in GRUB, before being able to use any of the menu entries or switch to the terminal. This protects your system from an attacker simply booting a live usb distro and re-flashing the boot firmware.

You probably only need base-devel (compilers and so on) to build and use cbfstool. It was already installed if you followed this tutorial, but here it is:
# pacman -S base-devel

For flashing the modified ROM, I just used flashrom from the Parabola repo's:
# pacman -S flashrom
I also installed dmidecode:
# pacman -S dmidecode

When done, deleted GRUB (remember, we only needed it for the grub-mkpasswd-pbkdf2 utility; GRUB is already part of libreboot, flashed alongside it as a payload):
# pacman -R grub

If you followed all that correctly, you should now have a fully encrypted Parabola installation. This is a very barebones Parabola install (the default one). Refer to the wiki for how to do the rest (desktop, etc).

Using a key file to unlock /boot/

By default, you will have to enter your LUKS passphrase twice; once in GRUB, and once when booting the kernel. GRUB unlocks the encrypted partition and then loads the kernel, but the kernel is not aware of the fact that it is being loaded from an encrypted volume. Therefore, you will be asked to enter your passphrase a second time. A workaround is to put a keyfile inside initramfs, with instructions for the kernel to use it when booting. This is safe, because /boot/ is encrypted (otherwise, putting a keyfile inside initramfs would be a bad idea).
Generate the file:
# dd bs=512 count=4 if=/dev/urandom of=/etc/mykeyfile iflag=fullblock
Insert it into the luks volume:
# cryptsetup luksAddKey /dev/sdX /etc/mykeyfile
Add the keyfile to the initramfs by adding it to FILES in /etc/mkinitcpio.conf. For example:
Integrate it inside initramfs:
# FILES="/etc/mykeyfile"
Create the initramfs image from scratch:
# mkinitcpio -p linux-libre
Add the following to your grub.cfg, or add it in the kernel command line for GRUB:
# cryptkey=rootfs:/etc/mykeyfile

You can also place this inside the grub.cfg that exists in CBFS: grub_cbfs.html.

Further security tips

https://wiki.archlinux.org/index.php/Security.
https://wiki.parabolagnulinux.org/User:GNUtoo/laptop

Follow-up tutorial: configuring Parabola

configuring_parabola.html shows my own notes post-installation. Using these, you can get a basic system similar to the one that I chose for myself. You can also cherry pick useful notes and come up with your own system. Parabola is user-centric, which means that you are in control. For more information, read The Arch Way (Parabola also follows it).

Copyright © 2014, 2015 Francis Rowe <info@gluglug.org.uk>
Copyright © 2015 Jeroen Quint <jezza@diplomail.ch>
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license can be found at ../gfdl-1.3.txt

Updated versions of the license (when available) can be found at https://www.gnu.org/licenses/licenses.html

UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS, IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION, WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS, ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.

TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION, NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT, INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES, COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.

The disclaimer of warranties and limitation of liability provided above shall be interpreted in a manner that, to the extent possible, most closely approximates an absolute disclaimer and waiver of all liability.