THIS PAGE IS OUTDATED, PLEASE VISIT LINK FOR MORE UP TO DATA INSTRUCTIONS
The following instructions should guide you through setting up Manjaro on an encrypted ZFS pool.
Boot an up-to-date Manjaro ISO on the system you want to install on and open a terminal. This guide will only work on a computer booting in UEFI mode.
create a short handle to reference the ssd by id e.g.:
DISK=/dev/disk/by-id/ata-Samsung_SSD_850_EVO_500GB_123ABCDEF12345G
Now we format the disk into a 1GB EFI partition, a ZFS root pool filling everything remaining except the last 16GB, and the last 16GB on disk we will use for an encrypted swap partition. If you prefer not to use an encrypted swap partition you are free to modify the following commands here, and later in the guide when we set it up. If you need guidance on how large your swap partition should be have a look at: Swap space on Linux systems: A primer | Opensource.com
sudo sgdisk --zap-all $DISK
sudo sgdisk -n1:0:+1G -t1:EF00 $DISK
sudo sgdisk -n2:0:-16G $DISK
sudo sgdisk -n3:0:0 $DISK
Warning
If you prefer using a swap file, I want to point out that it is not recommended to put a swap file on the root pool or any ZFS pool for that matter. The practise of having a swap file in a zfs pool has to be shown to cause problems and crashes.
Create a random UUID to append to the zfs pool names so that importing the pools on other computers e.g. for rescue or backing them up won’t result into name conflicts!
poolUUID=$(dd if=/dev/urandom of=/dev/stdout bs=1 count=100 2>/dev/null |tr -dc 'a-z0-9' | cut -c-6)
Create the root pool with the setting recommended in the Arch wiki:
https://wiki.archlinux.org/index.php/Install_Arch_Linux_on_ZFS#Setup_the_ZFS_filesystem
I want to point out that if you want to setup a more complex disk layout with ZFS your chance to do so is here in modifying to following command e.g. to setup a mirrored layout!
sudo zpool create \
-f -o ashift=12 -o autotrim=on \
-O acltype=posixacl \
-O relatime=on \
-O xattr=sa \
-O dnodesize=legacy \
-O normalization=formD \
-O mountpoint=none \
-O canmount=off \
-O devices=off \
-R /mnt \
-O compression=lz4 \
-O encryption=aes-256-gcm \
-O keyformat=passphrase \
-O keylocation=prompt \
rpool_$poolUUID ${DISK}-part2
Now we are going to create the datasets. Nothing is stored directly under rpool, hence: canmount=off! canmount is set to noauto for root as advised here: Install Arch Linux on ZFS - ArchWiki
sudo zfs create -o canmount=off -o mountpoint=none rpool_$poolUUID/HOME
sudo zfs create -o canmount=off -o mountpoint=none rpool_$poolUUID/ROOT
sudo zfs create -o mountpoint=/ -o canmount=noauto rpool_$poolUUID/ROOT/manjaro
sudo zfs mount rpool_$poolUUID/ROOT/manjaro
sudo zfs create -o mountpoint=/home rpool_$poolUUID/HOME/manjaro
sudo zfs create -o mountpoint=/root rpool_$poolUUID/HOME/manjaro/root
sudo zfs mount -a
Formatting and mounting the EFI partition.
sudo mkfs.vfat -n EFI $DISK-part1
sudo mkdir /mnt/boot
sudo mount $DISK-part1 /mnt/boot
Configuring the root filesystem as advised here:
https://wiki.archlinux.org/index.php/Install_Arch_Linux_on_ZFS#Configure_the_root_filesystem
sudo zpool set bootfs=rpool_$poolUUID/ROOT/manjaro rpool_$poolUUID
sudo zpool set cachefile=/etc/zfs/zpool.cache rpool_$poolUUID
Now the installation procedure will start, run the “setup” command in the terminal to start the interactive installer. In the following section I will give you hints which menu points you are required to use. At the time of writing this guide to most up-to-date linux kernel is Kernel 5.10 (package linux510), if you follow this tutorial at a later point you will need to adjust some parts of the following instructions accordingly:
Prepare Installation -> Set Virtual Console -> change -> <your selection>
Install Desktop System -> Install Manjaro Desktop -> yay + base-devel; linux510 -> <your selection> -> Yes -> cryptsetup; linux510-zfs -> <your selection> -> <your selection>
Install Desktop System -> Configure Base -> Generate FSTAB -> fstabgen -U -p
Install Desktop System -> Configure Base -> Set Hostname
Install Desktop System -> Configure Base -> Set System locale -> <your selection> -> <your selection>
Install Desktop System -> Configure Base -> Set Desktop Keybaord Layout -> <your selection>
Install Desktop System -> Configure Base -> Set Timezone and Clock -> <your selection> -> <your selection> -> Yes -> utc
Install Desktop System -> Configure Base -> Set Root Password
Install Desktop System -> Configure Base -> Add New User(s) -> <your selection> -> <your selection>
Done -> Yes -> No
Leaving the setup unmounts the zfs datasets and the efi partition so we need to remount them.
sudo zfs mount rpool_$poolUUID/ROOT/manjaro
sudo zfs mount -a
sudo mount $DISK-part1 /mnt/boot
Copy over the zpool.cache file to the new system
sudo cp /etc/zfs/zpool.cache /mnt/etc/zfs/zpool.cache
Now we are going to create the encrypted swap partition. If you are sure you do not want to use a swap partition don’t execute the following commands.
echo " " | sudo tee --append /mnt/etc/crypttab
echo "# encrypted swap partition" | sudo tee --append /mnt/etc/crypttab
echo "swap $DISK-part3 /dev/urandom swap,cipher=aes-cbc-essiv:sha256,size=256" | sudo tee --append /mnt/etc/crypttab
echo " " | sudo tee --append /mnt/etc/fstab
echo "# mounting the encrypted swap partition" | sudo tee --append /mnt/etc/fstab
echo "/dev/mapper/swap none swap defaults 0 0" | sudo tee --append /mnt/etc/fstab
Activating the zfs services like advised in:
https://wiki.archlinux.org/index.php/Install_Arch_Linux_on_ZFS#Configure_systemd_ZFS_mounts
sudo systemctl enable zfs.target --root=/mnt
sudo systemctl enable zfs-import-cache --root=/mnt
sudo systemctl enable zfs-mount --root=/mnt
sudo systemctl enable zfs-import.target --root=/mnt
When running ZFS on root, the machine’s hostid will not be available at the time of mounting the root filesystem. There are two solutions to this. You can either place your spl hostid in the kernel parameters in your boot loader. For example, adding spl.spl_hostid=0x12345678, to get your number use the hostid command.
The other, and suggested, solution is to make sure that there is a hostid in /etc/hostid, and then regenerate the initramfs image which will copy the hostid into the initramfs image. To write the hostid file safely you need to use the zgenhostid command.
The hostid string has to be 8 alphanumeric characters.
manjaro-chroot /mnt zgenhostid
manjaro-chroot /mnt mkinitcpio -P
Now we install the bootmanager!
manjaro-chroot /mnt bootctl install
manjaro-chroot /mnt sudo pacman -S systemd-boot-manager
manjaro-chroot /mnt sdboot-manage gen
Finally we unmount all the disks and then restart into our newly installed system!
sudo umount /mnt/boot
sudo zfs umount -a
sudo zfs umount rpool_$poolUUID/ROOT/manjaro
sudo zpool export rpool_$poolUUID