Steffen's Knowledge Base

Created at: 2019-09-23 20:50:00
Last modified at: 2024-07-14 14:04:46
Author: Steffen Rick

Jails

jail.conf
jail1 {
    allow.sysvipc = 1;                         # sysctl
    allow.raw_sockets = 1;                     # sysctl
    allow.chflags = 1;                         # sysctl
    host.hostname = jail1.hzn.srick.org;       # Hostname
    ip4.addr = 188.40.60.96;                   # IP address of the jail
    ip6.addr = "2a01:4f8:221:181::7";          # IP address of the jail
    path ="/zvol/jail1";                       # Path to the jail
    devfs_ruleset = "4";                       # devfs ruleset
    mount.devfs;                               # Mount devfs inside the jail
    exec.start = "/bin/sh /etc/rc";            # Start command
    exec.stop = "/bin/sh /etc/rc.shutdown";    # Stop command
}

jail2 {
    allow.sysvipc = 1;                         # sysctl
    allow.raw_sockets = 1;                     # sysctl
    allow.chflags = 1;                         # sysctl
    host.hostname = jail2.hzn.srick.org;       # Hostname
    ip4.addr = 10.0.0.1;                       # IP address of the jail
    path ="/mypool/raw/jails/jail2";           # Path to the jail
    devfs_ruleset = "4";                       # devfs ruleset
    mount.devfs;                               # Mount devfs inside the jail
    exec.start = "/bin/sh /etc/rc";            # Start command
    exec.stop = "/bin/sh /etc/rc.shutdown";    # Stop command
}

jail3 {
    allow.sysvipc = 1;                         # sysctl
    allow.raw_sockets = 1;                     # sysctl
    allow.chflags = 1;                         # sysctl
    host.hostname = jail3.hzn.srick.org;       # Hostname
    ip6.addr = "2a01:4f8:221:181::3";          # IP address of the jail
    path ="/mypool/raw/jails/jail3";           # Path to the jail
    devfs_ruleset = "4";                       # devfs ruleset
    mount.devfs;                               # Mount devfs inside the jail
    exec.start = "/bin/sh /etc/rc";            # Start command
    exec.stop = "/bin/sh /etc/rc.shutdown";    # Stop command
}
    
jail start and stop
jail -c jail1
jail -r jail1
    
list ip addresses of jails and jail id
jls -v
    
rc.conf alias entries
# jail1
ifconfig_re0_alias0="inet 188.40.60.96 netmask 255.255.255.192"

# jail2
cloned_interfaces="lo1"
ifconfig_lo1_alias0="inet 10.0.0.1 netmask 255.255.255.248"

# jail3
ifconfig_re0_alias1="inet6 2a01:4f8:221:181::3 prefixlen 64"
    
ZFS volume creation
zfs create -V 12G -o compression=off mypool/jail1 
newfs /dev/zvol/mypool/jail1 
mkdir /zvol/jail1 
mount /dev/zvol/mypool/jail1 /zvol/jail1 
make installworld DESTDIR=/zvol/jail1 
make distribution DESTDIR=/zvol/jail1 
mount -t devfs devfs /zvol/jail1/dev
    
ZFS volume backup and import
# taking the backup
zfs snapshot mypool/jail1@jail1_zvol_20190923
zfs send -v mypool/jail1@jail1_zvol_20190923 > /mypool/raw/backups/jail1_zvol_20190923

# creating a new volume with the backup contents
# jail name must have a new name
zfs recv mypool/jail8 < /mypool/raw/backups/jail1_zvol_20190923
    
Provide host's ports tree via null mount to save space
tar -cf - -C /usr/ports . | tar -xpf - -C /mnt/datadump/

mount -t nullfs /mnt/datadump /zvol/jail3/mnt/ports