What ZFS has to offer for a laptop
ZFS is best used in a RAID configuration:
- mirror (at least 2 disks)
- raidz1 (at least 3 disks)
- raidz2 (at least 4 disks)
- raidz3 (5 or more disks)
A laptop does not typically offer the advantage of being able to house so many disks. Nevertheless, ZFS offers other advantages that make it sensible to use on a laptop:
- scrubbing and on-line file system repair
- snapshots
- transparent compression
- transparent encryption
I have two drives in my laptop:
- a 256 GB SSD OS drive
- a 512 GB 7200 RPM expansion drive
It might make sense at some point to replace the expansion drive with a higher capacity drive. For now, I installed ZFS onto the expansion drive, inspired by:
http://www.ibm.com/developerworks/library/l-zfs/index.html
Ideally, I would have a mirror between my OS drive and a partition on the expansion drive; however, not only is my expansion drive fairly limited, but also this is my first attempt at using ZFS beyond FreeNAS, which handles ZFS at arm’s length. So, I decided to start with something simple: ZFS on an unmirrored disk.
Preliminary step
Although the kernel in Ubuntu 16.04 LTS supports ZFS, I needed to install the ZFS utils:
apt-get install zfsutils-linux
to use the zpool
and zfs
commands.
What I should have done, perhaps
If I am reading the man page correctly for the zpool
command (which says that the device name path is relative to /dev
), I could have deduced the invariant id for my disk
ata-HGST_HTS725050A7E630_RCF50ACE1P7B7M
using the command:
ls -l /dev/disk/by-id
and then creating and mounting the “zpool” called “zpdrone” using the command
zpool create zpdrone disk/by-id/\
ata-HGST_HTS725050A7E630_RCF50ACE1P7B7M
What I actually did
Unfortunately for me, I hadn’t quite understood the man page, so I went with the first thing that worked:
zpool create zpdrone sda
I next created a ZFS file system (“drone”) and enabled compression:
zfs create zpdrone/drone
zfs set compression=on zpdrone/drone
I proceeded to add some files to my file system (which was mounted at /zpdrone/drone
), rebooted, and verified that I could see the files.
What went wrong, and how to fix it
Shortly thereafter, I booted with an external drive attached.
I found that the external drive was assigned to sda
, so my expansion drive was assigned to sdb
, and consequently my zpool didn’t get mounted; this gave me the opportunity to learn how to untangle the mess that I had caused. As it turns out, this was not hard to do.
The first step was to “export” the pool (roughly equivalent to sync’ing and unmounting it):
zpool export zpdrone
The second step was to “import” the pool using the disk ID and pool ID. I obtained the pool ID (269414010796639802) from the output of
zpool import
and then told zpool to import it by searching under
/dev/disk/byid
for a zpool with the zpool ID
zpool import -d /dev/disk/by-id \
269414010796639802
Once again, my file system was mounted at
/zpdrone/drone
.
Subsequently, I could boot with an attached external hard drive, and, as expected,
zpool status
showed the disk ID for the pool
(
ata-HGST_HTS725050A7E630_RCF50ACE1P7B7M).