Difference between pages "Funtoo Linux Networking" and "ZFS Install Guide"

From Funtoo
(Difference between pages)
Jump to: navigation, search
m (Network-Dependent Services)
 
(Video Tutorial: new video)
 
Line 1: Line 1:
<blockquote>This document explains how to configure your network settings by explaining the network configuration functionality available in Funtoo Linux. Also covered is <tt>dhcpcd 5.x</tt>, Wi-Fi (IEEE 802.11) configuration, and the OpenResolv framework.
 
</blockquote>
 
 
 
== Introduction ==
 
== Introduction ==
  
Funtoo Linux has its own core network configuration system that differs somewhat from upstream network configuration systems used in [http://www.gentoo.org Gentoo Linux] and [http://roy.marples.name/projects/openrc OpenRC].
+
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:
  
In this document, I will explain the unique additions and changes to the Funtoo network configuration and show you how to use this system to configure your network.
+
* 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.
  
I'll also explain how to use <tt>dhcpcd 5.x</tt> for managing network interfaces on DHCP-based networks, and will also cover OpenRC stacked runlevel configuration, ''Wi-Fi'' (IEEE 802.11) configuration, and the OpenResolv framework, which is enabled in Funtoo Linux by default.
+
* 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.
  
== A Gentle Introduction to Funtoo Network Configuration ==
+
* 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.
  
Before I get into the technical details of configuring your network, it's important to understand that Funtoo Linux has a number of different options available to you for network configuration, with more likely to be added in the future. Each approach is different and has its own strengths and weaknesses, and this is, in my opinion, a good thing.
+
* ZFS has the ZFS Intent Log and SLOG devices, which accelerates small synchronous write performance.
  
=== The Easy (Dynamic) Way ===
+
* 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.
  
When configuring your network, one option is to skip traditional network configuration and simply rely on DHCP. This is by far the simplest method of configuring your network. If you are on a wired network, no other steps are typically required beyond enabling a DHCP client, and Funtoo Linux includes <tt>dhcpcd 5.x</tt> by default.  
+
* 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 gained integrated RAID 5/6 functionality in Linux 3.9. However, its implementation uses a stripe cache that can only partially mitigate the effect of the RAID write hole.
  
==== Network Manager, Wicd ====
+
* ZFS send/receive implementation supports incremental update when doing backups. btrfs' send/receive implementation requires sending the entire snapshot.
  
If you are going to use a third party package such as [[Network Manager]] or [[Wicd]] to manage your network then you do not need to configure DHCP at all. These packages configure DHCP for you. Simply emerge the package you want to use and start using it.
+
* ZFS supports data deduplication, which is a memory hog and only works well for specialized workloads. btrfs has no equivalent.
  
==== DHCP-Only Systems ====
+
* ZFS datasets have a hierarchical namespace while btrfs subvolumes have a flat namespace.
  
If you are not planning to use a third-party package to manage your network interfaces, it is still extremely easy to set up DHCP networking, especially if you always use DHCP to connect to networks, which is common for desktops or laptops. In this scenario, we can simply enable <tt>dhcpcd</tt> to run at system startup. It will run in the background and automatically look for DHCP servers on all your network interfaces, and will attempt to lease an IP address from any DHCP servers found.  
+
* 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.
  
If this sounds like what you want to do, then add <tt>dhcpcd</tt> to your default runlevel as follows:
+
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).
  
<console># ##i##rc-update add dhcpcd default</console>
+
=== Disclaimers ===
  
