Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.