-
-
Save florian-obradovic/a56600ebbe96a00af9655ac934cdf3c6 to your computer and use it in GitHub Desktop.
Alternative non-bpool/rpool zpool mount systemd 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
Big THX to Satmandu. | |
I just forked his scripts and added a README (https://gist.github.com/satmandu/4da5e900c2c80c93da38c76537291507) | |
HowTo: | |
create /lib/systemd/system/zpool-local.service and set your pool name (mine: tank) and the startup priority/Dependencies: | |
Before=smbd.service snap.lxd.daemon.service | |
ExecStart=+/usr/local/sbin/mount_zfs.sh tank | |
create /usr/local/sbin/mount_zfs.sh | |
chmod +x /usr/local/sbin/mount_zfs.sh | |
systemctl enable zpool-local.service | |
systemctl start zpool-local.service | |
systemctl status zpool-local.service | |
reboot and cross your fingers | |
Regards, Flo. |
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=smbd.service snap.lxd.daemon.service | |
[Service] | |
Type=oneshot | |
# Usage: ExecStart=+/usr/local/bin/mount_zfs.sh zpool1 zpool2 zpool3 ... zpoolN | |
ExecStart=+/usr/local/sbin/mount_zfs.sh tank | |
[Install] | |
WantedBy=multi-user.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment