Difference between pages "Install/ru/Partitioning" and "ZFS as Root Filesystem"

From Funtoo
< Install‎ | ru(Difference between pages)
Jump to navigation Jump to search
 
 
Line 1: Line 1:
<noinclude>
== Introduction ==
{{InstallPart|процесс разбиения диска и создания файловых систем}}
</noinclude>
=== Подготовка жесткого диска ===


В этой части  мы научимся различным способам установки Funtoo Linux -- и загрузки с -- жесткого диска.
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 ===


В прежние времена существовал лишь один способ загрузить PC-совместимый компьютер. Все наши дектопы и сервера имели стандартный PC BIOS, все наши харды использовали MBR и были разбиты используя схему разбивки MBR.  Вот как это все было и нам это нравилось!
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:


Затем появились EFI и UEFI, встроенные программы нового образца наряду со схемой разбивки GPT, поддерживающая диски размером более 2.2TБ. Неожиданно, нам стали доступны различные способы установки и загрузки Линукс систем . То, что было единым методом, стало чем-то более сложным.
* 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.


Воспользуемся моментом и рассмотрим доступные способы конфигурации жесткого диска для загрузки Funtoo Linux. Данное Руководство рекомендует способ "по-старинке" , загрузка BIOS и использование MBR. Данный способ работает (за исключением редких случаев) и всесторонне поддерживается. И в этом нет ничего плохого. Если Ваш жесткий диск 2TБ или меньшего размера это не является препятствием для использования всего дискового пространства.
* 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.


Но, бывают ситуации когда метод "по-старинке"  не является оптимальным. Если Ваш жесткий диск размером более 2TБ , MBR разбивка не сможет обеспечить доступ ко всему дисковому пространству. Это одна из причин.  Вторая причина: существуют  "PC" системы, которые более не поддерживают  BIOS загрузку  и  форсируют UEFI загрузку. Из чувства сострадания к тем, кто попал в затруднение перед выбором, это Руководство также описывает установку и загрузку UEFI систем.
* 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.


Мы всё же рекомендуем разбивку "по-старинке". Загрузчик мы используем для загрузки Линукс в этом руководстве называетсы GRUB, таки образом мы называем метод '''BIOS + GRUB (MBR)''' . Это традиционный способ setting up a PC-compatible system to boot Linux.
* ZFS has the ZFS Intent Log and SLOG devices, which accelerates small synchronous write performance.


If you need to use UEFI to boot, we recommend not using the MBR at all for booting, as some systems support this, but others don't. Instead, we recommend using UEFI to boot GRUB, which in turn will load Linux. We refer to this method as the '''UEFI + GRUB (GPT)''' method.
* 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.


And yes, there are even more methods, some of which are documented on the [[Boot Methods]] page. We used to recommend a '''BIOS + GRUB (GPT)''' method but it is not consistently supported across a wide variety of hardware.
* 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.


'''The big question is -- which boot method should you use?''' Here's how to tell.
* ZFS send/receive implementation supports incremental update when doing backups. btrfs' send/receive implementation requires sending the entire snapshot.


;Principle 1 - Old School: If you can reliably boot System Rescue CD and it shows you an initial light blue menu, you are booting the CD using the BIOS, and it's likely that you can thus boot Funtoo Linux using the BIOS. So, go old-school and use BIOS booting, ''unless'' you have some reason to use UEFI, such as having a >2.2TB system disk. In that case, see Principle 2, as your system may also support UEFI booting.
* ZFS supports data deduplication, which is a memory hog and only works well for specialized workloads. btrfs has no equivalent.


;Principle 2 - New School: If you can reliably boot System Rescue CD and it shows you an initial black and white menu -- congratulations, your system is configured to support UEFI booting. This means that you are ready to install Funtoo Linux to boot via UEFI. Your system may still support BIOS booting, but just be trying UEFI first. You can poke around in your BIOS boot configuration and play with this.
* ZFS datasets have a hierarchical namespace while btrfs subvolumes have a flat namespace.


;What's the Big Difference between Old School and New School?: Here's the deal. If you go with old-school MBR partitions, your <code>/boot</code> partition will be an ext2 filesystem, and you'll use <code>fdisk</code> to create your MBR partitions. If you go with new-school GPT partitions and UEFI booting, your <code>/boot</code> partition will be a vfat filesystem, because this is what UEFI is able to read, and you will use <code>gdisk</code> to create your GPT partitions. And you'll install GRUB a bit differently. That's about all it comes down to, in case you were curious.
* 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.


;Also Note: To install Funtoo Linux to boot via the New School UEFI method, you must boot System Rescue CD using UEFI -- and see an initial black and white screen. Otherwise, UEFI will not be active and you will not be able to set it up!
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).


{{Note|'''Some motherboards may appear to support UEFI, but don't.''' Do your research. For example, the Award BIOS in my Gigabyte GA-990FXA-UD7 rev 1.1 has an option to enable UEFI boot for CD/DVD. '''This is not sufficient for enabling UEFI boot for hard drives and installing Funtoo Linux.''' UEFI must be supported for both removable media (so you can boot System Rescue CD using UEFI) as well as fixed media (so you can boot your new Funtoo Linux installation.) It turns out that later revisions of this board (rev 3.0) have a new BIOS that fully supports UEFI boot.  This may point to a third principle -- know thy hardware.}}
For a quick tour of ZFS and have a big picture of its common operations you can consult the page [[ZFS Fun]].


