summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xezjail-admin37
1 files changed, 30 insertions, 7 deletions
diff --git a/ezjail-admin b/ezjail-admin
index 5c67d38..79233ce 100755
--- a/ezjail-admin
+++ b/ezjail-admin
@@ -327,13 +327,26 @@ parse_gbde_attach_args () {
327 return ${_exit} 327 return ${_exit}
328} 328}
329 329
330check_for_zfs () { 330check_for_zfs () {
331 . "/etc/rc.conf" 331 # check the ZFS version
332 if [ "${ezjail_use_zfs}" = "YES" ] && [ "${zfs_enable}" != "YES" ]; then 332 _zfs_version=`sysctl -nq vfs.zfs.version.spa`
333 echo "You have to enable ZFS in /etc/rc.conf" 333 [ "${_zfs_version}" ] || _zfs_version=0
334 if [ "${_zfs_version}" -lt "13" ]; then
335 echo "ERROR: ZFS is not loaded or your ZFS version is not supported."
334 exit 336 exit
335 fi 337 fi
338
339 # check if ZFS is enabled when managing basejail/newjail in ZFS
340 . /etc/rc.subr
341 load_rc_config_var zfs zfs_enable
342 if [ "${ezjail_use_zfs}" = "YES" ] && [ "${zfs_enable}" != "YES" ]; then
343 echo "WARNING: You should enable ZFS in /etc/rc.conf"
344 fi
345}
336 346
347check_for_zpool () {
348 # check for the ZFS zpool to be online
349 check_for_zfs
337 _zpoolstatus=`/sbin/zpool list -H -o health ${ezjail_jailzfs%%/*} 2> /dev/null` 350 _zpoolstatus=`/sbin/zpool list -H -o health ${ezjail_jailzfs%%/*} 2> /dev/null`
338 if [ ! "${_zpoolstatus}" = "ONLINE" ]; then 351 if [ ! "${_zpoolstatus}" = "ONLINE" ]; then
339 echo "Your zpool does not exist or is not online." 352 echo "Your zpool does not exist or is not online."
@@ -348,8 +361,6 @@ check_for_zfs () {
348# check for command 361# check for command
349[ $# -gt 0 ] || exerr ${ezjail_usage_ezjailadmin} 362[ $# -gt 0 ] || exerr ${ezjail_usage_ezjailadmin}
350 363
351check_for_zfs
352
353case "$1" in 364case "$1" in
354######################## ezjail-admin CREATE ######################## 365######################## ezjail-admin CREATE ########################
355create) 366create)
@@ -376,6 +387,11 @@ create)
376 387
377 # show the user the type of image used 388 # show the user the type of image used
378 echo "TYPE: $ezjail_imagetype" 389 echo "TYPE: $ezjail_imagetype"
390
391 # check for an active ZFS zpool
392 if [ "${ezjail_imagetype}" = "zfs" ]; then
393 check_for_zpool
394 fi
379 395
380 # check for sanity of settings concerning the image feature 396 # check for sanity of settings concerning the image feature
381 if [ "${ezjail_imagetype}" != "zfs" ]; then 397 if [ "${ezjail_imagetype}" != "zfs" ]; then
@@ -567,7 +583,7 @@ create)
567 # if the automount feature is not disabled, this fstab entry for new jail 583 # if the automount feature is not disabled, this fstab entry for new jail
568 # will be obeyed 584 # will be obeyed
569 echo -n > /etc/fstab.${ezjail_safename} 585 echo -n > /etc/fstab.${ezjail_safename}
570 if [ "${ezjail_imagetype}" ] && [ ! "${ezjail_imagetype}" = "zfs" ] ; then 586 if [ "${ezjail_imagetype}" -a "${ezjail_imagetype}" != "zfs" ] ; then
571 echo ${ezjail_devicelink} ${ezjail_rootdir} ufs rw 0 0 >> "/etc/fstab.${ezjail_safename}" 587 echo ${ezjail_devicelink} ${ezjail_rootdir} ufs rw 0 0 >> "/etc/fstab.${ezjail_safename}"
572 fi 588 fi
573 echo ${ezjail_jailbase} ${ezjail_rootdir}/basejail nullfs ro 0 0 >> "/etc/fstab.${ezjail_safename}" 589 echo ${ezjail_jailbase} ${ezjail_rootdir}/basejail nullfs ro 0 0 >> "/etc/fstab.${ezjail_safename}"
@@ -655,6 +671,11 @@ delete)
655 671
656 # check for existence of jail in our records 672 # check for existence of jail in our records
657 [ "${ezjail_config}" ] || exerr "Error: Nothing known about jail ${ezjail_name}." 673 [ "${ezjail_config}" ] || exerr "Error: Nothing known about jail ${ezjail_name}."
674
675 # check for an active ZFS zpool
676 if [ "${ezjail_imagetype}" = "zfs" ]; then
677 check_for_zpool
678 fi
658 679
659 if [ "${ezjail_id}" ]; then 680 if [ "${ezjail_id}" ]; then
660 # if jail is still running, refuse to go any further 681 # if jail is still running, refuse to go any further
@@ -741,6 +762,7 @@ setup|update)
741 [ "${ezjail_installaction}" ] || exerr "Error: No install action has been chosen.\n Please note that ezjails behaviour changed. Rebuilding the world no longer is default.\n Run '${ezjail_admin} update -b' to build and install a world from source or '${ezjail_admin} update -i' to install an already built world." 762 [ "${ezjail_installaction}" ] || exerr "Error: No install action has been chosen.\n Please note that ezjails behaviour changed. Rebuilding the world no longer is default.\n Run '${ezjail_admin} update -b' to build and install a world from source or '${ezjail_admin} update -i' to install an already built world."
742 763
743 if [ "${ezjail_use_zfs}" = "YES" ]; then 764 if [ "${ezjail_use_zfs}" = "YES" ]; then
765 check_for_zpool
744 zfs create -p -o mountpoint=${ezjail_jaildir} ${ezjail_jailzfs} 766 zfs create -p -o mountpoint=${ezjail_jaildir} ${ezjail_jailzfs}
745 fi 767 fi
746 768
@@ -831,6 +853,7 @@ install)
831 # Normally fulljail should be renamed by past ezjail-admin commands. 853 # Normally fulljail should be renamed by past ezjail-admin commands.
832 # However those may have failed 854 # However those may have failed
833 if [ "${ezjail_use_zfs}" = "YES" ]; then 855 if [ "${ezjail_use_zfs}" = "YES" ]; then
856 check_for_zpool
834 echo "ZFS: manage basejail and newjail" 857 echo "ZFS: manage basejail and newjail"
835 [ -d "${ezjail_jailfull}" ] && /sbin/zfs destroy -R "${ezjail_jailzfs}/fulljail" && rm -rf "${ezjail_jailfull}" 858 [ -d "${ezjail_jailfull}" ] && /sbin/zfs destroy -R "${ezjail_jailzfs}/fulljail" && rm -rf "${ezjail_jailfull}"
836 /sbin/zfs create -p "${ezjail_jailzfs}/fulljail" || exerr "Error: Cannot create temporary Jail directory." 859 /sbin/zfs create -p "${ezjail_jailzfs}/fulljail" || exerr "Error: Cannot create temporary Jail directory."