Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider automounting ZFS pools #28

Open
probonopd opened this issue Apr 6, 2021 · 1 comment
Open

Consider automounting ZFS pools #28

probonopd opened this issue Apr 6, 2021 · 1 comment

Comments

@probonopd
Copy link

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
Copy link
Owner

vermaden commented Apr 7, 2021

I will think about that.

Thanks for sharing these script snippets.

Regards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants