Difference between revisions of "ZFS Install Guide"

From Funtoo Linux
Jump to: navigation, search
(removed version=28 since grub-2.0.0-r7 supports 0.6.0_rc14's feature flags.)
(30 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{fancywarning|Guide is currently being restyled.}}
+
== Introduction ==
  
 
This tutorial will show you how to install Funtoo on ZFS (rootfs). This tutorial is meant to be an "overlay" over the [[Funtoo_Linux_Installation|Regular Funtoo Installation]]. Follow the normal installation and only use this guide for steps 2, 3, and 8.
 
This tutorial will show you how to install Funtoo on ZFS (rootfs). This tutorial is meant to be an "overlay" over the [[Funtoo_Linux_Installation|Regular Funtoo Installation]]. Follow the normal installation and only use this guide for steps 2, 3, and 8.
  
 +
=== Introduction to ZFS ===
 +
 +
Since ZFS is a new technology for Linux, it can be helpful to understand some of its benefits, particularly in comparison to BTRFS, another popular next-generation Linux filesystem:
 +
 +
* The current btrfs code in Linus' tree has known data corruption bugs that Chris Mason has yet to fix. The current ZFS code has a solid track record for data integrity.
 +
 +
* On Linux, the ZFS code can be updated independently of the kernel to obtain the latest fixes. btrfs is exclusive to Linux and you need to build the latest kernel sources to get the latest fixes.
 +
 +
* ZFS is supported on multiple platforms. The platforms with the best support are Solaris, FreeBSD and Linux. Other platforms with varying degrees of support are NetBSD, Mac OS X and Windows. btrfs is exclusive to Linux.
 +
 +
* ZFS has the Adaptive Replacement Cache replacement algorithm while btrfs uses the linux kernel's Last Recently Used replacement algorithm. The former often has an overwhelmingly superior hit rate, which means fewer disk accesses.
 +
 +
* ZFS has the ZFS Intent Log and SLOG devices, which accelerates small synchronous write performance.
 +
 +
* ZFS handles internal fragmentation gracefully, such that you can fill it until 100%. Internal fragmentation in btrfs can make btrfs think it is full at 10%. Btrfs has no automatic rebalancing code, so it requires a manual rebalance to correct it.
 +
 +
* ZFS has raidz, which is like RAID 5/6 (or a hypothetical RAID 7 that supports 3 parity disks), except it does not suffer from the RAID write hole issue thanks to its use of CoW and a variable stripe size. btrfs has no equivalent.
 +
 +
* ZFS send/receive implementation supports incremental update when doing backups. btrfs' send/receive implementation requires sending the entire snapshot.
 +
 +
* ZFS supports data deduplication, which is a memory hog and only works well for specialized workloads. btrfs has no equivalent.
 +
 +
* ZFS datasets have a hierarchical namespace while btrfs subvolumes have a flat namespace.
 +
 +
* ZFS has the ability to create virtual block devices called zvols in its namespace. btrfs has no equivalent and must rely on the loop device for this functionality, which is cumbersome.
 +
 +
The only area where btrfs is ahead of ZFS is in the area of small file
 +
efficiency. btrfs supports a feature called block suballocation, which
 +
enables it to store small files far more efficiently than ZFS. It is
 +
possible to use another filesystem (e.g. reiserfs) on top of a ZFS zvol
 +
to obtain similar benefits (with arguably better data integrity) when
 +
dealing with many small files (e.g. the portage tree).
 +
 +
 +
=== Disclaimers ===
 +
 +
{{fancywarning|This guide is a work in progress. Expect some quirks.}}
 
{{fancyimportant|'''Since ZFS was really designed for 64 bit systems, we are only recommending and supporting 64 bit platforms and installations. We will not be supporting 32 bit platforms'''!}}
 
{{fancyimportant|'''Since ZFS was really designed for 64 bit systems, we are only recommending and supporting 64 bit platforms and installations. We will not be supporting 32 bit platforms'''!}}
  
== Setting up your environment ==
+
== Video Tutorial ==
  
 +
As a companion to the install instructions below, a YouTube video ZFS install tutorial is now available:
 +
 +
{{#widget:YouTube|id=MXyBamArues|width=640|height=360}}
 +
 +
== Setting up your environment ==
 
In order for us to install Funtoo on ZFS, you will need an environment that provides the ZFS tools. We will be downloading two things:  
 
In order for us to install Funtoo on ZFS, you will need an environment that provides the ZFS tools. We will be downloading two things:  
  
Line 14: Line 56:
  
 
This is just a file that when combined with System Rescue CD, gives you those tools.
 
This is just a file that when combined with System Rescue CD, gives you those tools.
 
 
<pre>
 
<pre>
Name: SystemRescueCd-x86-3.2.0 (353 MiB)
+
Name: SystemRescueCd-x86-3.3.0 (368 MiB)
Release Date: 2013-01-07md5sum 90528f0c4b861363992fd9cbcc52d00a
+
Release Date: 2013-01-24
 +
md5sum 01c9d3ff99b46771779ea2d3a66a1c7c
 
</pre>
 
</pre>
  
[https://sourceforge.net/projects/systemrescuecd/files/sysresccd-x86/3.2.0/systemrescuecd-x86-3.2.0.iso/download Download System Rescue CD 3.2.0]<br />
 
[http://jonathanvasquez.com/files/sysresccd/ Download the ZFS System Rescue Module]
 
  
 +
Funtoo now has mirrored copies of System Rescue CD and the ZFS SRM at the links below.
 +
 +
[http://ftp.osuosl.org/pub/funtoo/distfiles/sysrescuecd/systemrescuecd-x86-3.3.0.iso Download System Rescue CD 3.3.0]<br />
 +
[http://ftp.osuosl.org/pub/funtoo/distfiles/sysrescuecd/zfs-3.4.27-std330-amd64.tar.bz2 Download the ZFS System Rescue Module]
  
 
[[Creating_System_Rescue_CD_Modules|Follow the instructions here to download and place the srm into your flash drive]].
 
[[Creating_System_Rescue_CD_Modules|Follow the instructions here to download and place the srm into your flash drive]].
 
  
 
== Creating partitions ==
 
== Creating partitions ==
 
 
 
There are two ways to partition your disk: You can use your entire drive and let ZFS automatically partition it for you, or you can do it manually.
 
There are two ways to partition your disk: You can use your entire drive and let ZFS automatically partition it for you, or you can do it manually.
 
  
 
Using your entire disk drive is recommended since ZFS turns on/off a few settings. For one, if you use your whole-disk, ZFS will set the I/O elevator for the drive automatically. On Solaris machines, ZFS also enables the disk's write cache.
 
Using your entire disk drive is recommended since ZFS turns on/off a few settings. For one, if you use your whole-disk, ZFS will set the I/O elevator for the drive automatically. On Solaris machines, ZFS also enables the disk's write cache.
  
 
+
If you partition it manually, you should set your I/O scheduler to no-op so it doesn't conflict with the ZFS scheduler. Partitioning manually also gives you the advantage of putting your /boot outside the ZFS pool so that you can use a bootloader that doesn't support booting from ZFS.
If you partition it manually, you should set your I/O scheduler to no-op so it doesn't conflict with the ZFS scheduler. Partitioning manually also gives you the advantage of putting your /boot outside the ZFS pool so that you can use a bootloader that doesn't support booting from ZFS.  
+
 
+
 
+
 
=== Whole Disk ===
 
=== Whole Disk ===
 
 
 
This is the easiest method and the recommended method. <br />
 
This is the easiest method and the recommended method. <br />
 
First lets make sure that the disk is completely wiped from any previous disk labels and partitions.
 
First lets make sure that the disk is completely wiped from any previous disk labels and partitions.
We will also assume that <tt>/dev/sda</tt> is the target drive.
+
We will also assume that <tt>/dev/sda</tt> is the target drive.<br />
 
+
 
+
 
<console>
 
<console>
 
# ##i##gdisk /dev/sda
 
# ##i##gdisk /dev/sda
 +
 
Command: ##i##x ↵
 
Command: ##i##x ↵
 
Expert command: ##i##z ↵
 
Expert command: ##i##z ↵
Line 55: Line 89:
 
Blank out MBR?: ##i##y ↵
 
Blank out MBR?: ##i##y ↵
 
</console>
 
</console>
 +
{{fancywarning|This is a destructive operation. Make sure you really don't want anything on this disk.}}
 +
Now that we have a clean drive, we will create the new pool in it while letting zfs automatically partition it.
  
 +
Create the pool as normal:
 +
<console>
 +
# ##i##zpool create -f -o ashift=12 -o cachefile= -O compression=on -m none -R /mnt/funtoo rpool /dev/sda
 +
</console>
 +
Doing this will let ZFS create a GPT style disk with two partitions. We will also slightly modify this to add a BIOS Boot Partition so that grub can be installed successfully. First lets export the pool so that the kernel can use the new partition table without rebooting.
 +
<console>
 +
# ##i##zpool export rpool
 +
</console>
  
{{fancywarning|This is a destructive operation. Make sure you really don't want anything on this disk.}}
+
 
 +
And now lets create a new BIOS Boot Partition at partition 2 from sectors '''48''' to '''2047''':
 +
<console>
 +
# ##i##gdisk /dev/sda
 +
 
 +
Command (? for help): ##i##p ↵
 +
 
 +
Number  Start (sector)    End (sector)  Size      Code  Name 
 +
1            2048        16758783  8.0 GiB    BF01  zfs 
 +
9        16758784        16775167  8.0 MiB    BF07
 +
 
 +
Command: ##i##n ↵
 +
Partition number: ##i##2 ↵
 +
First sector: ##i##48 ↵
 +
Last sector: ##i##2047 ↵
 +
Hex code or GUID: ##i##EF02 ↵
 +
 
 +
Command: ##i##w ↵
 +
Do you want to proceed? (Y/N): ##i##y
 +
OK; writing new GUID partition table (GPT) to /dev/sda.
 +
The operation has completed successfully.
 +
</console>
 +
 
 +
If you were to check <tt>/dev/sda</tt> again, you would see these 3 partitions:
 +
<console>
 +
Number  Start (sector)    End (sector)  Size      Code  Name 
 +
1            2048        16758783  8.0 GiB    BF01  zfs 
 +
2              48            2047  1000.0 KiB  EF02  BIOS boot partition 
 +
9        16758784        16775167  8.0 MiB    BF07
 +
</console>
 +
 
 +
Let's import the pool again:
 +
<console>
 +
# ##i##zpool import -f -o cachefile= -R /mnt/funtoo rpool
 +
</console>
 +
 
 +
 
 +
[[ZFS_Install_Guide#Create_the_zfs_datasets|Now continue with creating your datasets.]]
 +
=== Manual partitioning ===
 +
==== fdisk (MBR Style) ====
 +
'''Create Partition 1''' (boot):
 +
<console>
 +
Command: ##i##n ↵
 +
Partition type: ##i##↵
 +
Partition number: ##i##↵
 +
First sector: ##i##↵
 +
Last sector: ##i##+250M ↵
 +
</console>
 +
 
 +
'''Create Partition 2''' (ZFS):
 +
<console>
 +
Command: ##i##n ↵
 +
Partition type: ##i##↵
 +
Partition number: ##i##↵
 +
First sector: ##i##↵
 +
Last sector: ##i##↵
 +
 
 +
Command: ##i##t ↵
 +
Partition number: ##i##2 ↵
 +
Hex code: ##i##bf ↵
 +
 
 +
Command: ##i##p ↵
 +
 
 +
Device Boot      Start        End      Blocks  Id  System
 +
/dev/sda1            2048      514047      256000  83  Linux
 +
/dev/sda2          514048  1953525167  976505560  bf  Solaris
 +
</console>
 +
 
 +
 
 +
==== gdisk (GPT Style) ====
 +
'''Create Partition 1''' (boot):
 +
<console>
 +
Command: ##i##n ↵
 +
Partition Number: ##i##↵
 +
First sector: ##i##↵
 +
Last sector: ##i##+250M ↵
 +
Hex Code: ##i##↵
 +
</console>
 +
 
 +
'''Create Partition 2''' (BIOS Boot Partition):
 +
<console>Command: ##i##n ↵
 +
Partition Number: ##i##↵
 +
First sector: ##i##↵
 +
Last sector: ##i##+32M ↵
 +
Hex Code: ##i##EF02 ↵
 +
</console>
 +
{{fancyimportant|Only make the above BIOS Boot Partition if you are using GRUB 2 on GPT. If you are using the extlinux bootloader, this partition is not necessary.}}
 +
 
 +
'''Create Partition 2''' (ZFS):
 +
<console>Command: ##i##n ↵
 +
Partition Number: ##i##↵
 +
First sector: ##i##↵
 +
Last sector: ##i##↵
 +
Hex Code: ##i##bf01 ↵
 +
 
 +
Command: ##i##p ↵
 +
 
 +
Number  Start (sector)    End (sector)  Size      Code  Name 
 +
1            2048          514047  250.0 MiB  8300  Linux filesystem 
 +
2          514048      1953525134  931.3 GiB  BF01  Solaris /usr & Mac ZFS
 +
 
 +
Command: ##i##w ↵
 +
</console>
 +
 
 +
 
 +
=== Format your boot volume ===
 +
If you did manual partitioning, format your separate boot partition:
 +
<console># ##i##mkfs.ext4 /dev/sda1</console>
 +
 
 +
 
 +
=== Create the zpool ===
 +
We will first create the pool. The pool will be named `rpool` and the disk will be aligned to 4096 (using ashift=12)
 +
 
 +
<console># ##i##zpool create -f -o ashift=12 -o cachefile= -O compression=on -m none -R /mnt/funtoo rpool /dev/sda2</console>
 +
{{fancyimportant|If you followed the manual GPT partitioning instructions, you should change /dev/sda2 to /dev/sda3.}}{{fancynote|If you have a previous pool that you would like to import, you can do a: '''zpool import -f -R /mnt/funtoo <pool_name>'''}}
 +
 
 +
=== Create the zfs datasets ===
 +
We will now create some datasets. For this installation, we will create a small but future proof amount of datasets. We will have a dataset for the OS (/), and your swap. We will also show you how to create some optional datasets: /home, /var, /usr/src, and /usr/portage.
 +
 
 +
<console>
 +
Create some empty containers for organization purposes, and make the dataset that will hold /
 +
# ##i##zfs create -o mountpoint=none rpool/ROOT
 +
# ##i##zfs create -o mountpoint=/ rpool/ROOT/funtoo
 +
 
 +
Optional, but recommended datasets: /home, /root
 +
# ##i##zfs create -o mountpoint=/home rpool/HOME
 +
# ##i##zfs create -o mountpoint=/root rpool/HOME/root
 +
 
 +
Optional datasets: /usr/src, /var
 +
# ##i##zfs create -o mountpoint=none rpool/FUNTOO
 +
# ##i##zfs create -o mountpoint=/usr/src rpool/FUNTOO/src
 +
# ##i##zfs create -o mountpoint=/var rpool/FUNTOO/var
 +
</console>
 +
 
 +
 
 +
==== Creating a separate portage dataset (optional) ====
 +
Creating a separate portage dataset could be useful if you would like to keep your portage tree, distfiles (source code files), and packages (your compiled binaries if you have FEATURES="buildpkg" enabled) in a safe place (or if you want to back up this directory up easily). This requires a few extra steps because we can't just do a regular emerge --sync when we initially chroot. We will need to download a portage snapshot tarball and extract it into the directory. The required steps for getting and extracting the snapshot will be shown later on in the guide once you chroot into the environment.
 +
 
 +
For now just create the datasets:
 +
<console>
 +
# ##i##zfs create -o mountpoint=/usr/portage -o compression=off rpool/FUNTOO/portage
 +
# ##i##zfs create -o mountpoint=/usr/portage/distfiles -o compression=off rpool/FUNTOO/distfiles
 +
</console>
 +
 
 +
 
 +
=== Create your swap zvol ===
 +
'''Make your swap +1G greater than your RAM. An 8G machine would have 9G of RAM (This is kinda big though).'''
 +
<console>
 +
# ##i##zfs create -o sync=always -o primarycache=metadata -o secondarycache=none -V 9G rpool/swap
 +
</console>
 +
 
 +
 
 +
=== Format your swap zvol ===
 +
<console>
 +
# ##i##mkswap -f /dev/zvol/rpool/swap
 +
# ##i##swapon /dev/zvol/rpool/swap
 +
</console>
 +
 
 +
 
 +
=== Last minute checks and touches ===
 +
Check to make sure everything appears fine:
 +
<console>
 +
# ##i##zpool status
 +
# ##i##zfs list
 +
</console>
 +
 
 +
Copy the '''zpool.cache''' file to your new environment.
 +
<console>
 +
# ##i##mkdir -p /mnt/funtoo/etc/zfs
 +
# ##i##cp /etc/zfs/zpool.cache /mnt/funtoo/etc/zfs
 +
</console>
 +
 
 +
Make an empty mtab file
 +
<console># ##i##touch /mnt/funtoo/etc/mtab</console>
 +
 
 +
Now we will continue to install funtoo.
 +
== Installing Funtoo ==
 +
[[Funtoo_Linux_Installation|Download and install the Funtoo stage3 and continue installation as normal.]]
 +
 
 +
Then chroot into your new funtoo environment:
 +
<console>
 +
# ##i##cd /mnt/funtoo
 +
 
 +
Mount your boot drive ** You don't need to do this if you're using whole-disk zfs **
 +
# ##i##mount /dev/sda1 /mnt/funtoo/boot
 +
 
 +
Bind the kernel related directories
 +
# ##i##mount --rbind /proc proc
 +
# ##i##mount --rbind /dev dev
 +
# ##i##mount --rbind /sys sys
 +
 
 +
Copy network settings
 +
# ##i##cp /etc/resolv.conf etc/chroot into your new funtoo environment
 +
# ##i##env -i HOME=/root TERM=$TERM chroot . /bin/bash -l
 +
</console>
 +
 
 +
=== Syncing your portage tree ===
 +
==== If you didn't create a separate portage dataset, then just sync your portage tree as normal. ====
 +
<console># ##i##emerge --sync</console>
 +
 
 +
==== If you did create a separate portage dataset, let's now get the portage snapshot set up. ====
 +
<console>
 +
Change into your /usr directory
 +
# ##i##cd /usr
 +
 
 +
Download and extract the portage snapshot
 +
# ##i##wget http://ftp.osuosl.org/pub/funtoo/funtoo-current/snapshots/portage-latest.tar.xz
 +
# ##i##tar xf portage-latest.tar.xz
 +
 
 +
Change into your portage directory and checkout the funtoo branch
 +
# ##i##cd portage
 +
# ##i##git checkout funtoo.org
 +
 
 +
Now sync your portage tree
 +
# ##i##emerge --sync
 +
</console>
 +
 
 +
== Kernel Configuration ==
 +
{{fancynote|The below configurations are the requirements for "Bliss Initramfs Creator". Some of these might not be needed for genkernel.}}
 +
 
 +
Tested with kernel 2.6.32, 3.2.34, 3.6.X, 3.7.X.
 +
 
 +
When you get up to the kernel, make sure that you disable the CFQ scheduler, and turn on No-op (It's the default one once you disable all schedulers). The reason for this is because ZFS has its own scheduler and the CFQ one conflicts with it. Go to your kernel config, and make sure you have the following: (there should be a /usr/src/linux symlink as well)
 +
 
 +
<pre>ZLIB_INFLATE/DEFLATE must be compiled into the kernel (not as a module).
 +
> ZLIB_INFLATE [=y], ZLIB_DEFLATE [=y]
 +
 
 +
General setup --->
 +
> [*] Initial RAM filesystem and RAM disk (initramfs/initrd) support
 +
> () Initramfs source file(s)
 +
 
 +
[*] Enable loadable module support --->
 +
[*] Module unloading
 +
 
 +
Device Drivers --->
 +
> Generic Driver Options --->
 +
>> [*] Maintain a devtmpfs filesystem to mount at /dev
 +
 
 +
Cryptographic API --->
 +
<*> Deflate compression algorithm
 +
<*> Zlib compression algorithm
 +
 
 +
* All other drivers required to see your PATA/SATA drives must be compiled in.</pre>
 +
 
 +
Continue and compile/install your kernel:
 +
<console>
 +
# ##i##make bzImage modules
 +
# ##i##make install
 +
# ##i##make modules_install
 +
</console>
 +
 
 +
== Installing the ZFS userspace tools ==
 +
 
 +
<console># ##i##emerge -av zfs</console>
 +
 
 +
Check to make sure that the zfs tools are working, the zpool.cache file that you copied before should be displayed.<console>
 +
# ##i##zpool status
 +
# ##i##zfs list
 +
</console>
 +
 
 +
If everything worked, continue.
 +
 
 +
== Install the bootloader ==
 +
 
 +
=== GRUB 2 ===
 +
If you are using whole-disk zfs then you will need grub2 because grub2 is the only bootloader that supports booting from a zfs pool.
 +
 
 +
Before you do this, make sure this checklist is followed:
 +
* Installed kernel and kernel modules
 +
* Installed zfs package from the tree
 +
* /dev, /proc, /sys are mounted in the chroot environment
 +
 
 +
Once all this is checked, let's install grub2. First we need to enable the "libzfs" use flag so zfs support is compiled for grub2.
 +
 
 +
<console># ##i##echo "sys-boot/grub libzfs" >> /etc/portage/package.use</console>
 +
 
 +
Then we will compile grub2:
 +
{{fancyimportant|GRUB should be _at least_ version 2.0.0 since 2.0.0 added zfs support. 1.99,.98 will not work.}}
 +
<console># ##i##emerge -av grub</console>
 +
 
 +
Once this is done, you can check that grub is version 2.00 by doing the following command:
 +
<console>
 +
# ##i##grub-install --version
 +
grub-install (GRUB) 2.00
 +
</console>
 +
 
 +
Now try to install grub2:
 +
<console># ##i##grub-install --no-floppy /dev/sda</console>
 +
 
 +
You should receive the following message
 +
<console>Installation finished. No error reported.</console>
 +
 
 +
If not, then go back to the above checklist.
 +
=== Extlinux ===
 +
There are four things we need to do for extlinux:
 +
 
 +
# Install extlinux bootloader
 +
# Write the .bin to the front of the target disk
 +
# Toggle BIOS partition flag
 +
# Write a extlinux configuration file
 +
 
 +
First emerge extlinux:
 +
<console># ##i##emerge -av syslinux</console>
 +
 
 +
Then create a /boot/extlinux directory:
 +
<console>
 +
# ##i##cd /boot
 +
# ##i##mkdir /boot/extlinux
 +
</console>
 +
 
 +
Change into the extlinux dir and install the bootloader:
 +
<console>
 +
# ##i##cd /boot/extlinux
 +
# ##i##extlinux --install .
 +
</console>
 +
 
 +
==== MBR ====
 +
<console>
 +
# ##i##fdisk /dev/sda
 +
 
 +
Command: ##i##a ↵
 +
Partition number: ##i##1 ↵
 +
Command: ##i##w ↵
 +
</console>
 +
 
 +
Printing the <tt>fdisk</tt> partition layout should show a star next to <tt>/dev/sda1</tt>:
 +
<console>/dev/sda  *    2048    514047    256000    83    Linux</console>
 +
 
 +
Flash the .bin to the front of the disk:
 +
<console># ##i##dd conv=notrunc bs=440 count=1 if=/usr/share/syslinux/mbr.bin of=/dev/sda</console>
 +
 
 +
=== GPT ===
 +
<console># ##i##sgdisk /dev/sda --attributes=1:set:2</console>
 +
 
 +
Flash the .bin to the front of the disk:
 +
<console># ##i##dd conv=notrunc bs=440 count=1 if=/usr/share/syslinux/gptmbr.bin of=/dev/sda</console>
 +
 
 +
We will write the extlinux/grub configuration file in the next section.
 +
== Create the initramfs ==
 +
There are two ways to do this, you can use genkernel, or you can use my bliss initramfs creator. I will show you both.
 +
 
 +
=== genkernel ===
 +
<console>
 +
# ##i##emerge -av sys-kernel/genkernel
 +
# ##i##genkernel --zfs initramfs
 +
</console>
 +
 
 +
 
 +
<pre>
 +
Example: kernel name is: vmlinuz-3.7.3-ALL
 +
initramfs name is: initramfs-genkernel-x86_64-3.7.3-ALL
 +
pool name is: rpool
 +
</pre>
 +
 
 +
'''grub.cfg''':
 +
<console>
 +
set timeout=3
 +
set default=0
 +
 
 +
# Funtoo
 +
menuentry "Funtoo - 3.7.3" { 
 +
  insmod zfs 
 +
  linux /ROOT/funtoo/@/boot/vmlinuz-3.7.3-ALL root=rpool/ROOT/funtoo real_root=ZFS=rpool/ROOT/funtoo dozfs=force
 +
  initrd /ROOT/funtoo/@/boot/initramfs-genkernel-x86_64-3.7.3-ALL
 +
}
 +
</console>
 +
 
 +
'''extlinux.conf''':
 +
<console>
 +
LABEL funtoo
 +
  MENU LABEL Funtoo 3.7.3-ALL
 +
  KERNEL /boot/vmlinuz-3.7.3-ALL
 +
  INITRD /boot/initramfs-genkernel-x86_64-3.7.3-ALL
 +
  APPEND real_root=ZFS=rpool/ROOT/funtoo dozfs=force
 +
</console>
 +
 
 +
=== Bliss Initramfs Creator ===
 +
Clone my creator which is located at: git://github.com/fearedbliss/Bliss-Initramfs-Creator.git
 +
 
 +
<console># ##i##git clone git://github.com/fearedbliss/Bliss-Initramfs-Creator.git</console>
 +
 
 +
Then go into this new directory, run the script as root, and place it into /boot:
 +
<console># ##i##cd Bliss-Initramfs-Creator
 +
# ##i##./createInit
 +
# ##i##mv initrd-<kernel_name>.img /boot
 +
</console>
 +
 
 +
'''<kernel_name>''' is the name of what you selected in the initramfs creator, and the name of the outputted file. Once you do this just go to your bootloader config, and add it in there.
 +
 
 +
<pre>
 +
Example: Kernel name is: vmlinuz-3.7.3-ALL
 +
initramfs name is: initrd-3.7.3-ALL.img
 +
Pool root is: rpool/ROOT/funtoo
 +
</pre>
 +
 
 +
'''grub.cfg''':
 +
<console>
 +
set timeout=3
 +
set default=0
 +
 
 +
# Funtoo
 +
menuentry "Funtoo - 3.7.3" { 
 +
  insmod zfs
 +
  linux /ROOT/funtoo/@/boot/vmlinuz-3.7.3-ALL root=rpool/ROOT/funtoo quiet
 +
  initrd /ROOT/funtoo/@/boot/initrd-3.7.3-ALL.img
 +
}
 +
</console>
 +
 
 +
'''extlinux.conf:'''
 +
<console>
 +
LABEL funtoo 
 +
  MENU LABEL Funtoo 3.7.3-ALL 
 +
  KERNEL /boot/vmlinuz-3.7.3-ALL 
 +
  INITRD /boot/initrd-3.7.3-ALL.img 
 +
  APPEND root=rpool/ROOT/funtoo
 +
</console>
 +
 
 +
== Final configuration ==
 +
=== Add the zfs tools to openrc ===
 +
<console># ##i##rc-update add zfs boot</console>
 +
 
 +
=== Add filesystems to /etc/fstab ===
 +
<console>
 +
# ##i##nano /etc/fstab
 +
 
 +
# <fs>                  <mountpoint>    <type>          <opts>          <dump/pass>
 +
# Do not add the /boot line below if you are using whole-disk zfs
 +
/dev/sda1              /boot          ext4            defaults        1 2
 +
/dev/zvol/rpool/swap    none            swap            sw              0 0
 +
</console>
 +
 
 +
=== Clean up and reboot ===
 +
We are almost done, we are just going to clean up, '''set our root password''', and unmount whatever we mounted and get out.
 +
 
 +
<console>
 +
Delete the stage3/portage tarballs you downloaded earlier so they don't take up space.
 +
# ##i##cd /
 +
# ##i##rm stage3-latest.tar.xz
 +
# ##i##rm /usr/portage-latest.tar.xz
 +
 
 +
Set your root password
 +
# ##i##passwd
 +
>> Enter your password, you won't see what you are writing (for security reasons), but it is there!
 +
 
 +
Get out of the chroot environment
 +
# ##i##exit
 +
 
 +
Unmount all the kernel filesystem stuff and boot (if you have a separate /boot)
 +
# ##i##cd /mnt/funtoo
 +
# ##i##umount -l proc dev sys boot
 +
 
 +
Turn off the swap
 +
# ##i##swapoff /dev/zvol/rpool/swap
 +
 
 +
Export the zpool
 +
# ##i##cd /
 +
# ##i##zpool export -f rpool
 +
 
 +
Reboot
 +
# ##i##reboot
 +
</console>
 +
 
 +
{{fancyimportant|'''Don't forget to set your root password as stated above before exiting chroot and rebooting. If you don't set the root password, you won't be able to log into your new system.'''}}
 +
 
 +
and that should be enough to get your system to boot on ZFS.
 +
 
 +
== Extra: After reboot ==
 +
After you restart your machine and your inside your desktop, continue to set up anything you need in terms of /etc configurations. Once you have everything the way you like it, take a snapshot of your system. You will be using this snapshot to revert back to this state if anything ever happens to your system down the road. The snapshots are cheap, and almost instant.
 +
 
 +
To take the snapshot of your rootfs, type the following:
 +
<console># ##i##zfs snapshot rpool/ROOT/funtoo@install</console>
 +
 
 +
To see if your snapshot was taken, type:
 +
<console># ##i##zfs list -t snapshot</console>
 +
 
 +
If your machine ever fails and you need to get back to this state, just type:
 +
<console># ##i##zfs rollback rpool/ROOT/funtoo@install</console>
 +
 
 +
=== Recovery Environment ===
 +
On ZFS it is extremely easy to create a recovery environment using an already working snapshot. So that's what we will be doing. Create a clone of the @install snapshot which you will use for recovery purposes. If something happens to your main install, you can boot into this clone and fix the main one. One of the differences (maybe the only difference) between a clone and a snapshot is that a clone is rewritable while a snapshot is only read-only.
 +
 
 +
<console># ##i##zfs clone rpool/ROOT/funtoo@install rpool/ROOT/recovery</console>
 +
 
 +
==== Add the clone to your grub.cfg ====
 +
 
 +
<console>
 +
set timeout=3
 +
set default=0
 +
 
 +
# Funtoo Recovery
 +
menuentry "Funtoo Recovery - 3.7.3" { 
 +
  insmod zfs
 +
  linux /ROOT/funtoo/@/boot/vmlinuz-3.7.3-ALL root=rpool/ROOT/recovery quiet
 +
  initrd /ROOT/funtoo/@/boot/initrd-3.7.3-ALL.img
 +
}
 +
</console>
 +
 
 +
==== Add the clone to your extlinux.conf ====
 +
<console>
 +
LABEL funtoo-recovery   
 +
  MENU LABEL Funtoo Recovery   
 +
  KERNEL /boot/vmlinuz-3.7.3-ALL   
 +
  INITRD /boot/initrd-3.7.3-ALL.img   
 +
  APPEND root=rpool/ROOT/recovery
 +
</console>
 +
 
 +
==== Things to watch out for ====
 +
Since your recovery clone will tend to get old as you use your main system, and since your recovery and other stuff are on the same pool, we don't want the new pool stuff to be mounted when we launch recovery. We also don't want video drivers to be conflicting.
 +
# Make sure that nvidia/nouveau stuff are blacklisted.
 +
# Make sure that your /boot and /lib/modules for the kernel in your 'recovery' are matching.
 +
# Disable the zfs openrc script so that nothing else gets automatically mounted. Only your rootfs.
 +
 
 +
You can do the above stuff by mounting your copy and chrooting into it.
 +
 
 +
<console>
 +
Mount the recovery clone
 +
# ##i##mkdir /mnt/recovery
 +
# ##i##mount -t zfs -o zfsutil rpool/ROOT/recovery /mnt/recovery
 +
# ##i##cd /mnt/recovery
 +
 
 +
Mount the kernel devices
 +
# ##i##mount --rbind /proc ./proc
 +
# ##i##mount --rbind /dev ./dev
 +
# ##i##mount --rbind /sys ./sys
 +
 
 +
Copy zpool.cache
 +
# ##i##cp /etc/zfs/zpool.cache etc/zfs
 +
 
 +
Chroot into the new environment
 +
# ##i##env -i HOME=/root TERM=$TERM chroot . bash --login
 +
 
 +
Disable zfs/zfs-shutdown openrc scripts
 +
# ##i##rc-config delete zfs boot
 +
 
 +
Blacklist nouveau/nvidia drivers
 +
# ##i##echo "blacklist nouveau" >> /etc/modprobe.d/blacklist.conf
 +
# ##i##echo "blacklist nvidia" >> /etc/modprobe.d/blacklist.conf
 +
</console>
 +
 
 +
Once you are done doing your changes, just umount and exit the chroot:
 +
 
 +
<console>
 +
# ##i##cd /
 +
# ##i##umount -l proc dev sys
 +
# ##i##exit
 +
</console>
 +
 
 +
==== Getting into the recovery ====
 +
Just start your machine and pick the '''Funtoo Recovery''' option from the Boot Menu.
 +
 
 +
Enjoy your new install on ZFS :)
 +
 
 +
[[Category:HOWTO]]
 +
[[Category:Filesystems]]
 +
[[Category:Featured]]
  
  
Now that we have a clean drive, we will create the new pool in it while letting zfs automatically partition it.Create the pool as normal<console># ##i##zpool create -f -o ashift=12 -o cachefile= -O compression=on -m none -R /mnt/funtoo rpool /dev/sda</console>Doing this will let ZFS create a GPT style disk with two partitions. We will also slightly modify this to add a BIOS Boot Partition so that grub can be installed successfully. First lets export the pool so that the kernel can use the new partition table without rebooting.<console># ##i##zpool export rpool</console>And now lets create a new BIOS Boot Partition at partition 2 from sectors '''48''' to '''2047''':<console># ##i##gdisk /dev/sdaGPT fdisk (gdisk) version 0.8.5Partition table scan:  MBR: protective  BSD: not present  APM: not present  GPT: presentFound valid GPT with protective MBR; using GPT.Command (? for help): ##i##p ↵Disk /dev/sda: 16777216 sectors, 8.0 GiBLogical sector size: 512 bytesDisk identifier (GUID): 09DA0F98-A486-424F-A87D-B3B409381428Partition table holds up to 128 entriesFirst usable sector is 34, last usable sector is 16777182Partitions will be aligned on 2048-sector boundariesTotal free space is 4029 sectors (2.0 MiB)Number  Start (sector)    End (sector)  Size      Code  Name  1            2048        16758783  8.0 GiB    BF01  zfs  9        16758784        16775167  8.0 MiB    BF07 Command (? for help): ##i##n ↵Partition number (2-128, default 2): ##i##↵First sector (34-16777182, default = 16775168) or {+-}size{KMGTP}: ##i##48 ↵Last sector (48-2047, default = 2047) or {+-}size{KMGTP}: ##i## ↵Current type is 'Linux filesystem'Hex code or GUID (L to show codes, Enter = 8300): ##i##EF02 ↵Changed type of partition to 'BIOS boot partition'Command (? for help): ##i##w ↵Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTINGPARTITIONS!!Do you want to proceed? (Y/N): ##i##yOK; writing new GUID partition table (GPT) to /dev/sda.The operation has completed successfully.</console>If you were to check gdisk /dev/sda again, you would see these 3 partitions:<console>Number  Start (sector)    End (sector)  Size      Code  Name  1            2048        16758783  8.0 GiB    BF01  zfs  2              48            2047  1000.0 KiB  EF02  BIOS boot partition  9        16758784        16775167  8.0 MiB    BF07</console>Let's import the pool again:<console># ##i##zpool import -f -o cachefile= -R /mnt/funtoo rpool</console>[[ZFS_Install_Guide#Create_the_zfs_datasets|Now continue with creating your datasets.]]=== Manual partitioning ======= fdisk (MBR Style) ===='''Create Partition 1''' (boot):<console>Command: ##i##n ↵Partition type: ##i##↵Partition number: ##i##↵First sector: ##i##↵Last sector: ##i##+250M ↵</console>'''Create Partition 2''' (ZFS):<console>Command: ##i##n ↵Partition type: ##i##↵Partition number: ##i##↵First sector: ##i##↵Last sector: ##i##↵Command: ##i##t ↵Partition number: ##i##2 ↵Hex code (type L to list codes): ##i##bf ↵Command: ##i##p ↵Disk /dev/sda: 1000.2 GB, 1000204886016 bytes255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x3e954df7  Device Boot      Start        End      Blocks  Id  System/dev/sda1            2048      514047      256000  83  Linux/dev/sda2          514048  1953525167  976505560  bf  Solaris</console>==== gdisk (GPT Style) ===='''Create Partition 1''' (boot):<console>Command: ##i##n ↵Partition Number: ##i##↵First sector: ##i##↵Last sector: ##i##+250M ↵Hex Code: ##i##↵</console>'''Create Partition 2''' (BIOS Boot Partition):<console>Command: ##i##n ↵Partition Number: ##i##↵First sector: ##i##↵Last sector: ##i##+32M ↵Hex Code: ##i##EF02 ↵</console>{{fancyimportant|Only make the above BIOS Boot Partition if you are using GRUB 2 on GPT. If you are using the extlinux bootloader, this partition is not necessary. The below instructions continue as if you did not create this partition and assumes you are using extlinux as the bootloader.}}'''Create Partition 2''' (ZFS):<console>Command: ##i##n ↵Partition Number: ##i##↵First sector: ##i##↵Last sector: ##i##↵Hex Code: ##i##bf01 ↵Command: ##i##p ↵Disk /dev/sda: 1953525168 sectors, 931.5 GiBLogical sector size: 512 bytesDisk identifier (GUID): C0C1E56A-B24F-492F-95DB-2E227676F228Partition table holds up to 128 entriesFirst usable sector is 34, last usable sector is 1953525134Partitions will be aligned on 2048-sector boundariesTotal free space is 2014 sectors (1007.0 KiB)Number  Start (sector)    End (sector)  Size      Code  Name  1            2048          514047  250.0 MiB  8300  Linux filesystem  2          514048      1953525134  931.3 GiB  BF01  Solaris /usr & Mac ZFSCommand: ##i##w ↵</console>=== Format your boot volume ===<console># ##i##mkfs.ext4 /dev/sda1</console>=== Create the zpool ===We will first create the pool. The pool will be named `rpool` and the disk will be aligned to 4096 (using ashift=12)<console># ##i##zpool create -f -o ashift=12 -o cachefile= -O compression=on -m none -R /mnt/funtoo rpool /dev/sda2</console>{{fancyimportant|If you followed the GPT partitioning instructions, you should change /dev/sda2 to /dev/sda3.}}{{fancynote|If you have a previous pool that you would like to import, you can do a: '''zpool import -R /mnt/funtoo -f <pool_name>'''}}=== Create the zfs datasets ===We will now create some datasets. For this installation, we will create a small but future proof amount of datasets. We will have a dataset for the OS (/), and your swap. We will also show you how to create some optional datasets: /home, /var, /usr/src, and /usr/portage.<console>Create some empty containers for organization purposes, and make the dataset that will hold /# ##i##zfs create -o mountpoint=none rpool/ROOT# ##i##zfs create -o mountpoint=/ rpool/ROOT/funtooOptional, but recommended datasets: /home, /root # ##i##zfs create -o mountpoint=/home rpool/HOME# ##i##zfs create -o mountpoint=/root rpool/HOME/rootOptional datasets: /usr/src, /var# ##i##zfs create -o mountpoint=none rpool/FUNTOO# ##i##zfs create -o mountpoint=/usr/src rpool/FUNTOO/src# ##i##zfs create -o mountpoint=/var rpool/FUNTOO/var</console>==== Creating a separate portage dataset (optional) ====Creating a separate portage dataset could be useful if you would like to keep your portage tree, distfiles (source code files), and packages (your compiled binaries if you have FEATURES="buildpkg" enabled) in a safe place (or if you want to back up this directory up easily).This requires a few extra steps because we can't just do a regular emerge --sync when we initially chroot. We will need to download a portage snapshot tarball and extract it into the directory.The required steps for getting and extracting the snapshot will be shown later on in the guide once you chroot into the environment. For now just create the datasets:<console># ##i##zfs create -o mountpoint=/usr/portage -o compression=off rpool/FUNTOO/portage# ##i##zfs create -o mountpoint=/usr/portage/distfiles -o compression=off rpool/FUNTOO/distfiles</console>=== Create your swap zvol ==='''Make your swap +1G greater than your RAM. An 8G machine would have 9G of RAM (This is kinda big though).'''Be warned - zfs is memory hungry. Specially when used with compression=on. A machine with just 4GB can come in troubles while compiling big packages and/or a graphical desktop running. You definitly should have swap running.<console># ##i##zfs create -o sync=always -o primarycache=metadata -o secondarycache=none -V 9G rpool/swap</console>=== Format your swap zvol ===<console># ##i##mkswap -f /dev/zvol/rpool/swap# ##i##swapon /dev/zvol/rpool/swap</console>Alright that finishes the creation of the zpool and zfs datasets. Check to make sure everything appears fine:<console># ##i##zpool status# ##i##zfs list</console>Copy the zpool.cache file to your new environment.<console># ##i##mkdir -p /mnt/funtoo/etc/zfs# ##i##cp /etc/zfs/zpool.cache /mnt/funtoo/etc/zfs</console>Make an empty mtab file<console># ##i##touch /mnt/funtoo/etc/mtab</console>Now we will continue to install funtoo.== Installing Funtoo ==[[Funtoo_Linux_Installation|Download and install the Funtoo stage3 and continue installation as normal.]]Then chroot into your new funtoo environment:<console># ##i##cd /mnt/funtooMount your boot drive ** You don't need to do this if you're using whole-disk zfs **# ##i##mount /dev/sda1 /mnt/funtoo/bootBind the kernel related directories# ##i##mount --bind /proc ./proc# ##i##mount --bind /dev ./dev# ##i##mount --bind /sys ./sysCopy network settings# ##i##cp /etc/resolv.conf etc/chroot into your new funtoo environment# ##i##env -i HOME=/root TERM=$TERM chroot . bash -l</console>=== Syncing your portage tree ======= If you didn't create a separate portage dataset, then just sync your portage tree as normal. ====<console># ##i##emerge --sync</console>==== If you did create a separate portage dataset, let's now get the portage snapshot set up. ====<console>Change into your /usr directory# ##i##cd /usrDownload and extract the portage snapshot# ##i##wget http://ftp.osuosl.org/pub/funtoo/funtoo-current/snapshots/portage-latest.tar.xz# ##i##tar xf portage-latest.tar.xzChange into your portage directory and checkout the funtoo branch# ##i##cd portage# ##i##git checkout funtoo.orgNow sync your portage tree# ##i##emerge --sync</console>== Kernel Configuration =={{fancynote|The below configurations are the requirements for "Bliss Initramfs Creator". Some of these might not be needed for genkernel.}}Tested with kernel 2.6.32, 3.2.34, 3.6.9, 3.7.[1-3].When you get up to the kernel, make sure that you disable the CFQ scheduler, and turnon No-op (It's the default one once you disable all schedulers). The reason for this is because ZFS has itsown scheduler and the CFQ one conflicts with it.Go to your kernel config, and make sure you have the following: (there should be a /usr/src/linux symlink as well)<pre>ZLIB_INFLATE/DEFLATE must be compiled into the kernel (not as a module).> ZLIB_INFLATE [=y], ZLIB_DEFLATE [=y]General setup --->> [*] Initial RAM filesystem and RAM disk (initramfs/initrd) support> () Initramfs source file(s)[*] Enable loadable module support --->[*] Module unloadingEnable the block layer --->IO Schedulers --->< > Deadline I/O scheduler< > CFQ I/O schedulerDefault I/O scheduler (No-op)Device Drivers --->> Generic Driver Options --->>> [*] Maintain a devtmpfs filesystem to mount at /dev>> [*] Automount devtmpfs at /dev, after the kernel mounted the rootfsCryptographic API ---><*> Deflate compression algorithm<*> Zlib compression algorithm* All other drivers required to see your PATA/SATA drives must be compiled in.</pre>Continue and compile/install your kernel:<console># ##i##make bzImage modules# ##i##make install# ##i##make modules_install</console>== Installing the ZFS userspace tools ==<console># ##i##emerge -av zfs</console>Check to make sure that the zfs tools are working, the zpool.cache file that you copied before should be displayed.<console># ##i##zpool status# ##i##zfs list</console>If everything worked, continue.== Install the bootloader ===== GRUB 2 ===If you are using whole-disk zfs then you will need grub2 because grub2 is the only bootloader that supports booting from a zfs pool.Before you do this, make sure this checklist is followed:- Installed kernel and kernel modules- Installed zfs package from the tree- /dev, /proc, /sys are mounted in the chroot environmentOnce all this is good, let's install grub2. First we need to enable the "libzfs" use flag so zfs support is compiled for grub2.<console># ##i##echo "sys-boot/grub libzfs" >> /etc/portage/package.use</console>Then we will compile grub2 (GRUB 2 should be _at least_ version 2.0.0 since 2.0.0 added zfs support. 1.99,.98 will not work):<console># ##i##emerge -av grub</console>Once this is done, you can check that grub2 is version 2.00 by doing the following command:<console># ##i##grub-install --versiongrub-install (GRUB) 2.00</console>Now try to install grub2:<console># ##i##grub-install --no-floppy /dev/sda</console>You should receive the following message:<console>Installation finished. No error reported.</console>If not, then go back to the above checklist.=== Extlinux ===There are four things we need to do for extlinux:<br />1. Install extlinux bootloader<br />2. Write the .bin to the front of the target disk<br />3. Toggle BIOS partition flag<br />4. Write a extlinux configuration fileFirst emerge extlinux:<console># ##i##emerge -av syslinux</console>Then create a /boot/extlinux directory<console># ##i##cd /boot# ##i##mkdir /boot/extlinux</console>Change into the extlinux dir and install the bootloader<console># ##i##cd /boot/extlinux# ##i##extlinux --install .</console>==== MBR ====<console># ##i##fdisk /dev/sdaCommand: ##i##a ↵Partition number: ##i##1 ↵Command: ##i##w ↵</console>Printing the fdisk partition layout should show a star next to /dev/sda1<console>/dev/sda  *    2048    514047    256000    83    Linux</console>Flash the .bin to the front of the disk<console># ##i##dd conv=notrunc bs=440 count=1 if=/usr/share/syslinux/mbr.bin of=/dev/sda</console>=== GPT ===<console># ##i##sgdisk /dev/sda --attributes=1:set:2</console>Flash the .bin to the front of the disk<console># ##i##dd conv=notrunc bs=440 count=1 if=/usr/share/syslinux/gptmbr.bin of=/dev/sda</console>We will write the extlinux/grub configuration file in the next section.== Create the initramfs ==There are two ways to do this, you can use genkernel, or you can use my bliss initramfs creator. I willshow you both.=== genkernel ===<console># ##i##emerge -av sys-kernel/genkernel# ##i##genkernel --zfs initramfs</console><pre>Example: kernel name is: vmlinuz-3.7.3-ALLinitramfs name is: initramfs-genkernel-x86_64-3.7.3-ALLpool name is: rpool</pre>grub.cfg:<console>set timeout=3set default=0# Funtoomenuentry "Funtoo - 3.7.3" {  insmod zfs  linux /ROOT/funtoo/@/boot/vmlinuz-3.7.3-ALL root=rpool/ROOT/funtoo real_root=ZFS=rpool/ROOt/funtoo dozfs=force  initrd /ROOT/funtoo/@/boot/initramfs-genkernel-x86_64-3.7.3-ALL}</console>extlinux.conf:<console>LABEL funtoo  MENU LABEL Funtoo 3.7.3-ALL  KERNEL /boot/vmlinuz-3.7.3-ALL  INITRD /boot/initramfs-genkernel-x86_64-3.7.3-ALL  APPEND real_root=ZFS=rpool/ROOT/funtoo dozfs=force</console>=== Bliss Initramfs Creator ===Clone my creator which is located at: git://github.com/fearedbliss/Bliss-Initramfs-Creator.git<console># ##i##git clone git://github.com/fearedbliss/Bliss-Initramfs-Creator.git</console>Then go into this new directory, run the script as root, and place it into /boot<console># ##i##cd Bliss-Initramfs-Creator# ##i##./createInit# ##i##mv initrd-<kernel_name>.img /boot</console>'''<kernel_name>''' is the name of what you selected in the initramfs creator, and the name of the outputted file.Once you do this just go to your bootloader config, and add it in there.<pre>Example:Kernel name is: vmlinuz-3.7.3-ALLinitramfs name is: initrd-3.7.3-ALL.imgPool root is: rpool/ROOT/funtoo</pre>grub.cfg:<console>set timeout=3set default=0# Funtoomenuentry "Funtoo - 3.7.3" {  insmod zfs  linux /ROOT/funtoo/@/boot/vmlinuz-3.7.3-ALL root=rpool/ROOT/funtoo quiet  initrd /ROOT/funtoo/@/boot/initrd-3.7.3-ALL.img}</console>extlinux.conf:<console>LABEL funtoo  MENU LABEL Funtoo 3.7.1-ALL  KERNEL /boot/vmlinuz-3.7.1-ALL  INITRD /boot/initrd-3.7.1-ALL.img  APPEND pool_root=rpool/ROOT/funtoo</console>== Final configuration ===== Add the zfs tools to openrc ===<console># ##i##rc-update add zfs boot</console>=== Add filesystems to /etc/fstab ===<console># ##i##nano /etc/fstab# <fs>                  <mountpoint>    <type>          <opts>          <dump/pass># Do not add the /boot line below if you are using whole-disk zfs/dev/sda1              /boot          ext4            defaults        1 2/dev/zvol/rpool/swap    none            swap            sw              0 0</console>=== Clean up and reboot ===We are almost done, we are just going to clean up, '''set our root password''', and unmount whatever we mounted and get out.<console>Delete the stage3/portage tarballs you downloaded earlier so they don't take up space.# ##i##cd /# ##i##rm stage3-latest.tar.xz# ##i##rm /usr/portage-latest.tar.xzSet your root password# ##i##passwd>> Enter your password, you won't see what you are writing (for security reasons), but it is there!Get out of the chroot environment# ##i##exitUnmount all the kernel filesystem stuff and boot# ##i##cd /mnt/funtoo# ##i##umount proc dev sys bootTurn off the swap# ##i##swapoff /dev/zvol/rpool/swapExport the zpool# ##i##cd /# ##i##zpool export -f rpoolReboot# ##i##reboot</console>{{fancyimportant|'''Don't forget to set your root password as stated above before exiting chroot and rebooting. If you don't set the root password, you won't be able to log into your new system.'''}}and that should be enough to get your system to boot on ZFS.== Extra: After reboot ==After you restart your machine and your inside your desktop, continue to set up anything you need in terms of /etc configurations. Once you have everything the way you like it, take a snapshot of your system. You will be using this snapshot to revert back to this state if anything ever happens to your system down the road. The snapshots are cheap, and almost instant. To take the snapshot of your rootfs, type the following:<console># ##i##zfs snapshot rpool/ROOT/funtoo@install</console>To see if your snapshot was taken, type:<console># ##i##zfs list -t snapshot</console>If your machine ever fails and you need to get back to this state, just type:<console># ##i##zfs rollback rpool/ROOT/funtoo@install</console>=== Recovery Environment ===On ZFS it is extremely easy to create a recovery environment using an already working snapshot. So that's what we will be doing. Create a clone of the @install snapshot which you will use for recovery purposes. If something happens to your main install, you can boot into this clone and fix the main one. One of the differences (maybe the only difference) between a clone and a snapshot is that a clone is rewritable while a snapshot is only read-only.<console># ##i##zfs clone rpool/ROOT/funtoo@install rpool/ROOT/recovery</console>==== Add the clone to your extlinux.conf ====<console>LABEL funtoo-recovery    MENU LABEL Funtoo Recovery    KERNEL /boot/vmlinuz-3.7.1-ALL    INITRD /boot/initrd-3.7.1-ALL.img    APPEND pool_root=rpool/ROOT/recovery</console>==== Things to watch out for ====Since your recovery clone will tend to get old as you use your main system, and since your recovery and other stuff are on the same pool, we don't want the new pool stuffto be mounted when we launch recovery. We also don't want video drivers to beconflicting.1. Make sure that nvidia/nouveau stuff are blacklisted.2. Make sure that your /boot and /lib/modules for the kernel in your 'recovery' arematching.3. Disable the zfs openrc script so that nothing else gets automatically mounted.Only your rootfs.You can do the above stuff by mounting your copy and chrooting into it.<console>Mount the recovery clone# ##i##mkdir /mnt/recovery# ##i##mount -t zfs -o zfsutil rpool/ROOT/recovery /mnt/recovery# ##i##cd /mnt/recoveryMount the kernel devices# ##i##mount --bind /proc ./proc# ##i##mount --bind /dev ./dev# ##i##mount --bind /sys ./sysCopy zpool.cache# ##i##cp /etc/zfs/zpool.cache etc/zfsChroot into the new environment# ##i##env -i HOME=/root TERM=$TERM chroot . bash --loginDisable zfs/zfs-shutdown openrc scripts# ##i##rc-config delete zfs bootBlacklist nouveau/nvidia drivers# ##i##echo "blacklist nouveau" >> /etc/modprobe.d/blacklist.conf# ##i##echo "blacklist nvidia" >> /etc/modprobe.d/blacklist.conf</console>==== Getting into the recovery ====Just start your machine and pick the '''Funtoo Recovery''' option from the Boot Menu.Enjoy your new install on ZFS :)[[Category:HOWTO]][[Category:Filesystems]][[Category:Featured]]
+
__NOTOC__
 +
__NOTITLE__

Revision as of 06:45, 7 February 2013

Introduction

This tutorial will show you how to install Funtoo on ZFS (rootfs). This tutorial is meant to be an "overlay" over the Regular Funtoo Installation. Follow the normal installation and only use this guide for steps 2, 3, and 8.

Introduction to ZFS

Since ZFS is a new technology for Linux, it can be helpful to understand some of its benefits, particularly in comparison to BTRFS, another popular next-generation Linux filesystem:

  • The current btrfs code in Linus' tree has known data corruption bugs that Chris Mason has yet to fix. The current ZFS code has a solid track record for data integrity.
  • On Linux, the ZFS code can be updated independently of the kernel to obtain the latest fixes. btrfs is exclusive to Linux and you need to build the latest kernel sources to get the latest fixes.
  • ZFS is supported on multiple platforms. The platforms with the best support are Solaris, FreeBSD and Linux. Other platforms with varying degrees of support are NetBSD, Mac OS X and Windows. btrfs is exclusive to Linux.
  • ZFS has the Adaptive Replacement Cache replacement algorithm while btrfs uses the linux kernel's Last Recently Used replacement algorithm. The former often has an overwhelmingly superior hit rate, which means fewer disk accesses.
  • ZFS has the ZFS Intent Log and SLOG devices, which accelerates small synchronous write performance.
  • ZFS handles internal fragmentation gracefully, such that you can fill it until 100%. Internal fragmentation in btrfs can make btrfs think it is full at 10%. Btrfs has no automatic rebalancing code, so it requires a manual rebalance to correct it.
  • ZFS has raidz, which is like RAID 5/6 (or a hypothetical RAID 7 that supports 3 parity disks), except it does not suffer from the RAID write hole issue thanks to its use of CoW and a variable stripe size. btrfs has no equivalent.
  • ZFS send/receive implementation supports incremental update when doing backups. btrfs' send/receive implementation requires sending the entire snapshot.
  • ZFS supports data deduplication, which is a memory hog and only works well for specialized workloads. btrfs has no equivalent.
  • ZFS datasets have a hierarchical namespace while btrfs subvolumes have a flat namespace.
  • ZFS has the ability to create virtual block devices called zvols in its namespace. btrfs has no equivalent and must rely on the loop device for this functionality, which is cumbersome.

The only area where btrfs is ahead of ZFS is in the area of small file efficiency. btrfs supports a feature called block suballocation, which enables it to store small files far more efficiently than ZFS. It is possible to use another filesystem (e.g. reiserfs) on top of a ZFS zvol to obtain similar benefits (with arguably better data integrity) when dealing with many small files (e.g. the portage tree).


Disclaimers

This guide is a work in progress. Expect some quirks.


Since ZFS was really designed for 64 bit systems, we are only recommending and supporting 64 bit platforms and installations. We will not be supporting 32 bit platforms!


Video Tutorial

As a companion to the install instructions below, a YouTube video ZFS install tutorial is now available:

Setting up your environment

In order for us to install Funtoo on ZFS, you will need an environment that provides the ZFS tools. We will be downloading two things:

  1. System Rescue CD,
  2. ZFS System Rescue Module (SRM)


This is just a file that when combined with System Rescue CD, gives you those tools.

Name: SystemRescueCd-x86-3.3.0 (368 MiB)
Release Date: 2013-01-24
md5sum 01c9d3ff99b46771779ea2d3a66a1c7c


Funtoo now has mirrored copies of System Rescue CD and the ZFS SRM at the links below.

Download System Rescue CD 3.3.0
Download the ZFS System Rescue Module

Follow the instructions here to download and place the srm into your flash drive.

Creating partitions

There are two ways to partition your disk: You can use your entire drive and let ZFS automatically partition it for you, or you can do it manually.

Using your entire disk drive is recommended since ZFS turns on/off a few settings. For one, if you use your whole-disk, ZFS will set the I/O elevator for the drive automatically. On Solaris machines, ZFS also enables the disk's write cache.

If you partition it manually, you should set your I/O scheduler to no-op so it doesn't conflict with the ZFS scheduler. Partitioning manually also gives you the advantage of putting your /boot outside the ZFS pool so that you can use a bootloader that doesn't support booting from ZFS.

Whole Disk

This is the easiest method and the recommended method.
First lets make sure that the disk is completely wiped from any previous disk labels and partitions. We will also assume that /dev/sda is the target drive.

# gdisk /dev/sda

Command: x ↵
Expert command: z ↵
About to wipe out GPT on /dev/sda. Proceed?: y ↵
GPT data structures destroyed! You may now partition the disk using fdisk or other utilities.
Blank out MBR?: y ↵

This is a destructive operation. Make sure you really don't want anything on this disk.


Now that we have a clean drive, we will create the new pool in it while letting zfs automatically partition it.

Create the pool as normal:

# zpool create -f -o ashift=12 -o cachefile= -O compression=on -m none -R /mnt/funtoo rpool /dev/sda

Doing this will let ZFS create a GPT style disk with two partitions. We will also slightly modify this to add a BIOS Boot Partition so that grub can be installed successfully. First lets export the pool so that the kernel can use the new partition table without rebooting.

# zpool export rpool


And now lets create a new BIOS Boot Partition at partition 2 from sectors 48 to 2047:

# gdisk /dev/sda

Command (? for help): p ↵

Number  Start (sector)    End (sector)  Size       Code  Name   
1            2048        16758783   8.0 GiB     BF01  zfs   
9        16758784        16775167   8.0 MiB     BF07 

Command: n ↵
Partition number: 2 ↵
First sector: 48 ↵
Last sector: 2047 ↵
Hex code or GUID: EF02 ↵

Command: w ↵
Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sda.
The operation has completed successfully.

If you were to check /dev/sda again, you would see these 3 partitions:

Number  Start (sector)    End (sector)  Size       Code  Name   
1            2048        16758783   8.0 GiB     BF01  zfs   
2              48            2047   1000.0 KiB  EF02  BIOS boot partition   
9        16758784        16775167   8.0 MiB     BF07

Let's import the pool again:

# zpool import -f -o cachefile= -R /mnt/funtoo rpool


Now continue with creating your datasets.

Manual partitioning

fdisk (MBR Style)

Create Partition 1 (boot):

Command: n ↵
Partition type: 
Partition number: 
First sector: 
Last sector: +250M ↵

Create Partition 2 (ZFS):

Command: n ↵
Partition type: 
Partition number: 
First sector: 
Last sector: 

Command: t ↵
Partition number: 2 ↵
Hex code: bf ↵

Command: p ↵

Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048      514047      256000   83  Linux
/dev/sda2          514048  1953525167   976505560   bf  Solaris


gdisk (GPT Style)

Create Partition 1 (boot):

Command: n ↵
Partition Number: 
First sector: 
Last sector: +250M ↵
Hex Code: 

Create Partition 2 (BIOS Boot Partition):

Command: n ↵
Partition Number: 
First sector: 
Last sector: +32M ↵
Hex Code: EF02 ↵

Only make the above BIOS Boot Partition if you are using GRUB 2 on GPT. If you are using the extlinux bootloader, this partition is not necessary.


Create Partition 2 (ZFS):

Command: n ↵
Partition Number: 
First sector: 
Last sector: 
Hex Code: bf01 ↵

Command: p ↵

Number  Start (sector)    End (sector)  Size       Code  Name   
1            2048          514047   250.0 MiB   8300  Linux filesystem   
2          514048      1953525134   931.3 GiB   BF01  Solaris /usr & Mac ZFS

Command: w ↵


Format your boot volume

If you did manual partitioning, format your separate boot partition:

# mkfs.ext4 /dev/sda1


Create the zpool

We will first create the pool. The pool will be named `rpool` and the disk will be aligned to 4096 (using ashift=12)

# zpool create -f -o ashift=12 -o cachefile= -O compression=on -m none -R /mnt/funtoo rpool /dev/sda2

If you followed the manual GPT partitioning instructions, you should change /dev/sda2 to /dev/sda3.

If you have a previous pool that you would like to import, you can do a: zpool import -f -R /mnt/funtoo <pool_name>


Create the zfs datasets

We will now create some datasets. For this installation, we will create a small but future proof amount of datasets. We will have a dataset for the OS (/), and your swap. We will also show you how to create some optional datasets: /home, /var, /usr/src, and /usr/portage.

Create some empty containers for organization purposes, and make the dataset that will hold /
# zfs create -o mountpoint=none rpool/ROOT
# zfs create -o mountpoint=/ rpool/ROOT/funtoo

Optional, but recommended datasets: /home, /root
# zfs create -o mountpoint=/home rpool/HOME
# zfs create -o mountpoint=/root rpool/HOME/root

Optional datasets: /usr/src, /var
# zfs create -o mountpoint=none rpool/FUNTOO
# zfs create -o mountpoint=/usr/src rpool/FUNTOO/src
# zfs create -o mountpoint=/var rpool/FUNTOO/var


Creating a separate portage dataset (optional)

Creating a separate portage dataset could be useful if you would like to keep your portage tree, distfiles (source code files), and packages (your compiled binaries if you have FEATURES="buildpkg" enabled) in a safe place (or if you want to back up this directory up easily). This requires a few extra steps because we can't just do a regular emerge --sync when we initially chroot. We will need to download a portage snapshot tarball and extract it into the directory. The required steps for getting and extracting the snapshot will be shown later on in the guide once you chroot into the environment.

For now just create the datasets:

# zfs create -o mountpoint=/usr/portage -o compression=off rpool/FUNTOO/portage
# zfs create -o mountpoint=/usr/portage/distfiles -o compression=off rpool/FUNTOO/distfiles


Create your swap zvol

Make your swap +1G greater than your RAM. An 8G machine would have 9G of RAM (This is kinda big though).

# zfs create -o sync=always -o primarycache=metadata -o secondarycache=none -V 9G rpool/swap


Format your swap zvol

# mkswap -f /dev/zvol/rpool/swap
# swapon /dev/zvol/rpool/swap


Last minute checks and touches

Check to make sure everything appears fine:

# zpool status
# zfs list

Copy the zpool.cache file to your new environment.

# mkdir -p /mnt/funtoo/etc/zfs
# cp /etc/zfs/zpool.cache /mnt/funtoo/etc/zfs

Make an empty mtab file

# touch /mnt/funtoo/etc/mtab

Now we will continue to install funtoo.

Installing Funtoo

Download and install the Funtoo stage3 and continue installation as normal.

Then chroot into your new funtoo environment:

# cd /mnt/funtoo

Mount your boot drive ** You don't need to do this if you're using whole-disk zfs **
# mount /dev/sda1 /mnt/funtoo/boot

Bind the kernel related directories
# mount --rbind /proc proc
# mount --rbind /dev dev
# mount --rbind /sys sys

Copy network settings
# cp /etc/resolv.conf etc/chroot into your new funtoo environment
# env -i HOME=/root TERM=$TERM chroot . /bin/bash -l

Syncing your portage tree

If you didn't create a separate portage dataset, then just sync your portage tree as normal.

# emerge --sync

If you did create a separate portage dataset, let's now get the portage snapshot set up.

Change into your /usr directory
# cd /usr

Download and extract the portage snapshot
# wget http://ftp.osuosl.org/pub/funtoo/funtoo-current/snapshots/portage-latest.tar.xz
# tar xf portage-latest.tar.xz

Change into your portage directory and checkout the funtoo branch
# cd portage
# git checkout funtoo.org

Now sync your portage tree
# emerge --sync

Kernel Configuration

The below configurations are the requirements for "Bliss Initramfs Creator". Some of these might not be needed for genkernel.


Tested with kernel 2.6.32, 3.2.34, 3.6.X, 3.7.X.

When you get up to the kernel, make sure that you disable the CFQ scheduler, and turn on No-op (It's the default one once you disable all schedulers). The reason for this is because ZFS has its own scheduler and the CFQ one conflicts with it. Go to your kernel config, and make sure you have the following: (there should be a /usr/src/linux symlink as well)

ZLIB_INFLATE/DEFLATE must be compiled into the kernel (not as a module).
> ZLIB_INFLATE [=y], ZLIB_DEFLATE [=y]

General setup --->
> [*] Initial RAM filesystem and RAM disk (initramfs/initrd) support
> () Initramfs source file(s)

[*] Enable loadable module support --->
[*] Module unloading

Device Drivers --->
> Generic Driver Options --->
>> [*] Maintain a devtmpfs filesystem to mount at /dev

Cryptographic API --->
<*> Deflate compression algorithm
<*> Zlib compression algorithm

* All other drivers required to see your PATA/SATA drives must be compiled in.

Continue and compile/install your kernel:

# make bzImage modules
# make install
# make modules_install

Installing the ZFS userspace tools

# emerge -av zfs
Check to make sure that the zfs tools are working, the zpool.cache file that you copied before should be displayed.
# zpool status
# zfs list

If everything worked, continue.

Install the bootloader

GRUB 2

If you are using whole-disk zfs then you will need grub2 because grub2 is the only bootloader that supports booting from a zfs pool.

Before you do this, make sure this checklist is followed:

  • Installed kernel and kernel modules
  • Installed zfs package from the tree
  • /dev, /proc, /sys are mounted in the chroot environment

Once all this is checked, let's install grub2. First we need to enable the "libzfs" use flag so zfs support is compiled for grub2.

# echo "sys-boot/grub libzfs" >> /etc/portage/package.use

Then we will compile grub2:

GRUB should be _at least_ version 2.0.0 since 2.0.0 added zfs support. 1.99,.98 will not work.


# emerge -av grub

Once this is done, you can check that grub is version 2.00 by doing the following command:

# grub-install --version
grub-install (GRUB) 2.00

Now try to install grub2:

# grub-install --no-floppy /dev/sda

You should receive the following message

Installation finished. No error reported.

If not, then go back to the above checklist.

Extlinux

There are four things we need to do for extlinux:

  1. Install extlinux bootloader
  2. Write the .bin to the front of the target disk
  3. Toggle BIOS partition flag
  4. Write a extlinux configuration file

First emerge extlinux:

# emerge -av syslinux

Then create a /boot/extlinux directory:

# cd /boot
# mkdir /boot/extlinux

Change into the extlinux dir and install the bootloader:

# cd /boot/extlinux
# extlinux --install .

MBR

# fdisk /dev/sda

Command: a ↵
Partition number: 1 ↵
Command: w ↵

Printing the fdisk partition layout should show a star next to /dev/sda1:

/dev/sda   *    2048    514047    256000    83    Linux

Flash the .bin to the front of the disk:

# dd conv=notrunc bs=440 count=1 if=/usr/share/syslinux/mbr.bin of=/dev/sda

GPT

# sgdisk /dev/sda --attributes=1:set:2

Flash the .bin to the front of the disk:

# dd conv=notrunc bs=440 count=1 if=/usr/share/syslinux/gptmbr.bin of=/dev/sda

We will write the extlinux/grub configuration file in the next section.

Create the initramfs

There are two ways to do this, you can use genkernel, or you can use my bliss initramfs creator. I will show you both.

genkernel

# emerge -av sys-kernel/genkernel
# genkernel --zfs initramfs


Example: kernel name is: vmlinuz-3.7.3-ALL
initramfs name is: initramfs-genkernel-x86_64-3.7.3-ALL
pool name is: rpool

grub.cfg:

set timeout=3
set default=0

# Funtoo
menuentry "Funtoo - 3.7.3" {  
  insmod zfs  
  linux /ROOT/funtoo/@/boot/vmlinuz-3.7.3-ALL root=rpool/ROOT/funtoo real_root=ZFS=rpool/ROOT/funtoo dozfs=force
  initrd /ROOT/funtoo/@/boot/initramfs-genkernel-x86_64-3.7.3-ALL
}

extlinux.conf:

LABEL funtoo
  MENU LABEL Funtoo 3.7.3-ALL
  KERNEL /boot/vmlinuz-3.7.3-ALL
  INITRD /boot/initramfs-genkernel-x86_64-3.7.3-ALL
  APPEND real_root=ZFS=rpool/ROOT/funtoo dozfs=force

Bliss Initramfs Creator

Clone my creator which is located at: git://github.com/fearedbliss/Bliss-Initramfs-Creator.git

# git clone git://github.com/fearedbliss/Bliss-Initramfs-Creator.git

Then go into this new directory, run the script as root, and place it into /boot:

# cd Bliss-Initramfs-Creator
# ./createInit
# mv initrd-<kernel_name>.img /boot

<kernel_name> is the name of what you selected in the initramfs creator, and the name of the outputted file. Once you do this just go to your bootloader config, and add it in there.

Example: Kernel name is: vmlinuz-3.7.3-ALL
initramfs name is: initrd-3.7.3-ALL.img
Pool root is: rpool/ROOT/funtoo

grub.cfg:

set timeout=3
set default=0

# Funtoo
menuentry "Funtoo - 3.7.3" {  
  insmod zfs
  linux /ROOT/funtoo/@/boot/vmlinuz-3.7.3-ALL root=rpool/ROOT/funtoo quiet
  initrd /ROOT/funtoo/@/boot/initrd-3.7.3-ALL.img
}

extlinux.conf:

LABEL funtoo  
  MENU LABEL Funtoo 3.7.3-ALL  
  KERNEL /boot/vmlinuz-3.7.3-ALL  
  INITRD /boot/initrd-3.7.3-ALL.img  
  APPEND root=rpool/ROOT/funtoo

Final configuration

Add the zfs tools to openrc

# rc-update add zfs boot

Add filesystems to /etc/fstab

# nano /etc/fstab

# <fs>                  <mountpoint>    <type>          <opts>          <dump/pass>
# Do not add the /boot line below if you are using whole-disk zfs
/dev/sda1               /boot           ext4            defaults        1 2
/dev/zvol/rpool/swap    none            swap            sw              0 0

Clean up and reboot

We are almost done, we are just going to clean up, set our root password, and unmount whatever we mounted and get out.

Delete the stage3/portage tarballs you downloaded earlier so they don't take up space.
# cd /
# rm stage3-latest.tar.xz
# rm /usr/portage-latest.tar.xz

Set your root password
# passwd
>> Enter your password, you won't see what you are writing (for security reasons), but it is there!

Get out of the chroot environment
# exit

Unmount all the kernel filesystem stuff and boot (if you have a separate /boot)
# cd /mnt/funtoo
# umount -l proc dev sys boot

Turn off the swap
# swapoff /dev/zvol/rpool/swap

Export the zpool
# cd /
# zpool export -f rpool

Reboot
# reboot

Don't forget to set your root password as stated above before exiting chroot and rebooting. If you don't set the root password, you won't be able to log into your new system.


and that should be enough to get your system to boot on ZFS.

Extra: After reboot

After you restart your machine and your inside your desktop, continue to set up anything you need in terms of /etc configurations. Once you have everything the way you like it, take a snapshot of your system. You will be using this snapshot to revert back to this state if anything ever happens to your system down the road. The snapshots are cheap, and almost instant.

To take the snapshot of your rootfs, type the following:

# zfs snapshot rpool/ROOT/funtoo@install

To see if your snapshot was taken, type:

# zfs list -t snapshot

If your machine ever fails and you need to get back to this state, just type:

# zfs rollback rpool/ROOT/funtoo@install

Recovery Environment

On ZFS it is extremely easy to create a recovery environment using an already working snapshot. So that's what we will be doing. Create a clone of the @install snapshot which you will use for recovery purposes. If something happens to your main install, you can boot into this clone and fix the main one. One of the differences (maybe the only difference) between a clone and a snapshot is that a clone is rewritable while a snapshot is only read-only.

# zfs clone rpool/ROOT/funtoo@install rpool/ROOT/recovery

Add the clone to your grub.cfg

set timeout=3
set default=0

# Funtoo Recovery
menuentry "Funtoo Recovery - 3.7.3" {  
  insmod zfs
  linux /ROOT/funtoo/@/boot/vmlinuz-3.7.3-ALL root=rpool/ROOT/recovery quiet
  initrd /ROOT/funtoo/@/boot/initrd-3.7.3-ALL.img
}

Add the clone to your extlinux.conf

LABEL funtoo-recovery    
  MENU LABEL Funtoo Recovery    
  KERNEL /boot/vmlinuz-3.7.3-ALL    
  INITRD /boot/initrd-3.7.3-ALL.img    
  APPEND root=rpool/ROOT/recovery

Things to watch out for

Since your recovery clone will tend to get old as you use your main system, and since your recovery and other stuff are on the same pool, we don't want the new pool stuff to be mounted when we launch recovery. We also don't want video drivers to be conflicting.

  1. Make sure that nvidia/nouveau stuff are blacklisted.
  2. Make sure that your /boot and /lib/modules for the kernel in your 'recovery' are matching.
  3. Disable the zfs openrc script so that nothing else gets automatically mounted. Only your rootfs.

You can do the above stuff by mounting your copy and chrooting into it.

Mount the recovery clone
# mkdir /mnt/recovery
# mount -t zfs -o zfsutil rpool/ROOT/recovery /mnt/recovery
# cd /mnt/recovery

Mount the kernel devices
# mount --rbind /proc ./proc
# mount --rbind /dev ./dev
# mount --rbind /sys ./sys

Copy zpool.cache
# cp /etc/zfs/zpool.cache etc/zfs

Chroot into the new environment
# env -i HOME=/root TERM=$TERM chroot . bash --login

Disable zfs/zfs-shutdown openrc scripts
# rc-config delete zfs boot

Blacklist nouveau/nvidia drivers
# echo "blacklist nouveau" >> /etc/modprobe.d/blacklist.conf
# echo "blacklist nvidia" >> /etc/modprobe.d/blacklist.conf

Once you are done doing your changes, just umount and exit the chroot:

# cd /
# umount -l proc dev sys
# exit

Getting into the recovery

Just start your machine and pick the Funtoo Recovery option from the Boot Menu.

Enjoy your new install on ZFS :)

Personal tools
Namespaces

Variants
Actions
Categories
Toolbox
Stuff