To enable DHCP immediately, you would follow the previous command with an <tt>rc</tt> command, which would start the <tt>dhcpcd</tt> client you just added:
+
{{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'''!}}
  
<console># ##i##rc</console>
+
== Video Tutorial ==
  
If you're on a wired network and have the necessary drivers in your kernel, then this should get you going. For wireless networks, more steps are required to utilize your wireless hardware to associate with an access point, which will be covered later in this document.
+
As a companion to the install instructions below, a YouTube video ZFS install tutorial is now available:
  
===== Tweaking Dhcpcd =====
+
{{#widget:YouTube|id=SWyThdxNoP8|width=640|height=360}}
  
For now, it's important to note that <tt>dhcpcd 5.x</tt> will manage ''all'' available network interfaces by default. If you want to run a DHCP client on ''all but one'' interface, or some other subset of interfaces, you can add the appropriate <tt>denyinterfaces</tt> or <tt>allowinterfaces</tt> [[glob pattern]] to <tt>/etc/dhcpcd.conf</tt>:
+
== Downloading the ISO (With ZFS) ==
 +
In order for us to install Funtoo on ZFS, you will need an environment that provides the ZFS tools. Therefore we will download a customized version of System Rescue CD with ZFS already included. When booting, use the "alternate"-kernel. The ZFS-module won't work with the default kernel.  
  
 
<pre>
 
<pre>
# manage all interfaces but eth0 with dhcpcd
+
Name: sysresccd-4.0.0_zfs_0.6.2.iso  (522 MB)
denyinterfaces eth0
+
Release Date: 2014-01-18
 +
md5sum 5a6530088e63b516765f78076a2e4859
 
</pre>
 
</pre>
  
This can also be accomplished by modifying <tt>/etc/init.d/dhcpcd</tt> directly and adding <tt>-Z ''ifglob''</tt> or <tt>-z ''ifglob''</tt> (the equivalent command-line parameters) to <tt>command_args</tt>.
 
  
==== Using Funtoo Scripts for DHCP ====
+
'''[http://ftp.osuosl.org/pub/funtoo/distfiles/sysresccd/ Download System Rescue CD with ZFS]'''<br />
  
You can also use the Funtoo Linux networking scripts to start a DHCP client just on a specific interface. This approach is best if you are planning to also do some advanced bridging, bonding or VLAN configuration on your machine along with DHCP, since you will be using the Funtoo Linux networking scripts for that too.
+
== Creating a bootable USB from ISO ==
 
+
After you download the iso, you can do the following steps to create a bootable USB:
To use this variant approach, ''don't'' enable <tt>/etc/init.d/dhcpcd</tt> directly. Instead, use the Funtoo Linux <tt>dhcpcd</tt> template which will start dhcpcd on only one interface. Below, you will see the steps to do this. This is very similar to how we set up advanced network interfaces, which will be covered later in this documentation:
+
  
 
<console>
 
<console>
# ##i##cd /etc/init.d
+
Make a temporary directory
# ##i##ln -s netif.tmpl netif.eth0
+
# ##i##mkdir /tmp/loop
# ##i##rc-update add netif.eth0 default
+
 
# ##i##echo template=dhcpcd > /etc/conf.d/netif.eth0
+
Mount the iso
# ##i##rc
+
# ##i##mount -o ro,loop /root/sysresccd-4.0.0_zfs_0.6.2.iso /tmp/loop
 +
 
 +
Run the usb installer
 +
# ##i##/tmp/loop/usb_inst.sh
 
</console>
 
</console>
  
The last command, <tt>rc</tt>, causes <tt>netif.eth0</tt> to be started.
+
That should be all you need to do to get your flash drive working.
  
=== Server Network Configuration ===
+
When you are booting into system rescue cd, make sure you select the '''alternative 64 bit kernel'''. ZFS support was specifically added to the alternative 64 bit kernel rather than the standard 64 bit kernel.
  
For servers and advanced networking scenarios, Funtoo Linux offers its own modular, template-based network configuration system. This system offers a lot of flexibility for configuring network interfaces, essentially serving as a &quot;network interface construction kit.&quot; This system can be used by itself, or even combined with <tt>dhcpcd</tt>, as shown in the previous section.
+
== 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.
  
Here are the key components of the template-based network configuration system:
+
We will be showing you how to partition it '''manually''' because if you partition it manually you get to create your own layout, you get to have your own separate /boot partition (Which is nice since not every bootloader supports booting from ZFS pools), and you get to boot into RAID10, RAID5 (RAIDZ) pools and any other layouts due to you having a separate /boot partition.
  
;<tt>/etc/init.d/netif.lo</tt>: An init script that configures the localhost interface. This script is always enabled and is part of the boot process.
+
==== gdisk (GPT Style) ====
;<tt>/etc/netif.d</tt>: This is a directory that contains various network configuration templates. Each of these templates is focused on configuring a particular type of network interface, such as a general static IP-based interface, a bridge interface, a bond interface, etc.
+
;<tt>/etc/init.d/netif.tmpl</tt>: This is the master init script for the template-based network configuration system. New interfaces are added to your system by creating '''symbolic links''' to this file in <tt>/etc/init.d</tt>.
+
  
So, if you wanted to use this system to configure <tt>eth0</tt> with a static IP address, you would create a <tt>netif.eth0</tt> symlink to <tt>netif.tmpl</tt> as follows:
+
'''A Fresh Start''':
  
<console># ##i##cd /etc/init.d
+
First lets make sure that the disk is completely wiped from any previous disk labels and partitions.
# ##i##ln -s netif.tmpl netif.eth0</console>
+
We will also assume that <tt>/dev/sda</tt> is the target drive.<br />
Then, you would create an <tt>/etc/conf.d/netif.eth0</tt> configuration file that would specify which template to use from the <tt>/etc/netif.d</tt> directory:
+
  
<pre>
+
<console>
template="interface"
+
# ##i##gdisk /dev/sda
ipaddr="10.0.1.200/24"
+
gateway="10.0.1.1"
+
nameservers="10.0.1.1 10.0.1.2"
+
domain="funtoo.org"
+
</pre>
+
  
To complete our static IP network configuration we would need to:
+
Command: ##i##x ↵
 +
Expert command: ##i##z ↵
 +
About to wipe out GPT on /dev/sda. Proceed?: ##i##y ↵
 +
GPT data structures destroyed! You may now partition the disk using fdisk or other utilities.
 +
Blank out MBR?: ##i##y ↵
 +
</console>
  
<console># ##i##rc-update add netif.eth0 default</console>
+
{{fancywarning|This is a destructive operation. Make sure you really don't want anything on this disk.}}
When configuring your own static network interface, one of <tt>ipaddr</tt> or <tt>ipaddrs</tt> is required and should specify the IP address(es) to configure for this interface, in &quot;a.b.c.d/netmask&quot; format. Optional parameters include <tt>gateway</tt>, which defines a default gateway for your entire network, and if set should specify the gateway's IP address. In addition, <tt>domain</tt> and <tt>nameservers</tt> (space-separated if more than one) can be used to specify DNS information for this interface.
+
  
=== Configuration Variables ===
+
Now that we have a clean drive, we will create the new layout.
  
==== Interface Variables ====
+
'''Create Partition 1''' (boot):
 +
<console>
 +
Command: ##i##n ↵
 +
Partition Number: ##i##↵
 +
First sector: ##i##↵
 +
Last sector: ##i##+250M ↵
 +
Hex Code: ##i##↵
 +
</console>
  
The <tt>ipaddr</tt> and <tt>ipaddrs</tt> variables are supported by the <tt>interface</tt> and <tt>bridge</tt> templates, and are used to specify a single or multiple  IPv4 or IPv6 address(es) for the interface. IP addresses should be specified in 'IP/netmask' format, such as <tt>10.0.0.1/24</tt>. Multiple IP addresses can be specified delimited by whitespace:
+
'''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>
  
<pre>ipaddrs=&quot;10.0.0.1/24 10.0.0.2/24&quot;</pre>
+
'''Create Partition 3''' (ZFS):
 +
<console>Command: ##i##n ↵
 +
Partition Number: ##i##↵
 +
First sector: ##i##↵
 +
Last sector: ##i##↵
 +
Hex Code: ##i##bf00 ↵
  
===== Broadcast Address =====
+
Command: ##i##p ↵
  
By default, a broadcast address will be calculated based on the IP address and network mask. If you need to manually specify a broadcast address, use the following format for your IP address:
+
Number  Start (sector)    End (sector)  Size      Code  Name
 +
  1            2048          514047  250.0 MiB  8300  Linux filesystem
 +
  2          514048          579583  32.0 MiB    EF02  BIOS boot partition
 +
  3          579584      1953525134  931.2 GiB  BF00  Solaris root
  
<pre>
+
Command: ##i##w ↵
ipaddrs="10.0.0.1/24;broadcast=10.0.1.255 10.0.0.2/24"
+
</console>
</pre>
+
  
===== Not Specifying An Address =====
 
  
Note that in some cases, you may choose to '''not''' specify <tt>ipaddr</tt> or <tt>ipaddrs</tt> for a <tt>bridge</tt> template. That is allowed. If you don't want to specify an IP address for a regular interface, you can choose to use the <tt>interface</tt> template without an IP address specified in the config, or use the <tt>interface-noip</tt> template instead, for the sake of clarity.
+
=== Format your boot volume ===
 +
Format your separate <tt>/boot</tt> partition:
 +
<console>
 +
# ##i##mkfs.ext2 /dev/sda1
 +
</console>
  
===== Viewing All Configured IP Addresses =====
+
=== Encryption (Optional) ===
 +
If you want encryption, then create your encrypted vault(s) now by doing the following:
  
Also note that if you specify multiple IPv4 addresses, <tt>ifconfig</tt> will only show the first IP address. To view all IP addresses associated with the interface, use the <tt>ip addr show</tt> command.
+
<console>
 +
# ##i##cryptsetup luksFormat /dev/sda3
 +
# ##i##cryptsetup luksOpen /dev/sda3 vault_1
 +
</console>
  
=== General Variables ===
+
=== Create the zpool ===
 +
We will first create the pool. The pool will be named `tank` 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 tank /dev/sda3</console>
  
The following variables are enabled by default for all network scripts, and if specified will trigger a corresponding configuration action:
+
{{fancyimportant|If you are using encrypted root, change '''/dev/sda3 to /dev/mapper/vault_1'''.}}
  
;<tt>nameservers</tt>: Set DNS nameservers using OpenResolv. Specify multiple IPv4 or IPv6 nameservers like this: &quot;1.2.3.4 1.2.3.5 1.2.3.6&quot;. Please note that OpenResolv treats <tt>127.0.0.1</tt> specially, and it indicates that you are running a local name resolver like <tt>dnsmasq</tt> or <tt>bind</tt>. OpenResolv will ignore all other name servers specified alongside <tt>127.0.0.1</tt>. See <tt>man resolvconf</tt> and <tt>man resolvconf.conf</tt> for additional setup information.
+
{{fancynote| '''ashift<nowiki>=</nowiki>12''' should be use if you have a newer, advanced format disk that has a sector size of 4096 bytes. If you have an older disk with 512 byte sectors, you should use '''ashift<nowiki>=</nowiki>9''' or don't add the option for auto detection.}}
;<tt>search</tt>: Set DNS search information using OpenResolv.
+
;<tt>domain</tt>: Set DNS domain using OpenResolv.
+
;<tt>gateway</tt>: Define a default IPv4 gateway on this interface.
+
;<tt>gateway6</tt>: Define a default IPv6 gateway on this interface.
+
;<tt>route</tt>: Specify a semi-colon delimited list of IPv4 routes to apply when this interface is brought up. Will be appended to <tt>ip -4 route add</tt>.
+
;<tt>route6</tt>: Specify a semi-colon delimited list of IPv6 routes to apply when this interface is brought up. Will be appended to <tt>ip -6 route add</tt>.
+
;<tt>mtu</tt>: Set Maximum Transmit Unit for the interface
+
  
 +
{{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: <tt>/home</tt>, <tt>/var</tt>, <tt>/usr/src</tt>, and <tt>/usr/portage</tt>.
  
==== VLAN Variables ====
+
<console>
 +
Create some empty containers for organization purposes, and make the dataset that will hold /
 +
# ##i##zfs create -p tank/os/funtoo
 +
# ##i##zfs create -o mountpoint=/ tank/os/funtoo/root
  
VLAN support is enabled by default for all network configuration scripts. If a network script has a name in the format <tt>netif.ethX.Y</tt>, then it is assumed to be a VLAN interface referencing trunk <tt>ethX</tt> and VLAN ID <tt>Y</tt>. If you desire a custom name for your VLAN interface, you can name your interface whatever you'd like and specify the following variables in your interface config:
+
Optional, but recommended datasets: /home
 +
# ##i##zfs create -o mountpoint=/home tank/os/funtoo/home
  
;<tt>trunk</tt>: VLAN trunk interface, e.g. &quot;eth0&quot;
+
Optional datasets: /usr/src, /usr/portage/{distfiles,packages}
;<tt>vlan</tt>: VLAN id, e.g. &quot;32&quot;
+
# ##i##zfs create -o mountpoint=/usr/src tank/os/funtoo/src
 +
# ##i##zfs create -o mountpoint=/usr/portage -o compression=off tank/os/funtoo/portage
 +
# ##i##zfs create -o mountpoint=/usr/portage/distfiles tank/os/funtoo/portage/distfiles
 +
# ##i##zfs create -o mountpoint=/usr/portage/packages tank/os/funtoo/portage/packages
 +
</console>
  
==== Bridge / Tap Variables ====
+
=== Create your swap zvol ===
 +
'''Make your swap +1G greater than your RAM. An 8G machine would have 9G of SWAP (This is kinda big though). For machines with this much memory, You could just make it 2G if you don't have any problems.'''
 +
<console>
 +
# ##i##zfs create -o sync=always -o primarycache=metadata -o secondarycache=none -o volblocksize=4K -V 1G tank/swap
 +
</console>
  
The following variables for configuring a functional bridge interface with optional tap interfaces:
+
=== Format your swap zvol ===
 +
<console>
 +
# ##i##mkswap -f /dev/zvol/tank/swap
 +
# ##i##swapon /dev/zvol/tank/swap
 +
</console>
  
;<tt>slaves</tt>: Set slave interfaces of this interface (for bridges, etc.) All slaves will automatically be depended upon, and will also automatically have their <tt>mtu</tt> set to that of the current interface, if an <tt>mtu</tt> is specified for the current interface. This setting is required for the <tt>bond</tt> template and optional for the <tt>bridge</tt> template.
+
Now we will continue to install funtoo.
;<tt>stp</tt>: Enables Spanning Tree Protocol on a bridge interface like this &quot;stp=on&quot;
+
;<tt>forwarding</tt>: Enables forwarding on a bridge interface by calling sysctl; as this interface does not exist when sysctl is called by init, we do it here. If this is disabled, your bridge will not forward traffic back out onto the network. useage: &quot;forwarding=1&quot;
+
;<tt>mac_addr</tt>: Sets a MAC address on a tap interface. This is usefull for avoiding layer2 address collisions when using large numbers of TUN interfaces (KVM, openVPN, ect)
+
  
=== OpenResolv and resolv.conf ===
+
== Installing Funtoo ==
 +
[[Funtoo_Linux_Installation|Download and extract the Funtoo stage3 and continue installation as normal.]]
  
OpenResolv will be used to set DNS information provided by the <tt>nameservers</tt>, <tt>domain</tt> and <tt>search</tt> variables when an interface is brought up. The OpenResolv framework will add entries to <tt>/etc/resolv.conf</tt>, and will also handle removing these entries when the interface is brought down. This way, <tt>/etc/resolv.conf</tt> should always contain current information and should not need to be manually edited by the system administrator. <tt>dhcpcd</tt> will use OpenResolv for updating system DNS information as well.
+
Then once you've extracted the stage3, chroot into your new funtoo environment:
 +
<console>
 +
Go into the directory that you will chroot into
 +
# ##i##cd /mnt/funtoo
  
=== Network-Dependent Services ===
+
Mount your boot drive
 +
# ##i##mount /dev/sda1 /mnt/funtoo/boot
  
One important difference between Gentoo Linux and Funtoo Linux is that, in Funtoo Linux, network-dependent services only strictly depend on <tt>netif.lo</tt>. This means that if another network service requires an interface to be up, such as <tt>samba</tt> requiring <tt>eth0</tt>, then the system administrator must specify this relationship by adding the following line to <tt>/etc/conf.d/samba</tt>:
+
Bind the kernel related directories
 +
# ##i##mount -t proc none /mnt/funtoo/proc
 +
# ##i##mount --rbind /dev /mnt/funtoo/dev
 +
# ##i##mount --rbind /sys /mnt/funtoo/sys
  
<pre>rc_need=&quot;netif.eth0&quot;</pre>
+
Copy network settings
This will have the effect of ensuring that <tt>netif.eth0</tt> is started prior to <tt>samba</tt> and that <tt>samba</tt> is stopped prior to stopping <tt>netif.eth0</tt>.
+
# ##i##cp /etc/resolv.conf /mnt/funtoo/etc/
  
Many network services, especially those that listen on all network intefaces, don't need an <tt>rc_need</tt> line in order to function properly. Avoiding the use of <tt>rc_need</tt> when required will optimize boot times and allow more network services to remain available when network interfaces are brought up and down by the system administrator.
+
chroot into your new funtoo environment
 +
# ##i##env -i HOME=/root TERM=$TERM chroot /mnt/funtoo /bin/bash --login
  
=== Multiple Network Configurations ===
+
Place your mountpoints into your /etc/mtab file
 +
# ##i##cat /proc/mounts > /etc/mtab
  
For information on how to have multiple, independent network configurations, please see [[Stacked Runlevels]].
+
Sync your tree
 +
# ##i##emerge --sync
 +
</console>
  
=== Alternate Configs ===
+
=== Add filesystems to /etc/fstab ===
If you need to run the same service with different configuration parameters depending upon runlevel, then you'll be happy to know that you can specify runlevel-specific conf.d files by appending a <tt>.
+
&lt;runlevel&gt;</tt> suffix. In this particular example, we could imagine a situation where we had two child runlevels named <tt>home</tt> and <tt>work</tt>:
+
  
<pre>/etc/conf.d/netif.eth0.home
+
Before we continue to compile and or install our kernel in the next step, we will edit the <tt>/etc/fstab</tt> file because if we decide to install our kernel through portage, portage will need to know where is your <tt>/boot</tt> so that it can place the files in there. We also need to update <tt>/etc/mtab</tt> so our system knows what is mounted. Edit <tt>/etc/fstab</tt>:
/etc/conf.d/netif.eth0.work</pre>Note that this feature works for all init scripts, not just network configuration scripts.
+
  
=== Interface Renaming ===
+
<pre>
 +
# <fs>                  <mountpoint>    <type>          <opts>          <dump/pass>
  
Funtoo network scripts now support interface renaming, so you can create an interface called <tt>lan</tt> if you would like. To do this, simply specify the MAC address of the interface you would like to rename using the <tt>macaddr</tt> variable:
+
/dev/sda1              /boot          ext2            defaults        0 2
<pre>macaddr=&quot;00:15:17:19:b6:a3&quot;</pre>If this MAC address is part of the <tt>netif.lan</tt> configuration file, then when this interface starts, whatever interface currently has the MAC address of 00:15:17:19:b6:a3 (i.e. <tt>eth5</tt>) will be renamed to <tt>lan</tt> prior to the interface being brought up, and will show up in <tt>ifconfig</tt> and <tt>ip</tt> commands as being an interface named <tt>lan</tt>.
+
/dev/zvol/tank/swap    none            swap            sw              0 0
 +
</pre>
  
=== Basic VLAN Configuration ===
+
== Kernel Configuration ==
 
+
To speed up this step, you can install "bliss-kernel" since it's already properly configured for ZFS and a lot of other configurations. The kernel is also compiled and ready to go. To install {{Package|sys-kernel/bliss-kernel}} type the following:
The standard <tt>interface</tt> template supports VLANs. To use VLAN support, first ensure that your kernel was compiled with VLAN support (the module name is <tt>8021q</tt>) :
+
  
 
<console>
 
<console>
# ##i##grep CONFIG_VLAN /usr/src/linux/.config
+
# ##i##emerge bliss-kernel
CONFIG_VLAN_8021Q=m
+
CONFIG_VLAN_8021Q_GVRP=y
+
 
</console>
 
</console>
  
Then, configure the trunk interface using the <tt>interface-noip</tt> template. Assuming <tt>eth1</tt> is trunked, you would create the file <tt>/etc/conf.d/netif.eth1</tt> with the following contents:
+
Now make sure that your <tt>/usr/src/linux symlink</tt> is pointing to this kernel by typing the following:
 
+
<pre>template=&quot;interface-noip&quot;</pre>
+
 
+
Then, create a network interface symlink for the trunk and add it to your default runlevel:
+
 
+
 
<console>
 
<console>
# ##i##cd /etc/init.d
+
# ##i##eselect kernel list
# ##i##ln -s netif.tmpl netif.eth1
+
Available kernel symlink targets:
# ##i##rc-update add netif.eth1 default
+
[1]  linux-3.10.10-FB.01 *
 
</console>
 
</console>
 +
You should see a star next to the bliss-kernel version you installed. In this case it was 3.10.10-FB.01. If it's not set, you can type '''eselect kernel set #'''.
  
Now, assuming you wanted to configure a VLAN of 32, you would create a config file named <tt>/etc/conf.d/netif.eth1.32</tt> that looks something like this:
+
== Installing the ZFS userspace tools and kernel modules ==
 
+
Emerge {{Package|sys-fs/zfs}}, {{Package|sys-kernel/spl}}, and {{Package|sys-fs/zfs-kmod}}:
<pre>
+
<console># ##i##emerge zfs </console>
template=&quot;interface&quot;
+
Check to make sure that the zfs tools are working, the <code>zpool.cache</code> file that you copied before should be displayed.
ipaddr=&quot;1.2.3.4/24&quot;
+
gateway=&quot;1.2.3.1&quot;# etc...
+
</pre>
+
 
+
Then, create a VLAN network interface symlink and add it to your default runlevel:
+
  
 +
{{Fancynote| SPL stands for: Solaris Porting Layer}}
 
<console>
 
<console>
# ##i##cd /etc/init.d
+
# ##i##zpool status
# ##i##ln -s netif.tmpl netif.eth1.32
+
# ##i##zfs list
# ##i##rc-update add netif.eth1.32 default
+
 
</console>
 
</console>
  
The Funtoo network configuration scripts will automatically recognize the filename <tt>netif.eth1.32</tt> as being VLAN 32 of trunk interface <tt>netif.eth1</tt>.
+
If everything worked, continue.
  
When the VLAN interface is brought up, it will be named <tt>eth1.32</tt>.
+
== Install the bootloader ==
 +
=== GRUB 2 ===
 +
Before you do this, make sure this checklist is followed:
 +
* Installed kernel and kernel modules
 +
* Installed zfs package from the tree
 +
* <code>/dev</code>, <code>/proc</code>, <code>/sys</code> are mounted in the chroot environment
  
=== Custom VLAN Names ===
+
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.
  
However, sometimes you may want to turn off automatic file-based VLAN naming and give your VLAN interface a custom name, such as <tt>mgmt</tt>. To do this, you would set up the trunk interface in the exact same way as described above, but instead of creating a <tt>netif.eth1.32</tt> interface, you would create a <tt>netif.mgmt</tt> interface, and specify <tt>vlan</tt> and <tt>trunk</tt> in the <tt>/etc/conf.d/netif.mgmt</tt> config file, as follows:
+
<console># ##i##echo "sys-boot/grub libzfs" >> /etc/portage/package.use</console>
  
<pre>template=&quot;interface&quot;
+
Then we will compile grub2:
vlan=&quot;32&quot;
+
trunk=&quot;eth1&quot;
+
ipaddr=&quot;1.2.3.4/24&quot;
+
gateway=&quot;1.2.3.1&quot;
+
# etc...</pre>
+
When you specify <tt>trunk</tt> and <tt>vlan</tt> in the interface config file, filename-based auto-detecting of VLAN ID and trunk is disabled. Both <tt>trunk</tt> and <tt>vlan</tt> must be specified -- you can't specify just one.
+
  
Then you would simply create a VLAN network interface symlink for <tt>netif.mgmt</tt>:
+
<console># ##i##emerge grub</console>
 
+
<console># ##i##cd /etc/init.d
+
# ##i##ln -s netif.tmpl netif.mgmt
+
# ##i##rc-update add netif.mgmt default</console>
+
When the VLAN interface is brought up, it will be named <tt>mgmt</tt>.
+
 
+
=== Bonding Configuration ===
+
 
+
Bonding allows you to aggregate multiple network interfaces into a single logical network interface, allowing for benefits in throughput as well as resiliency in the case that an individual interface may go down. This example shows how you would create a bonding interface (<tt>mybond</tt>) with a simple static ip setup, containing two slave devices (<tt>eth0</tt> and <tt>eth1</tt>).
+
 
+
First, ensure that your kernel is configured to support bonding (the module name is <tt>bonding</tt>) :
+
  
 +
Once this is done, you can check that grub is version 2.00 by doing the following command:
 
<console>
 
<console>
$ ##i##grep CONFIG_BONDING /usr/src/linux/.config
+
# ##i##grub-install --version
CONFIG_BONDING=m
+
grub-install (GRUB) 2.00
 
</console>
 
</console>
  
You'l want to ensure that CONFIG_BONDING is set to "m" or "y". You can find this kernel configuration option tucked under "Device Drivers" -> "Network Device Support" -> "Bonding driver support".
+
Now try to install {{Package|sys-boot/grub}}:
Be sure that ifenslave is emerged:
+
 
+
 
<console>
 
<console>
emerge ifenslave
+
# ##i##grub-install --recheck /dev/sda
 
</console>
 
</console>
Once bonding is enabled in the kernel, you will need to choose at least two devices to bond together. These will be set up as "slave" interfaces with no IP address.
 
  
 +
You should receive the following message:
 
<console>
 
<console>
# ##i##cd /etc/init.d/
+
Installation finished. No error reported.
# ##i##ln -s netif.tmpl netif.eth0
+
# ##i##ln -s netif.tmpl netif.eth1
+
 
</console>
 
</console>
  
Then, configure the slave interfaces by creating <tt>/etc/conf.d/netif.eth0</tt> and <tt>/etc/conf.d/netif.eth1</tt> with the following contents:
+
If not, then go back to the above checklist.
  
<pre>
+
=== LILO ===
template="interface-noip"
+
Before you do this, make sure the following checklist is followed:
</pre>
+
* <code>/dev</code>, <tt>/proc</tt> and <tt>/sys</tt> are mounted.
 +
* Installed the {{Package|sys-fs/zfs}} package from the tree.
 +
Once the above requirements are met, LILO can be installed.
  
Now, we will create the bond interface and make <tt>netif.eth0</tt> and <tt>netif.eth1</tt> slaves of this interface. Note that our bond interface can have any name. To demonstrate this, we will give it the name of "mybond" below:
+
Now we will install {{Package|sys-boot/lilo}}.
 +
<console># ##i##emerge sys-boot/lilo</console>
 +
Once the installation of LILO is complete we will need to edit the <tt>/etc/lilo.conf</tt> file:
  
<console>
 
# ##i##ln -s netif.tmpl netif.mybond
 
# ##i##rc-update add netif.mybond default
 
</console>
 
 
Now we can configure "mybond" using its configuration file <tt>/etc/conf.d/netif.mybond</tt>, just as we would a regular interface, except that we specify <tt>slaves</tt>:
 
  
 
<pre>
 
<pre>
template="bond"
+
boot=/dev/sda
ipaddr="10.0.1.200/24"
+
prompt
gateway="10.0.1.1"
+
timeout=4
nameservers="10.0.1.1 10.0.1.2"
+
default=Funtoo
domain="funtoo.org"
+
slaves="netif.eth0 netif.eth1"
+
</pre>
+
  
In a bonded configuration, it is common to set the MTU to the maximum possible value supported by hardware to maximize throughput. In order to do this, simply set the MTU option in <tt>/etc/conf.d/netif.mybond</tt> to the maximum value supported by your hardware. The network scripts will ensure that this MTU setting is applied to all slave interfaces:
+
image=/boot/bzImage
 
+
      label=Funtoo
<pre>
+
      read-only
mtu=9000
+
      append="root=tank/os/funtoo/root"
 +
      initrd=/boot/initramfs
 
</pre>
 
</pre>
 +
All that is left now is to install the bootcode to the MBR.
  
=== Bridge Configuration ===
+
This can be accomplished by running:
 
+
<console># ##i##/sbin/lilo</console>
When hosting virtual machines, it can be convenient to use a bridge setup. This example shows how you would create a bridge (br0) with a simple static ip setup, containing two slave devices (eth0, tap0).
+
If it is successful you should see:
 +
<console>
 +
Warning: LBA32 addressing assumed
 +
Added Funtoo + *
 +
One warning was issued
 +
</console>
  
First, ensure that your kernel is configured to support bridging (the module name is <tt>bridge</tt>) :
+
== 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>
 
<console>
$ ##i##grep CONFIG_BRIDGE /usr/src/linux/.config
+
# ##i##emerge sys-kernel/genkernel
CONFIG_BRIDGE=m
+
# You only need to add --luks if you used encryption
CONFIG_BRIDGE_IGMP_SNOOPING=y
+
# ##i##genkernel --zfs --luks initramfs
 
</console>
 
</console>
  
Second, make sure you have the required software installed:
+
=== Bliss Initramfs Creator ===
 +
If you are encrypting your drives, then add the "luks" use flag to your package.use before emerging:
  
 
<console>
 
<console>
# ##i##emerge -av bridge-utils usermode-utilities
+
# ##i##echo "sys-kernel/bliss-initramfs luks" >> /etc/portage/package.use
 
</console>
 
</console>
  
Then, create the necessary symlinks for the interfaces and add them to your default runlevel :
+
Now install the creator:
  
 
<console>
 
<console>
# ##i##cd /etc/init.d/
+
# ##i##emerge bliss-initramfs
# ##i##ln -s netif.tmpl netif.eth0
+
# ##i##ln -s netif.tmpl netif.br0
+
# ##i##ln -s netif.tmpl netif.tap0
+
# ##i##rc-update add netif.br0 default
+
# ##i##rc-update add netif.tap0 default
+
 
</console>
 
</console>
  
Then, configure the slave interface <tt>/etc/conf.d/netif.eth0</tt> :
 
  
<pre>
+
Then go into the install directory, run the script as root, and place it into /boot:
template="interface-noip"
+
<console># ##i##cd /opt/bliss-initramfs
</pre>
+
# ##i##./createInit
 +
# ##i##mv initrd-<kernel_name> /boot
 +
</console>
 +
'''<kernel_name>''' is the name of what you selected in the initramfs creator, and the name of the outputted file.
  
Then, configure the slave interface <tt>/etc/conf.d/netif.tap0</tt> - note you only require group OR user, not both :
+
== Using boot-update ==
 +
=== /boot on separate partition ===
 +
If you created a separate non-zfs partition for boot then configuring boot-update is almost exactly the same as a normal install except that auto detection for root does not work. You must tell boot-update what your root is.
 +
==== Genkernel ====
 +
If your using genkernel you must add 'real_root=ZFS=<root>' and 'dozfs' to your params.
 +
Example entry for <tt>/etc/boot.conf</tt>:
  
 
<pre>
 
<pre>
template="tap"
+
"Funtoo ZFS" {
group="kvm"
+
        kernel vmlinuz[-v]
user="kvm"
+
        initrd initramfs-genkernel-x86_64[-v]
mac_addr="10:20:30:40:50:66"
+
        params real_root=ZFS=tank/os/funtoo/root
 +
        params += dozfs=force
 +
        # Also add 'params += crypt_root=/dev/sda3' if you used encryption
 +
        # Adjust the above setting to your system if needed
 +
}
 
</pre>
 
</pre>
  
... and the bridge interface <tt>/etc/conf.d/netif.br0</tt> :
+
==== Bliss Initramfs Creator ====
 +
If you used the Bliss Initramfs Creator then all you need to do is add 'root=<root>' to your params.
 +
Example entry for <tt>/etc/boot.conf</tt>:
  
 
<pre>
 
<pre>
template="bridge"
+
"Funtoo ZFS" {
ipaddr="10.0.1.200/24"
+
        kernel vmlinuz[-v]
gateway="10.0.1.1"
+
        initrd initrd[-v]
nameservers="10.0.1.1 10.0.1.2"
+
        params root=tank/os/funtoo/root quiet
domain="funtoo.org"
+
        # If you have an encrypted device with a regular passphrase,
slaves="netif.eth0 netif.tap0"
+
        # you can add the following line
stp="on"
+
        params += enc_root=/dev/sda3 enc_type=pass
forwarding=1
+
}
 
</pre>
 
</pre>
  
If you are using dhcpcd, you should ensure that it does not attempt to configure <tt>eth0</tt> or <tt>br0</tt> by adding the following to <tt>/etc/dhcpcd.conf</tt> :
+
After editing /etc/boot.conf, you just need to run boot-update to update grub.cfg
 +
<console>
 +
###i## boot-update
 +
</console>
  
<pre>
+
=== /boot on ZFS ===
# don't attempt to pull an ip address for br0 or its slave device
+
TBC - pending update to boot-update to support this
denyinterfaces eth0 br0
+
</pre>
+
  
=== More Complex Network Configuration ===
+
== Final configuration ==
 +
=== Add the zfs tools to openrc ===
 +
<console># ##i##rc-update add zfs boot</console>
  
If the standard templates don't work for your needs, simply create a new template -- I recommend starting from the <tt>interface</tt> template for most things:
+
=== 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># ##i##cd /etc/netif.d
+
<console>
# ##i##cp interface custom</console>
+
Delete the stage3 tarball that you downloaded earlier so it doesn't take up space.
You can now call whatever commands you need to <tt>/etc/netif.d/custom</tt>. The following shell functions can be defined in a network script:
+
# ##i##cd /
 +
# ##i##rm stage3-latest.tar.xz
  
==== netif_create ====
+
Set your root password
 +
# ##i##passwd
 +
>> Enter your password, you won't see what you are writing (for security reasons), but it is there!
  
In <tt>netif_create</tt>, you should call any commands to create the interface if it does not yet exist.
+
Get out of the chroot environment
 +
# ##i##exit
  
==== netif_depend ====
+
Unmount all the kernel filesystem stuff and boot (if you have a separate /boot)
 +
# ##i##umount -l proc dev sys boot
  
In <tt>netif_depend</tt>, you can define dependencies, using the functions <tt>need</tt> and <tt>use</tt>.
+
Turn off the swap
 +
# ##i##swapoff /dev/zvol/tank/swap
  
==== netif_pre_up ====
+
Export the zpool
 +
# ##i##cd /
 +
# ##i##zpool export tank
  
In <tt>netif_pre_up</tt>, you can define network configuration actions to perform prior to bringing the interface up. You can also ensure certain variables are specified by calling <tt>require var1 [var2...]</tt> here.
+
Reboot
 +
# ##i##reboot
 +
</console>
  
==== netif_post_up====
+
{{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.'''}}
  
In <tt>netif_post_up</tt>, you can define network configuration actions to perform after bringing the interface up.
+
and that should be enough to get your system to boot on ZFS.
  
==== netif_pre_down ====
+
== After reboot ==
 +
=== Create initial ZFS Snapshot ===
 +
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.
  
In <tt>netif_pre_down</tt>, you can define network configuration actions to perform prior to bringing the interface down.
+
To take the snapshot of your system, type the following:
 +
<console># ##i##zfs snapshot -r tank@install</console>
  
==== netif_post_down ====
+
To see if your snapshot was taken, type:
 +
<console># ##i##zfs list -t snapshot</console>
  
In <tt>netif_post_down</tt>, you can define network configuration actions to perform after bringing the interface down.
+
If your machine ever fails and you need to get back to this state, just type (This will only revert your / dataset while keeping the rest of your data intact):
 +
<console># ##i##zfs rollback tank/os/funtoo/root@install</console>
  
==== netif_destroy ====
+
{{fancyimportant|'''For a detailed overview, presentation of ZFS' capabilities, as well as usage examples, please refer to the [[ZFS_Fun|ZFS Fun]] page.'''}}
  
In <tt>netif_destroy</tt>, you can call any commands necessary to destroy/delete the interface if it is dynamic in nature (tun/tap, etc.)
+
[[Category:HOWTO]]
 +
[[Category:Filesystems]]
 +
[[Category:Featured]]
  
==== How It Works ====
+
__NOTITLE__
 
+
You do not specify a function for actually bringing up the interface, because the template-based system does this for you. The template-based system also performs all normal actions required to bring an interface down, so you only need to specify atypical actions that must be performed - such as removing child interfaces or destroying a bridge using <tt>brctl</tt>.
+
 
+
When you create your own network configuration template, the following capabilities are available for use automatically, as long as the appropriate variables are set in the <tt>/etc/conf.d/netif.&lt;ifname&gt;</tt> file, without requiring any explicit steps on your part:
+
 
+
* DNS configuration using <tt>domain</tt> and <tt>nameservers</tt> config settings. OpenResolv is used automatically.
+
* VLAN configuration using auto-naming (<tt>netif.ethX.Y</tt>) or via custom naming with <tt>trunk</tt> and <tt>vlan</tt> config settings.
+
* Default IPv4 gateway and route configuration using the <tt>gateway</tt> and <tt>route</tt> settings.
+
* Default IPv6 gateway and route configuration using the <tt>gateway6</tt> and <tt>route6</tt> settings.
+
* MTU configuration using the <tt>mtu</tt> setting.
+
* Auto-depend (and auto-MTU configuration) of slave interfaces specified using <tt>slaves</tt> setting.
+
* Renaming of existing network interface (specify MAC address using <tt>macaddr</tt> setting).
+
 
+
To take advantage of this functionality, simply enable the appropriate variables.
+
 
+
All other necessary network configuration and dependency behavior should be defined using the <tt>netif_</tt>-prefix functions described above.
+
 
+
== Wireless Configuration ==
+
 
+
The recommended approach for setting up Wi-Fi under Funtoo Linux is to use NetworkManager. Steps are provided in the [[Funtoo Linux Installation#Wi-Fi|Wi-Fi section of the Funtoo Linux Installation Guide]].
+
 
+
== Other Network Configurations ==
+
 
+
If you have a network configuration template that might be useful to others, please post it to the [http://groups.google.com/group/funtoo-dev funtoo-dev mailing list] so we can review it and possibly incorporate it into Funtoo.
+
 
+
== License ==
+
 
+
Funtoo Linux networking scripts are released under the following license:
+
 
+
{{BSD2 Funtoo|src=http://github.com/funtoo/corenetwork}}
+
 
+
[[Category:HOWTO]]
+
[[Category:Projects]]
+
[[Category:Networking]]
+
[[Category:Install]]
+
[[Category:Funtoo features]]
+

Revision as of 00:39, 23 February 2014

Contents

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:

  • 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 gained integrated RAID 5/6 functionality in Linux 3.9. However, its implementation uses a stripe cache that can only partially mitigate the effect of the RAID write hole.
  • 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

Warning: This guide is a work in progress. Expect some quirks.
Important: 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:

Downloading the ISO (With ZFS)

In order for us to install Funtoo on ZFS, you will need an environment that provides the ZFS tools. Therefore we will download a customized version of System Rescue CD with ZFS already included. When booting, use the "alternate"-kernel. The ZFS-module won't work with the default kernel.

Name: sysresccd-4.0.0_zfs_0.6.2.iso   (522 MB)
Release Date: 2014-01-18
md5sum 5a6530088e63b516765f78076a2e4859


Download System Rescue CD with ZFS

Creating a bootable USB from ISO

After you download the iso, you can do the following steps to create a bootable USB:

Make a temporary directory
# mkdir /tmp/loop

Mount the iso
# mount -o ro,loop /root/sysresccd-4.0.0_zfs_0.6.2.iso /tmp/loop

Run the usb installer
# /tmp/loop/usb_inst.sh

That should be all you need to do to get your flash drive working.

When you are booting into system rescue cd, make sure you select the alternative 64 bit kernel. ZFS support was specifically added to the alternative 64 bit kernel rather than the standard 64 bit kernel.

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.

We will be showing you how to partition it manually because if you partition it manually you get to create your own layout, you get to have your own separate /boot partition (Which is nice since not every bootloader supports booting from ZFS pools), and you get to boot into RAID10, RAID5 (RAIDZ) pools and any other layouts due to you having a separate /boot partition.

gdisk (GPT Style)

A Fresh Start:

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 ↵
Warning: 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 layout.

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 ↵

Create Partition 3 (ZFS):

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

Command: p ↵

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048          514047   250.0 MiB   8300  Linux filesystem
   2          514048          579583   32.0 MiB    EF02  BIOS boot partition
   3          579584      1953525134   931.2 GiB   BF00  Solaris root

Command: w ↵


Format your boot volume

Format your separate /boot partition:

# mkfs.ext2 /dev/sda1

Encryption (Optional)

If you want encryption, then create your encrypted vault(s) now by doing the following:

# cryptsetup luksFormat /dev/sda3
# cryptsetup luksOpen /dev/sda3 vault_1

Create the zpool

We will first create the pool. The pool will be named `tank` 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 tank /dev/sda3
Important: If you are using encrypted root, change /dev/sda3 to /dev/mapper/vault_1.
Note: ashift=12 should be use if you have a newer, advanced format disk that has a sector size of 4096 bytes. If you have an older disk with 512 byte sectors, you should use ashift=9 or don't add the option for auto detection.
Note: 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 -p tank/os/funtoo
# zfs create -o mountpoint=/ tank/os/funtoo/root

Optional, but recommended datasets: /home
# zfs create -o mountpoint=/home tank/os/funtoo/home

Optional datasets: /usr/src, /usr/portage/{distfiles,packages}
# zfs create -o mountpoint=/usr/src tank/os/funtoo/src
# zfs create -o mountpoint=/usr/portage -o compression=off tank/os/funtoo/portage
# zfs create -o mountpoint=/usr/portage/distfiles tank/os/funtoo/portage/distfiles
# zfs create -o mountpoint=/usr/portage/packages tank/os/funtoo/portage/packages

Create your swap zvol

Make your swap +1G greater than your RAM. An 8G machine would have 9G of SWAP (This is kinda big though). For machines with this much memory, You could just make it 2G if you don't have any problems.

# zfs create -o sync=always -o primarycache=metadata -o secondarycache=none -o volblocksize=4K -V 1G tank/swap

Format your swap zvol

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

Now we will continue to install funtoo.

Installing Funtoo

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

Then once you've extracted the stage3, chroot into your new funtoo environment:

Go into the directory that you will chroot into
# cd /mnt/funtoo

Mount your boot drive
# mount /dev/sda1 /mnt/funtoo/boot

Bind the kernel related directories
# mount -t proc none /mnt/funtoo/proc
# mount --rbind /dev /mnt/funtoo/dev
# mount --rbind /sys /mnt/funtoo/sys

Copy network settings
# cp /etc/resolv.conf /mnt/funtoo/etc/

chroot into your new funtoo environment
# env -i HOME=/root TERM=$TERM chroot /mnt/funtoo /bin/bash --login

Place your mountpoints into your /etc/mtab file
# cat /proc/mounts > /etc/mtab

Sync your tree
# emerge --sync

Add filesystems to /etc/fstab

Before we continue to compile and or install our kernel in the next step, we will edit the /etc/fstab file because if we decide to install our kernel through portage, portage will need to know where is your /boot so that it can place the files in there. We also need to update /etc/mtab so our system knows what is mounted. Edit /etc/fstab:

# <fs>                  <mountpoint>    <type>          <opts>          <dump/pass>

/dev/sda1               /boot           ext2            defaults        0 2
/dev/zvol/tank/swap     none            swap            sw              0 0

Kernel Configuration

To speed up this step, you can install "bliss-kernel" since it's already properly configured for ZFS and a lot of other configurations. The kernel is also compiled and ready to go. To install sys-kernel/bliss-kernel type the following:

# emerge bliss-kernel

Now make sure that your /usr/src/linux symlink is pointing to this kernel by typing the following:

# eselect kernel list
Available kernel symlink targets:
[1]   linux-3.10.10-FB.01 *

You should see a star next to the bliss-kernel version you installed. In this case it was 3.10.10-FB.01. If it's not set, you can type eselect kernel set #.

Installing the ZFS userspace tools and kernel modules

Emerge sys-fs/zfs, sys-kernel/spl, and sys-fs/zfs-kmod:

# emerge zfs 

Check to make sure that the zfs tools are working, the zpool.cache file that you copied before should be displayed.

Note: SPL stands for: Solaris Porting Layer
# zpool status
# zfs list

If everything worked, continue.

Install the bootloader

GRUB 2

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:

# emerge 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 sys-boot/grub:

# grub-install --recheck /dev/sda

You should receive the following message:

Installation finished. No error reported.

If not, then go back to the above checklist.

LILO

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

  • /dev, /proc and /sys are mounted.
  • Installed the sys-fs/zfs package from the tree.

Once the above requirements are met, LILO can be installed.

Now we will install sys-boot/lilo.

# emerge sys-boot/lilo

Once the installation of LILO is complete we will need to edit the /etc/lilo.conf file:


boot=/dev/sda
prompt
timeout=4
default=Funtoo

image=/boot/bzImage
      label=Funtoo
      read-only
      append="root=tank/os/funtoo/root"
      initrd=/boot/initramfs

All that is left now is to install the bootcode to the MBR.

This can be accomplished by running:

# /sbin/lilo

If it is successful you should see:

Warning: LBA32 addressing assumed
Added Funtoo + *
One warning was issued

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 sys-kernel/genkernel
# You only need to add --luks if you used encryption
# genkernel --zfs --luks initramfs

Bliss Initramfs Creator

If you are encrypting your drives, then add the "luks" use flag to your package.use before emerging:

# echo "sys-kernel/bliss-initramfs luks" >> /etc/portage/package.use

Now install the creator:

# emerge bliss-initramfs


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

# cd /opt/bliss-initramfs
# ./createInit
# mv initrd-<kernel_name> /boot

<kernel_name> is the name of what you selected in the initramfs creator, and the name of the outputted file.

Using boot-update

/boot on separate partition

If you created a separate non-zfs partition for boot then configuring boot-update is almost exactly the same as a normal install except that auto detection for root does not work. You must tell boot-update what your root is.

Genkernel

If your using genkernel you must add 'real_root=ZFS=<root>' and 'dozfs' to your params. Example entry for /etc/boot.conf:

"Funtoo ZFS" {
        kernel vmlinuz[-v]
        initrd initramfs-genkernel-x86_64[-v]
        params real_root=ZFS=tank/os/funtoo/root
        params += dozfs=force
        # Also add 'params += crypt_root=/dev/sda3' if you used encryption
        # Adjust the above setting to your system if needed
}

Bliss Initramfs Creator

If you used the Bliss Initramfs Creator then all you need to do is add 'root=<root>' to your params. Example entry for /etc/boot.conf:

"Funtoo ZFS" {
        kernel vmlinuz[-v]
        initrd initrd[-v]
        params root=tank/os/funtoo/root quiet
        # If you have an encrypted device with a regular passphrase,
        # you can add the following line
        params += enc_root=/dev/sda3 enc_type=pass
}

After editing /etc/boot.conf, you just need to run boot-update to update grub.cfg

# boot-update

/boot on ZFS

TBC - pending update to boot-update to support this

Final configuration

Add the zfs tools to openrc

# rc-update add zfs boot

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 tarball that you downloaded earlier so it doesn't take up space.
# cd /
# rm stage3-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)
# umount -l proc dev sys boot

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

Export the zpool
# cd /
# zpool export tank

Reboot
# reboot
Important: 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.

After reboot

Create initial ZFS Snapshot

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 system, type the following:

# zfs snapshot -r tank@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 (This will only revert your / dataset while keeping the rest of your data intact):

# zfs rollback tank/os/funtoo/root@install
Important: For a detailed overview, presentation of ZFS' capabilities, as well as usage examples, please refer to the ZFS Fun page.