==== Old-School (BIOS/MBR) Method ====
=== Disclaimers ===


{{Note|Use this method if you are booting using your BIOS, and if your System Rescue CD initial boot menu was light blue. If you're going to use the new-school method, [[#New-School (UEFI/GPT) Method|click here to jump down to UEFI/GPT.]]}}
{{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'''!}}
== Downloading the ISO (With ZFS) ==
In order for us to install Funtoo on ZFS, you will need an environment that already provides the ZFS tools. Therefore we will download a customized version of System Rescue CD with ZFS included.  


===== Preparation =====
<pre>
Name: sysresccd-4.2.0_zfs_0.6.2.iso  (545 MB)
Release Date: 2014-02-25
md5sum 01f4e6929247d54db77ab7be4d156d85
</pre>


First, it's a good idea to make sure that you've found the correct hard disk to partition. Try this command and verify that <code>/dev/sda</code> is the disk that you want to partition:
 
'''[http://ftp.osuosl.org/pub/funtoo/distfiles/sysresccd/ Download System Rescue CD with ZFS]'''<br />
 
== Creating a bootable USB from ISO (From a Linux Environment) ==
After you download the iso, you can do the following steps to create a bootable USB:


<console>
<console>
# ##i##fdisk -l /dev/sda
Make a temporary directory
# ##i##mkdir /tmp/loop


Disk /dev/sda: 640.1 GB, 640135028736 bytes, 1250263728 sectors
Mount the iso
Units = sectors of 1 * 512 = 512 bytes
# ##i##mount -o ro,loop /root/sysresccd-4.2.0_zfs_0.6.2.iso /tmp/loop
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: gpt


Run the usb installer
# ##i##/tmp/loop/usb_inst.sh
</console>


#        Start          End    Size  Type            Name
That should be all you need to do to get your flash drive working.
1        2048  1250263694  596.2G  Linux filesyste Linux filesystem
</console>


Now, it's recommended that you erase any existing MBR or GPT partition tables on the disk, which could confuse the system's BIOS at boot time. We do this using <code>sgdisk</code>:
== Booting the ISO ==
{{fancywarning|This will make any existing partitions inaccessible! You are '''strongly''' cautioned and advised to backup any critical data before proceeding.}}


<console>
{{fancywarning|'''When booting into the ISO, Make sure that you select the "Alternate 64 bit kernel (altker64)". The ZFS modules have been built specifically for this kernel rather than the standard kernel. If you select a different kernel, you will get a fail to load module stack error message.'''}}
# ##i##sgdisk --zap-all /dev/sda


Creating new GPT entries.
== Creating partitions ==
GPT data structures destroyed! You may now partition the disk using fdisk or
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.
other utilities.
</console>


This output is also nothing to worry about, as the command still succeded:
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.


<console>
==== gdisk (GPT Style) ====
***************************************************************
Found invalid GPT and valid MBR; converting MBR to GPT format
in memory.
***************************************************************
</console>


===== Partitioning =====
'''A Fresh Start''':


Now we will use <code>fdisk</code> to create the MBR partition table 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.<br />


<console>
<console>
# ##i##fdisk /dev/sda
# ##i##sgdisk -Z /dev/sda
</console>
</console>


Within <code>fdisk</code>, follow these steps:
{{fancywarning|This is a destructive operation and the program will not ask you for confirmation! Make sure you really don't want anything on this disk.}}
 
Now that we have a clean drive, we will create the new layout.


'''Empty the partition table''':
First open up the application:


<console>
<console>
Command (m for help): ##i##o ↵
# ##i##gdisk /dev/sda
</console>
</console>


'''Create Partition 1''' (boot):
'''Create Partition 1''' (boot):
<console>
<console>
Command (m for help): ##i##n ↵
Command: ##i##n ↵
Partition type (default p): ##i##↵
Partition Number: ##i##↵
Partition number (1-4, default 1): ##i##↵
First sector: ##i##↵
First sector: ##i##↵
Last sector: ##i##+128M
Last sector: ##i##+250M ↵
Hex Code: ##i##
</console>
</console>


'''Create Partition 2''' (swap):
'''Create Partition 2''' (BIOS Boot Partition):
 
<console>Command: ##i##n ↵
<console>
Partition Number: ##i##↵
Command (m for help): ##i##n ↵
Partition type (default p): ##i##↵
Partition number (2-4, default 2): ##i##↵
First sector: ##i##↵
First sector: ##i##↵
Last sector: ##i##+2G ↵
Last sector: ##i##+32M
Command (m for help): ##i##t ↵
Hex Code: ##i##EF02
Partition number (1,2, default 2): ##i##
Hex code (type L to list all codes): ##i##82
</console>
</console>


'''Create the root partition:'''
'''Create Partition 3''' (ZFS):
 
<console>Command: ##i##n ↵
<console>
Partition Number: ##i##↵
Command (m for help): ##i##n ↵
Partition type (default p): ##i##↵
Partition number (3,4, default 3): ##i##↵
First sector: ##i##↵
First sector: ##i##↵
Last sector: ##i##↵
Last sector: ##i##↵
</console>
Hex Code: ##i##bf00 ↵
 
'''Verify the partition table:'''


<console>
Command: ##i##p
Command (m for help): ##i##p


Disk /dev/sda: 298.1 GiB, 320072933376 bytes, 625142448 sectors
Number  Start (sector)   End (sector) Size      Code  Name
Units: sectors of 1 * 512 = 512 bytes
  1            2048          514047  250.0 MiB  8300  Linux filesystem
Sector size (logical/physical): 512 bytes / 512 bytes
  2          514048          579583  32.0 MiB    EF02  BIOS boot partition
I/O size (minimum/optimal): 512 bytes / 512 bytes
  3          579584      1953525134  931.2 GiB  BF00  Solaris root
Disklabel type: dos
Disk identifier: 0x82abc9a6


Device    Boot    Start      End    Blocks  Id System
Command: ##i##w ↵
/dev/sda1          2048    264191    131072  83 Linux
/dev/sda2        264192  4458495  2097152  82 Linux swap / Solaris
/dev/sda3        4458496 625142447 310341976  83 Linux
</console>
</console>


'''Write the parition table to disk:'''
 
=== Format your /boot partition ===


<console>
<console>
Command (m for help): ##i##w
# ##i##mkfs.ext2 -m 1 /dev/sda1
</console>
</console>


Your new MBR partition table will now be written to your system disk.
=== 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>


{{Note|You're done with partitioning! Now, jump over to [[#Creating filesystems|Creating filesystems]].}}
=== 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>.


==== New-School (UEFI/GPT) Method ====
<console>
Create some empty containers for organization purposes, and make the dataset that will hold /
# ##i##zfs create -p tank/funtoo
# ##i##zfs create -o mountpoint=/ tank/funtoo/root


{{Note|Use this method if you are booting using UEFI, and if your System Rescue CD initial boot menu was black and white. If it was light blue, this method will not work.}}
Optional, but recommended datasets: /home
# ##i##zfs create -o mountpoint=/home tank/funtoo/home


The <tt>gdisk</tt> commands to create a GPT partition table are as follows. Adapt sizes as necessary, although these defaults will work for most users. Start <code>gdisk</code>:
Optional datasets: /usr/src, /usr/portage/{distfiles,packages}
 
# ##i##zfs create -o mountpoint=/usr/src tank/funtoo/src
<console>
# ##i##zfs create -o mountpoint=/usr/portage -o compression=off tank/funtoo/portage
# ##i##gdisk
# ##i##zfs create -o mountpoint=/usr/portage/distfiles tank/funtoo/portage/distfiles
# ##i##zfs create -o mountpoint=/usr/portage/packages tank/funtoo/portage/packages
</console>
</console>


Within <tt>gdisk</tt>, follow these steps:
=== Create your swap zvol ===
For modern machines that have greater than 4 GB of RAM, A swap size of 2G should be enough. However if your machine doesn't have a lot of RAM, the rule of thumb is either 2x the RAM or RAM + 1 GB.


'''Create a new empty partition table''' (This ''will'' erase all data on the disk when saved):
For this tutorial we will assume that it is a newer machine and make a 2 GB swap.


<console>
<console>
Command: ##i##o
# ##i##zfs create -o sync=always -o primarycache=metadata -o secondarycache=none -o volblocksize=4K -V 2G tank/swap
This option deletes all partitions and creates a new protective MBR.
Proceed? (Y/N): ##i##y ↵
</console>
</console>
{{fancywarning|ZFS swap is not stable and should be used with precautions.}}


'''Create Partition 1''' (boot):
=== Format your swap zvol ===
 
<console>
<console>
Command: ##i##n ↵
# ##i##mkswap -f /dev/zvol/tank/swap
Partition Number: ##i##1 ↵
# ##i##swapon /dev/zvol/tank/swap
First sector: ##i##
Last sector: ##i##+500M ↵
Hex Code: ##i##
</console>
</console>


'''Create Partition 2''' (swap):
Now we will continue to install funtoo.
 
== Installing Funtoo ==
 
=== Pre-Chroot ===


<console>
<console>
Command: ##i##n ↵
Go into the directory that you will chroot into
Partition Number: ##i##2 ↵
# ##i##cd /mnt/funtoo
First sector: ##i##
 
Last sector: ##i##+4G ↵
Make a boot folder and mount your boot drive
Hex Code: ##i##8200 ↵
# ##i##mkdir boot
# ##i##mount /dev/sda1 boot
</console>
</console>


'''Create Partition 3''' (root):
[[Funtoo_Linux_Installation|Now download and extract the Funtoo stage3 ...]]
 
Once you've extracted the stage3, do a few more preparations and chroot into your new funtoo environment:


<console>
<console>
Command: ##i##n ↵
Bind the kernel related directories
Partition Number: ##i##3 ↵
# ##i##mount -t proc none proc
First sector: ##i##
# ##i##mount --rbind /dev dev
Last sector: ##i####!i## (for rest of disk)
# ##i##mount --rbind /sys sys
Hex Code: ##i##
 
</console>
Copy network settings
# ##i##cp -f /etc/resolv.conf etc


Along the way, you can type "<tt>p</tt>" and hit Enter to view your current partition table. If you make a mistake, you can type "<tt>d</tt>" to delete an existing partition that you created. When you are satisfied with your partition setup, type "<tt>w</tt>" to write your configuration to disk:
Make the zfs folder in 'etc' and copy your zpool.cache
# ##i##mkdir etc/zfs
# ##i##cp /etc/zfs/zpool.cache etc/zfs


'''Write Partition Table To Disk''':
Chroot into Funtoo
# ##i##env -i HOME=/root TERM=$TERM chroot . bash -l
</console>


=== In Chroot ===
Sync your tree
<console>
<console>
Command: ##i##w ↵
# ##i##emerge --sync
Do you want to proceed? (Y/N): ##i##Y ↵
</console>
</console>


The partition table will now be written to disk and <tt>gdisk</tt> will close.
=== Add filesystems to /etc/fstab ===
 
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 our <tt>/boot</tt> is, so that it can place the files in there.  
 
Edit <tt>/etc/fstab</tt>:


Now, your GPT/GUID partitions have been created, and will show up as the following ''block devices'' under Linux:
<pre>
# <fs>                  <mountpoint>    <type>          <opts>          <dump/pass>


* <tt>/dev/sda1</tt>, which will be used to hold the <tt>/boot</tt> filesystem,
/dev/sda1               /boot           ext2            defaults        0 2
* <tt>/dev/sda2</tt>, which will be used for swap space, and
/dev/zvol/tank/swap     none            swap            sw              0 0
* <tt>/dev/sda3</tt>, which will hold your root filesystem.
</pre>


==== Creating filesystems ====
== Kernel Configuration ==
...wip


{{Note|This section covers both BIOS ''and'' UEFI installs. Don't skip it!}}
== Installing the ZFS userspace tools and kernel modules ==
Emerge {{Package|sys-fs/zfs}}. This package will bring in {{Package|sys-kernel/spl}}, and {{Package|sys-fs/zfs-kmod}} as its dependencies:


Before your newly-created partitions can be used, the block devices need to be initialized with filesystem ''metadata''. This process is known as ''creating a filesystem'' on the block devices. After filesystems are created on the block devices, they can be mounted and used to store files.
<console>
# ##i##emerge zfs
</console>


Let's keep this simple. Are you using old-school MBR partitions? If so, let's create an ext2 filesystem on /dev/sda1:
Check to make sure that the zfs tools are working. The <code>zpool.cache</code> file that you copied before should be displayed.


<console>
<console>
# ##i##mkfs.ext2 /dev/sda1
# ##i##zpool status
# ##i##zfs list
</console>
</console>


If you're using new-school GPT partitions for UEFI, you'll want to create a vfat filesystem on /dev/sda1, because this is what UEFI is able to read:
If everything worked, continue.


== Create the initramfs ==
=== genkernel ===
Install genkernel and run it:
<console>
<console>
# ##i##mkfs.vfat -F 32 /dev/sda1
# ##i##emerge genkernel
 
You only need to add --luks if you used encryption
# ##i##genkernel --zfs --luks initramfs
</console>
</console>


Now, let's create a swap partition. This partition will be used as disk-based virtual memory for your Funtoo Linux system.
== Installing & Configuring the Bootloader ==


You will not create a filesystem on your swap partition, since it is not used to store files. But it is necessary to initialize it using the <code>mkswap</code> command. Then we'll run the <code>swapon</code> command to make your newly-initialized swap space immediately active within the live CD environment, in case it is needed during the rest of the install process:
=== GRUB 2  ===
<console>
# ##i##emerge grub
</console>


Now install grub to the drive itself (not a partition):
<console>
<console>
# ##i##mkswap /dev/sda2
# ##i##grub-install /dev/sda
# ##i##swapon /dev/sda2
</console>
</console>


Now, we need to create a root filesystem. This is where Funtoo Linux will live. We generally recommend ext4 or XFS root filesystems. If you're not sure, choose ext4. Here's how to create a root ext4 filesystem:
=== boot-update ===
boot-update comes as a dependency of grub2, so if you already installed grub, it's already on your system!
 
==== 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>
"Funtoo ZFS" {
        kernel kernel[-v]
        initrd initramfs-genkernel-x86_64[-v]
        params real_root=ZFS=tank/funtoo/root
        params += dozfs=force
}
</pre>
 
After editing /etc/boot.conf, you just need to run boot-update to update grub.cfg


<console>
<console>
# ##i##mkfs.ext4 /dev/sda3
###i## boot-update
</console>
</console>


...and here's how to create an XFS root filesystem, if you choose to use XFS:
== Final configuration ==
=== Add the zfs tools to openrc ===
<console># ##i##rc-update add zfs boot</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>
<console>
# ##i##mkfs.xfs /dev/sda3
Delete the stage3 tarball that you downloaded earlier so it doesn't take up space.
# ##i##cd /
# ##i##rm stage3-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##umount -l proc dev sys boot
 
Turn off the swap
# ##i##swapoff /dev/zvol/tank/swap
 
Export the zpool
# ##i##cd /
# ##i##zpool export tank
 
Reboot
# ##i##reboot
</console>
</console>


Your filesystems (and swap) have all now been initialized, so that that can be mounted (attached to your existing directory heirarchy) and used to store files. We are ready to begin installing Funtoo Linux on these brand-new filesystems.
{{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.'''}}


{{fancywarning|1=
and that should be enough to get your system to boot on ZFS.
When deploying an OpenVZ host, please use ext4 exclusively. The Parallels development team tests extensively with ext4, and modern versions of <code>openvz-rhel6-stable</code> are '''not''' compatible with XFS, and you may experience kernel bugs.
}}


==== Mounting filesystems ====
== After reboot ==


Mount the newly-created filesystems as follows, creating <code>/mnt/funtoo</code> as the installation mount point:
=== Forgot to reset password? ===
==== System Rescue CD ====
If you aren't using bliss-initramfs, then you can reboot back into your sysresccd and reset through there by mounting your drive, chrooting, and then typing passwd.


Example:
<console>
<console>
# ##i##mkdir /mnt/funtoo
# ##i##zpool import -f -R /mnt/funtoo tank
# ##i##mount /dev/sda3 /mnt/funtoo
# ##i##chroot /mnt/funtoo bash -l
# ##i##mkdir /mnt/funtoo/boot
# ##i##passwd
# ##i##mount /dev/sda1 /mnt/funtoo/boot
# ##i##exit
# ##i##zpool export -f tank
# ##i##reboot
</console>
</console>


Optionally, if you have a separate filesystem for <code>/home</code> or anything else:
=== 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:
<console># ##i##zfs snapshot -r tank@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 (This will only revert your / dataset while keeping the rest of your data intact):
<console># ##i##zfs rollback tank/funtoo/root@install</console>
 
{{fancyimportant|'''For a detailed overview, presentation of ZFS' capabilities, as well as usage examples, please refer to the [[ZFS_Fun|ZFS Fun]] page.'''}}
 
== Troubleshooting ==
 
=== Starting from scratch ===
If your installation has gotten screwed up for whatever reason and you need a fresh restart, you can do the following from sysresccd to start fresh:


<console>
<console>
# ##i##mkdir /mnt/funtoo/home
Destroy the pool and any snapshots and datasets it has
# ##i##mount /dev/sda4 /mnt/funtoo/home
# ##i##zpool destroy -R -f tank
 
This deletes the files from /dev/sda1 so that even after we zap, recreating the drive in the exact sector
position and size will not give us access to the old files in this partition.
# ##i##mkfs.ext2 /dev/sda1
# ##i##sgdisk -Z /dev/sda
</console>
</console>


If you have <code>/tmp</code> or <code>/var/tmp</code> on a separate filesystem, be sure to change the permissions of the mount point to be globally-writeable after mounting, as follows:
Now start the guide again :).
 
[[Category:HOWTO]]
[[Category:Filesystems]]
[[Category:Featured]]
[[Category:Install]]


<console>
__NOTITLE__
# ##i##chmod 1777 /mnt/funtoo/tmp
</console>

Revision as of 14:24, January 6, 2015

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

For a quick tour of ZFS and have a big picture of its common operations you can consult the page ZFS Fun.

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!

Downloading the ISO (With ZFS)

In order for us to install Funtoo on ZFS, you will need an environment that already provides the ZFS tools. Therefore we will download a customized version of System Rescue CD with ZFS included.

Name: sysresccd-4.2.0_zfs_0.6.2.iso  (545 MB)
Release Date: 2014-02-25
md5sum 01f4e6929247d54db77ab7be4d156d85


Download System Rescue CD with ZFS

Creating a bootable USB from ISO (From a Linux Environment)

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

Make a temporary directory
root # mkdir /tmp/loop

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

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

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

Booting the ISO

   Warning

When booting into the ISO, Make sure that you select the "Alternate 64 bit kernel (altker64)". The ZFS modules have been built specifically for this kernel rather than the standard kernel. If you select a different kernel, you will get a fail to load module stack error message.

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.

root # sgdisk -Z /dev/sda
   Warning

This is a destructive operation and the program will not ask you for confirmation! Make sure you really don't want anything on this disk.

Now that we have a clean drive, we will create the new layout.

First open up the application:

root # gdisk /dev/sda

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 partition

root # mkfs.ext2 -m 1 /dev/sda1

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)

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

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 /
root # zfs create -p tank/funtoo
root # zfs create -o mountpoint=/ tank/funtoo/root

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

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

Create your swap zvol

For modern machines that have greater than 4 GB of RAM, A swap size of 2G should be enough. However if your machine doesn't have a lot of RAM, the rule of thumb is either 2x the RAM or RAM + 1 GB.

For this tutorial we will assume that it is a newer machine and make a 2 GB swap.

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

ZFS swap is not stable and should be used with precautions.

Format your swap zvol

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

Now we will continue to install funtoo.

Installing Funtoo

Pre-Chroot

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

Make a boot folder and mount your boot drive
root # mkdir boot
root # mount /dev/sda1 boot

Now download and extract the Funtoo stage3 ...

Once you've extracted the stage3, do a few more preparations and chroot into your new funtoo environment:

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

Copy network settings
root # cp -f /etc/resolv.conf etc

Make the zfs folder in 'etc' and copy your zpool.cache
root # mkdir etc/zfs
root # cp /etc/zfs/zpool.cache etc/zfs

Chroot into Funtoo
root # env -i HOME=/root TERM=$TERM chroot . bash -l

In Chroot

Sync your tree

root # 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 our /boot is, so that it can place the files in there.

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

...wip

Installing the ZFS userspace tools and kernel modules

Emerge No results. This package will bring in No results, and No results as its dependencies:

root # emerge zfs

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

root # zpool status
root # zfs list

If everything worked, continue.

Create the initramfs

genkernel

Install genkernel and run it:

root # emerge genkernel

You only need to add --luks if you used encryption
root # genkernel --zfs --luks initramfs

Installing & Configuring the Bootloader

GRUB 2

root # emerge grub

Now install grub to the drive itself (not a partition):

root # grub-install /dev/sda

boot-update

boot-update comes as a dependency of grub2, so if you already installed grub, it's already on your system!

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 kernel[-v]
        initrd initramfs-genkernel-x86_64[-v]
        params real_root=ZFS=tank/funtoo/root
        params += dozfs=force
}

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

root # boot-update

Final configuration

Add the zfs tools to openrc

root # 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.
root # cd /
root # rm stage3-latest.tar.xz

Set your root password
root # 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
root # exit

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

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

Export the zpool
root # cd /
root # zpool export tank

Reboot
root # 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

Forgot to reset password?

System Rescue CD

If you aren't using bliss-initramfs, then you can reboot back into your sysresccd and reset through there by mounting your drive, chrooting, and then typing passwd.

Example:

root # zpool import -f -R /mnt/funtoo tank
root # chroot /mnt/funtoo bash -l
root # passwd
root # exit
root # zpool export -f tank
root # 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:

root # zfs snapshot -r tank@install

To see if your snapshot was taken, type:

root # 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):

root # zfs rollback tank/funtoo/root@install
   Important

For a detailed overview, presentation of ZFS' capabilities, as well as usage examples, please refer to the ZFS Fun page.

Troubleshooting

Starting from scratch

If your installation has gotten screwed up for whatever reason and you need a fresh restart, you can do the following from sysresccd to start fresh:

Destroy the pool and any snapshots and datasets it has
root # zpool destroy -R -f tank

This deletes the files from /dev/sda1 so that even after we zap, recreating the drive in the exact sector
position and size will not give us access to the old files in this partition.
root # mkfs.ext2 /dev/sda1
root # sgdisk -Z /dev/sda

Now start the guide again :).