Difference between pages "Install/fr/Partitioning" and "ZFS Install Guide"

< Install‎ | fr(Difference between pages)
 
(Genkernel)
 
Line 1: Line 1:
<noinclude>
+
== Introduction ==
{{InstallPart|création et partitionnement des fichiers du système}}
+
</noinclude>
+
=== Préparation du disque ===
+
  
==== Introduction ====
+
This tutorial will show you how to install Funtoo on ZFS (rootfs). This tutorial is meant to be an "overlay" over the [[Funtoo_Linux_Installation|Regular Funtoo Installation]]. Follow the normal installation and only use this guide for steps 2, 3, and 8.
  
Il fut un temps où il n'y avait qu'une seule façon de démarrer un PC compatible. Tous les postes de travail ainsi que les serveurs utilisaient un BIOS standard. Le Master Boot Records se retrouvait sur tous les disques durs et le partitionnement reposait sur un schéma MBR.
+
=== Introduction to ZFS ===
  
Les temps ont bien changé depuis. La technologie évoluant, de nouveaux firmwares, EFI et UEFI, sont apparus. Ils sont conçus pour amorcer les systèmes d'exploitation et pour prendre en charge le mode de partitionnement GPT. Celui-ci supporte le partitionnement des disques de très grande capacité, 2,2 To et plus. Nous nous retrouvons ainsi devant un large éventail d'options pour démarrer un système d'exploitation. Ce qui était jadis unique et simple apporte maintenant son lot de complexité.
+
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:
  
Regardons d'un peu plus près les options d'amorçage disponibles. Ce guide d'installation utilise et recommande la méthode dite de la vieille école, soit le démarrage BIOS et le partitionnement MBR. Il n'y a rien de mal là-dedans et ça fonctionne. Si vos disques sont d'une capacité de stockage de 2 To et moins, vous n'aurez aucune contrainte à en utiliser toute leur capacité.
+
* 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.
  
Il y a toutefois des situations où la méthode dite de la vieille école ne se révèle pas optimale. Par exemple, si vous possédez un disque d'une capacité de stockage supérieure à 2 To, le mode de partitionnement MBR vous empêche de profiter de toute cette capacité. Il y a aussi des PC dont la carte mère ne reconnaît pas l'amorçage BIOS. Pour ces raisons, ce guide d'installation traite également de la méthode d'amorçage UEFI.
+
* 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.
  
Nous continuons à recommander la méthode d'amorçage BIOS et le partitionnement MBR sauf si vous avez des raisons de procéder autrement. Nous appelons cette méthode la méthode '''BIOS + GRUB(MBR)'''. C'est la façon traditionnelle de mettre en place un mécanisme d'amorçage 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.
  
Si vous devez utiliser le mode UEFI pour démarrer, nous recommandons de ne pas utiliser le partitionnement MBR. Certaines cartes mère le supportent mais d'autres non. Nous recommandons plutôt l'utilisation de UEFI pour amorcer GRUB qui en retour lancera Linux. Nous référons à cette méthode en l'appelant '''UEFI + GRUB(GPT)'''.
+
* ZFS has the ZFS Intent Log and SLOG devices, which accelerates small synchronous write performance.
  
'''La grande question est : quelle méthode d'amorçage dois-je utiliser ?'''. En voici la réponse.
+
* 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.
  
;Principe #1 - Vieille école: Si vous démarrez votre PC en amorçant sur System Rescue CD et que vous voyez un menu bleu pâle, c'est que l'amorçage se fait en mode BIOS. Cela signifie que vous pouvez lancer Funtoo Linux en utilisant BIOS. Allez-y avec la méthode dite de la vieille école. Par contre si le disque dur est d'une capacité de 2,2 To et plus, il faut alors y aller avec la méthode dite de la nouvelle école. Appliquez le principe #2.
+
* 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.
  
;Principe #2 - Nouvelle école: Le système sur la carte mère est conçu pour le support UEFI quand l'amorçage avec System Rescue CD affiche un menu en noir et blanc. Vous pouvez donc installer Funtoo Linux avec une configuration d'amorçage en mode UEFI. Vous pourriez être capable de configurer un amorçage en mode BIOS, mais essayez UEFI en premier. Fouillez un peu dans la configuration BIOS pour faire les ajustements nécessaires.
+
* ZFS send/receive implementation supports incremental update when doing backups. btrfs' send/receive implementation requires sending the entire snapshot.
  
