Difference between revisions of "ZFS Install Guide"

From Funtoo Linux
Jump to: navigation, search
m (removed extra fstab comments)
Line 336: Line 336:
 
   KERNEL /boot/vmlinuz-3.7.1-ALL
 
   KERNEL /boot/vmlinuz-3.7.1-ALL
 
   INITRD /boot/initramfs-genkernel-x86_64-3.7.1-ALL
 
   INITRD /boot/initramfs-genkernel-x86_64-3.7.1-ALL
   APPEND root=ZFS=rpool dozfs=force
+
   APPEND real_root=ZFS=rpool/ROOT/funtoo dozfs=force
 
</console>
 
</console>
  
Line 344: Line 344:
  
 
<console>
 
<console>
# ##i##rc-config add zfs boot
+
# ##i##rc-update add zfs boot
 
</console>
 
</console>
  

Revision as of 15:28, 27 December 2012

This tutorial will show you how to install Funtoo on ZFS. In order for us to install Funtoo on ZFS, you will need an environment that provides the ZFS userspace tools. System Rescue CD 2.5.1 had the ZFS tools but they were removed. Thus we will be using the Gentoo Live DVD 12/12/2012 - End of the World Edition. This Live DVD does not have `gptfdisk`. So if you need that application to create GPT partitions, you will need to emerge it.

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.

Download the Gentoo LiveDVD

# MD5 HASH
e86da868be423283ec167725390faefc  livedvd-amd64-multilib-20121221.iso
afbbcfc4c440ef5857a9144ab1e18251  livedvd-amd64-multilib-20121221.iso.CONTENTS
26cde567e977ef1f4645f2f33dbad39b  livedvd-amd64-multilib-20121221.iso.CONTENTS-squashfs.gz
38f0954203934175f751fe15ab80891c  livedvd-amd64-multilib-20121221.iso.CREDITS
8becbfcecaa8423eaa196b544be9fa5a  livedvd-amd64-multilib-20121221.iso.PACKAGES

Once you burn the DVD and boot it, we will start to partition the system. Open up a terminal, and type in the following (We will assume it's a fresh drive for simplicity).

Contents

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 (m for help): n
Partition type: 
Partition number: 
First sector: 
Last sector: +250M

Create Partition 2 (swap):

Make this partition twice the amount of RAM you have.

Command (m for help): n
Partition type: 
Partition number: 
First sector: 
Last sector: +4G

Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): 82

Create Partition 3 (ZFS):

Command (m for help): n
Partition type: 
Partition number: 
First sector: 
Last sector: 

Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): bf

Command (m for help): 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: 0x390225b5

Device Boot      Start         End      Blocks   Id  System

/dev/sda1            2048      514047      256000   83  Linux
/dev/sda2          514048     8902655     4194304   82  Linux swap / Solaris
/dev/sda3         8902656  1953525167   972311256   bf  Solaris

gdisk (GPT Style)

Create Partition 1 (boot):

Command: n
Partition Number: 
First sector: 
Last sector: +250M
Hex Code: 

Create Partition 2 (swap):

Command: n
Partition Number: 
First sector: 
Last sector: +4G
Hex Code: 8200

Create Partition 3 (ZFS):

Command: n
Partition Number: 
First sector: 
Last sector: 
Hex Code: bf01

Command (? for help): p
Disk /dev/sda: 1953525168 sectors, 931.5 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 5A4D6576-FEF4-4693-B48B-C390FF3B1077
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         8902655   4.0 GiB     8200  Linux swap
   3         8902656      1953525134   927.3 GiB   BF01  Solaris /usr & Mac ZFS

Format your boot volume

# mkfs.ext4 /dev/sda1

Format your swap partition

# mkswap -f /dev/sda2
# swapon /dev/sda2

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= -m none -R /mnt/funtoo rpool /dev/sda3

Create the zfs datasets

We will now create some datasets. For this installation, it will just be a basic dataset that has only /. You can create more datasets depending on your needs as you become familiar with ZFS.

# zfs create -o mountpoint=none rpool/ROOT
# zfs create -o mountpoint=/ rpool/ROOT/funtoo

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

Make a directory for your boot partition and mount it

# mkdir /mnt/funtoo/boot
# mount /dev/sda1 /mnt/funtoo/boot

Everything is currently mounted in /mnt/funtoo. So download and install the funtoo stage3 and continue installation as normal.

Then chroot into your new funtoo environment:

# cd /mnt/funtoo
# mount --bind /proc ./proc
# mount --bind /dev ./dev
# mount --bind /sys ./sys
# env -i HOME=/root TERM=$TERM chroot . bash -l

and finally sync your portage tree

# emerge --sync


Kernel Configuration

Tested with kernel 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)

General setup --->
[*] Initial RAM filesystem and RAM disk (initramfs/initrd) support

[*] 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

Very important, make sure that ZLIB_DEFLATE is compiled as a module.

ZLIB_INFLATE [=y], ZLIB_DEFLATE [=m]

Anything required to see your hard drives should be compiled into the kernel This includes all filesystem drivers etc

Continue and compile/install your kernel:

# make bzImage modules
# make install
# make modules_install

Installing the ZFS userspace tools

# emerge -av =sys-kernel/spl =sys-fs/zfs =sys-fs/zfs-kmod

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 zfs initramfs creator. I will show you both.

Bliss Initramfs Creator

Make sure that you have cpio installed (Funtoo has this by default) 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.github

# 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-zfs.img /boot

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-zfs.img pool name is: rpool

extlinux.conf:

LABEL funtoo
  MENU LABEL Funtoo 3.7.1-ALL
  KERNEL /boot/vmlinuz-3.7.1-ALL
  INITRD /boot/initrd-zfs.img
  APPEND pool_name=rpool

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/sda2               none            swap            sw              0 0

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

Enjoy your new install on ZFS :)

Personal tools
Namespaces

Variants
Actions
Categories
Toolbox
Stuff