Difference between revisions of "ZFS Install Guide"
Fearedbliss (Talk | contribs) m (→Setting up your environment) |
Fearedbliss (Talk | contribs) m (→Create the zfs datasets: - removed rpool/HOME/root) |
||
| (62 intermediate revisions by 6 users not shown) | |||
| Line 6: | Line 6: | ||
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: | 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. | * 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. | ||
| Line 19: | Line 17: | ||
* 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 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 | + | * 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 send/receive implementation supports incremental update when doing backups. btrfs' send/receive implementation requires sending the entire snapshot. | ||
| Line 35: | Line 33: | ||
to obtain similar benefits (with arguably better data integrity) when | to obtain similar benefits (with arguably better data integrity) when | ||
dealing with many small files (e.g. the portage tree). | dealing with many small files (e.g. the portage tree). | ||
| − | |||
=== Disclaimers === | === Disclaimers === | ||
| Line 46: | Line 43: | ||
As a companion to the install instructions below, a YouTube video ZFS install tutorial is now available: | As a companion to the install instructions below, a YouTube video ZFS install tutorial is now available: | ||
| − | {{#widget:YouTube|id= | + | {{#widget:YouTube|id=kxEdSXwU0ZI|width=640|height=360}} |
| − | == | + | == Downloading the ISO (With ZFS) == |
| − | In order for us to install Funtoo on ZFS, you will need an environment that provides the ZFS tools. | + | 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 SLAX with ZFS SBs (SLAX Bundle) already included. |
| − | + | This is just a file that when combined with SLAX, gives you those tools. | |
| − | + | ||
| − | |||
| − | |||
<pre> | <pre> | ||
| − | Name: | + | Name: SLAX-English-US-7.0.8-x86_64_ZFS.iso (229 MB) |
| − | Release Date: 2013- | + | Release Date: 2013-06-15 |
| − | md5sum | + | md5sum 358e4b3cbec9110de83e5d1779200eeb |
</pre> | </pre> | ||
| − | + | '''[http://ftp.osuosl.org/pub/funtoo/distfiles/slax/SLAX-English-US-7.0.8-x86_64_ZFS.iso Download SLAX 7.0.8 with ZFS]'''<br /> | |
| − | + | ||
| − | [http://ftp.osuosl.org/pub/funtoo/distfiles/ | + | |
| − | + | ||
| − | + | ||
| − | + | ||
== Creating partitions == | == Creating partitions == | ||
There are two ways to partition your disk: You can use your entire drive and let ZFS automatically partition it for you, or you can do it manually. | There are two ways to partition your disk: You can use your entire drive and let ZFS automatically partition it for you, or you can do it manually. | ||
| − | + | 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. | |
| + | |||
| + | ==== fdisk (MBR Style) ==== | ||
| + | |||
| + | '''A Fresh Start''': | ||
| − | |||
| − | |||
| − | |||
First lets make sure that the disk is completely wiped from any previous disk labels and partitions. | First lets make sure that the disk is completely wiped from any previous disk labels and partitions. | ||
We will also assume that <tt>/dev/sda</tt> is the target drive.<br /> | We will also assume that <tt>/dev/sda</tt> is the target drive.<br /> | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
<console> | <console> | ||
| − | + | Command (m for help): ##i##o ↵ | |
| − | + | Building a new DOS disklabel with disk identifier 0xbeead864. | |
| − | + | ||
| − | + | ||
| − | + | ||
</console> | </console> | ||
| + | {{fancywarning|This is a destructive operation. Make sure you really don't want anything on this disk.}} | ||
| − | + | Now that we have a clean drive, we will create the new layout. | |
| − | + | ||
| − | + | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
'''Create Partition 1''' (boot): | '''Create Partition 1''' (boot): | ||
<console> | <console> | ||
| Line 169: | Line 108: | ||
</console> | </console> | ||
| + | ==== 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> | ||
| + | # ##i##gdisk /dev/sda | ||
| + | |||
| + | 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> | ||
| + | |||
| + | {{fancywarning|This is a destructive operation. Make sure you really don't want anything on this disk.}} | ||
| + | |||
| + | Now that we have a clean drive, we will create the new layout. | ||
| − | |||
'''Create Partition 1''' (boot): | '''Create Partition 1''' (boot): | ||
<console> | <console> | ||
| Line 189: | Line 147: | ||
{{fancyimportant|Only make the above BIOS Boot Partition if you are using GRUB 2 on GPT. If you are using the extlinux bootloader, this partition is not necessary.}} | {{fancyimportant|Only make the above BIOS Boot Partition if you are using GRUB 2 on GPT. If you are using the extlinux bootloader, this partition is not necessary.}} | ||
| − | '''Create Partition | + | '''Create Partition 3''' (ZFS): |
<console>Command: ##i##n ↵ | <console>Command: ##i##n ↵ | ||
Partition Number: ##i##↵ | Partition Number: ##i##↵ | ||
First sector: ##i##↵ | First sector: ##i##↵ | ||
Last sector: ##i##↵ | Last sector: ##i##↵ | ||
| − | Hex Code: ##i## | + | Hex Code: ##i##bf00 ↵ |
Command: ##i##p ↵ | Command: ##i##p ↵ | ||
| − | Number Start (sector) End (sector) Size Code Name | + | Number Start (sector) End (sector) Size Code Name |
| − | 1 2048 514047 250.0 MiB 8300 Linux filesystem | + | 1 2048 514047 250.0 MiB 8300 Linux filesystem |
| − | 2 514048 1953525134 931. | + | 2 514048 579583 32.0 MiB EF02 BIOS boot partition |
| + | 3 579584 1953525134 931.2 GiB BF00 Solaris root | ||
Command: ##i##w ↵ | Command: ##i##w ↵ | ||
| Line 207: | Line 166: | ||
=== Format your boot volume === | === Format your boot volume === | ||
| − | + | Format your separate /boot partition: | |
| − | <console># ##i##mkfs. | + | <console># ##i##mkfs.ext2 /dev/sda1</console> |
| + | === Encryption (Optional) === | ||
| + | If you want encryption, then create your encrypted vault(s) now by doing the following: | ||
| + | |||
| + | <console> | ||
| + | # ##i##cryptsetup -c aes-xts-plain64 luksFormat /dev/sda2 | ||
| + | # ##i##cryptsetup luksOpen /dev/sda2 vault_1 | ||
| + | </console> | ||
| + | |||
| + | {{fancyimportant|If you followed the manual GPT partitioning instructions, you should change '''/dev/sda2 to /dev/sda3'''.}} | ||
=== Create the zpool === | === Create the zpool === | ||
We will first create the pool. The pool will be named `rpool` and the disk will be aligned to 4096 (using ashift=12) | We will first create the pool. The pool will be named `rpool` and the disk will be aligned to 4096 (using ashift=12) | ||
| − | |||
<console># ##i##zpool create -f -o ashift=12 -o cachefile= -O compression=on -m none -R /mnt/funtoo rpool /dev/sda2</console> | <console># ##i##zpool create -f -o ashift=12 -o cachefile= -O compression=on -m none -R /mnt/funtoo rpool /dev/sda2</console> | ||
| − | |||
| + | {{fancyimportant|If you followed the manual GPT partitioning instructions, you should change '''/dev/sda2 to /dev/sda3'''. If you are using encrypted root, then change '''/dev/sda2 to vault_1'''.}} | ||
| + | |||
| + | {{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 === | === 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. | 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. | ||
| Line 222: | Line 191: | ||
<console> | <console> | ||
Create some empty containers for organization purposes, and make the dataset that will hold / | Create some empty containers for organization purposes, and make the dataset that will hold / | ||
| − | # ##i##zfs create | + | # ##i##zfs create rpool/ROOT |
# ##i##zfs create -o mountpoint=/ rpool/ROOT/funtoo | # ##i##zfs create -o mountpoint=/ rpool/ROOT/funtoo | ||
| − | Optional, but recommended | + | Optional, but recommended dataset: /home |
# ##i##zfs create -o mountpoint=/home rpool/HOME | # ##i##zfs create -o mountpoint=/home rpool/HOME | ||
| − | # ##i##zfs create -o mountpoint=/ | + | |
| + | Optional, portage tree, distfiles, and binary packages: | ||
| + | # ##i##zfs create rpool/FUNTOO | ||
| + | # ##i##zfs create -o mountpoint=/usr/portage -o compression=off rpool/FUNTOO/portage | ||
| + | # ##i##zfs create -o mountpoint=/usr/portage/distfiles rpool/FUNTOO/portage/distfiles | ||
| + | # ##i##zfs create -o mountpoint=/usr/portage/packages rpool/FUNTOO/portage/packages | ||
Optional datasets: /usr/src, /var | Optional datasets: /usr/src, /var | ||
| − | |||
# ##i##zfs create -o mountpoint=/usr/src rpool/FUNTOO/src | # ##i##zfs create -o mountpoint=/usr/src rpool/FUNTOO/src | ||
# ##i##zfs create -o mountpoint=/var rpool/FUNTOO/var | # ##i##zfs create -o mountpoint=/var rpool/FUNTOO/var | ||
</console> | </console> | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
=== Create your swap zvol === | === Create your swap zvol === | ||
| − | '''Make your swap +1G greater than your RAM. An 8G machine would have 9G of | + | '''Make your swap +1G greater than your RAM. An 8G machine would have 9G of SWAP (This is kinda big though).''' |
<console> | <console> | ||
# ##i##zfs create -o sync=always -o primarycache=metadata -o secondarycache=none -o volblocksize=4K -V 9G rpool/swap | # ##i##zfs create -o sync=always -o primarycache=metadata -o secondarycache=none -o volblocksize=4K -V 9G rpool/swap | ||
| Line 276: | Line 238: | ||
Now we will continue to install funtoo. | Now we will continue to install funtoo. | ||
| + | |||
== Installing Funtoo == | == Installing Funtoo == | ||
[[Funtoo_Linux_Installation|Download and install the Funtoo stage3 and continue installation as normal.]] | [[Funtoo_Linux_Installation|Download and install the Funtoo stage3 and continue installation as normal.]] | ||
| Line 283: | Line 246: | ||
# ##i##cd /mnt/funtoo | # ##i##cd /mnt/funtoo | ||
| − | Mount your boot drive | + | Make a directory for /boot |
| + | # ##i##mkdir /mnt/funtoo/boot | ||
| + | |||
| + | Mount your boot drive | ||
# ##i##mount /dev/sda1 /mnt/funtoo/boot | # ##i##mount /dev/sda1 /mnt/funtoo/boot | ||
| Line 293: | Line 259: | ||
Copy network settings | Copy network settings | ||
# ##i##cp /etc/resolv.conf etc/ | # ##i##cp /etc/resolv.conf etc/ | ||
| + | |||
chroot into your new funtoo environment | chroot into your new funtoo environment | ||
# ##i##env -i HOME=/root TERM=$TERM chroot . /bin/bash -l | # ##i##env -i HOME=/root TERM=$TERM chroot . /bin/bash -l | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | Sync your tree | |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
# ##i##emerge --sync | # ##i##emerge --sync | ||
</console> | </console> | ||
| Line 321: | Line 270: | ||
{{fancynote|The below configurations are the requirements for "Bliss Initramfs Creator". Some of these might not be needed for genkernel.}} | {{fancynote|The below configurations are the requirements for "Bliss Initramfs Creator". Some of these might not be needed for genkernel.}} | ||
| − | Tested with | + | Tested with kernels 2.6.32 - 3.9.X |
When you get up to the kernel, make sure that you disable the CFQ scheduler, and turn on No-op (It's the default one once you disable all schedulers). The reason for this is because ZFS has its own scheduler and the CFQ one conflicts with it. Go to your kernel config, and make sure you have the following: (there should be a /usr/src/linux symlink as well) | When you get up to the kernel, make sure that you disable the CFQ scheduler, and turn on No-op (It's the default one once you disable all schedulers). The reason for this is because ZFS has its own scheduler and the CFQ one conflicts with it. Go to your kernel config, and make sure you have the following: (there should be a /usr/src/linux symlink as well) | ||
| − | <pre>ZLIB_INFLATE/DEFLATE must be compiled into the kernel (not as a module). | + | <pre>- Linux Kernel |
| + | ZLIB_INFLATE/DEFLATE must be compiled into the kernel (not as a module). | ||
> ZLIB_INFLATE [=y], ZLIB_DEFLATE [=y] | > ZLIB_INFLATE [=y], ZLIB_DEFLATE [=y] | ||
General setup ---> | General setup ---> | ||
> [*] Initial RAM filesystem and RAM disk (initramfs/initrd) support | > [*] Initial RAM filesystem and RAM disk (initramfs/initrd) support | ||
| − | > () Initramfs source file(s) | + | > () Initramfs source file(s) |
| − | + | ||
| − | + | ||
| − | + | ||
Device Drivers ---> | Device Drivers ---> | ||
| − | > Generic Driver Options ---> | + | > Generic Driver Options ---> |
| − | >> [*] Maintain a devtmpfs filesystem to mount at /dev | + | >> [*] Maintain a devtmpfs filesystem to mount at /dev |
| + | >> [*] Automount devtmpfs at /dev, after the kernel mounted the rootfs | ||
| − | + | # Only if you want to make an SRM | |
| − | <*> | + | > File systems ---> |
| − | + | >> Miscellaneous filesystems ---> | |
| + | >>> <*> SquashFS 4.0 - Squashed file system support | ||
| + | >>> [*] Squashfs XATTR support | ||
| + | >>> [*] Include support for ZLIB compressed file systems | ||
| + | >>> [*] Include support for LZO compressed file systems | ||
| + | >>> [*] Include support for XZ compressed file systems | ||
| − | * All other drivers required to see your PATA/SATA drives must be compiled in.</pre> | + | * All other drivers required to see your PATA/SATA drives must be compiled in. |
| + | |||
| + | - app-arch/cpio | ||
| + | - sys-apps/busybox | ||
| + | - sys-kernel/spl | ||
| + | - sys-fs/zfs | ||
| + | - sys-fs/zfs-kmod | ||
| + | |||
| + | For SRM creation: | ||
| + | - sys-fs/squashfs-tools | ||
| + | |||
| + | For LUKS support: | ||
| + | - sys-fs/cryptsetup | ||
| + | |||
| + | - Linux Kernel | ||
| + | Device Drivers ---> | ||
| + | [*] Multiple devices driver support (RAID and LVM) ---> | ||
| + | <*> Device mapper support | ||
| + | <*> Crypt target support | ||
| + | |||
| + | Cryptographic API ---> | ||
| + | <*> XTS support | ||
| + | -*- AES cipher algorithms | ||
| + | </pre> | ||
Continue and compile/install your kernel: | Continue and compile/install your kernel: | ||
| + | |||
<console> | <console> | ||
# ##i##make bzImage modules | # ##i##make bzImage modules | ||
| Line 356: | Line 333: | ||
<console># ##i##emerge -av zfs</console> | <console># ##i##emerge -av zfs</console> | ||
| − | Check to make sure that the zfs tools are working, the zpool.cache file that you copied before should be displayed.<console> | + | Check to make sure that the zfs tools are working, the zpool.cache file that you copied before should be displayed. |
| + | |||
| + | <console> | ||
# ##i##zpool status | # ##i##zpool status | ||
# ##i##zfs list | # ##i##zfs list | ||
| Line 366: | Line 345: | ||
=== GRUB 2 === | === GRUB 2 === | ||
| − | |||
| − | |||
Before you do this, make sure this checklist is followed: | Before you do this, make sure this checklist is followed: | ||
* Installed kernel and kernel modules | * Installed kernel and kernel modules | ||
| Line 378: | Line 355: | ||
Then we will compile grub2: | Then we will compile grub2: | ||
| − | + | ||
<console># ##i##emerge -av grub</console> | <console># ##i##emerge -av grub</console> | ||
| Line 394: | Line 371: | ||
If not, then go back to the above checklist. | If not, then go back to the above checklist. | ||
| − | |||
| − | |||
| − | + | === Create a boot symlink === | |
| − | + | We will create a boot symlink so that we can have "consistent" boot configurations without any errors. | |
| − | + | ||
| − | + | ||
| − | |||
| − | |||
| − | |||
| − | |||
<console> | <console> | ||
# ##i##cd /boot | # ##i##cd /boot | ||
| − | # ##i## | + | # ##i##ln -s . boot |
</console> | </console> | ||
| − | + | You should now have a symlink called 'boot' inside /boot that points to /boot :). | |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
== Create the initramfs == | == 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. | There are two ways to do this, you can use genkernel, or you can use my bliss initramfs creator. I will show you both. | ||
| Line 450: | Line 393: | ||
<pre> | <pre> | ||
| − | Example: kernel name is: vmlinuz-3. | + | Example: kernel name is: vmlinuz-3.8.5-ALL |
| − | initramfs name is: initramfs-genkernel-x86_64-3. | + | initramfs name is: initramfs-genkernel-x86_64-3.8.5-ALL |
| + | /boot partition is: /dev/sda1 (on GPT) | ||
pool name is: rpool | pool name is: rpool | ||
</pre> | </pre> | ||
| + | |||
| + | '''genkernel entries need verification''' | ||
'''grub.cfg''': | '''grub.cfg''': | ||
<console> | <console> | ||
| Line 461: | Line 407: | ||
# Funtoo | # Funtoo | ||
| − | menuentry "Funtoo - 3. | + | menuentry "Funtoo - 3.8.5" { |
| − | + | insmod part_gpt | |
| − | + | insmod ext2 | |
| − | + | ||
| + | set root=(hd0,gpt1) | ||
| + | |||
| + | linux /vmlinuz-3.8.5-ALL real_root=ZFS=rpool/ROOT/funtoo dozfs=force | ||
| + | initrd /initramfs-genkernel-x86_64-3.8.5-ALL | ||
} | } | ||
</console> | </console> | ||
| − | + | ||
| + | If you followed the way to set up a separate partition to boot of (/dev/sda1 in this guid) you need to modify the entries in your grub.cfg, since grub will now not search inside zfs: | ||
<console> | <console> | ||
| − | + | set timeout=3 | |
| − | + | set default=0 | |
| − | + | ||
| − | + | # Funtoo | |
| − | + | menuentry "Funtoo - 3.8.5" { | |
| + | insmod zfs | ||
| + | linux /vmlinuz-3.8.5-ALL real_root=ZFS=rpool/ROOT/funtoo dozfs=force | ||
| + | initrd /initramfs-genkernel-x86_64-3.8.5-ALL | ||
| + | } | ||
</console> | </console> | ||
=== Bliss Initramfs Creator === | === Bliss Initramfs Creator === | ||
| − | + | If you are encrypting your drives, then add the "luks" use flag to your package.use before emerging: | |
| + | |||
| + | <console> | ||
| + | # ##i##echo "sys-kernel/bliss-initramfs luks" >> /etc/portage/package.use | ||
| + | </console> | ||
| + | |||
| + | Now install the creator: | ||
| + | |||
| + | <console> | ||
| + | # ##i##emerge bliss-initramfs | ||
| + | </console> | ||
| − | |||
| − | Then go into | + | Then go into the install directory, run the script as root, and place it into /boot: |
| − | <console># ##i##cd | + | <console># ##i##cd /opt/bliss-initramfs |
# ##i##./createInit | # ##i##./createInit | ||
# ##i##mv initrd-<kernel_name>.img /boot | # ##i##mv initrd-<kernel_name>.img /boot | ||
</console> | </console> | ||
| + | |||
'''<kernel_name>''' is the name of what you selected in the initramfs creator, and the name of the outputted file. Once you do this just go to your bootloader config, and add it in there. | '''<kernel_name>''' is the name of what you selected in the initramfs creator, and the name of the outputted file. Once you do this just go to your bootloader config, and add it in there. | ||
<pre> | <pre> | ||
| − | Example: Kernel name is: vmlinuz-3. | + | Example: Kernel name is: vmlinuz-3.8.5-ALL |
| − | initramfs name is: initrd-3. | + | initramfs name is: initrd-3.8.5-ALL.img |
| + | /boot partition is: /dev/sda1 (on GPT) | ||
| + | Encrypted partitions (If any, example: /dev/sda2, /dev/sdb3, /dev/sdc4) | ||
Pool root is: rpool/ROOT/funtoo | Pool root is: rpool/ROOT/funtoo | ||
</pre> | </pre> | ||
| + | |||
'''grub.cfg''': | '''grub.cfg''': | ||
| Line 502: | Line 470: | ||
# Funtoo | # Funtoo | ||
| − | menuentry "Funtoo - 3. | + | menuentry "Funtoo - 3.8.5" { |
| − | + | insmod part_gpt | |
| − | + | insmod ext2 | |
| − | + | ||
| + | set root=(hd0,gpt1) | ||
| + | |||
| + | linux /vmlinuz-3.8.5-ALL root=rpool/ROOT/funtoo quiet refresh | ||
| + | # Let's say you have 3 drives that are encrypted, and your pool (which also contains your root) is on here | ||
| + | # linux /vmlinuz-3.8.5-ALL root=rpool/ROOT/funtoo enc_root=/dev/sda2,/dev/sdb3,/dev/sdc4 quiet | ||
| + | initrd /initrd-3.8.5-ALL.img | ||
} | } | ||
</console> | </console> | ||
| − | ''' | + | {{fancyimportant|We are using the 'refresh' option because the current cachefile that was generated in SLAX won't work when the system is live. We will generate a new cachefile on the fly. You will need to recreate the initramfs once you are in the system so that the initramfs can have the new cachefile inside of it!}} |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
== Final configuration == | == Final configuration == | ||
| Line 528: | Line 495: | ||
# <fs> <mountpoint> <type> <opts> <dump/pass> | # <fs> <mountpoint> <type> <opts> <dump/pass> | ||
# Do not add the /boot line below if you are using whole-disk zfs | # Do not add the /boot line below if you are using whole-disk zfs | ||
| − | /dev/sda1 /boot | + | /dev/sda1 /boot ext2 defaults 0 2 |
/dev/zvol/rpool/swap none swap sw 0 0 | /dev/zvol/rpool/swap none swap sw 0 0 | ||
</console> | </console> | ||
| Line 536: | Line 503: | ||
<console> | <console> | ||
| − | Delete the stage3 | + | Delete the stage3 tarball that you downloaded earlier so it doesn't take up space. |
# ##i##cd / | # ##i##cd / | ||
# ##i##rm stage3-latest.tar.xz | # ##i##rm stage3-latest.tar.xz | ||
| − | |||
Set your root password | Set your root password | ||
| Line 549: | Line 515: | ||
Unmount all the kernel filesystem stuff and boot (if you have a separate /boot) | Unmount all the kernel filesystem stuff and boot (if you have a separate /boot) | ||
| − | |||
# ##i##umount -l proc dev sys boot | # ##i##umount -l proc dev sys boot | ||
| Line 557: | Line 522: | ||
Export the zpool | Export the zpool | ||
# ##i##cd / | # ##i##cd / | ||
| − | # ##i##zpool export | + | # ##i##zpool export rpool |
Reboot | Reboot | ||
| Line 567: | Line 532: | ||
and that should be enough to get your system to boot on ZFS. | and that should be enough to get your system to boot on ZFS. | ||
| − | == | + | == After reboot == |
| − | + | ||
| − | + | === Recreate initramfs === | |
| − | + | After you restart your machine and your inside the live system, remake a new initrd if you are using "Bliss Initramfs Creator". This is because the old cachefile that was used inside SLAX won't work for booting (At least not the first time). Now that our system is up, we will recreate the cache. | |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | === | + | |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
<console> | <console> | ||
| − | + | # ##i##cd /opt/bliss-initramfs | |
| − | + | # ##i##./createInit | |
| − | + | Pick your desired option | |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | Once your initrd is made, move it to /boot | |
| − | + | # ##i##mv initrd* /boot | |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | Now edit grub.cfg and remove the "refresh" option | |
| − | + | nano /boot/grub/grub.cfg | |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
</console> | </console> | ||
| − | Once you | + | === 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. | ||
| − | <console> | + | To take the snapshot of your system, type the following: |
| − | # ##i## | + | <console># ##i##zfs snapshot -r rpool@install</console> |
| − | + | ||
| − | + | ||
| − | </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 rpool/ROOT/funtoo@install</console> | ||
[[Category:HOWTO]] | [[Category:HOWTO]] | ||
Latest revision as of 20:03, 17 June 2013
[edit] 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.
[edit] 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).
[edit] Disclaimers
This guide is a work in progress. Expect some quirks.
Since ZFS was really designed for 64 bit systems, we are only recommending and supporting 64 bit platforms and installations. We will not be supporting 32 bit platforms!
[edit] Video Tutorial
As a companion to the install instructions below, a YouTube video ZFS install tutorial is now available:
[edit] 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 SLAX with ZFS SBs (SLAX Bundle) already included.
This is just a file that when combined with SLAX, gives you those tools.
Name: SLAX-English-US-7.0.8-x86_64_ZFS.iso (229 MB) Release Date: 2013-06-15 md5sum 358e4b3cbec9110de83e5d1779200eeb
[edit] 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.
[edit] fdisk (MBR 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.
Command (m for help): o ↵
Building a new DOS disklabel with disk identifier 0xbeead864.
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 type: ↵ Partition number: ↵ First sector: ↵ Last sector: +250M ↵
Create Partition 2 (ZFS):
Command: n ↵ Partition type: ↵ Partition number: ↵ First sector: ↵ Last sector: ↵ Command: t ↵ Partition number: 2 ↵ Hex code: bf ↵ Command: p ↵ Device Boot Start End Blocks Id System /dev/sda1 2048 514047 256000 83 Linux /dev/sda2 514048 1953525167 976505560 bf Solaris
[edit] 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 ↵
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 ↵
Only make the above BIOS Boot Partition if you are using GRUB 2 on GPT. If you are using the extlinux bootloader, this partition is not necessary.
Create Partition 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 ↵
[edit] Format your boot volume
Format your separate /boot partition:
# mkfs.ext2 /dev/sda1
[edit] Encryption (Optional)
If you want encryption, then create your encrypted vault(s) now by doing the following:
# cryptsetup -c aes-xts-plain64 luksFormat /dev/sda2 # cryptsetup luksOpen /dev/sda2 vault_1
If you followed the manual GPT partitioning instructions, you should change /dev/sda2 to /dev/sda3.
[edit] Create the zpool
We will first create the pool. The pool will be named `rpool` and the disk will be aligned to 4096 (using ashift=12)
# zpool create -f -o ashift=12 -o cachefile= -O compression=on -m none -R /mnt/funtoo rpool /dev/sda2
If you followed the manual GPT partitioning instructions, you should change /dev/sda2 to /dev/sda3. If you are using encrypted root, then change /dev/sda2 to vault_1.
If you have a previous pool that you would like to import, you can do a: zpool import -f -R /mnt/funtoo <pool_name>
[edit] 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 rpool/ROOT # zfs create -o mountpoint=/ rpool/ROOT/funtoo Optional, but recommended dataset: /home # zfs create -o mountpoint=/home rpool/HOME Optional, portage tree, distfiles, and binary packages: # zfs create rpool/FUNTOO # zfs create -o mountpoint=/usr/portage -o compression=off rpool/FUNTOO/portage # zfs create -o mountpoint=/usr/portage/distfiles rpool/FUNTOO/portage/distfiles # zfs create -o mountpoint=/usr/portage/packages rpool/FUNTOO/portage/packages Optional datasets: /usr/src, /var # zfs create -o mountpoint=/usr/src rpool/FUNTOO/src # zfs create -o mountpoint=/var rpool/FUNTOO/var
[edit] 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).
# zfs create -o sync=always -o primarycache=metadata -o secondarycache=none -o volblocksize=4K -V 9G rpool/swap
[edit] Format your swap zvol
# mkswap -f /dev/zvol/rpool/swap # swapon /dev/zvol/rpool/swap
[edit] Last minute checks and touches
Check to make sure everything appears fine:
# zpool status # zfs list
Copy the zpool.cache file to your new environment.
# mkdir -p /mnt/funtoo/etc/zfs # cp /etc/zfs/zpool.cache /mnt/funtoo/etc/zfs
Make an empty mtab file
# touch /mnt/funtoo/etc/mtab
Now we will continue to install funtoo.
[edit] Installing Funtoo
Download and install the Funtoo stage3 and continue installation as normal.
Then chroot into your new funtoo environment:
# cd /mnt/funtoo Make a directory for /boot # mkdir /mnt/funtoo/boot Mount your boot drive # mount /dev/sda1 /mnt/funtoo/boot Bind the kernel related directories # mount --rbind /proc proc # mount --rbind /dev dev # mount --rbind /sys sys Copy network settings # cp /etc/resolv.conf etc/ chroot into your new funtoo environment # env -i HOME=/root TERM=$TERM chroot . /bin/bash -l Sync your tree # emerge --sync
[edit] Kernel Configuration
The below configurations are the requirements for "Bliss Initramfs Creator". Some of these might not be needed for genkernel.
Tested with kernels 2.6.32 - 3.9.X
When you get up to the kernel, make sure that you disable the CFQ scheduler, and turn on No-op (It's the default one once you disable all schedulers). The reason for this is because ZFS has its own scheduler and the CFQ one conflicts with it. Go to your kernel config, and make sure you have the following: (there should be a /usr/src/linux symlink as well)
- Linux Kernel ZLIB_INFLATE/DEFLATE must be compiled into the kernel (not as a module). > ZLIB_INFLATE [=y], ZLIB_DEFLATE [=y] General setup ---> > [*] Initial RAM filesystem and RAM disk (initramfs/initrd) support > () Initramfs source file(s) Device Drivers ---> > Generic Driver Options ---> >> [*] Maintain a devtmpfs filesystem to mount at /dev >> [*] Automount devtmpfs at /dev, after the kernel mounted the rootfs # Only if you want to make an SRM > File systems ---> >> Miscellaneous filesystems ---> >>> <*> SquashFS 4.0 - Squashed file system support >>> [*] Squashfs XATTR support >>> [*] Include support for ZLIB compressed file systems >>> [*] Include support for LZO compressed file systems >>> [*] Include support for XZ compressed file systems * All other drivers required to see your PATA/SATA drives must be compiled in. - app-arch/cpio - sys-apps/busybox - sys-kernel/spl - sys-fs/zfs - sys-fs/zfs-kmod For SRM creation: - sys-fs/squashfs-tools For LUKS support: - sys-fs/cryptsetup - Linux Kernel Device Drivers ---> [*] Multiple devices driver support (RAID and LVM) ---> <*> Device mapper support <*> Crypt target support Cryptographic API ---> <*> XTS support -*- AES cipher algorithms
Continue and compile/install your kernel:
# make bzImage modules # make install # make modules_install
[edit] Installing the ZFS userspace tools
# emerge -av zfs
Check to make sure that the zfs tools are working, the zpool.cache file that you copied before should be displayed.
# zpool status # zfs list
If everything worked, continue.
[edit] Install the bootloader
[edit] 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 -av grub
Once this is done, you can check that grub is version 2.00 by doing the following command:
# grub-install --version
grub-install (GRUB) 2.00
Now try to install grub2:
# grub-install --no-floppy /dev/sda
You should receive the following message
Installation finished. No error reported.
If not, then go back to the above checklist.
[edit] Create a boot symlink
We will create a boot symlink so that we can have "consistent" boot configurations without any errors.
# cd /boot # ln -s . boot
You should now have a symlink called 'boot' inside /boot that points to /boot :).
[edit] 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.
[edit] genkernel
# emerge -av sys-kernel/genkernel # genkernel --zfs initramfs
Example: kernel name is: vmlinuz-3.8.5-ALL initramfs name is: initramfs-genkernel-x86_64-3.8.5-ALL /boot partition is: /dev/sda1 (on GPT) pool name is: rpool
genkernel entries need verification
grub.cfg:
set timeout=3
set default=0
# Funtoo
menuentry "Funtoo - 3.8.5" {
insmod part_gpt
insmod ext2
set root=(hd0,gpt1)
linux /vmlinuz-3.8.5-ALL real_root=ZFS=rpool/ROOT/funtoo dozfs=force
initrd /initramfs-genkernel-x86_64-3.8.5-ALL
}
If you followed the way to set up a separate partition to boot of (/dev/sda1 in this guid) you need to modify the entries in your grub.cfg, since grub will now not search inside zfs:
set timeout=3
set default=0
# Funtoo
menuentry "Funtoo - 3.8.5" {
insmod zfs
linux /vmlinuz-3.8.5-ALL real_root=ZFS=rpool/ROOT/funtoo dozfs=force
initrd /initramfs-genkernel-x86_64-3.8.5-ALL
}
[edit] 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>.img /boot
<kernel_name> is the name of what you selected in the initramfs creator, and the name of the outputted file. Once you do this just go to your bootloader config, and add it in there.
Example: Kernel name is: vmlinuz-3.8.5-ALL initramfs name is: initrd-3.8.5-ALL.img /boot partition is: /dev/sda1 (on GPT) Encrypted partitions (If any, example: /dev/sda2, /dev/sdb3, /dev/sdc4) Pool root is: rpool/ROOT/funtoo
grub.cfg:
set timeout=3
set default=0
# Funtoo
menuentry "Funtoo - 3.8.5" {
insmod part_gpt
insmod ext2
set root=(hd0,gpt1)
linux /vmlinuz-3.8.5-ALL root=rpool/ROOT/funtoo quiet refresh
# Let's say you have 3 drives that are encrypted, and your pool (which also contains your root) is on here
# linux /vmlinuz-3.8.5-ALL root=rpool/ROOT/funtoo enc_root=/dev/sda2,/dev/sdb3,/dev/sdc4 quiet
initrd /initrd-3.8.5-ALL.img
}
We are using the 'refresh' option because the current cachefile that was generated in SLAX won't work when the system is live. We will generate a new cachefile on the fly. You will need to recreate the initramfs once you are in the system so that the initramfs can have the new cachefile inside of it!
[edit] Final configuration
[edit] Add the zfs tools to openrc
# rc-update add zfs boot
[edit] Add filesystems to /etc/fstab
# nano /etc/fstab
# <fs> <mountpoint> <type> <opts> <dump/pass>
# Do not add the /boot line below if you are using whole-disk zfs
/dev/sda1 /boot ext2 defaults 0 2
/dev/zvol/rpool/swap none swap sw 0 0
[edit] 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/rpool/swap Export the zpool # cd / # zpool export rpool Reboot # reboot
Don't forget to set your root password as stated above before exiting chroot and rebooting. If you don't set the root password, you won't be able to log into your new system.
and that should be enough to get your system to boot on ZFS.
[edit] After reboot
[edit] Recreate initramfs
After you restart your machine and your inside the live system, remake a new initrd if you are using "Bliss Initramfs Creator". This is because the old cachefile that was used inside SLAX won't work for booting (At least not the first time). Now that our system is up, we will recreate the cache.
# cd /opt/bliss-initramfs # ./createInit Pick your desired option Once your initrd is made, move it to /boot # mv initrd* /boot Now edit grub.cfg and remove the "refresh" option nano /boot/grub/grub.cfg
[edit] 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 rpool@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 rpool/ROOT/funtoo@install