ZFS

From Funtoo
Revision as of 03:25, August 26, 2018 by Drobbins (talk | contribs) (Created page with "ZFS is an advanced filesystem that is available for use in Funtoo Linux, thanks to the ZFS on Linux project. It is easy to set up and use ZFS. In this quick tutorial, we're...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

ZFS is an advanced filesystem that is available for use in Funtoo Linux, thanks to the ZFS on Linux project.

It is easy to set up and use ZFS. In this quick tutorial, we're going to set up ZFS using an existing debian-sources or debian-sources-lts kernel like the one that comes pre-built for you with Funtoo Linux, and we will also be using our ZFS storage pool for storing data that isn't part of the Funtoo Linux installation itself. This means that we don't need to worry about enabling ZFS support in GRUB, or mounting ZFS to actually boot Funtoo Linux. Funtoo Linux will boot from a non-ZFS filesystem, and as part of the initialization process will initialize our ZFS storage pool and mount it at the location of our choice.

Installation

To install ZFS, perform the following steps:

root # emerge zfs

This will emerge the ZFS userspace tools (zfs) as well as ZFS kernel modules (zfs-kmod and spl). Once complete, enable ZFS in your default runlevel as follows:

root # rc-update add zfs-import default
root # rc

ZFS is now initialized and ready for use.

ZFS Concepts

Unlike traditional filesystems like ext4 and xfs, ZFS is an all-inclusive storage technology that manages its own filesystems without using /etc/fstab. The ZFS concept of importing volumes and their associated filesystems makes them available for use by the operating system. This will be performed when the system boots via the zfs-import startup script.

ZFS also generally manages the physical disks that it uses, and physical disks are added to a ZFS storage pool. Then, ZFS can create volumes from the storage pool on which files can be stored.

Unlike traditional Linux filesystems, ZFS filesystems will allocate storage on-demand from the underlying storage pool. Thus, we can set the "size" of a ZFS volume, but this space only actually allocated when files are stored on the filesystem. In contrast, traditional Linux filesystems like ext4 and xfs must be assigned underlying block storage in advance.

In ZFS terminology, a ZFS storage pool can hold the following things, all of which are considered to be datasets:

  • filesystems - these are what get mounted and you store files in. Generally, this is the main thing people use ZFS for.
  • clones - a filesystem that is created as a copy of an existing snapshot.
  • snapshots - a read-only copy of a filesystem at a given point in time.
  • volume - a dataset that acts as a block device, such as a swap device.

When you inspect the contents of a ZFS storage pool, you will see potentially all these different types of things listed as the contents of the pool, and their names will appear in a pool/path[@snapshot] format. Pool is the name of the storage pool. Path is a slash-delimited path name for the component, and the slashes don't represent directories but a logical organizational hierarchy for the dataset in the pool.

Creating a Storage Pool

To create a basic ZFS storage pool, you will need an extra empty disk. Perform the following steps:

root # zpool create mypool /dev/sdxy

/dev/sdxy should be an unused disk. You may need to use the following command if this disk contains any pre-existing data on it:

root # zpool create -f mypool /dev/sdxy

Once your storage pool is created, you can verify its existence with the zpool status command:

root # zpool status
  pool: mypool
 state: ONLINE
  scan: none requested
config:

	NAME        STATE     READ WRITE CKSUM
	mypool      ONLINE       0     0     0
	  sdb       ONLINE       0     0     0

errors: No known data errors
root #