notify 100 {
    match "system" "DEVFS";
    match "subsystem" "CDEV";
    match "type" "CREATE";
    match "cdev" "da[0-9]+$";
    action "/usr/local/sbin/zfs-autoimport.sh $cdev attach";
};zpool import -o readonly=on <pool name>#!/bin/sh
#   -------------------------------------------------------------
#   ZFS auto import
#   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
set -e
#   -------------------------------------------------------------
#   Parse arguments
#   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if [ $# -lt 3 ]; then
    echo "Usage: $(basename "$0") <device> <action>" >&2
    exit 1
fi
CDEV=$1
ACTION=$2
#   -------------------------------------------------------------
#   Handle the ZFS pool
#   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Here some heuristic to find pool name?
# What about parsing `zpool import -aN`?
POOL=external
LOGTAG=zfs-autoimport
# Device needs a little time to be available
sleep 3
if [ "$ACTION" = "attach" ]; then
    logger -t $LOGTAG "Trying to import ZFS pool for device $CDEV"
    zpool import -o readonly=on $POOL
elif [ "$ACTION" = "detach" ]; then
    logger -t $LOGTAG "Trying to export ZFS pool as device $CDEV has been removed"
    zpool export $POOL
else
fiThere are various pool names following no convention.The challenge for me is to find a way to detect in zfs-autoimport.sh you inserted a drive with a ZFS pool,
$ zpool import | grep -F pool: | cut -c10-$ zpool import <poolname> them and$ zpool status <poolname> | grep -F " ONLINE " | tail -1$ zpool export <poolname> and continue what we do if not zfs$ beep if successful$ cat /usr/local/etc/devd/mmcsd.conf
# see also https://wiki.freebsd.org/Devd but IMO simpler than automountd
notify 100 {
    match "system"        "GEOM";
    match "subsystem"    "DEV";
    match "type"        "CREATE|DESTROY";
    match "cdev"        "mmcsd.+";
    action "sh /usr/local/etc/devd/mmcsd.sh $type $cdev";
};$ cat /usr/local/etc/devd/mmcsd.sh
#!/bin/sh
# see also https://wiki.freebsd.org/Devd but IMO simpler than automountd
echo "$0 $@" | logger -t devd
set -e
case $1 in
"CREATE")
  shift
  sleep 2
  pool="$(zpool import | grep -B 1 -F " $1 " | grep -oE "[^ ]+"| head -1 | xargs)"
  zpool import -o readonly=on "$pool"
  beep
  echo "Mounted readonly. Make writeable: zpool export $pool && zpool import $pool # $1" | logger -t devd
  ;;
"DESTROY")
  shift
  pool="$(zpool status | grep -B 1 -F "$1" | grep -oE "[^ ]+" | head -1 | xargs)"
  [ "$pool" = "" ] && exit 0
  echo "zpool export -f $pool # $1" | logger -t devd
  zpool export -f "$pool"
  rmdir "/media/zfs/$pool"
  ;;
*)
  exit 1
  ;;
esacI guess soIs it good idea to store ZFS
why not?on flash?
why? I think e.g. Linux won't like it.Why not UFS
