Difference between revisions of "ZFS Install Guide"
Fearedbliss (Talk | contribs) m (swap should be created with sync=always.) |
|||
| Line 179: | Line 179: | ||
<console> | <console> | ||
| − | # ##i##zfs create -o sync= | + | # ##i##zfs create -o sync=always -o primarycache=metadata -o secondarycache=none -V 9G rpool/swap |
</console> | </console> | ||
Revision as of 07:15, 19 January 2013
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.
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!
Contents |
Setting up your environment
In order for us to install Funtoo on ZFS, you will need an environment that provides the ZFS tools. We will be downloading two things: System Rescue CD,
and the ZFS System Rescue Module (SRM). This is just a file that when combined with System Rescue CD, gives you those tools.
Download System Rescue CD 3.2.0
Download the ZFS System Rescue Module
Name: SystemRescueCd-x86-3.2.0 (353 MiB) Release Date: 2013-01-07 md5sum 90528f0c4b861363992fd9cbcc52d00a
Follow the instructions here to download and place the srm into your flash drive.
Choose the alter64 kernel at the bootmenu to be able to load and use the zfs modules. Other kernels mostly refuse to load them. First thing after booting System_Rescue is to create a funtoo mountpoint :
Command: mkdir /mnt/funtoo ↵
We will now start to partition the system. Open up a terminal, and type in the following (We will assume it's a fresh drive for simplicity).
Creating partitions
We will be creating two partitions, /boot, and the remaining disk space will be for ZFS.
(All commands will be ran as root).
fdisk (MBR Style)
Create Partition 1 (boot):
Command: n ↵ Partition type: ↵ Partition number: ↵ First sector: ↵ Last sector: +250M ↵
Create Partition 2 (ZFS):
Command: n ↵ Partition type: ↵ Partition number: ↵ First sector: ↵ Last sector: ↵ Command: t ↵ Partition number: 2 ↵ Hex code (type L to list codes): bf ↵ Command: p ↵ Disk /dev/sda: 1000.2 GB, 1000204886016 bytes 255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x3e954df7 Device Boot Start End Blocks Id System /dev/sda1 2048 514047 256000 83 Linux /dev/sda2 514048 1953525167 976505560 bf Solaris
gdisk (GPT Style)
Create Partition 1 (boot):
Command: n ↵ Partition Number: ↵ First sector: ↵ Last sector: +250M ↵ Hex Code: ↵
Create Partition 2 (BIOS Boot Partition):
Command: n ↵ Partition Number: ↵ First sector: ↵ Last sector: +32M ↵ Hex Code: EF02 ↵
Only make the above BIOS Boot Partition if you are using GRUB 2 on GPT. If you are using the extlinux bootloader, this partition is not necessary. The below instructions continue as if you did not create this partition and assumes you are using extlinux as the bootloader.
Create Partition 2 (ZFS):
Command: n ↵ Partition Number: ↵ First sector: ↵ Last sector: ↵ Hex Code: bf01 ↵ Command: p ↵ Disk /dev/sda: 1953525168 sectors, 931.5 GiB Logical sector size: 512 bytes Disk identifier (GUID): C0C1E56A-B24F-492F-95DB-2E227676F228 Partition table holds up to 128 entries First usable sector is 34, last usable sector is 1953525134 Partitions will be aligned on 2048-sector boundaries Total free space is 2014 sectors (1007.0 KiB) Number Start (sector) End (sector) Size Code Name 1 2048 514047 250.0 MiB 8300 Linux filesystem 2 514048 1953525134 931.3 GiB BF01 Solaris /usr & Mac ZFS Command: w ↵
Format your boot volume
# mkfs.ext4 /dev/sda1
Create the zpool
We will first create the pool. The pool will be named `rpool` and the disk will be aligned to 4096 (using ashift=12)
# zpool create -f -o ashift=12 -o cachefile= -O compression=on -m none -R /mnt/funtoo rpool /dev/sda2
If you followed the GPT partitioning instructions, you should change /dev/sda2 to /dev/sda3.
If you have a previous pool that you would like to import, you can do a: zpool import -R /mnt/funtoo -f <pool_name>
Create the zfs datasets
We will now create some datasets. For this installation, we will create a small but future proof amount of datasets. We will have a dataset for the OS (/), and your swap. We will also show you how to create some optional datasets: /home, /var, /usr/src, and /usr/portage.
Create some empty containers for organization purposes, and make the dataset that will hold / # zfs create -o mountpoint=none rpool/ROOT # zfs create -o mountpoint=/ rpool/ROOT/funtoo Optional, but recommended datasets: /home, /root # zfs create -o mountpoint=/home rpool/HOME # zfs create -o mountpoint=/root rpool/HOME/root Optional datasets: /usr/src, /var # zfs create -o mountpoint=none rpool/FUNTOO # zfs create -o mountpoint=/usr/src rpool/FUNTOO/src # zfs create -o mountpoint=/var rpool/FUNTOO/var
Creating a separate portage dataset (optional)
Creating a separate portage dataset could be useful if you would like to keep your portage tree, distfiles (source code files), and packages (your compiled binaries if you have FEATURES="buildpkg" enabled) in a safe place (or if you want to back up this directory up easily).
This requires a few extra steps because we can't just do a regular emerge --sync when we initially chroot. We will need to download a portage snapshot tarball and extract it into the directory.
The required steps for getting and extracting the snapshot will be shown later on in the guide once you chroot into the environment. For now just create the datasets:
# zfs create -o mountpoint=/usr/portage -o compression=off rpool/FUNTOO/portage # zfs create -o mountpoint=/usr/portage/distfiles -o compression=off rpool/FUNTOO/distfiles
Create your swap zvol
Make your swap +1G greater than your RAM. An 8G machine would have 9G of RAM (This is kinda big though). Be warned - zfs is memory hungry. Specially when used with compression=on. A machine with just 4GB can come in troubles while compiling big packages and/or a graphical desktop running. You definitly should have swap running.
# zfs create -o sync=always -o primarycache=metadata -o secondarycache=none -V 9G rpool/swap
Format your swap zvol
# mkswap -f /dev/zvol/rpool/swap # swapon /dev/zvol/rpool/swap
Alright that finishes the creation of the zpool and zfs datasets.
Check to make sure everything appears fine:
# zpool status # zfs list
Copy the zpool.cache file to your new environment.
# mkdir -p /mnt/funtoo/etc/zfs # cp /etc/zfs/zpool.cache /mnt/funtoo/etc/zfs
Make an empty mtab file
# touch /mnt/funtoo/etc/mtab
Now we will continue to install funtoo.
Installing Funtoo
Download and install the Funtoo stage3 and continue installation as normal.
Then chroot into your new funtoo environment:
# cd /mnt/funtoo Mount your boot drive # mount /dev/sda1 /mnt/funtoo/boot Bind the kernel related directories # mount --bind /proc ./proc # mount --bind /dev ./dev # mount --bind /sys ./sys Copy network settings # cp /etc/resolv.conf etc/ chroot into your new funtoo environment # env -i HOME=/root TERM=$TERM chroot . bash -l
Syncing your portage tree
If you didn't create a separate portage dataset, then just sync your portage tree as normal.
# emerge --sync
If you did create a separate portage dataset, let's now get the portage snapshot set up.
Change into your /usr directory # cd /usr Download and extract the portage snapshot # wget http://ftp.osuosl.org/pub/funtoo/funtoo-current/snapshots/portage-latest.tar.xz # tar xf portage-latest.tar.xz Change into your portage directory and checkout the funtoo branch # cd portage # git checkout funtoo.org Now sync your portage tree # emerge --sync
Kernel Configuration
Tested with kernel 2.6.32, 3.2.34, 3.6.9, 3.7.1.
When you get up to the kernel, make sure that you disable the CFQ scheduler, and turn on No-op (It's the default one once you disable all schedulers). The reason for this is because ZFS has its own scheduler and the CFQ one conflicts with it.
Go to your kernel config, and make sure you have the following: (there should be a /usr/src/linux symlink as well)
ZLIB_INFLATE/DEFLATE must be compiled into the kernel (not as a module). > ZLIB_INFLATE [=y], ZLIB_DEFLATE [=y] General setup ---> > [*] Initial RAM filesystem and RAM disk (initramfs/initrd) support > () Initramfs source file(s) [*] Enable loadable module support ---> [*] Module unloading Enable the block layer ---> IO Schedulers ---> < > Deadline I/O scheduler < > CFQ I/O scheduler Default I/O scheduler (No-op) Device Drivers ---> > Generic Driver Options ---> >> [*] Maintain a devtmpfs filesystem to mount at /dev >> [*] Automount devtmpfs at /dev, after the kernel mounted the rootfs Cryptographic API ---> <*> Deflate compression algorithm <*> Zlib compression algorithm * All other drivers required to see your PATA/SATA drives must be compiled in.
Continue and compile/install your kernel:
# make bzImage modules # make install # make modules_install
Installing the ZFS userspace tools
# emerge -av zfs
Check to make sure that the zfs tools are working, the zpool.cache file that you copied before should be displayed.
# zpool status # zfs list
If everything worked, continue.
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.
Bliss Initramfs Creator
Make sure you compile sys-apps/busybox with the static flag.
# echo "sys-apps/busybox static" >> /etc/portage/package.use # emerge -av sys-apps/busybox
Clone my creator which is located at: git://github.com/fearedbliss/Bliss-Initramfs-Creator.git
# git clone git://github.com/fearedbliss/Bliss-Initramfs-Creator.git
Then go into this new directory, run the script as root, and place it into /boot
# cd Bliss-Initramfs-Creator # ./createInit # mv initrd-<kernel_name>.img /boot
<kernel_name> is the name of what you selected in the initramfs creator, and the name of the outputted file.
Once you do this just go to your bootloader config, and add it in there.
Example: Kernel name is: vmlinuz-3.7.1-ALL initramfs name is: initrd-3.7.1-ALL.img Pool root is: rpool/ROOT/funtoo
extlinux.conf:
LABEL funtoo MENU LABEL Funtoo 3.7.1-ALL KERNEL /boot/vmlinuz-3.7.1-ALL INITRD /boot/initrd-3.7.1-ALL.img APPEND pool_root=rpool/ROOT/funtoo
genkernel
# emerge -av sys-kernel/genkernel # genkernel --zfs initramfs
Example: kernel name is: vmlinuz-3.7.1-ALL initramfs name is: initramfs-genkernel-x86_64-3.7.1-ALL pool name is: rpool
extlinux.conf:
LABEL funtoo MENU LABEL Funtoo 3.7.1-ALL KERNEL /boot/vmlinuz-3.7.1-ALL INITRD /boot/initramfs-genkernel-x86_64-3.7.1-ALL APPEND real_root=ZFS=rpool/ROOT/funtoo dozfs=force
Final configuration
Add the zfs tools to openrc
# rc-update add zfs boot
Add filesystems to /etc/fstab
# nano /etc/fstab
# <fs> <mountpoint> <type> <opts> <dump/pass>
/dev/sda1 /boot ext4 defaults 1 2
/dev/zvol/rpool/swap none swap sw 0 0
Clean up and reboot
We are almost done, we are just going to clean up, set our root password, and unmount whatever we mounted and get out.
Delete the stage3/portage tarballs you downloaded earlier so they don't take up space. # cd / # rm stage3-latest.tar.xz # rm /usr/portage-latest.tar.xz Set your root password # passwd >> Enter your password, you won't see what you are writing (for security reasons), but it is there! Get out of the chroot environment # exit Unmount all the kernel filesystem stuff and boot # cd /mnt/funtoo # umount proc dev sys boot Turn off the swap # swapoff /dev/zvol/rpool/swap Export the zpool # cd / # zpool export -f rpool Reboot # reboot
Don't forget to set your root password as stated above before exiting chroot and rebooting. If you don't set the root password, you won't be able to log into your new system.
and that should be enough to get your system to boot on ZFS.
Extra: After reboot
After you restart your machine and your inside your desktop, continue to set up anything you need in terms of /etc configurations. Once you have everything the way you like it, take a snapshot of your system. You will be using this snapshot to revert back to this state if anything ever happens to your system down the road. The snapshots are cheap, and almost instant. To take the snapshot of your rootfs, type the following:
# zfs snapshot rpool/ROOT/funtoo@install
To see if your snapshot was taken, type:
# zfs list -t snapshot
If your machine ever fails and you need to get back to this state, just type:
# zfs rollback rpool/ROOT/funtoo@install
Recovery Environment
On ZFS it is extremely easy to create a recovery environment using an already working snapshot. So that's what we will be doing.
Create a clone of the @install snapshot which you will use for recovery purposes. If something happens to your main install, you can boot into this clone and fix the main one. One of the differences (maybe the only difference) between a clone and a snapshot is that a clone is rewritable while a snapshot is only read-only.
# zfs clone rpool/ROOT/funtoo@install rpool/ROOT/recovery
Add the clone to your extlinux.conf
LABEL funtoo-recovery
MENU LABEL Funtoo Recovery
KERNEL /boot/vmlinuz-3.7.1-ALL
INITRD /boot/initrd-3.7.1-ALL.img
APPEND pool_root=rpool/ROOT/recovery
Things to watch out for
Since your recovery clone will tend to get old as you use your main system, and since your recovery and other stuff are on the same pool, we don't want the new pool stuff to be mounted when we launch recovery. We also don't want video drivers to be conflicting.
1. Make sure that nvidia/nouveau stuff are blacklisted. 2. Make sure that your /boot and /lib/modules for the kernel in your 'recovery' are matching. 3. Disable the zfs openrc script so that nothing else gets automatically mounted. Only your rootfs.
You can do the above stuff by mounting your copy and chrooting into it.
Mount the recovery clone # mkdir /mnt/recovery # mount -t zfs -o zfsutil rpool/ROOT/recovery /mnt/recovery # cd /mnt/recovery Mount the kernel devices # mount --bind /proc ./proc # mount --bind /dev ./dev # mount --bind /sys ./sys Copy zpool.cache # cp /etc/zfs/zpool.cache etc/zfs Chroot into the new environment # env -i HOME=/root TERM=$TERM chroot . bash --login Disable zfs/zfs-shutdown openrc scripts # rc-config delete zfs boot Blacklist nouveau/nvidia drivers # echo "blacklist nouveau" >> /etc/modprobe.d/blacklist.conf # echo "blacklist nvidia" >> /etc/modprobe.d/blacklist.conf
Getting into the recovery
Just start your machine and pick the Funtoo Recovery option from the Boot Menu.
Enjoy your new install on ZFS :)