Jail Lifecycle Management
The jstart, jstop, and jremove (synonym jdestroy) commands manage the FreeBSD jail lifecycle. All three commands support powerful target selection mechanisms: single names, lists, masks, and SQL queries.
Built-in help and examples are available for each command:
cbsd jstart --help
cbsd jstop --help
cbsd jremove --help
Basic Syntax
cbsd jstart jname=<jailname>
cbsd jstop jname=<jailname>
cbsd jremove jname=<jailname>
jremove and jdestroy are functionally identical.
Command Behavior
- jstart — starts a stopped jail. If the jail is already running, the command will display an appropriate message.
- jstop — stops a jail via
exec_stop(defaults to/bin/sh /etc/rc.shutdown). If the jail is not running, the command does nothing. - jremove — completely removes a jail. If the jail is running, it will be automatically stopped before removal. The command deletes the jail's filesystem (ZFS dataset or directory), fstab entries, and associated snapshots.
Bulk Operations
CBSD supports performing operations on a group of jails simultaneously.
Wildcards
The jname parameter accepts patterns with the * character:
# Start all jails whose name starts with 'sd'
cbsd jstart jname='sd*'
# Stop ALL jails on the host
cbsd jstop jname='*'
# Remove all jails starting with 'test'
cbsd jremove jname='test*'
Multiple explicit names
Instead of jname=, you can list jails directly:
cbsd jstop web1 web2 web3
cbsd jstart db1 db2 db3 cache1
Combining approaches
You can use both mechanisms together:
cbsd jstart jname='prod-*' staging1 staging2
Parallel execution
Operations on multiple jails can be performed in parallel. Behavior is configured via the parallel parameter in cbsd initenv-tui.
SQL WHERE — filtering by conditions
The most powerful feature is filtering jails using an SQL-like condition after the WHERE keyword. This allows precise control over which jails are affected by the operation.
Syntax
cbsd <command> WHERE <sql-condition>
<sql-condition> — a standard SQL expression supporting:
- Comparisons:
=,!=,<,> - Logical operators:
AND,OR - Pattern matching:
LIKE - Grouping with parentheses
Examples
Stop all running jails with autostart enabled
cbsd jstop WHERE status='1' AND astart='1'
This will stop only those jails that are currently running (status='1') and have autostart enabled (astart='1').
Start jails with autostart, VNET, and a specific IP range
cbsd jstart WHERE astart=1 AND vnet=1 AND ip4_addr LIKE '1%'
Starts jails where:
- Autostart is enabled (astart=1)
- Isolated network space is configured (vnet=1)
- IPv4 address starts with 1 (e.g., 10.0.0.x, 192.168.x.x)
Stop all non-VNET jails
cbsd jstop WHERE vnet=0
Remove all hidden jails
cbsd jremove WHERE hidden=1
Complex condition with OR
cbsd jstart WHERE (astart=1 AND status=0) OR jname='emergency'
Starts all stopped jails with autostart enabled, plus the specific emergency jail regardless of its settings.
Available fields for WHERE
The WHERE condition can reference any columns from the jail table in the CBSD database. Main fields:
| Field | Type | Description |
|---|---|---|
jname |
TEXT | Jail name |
status |
INT | Current status: 0 = stopped, 1 = running |
astart |
INT | Autostart: 0 = off, 1 = on |
vnet |
INT | VNET isolation: 0 = off, 1 = on |
ip4_addr |
TEXT | IPv4 address |
hidden |
INT | Hidden flag: 0 = visible, 1 = hidden |
host_hostname |
TEXT | Jail FQDN hostname |
ver |
TEXT FreeBSD release version | |
| arch TEXT Architecture | ||
| path TEXT Path to jail root directory | ||
| interface TEXT Network interface | ||
| tags TEXT Custom tags | ||
| basename TEXT Base release name for clones |
Practical scenarios
Emergency shutdown
Stop everything with a single command:
cbsd jstop jname='*'
Or using WHERE:
cbsd jstop WHERE status=1
Production environment restart
cbsd jstop jname='prod-*' cbsd jstart jname='prod-*' ``` ### Cleanup test environments Remove all test jails : ``` bash cbsd jremove jname ='test*' cbsd jremove jname ='tmp*' ```
Or remove all jails with a specific tag:
```bash
cbsd jremove WHERE tags LIKE '%ephemeral%'
Starting only VNET jails after a network update
cbsd jstart WHERE vnet=1 AND astart=1
Removing jails of an older FreeBSD version
cbsd jremove WHERE ver='13.0'