Nowadays I can easily forget what I’ve already done. When it comes to ZFS, that includes forgetting what pools I’d already created on a particular device. That’s the point of this “memo to self” …
zpool import is your friend.
When you want to import the pools after juggling disks between machines, but can’t remember what the heck you named the pools in the first place, just do:-
…to display a list of all available pools which are not currently attached (or a message to the effect that there are none available). The important point here is that it won’t actually try to actually import any pools with this simple command; it only lists them.
If you have a pool which is shown as available for import (ie:- it exists, but is not currently attached — which might be the case if you’ve just physically moved a disk from some other machine to this system), you can temporarily have it imported and attached to a temporary mount point using the “
-R /tmp/NAME” option. This can be really handy for recovering data from a “retired” drive. For instance, an old disk has a “data_tank” pool, which had the mountpoint “/store” on the old machine. You want to recover some data from that drive, but your current system already has “d_pool” mounted at “/store”, so you can’t simply do “zpool import data_tank”, because the mountpoint is already in use. Your import command should instead be:-
zpool import -R /tmp/old_store data_tank
…and all of your old data will be mounted to /tmp/old_store where you can access it normally. But wait, there’s more!
If you already have an existing pool named “data_tank” on your current system, you can have “import” rename the old pool to something different (to prevent embarrassing mistakes) by simply appending a new name to the previous command:-
zpool import -R /tmp/old_store data_tank old_data_tank
Now when you do a “
zpool status” or “
zpool list” the pool mounted from the old disk will show up as “old_data_tank”.
When things go awry
What about if you’ve already suffered some late-night brain fade and just destroyed the live pool on your current system by mistake? Well, as long as you realize your mistake fairly promptly and haven’t already scribbled all over the disk, import can help you with that, too. The “-D” option will show you any pools which have been destroyed, but for which ZFS can still find valid metadata. So:-
zpool import -D
…will display all pools, including previously destroyed ones, which still appear to be available for importing.
zpool import -D -f -R /tmp/old_store data_tank old_data_tank
…will import the original “data_tank” pool (note the -D -f options to force import of a previously destroyed pool) with the new pool name of “old_data_tank” and mount it at /tmp/old_store.
More pool recovery tricks
There are additional options to “import” which can further aid recovery of incomplete pools (see the zpool manual page entries for import and check the “-F”, “-m” and “-n” options for more information on how import can provide extra help for getting out of sticky situations).
Doing things nicely
While the import command will do it’s very best to save you from yourself, you can help things along considerably by doing the right thing and using the “export” command on any pool which you intend to re-import elsewhere at a later date. Note that this command will make the target pool unavailable on the system where you run it (that’s the whole point …to effectively shut down the pool cleanly and prevent any further modifications by marking it as still being reserved space), but the subsequent import shouldn’t have any difficulty at all when re-importing a previously exported pool.