The Funtoo Linux project has transitioned to "Hobby Mode" and this wiki is now read-only.
Difference between revisions of "ZFS as Root Filesystem"
Line 31: | Line 31: | ||
== | == Drive Partitions == | ||
We are letting ZFS automatically partition the drive. | We are letting ZFS automatically partition the drive. This ideal for our example using a single disk and legacy (BIOS) boot. | ||
=== Creating of pool === | === Creating of pool === | ||
Create a ZFS Storage Pool using a single whole disk | Create a ZFS Storage Pool using a single whole disk | ||
<console> | <console> | ||
root@ubuntu:~###i## zpool create -f -o ashift=12 -o cachefile=/tmp/zpool.cache -O normalization=formD -O atime=off -m none -R /mnt/funtoo rpool /dev/disk/by-id/foo | root@ubuntu:~###i## zpool create -f -o ashift=12 -o cachefile=/tmp/zpool.cache -O normalization=formD -O atime=off -m none -R /mnt/funtoo rpool /dev/disk/by-id/foo | ||
Line 53: | Line 53: | ||
{{2Col|{{c|/dev/disk/by-id/foo}}|The path to the physical disk. e.g. /dev/disk/by-id/ata-Samsung_SSD_840_EVO_120GB_123456789ABCDEF. Known in 'ZFS-speak' as a 'VDEV'.}} | {{2Col|{{c|/dev/disk/by-id/foo}}|The path to the physical disk. e.g. /dev/disk/by-id/ata-Samsung_SSD_840_EVO_120GB_123456789ABCDEF. Known in 'ZFS-speak' as a 'VDEV'.}} | ||
{{TableEnd}} | {{TableEnd}} | ||
Please note that the options 'ashift' and 'cachefile' are preceded with a lowercase '-o', while 'normalization' and 'atime' are preceded with an uppercase '-O'. | |||
Without additional options this will create our storage pool and enable all 'features' available under version 0.6.5.6. The pool will be automatically mounted at the (temporary) location {{f|/mnt/funtoo}}. | |||
To confirm the presence of our newly created pool | |||
{{console|body= | |||
root@ubuntu:~###i## zpool status | |||
pool: rpool | |||
state: ONLINE | |||
scan: none requested | |||
config: | |||
NAME STATE READ WRITE CKSUM | |||
rpool ONLINE 0 0 0 | |||
ata-Samsung_SSD_840_EVO_120GB_123456789ABCDEF ONLINE 0 0 0 | |||
errors: No known data errors | |||
}} | |||
=== Create | === Create ZFS Datasets === | ||
==== Create | Now we will create one or more ZFS filesystems within our storage pool. These will contain Funtoo Linux. | ||
==== Create the Root file system (Required) ==== | |||
<console> | <console> | ||
# ##i## zfs create -o mountpoint=none rpool/ROOT | # ##i## zfs create -o mountpoint=none -o canmount=off rpool/ROOT | ||
# ##i## zfs create -o mountpoint=/ rpool/ROOT/funtoo | # ##i## zfs create -o mountpoint=/ rpool/ROOT/funtoo | ||
</console> | </console> | ||
==== Create optional | ==== Create optional Datasets==== | ||
Described below datasets are examples and optional. It's up to users to perform creation of their own datasets. | Described below datasets are examples and optional. It's up to users to perform creation of their own datasets. | ||
===== Home===== | ===== Home===== | ||
<console> | <console> | ||
# ##i## zfs create -o mountpoint=/home rpool/HOME | # ##i## zfs create -o mountpoint=/home rpool/HOME | ||
</console> | </console> | ||
=====Portage directories===== | =====Portage directories===== | ||
<console> | <console> | ||
# ##i## zfs create -o mountpoint=none -o setuid=off rpool/FUNTOO | # ##i## zfs create -o mountpoint=none -o canmount=off -o setuid=off rpool/FUNTOO | ||
# ##i## zfs create -o mountpoint=/usr/portage | # ##i## zfs create -o mountpoint=/usr/portage rpool/FUNTOO/portage | ||
# ##i## zfs create -o mountpoint=/usr/portage/distfiles rpool/FUNTOO/distfiles | # ##i## zfs create -o mountpoint=/usr/portage/distfiles rpool/FUNTOO/distfiles | ||
</console> | </console> | ||
Line 79: | Line 95: | ||
# ##i## zfs create -o mountpoint=/var/tmp/portage -o compression=lz4 -o sync=disabled rpool/FUNTOO/build | # ##i## zfs create -o mountpoint=/var/tmp/portage -o compression=lz4 -o sync=disabled rpool/FUNTOO/build | ||
</console> | </console> | ||
To confirm the presence of the filesystems that we have created | |||
{{console|body= | |||
root@ubuntu:~# ##i##zfs list -t all | |||
NAME USED AVAIL REFER MOUNTPOINT | |||
rpool 660K 19.3G 96K none | |||
rpool/HOME 96K 19.3G 96K /mnt/funtoo/home | |||
rpool/ROOT 192K 19.3G 96K none | |||
rpool/ROOT/funtoo 96K 19.3G 96K /mnt/funtoo | |||
}} | |||
===Make the root filesystem bootable=== | |||
{{important|Do not skip this!}} | |||
When booting from ZFS, you must specify a boot device and a root file system within the pool that was identified by the boot device. By default, the dataset selected for booting is the one identified by the pool's <code>bootfs</code> property. | When booting from ZFS, you must specify a boot device and a root file system within the pool that was identified by the boot device. By default, the dataset selected for booting is the one identified by the pool's <code>bootfs</code> property. | ||
Line 91: | Line 118: | ||
{{console|body= | {{console|body= | ||
###i## cd /mnt/funtoo | # ##i## cd /mnt/funtoo | ||
###i## wget http://build.funtoo.org/funtoo-current/x86-64bit/generic_64/stage3-latest.tar.xz | # ##i## wget http://build.funtoo.org/funtoo-current/x86-64bit/generic_64/stage3-latest.tar.xz | ||
}} | }} | ||
Line 98: | Line 125: | ||
{{console|body= | {{console|body= | ||
###i## tar xpf stage3-latest.tar.xz | # ##i## tar xpf stage3-latest.tar.xz | ||
}} | }} | ||
Line 126: | Line 153: | ||
# ##i##chroot /mnt/funtoo /bin/bash | # ##i##chroot /mnt/funtoo /bin/bash | ||
# ##i##export PS1="(chroot) $PS1"; cd | # ##i##export PS1="(chroot) $PS1"; cd | ||
}} | |||
Configure your system according to the main Install Guide. During startup ZFS Filesystems will be mounted '''without''' the need of entries in {{f|/etc/fstab}}. Other partitions such as CD-ROMs, tmpfs, etc. should still be included in {{f|/etc/fstab}}. | |||
Next, update the portage tree: | |||
{{console|body= | |||
###i## emerge --sync | |||
###i## env-update | |||
###i## source /etc/profile | |||
}} | }} | ||
Revision as of 09:46, October 3, 2016
Introduction
This wiki will show you how to install Funtoo on ZFS (rootfs).
Prerequisites
ZFS designed for 64-bit systems. We only recommending and supporting 64-bit platforms and installations!
ZFS recommendation is to control entire disk, hence, guide reflecting only installing ZFS on whole disk and legacy boot. Installing on UEFI requires separate partition for /boot, formatted into FAT32 and not covered here, though, installation on UEFI is certainly possible. Guide also not describing anything related to encryption.
Downloading the ISO (With ZFS)
In order to install Funtoo on ZFS, you will need an environment such as live media with ZFS tools provided.
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: TBA.
Booting the ISO
(example using ubuntu live iso 16.04.1 amd64)
ubuntu@ubuntu:~$ sudo -i root@ubuntu:~# apt-add-repository universe root@ubuntu:~# apt update root@ubuntu:~# apt install --yes debootstrap gdisk zfs-initramfs
verify that the ZFS kernel module has loaded
root@ubuntu:~# dmesg | grep ZFS [ 377.595348] ZFS: Loaded module v0.6.5.6-0ubuntu10, ZFS pool version 5000, ZFS filesystem version 5
Drive Partitions
We are letting ZFS automatically partition the drive. This ideal for our example using a single disk and legacy (BIOS) boot.
Creating of pool
Create a ZFS Storage Pool using a single whole disk
root@ubuntu:~# zpool create -f -o ashift=12 -o cachefile=/tmp/zpool.cache -O normalization=formD -O atime=off -m none -R /mnt/funtoo rpool /dev/disk/by-id/foo
The options used here are
option | description |
---|---|
create | Use zpool to create a ZFS Storage Pool. |
-f | Force the use of the selected disk. |
-o ashift=12 | Alignment of the pool to underlying device sectors. The recommended value is 12, which corresponds to 2^12 Bytes or 4 KiB. This value is typical of drives nowdays. Can only be set at pool creation. |
-o cachefile=/tmp/zpool.cache | Create a pool configuration cache and place it in /tmp . This will be required for our Funtoo install. |
-O normalization=formD | Recommended. Set the default Unicode (UTF-8) normalization for future filesystems (created within this pool) to 'formD'. |
-O atime=off | Optional. As a default preference, set future filesystems (created within this pool) to not update file access time. Useful if wanting to reduce writes to disk (e.g. Solid State Drives). Can cause problems for mailers and other software relying on file access-time data. |
-m none | Do not set mountpoint for this storage pool. (This guide will address this later). |
-R /mnt/funtoo | Alternate root directory. Essentially a temporary 'mount point' for our pool. |
rpool | The name of this ZFS Storage Pool. The pool name is irrelevant, however rpool will be used throughout this guide. |
/dev/disk/by-id/foo | The path to the physical disk. e.g. /dev/disk/by-id/ata-Samsung_SSD_840_EVO_120GB_123456789ABCDEF. Known in 'ZFS-speak' as a 'VDEV'. |
Please note that the options 'ashift' and 'cachefile' are preceded with a lowercase '-o', while 'normalization' and 'atime' are preceded with an uppercase '-O'.
Without additional options this will create our storage pool and enable all 'features' available under version 0.6.5.6. The pool will be automatically mounted at the (temporary) location /mnt/funtoo
.
To confirm the presence of our newly created pool
root@ubuntu:~# zpool status
pool: rpool
state: ONLINE
scan: none requested
config:
NAME STATE READ WRITE CKSUM
rpool ONLINE 0 0 0
ata-Samsung_SSD_840_EVO_120GB_123456789ABCDEF ONLINE 0 0 0
errors: No known data errors
Create ZFS Datasets
Now we will create one or more ZFS filesystems within our storage pool. These will contain Funtoo Linux.
Create the Root file system (Required)
root # zfs create -o mountpoint=none -o canmount=off rpool/ROOT root # zfs create -o mountpoint=/ rpool/ROOT/funtoo
Create optional Datasets
Described below datasets are examples and optional. It's up to users to perform creation of their own datasets.
Home
root # zfs create -o mountpoint=/home rpool/HOME
Portage directories
root # zfs create -o mountpoint=none -o canmount=off -o setuid=off rpool/FUNTOO root # zfs create -o mountpoint=/usr/portage rpool/FUNTOO/portage root # zfs create -o mountpoint=/usr/portage/distfiles rpool/FUNTOO/distfiles
Build directory
root # zfs create -o mountpoint=/var/tmp/portage -o compression=lz4 -o sync=disabled rpool/FUNTOO/build
To confirm the presence of the filesystems that we have created
root@ubuntu:~# zfs list -t all
NAME USED AVAIL REFER MOUNTPOINT
rpool 660K 19.3G 96K none
rpool/HOME 96K 19.3G 96K /mnt/funtoo/home
rpool/ROOT 192K 19.3G 96K none
rpool/ROOT/funtoo 96K 19.3G 96K /mnt/funtoo
Make the root filesystem bootable
Do not skip this!
When booting from ZFS, you must specify a boot device and a root file system within the pool that was identified by the boot device. By default, the dataset selected for booting is the one identified by the pool's bootfs
property.
root # zpool set bootfs=rpool/ROOT/funtoo rpool
Installing Funtoo
Now that initial ZFS pool created, datasets ready, we can perform stage3 unpack and basic system installation. This part does not differ much from regular Funtoo Linux installation. http://www.funtoo.org/Install#Installing_the_Stage_3_tarball. We recommend using funtoo-current
stages for ZFS.
root # cd /mnt/funtoo root # wget http://build.funtoo.org/funtoo-current/x86-64bit/generic_64/stage3-latest.tar.xz
Extract the contents with the following command, substituting in the actual name of your stage 3 tarball (in case of arch optimized stage).
root # tar xpf stage3-latest.tar.xz
Now we need to create chroot environment by following:
root # cd /mnt/funtoo root # mount -t proc none proc root # mount --rbind /sys sys root # mount --rbind /dev dev
Important step is to copy ZFS cache we created at the very beginning of our rpool
creation into chroot.
root # mkdir -p /mnt/funtoo/etc/zfs root # cp /tmp/zpool.cache /mnt/funtoo/etc/zfs/zpool.cache
You'll also want to copy over resolv.conf
in order to have proper resolution of Internet hostnames from inside the chroot:
root # cp /etc/resolv.conf /mnt/funtoo/etc/
We are ready to chroot
root # chroot /mnt/funtoo /bin/bash root # export PS1="(chroot) $PS1"; cd
Configure your system according to the main Install Guide. During startup ZFS Filesystems will be mounted without the need of entries in /etc/fstab
. Other partitions such as CD-ROMs, tmpfs, etc. should still be included in /etc/fstab
.
Next, update the portage tree:
root # emerge --sync root # env-update root # source /etc/profile
Installing ZFS userspace and bootloader
Installing the ZFS userspace tools and kernel modules
In order to install ZFS packages we need to get portage tree first:
root # emerge --sync root # emerge sys-fs/zfs
Installing GRUB 2
Install grub2:
root # echo "sys-boot/grub libzfs" >> /etc/portage/package.use root # emerge grub
Initial kernel build
Funtoo stage3 have precompiled kernel but initramfs needs rebuilding to include ZFS binaries. This possible with --zfs
argument:
root # genkernel initramfs --no-clean --no-mountboot --zfs
Configuring the Bootloader
sys-boot/grub
require small partition, called Bios boot partition. Remember, that we let ZFS partition whole drive. By design, during this, a very small unpartitioned space left at the beginning of the disk. We will use sgdisk
, which is part of sys-apps/gptfdisk
to format free space into BIOS partition.
root # sgdisk --new=2:48:2047 --typecode=2:EF02 --change-name=2:"BIOS boot partition" /dev/sda
Installing GRUB2 to disk is as easy as:
root # grub-install /dev/sda
Now it's time for us to create grub's configuration file:
root # grub-mkconfig -O /boot/grub/grub.cfg
Final configuration
After reboot
Forgot to reset password?
Troubleshooting
Starting from scratch
Starting again reusing the same disk partitions and the same pool