User:Fearedbliss/Installing Gentoo Linux On ZFS

Install Gentoo Linux on ZFS
Author: Jonathan Vasquez (fearedbliss) Contact: fearedbliss@gentoo.org

Preface
This guide will show you how to install Gentoo Linux on AMD64 with:

* UEFI/GPT (/boot will be on a FAT32 Unencrypted EFI System Partition) * Everything else on ZFS (/, swap - With all feature flags enabled and lz4 compression) * ZFS 0.6.5.9 * GRUB 2 (Bootloader) * OpenRC * Gentoo Stable (amd64)

Notes on other stuff you can do in the ZFS install can be found here.

Required Tools
Download my modified System Rescue CD that includes ZFS from one of the mirrors on the front page.

Linux
If you have a Linux system, you can create a bootable usb from it by doing the following:

That should open up a screen where you can select your plugged in flash drive.

Windows
You can download "Rufus" and select the ISO by clicking the little image next to the "Create a bootable disk using <>". After that, you can use the default settings and press "Start".

Download Rufus

Assumptions

 * Only installing Gentoo on one drive called /dev/sda.
 * You are using my modified System Rescue CD that includes ZFS
 * Will be using my tools (bliss-kernel, bliss-initramfs).

Also, this guide is the way I install Gentoo, not exactly the way the handbook has it.

Partition
We will now partition the drive and aim to create the following layout:

/dev/sda1  | 2 MB         |   BIOS Boot Partition    | So GRUB 2 can work in GPT /dev/sda2  | 500 MB       |   EFI System Partition   | /boot /dev/sda3  | Rest of Disk |   ZFS Pool               | /, swap, etc

Open up your drive in GNU parted and tell it to use optimal alignment:

Create GPT partition layout
This will delete all partitions and create a new GPT table.

Final View
Exit the application

Create your zpool
Create your zpool which will contain your drives and datasets:

Create your zfs datasets
We will keep it simple and just create a few datasets for /, and /home. ZFS is extremely flexible and you can easily add or remove datasets in the future.

Create your swap zvol
This creates the zfs block device that we will use for swap.

Verify everything looks good
You can verify that all of these things worked by running the following:

Now we are ready to install Gentoo!

Check and set your time
If it's wrong then fix it. Let's say it's August 24, 2014 @ 2:48 PM (will be 14:48 in 24 hour time), we would do the following:

Preparing to chroot
First let's mount our boot partition in our chroot directory:

and now download the amd64 systemd image here and extract it:

Generate locales
I'm using US English w/ UTF-8, so I will enable that locale on my system:

Edit fstab
Everything is on zfs so we don't need anything in here except for the boot and swap zvol entries. My fstab looks as follows:

Modify make.conf
Let's modify our /etc/portage/make.conf so we can start installing stuff with a good base (Change it to what you need):

Configure Portage, get the Portage Tree, and setup bliss-overlay
We will now configure portage, download the Portage Tree, and setup "bliss-overlay" through it. This means that you will be able to receive all bliss-overlay updates through portage.

Since our livecd and chroot don't have git, we will download a github snapshot that contains the .git repository as well. Normally if we download this from github directly, it won't include .git directory, which would require us to re-download all the files again after we compiled git in order to get updates via git. If we do this, we can avoid this second download.

Bootstrap the portage tree

Copy the example portage config so we can modify it

Open repos.conf and switch the following values for the [gentoo] entry to the following and add the other block below it

Compile git

Sync once more to get bliss-overlay

Install required applications
Enable the AMD64 EFI platform for grub

Unmask the latest versions of zfs:

Now install the apps:

Installing the bootloader onto your drive
We will need to install the bootloader onto the drive. Before we do that however, let's see if GRUB can detect our /'s filesystem type:

It should say 'fat'. If it doesn't, then something is wrong and your system will not boot!

Now run the following to install the bootloader to the drive:

The above command should return a "Installation finished. No error reported." message. If it doesn't, then something is wrong and your system will not boot!

Make the GRUB 2 configuration file
You can use the following configuration file as a basis for your system:

Generating new zpool.cache file before/after reboot
ZFS is very sensitive about the data that is contained in the zpool.cache file and at this point, when we reboot, the information in it might not be completely accurate. To ensure we have a good cache file, we have instructed bliss-initramfs in the bootloader config above, to ignore the cachefile, and make a new one that is up-to-date. Once we do that, we can remake our initramfs file so that we have the latest correct information.

After you reboot
Since we are using systemd and the required systemd services weren't running during our install process, we didn't set up the hostname, time, and locales. Let's complete that now.

Fix your date
I'm in New York and I want my network time to be automatically updated using the internet, so I will do the following:

Set locale for systemd
I will be setting the locale to UTF-8 for US English:

Remove zpool.cache refresh flag from bootloader configuration and remake initramfs
Open up your grub.cfg and remove the 'refresh' flag from the kernel line, and then remake your initramfs.

Take a snapshot of your new system
Since we now have a working system, we will snapshot it in case we ever want to go back or recover files:

You can view the contents of these snapshots by checking their respective and hidden .zfs directories:

Bliss ZFS Scripts
The following scripts allow you to automatically:


 * Take snapshots of your pool
 * Replicate the pool to another pool (Full and Incremental Backups)
 * Clean the old snapshots on your pools.

You can download, customize, and install the scripts into your /usr/local/sbin directory. Github.

And that's it. Enjoy!