Difference between revisions of "Installing Arch Linux on ZFS"

From ArchWiki
Jump to: navigation, search
(Install and configure the Arch Linux installation)
(I added a GPT partition example including a BIOS boot partition and the steps to make your system rebootable after installation. I did it because I tried to follow the existing wiki to install ZFS on my system, and it didn't work well.)
(45 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
[[Category:Getting and installing Arch]]
 
[[Category:Getting and installing Arch]]
 
{{Article summary start}}
 
{{Article summary start}}
{{Article summary text|This article describes the necassary procedures for installing Arch Linux onto a ZFS root filesystem.}}
+
{{Article summary text|This article describes the necessary procedures for installing Arch Linux onto a ZFS root filesystem.}}
 
{{Article summary heading|Related}}
 
{{Article summary heading|Related}}
 
{{Article summary wiki|ZFS}}
 
{{Article summary wiki|ZFS}}
Line 7: Line 7:
 
{{Article summary end}}
 
{{Article summary end}}
  
The [[Wikipedia:ZFS|Zettabyte File System (ZFS)]] is an advanced [[Wikipedia:Copy-on-write|copy-on-write]] filesystem designed to preserve data integrity from a multitude of possible corruption scenarios as well as provide simple administration features. ZFS makes disk administration effortless with support ZFS storage pools (zpools) and automatic mount handling. First released in 2005 for Solaris OS, ZFS has since become the flag bearer for next generation filesystems.
+
This article details the steps required to install Arch Linux onto a root ZFS filesystem. This article supplements the [[Beginners' Guide]].
  
ZFS was first developed and released by Sun (now owned by Oracle) as [[Wikipedia:Open source software|Open Source Software]] licensed under the [[Wikipedia:Common Development and Distribution License|Common Development and Distribution License]] (CDDL) which is famously [http://arstechnica.com/information-technology/2010/06/uptake-of-native-linux-zfs-port-hampered-by-license-conflict/ incompatible with the GNU Public License]. This incompatibility prevents ZFS from being merged into the mainline kernel, and generally presents some obstacles for users that want to use ZFS in Linux.
+
==Installing archzfs==
  
[http://zfsonlinux.org/ ZFSonLinux.org] is a project funded by the [https://www.llnl.gov/ Lawrence Livermore National Laboratory] to develop a native Linux kernel module for its massive storage requirements and super computers.
+
Using the archzfs repository is highly recommended for effortless updates.
  
==Notes before installation==
+
{{warning|The ZFS packages are tied to the kernel version they were built against. This means it will not be possible to perform kernel updates until new packages (or package sources) are released by the ZFS package maintainer.}}
  
* This guide uses the unofficial archzfs repository hosted at http://demizerone.com/demz-repo-core. This repository is maintained by Jesus Alvarez and is signed with his PGP key: [http://pgp.mit.edu:11371/pks/lookup?op=vindex&search=0x5E1ABF240EE7A126 0EE7A126].
+
{{note|1=This guide uses the unofficial archzfs repository hosted at http://demizerone.com/demz-repo-core. This repository is maintained by Jesus Alvarez and is signed with his PGP key: [http://pgp.mit.edu:11371/pks/lookup?op=vindex&search=0x5E1ABF240EE7A126 0EE7A126].}}
  
* The ZFS packages are tied to the kernel version they were built against. This means it will not be possible to perform kernel updates until new packages (or package sources) are released by the ZFS package maintainer.
+
===Embedding archzfs into archiso===
 
+
See [[ZFS#Embed_the_archzfs_packages_into_an_archiso]].
==Boot from the installation media==
+
 
+
It is a good idea make an installation media with the needed software included. Otherwise, you will need the latest archiso installation media burned to a CD or a USB key.
+
 
+
To embed {{ic|zfs}} in the archiso, from an existing install, download the {{ic|archiso}} package.
+
# pacman -S archiso
+
 
+
Start the process:
+
# cp -r /usr/share/archiso/configs/releng /root/media
+
 
+
Edit the {{ic|packages.x86_64}} file adding those lines:
+
spl-utils
+
spl
+
zfs-utils
+
zfs
+
 
+
Edit the {{ic|pacman.conf}} file adding those lines (TODO, correctly embed keys in the installation media?):
+
[demz-repo-archiso]
+
SigLevel = Never
+
Server = <nowiki>http://demizerone.com/$repo/$arch</nowiki>
+
 
+
Add other packages in {{ic|packages.both}}, {{ic|packages.i686}}, or {{ic|packages.x86_64}} if needed and create the image.
+
# ./build.sh -v
+
 
+
The image will be in the {{ic|/root/media/out}} directory.
+
 
+
More informations about the process can be read in [http://kroweer.wordpress.com/2011/09/07/creating-a-custom-arch-linux-live-usb/ this guide] or in the [[Archiso]] article.
+
 
+
If you are installing onto a UEFI system, see [[Unified Extensible Firmware Interface#Create UEFI bootable USB from ISO]] for creating UEFI compatible installation media.
+
 
+
==Setup pacman==
+
  
 +
===Using the archzfs repository===
 
Activate the required network connection and then edit {{ic|/etc/pacman.d/mirrorlist}} and configure the mirrors for pacman to use.  Once that is done, edit {{ic|/etc/pacman.conf}} and add the archzfs repository:
 
Activate the required network connection and then edit {{ic|/etc/pacman.d/mirrorlist}} and configure the mirrors for pacman to use.  Once that is done, edit {{ic|/etc/pacman.conf}} and add the archzfs repository:
  
Line 62: Line 32:
 
Next, add the archzfs maintainer's PGP key to the local trust:
 
Next, add the archzfs maintainer's PGP key to the local trust:
  
    # pacman-key -r 0EE7A126
+
{{bc|# pacman-key -r 0EE7A126
    # pacman-key --lsign-key 0EE7A126
+
# pacman-key --lsign-key 0EE7A126}}
  
Finally, update the pacman databases,
+
Finally, update the pacman databases and install archzfs:
  
    # pacman -Syy
+
{{bc|# pacman -Syy}}
  
==Install needed packages==
+
This is also the best time to install your favorite text editor, otherwise nano or vi will have to be used.
  
This is also the best time to install your favorite text editor, otherwise nano will have to be used.
+
{{bc|# pacman -S archzfs dosfstools gptfdisk vim}}
 
+
    # pacman -S archzfs dosfstools gptfdisk vim
+
  
 
==Partition the destination drive==
 
==Partition the destination drive==
  
===UEFI systems===
+
Review [[Beginners'_Guide#Prepare_the_storage_drive]] for information on determining the partition table type to use for ZFS. ZFS supports GPT and MBR partition tables.
  
Use the cgdisk partition utility and create a GPT partition table:
+
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 {{ic|bf00}}, or "Solaris Root".
  
  Part    Size  Type
+
===Partition scheme===
  ====     =====  =============
+
      1    512M  EFI (ef00)
+
      2    512M  Ext4 (8300)
+
      2    XXXG  Solaris Root (bf00)
+
  
{{Note|The EFI partion will be formatted to FAT32 and contain the UEFI boot loader. The Ext4 partition will contain the boot partition and kernel images.}}
+
Here is an example, using MBR, of a basic partition scheme that could be employed for your ZFS root setup:
  
{{Note|The filesystem type codes for cgdisk are indicated in the parenthesis after the filesystem name.}}
+
{{bc|<nowiki>Part    Size  Type
 +
----    ----  -------------------------
 +
  1    512M  Ext boot partition (8300)
 +
  2    XXXG  Solaris Root (bf00)</nowiki>}}
  
{{Warning|The EFI partition must be at least 512MB specified by the UEFI standard.}}
+
Here is an example using GPT. The BIOS boot partition contains the bootloader.
  
===BIOS systems===
+
{{bc|<nowiki>Part    Size  Type
 +
----    ----  -------------------------
 +
  1      2M  BIOS boot partition (ef02)
 +
  1    512M  Ext boot partition (8300)
 +
  2    XXXG  Solaris Root (bf00)</nowiki>}}
  
  Part    Size  Type
+
An additional partition may be required depending on your hardware and chosen bootloader. Consult [[Beginners'_Guide#Install_and_configure_a_bootloader]] for more info.
  ====    =====  =============
+
      2    1007K  BIOS Boot Partition (ef02)
+
      1    512M  Ext4 (8300)
+
      3    XXXG  Solaris Root (bf00)
+
  
{{Note|You will have to create the ext4 partition first due to cgdisk's disk alignment policies. Start it at sector 2048 to leave room for the BIOS parition.}}
+
{{tip|Bootloaders with support for ZFS are described in [[#Install and configure the bootloader]].}}
  
 
==Format the destination disk==
 
==Format the destination disk==
  
===UEFI systems===
+
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.
 
+
Format the EFI partition to FAT32
+
 
+
    mkfs.vfat -F 32 /dev/sda1 -n EFIBOOT
+
 
+
Format the Ext4 boot partition
+
 
+
    mkfs.ext4 /dev/sda2 -L BOOT
+
 
+
===BIOS systems===
+
 
+
Format the Ext4 boot partition
+
   
+
    mkfs.ext4 /dev/sda1 -L BOOT
+
 
+
{{Note|The boot filesystem is {{ic|sda1}} because of the order we created the partitions}}
+
 
+
The BIOS partition does not need a filesystem.
+
  
 
==Setup the ZFS filesystem==
 
==Setup the ZFS filesystem==
Line 129: Line 78:
 
First, make sure the ZFS modules are loaded,
 
First, make sure the ZFS modules are loaded,
  
    # modprobe zfs
+
{{bc|# modprobe zfs}}
  
 
===Create the root zpool===
 
===Create the root zpool===
  
    # zpool create zroot /dev/disk/by-id/<id-to-partition>
+
{{bc|# zpool create zroot /dev/disk/by-id/<id-to-partition>}}
  
 
{{Warning|Always use id names when working with ZFS, otherwise import errors will occur.}}
 
{{Warning|Always use id names when working with ZFS, otherwise import errors will occur.}}
Line 141: Line 90:
 
If so desired, sub-filesystem mount points such as /home and /root can be created with the following commands:
 
If so desired, sub-filesystem mount points such as /home and /root can be created with the following commands:
  
    # zfs create zroot/home
+
{{bc|# zfs create zroot/home
    # zfs create zroot/root
+
# zfs create zroot/root}}
<!-- Taken the following Swap info from https://wiki.archlinux.org/index.php/ZFS -->
+
=== Swap partition ===
+
  
ZFS does not allow to use swapfiles, but you can use a ZFS volume as swap partition. It is importart to set the ZVOL block size to match the system page size, for x86_64 systems that is 4k.
+
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.
  
Create a 8gb zfs volume:
+
<!-- Taken the following Swap info from https://wiki.archlinux.org/index.php/ZFS -->
  
  # zfs create -V 8gb -b 4K <pool>/swap
+
=== Swap partition ===
  
Prepare it as swap partition:
+
ZFS does not allow the use swapfiles, but it is possible to use a ZFS volume as swap partition. It is important to set the ZVOL block size to match the system page size; for x86_64 systems that is 4k.
  
  # mkswap /dev/zvol/<pool>/swap
+
Create a 8gb (or whatever is required) ZFS volume:
  
Enable swap:
+
{{bc|# zfs create -V 8G -b 4K <pool>/swap}}
  
  # swapon /dev/zvol/<pool>/swap
+
Initialize and enable the volume as a swap partition:
  
To make it permament you need to edit your {{ic|/mnt/etc/fstab}} after pacstraping the system:
+
{{bc|# mkswap /dev/zvol/<pool>/swap
 +
# swapon /dev/zvol/<pool>/swap}}
  
Add a line to {{ic|/mnt/etc/fstab}}:
+
After using {{ic|pacstrap}} to install the base system, edit {{ic|/<root>/etc/fstab}} to ensure the swap partition is mounted at boot:
  
  /dev/zvol/<pool>/swap none swap defaults 0 0
+
{{bc|/dev/zvol/<pool>/swap none swap defaults 0 0}}
  
For safety, unmount all zfs filesystems if they are mounted:
+
Make sure to unmount all ZFS filesystems before rebooting the machine, otherwise any ZFS pools will refuse to be imported:
  
    # zfs umount -a
+
{{bc|# zfs umount -a}}
  
 
===Configure the root filesystem===
 
===Configure the root filesystem===
  
Now it is time to set the mount point of the root filesystem:
+
First, set the mount point of the root filesystem:
  
    # zfs set mountpoint=/ zroot
+
{{bc|<nowiki># zfs set mountpoint=/ zroot</nowiki>}}
  
 
and optionally, any sub-filesystems:
 
and optionally, any sub-filesystems:
  
    # zfs set mountpoint=/home zroot/home
+
{{bc|<nowiki># zfs set mountpoint=/home zroot/home
    # zfs set mountpoint=/root zroot/root
+
# zfs set mountpoint=/root zroot/root</nowiki>}}
  
 
Set the bootfs property on the descendant root filesystem so the boot loader knows where to find the operating system.
 
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
+
{{bc|<nowiki># zpool set bootfs=zroot zroot</nowiki>}}
  
 
Export the pool,
 
Export the pool,
  
    # zpool export zroot
+
{{bc|# zpool export zroot}}
  
 
{{Warning|Don't skip this, otherwise you will be required to use -f when importing your pools. This unloads the imported pool.}}
 
{{Warning|Don't skip this, otherwise you will be required to use -f when importing your pools. This unloads the imported pool.}}
 +
{{Note|This might fail if you added a swap partition above. Need to turn it off with the ''swapoff'' command.}}
  
 
Finally, re-import the pool,
 
Finally, re-import the pool,
  
    # zpool import -d /dev/disk/by-id -R /mnt zroot
+
{{bc|# zpool import -d /dev/disk/by-id -R /mnt zroot}}
  
 
{{Note|"-d" is not the actual device id, but the /dev/by-id directory containing the symlinks.}}
 
{{Note|"-d" is not the actual device id, but the /dev/by-id directory containing the symlinks.}}
Line 199: Line 148:
 
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.
 
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.
  
==Mount the boot partitions==
+
==Install and configure Arch Linux==
  
===UEFI systems===
+
Follow the following steps using the [[Beginners' Guide]]. It will be noted where special consideration must be taken for ZFSonLinux.
  
    # mkdir /mnt/boot
+
* First mount any boot or system partitions using the mount command.
    # mount /dev/sda2 /mnt/boot
+
    # mkdir /mnt/boot/efi
+
    # mount /dev/sda1 /mnt/boot/efi
+
  
===BIOS systems===
+
* Install the base system.
  
    # mkdir /mnt/boot
+
* 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 the fstab for filesystems, use: {{bc|<nowiki># genfstab -U -p /mnt | grep boot >> /mnt/etc/fstab</nowiki>}}
    # mount /dev/sda1 /mnt/boot
+
  
==Install and configure the Arch Linux installation==
+
*Edit the /etc/fstab:
  
Install the base packages
+
{{Note|If you chose to create datasets for system directories, Keep them in this fstab!  Comment out the lines for the '/', '/root', and '/home' mountpoints, rather than deleting them.  You may need those UUIDs later if something goes wrong.}} 
 
+
    # pacstrap -i /mnt base base-devel
+
  
    The other packages will be installed in the chrooted environment
+
{{Note|Anyone who just stuck with the guide's directions can delete everything except for the swap file and the boot/EFI partition.  It seems convention to replace the swap's uuid with '/dev/zvol/zroot/swap'}}
Generate the fstab,
+
  
    # genfstab -U -p /mnt | grep boot >> /mnt/etc/fstab
 
  
{{Note|ZFS auto mounts its own partitions, so we do not need ZFS partitions in fstab file.}}
+
* When creating the initial ramdisk, first edit {{ic|/etc/mkinitcpio.conf}} and add {{ic|zfs}} before filesystems. Also, move {{ic|keyboard}} hook before {{ic|zfs}} so you can type in console if something goes wrong. You may also remove fsck (if you are not using Ext3 or Ext4). Your HOOKS line should look something like this:{{bc|<nowiki>HOOKS="base udev autodetect modconf block keyboard zfs filesystems"</nowiki>}}
  
If installing on a UEFI system, you will need to load the efivars kernel module before chrooting into the installation:
+
* Regenerate the initramfs with the command: {{bc|# mkinitcpio -p linux}}
  
    # modprobe efivars
+
==Install and configure the bootloader==
  
Chroot into the installation
+
===For BIOS motherboards===
  
    # arch-chroot /mnt /bin/bash
+
Follow [[Grub2#BIOS_systems_2]] to install grub onto your disk. {{ic|grub-mkconfig}} does not properly detect the ZFS filesystem, so it is necessary to edit {{ic|grub.cfg}} manually:
 
+
Next, follow the [[Beginners' Guide]] from the "Locale" section to the "Configure Pacman Section". Once done, edit {{ic|pacman.conf}}, add the archzfs repository, and update the pacman database,
+
 
+
    # pacman -Syy
+
    # pacman -Su --ignore filesystem,bash
+
    # pacman -S bash
+
    # pacman -Su
+
   
+
    Now lets install the other needed packages.
+
    # pacman -S gnupg vim archzfs
+
 
+
Re-create the initramfs, edit {{ic|/etc/mkinitcpio.conf}} and add {{ic|zfs}} before filesystems. Also, move {{ic|keyboard}} hook before {{ic|zfs}} so you can type in console if something goes wrong. Remove fsck and then regenerate the initramfs:
+
 
+
    # mkinitcpio -p linux
+
 
+
Finally, set root password and add a regular user.
+
 
+
==Setup the bootloader==
+
 
+
===UEFI systems===
+
 
+
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 aren't needed.
+
 
+
===BIOS systems===
+
 
+
Follow the [[Grub2#BIOS_systems_2]] wiki. {{ic|grub-mkconfig}} fails for me, so I edited {{ic|grub.cfg}} manually.
+
  
 
{{hc|/boot/grub/grub.cfg|<nowiki>
 
{{hc|/boot/grub/grub.cfg|<nowiki>
Line 272: Line 187:
 
</nowiki>
 
</nowiki>
 
}}
 
}}
 +
 +
===For UEFI motherboards===
 +
 +
Use {{ic|EFISTUB}} and {{ic|rEFInd}} for the UEFI boot loader. See [[Beginners' Guide#For UEFI motherboards]].  The kernel parameters in {{ic|refind_linux.conf}} for ZFS should include {{ic|1=zfs=bootfs}} or {{ic|1=zfs=zroot}} so the system can boot from ZFS. The 'root' and 'rootfstype' parameters aren't needed.
  
 
==Unmount and restart==
 
==Unmount and restart==
  
This is it, we are done!
+
We're almost done!
  
    # exit
+
{{bc|# exit
    # umount /mnt/boot
+
# umount /mnt/boot
    # zfs umount -a
+
# zfs umount -a
    # zpool export zroot
+
# zpool export zroot
    # reboot
+
# reboot}}
  
 
{{Warning|If you do not properly export the zpool, the pool will refuse to import in the ramdisk environment and you will be stuck at the busybox terminal.}}
 
{{Warning|If you do not properly export the zpool, the pool will refuse to import in the ramdisk environment and you will be stuck at the busybox terminal.}}
  
==Troubleshooting==
+
==Proper zpool exporting on shutdown==
 +
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 properly export the ZFS pool on shutdown. The proper way to do this is:
  
If the new installation does not boot because the zpool cannot be imported, you will need to chroot into the installation and properly export the zpool. See [[ZFS#Emergency chroot repair with archzfs]].
+
{{bc|# systemctl enable zfs.service}}
  
Once inside the chroot environment, load the ZFS module and force import the zpool,
+
The systemd service file installed with archzfs by default does not work properly because it ends up with the system trying to import your zpool and mount the filesystem twice. Here's how it should be.
  
    # zpool import -a -f
+
{{hc|/usr/lib/systemd/system/zfs.service|<nowiki>
 +
[Unit]
 +
Description=Zettabyte File System (ZFS)
 +
Documentation=man:zfs(8) man:zpool(8)
 +
DefaultDependencies=no
 +
After=cryptsetup.target
 +
Before=local-fs.target
 +
Conflicts=shutdown.target umount.target
  
now export the pool:
+
[Service]
 +
Type=oneshot
 +
RemainAfterExit=yes
 +
ExecStart=/sbin/modprobe zfs
  
    # zpool export <pool>
+
#remove or comment out this three lines
 +
#ExecStart=/usr/bin/zpool import -c /etc/zfs/zpool.cache -aN
 +
#ExecStart=/usr/bin/zfs mount -a
 +
#ExecStart=/usr/bin/zfs share -a
  
To see your available pools, use,
+
ExecStop=/usr/bin/zfs umount -a
  
    # zpool status
+
#add this line
 +
ExecStop=/usr/bin/zpool export zroot
  
It is necessary to export a pool because of the way ZFS uses the hostid to track the system the zpool was created on. The hostid is generated partly based on your network setup. During the installation in the archiso your network configuration could be different generating a different hostid than the one contained in your new installation. Once the zfs filesystem is exported and then re-imported in the new installation, the hostid is reset. See [http://osdir.com/ml/zfs-discuss/2011-06/msg00227.html Re: Howto zpool import/export automatically? - msg#00227].
+
[Install]
 
+
WantedBy=local-fs.target
If ZFS complains about "pool may be in use" after every reboot, you should properly export pool as described above, and then rebuild ramdisk in normally booted system:
+
</nowiki>
 +
}}
  
    # mkinitcpio -p linux
+
That's it! Your system should work and reboot properly now.
  
 
==See also==
 
==See also==
Line 311: Line 247:
 
* [https://github.com/dajhorn/pkg-zfs/wiki/HOWTO-install-Ubuntu-to-a-Native-ZFS-Root-Filesystem HOWTO install Ubuntu to a Native ZFS Root]
 
* [https://github.com/dajhorn/pkg-zfs/wiki/HOWTO-install-Ubuntu-to-a-Native-ZFS-Root-Filesystem HOWTO install Ubuntu to a Native ZFS Root]
 
* [http://lildude.co.uk/zfs-cheatsheet ZFS Cheatsheet]
 
* [http://lildude.co.uk/zfs-cheatsheet ZFS Cheatsheet]
 +
* [http://www.funtoo.org/wiki/ZFS_Install_Guide Funtoo ZFS Install Guide]

Revision as of 21:34, 11 September 2013

Template:Article summary start Template:Article summary text Template:Article summary heading Template:Article summary wiki Template:Article summary wiki Template:Article summary end

This article details the steps required to install Arch Linux onto a root ZFS filesystem. This article supplements the Beginners' Guide.

Installing archzfs

Using the archzfs repository is highly recommended for effortless updates.

Warning: The ZFS packages are tied to the kernel version they were built against. This means it will not be possible to perform kernel updates until new packages (or package sources) are released by the ZFS package maintainer.
Note: This guide uses the unofficial archzfs repository hosted at http://demizerone.com/demz-repo-core. This repository is maintained by Jesus Alvarez and is signed with his PGP key: 0EE7A126.

Embedding archzfs into archiso

See ZFS#Embed_the_archzfs_packages_into_an_archiso.

Using the archzfs repository

Activate the required network connection and then edit /etc/pacman.d/mirrorlist and configure the mirrors for pacman to use. Once that is done, edit /etc/pacman.conf and add the archzfs repository:

# nano /etc/pacman.conf
[demz-repo-core]
Server = http://demizerone.com/$repo/$arch
Note: You should change the repo name from 'demz-repo-core' to 'demz-repo-archiso' if you are using the standard Arch ISOs to install (didn't build your own, above)

Next, add the archzfs maintainer's PGP key to the local trust:

# pacman-key -r 0EE7A126
# pacman-key --lsign-key 0EE7A126

Finally, update the pacman databases and install archzfs:

# pacman -Syy

This is also the best time to install your favorite text editor, otherwise nano or vi will have to be used.

# pacman -S archzfs dosfstools gptfdisk vim

Partition the destination drive

Review Beginners'_Guide#Prepare_the_storage_drive 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.

Tip: Bootloaders with support for ZFS are described in #Install and configure the bootloader.

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>
Warning: Always use id names when working with ZFS, otherwise import errors will occur.

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
# zfs create zroot/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

ZFS does not allow the use swapfiles, but it is possible to use a ZFS volume as swap partition. It is important to set the ZVOL block size to match the system page size; for x86_64 systems that is 4k.

Create a 8gb (or whatever is required) ZFS volume:

# zfs create -V 8G -b 4K <pool>/swap

Initialize and enable the volume as a swap partition:

# mkswap /dev/zvol/<pool>/swap
# swapon /dev/zvol/<pool>/swap

After using pacstrap to install the base system, edit /<root>/etc/fstab to ensure the swap partition is mounted at boot:

/dev/zvol/<pool>/swap none swap defaults 0 0

Make sure to unmount all ZFS filesystems before rebooting the machine, otherwise any ZFS pools will refuse to be imported:

# zfs umount -a

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

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
Warning: Don't skip this, otherwise you will be required to use -f when importing your pools. This unloads the imported pool.
Note: This might fail if you added a swap partition above. Need to turn it off with the swapoff command.

Finally, re-import the pool,

# zpool import -d /dev/disk/by-id -R /mnt zroot
Note: "-d" is not the actual device id, but the /dev/by-id directory containing the symlinks.

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.

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 the fstab for filesystems, use:
    # genfstab -U -p /mnt | grep boot >> /mnt/etc/fstab
  • Edit the /etc/fstab:
Note: If you chose to create datasets for system directories, Keep them in this fstab! Comment out the lines for the '/', '/root', and '/home' mountpoints, rather than deleting them. You may need those UUIDs later if something goes wrong.
Note: Anyone who just stuck with the guide's directions can delete everything except for the swap file and the boot/EFI partition. It seems convention to replace the swap's uuid with '/dev/zvol/zroot/swap'


  • When creating the initial ramdisk, first edit /etc/mkinitcpio.conf and add zfs before filesystems. Also, move keyboard hook before zfs so you can type in console if something goes wrong. You may also remove fsck (if you are not using Ext3 or Ext4). Your HOOKS 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 Grub2#BIOS_systems_2 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" {
    set root=(hd0,1)
    linux /vmlinuz-linux zfs=zroot
    initrd /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 aren't needed.

Unmount and restart

We're almost done!

# exit
# umount /mnt/boot
# zfs umount -a
# zpool export zroot
# reboot
Warning: If you do not properly export the zpool, the pool will refuse to import in the ramdisk environment and you will be stuck at the busybox terminal.

Proper zpool exporting on shutdown

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 properly export the ZFS pool on shutdown. The proper way to do this is:

# systemctl enable zfs.service

The systemd service file installed with archzfs by default does not work properly because it ends up with the system trying to import your zpool and mount the filesystem twice. Here's how it should be.

/usr/lib/systemd/system/zfs.service
[Unit]
Description=Zettabyte File System (ZFS)
Documentation=man:zfs(8) man:zpool(8)
DefaultDependencies=no
After=cryptsetup.target
Before=local-fs.target
Conflicts=shutdown.target umount.target

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/sbin/modprobe zfs

#remove or comment out this three lines
#ExecStart=/usr/bin/zpool import -c /etc/zfs/zpool.cache -aN
#ExecStart=/usr/bin/zfs mount -a
#ExecStart=/usr/bin/zfs share -a

ExecStop=/usr/bin/zfs umount -a

#add this line
ExecStop=/usr/bin/zpool export zroot

[Install]
WantedBy=local-fs.target

That's it! Your system should work and reboot properly now.

See also