Installing Arch Linux on ZFS
Related articles
This article details the steps required to install Arch Linux onto a root ZFS filesystem. This article supplements the Beginners' guide.
Contents
Installation
See ZFS#Installation for installing the ZFS packages. If installing Arch Linux onto ZFS from the archiso, it would be easier to use the demz-repo-archiso repository.
Embedding archzfs into archiso
See ZFS article.
Partition the destination drive
Review Beginners' guide#Prepare the storage devices for information on determining the partition table type to use for ZFS. ZFS supports GPT and MBR partition tables.
ZFS manages its own partitions, so only a basic partition table scheme is required. The partition that will contain the ZFS filesystem should be of the type bf00
, or "Solaris Root".
Partition scheme
Here is an example, using MBR, of a basic partition scheme that could be employed for your ZFS root setup:
Part Size Type ---- ---- ------------------------- 1 512M Ext boot partition (8300) 2 XXXG Solaris Root (bf00)
Here is an example using GPT. The BIOS boot partition contains the bootloader.
Part Size Type ---- ---- ------------------------- 1 2M BIOS boot partition (ef02) 1 512M Ext boot partition (8300) 2 XXXG Solaris Root (bf00)
An additional partition may be required depending on your hardware and chosen bootloader. Consult Beginners' guide#Install and configure a bootloader for more info.
Format the destination disk
Format the boot partition as well as any other system partitions. Do not do anything to the Solaris partition nor to the BIOS boot partition. ZFS will manage the first, and your bootloader the second.
Setup the ZFS filesystem
First, make sure the ZFS modules are loaded,
# modprobe zfs
Create the root zpool
# zpool create zroot /dev/disk/by-id/id-to-partition
Create necessary filesystems
If so desired, sub-filesystem mount points such as /home
and /root
can be created with the following commands:
# zfs create zroot/home -o mountpoint=/home # zfs create zroot/root -o mountpoint=/root
Note that if you want to use other datasets for system directories (/var
or /etc
included) your system will not boot unless they are listed in /etc/fstab
! We will address that at the appropriate time in this tutorial.
Swap partition
See ZFS#Swap volume.
Configure the root filesystem
First, set the mount point of the root filesystem:
# zfs set mountpoint=/ zroot
and optionally, any sub-filesystems:
# zfs set mountpoint=/home zroot/home # zfs set mountpoint=/root zroot/root
and if you have separate datasets for system directories (ie /var
or /usr
)
# zfs set mountpoint=legacy zroot/usr # zfs set mountpoint=legacy zroot/var
and put them in /etc/fstab
/etc/fstab
# <file system> <dir> <type> <options> <dump> <pass> zroot/usr /usr zfs defaults,noatime 0 0 zroot/var /var zfs defaults,noatime,acl 0 0
Note that the /var
filesystem requires the Access Control List enabled (acl) that in zfs it is disabled by default. To enable it use zfs set
:
# zfs set xattr=sa zroot/var # zfs set acltype=posixacl zroot/var
The property xattr=sa
is not mandatory, but suggested. Check man zfs
for all details.
Set the bootfs property on the descendant root filesystem so the boot loader knows where to find the operating system.
# zpool set bootfs=zroot zroot
Export the pool,
# zpool export zroot
Finally, re-import the pool,
# zpool import -d /dev/disk/by-id -R /mnt zroot
If there is an error in this step, you can export the pool to redo the command. The ZFS filesystem is now ready to use.
Be sure to bring the zpool.cache file into your new system. This is required later for the ZFS daemon to start.
# cp /etc/zfs/zpool.cache /mnt/etc/zfs/zpool.cache
if you do not have /etc/zfs/zpool.cache, create it:
# zpool set cachefile=/etc/zfs/zpool.cache zroot
Install and configure Arch Linux
Follow the following steps using the Beginners' guide. It will be noted where special consideration must be taken for ZFSonLinux.
- First mount any boot or system partitions using the mount command.
- Install the base system.
- The procedure described in Beginners' guide#Generate an fstab is usually overkill for ZFS. ZFS usually auto mounts its own partitions, so we do not need ZFS partitions in
fstab
file, unless the user made datasets of system directories. To generate thefstab
for filesystems, use:
# genfstab -U -p /mnt | grep boot >> /mnt/etc/fstab
- Edit the
/etc/fstab
:
- When creating the initial ramdisk, first edit
/etc/mkinitcpio.conf
and addzfs
before filesystems. Also, movekeyboard
hook beforezfs
so you can type in console if something goes wrong. You may also remove fsck (if you are not using Ext3 or Ext4). YourHOOKS
line should look something like this:
HOOKS="base udev autodetect modconf block keyboard zfs filesystems"
- Regenerate the initramfs with the command:
# mkinitcpio -p linux
Install and configure the bootloader
For BIOS motherboards
Follow GRUB#BIOS systems to install GRUB onto your disk. grub-mkconfig
does not properly detect the ZFS filesystem, so it is necessary to edit grub.cfg
manually:
/boot/grub/grub.cfg
set timeout=2 set default=0 # (0) Arch Linux menuentry "Arch Linux" { linux /vmlinuz-linux zfs=zroot rw initrd /initramfs-linux.img }
if you did not create a separate /boot participation, kernel and initrd paths have to be in the following format:
/dataset/@/actual/path
Example with Arch installed on the main datasetĀ :
linux /@/boot/vmlinuz-linux zfs=zroot rw initrd /@/boot/initramfs-linux.img
Example with Arch installed on separator dataset zroot/OS/root
linux /OS/root/@/boot/vmlinuz-linux zfs=zroot/OS/root rw initrd /OS/root/@/boot/initramfs-linux.img
For UEFI motherboards
Use EFISTUB
and rEFInd
for the UEFI boot loader. See Beginners' guide#For UEFI motherboards. The kernel parameters in refind_linux.conf
for ZFS should include zfs=bootfs
or zfs=zroot
so the system can boot from ZFS. The root
and rootfstype
parameters are not needed.
Unmount and restart
We are almost done!
# exit # umount /mnt/boot # zfs umount -a # zpool export zroot
Now reboot.
After the first boot
If everything went fine up to this point, your system will boot. Once.
For your system to be able to reboot without issues, you need to enable the zfs.target
to auto mount the pools and set the hostid.
For each pool you want automatically mounted execute:
# zpool set cachefile=/etc/zfs/zpool.cache <pool>
Enable the target with systemd:
# systemctl enable zfs.target
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=0x00bab10c
, 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 do write the hostid file safely you need to use a small C program:
#include <stdio.h> #include <errno.h> #include <unistd.h> int main() { int res; res = sethostid(gethostid()); if (resĀ != 0) { switch (errno) { case EACCES: fprintf(stderr, "Error! No permission to write the" " file used to store the host ID.\n" "Are you root?\n"); break; case EPERM: fprintf(stderr, "Error! The calling process's effective" " user or group ID is not the same as" " its corresponding real ID.\n"); break; default: fprintf(stderr, "Unknown error.\n"); } return 1; } return 0; }
Copy it, save it as writehostid.c
and compile it with gcc -o writehostid writehostid.c
, finally execute it and regenerate the initramfs image:
# ./writehostid # mkinitcpio -p linux
You can now delete the two files writehostid.c
and writehostid
. Your system should work and reboot properly now.