0. Install Open ZFS on Ubuntu.
sudo apt install zfsutils-linux
1. Create a pool
sudo zpool create red /home/ubuntu/0
- Creates a pool named
red, with single vdev and single disk. In this case disks is a regular file. Full path needs to be provided. Otherwise in Ubuntu
2. Create a dataset
sudo zfs create red/downloads
Creates a dataset named
sudois needed for mounting permissions because regular users can not mount to filesystem.
Mount point defaults if not specified.
3. Attach a device to vdev
sudo zpool attach red /home/ubuntu/0 /home/ubuntu/1
- The pool will "resilver".
4. Detach a device from vdev
sudo zpool detach red /home/ubuntu/1
- The pool will "resilver".
5. Add a second "mirror" vdev to pool
sudo zpool add red mirror /home/ubuntu/2 /home/ubuntu/3
6. Remove top-level vdev from pool
sudo zpool remove red mirror-1
Gives an error.
- It should work with a physical disk, testing here is done with files.
device_removalfeature is enabled.
zpool get all redto list all properties and features of pool
zpool upgrade redto upgrade ZFS features for pool
- zpool-remove man pages
To enable the feature run
sudo zpool set feature@device_removal=enabled red
7. Destroy dataset
sudo zfs destroy red/downloads
- Destroys dataset
downloadson the pool named
8. Destroy pool
sudo zpool destroy red
- Destroys the pool named
9. Import pool
sudo zpool import blue
- Imports pool
blueon same machine or a new machine.
This is useful if moving disks to a new server machine, then all is needed is ZFS installed and run the command to import the pool.
Another case is if the OS is reinstalled, then the pool can be imported. Given that the OS isn't installed on the pool as zroot or "root on ZFS".
zfs snapshot -r blue/backups@test
- Creates snapshots for
blue/backupsand for all descendent file systems by using the -r option.
zfs list -t snapshot
- Lists snapshots
zfs send blue/backups@test | sudo zfs recv blue/backups/new
Send and receive snapshot and mount it as a new dataset at
A dataset is considered an independent file system, moving files across datasets is io intensive even when inside the same pool.
sudo zfs send -R zroot/usr/home@today | ssh email@example.com sudo zfs recv blue/backups/FreeBSD
Sends a snapshot over SSH, mounts it on backup server as a new dataset with all children datasets using option -R.
sudois needed at receiving ent to mount the dataset to fs.
If using incremental snapshots use option -i, and include the original snapshot and all incremental subsequent snapshots. List snapshots
11. ZFS Delegated Permissions
zpool get delegation blue
- Checks if delegation property is on.
zfs allow blue
- Displays Permissions on pool
sudo zfs allow ubuntu create,destroy,mount,mountpoint,snapshot blue
- Sets Permissons for user ubuntu on pool
sudo zfs allow ubuntu create,destroy,mount,mountpoint,snapshot blue/ubuntu
- Sets Permissons for user ubuntu on dataset
12. Other commands
- Shows mounted datasets with mount points.
zpool iostat 5
- Displays io stats every 5 seconds. Add option
-vto include vdevs.
zfs get all
- Displays properties and features.
zfs allow blue/downloads
- Displays Permissions on dataset
FreeBSD specific commands
geom disk list
- Lists disks.
smartctl -a /dev/da0
- Displays S.M.A.R.T. info for device
sudo diskinfo -v da0
- Displays info for disk
sudo smartctl --scan
- Scans for devices.
Testing ZFS using files
for ((i=0;i<=5;++i)); do dd if=/dev/zero of=disk_$i bs=1M count=100; done
for i in $(seq 6); do dd if=/dev/zero of=disk_$i bs=1M count=100; done
Creates 6 empty files for testing.
Files need to be larger than 64MB to be used in ZFS.
sudo zpool create purpleelephants mirror /home/ubuntu/disk_0 /home/ubuntu/disk_1 /home/ubuntu/disk_2 mirror /home/ubuntu/disk_3 /home/ubuntu/disk_4 /home/ubuntu/disk_5
- Creates a pool consisting of two mirrored vdevs with three disks each.
Root on ZFS (zroot) considerations
OS can be installed on a separate disk with either UFS EXT4 or ZFS (root on ZFS) fs, and have separate ZFS pools of disks for user data.
OS can live on a single ZFS pool along with user data on a single zroot pool consisting of however many disks plus have other ZFS pools of disks.