Installing Arch with LVM on LUKS and Btrfs (EFI)

NOTE: This post has been updated 2017-05-30 to use systemd-boot instead of GRUB.

I did the steps below to install my Arch for the first time, because I wanted to use Btrfs and LUKS, and also enable swap.

Start Installation CD/USB.
Set up keymap (see available keymaps with ls /usr/share/kbd/keymaps/i386/qwerty):
loadkeys sv-latin1
And start dhcp-request if you haven’t received an IP-address (check with ip addr):
dhcpcd
And now the fun part, partitioning!
Open up gdisk to create partitions for EFI and /boot:
gdisk /dev/sda
o (Create a new empty GUID partition table (GPT))
Proceed? Y

Create partitions:
n (Add a new partition)
Partition number 1
First sector 2048 (default)
Last sector +512M
Hex code EF00

n (Add a new partition)
Partition number 2
First sector 2099200 (default)
Last sector (press Enter to use remaining disk)
Hex code 8E00

It should look something like this (print with p):
Number Start (sector) End (sector) Size Code Name
1 2048 1050623 512.0 MiB EF00 EFI System
2 1050624 500118158 238.0 GiB 8E00 Linux LVM

If everything looks good, save and quit:
w
Y

Set up the encryption container:
cryptsetup luksFormat /dev/sda2
Are you sure? YES
Enter passphrase (twice)

Open up the container:
cryptsetup luksOpen /dev/sda2 lvm
Create the LVM physical volume:
pvcreate /dev/mapper/lvm
Create the LVM volume group:
vgcreate lvmvg /dev/mapper/lvm
Create LVM logical volumes:
lvcreate -L 8G lvmvg -n swapvol
lvcreate -l 100%FREE lvmvg -n rootvol

Time to format everything:
mkfs.vfat -F32 /dev/sda1
mkfs.btrfs -L btrfs /dev/mapper/lvmvg-rootvol
mkswap /dev/mapper/lvmvg-swapvol
swapon /dev/mapper/lvmvg-swapvol

Create Btrfs subvolumes:
mount /dev/mapper/lvmvg-rootvol /mnt
btrfs subvolume create /mnt/root
btrfs subvolume create /mnt/home
umount /mnt
mount -o subvol=root,ssd,compress=lzo /dev/mapper/lvmvg-rootvol /mnt
mkdir /mnt/{boot,home}
mount -o subvol=home,ssd,compress=lzo /dev/mapper/lvmvg-rootvol /mnt/home

And finally the /boot volume:
mount /dev/sda1 /mnt/boot

Installation:
pacstrap /mnt base base-devel btrfs-progs vim efibootmgr sudo zsh zsh-completions grml-zsh-config

Generate fstab:
genfstab -p /mnt > /mnt/etc/fstab
It should look something like this (genfstab -p /mnt):
/dev/mapper/lvmvg-swapvol swap swap defaults 0 0
/dev/mapper/lvmvg-rootvol / btrfs rw,relatime,ssd,compress=lzo,space_cache,subvol=root 0 0
/dev/mapper/lvmvg-rootvol /home btrfs rw,relatime,ssd,compress=lzo,space_cache,subvol=home 0 0
/dev/sda1 /boot/efi vfat rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro 0 2

Setting up stuff:
arch-chroot /mnt /bin/zsh
echo computer_name > /etc/hostname
chsh -s /bin/zsh
ln -sf /usr/share/zoneinfo/Europe/Stockholm /etc/localtime (See available timezones with ls /usr/share/zoneinfo)
vim /etc/locale.gen (uncomment en_GB.UTF-8 and sv_SE.UTF-8, or other locales that you want)
locale-gen
echo LANG=en_GB.UTF-8 > /etc/locale.conf
echo KEYMAP=sv-latin1 > /etc/vconsole.conf
passwd

Change/add the following to /etc/mkinitcpio.conf:
MODULES="crc32c-intel"
HOOKS="base udev autodetect modconf block encrypt lvm2 btrfs resume filesystems keyboard fsck"

Generate mkinitcpio:
mkinitcpio -p linux

Run the command below to initialize systemd-boot, the path is your EFI-partition.

bootctl --path=/boot install

Create the file /boot/loader/entries/arch.conf with the following content, or as you have your partitions set up:
title Arch Linux
linux /vmlinuz-linux
initrd /initramfs-linux.img
options cryptdevice=/dev/sda2:lvm root=/dev/mapper/lvmvg-rootvol rw rootflags=subvol=root resume=/dev/mapper/lvmvg-swapvol quiet

Edit the file /boot/loader/loader.conf:
timeout 3
default arch

Done, rebooting time!
exit
umount -R /mnt
reboot

Installing KDE (personal preferences, might not apply to your setup!):
systemctl start dhcpcd (Starts DHCP so that you can download packages)
pacman -S networkmanager sddm
systemctl enable NetworkManager sddm
useradd -m -g users -G wheel username
passwd username

Add your user to sudo (edit /etc/sudoers):
username ALL=(ALL) ALL
Intel-specific GPU drivers and xorg. You might have to change xf86-video depending on your GPU vendor:
pacman -S xf86-video-intel xorg-server (for laptops: xf86-input-synaptics)
pacman -S plasma-meta ttf-dejavu ttf-droid ttf-liberation ttf-freefont konsole (select defaults on package selections)

Optional packages that you might want:
pacman -S kate pulseaudio yakuake firefox thunderbird dolphin ark chromium kodi feh conky firewalld unrar unzip zip git pavucontrol nfs-utils alsa-utils mpv openssh gimp spectacle intel-ucode lm_sensors redshift bind-tools whois krdc freerdp kcalc
If you want to install steam you must enable multilib, edit /etc/pacman/ and uncomment:
[multilib]
Include = /etc/pacman.d/mirrorlist

Install Steam:
pacman -Sy steam
And finally the last reboot!
reboot

After reboot, change login shell in the top-left to Plasma, and login.

All done! Now install everything else you might want :)

If you did something wrong and the OS doesn’t start correctly, you can start the USB/CD again and write the following to mount all things again:
loadkeys sv-latin1
cryptsetup luksOpen /dev/sda2 lvm
mount -o subvol=root,ssd /dev/mapper/lvmvg-rootvol /mnt
mount -o subvol=home,ssd /dev/mapper/lvmvg-rootvol /mnt/home
swapon /dev/mapper/lvmvg-swapvol
mount /dev/sda1 /mnt/boot
arch-chroot /mnt /bin/zsh

Sources:
My very good friend Dezponia
https://wiki.archlinux.org/index.php/Installation_guide
https://wiki.archlinux.org/index.php/Dm-crypt/Encrypting_an_entire_system#LVM_on_LUKS
https://wiki.archlinux.org/index.php?title=Btrfs&direction=prev&oldid=374303#Installing_Archlinux_on_btrfs