Howto Configure Ubuntu 14.04 to Native ZFS Root Filesystem

Hello everybody, today we are going to setup Ubuntu to a Native ZFS root file  which is an advanced file system and logical volume manager designed to overcome many of the major problems found in previous designs which is designed by Sun Microsystems. The major features of ZFS include its performance with data integrity that includes checksum of the data to provide protection against corruption. ZFS automatically attempts to correct errors when data redundancy is available. ZFS provides support for high storage capacities and efficient data compression with physical pool storage devices that are added to a pool, and storage space is allocated from that shared pool.

Base System Prerequisites

In this setup we will be using ZFS on an installed Ubuntu 14.04 64-Bit environment as base with following specifications and versions.

  • Operating System: Ubuntu 14.04.1 LTS x86_64
  • grub-install (GRUB) 2.02~beta2-9ubuntu1.3
  • spl-dkms 0.6.4-2~utopic
  • zfs-dkms 0.6.4-3~utopic
  • zfs-initramfs 0.6.4-3~utopic
  • Free disk/partition size 10GB
  • Recommended memory used 4 GB
  • Number of Core used 2 GHz

ZFS Installation Setup

We are going to start ZFS installation setup on an already installed Ubuntu 14.04 operating system with 10 GB of free space on it. We need to be login with the root user to perform all these steps.

Adding ZFS Repository

Before we can start using ZFS, we need to install it. Simply add the repository to apt-get with the following command:

root@ubuntu-14:~# apt-add-repository --yes ppa:zfs-native/stable
Add Repo

System Update with ZFS install

Here we need to update the OS with new repository and then we will start its installing with apt-get.

root@ubuntu-14:~#apt-get update
root@ubuntu-14:~#apt-get install debootstrap ubuntu-zfs

The packages installation will take some time while compiling kernel modules.

zfs and debootstrap

zfs-initramfs is required to put the ZFS utilities for managing ZFS file systems in the initramfs booting images.

root@ubuntu-14:~#apt-get install zfs-initramfs
zfs initframefs

ZFS modules check

By using following commands first we will load zfs modules and then check if they exists or not.


Disk Partitioning for ZFS

Our partitions table will be as follow for single vdev pool layout, where sda2 will be used for zfs root.


Creating Root Pool

Now we will create the root pool by using /dev/sda*, As an alternative, you could also create it using /dev/disk/by-id links to create the pool.

root@ubuntu-14:~# mke2fs -m 0 -L /boot/grub -j /dev/sda2
root@ubuntu-14:~# zpool create -o ashift=9 rpool /dev/sda2

We have created the rpool that we can check through zpool list command.

zpool status

Creating root dataset and Base System Install

Here we create the root dataset then export it, and import it again using -d /dev/sda2

root@ubuntu-14:~# zfs create rpool/ROOT
root@ubuntu-14:~# zfs create rpool/ROOT/ubuntu-1
root@ubuntu-14:~# zfs umount -a
root@ubuntu-14:~# zfs set mountpoint=/ rpool/ROOT/ubuntu-1
root@ubuntu-14:~# zpool export rpool
root@ubuntu-14:~# zpool import -d /dev/sda2 -R /mnt rpool

Now mount the boot filesystem for GRUB that we had created in previous step.

root@ubuntu-14:~# mkdir -p /mnt/boot/grub
root@ubuntu-14:~# mount /dev/sda2 /mnt/boot/grub
root@ubuntu-14:~# debootstrap trusty /mnt

The debootstrap command leaves the new system in an unconfigured state that we will do with its minimal configurations in next.


After successful completion of debootstrap we get the message about successful installation of Base system, now after executing following commands we will update the system after generating locales as follow.

root@ubuntu-14:~# cp /etc/hostname /mnt/etc/
root@ubuntu-14:~# cp /etc/hosts /mnt/etc/
root@ubuntu-14:~# mount --bind /dev /mnt/dev
root@ubuntu-14:~# mount --bind /proc /mnt/proc
root@ubuntu-14:~# mount --bind /sys /mnt/sys
root@ubuntu-14:~# chroot /mnt /bin/bash --login
root@ubuntu-14:/# locale-gen en_US.UTF-8

So, we had made with virtual filesystems in the environment that is visible to the new system and installed PPA support in the chroot environment with chroot command.


Installing Ubuntu and Native packages

The ubuntu-minimal package is required to use ZFS on Linux as packaged in the PPA. Let;s Install ZFS in the chroot environment for the new system by executing following commands.

root@ubuntu-14:/# apt-get install ubuntu-minimal software-properties-common
root@ubuntu-14:/# apt-add-repository --yes ppa:zfs-native/stable
root@ubuntu-14:/# apt-add-repository --yes ppa:zfs-native/grub < - See below note on this command
root@ubuntu-14:/# apt-get update
root@ubuntu-14:/# apt-get install --no-install-recommends linux-image-generic linux-headers-generic
image installer
root@ubuntu-14:/# apt-get dist-upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

Generating new grub config

root@ubuntu-14:/# grub-probe /
root@ubuntu-14:~# ls /boot/grub/i386-pc/zfs*
/boot/grub/i386-pc/zfs.mod /boot/grub/i386-pc/zfscrypt.mod /boot/grub/i386-pc/zfsinfo.mod
root@ubuntu-14:~# update-initramfs -c -k all
update-initramfs: Generating /boot/initrd.img-3.13.0-24-generic

Verifying correct root entry

root@ubuntu-14:~# grep "boot=zfs" /boot/grub/grub.cfg
linux /ROOT/ubuntu-1@/boot/vmlinuz-3.13.0-24-generic root=ZFS=rpool/ROOT/ubuntu-1 ro boot=zfs
linux /ROOT/ubuntu-1@/boot/vmlinuz-3.13.0-24-generic root=ZFS=rpool/ROOT/ubuntu-1 ro boot=zfs
root@ubuntu-14:~# grep zfs /etc/default/grub

Update Grub

Update grub to allow auto-generated zfs boot menu with update-grub command.

grub install
root@ubuntu-14:~# update-grub
Generating grub configuration file ...
Warning: Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.
Found linux image: /boot/vmlinuz-3.13.0-24-generic
Found initrd image: /boot/initrd.img-3.13.0-24-generic

Install the boot loader to the MBR with below command and make sure that you get the finished installation message. The readlink is required because recent GRUB releases do not de reference symlinks.

root@ubuntu-14:~# grub-install $(readlink -f /dev/sda)
Installing for i386-pc platform.
Installation finished. No error reported.

Now Exit from the chroot environment back to the base environment and dismount from all filesystems if connected.

ZFS Confirmation

We had done with all of its setup now check with df command for confirmation of rpool.

rpool status

Some Known Issues

During this setup you might face some issues with the ZFS boot up that you can avoid by using following procedures.

Create snapshot

You must create ZFS snapshot that can be used as rescue environment after its first boot. You can use following command to take ZFS Snapshot as.

root@ubuntu-14:~# apt-get clean
root@ubuntu-14:~# zfs snapshot rpool/ROOT/ubuntu1

Grub Issue

Some times Grub doesn't display boot menu, or it shows error "unknown filesystem". This might be because of grub can't read the zfs pool or its possible cause is that you previously offline some vdev. To recover from this we need to do following two things.

  • Remove/disconnect the offline disks
  • Using Live CD method you can boot from your ext4 installation
  • Or do by onlining the disks, or remove the offline disk, and add them again


ZFS Changes the Way Data Is Managed by offering data security and integrity, virtually unlimited scalability, as well as easy and automated manageability. So We can conclude that ZFS is an OS feature that seems to be a very popular choice for some administrators who knows its features rich functionality.

4 Comments... add one

  1. NOTE: these instructions mix up sda1 vs. sda2 (boot vs. root) periodically. Please be aware and thoughtful of what commands are being run on which devices!

  2. Hi,

    I have a native ubuntu installation on my computer, I would like to migrate all my services to zfs file system, I have installed in another computer it works like a charm, now my question is : can I migrate my installation to zfs without reinstall my system and all my apps, I spent a lot time to have a stable installation I dont want ti reinstall all my stuff. thanks in advantage for the answer, I was trying to googleling this question but I could not find any information about that, thanks a lot guys ..


Leave a Comment