"Plug-and-play" ZFS external hard drive

New to OpenZFS on OS X (Or ZFS in general)? Ask your questions here!

"Plug-and-play" ZFS external hard drive

Postby michaelsproul » Fri Apr 07, 2017 5:15 pm

Hi all,

I've created a 1-disk ZFS pool using my 2TB external hard drive, and so far I'm loving it. However, I'd like to improve the ergonomics around plugging it in and unplugging it. If I'm not mistaken, pools need to be imported if they are connected after boot, and exported before ejecting the relevant disks. Running sudo zpool import <pool> and sudo zpool export <pool> in a terminal isn't sooo unergonomic, but sometimes I just want to plug the disk in, yank one episode of Rick and Morty off it, and then unplug it.

I think I've solved the plugging in side of things with a hacky C program I wrote that listens for Apple's "DiskArbitration" events and runs zpool import -a as root whenever a new disk is connected to the system (probably overkill, and might also be subject to a race condition if zpool doesn't deem the disk ready yet). It does seem to work though. Code is here: https://github.com/michaelsproul/autozfs. What do you think of this approach? Is there a better alternative that doesn't require running yet-another daemon? The InvariantDisks daemon that comes with O3X listens for the same events, maybe they could be combined?

Regarding ejects, I think all that needs to happen is for OpenZFS to do a pool export when ejecting a disk from Finder. At the moment ejecting a stand-alone ZFS external disk unmounts the filesystem but doesn't export the pool. I think there's a slight conceptual mismatch here (because ZFS isn't like other filesystems) but we could hack something together that works for this use-case, which I imagine would be fairly common amongst home users like myself.

Anyway, thanks for reading, interested to hear your thoughts on this and any other tips and tricks you're using,


Posts: 1
Joined: Fri Apr 07, 2017 4:29 pm

Re: "Plug-and-play" ZFS external hard drive

Postby rob09234 » Sat Dec 23, 2017 3:11 am

I am also interested in this topic and it would be nice if someone with more ZFS-experience could evaluate this approach.

Posts: 1
Joined: Sat Dec 23, 2017 3:07 am

Re: "Plug-and-play" ZFS external hard drive

Postby nodarkthings » Sat Dec 23, 2017 4:46 pm

It might not be what you're looking for, but I use AppleScripts, one to mount, the other to unmount, one of each per zfs pool.
I'm using the root user and its password:
Code: Select all
do shell script "zpool import -f Tank" user name "root" password "root_password" with administrator privileges

Code: Select all
do shell script "zpool export Tank" user name "root" password "root_password" with administrator privileges

P.S.: I'm on 10.9.5, I don't know if AppleScript syntax has changed in recent OSes, but there shouldn't be much difference...
Posts: 70
Joined: Mon Jan 26, 2015 10:32 am

Re: "Plug-and-play" ZFS external hard drive

Postby Sharko » Tue Jan 02, 2018 12:29 pm

Errr, nodarkthings, are you keeping a plain-text Applescript on your system with a root password embedded in it? Yikes, that seems like a bad security risk to me.
Posts: 41
Joined: Thu May 12, 2016 12:19 pm

Re: "Plug-and-play" ZFS external hard drive

Postby nodarkthings » Tue Jan 02, 2018 12:40 pm

Well, of course, this is on a totally "isolated" computer. ;)
Of course, you can make a more complex script for it to ask for your pw every time. 8-)
It might start with something like:
Code: Select all
set shortname to do shell script "whoami"
set x to display dialog "Enter the administrator password for " & shortname default answer ""

If you're interested and not too brave at AppleScript, I could try and make a "less risky" one for you.

EDIT: actually, there's something really simple, you just have to use the scripts I gave without
Code: Select all
user name "root" password "root_password"

It will only ask for your admin password the first time you use them during a session.
Posts: 70
Joined: Mon Jan 26, 2015 10:32 am

Return to Absolute Beginners Section

Who is online

Users browsing this forum: No registered users and 3 guests