Skip to content

Instantly share code, notes, and snippets.

@2510
Last active May 11, 2023 22:30
Show Gist options
  • Save 2510/eb9c83c7e8949f857228a4602c14a27a to your computer and use it in GitHub Desktop.
Save 2510/eb9c83c7e8949f857228a4602c14a27a to your computer and use it in GitHub Desktop.
FreeBSD rc.script for activating ZFS pool over iSCSI
#!/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"
@amikhail74
Copy link

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