cbsd: [jcreate] `extract` option cannot be used with `inter=0`

Background

FreeBSD version (uname -a):

FreeBSD bazinga.localdomain 11.2-RELEASE FreeBSD 11.2-RELEASE #0 r335510: Fri Jun 22 04:32:14 UTC 2018 root@releng2.nyi.freebsd.org:/usr/obj/usr/src/sys/GENERIC amd64

CBSD version (cbsd version):

12.0.3

Firstly, thank you for this tool! Its ability to run in non-interactive shell, download and use distribution release binaries feature in jcreate, are some rare gems! 💎

On a fresh FreeBSD amd64 system, a script takes precisely seven steps to get into ia32 jail:

Code (click or tap to expand)
#!/usr/bin/env sh

# 0. prepare skel directory '/tmp/s/g/x' (git clone etc.)

# 1. install package
sudo pkg install -y cbsd

# 2. initialize with a random(?) workdir
sudo workdir=/tmp /usr/local/cbsd/sudoexec/initenv /usr/local/cbsd/share/initenv.conf

# 3. create a jconf
# (copied from Oleg's example in gh#34,
# can we have this i386 conf in samples, so we can just copy it and override
# its values during jcreate?)
cat > /tmp/jail-11i386.jconf << EOF
jname="jail-11i386";
path="/usr/jails/jails/jail-11i386";
host_hostname="jail-11i386.my.domain";
ip4_addr="10.0.0.4/16";
mount_devfs="1";
allow_mount="1";
allow_devfs="1";
allow_nullfs="1";
mount_fstab="/usr/jails/jails-fstab/fstab.jail-11i386";
arch="i386";
mkhostsfile="1";
devfs_ruleset="4";
ver="11.2";
basename="";
baserw="0";
mount_src="0";
mount_obj="0";
mount_kernel="0";
mount_ports="1";
astart="1";
data="/usr/jails/jails-data/jail-11i386-data";
vnet="0";
applytpl="1";
mdsize="0";
rcconf="/usr/jails/jails-rcconf/rc.conf_jail-11i386";
floatresolv="1";

exec_poststart="0";
exec_poststop="";
exec_prestart="0";
exec_prestop="0";

exec_master_poststart="0";
exec_master_poststop="0";
exec_master_prestart="0";
exec_master_prestop="0";
pkg_bootstrap="1";
user_pw_root='rootpw'
interface="auto"
jailskeldir="/tmp/s/g/x"
pkglist="/tmp/pkglist.txt";
exec_start="/bin/sh /etc/rc"
exec_stop="/bin/sh /etc/rc.shutdown"
EOF

# 4. specify required packages
cat > /tmp/pkglist.txt << EOF
c-ares
gmake
icu
libnghttp2
libuv
git
EOF

# 5. create a jail (not the use of `inter=0` for non-interactive scenario)
sudo cbsd jcreate jconf=/tmp/jail-11i386.jconf inter=0 arch=i386

# 6. start the jail
sudo cbsd jstart jail-11i386

# 7. enter jail-i386 for further execution
sudo cbsd jexec jname=jail-11i386 /bin/tcsh

There is an explicit check in system.subr for inter=0 (step 5 above), that it has to use repo option to get the system. By reading the code further in :/tools/repo file, it seems like the repo option causes CBSD to download binaries from the internet.

Feature Request

A way for non-interactive shell to re-use the pre-downloaded files, without downloading from the internet again.

Something like:

sudo cbsd jcreate jconf=/tmp/jail-11i386.jconf inter=0 arch=i386 archivedir=/tmp/archives/fbsd-i386/

and/or better yet, if we already have it extracted as well, could we use it? e.g. in /tmp/fbsd-i386/ directory, user could untar the base.txz and use it multiple times in jcreate:

sudo cbsd jcreate jconf=/tmp/jail-11i386.jconf inter=0 arch=i386 systemdir=/tmp/fbsd-i386/

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 49 (32 by maintainers)

Commits related to this issue

Most upvoted comments

commited to ports tree: 12.0.4

Well, it seems the problem with resolv is solved:

https://cirrus-ci.com/task/5351638421209088

but I don’t know where ‘Signaled to exit!’ comes from. Or just !=0 exit code from last command?

It was my fork from your branch: https://github.com/olevole/node-sass/commits/freebsd-ci

where I added more debug. And looks like key instructions in solving a problem is:

  1. configure nodeippool with
cp /usr/local/cbsd/share/initenv.conf /tmp/initenv.conf
sysrc -qf /tmp/initenv.conf nodeippool=192.168.0.0/24
  1. configure nat and load pf module by hand
cbsd natcfg fw_new=fw natip_new=${auto_iface}
kldload pf || true
cbsd naton

( for some reason it does not load itself. although should )

  1. configure ip forwarding:

sysctl -w net.inet.ip.forwarding=1

  1. inherits resolv.conf from hoster:

cbsd jailscp /etc/resolv.conf jail-11i386:/etc/resolv.conf

yeah, i’ve fix this via

fqdn=$( hostname )
hostname=$( hostname -s )

if [ "${fqdn}" = "${hostname}" ]; then
        echo "set hostname $hostname -> ${hostname}.my.domain"
        sysrc hostname="${hostname}.my.domain"
        hostname ${hostname}.my.domain
fi

😉

i don’t remember why i had to use FQDN for CBSD. Most likely for node name uniqueness (when ‘cbsd node mode=add’ is used)

I think it needs to be fixed and change to UUID.

Sorry for not mentioning it early, I had to apply this patch to workaround hostname check: https://github.com/am11/cbsd/commit/87e17f62ff72ee3d95117b1f05e0e158035fc59d and meant to ask, is this check necessary? But I guess you already have it under control. 😃

@am11 Looks like its pkg-related stuff.

if you change pkg_bootstrap to 0:

pkg_bootstrap=“0”

this should not happen. I think it can be regulated through pkg.conf in jail skel directory

notes for myself: CBSD can use multiple sources to receive bases ( from archive, from network, from current system …)… maybe we can do config file to control the default action in non-interactive mode with archivedir/cachedir optional settings ?