;Quelle est la grande différence entre Vieille école et Nouvelle école ?: Quand vous appliquez la méthode vieille école, partitionnement MBR, votre partition <code>/boot</code> sera formatée avec le système de fichiers ext2 et les partitions seront créées avec l'utilitaire <code>fdisk</code>. Quand vous y allez avec la méthode nouvelle école, partitionnement GPT et amorçage UEFI, votre partition <code>/boot</code> sera formaté au système de fichiers vfat car UEFI ne reconnaît que celui-ci. Vous utilisez l'utilitaire <code>gdisk</code> pour créer vos partitions selon le mode de partitionnement GPT. L'installation de l'amorceur GRUB se réalise différemment dans le cas d'un démarrage UEFI.
+
* ZFS supports data deduplication, which is a memory hog and only works well for specialized workloads. btrfs has no equivalent.
  
{{Note|'''Certaines cartes mère semblent supporter UEFI, mais ne le font pas.''' Faites quelques recherches. Par exemple, une carte mère va permettre d'amorcer un système en mode UEFI si vous démarrez le PC à partir d'un CD/DVD amorçable. Cette même carte mère refusera d'amorcer la machine en mode UEFI quand le démarrage se fait à partir du disque dur. Cela nous amène à un troisième principe : il faut connaître notre matériel.}}
+
* ZFS datasets have a hierarchical namespace while btrfs subvolumes have a flat namespace.
  
==== (BIOS/MBR) Méthode dite de la vieille école ====
+
* 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.
  
{{Note|Appliquez cette méthode si vous démarrez en mode BIOS et si le menu initial de System Rescue CD est bleu pâle. Si vous devez plutôt appliquer la méthode dite de la vieille école, [[#(UEFI/GPT) Méthode dite de la nouvelle école|cliquez ici.]]}}
+
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).
  
===== Préparation =====
+
For a quick tour of ZFS and have a big picture of its common operations you can consult the page [[ZFS Fun]].
  
Vous assurer que vous partitionnerez le bon disque s'avère une très bonne idée. Lancez cette commande et vérifiez que <code>/dev/sda</code> est le dique visé par le partitionnement:
+
=== Disclaimers ===
  
<console>
+
{{fancywarning|This guide is a work in progress. Expect some quirks.}}
# ##i##fdisk -l /dev/sda
+
{{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.
  
Disk /dev/sda: 640.1 GB, 640135028736 bytes, 1250263728 sectors
+
<pre>
Units = sectors of 1 * 512 = 512 bytes
+
Name: sysresccd-4.2.0_zfs_0.6.2.iso  (545 MB)
Sector size (logical/physical): 512 bytes / 512 bytes
+
Release Date: 2014-02-25
I/O size (minimum/optimal): 512 bytes / 512 bytes
+
md5sum 01f4e6929247d54db77ab7be4d156d85
Disk label type: gpt
+
</pre>
  
  
#        Start          End    Size  Type            Name
+
'''[http://ftp.osuosl.org/pub/funtoo/distfiles/sysresccd/ Download System Rescue CD with ZFS]'''<br />
1        2048  1250263694  596.2G  Linux filesyste Linux filesystem
+
</console>
+
  
Une recommandation dicte que vous devez effacer toute trace d'une table de partitions existante, MBR ou GPT. Vous prévenez ainsi toute confusion de la part du système BIOS lors du démarrage. Nous lançons<code>sgdisk</code> pour achever cette tâche.
+
== 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:
{{Warning|Cette opération rend impossible l'accès au contenu du disque. Sauvegardez vos données importantes et critiques.}}
+
  
 
<console>
 
<console>
# ##i##sgdisk --zap-all /dev/sda
+
Make a temporary directory
 +
# ##i##mkdir /tmp/loop
  
Creating new GPT entries.
+
Mount the iso
GPT data structures destroyed! You may now partition the disk using fdisk or
+
# ##i##mount -o ro,loop /root/sysresccd-4.2.0_zfs_0.6.2.iso /tmp/loop
other utilities.
+
 
 +
Run the usb installer
 +
# ##i##/tmp/loop/usb_inst.sh
 
</console>
 
</console>
  
Ne vous préoccupez pas du message suivant. La commande a effectué la requête avec succès.
+
That should be all you need to do to get your flash drive working.
  
<console>
+
== Booting the ISO ==
***************************************************************
+
Found invalid GPT and valid MBR; converting MBR to GPT format
+
in memory.
+
***************************************************************
+
</console>
+
  
===== Partitionnement =====
+
{{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.'''}}
  
Maintenant utilisons <code>fdisk</code> pour créer les partitions et la table de partitions MBR:
+
== 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.
  
{{Note|Vous pouvez séparer les données du système de vos données personnelles en créant une partition /home en plus de la partition racine.}}
+
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 <tt>/dev/sda</tt> is the target drive.<br />
  
 
<console>
 
<console>
# ##i##fdisk /dev/sda
+
# ##i##sgdisk -Z /dev/sda
 
</console>
 
</console>
  
Dans le shell <code>fdisk</code>, suivez ces étapes:
+
{{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.}}
  
'''Vidage de la table des partitions''':
+
Now that we have a clean drive, we will create the new layout.
 +
 
 +
First open up the application:
  
 
<console>
 
<console>
Command (m for help): ##i##o ↵
+
# ##i##gdisk /dev/sda
 
</console>
 
</console>
  
'''Création de la 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>
  
'''Création de la partition 2''' (swap):
+
'''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>
  
<console>
+
'''Create Partition 3''' (ZFS):
Command (m for help): ##i##n ↵
+
<console>Command: ##i##n ↵
Partition type (default p): ##i##↵
+
Partition Number: ##i##↵
Partition number (2-4, default 2): ##i##↵
+
 
First sector: ##i##↵
 
First sector: ##i##↵
Last sector: ##i##+2G
+
Last sector: ##i##↵
Command (m for help): ##i##t ↵  
+
Hex Code: ##i##bf00
Partition number (1,2, default 2): ##i## ↵
+
 
Hex code (type L to list all codes): ##i##82
+
Command: ##i##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: ##i##w
 
</console>
 
</console>
  
'''Création de la partition racine:'''
+
 
 +
=== Format your /boot partition ===
  
 
<console>
 
<console>
Command (m for help): ##i##n ↵
+
# ##i##mkfs.ext2 -m 1 /dev/sda1
Partition type (default p): ##i##
+
Partition number (3,4, default 3): ##i##↵
+
First sector: ##i##↵
+
Last sector: ##i##↵
+
 
</console>
 
</console>
  
'''Vérification de la table des partitions:'''
+
=== 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>
 +
 
 +
=== 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>.
  
 
<console>
 
<console>
Command (m for help): ##i##p
+
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
  
Disk /dev/sda: 298.1 GiB, 320072933376 bytes, 625142448 sectors
+
Optional, but recommended datasets: /home
Units: sectors of 1 * 512 = 512 bytes
+
# ##i##zfs create -o mountpoint=/home tank/funtoo/home
Sector size (logical/physical): 512 bytes / 512 bytes
+
I/O size (minimum/optimal): 512 bytes / 512 bytes
+
Disklabel type: dos
+
Disk identifier: 0x82abc9a6
+
  
Device    Boot    Start      End    Blocks  Id System
+
Optional datasets: /usr/src, /usr/portage/{distfiles,packages}
/dev/sda1          2048    264191    131072  83 Linux
+
# ##i##zfs create -o mountpoint=/usr/src tank/funtoo/src
/dev/sda2        264192  4458495  2097152  82 Linux swap / Solaris
+
# ##i##zfs create -o mountpoint=/usr/portage -o compression=off tank/funtoo/portage
/dev/sda3        4458496 625142447 310341976  83 Linux
+
# ##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>
  
'''Enregistrement de la table des partitions:'''
+
=== 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.
  
 
<console>
 
<console>
Command (m for help): ##i##w
+
# ##i##zfs create -o sync=always -o primarycache=metadata -o secondarycache=none -o volblocksize=4K -V 2G tank/swap
 
</console>
 
</console>
 +
{{fancywarning|ZFS swap is not stable and should be used with precautions.}}
  
{{Note|Partitionnement terminé! Maintenant allez à [[#Création des systèmes de fichier (formatage)|Création des systèmes de fichier]].}}
+
=== Format your swap zvol ===
 +
<console>
 +
# ##i##mkswap -f /dev/zvol/tank/swap
 +
# ##i##swapon /dev/zvol/tank/swap
 +
</console>
  
==== (UEFI/GPT) Méthode dite de la nouvelle école ====
+
Now we will continue to install funtoo.
  
{{Note|Appliquez cette méthode si vous démarrez en mode UEFI et que le menu initial de System Rescue CD s'affiche en noir et blanc.}}
+
== Installing Funtoo ==
  
Les commandes <tt>gdisk</tt> pour créer une table de partitions GPT sont présentées ci-après. Adaptez les tailles si nécessaire bien que les valeurs par défaut répondent aux besoins de la majorité des utilisateurs . Lancez <code>gdisk</code>:
+
=== Pre-Chroot ===
 
+
{{Note|Vous pouvez séparer les données du système de vos données personnelles en créant une partition /home en plus de la partition racine.}}
+
  
 
<console>
 
<console>
# ##i##gdisk
+
Go into the directory that you will chroot into
 +
# ##i##cd /mnt/funtoo
 +
 
 +
Make a boot folder and mount your boot drive
 +
# ##i##mkdir boot
 +
# ##i##mount /dev/sda1 boot
 
</console>
 
</console>
  
Dans le shell <tt>gdisk</tt>, suivez ces étapes:
+
[[Funtoo_Linux_Installation|Now download and extract the Funtoo stage3 ...]]
  
'''Création d'une table de partitions vide''' (Ceci '''effacera''' toutes les données du disque quand la table sera enregistrée):
+
Once you've extracted the stage3, do a few more preparations and chroot into your new funtoo environment:
  
 
<console>
 
<console>
Command: ##i##o ↵
+
Bind the kernel related directories
This option deletes all partitions and creates a new protective MBR.
+
# ##i##mount -t proc none proc
Proceed? (Y/N): ##i##y ↵
+
# ##i##mount --rbind /dev dev
 +
# ##i##mount --rbind /sys sys
 +
 
 +
Copy network settings
 +
# ##i##cp -f /etc/resolv.conf etc
 +
 
 +
Make the zfs folder in 'etc' and copy your zpool.cache
 +
# ##i##mkdir etc/zfs
 +
# ##i##cp /etc/zfs/zpool.cache etc/zfs
 +
 
 +
Chroot into Funtoo
 +
# ##i##env -i HOME=/root TERM=$TERM chroot . bash -l
 
</console>
 
</console>
  
'''Création de la partition 1''' (boot):
+
=== In Chroot ===
  
 
<console>
 
<console>
Command: ##i##n ↵
+
Create a symbolic link to your mountpoints
Partition Number: ##i##1 ↵
+
# ##i##ln -sf /proc/mounts /etc/mtab
First sector: ##i##
+
 
Last sector: ##i##+500M ↵
+
Sync your tree
Hex Code: ##i##
+
# ##i##emerge --sync
 
</console>
 
</console>
  
'''Création de la partition 2''' (swap):
+
=== 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>:
 +
 
 +
<pre>
 +
# <fs>                  <mountpoint>    <type>          <opts>          <dump/pass>
 +
 
 +
/dev/sda1              /boot          ext2            defaults        0 2
 +
/dev/zvol/tank/swap     none            swap            sw              0 0
 +
</pre>
 +
 
 +
== Kernel Configuration ==
 +
...wip
 +
 
 +
== 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:
  
 
<console>
 
<console>
Command: ##i##n ↵
+
# ##i##emerge zfs
Partition Number: ##i##2 ↵
+
First sector: ##i##↵
+
Last sector: ##i##+4G ↵
+
Hex Code: ##i##8200 ↵
+
 
</console>
 
</console>
  
'''Création de la partition 3''' (root):
+
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>
Command: ##i##n ↵
+
# ##i##zpool status
Partition Number: ##i##3 ↵
+
# ##i##zfs list
First sector: ##i##↵
+
Last sector: ##i##↵##!i## (for rest of disk)
+
Hex Code: ##i##
+
 
</console>
 
</console>
  
Pendant que vous y êtes, tapez "<tt>p</tt>" pour consulet la table de partitions courante. Si vous avez commis une erreur, tapez "<tt>d</tt>" pour supprimer la partition que vous avez créée. Quand votre partitionnement vous satisfait, tapez "<tt>w</tt>" pour enregistrer le partitionnement:
+
If everything worked, continue.
  
'''Enregistrement de la table des partitions''':
+
== Create the initramfs ==
 +
There are two ways to do this, you can use "genkernel" or "bliss-initramfs". Both will be shown.
  
 +
=== genkernel ===
 +
Install genkernel and run it:
 
<console>
 
<console>
Command: ##i##w ↵
+
# ##i##emerge genkernel
Do you want to proceed? (Y/N): ##i##Y ↵
+
 
 +
You only need to add --luks if you used encryption
 +
# ##i##genkernel --zfs --luks initramfs
 
</console>
 
</console>
  
Now, your GPT/GUID partitions have been created, and will show up as the following ''block devices'' under Linux:
+
== Installing & Configuring the Bootloader ==
  
* <tt>/dev/sda1</tt>, which will be used to hold the <tt>/boot</tt> filesystem,
+
=== GRUB 2  ===
* <tt>/dev/sda2</tt>, which will be used for swap space, and
+
<console>
* <tt>/dev/sda3</tt>, which will hold your root filesystem.
+
# ##i##emerge grub
 +
</console>
  
==== Création des systèmes de fichier (formatage) ====
+
You can check that grub is version 2.00 by typing the following command:
  
{{Note|This section covers both BIOS ''and'' UEFI installs. Don't skip it!}}
+
<console>
 +
# ##i##grub-install --version
 +
grub-install (GRUB) 2.00
 +
</console>
  
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.
+
Now install grub to the drive itself (not a partition):
 +
<console>
 +
# ##i##grub-install /dev/sda
 +
</console>
  
Let's keep this simple. Are you using old-school MBR partitions? If so, let's create an ext2 filesystem on /dev/sda1:
+
You should receive the following message:
  
 
<console>
 
<console>
# ##i##mkfs.ext2 /dev/sda1
+
Installation finished. No error reported.
 
</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:
+
You should now see some a grub directory with some files inside your /boot folder:
  
 
<console>
 
<console>
# ##i##mkfs.vfat -F 32 /dev/sda1
+
# ##i##ls -l /boot/grub
 +
total 2520
 +
-rw-r--r-- 1 root root    1024 Jan  4 16:09 grubenv
 +
drwxr-xr-x 2 root root    8192 Jan 12 14:29 i386-pc
 +
drwxr-xr-x 2 root root    4096 Jan 12 14:28 locale
 +
-rw-r--r-- 1 root root 2555597 Feb  4 11:50 unifont.pf2
 
</console>
 
</console>
  
Now, let's create a swap partition. This partition will be used as disk-based virtual memory for your Funtoo Linux system.
+
=== boot-update ===
 +
boot-update comes as a dependency of grub2, so if you already installed grub, it's already on your system!
  
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:
+
==== 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 vmlinuz[-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##mkswap /dev/sda2
+
###i## boot-update
# ##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:
+
=== LILO (Optional if you are using another bootloader) ===
 +
Now that bliss-boot generated the lilo.conf file, move that config file to its appropriate location
 +
and install lilo to the MBR:
  
 
<console>
 
<console>
# ##i##mkfs.ext4 /dev/sda3
+
# ##i##mv lilo.conf /etc
 +
# ##i##lilo
 +
 
 +
You should see the following:
 +
 
 +
Warning: LBA32 addressing assumed
 +
Added Funtoo + *
 +
One warning was issued
 
</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.
</console>
+
# ##i##cd /
 +
# ##i##rm stage3-latest.tar.xz
  
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.
+
Set your root password
 +
# ##i##passwd
 +
>> Enter your password, you won't see what you are writing (for security reasons), but it is there!
  
{{fancywarning|1=
+
Get out of the chroot environment
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.
+
# ##i##exit
}}
+
  
==== Montage des partitions ====
+
Unmount all the kernel filesystem stuff and boot (if you have a separate /boot)
 +
# ##i##umount -l proc dev sys boot
  
Mount the newly-created filesystems as follows, creating <code>/mnt/funtoo</code> as the installation mount point:
+
Turn off the swap
 +
# ##i##swapoff /dev/zvol/tank/swap
  
<console>
+
Export the zpool
# ##i##mkdir /mnt/funtoo
+
# ##i##cd /
# ##i##mount /dev/sda3 /mnt/funtoo
+
# ##i##zpool export tank
# ##i##mkdir /mnt/funtoo/boot
+
 
# ##i##mount /dev/sda1 /mnt/funtoo/boot
+
Reboot
 +
# ##i##reboot
 
</console>
 
</console>
  
Optionally, if you have a separate filesystem for <code>/home</code> or anything else:
+
{{fancyimportant|'''Don't forget to set your root password as stated above before exiting chroot and rebooting. If you don't set the root password, you won't be able to log into your new system.'''}}
  
 +
and that should be enough to get your system to boot on ZFS.
 +
 +
== 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:
 
<console>
 
<console>
# ##i##mkdir /mnt/funtoo/home
+
# ##i##zpool import -f -R /mnt/funtoo tank
# ##i##mount /dev/sda4 /mnt/funtoo/home
+
# ##i##chroot /mnt/funtoo bash -l
 +
# ##i##passwd
 +
# ##i##exit
 +
# ##i##zpool export -f tank
 +
# ##i##reboot
 
</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:
+
==== Using bliss-initramfs ====
 +
If you forgot to reset your password and are using '''bliss-initramfs''', you can add the '''su''' option to your bootloader parameters and the initramfs will throw you into the rootfs of your drive. In there you can run 'passwd' and then type 'exit'. Once you type 'exit', the initramfs will continue to boot your system as normal.
 +
 
 +
=== 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##chmod 1777 /mnt/funtoo/tmp
+
Destroy the pool and any snapshots and datasets it has
 +
# ##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>
 +
 +
Now start the guide again :).
 +
 +
[[Category:HOWTO]]
 +
[[Category:Filesystems]]
 +
[[Category:Featured]]
 +
[[Category:Install]]
 +
 +
__NOTITLE__

Revision as of 15:00, January 5, 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
# mkdir /tmp/loop

Mount the iso
# mount -o ro,loop /root/sysresccd-4.2.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.

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.

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

# 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

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

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

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

Optional datasets: /usr/src, /usr/portage/{distfiles,packages}
# zfs create -o mountpoint=/usr/src tank/funtoo/src
# zfs create -o mountpoint=/usr/portage -o compression=off tank/funtoo/portage
# zfs create -o mountpoint=/usr/portage/distfiles tank/funtoo/portage/distfiles
# 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.

# 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

# mkswap -f /dev/zvol/tank/swap
# 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
# cd /mnt/funtoo

Make a boot folder and mount your boot drive
# mkdir boot
# 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
# mount -t proc none proc
# mount --rbind /dev dev
# mount --rbind /sys sys

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

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

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

In Chroot

Create a symbolic link to your mountpoints
# ln -sf /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 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 sys-fs/zfs (package not on wiki - please add). This package will bring in sys-kernel/spl (package not on wiki - please add), and sys-fs/zfs-kmod (package not on wiki - please add) as its dependencies:

# emerge zfs

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

# zpool status
# zfs list

If everything worked, continue.

Create the initramfs

There are two ways to do this, you can use "genkernel" or "bliss-initramfs". Both will be shown.

genkernel

Install genkernel and run it:

# emerge genkernel

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

Installing & Configuring the Bootloader

GRUB 2

# emerge grub

You can check that grub is version 2.00 by typing the following command:

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

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

# grub-install /dev/sda

You should receive the following message:

Installation finished. No error reported.

You should now see some a grub directory with some files inside your /boot folder:

# ls -l /boot/grub
total 2520
-rw-r--r-- 1 root root    1024 Jan  4 16:09 grubenv
drwxr-xr-x 2 root root    8192 Jan 12 14:29 i386-pc
drwxr-xr-x 2 root root    4096 Jan 12 14:28 locale
-rw-r--r-- 1 root root 2555597 Feb  4 11:50 unifont.pf2

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 vmlinuz[-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

# boot-update

LILO (Optional if you are using another bootloader)

Now that bliss-boot generated the lilo.conf file, move that config file to its appropriate location and install lilo to the MBR:

# mv lilo.conf /etc
# lilo

You should see the following:

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

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

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:

# zpool import -f -R /mnt/funtoo tank
# chroot /mnt/funtoo bash -l
# passwd
# exit
# zpool export -f tank
# reboot

Using bliss-initramfs

If you forgot to reset your password and are using bliss-initramfs, you can add the su option to your bootloader parameters and the initramfs will throw you into the rootfs of your drive. In there you can run 'passwd' and then type 'exit'. Once you type 'exit', the initramfs will continue to boot your system as normal.

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/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
# 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.
# mkfs.ext2 /dev/sda1
# sgdisk -Z /dev/sda

Now start the guide again :).