User:Fearedbliss/Installing Gentoo Linux On ZFS

Install Gentoo Linux on ZFS

 * Author:** Jonathan Vasquez (fearedbliss) \\
 * Contact:** jvasquez1011@gmail.com

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

* / on ZFS * Separate /boot and swap * GPT (Partition Layout) * Extlinux (Bootloader) * OpenRC (Init) * Gentoo Stable (amd64) * Portage 2.2.18 (So we can use the new repository management) * [|Precompiled Binary Packages]

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 at []

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, bliss-boot).

Also, * This guide is the way I install Gentoo, not exactly the way the handbook has it * I only run Gentoo Stable (with select applications coming from ~amd64).

Optional: Installing over SSH
If you want to be able to copy links easier into your terminal (I use PuTTY on Windows), you could set the password on your laptop, get the ip, and then connect to your laptop over the network and perform most of the install through it. Using screen is optional but convenient.

Wipe Partition Layout
This will delete all partitions and their respective MBR/GPT data structures. No confirmation or prompt will be given.

Create your partitions
Once gdisk is opened, use the following layout:

The "->" means to just press enter and accept the default.


 * /boot Partition**


 * BIOS Boot Partition (only needed in case you want GRUB 2 in the future)**


 * swap Partition**


 * / Partition**

You should have a swap even if it is small. Your system could lock up under high load, especially since ZFS uses your physical RAM for its ARC.

Enable Legacy BIOS Bootable Flag
In order for extlinux to boot your /boot partition, you will need to toggle the legacy BIOS bootable flag since we are using the GPT layout.

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 two datasets, one for your root filesystem, and one for your home. ZFS is extremely flexible and you can easily shrink or extend it in the future.

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:

08 24 1448 2014 (Month, Date, 24 Hour Time, Year). It will be UTC at the moment but we will fix it once we are inside our environment.

Preparing to chroot
[|If you don't have a stage 3 for your architecture already downloaded, then click here.]

Fix your date
I'm in New York so I will do the following:

Edit fstab
I removed the root, floppy, and cdrom lines. Our root is on zfs so we don't need it to be here. Our swap is /dev/sda3, and our boot is /dev/sda1. My fstab looks as follows: /dev/sda1              /boot           ext2            noatime         0 0 /dev/sda3              none            swap            sw              0 0

Modify make.conf
Let's modify our /etc/portage/make.conf so we can start installing stuff with a good base:

Example, change it to what you need:

ACCEPT_LICENSE="*"

CPU_FLAGS_X86="mmx sse sse2" USE="$CPU_FLAGS_X86 -branding"

SYNC="rsync://xyinn.org/portage" GENTOO_SOURCES="http://xyinn.org/gentoo/ http://mirrors.rit.edu/gentoo/" PORTAGE_BINHOST="http://xyinn.org/gentoo/packages"

MAKEOPTS="-j5" EMERGE_DEFAULT_OPTS="--jobs=2 --load-average=2 --with-bdeps=y --quiet-build=y" LINGUAS="en en_US" VIDEO_CARDS="intel" INPUT_DEVICES="evdev synaptics"

Get your portage tree
We will first download the portage tree using the current version of portage that is on the stage3, afterwards, we will migrate to the new portage so that we can use its new repository management features. This allows us to pull the bliss-overlay git repository and integrate it directly into portage so that when we do an 'emerge --sync', our overlay also gets updated along the portage tree.

Install required applications
Let's use ~amd64 syslinux:

Now install the apps:

Consider pinning the kernel version that was installed so that when we do a future kernel upgrade, an emerge --depclean won't delete our kernel files from the /boot directory. If the bliss-kernel ebuild that emerge pulled to install was: bliss-kernel-3.14.26, we would do:


 * emerge --noreplace =bliss-kernel-3.14.26**

Update your system
The "g" option in the first emerge command will attempt to pull as many compatible binary packages from my server. This means you will have to compile from source a lot less packages.

Installing the bootloader onto your drive
We will need to install the bootloader, copy some files so we can get a menu, and also flash the firmware that will allow us to boot from gpt:

Configure bliss-boot
Navigate to the "Kernels & Options" section and modify the default entry that's there to look like the following (or similar depending your situation):

And switch the bootloader to extlinux so that bliss-boot generates that config type:

Generate the bootloader config
Check your extlinux.conf to make sure that it has the correct information!

Generate the initramfs and move the file to its correct location
If all went well, extlinux should now be installed and configured.

Ensuring we have our /boot directory files inside our zfs snapshots
Since our /boot directory is not on zfs, any zfs snapshots we take will not contain the files in this directory (kernel, initramfs, bootloader config, etc). This is pretty important considering one of the reasons we've put our rootfs on zfs is so that in the case of a system failure, we could easily rollback to a good state.

What we can do is use the program 'lsyncd' so that it monitors our /boot directory and whenever a file gets added, removed, changed, it will update another location (/boot2). This /boot2 directory will reside on the zfs pool itself, which means our snapshots will contain this folder.

I've added the openrc script and an example config file (Which happens to be a /boot -> /boot2 example) to my overlay (ebuild was forked from Gentoo's portage tree).

If you check your / directory, you should see that you now have a /boot and /boot2 directory, with /boot2 just mirroring the files that are on /boot.

Take a snapshot of your new system
We will take a snapshot with zfs of the system in this state in case we ever want to rollback to it:

Bliss ZFS Scripts
The following scripts allow you to automatically take snapshots of your pool, automatically replicate the pool to another pool (Full and Incremental Backups), and 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!