Skip to content

Instantly share code, notes, and snippets.

@satmandu
Last active November 20, 2019 09:01
Show Gist options
  • Save satmandu/4da5e900c2c80c93da38c76537291507 to your computer and use it in GitHub Desktop.
Save satmandu/4da5e900c2c80c93da38c76537291507 to your computer and use it in GitHub Desktop.
Alternative non-bpool/rpool zpool mount service for ubuntu 19.10
#!/bin/bash -e
#export PS4='+(${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
# Place in /usr/local/sbin/mount_zfs.sh
USAGE="Usage: $0 zpool1 zpool2 zpool3 ... zpoolN"
MOUNTATTEMPTS=50
COUNTER=1
if [ "$#" == "0" ]; then
echo "$USAGE"
exit 0
fi
mount_zpool () {
[[ $COUNTER -ge $MOUNTATTEMPTS ]] && return 1
if zpool list | grep "${pool}" > /dev/null; then
echo "${pool} already mounted."
COUNTER=$MOUNTATTEMPTS
return 1
else
echo "${pool} mount attempt ${COUNTER}."
zpool import "${pool}"
if ! (zpool list | grep "${pool}" > /dev/null); then
echo "${pool} mount attempt ${COUNTER} failed."
sleep "${SLEEP}"
((COUNTER=COUNTER+1))
((SLEEP=SLEEP+1))
return 0
else
echo "${pool} mounted."
return 1
fi
fi
}
while (( "$#" )); do
pool="${1}"
SLEEP=1
if zpool list | grep "${pool}" > /dev/null; then
echo "${pool} already mounted."
else
while mount_zpool ; do
echo "${pool} mount complete."
done
fi
shift
done
[Unit]
Description=Create Local ZFS mounts
# Placed in /lib/systemd/system/zpool-local.service
Requires=systemd-udev-settle.service
After=systemd-remount-fs.service
After=systemd-udev-settle.service
# Usage: Before=smbd.service containerd.service ...service
Before=
[Service]
Type=oneshot
# Usage: ExecStart=+/usr/local/bin/mount_zfs.sh zpool1 zpool2 zpool3 ... zpoolN
ExecStart=+/usr/local/sbin/mount_zfs.sh
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment