Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow using the base system as a jail #429

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/share/poudriere/include/fs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,11 @@ clonefs() {
# When using TMPFS, there is no need to clone the originating FS from
# a snapshot as the destination will be tmpfs. We do however need to
# ensure the originating FS is rolled back to the expected snapshot.
if [ -n "${fs}" -a ${TMPFS_ALL} -eq 1 ]; then
if [ ${from} != "/" -a -n "${fs}" -a ${TMPFS_ALL} -eq 1 ]; then
rollbackfs "${snap}" "${from}" "${fs}"
unset fs
fi
if [ -n "${fs}" ]; then
if [ ${from} != "/" -a -n "${fs}" ]; then
name=${to##*/}

if [ "${name}" = "ref" ]; then
Expand All @@ -278,7 +278,19 @@ clonefs() {
echo "debug" >> "${from}/usr/lib/.cpignore" || :
echo "freebsd-update" >> "${from}/var/db/.cpignore" || :
fi
do_clone -r "${from}" "${to}"
if [ ${from} = "/" ]; then
for dir in bin boot boot/modules lib libexec sbin \
usr/bin usr/include usr/lib usr/lib32 \
usr/libdata usr/libexec usr/sbin usr/share \
usr/src; do
if [ -d "${from}/${dir}" ]; then
mkdir -p "${to}/${dir}"
do_clone "${from}/${dir}" "${to}/${dir}"
fi
done
else
do_clone "${from}" "${to}"
fi
if [ "${snap}" = "clean" ]; then
rm -f "${from}/usr/.cpignore" \
"${from}/usr/lib/.cpignore" \
Expand Down
23 changes: 14 additions & 9 deletions src/share/poudriere/jail.sh
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ delete_jail() {
err 1 "Unable to delete jail ${JAILNAME}: it is running"
msg_n "Removing ${JAILNAME} jail..."
method=$(jget ${JAILNAME} method)
if [ "${method}" = "null" ]; then
mnt=$(jget ${JAILNAME} mnt)
# login.conf was not patched if mnt=/
if [ "${method}" = "null" -a "${mnt}" != "/" ]; then
mv -f ${JAILMNT}/etc/login.conf.orig \
${JAILMNT}/etc/login.conf
cap_mkdb ${JAILMNT}/etc/login.conf
Expand Down Expand Up @@ -768,8 +770,6 @@ create_jail() {
if [ "${METHOD}" = "null" ]; then
[ -z "${JAILMNT}" ] && \
err 1 "Must set -M to path of jail to use"
[ "${JAILMNT}" = "/" ] && \
err 1 "Cannot use / for -M"
fi

if [ -z ${JAILMNT} ]; then
Expand Down Expand Up @@ -849,6 +849,10 @@ create_jail() {
null)
JAILFS=none
FCT=
if [ -f "${JAILMNT}/bin/freebsd-version" ]; then
# Override VERSION with what the jail contains
VERSION=$(chroot "${JAILMNT}" /bin/freebsd-version -u)
fi
;;
*)
err 2 "Unknown method to create the jail"
Expand Down Expand Up @@ -883,12 +887,15 @@ create_jail() {
RELEASE="${VERSION}"
fi

cp -f "${JAILMNT}/etc/login.conf" "${JAILMNT}/etc/login.conf.orig"
update_version_env "${RELEASE}"
# Don't do quite a few things if JAILMNT=/
if [ "${JAILMNT}" != "/" ]; then
cp -f "${JAILMNT}/etc/login.conf" "${JAILMNT}/etc/login.conf.orig"
update_version_env "${RELEASE}"

pwd_mkdb -d ${JAILMNT}/etc/ -p ${JAILMNT}/etc/master.passwd
pwd_mkdb -d ${JAILMNT}/etc/ -p ${JAILMNT}/etc/master.passwd

markfs clean ${JAILMNT}
markfs clean ${JAILMNT}
fi

# Check VERSION before running 'update_jail' on jails created using FreeBSD dists.
case ${METHOD} in
Expand Down Expand Up @@ -1160,10 +1167,8 @@ else
GIT_FULLURL=${proto}://${GIT_BASEURL}
fi


case "${CREATE}${INFO}${LIST}${STOP}${START}${DELETE}${UPDATE}${RENAME}" in
10000000)
test -z ${JAILNAME} && usage JAILNAME
case ${METHOD} in
src=*|null|tar) ;;
*) test -z ${VERSION} && usage VERSION ;;
Expand Down