vermaden / automount

Simple devd(8) based automounter for FreeBSD
66 stars 20 forks source link

Consider automounting ZFS pools #28

Open probonopd opened 3 years ago

probonopd commented 3 years ago

User story: As a user, I want to take the ZFS-formatted disk of computer A out of the computer (e.g., when it is not booting anymore), and attach it to a working computer B using a USB adapter. I expect the disk to be automounted so that I can access the files.

Currently disks that use ZFS behave differently from other disks, e.g., those formatted with FAT or NTFS. Automounting ZFS pools with altroot would lead to a more consistent behavior for users who expect to plug in a disk and have it mounted no matter which filesystem the disk has been formatted with.

Right now I am using the following script to "mount" all ZFS pools:

# Import ("mount") all ZFS pools read-only to /media/zfs-altroot-...
# that are online (physically attached) but are not yet imported ("mounted")
NUMERICS=$(sudo zpool import -N -F -n | grep "id:" | cut -d ":" -f 2 | xargs)
for NUMERIC in $NUMERICS ; do
  mkdir -p "/media/zfs-altroot-${NUMERIC}"
  zpool import -o altroot="/media/zfs-altroot-${NUMERIC}" -o readonly=on "${NUMERIC}" "zfs-altroot-${NUMERIC}" -f
done

And to "unmount":

# Export ("unmount") all ZFS pools "mounted" to /media/zfs-altroot-...
NUMERICS=$(zpool list | grep "/media/zfs-altroot-" | grep ONLINE |  awk '{print $1}' | xargs)
for NUMERIC in $NUMERICS ; do
  sudo zpool export -f "${NUMERIC}" && rm -r "/media/${NUMERIC}"
done

I don't know how to properly hook this into automount but maybe it gives you an idea.

Thanks for considering.

vermaden commented 3 years ago

I will think about that.

Thanks for sharing these script snippets.

Regards.