Skip to content

Consider automounting ZFS pools #28

@probonopd

Description

@probonopd

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions