[PC-BSD Commits] r20112 - in pcbsd/branches/9.1/src-sh/warden: bin scripts/backend
svn at pcbsd.org
svn at pcbsd.org
Fri Nov 2 20:09:15 PDT 2012
Author: kris
Date: 2012-11-03 03:09:15 +0000 (Sat, 03 Nov 2012)
New Revision: 20112
Modified:
pcbsd/branches/9.1/src-sh/warden/bin/warden
pcbsd/branches/9.1/src-sh/warden/scripts/backend/createjail.sh
pcbsd/branches/9.1/src-sh/warden/scripts/backend/functions.sh
Log:
MFC the enhancements to the warden CLI, allowing us to use ZFS cloning for
new jail creation, and also a -32 flag for building jails
Modified: pcbsd/branches/9.1/src-sh/warden/bin/warden
===================================================================
--- pcbsd/branches/9.1/src-sh/warden/bin/warden 2012-11-03 03:07:44 UTC (rev 20111)
+++ pcbsd/branches/9.1/src-sh/warden/bin/warden 2012-11-03 03:09:15 UTC (rev 20112)
@@ -507,6 +507,7 @@
Creates a new jail, with options for system source, ports and autostarting.
Available Flags:
+ -32 (Create 32bit jail on 64bit system)
--src (Includes /usr/src system source)
--ports (Includes the ports tree)
--startauto (Start this jail at system boot)
@@ -864,6 +865,12 @@
exit_err "--linuxjail and --linuxarchive are mutually exclusive!"
fi
;;
+ -32) if [ "$REALARCH" != "amd64" ] ; then
+ exit_err "-32 can only be used on amd64 host"
+ fi
+ ARCH=i386
+ export ARCH
+ ;;
--archive) shift
if [ -z "$1" ] ; then exit_err "No archive file specified!"; fi
ARCHIVE_FILE="$1" ; export ARCHIVE_FILE
Modified: pcbsd/branches/9.1/src-sh/warden/scripts/backend/createjail.sh
===================================================================
--- pcbsd/branches/9.1/src-sh/warden/scripts/backend/createjail.sh 2012-11-03 03:07:44 UTC (rev 20111)
+++ pcbsd/branches/9.1/src-sh/warden/scripts/backend/createjail.sh 2012-11-03 03:09:15 UTC (rev 20112)
@@ -2,6 +2,22 @@
# Script to create a new jail based on given flags
#####################################################################
+# Source our functions
+PROGDIR="/usr/local/share/warden"
+
+# Source our variables
+. ${PROGDIR}/scripts/backend/functions.sh
+
+# Location of the chroot environment
+isDirZFS "${JDIR}"
+if [ $? -eq 0 ] ; then
+ WORLDCHROOT="${JDIR}/.warden-chroot-${ARCH}"
+ export WORLDCHROOT
+else
+ WORLDCHROOT="${JDIR}/.warden-chroot-${ARCH}.txz"
+ export WORLDCHROOT
+fi
+
setup_linux_jail()
{
echo "Setting up linux jail..."
@@ -60,12 +76,6 @@
echo "Success! Linux jail created at ${JDIR}/${IP}"
}
-# Source our functions
-PROGDIR="/usr/local/share/warden"
-
-# Source our variables
-. ${PROGDIR}/scripts/backend/functions.sh
-
# Load our passed values
IP="${1}"
HOST="${2}"
@@ -109,27 +119,38 @@
# Check if we need to download the chroot file
if [ ! -e "${WORLDCHROOT}" -a "${LINUXJAIL}" != "YES" ] ; then downloadchroot ; fi
-isDirZFS "${JDIR}"
-if [ $? -eq 0 ] ; then
- # Create ZFS mount
- tank=`getZFSTank "$JDIR"`
- zfs create -o mountpoint=${JAILDIR} -p ${tank}${JAILDIR}
-else
- mkdir -p "${JAILDIR}"
-fi
# If we are setting up a linux jail, lets do it now
if [ "$LINUXJAIL" = "YES" ] ; then
+ isDirZFS "${JDIR}"
+ if [ $? -eq 0 ] ; then
+ # Create ZFS mount
+ tank=`getZFSTank "$JDIR"`
+ zfs create -o mountpoint=${JAILDIR} -p ${tank}${JAILDIR}
+ else
+ mkdir -p "${JAILDIR}"
+ fi
setup_linux_jail
exit 0
fi
echo "Building new Jail... Please wait..."
-echo "Installing world..."
-tar xvf ${WORLDCHROOT} -C "${JAILDIR}" 2>/dev/null
-echo "Done"
+isDirZFS "${JDIR}"
+if [ $? -eq 0 ] ; then
+ # Create ZFS CLONE
+ tank=`getZFSTank "$JDIR"`
+ zfs clone ${tank}${WORLDCHROOT}@clean ${tank}${JAILDIR}
+ if [ $? -ne 0 ] ; then exit_err "Failed creating clean ZFS base clone"; fi
+else
+ # Running on UFS
+ mkdir -p "${JAILDIR}"
+ echo "Installing world..."
+ tar xvf ${WORLDCHROOT} -C "${JAILDIR}" 2>/dev/null
+ echo "Done"
+fi
+
mkdir ${JMETADIR}
echo "${HOST}" > ${JMETADIR}/host
echo "${IP}" > ${JMETADIR}/ip
Modified: pcbsd/branches/9.1/src-sh/warden/scripts/backend/functions.sh
===================================================================
--- pcbsd/branches/9.1/src-sh/warden/scripts/backend/functions.sh 2012-11-03 03:07:44 UTC (rev 20111)
+++ pcbsd/branches/9.1/src-sh/warden/scripts/backend/functions.sh 2012-11-03 03:09:15 UTC (rev 20112)
@@ -13,9 +13,13 @@
JDIR="$(grep ^JDIR: /usr/local/etc/warden.conf | cut -d' ' -f2)"
export JDIR
-# Location of the chroot environment
-WORLDCHROOT="${JDIR}/.warden-chroot.txz"
-export WORLDCHROOT
+# Set arch type
+REALARCH=`uname -m`
+export REALARCH
+if [ -z "$ARCH" ] ; then
+ ARCH="$REALARCH"
+ export ARCH
+fi
# Location of pcbsd.conf file
PCBSD_ETCCONF="/usr/local/etc/pcbsd.conf"
@@ -48,7 +52,6 @@
SYSVER="$(pbreg get /PC-BSD/Version)"
FBSD_TARBALL="fbsd-release.txz"
FBSD_TARBALL_CKSUM="${FBSD_TARBALL}.md5"
- ARCH=`uname -m`
# Set the mirror URL, may be overridden by setting MIRRORURL environment variable
if [ -z "${MIRRORURL}" ]; then
@@ -71,8 +74,28 @@
[ "$(md5 -q ${FBSD_TARBALL})" != "$(cat ${FBSD_TARBALL_CKSUM})" ] &&
printerror "Error in download data, checksum mismatch. Please try again later."
- # Save the chroot tarball
- mv ${FBSD_TARBALL} ${WORLDCHROOT}
+ # Creating ZFS dataset?
+ isDirZFS "${JDIR}"
+ if [ $? -eq 0 ] ; then
+ # Use ZFS base for cloning
+ echo "Creating ZFS ${WORLDCHROOT} dataset..."
+ tank=`getZFSTank "$JDIR"`
+ isDirZFS "${WORLDCHROOT}" "1"
+ if [ $? -ne 0 ] ; then
+ zfs create -o mountpoint=${WORLDCHROOT} -p ${tank}${WORLDCHROOT}
+ if [ $? -ne 0 ] ; then exit_err "Failed creating ZFS base dataset"; fi
+ fi
+
+ tar xvpf ${FBSD_TARBALL} -C ${WORLDCHROOT} 2>/dev/null
+ if [ $? -ne 0 ] ; then exit_err "Failed extracting ZFS chroot environment"; fi
+
+ zfs snapshot ${tank}${WORLDCHROOT}@clean
+ if [ $? -ne 0 ] ; then exit_err "Failed creating clean ZFS base snapshot"; fi
+ rm ${FBSD_TARBALL}
+ else
+ # Save the chroot tarball
+ mv ${FBSD_TARBALL} ${WORLDCHROOT}
+ fi
rm ${FBSD_TARBALL_CKSUM}
};
More information about the Commits
mailing list