Solved How can I identify the OS installed in each jail?

I'd like to be able to configure my jails with some local variables that don't need to be passed to the kernel during jail(8) creation. I can set one, and jail -e \; will display it:

Code:
 ...;X.my_variable=my_value;...

but it causes an error when starting the jail:

Code:
jail: my_jail: unknown parameter: X.my_variable

I was hoping there might be some reserved namespace for user-defined config variables that I could use in lieu of X

While I believe this would be generally useful, especially if perhaps these user-defined variables got inherited by the jail's environment, my specific objective is to be able to identify what OS is installed in each jail. There is a variable security.jail.param.linux.osname, but it doesn't seem to accept an arbitrary string value when defined in jail.conf.

Code:
# sysctl -d security.jail.param.linux.osname security.jail.param.host.hostname security.jail.param.host.domainname
security.jail.param.linux.osname: Jail Linux kernel OS name
security.jail.param.host.hostname: Jail hostname
security.jail.param.host.domainname: Jail NIS domainname

My current jail.conf does not set any of those, yet they have somewhat puzzling default values:

Code:
# for j in 7 8 9 10; do sysctl -j $j security.jail.param.linux.osname security.jail.param.host.hostname \
           security.jail.param.host.domainname; echo --; done
security.jail.param.linux.osname: 65
security.jail.param.host.hostname: 256
security.jail.param.host.domainname: 256
--
security.jail.param.linux.osname: 65
security.jail.param.host.hostname: 256
security.jail.param.host.domainname: 256
--
security.jail.param.linux.osname: 65
security.jail.param.host.hostname: 256
security.jail.param.host.domainname: 256
--
security.jail.param.linux.osname: 65
security.jail.param.host.hostname: 256
security.jail.param.host.domainname: 256

The actual OSes in those jails are:

Code:
# for j in 7 8 9 10; do jexec $j uname -a; done
FreeBSD webwork2.example.edu 14.3-BETA2 FreeBSD 14.3-BETA2 releng/14.3-n271377-0e8065166204 GENERIC amd64
FreeBSD listserv.example.edu 14.3-BETA2 FreeBSD 14.3-BETA2 releng/14.3-n271377-0e8065166204 GENERIC amd64
FreeBSD aarch64.example.edu 14.3-BETA2 FreeBSD 14.3-BETA2 releng/14.3-n271377-0e8065166204 GENERIC amd64
Linux ubuntu 5.15.0 FreeBSD 14.3-BETA2 releng/14.3-n271377-0e8065166204 GENERIC x86_64 x86_64 x86_64 GNU/Linux
# jexec 10 lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 24.04.2 LTS
Release:        24.04
Codename:       noble

But when I set the config to be:

Code:
name=ubuntu-23;path=/jail/ubuntu-23.10;interface=private;mount.devfs;exec.clean;exec.jail_user=root;exec.start="/etc/init.d/rc 3";
exec.stop="/etc/init.d/rc 0";exec.consolelog=/var/log/jail_ubuntu-23.log;exec.system_user=root;allow.raw_sockets;allow.mount=1;
allow.set_hostname=0;allow.sysvipc=0;security.jail.param.linux.osname="Ubuntu 24.04.2 LTS";host.hostname=ubuntu;persist;
sysvmsg=inherit;sysvsem=inherit;sysvshm=inherit;enforce_statfs=1;devfs_ruleset=7;ip4.addr=192.168.1.8;mount.fstab=/etc/fstab.ubuntu23

the jail again refuses to start and complains unknown parameter: security.jail.param.linux.osname

What can I do to query the OS inside a jail other than jexec trickery? A jexec-based query of course requires the jail to be running, whereas I'd prefer to be able to query even stopped jails, based on their jail.conf settings.
 
Figured it out .... I should have been paying more attention to jail(8) instead of sysctl(8).

Early on in /etc/jail.conf, up high in the global defaults:

Code:
# Jail defaults:
... the usual defaults ...
linux.osname        = 'FreeBSD';    # default OS name

In /etc/jail.conf.d/ubuntu-23.conf:

Code:
linux.osname    = "Ubuntu 24.04.2 LTS";

Then I can display the raw config file data:

Code:
# jail -e \; | egrep -o '(^|;)(path|linux\.osname)=[^;]+' | sed -e 's/^;//'
linux.osname=FreeBSD
path=/jail/aarch64
linux.osname=FreeBSD
path=/jail/mailman
linux.osname=FreeBSD
path=/jail/mailman2
linux.osname="Ubuntu 24.04.2 LTS"
path=/jail/ubuntu-23.10
linux.osname=FreeBSD
path=/jail/webwork2

Or I can use jls to query the OS type of just the currently running jails:

Code:
# service jail restart
....
# jls -s jid host.hostname path linux.osname
jid=20 host.hostname=webwork2.example.edu path=/jail/webwork2 linux.osname=FreeBSD
jid=21 host.hostname=listhost.example.edu path=/jail/mailman2 linux.osname=FreeBSD
jid=22 host.hostname=aarch64.example.edu path=/jail/aarch64 linux.osname=FreeBSD
jid=23 host.hostname=ubuntu path=/jail/ubuntu-23.10 linux.osname="Ubuntu 24.04.2 LTS"
 
Back
Top