Last active
May 11, 2023 22:30
-
-
Save 2510/eb9c83c7e8949f857228a4602c14a27a to your computer and use it in GitHub Desktop.
FreeBSD rc.script for activating ZFS pool over iSCSI
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/sh | |
# PROVIDE: iscsi-zfs | |
# REQUIRE: iscsid iscsictl mountcritlocal var | |
. /etc/rc.subr | |
name="iscsi_zfs" | |
start_cmd="iscsi_zfs_start" | |
stop_cmd="iscsi_zfs_stop" | |
rcvar="iscsi_zfs_enable" | |
iscsi_zfs_enable=${iscsi_zfs_enable:-"NO"} | |
iscsi_zfs_wait_iqn=${iscsi_zfs_wait_iqn:-""} | |
iscsi_zfs_wait_pool=${iscsi_zfs_wait_pool:-""} | |
iscsi_zfs_wait_retry=${iscsi_zfs_wait_retry:-"30"} | |
iscsi_zfs_start() | |
{ | |
retry=0 | |
while [ "$retry" -lt "${iscsi_zfs_wait_retry}" ] | |
do | |
if iscsictl | fgrep "${iscsi_zfs_wait_iqn}" | fgrep "Connected: " >/dev/null; then | |
break | |
fi | |
retry=`expr ${retry} + 1` | |
sleep 1 | |
done | |
while [ "$retry" -lt "${iscsi_zfs_wait_retry}" ] | |
do | |
if zpool status "${iscsi_zfs_wait_pool}" >/dev/null 2>&1; then | |
break | |
fi | |
retry=`expr ${retry} + 1` | |
sleep 1 | |
done | |
while [ "$retry" -lt "${iscsi_zfs_wait_retry}" ] | |
do | |
zfs mount -a | |
if mount | fgrep "${iscsi_zfs_wait_pool}" >/dev/null 2>&1; then | |
break | |
fi | |
retry=`expr ${retry} + 1` | |
sleep 1 | |
done | |
} | |
load_rc_config $name | |
run_rc_command "$1" |
Yes, this script expects target pools to be imported already (and imported state persists over reboots).
I'm not sure whether imported pools persists over reboot, but adding zpool import "${iscsi_zfs_wait_pool}"
in retry-loop may help.
while [ "$retry" -lt "${iscsi_zfs_wait_retry}" ]
do
if zpool status "${iscsi_zfs_wait_pool}" >/dev/null 2>&1; then
break
fi
+ zpool import "${iscsi_zfs_wait_pool}"
retry=`expr ${retry} + 1`
sleep 1
It can be even more simple. 'zpool import -a' mounts all imported pools.
Thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a lot for your help! Now it starts but it does not seem to work. The problem that the script expects pools already be imported. But the fact is that after reboot the list of pools is empty. It requres zpool import to be done first. Maybe either the issue with the local iscsictl configuration, or remote iscsi share, or zfs pool requires some special setting.
Upd: It seems that there is a difference between FreeBSD 13 and FreeBSD 12.2. 12.2 works as expected. After reboot 12.2 has a zfs pool in place