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:

[email protected]:~# 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.

[email protected]:~#apt-get update
[email protected]:~#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.

[email protected]:~#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.

modprobe

Disk Partitioning for ZFS

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

fdisk

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.

[email protected]:~# mke2fs -m 0 -L /boot/grub -j /dev/sda2
[email protected]:~# zpool create -o ashift=9 rpool /dev/sda2

mkewfs

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

[email protected]:~# zfs create rpool/ROOT
[email protected]:~# zfs create rpool/ROOT/ubuntu-1
[email protected]:~# zfs umount -a
[email protected]:~# zfs set mountpoint=/ rpool/ROOT/ubuntu-1
[email protected]:~# zpool export rpool
[email protected]:~# zpool import -d /dev/sda2 -R /mnt rpool

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

[email protected]:~# mkdir -p /mnt/boot/grub
[email protected]:~# mount /dev/sda2 /mnt/boot/grub
[email protected]:~# debootstrap trusty /mnt

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

Debootstrap

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.

[email protected]:~# cp /etc/hostname /mnt/etc/
[email protected]:~# cp /etc/hosts /mnt/etc/
[email protected]:~# mount --bind /dev /mnt/dev
[email protected]:~# mount --bind /proc /mnt/proc
[email protected]:~# mount --bind /sys /mnt/sys
[email protected]:~# chroot /mnt /bin/bash --login
[email protected]:/# 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.

Locales

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.

[email protected]:/# apt-get install ubuntu-minimal software-properties-common
[email protected]:/# apt-add-repository --yes ppa:zfs-native/stable
[email protected]:/# apt-add-repository --yes ppa:zfs-native/grub < - See below note on this command
[email protected]:/# apt-get update
[email protected]:/# apt-get install --no-install-recommends linux-image-generic linux-headers-generic

image installer

[email protected]:/# 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

[email protected]:/# grub-probe /
zfs

[email protected]:~# ls /boot/grub/i386-pc/zfs*
/boot/grub/i386-pc/zfs.mod /boot/grub/i386-pc/zfscrypt.mod /boot/grub/i386-pc/zfsinfo.mod
[email protected]:~#
[email protected]:~# update-initramfs -c -k all
update-initramfs: Generating /boot/initrd.img-3.13.0-24-generic

Verifying correct root entry

[email protected]:~# grep "boot=zfs" /boot/grub/grub.cfg
linux /ROOT/[email protected]/boot/vmlinuz-3.13.0-24-generic root=ZFS=rpool/ROOT/ubuntu-1 ro boot=zfs
linux /ROOT/[email protected]/boot/vmlinuz-3.13.0-24-generic root=ZFS=rpool/ROOT/ubuntu-1 ro boot=zfs
[email protected]:~# grep zfs /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="boot=zfs"

Update Grub

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

grub install

[email protected]:~# 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
done

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.

[email protected]:~# 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.

[email protected]:~# apt-get clean
[email protected]:~# 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

Conclusion

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.

Kashif Siddique 11:08 am

About Kashif Siddique

Linux Systems and Security Engineer in Information and Communication Technology. Results-driven ICT Professional and Open Source Geek with technical specialties in the area of Open Source Operating systems and Applications.

Author Archive Page

Have anything to say?

Your email address will not be published. Required fields are marked *

All comments are subject to moderation.

4 Comments

  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 ..