Last active
November 20, 2019 09:01
-
-
Save satmandu/4da5e900c2c80c93da38c76537291507 to your computer and use it in GitHub Desktop.
Alternative non-bpool/rpool zpool mount service for ubuntu 19.10
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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