ZFS Help mounting a dataset to a jail at boot

Working on getting all my jails off TrueNAS and on to a FreeBSD server. I've got most of them completed but I'm having trouble reproducing the mount points for a couple of the jails.

The source for the mount is
Code:
/tank/Torrents
The destination for the mount is
Code:
/tank/iocage/jails/qbittorrent/root/mnt

I added an entry to /etc/fstab as follows:
Code:
/tank/Torrents /tank/iocage/jails/qbittorrent/root/mnt nullfs rw 0 0

Problem is this results in en error at boot and drops me into single user mode.

What am I missing?
 
I added an entry to /etc/fstab
Don't put this in the host's fstab, jails can have their own fstab with filesystems that will be mounted when the jail starts. By default those are /etc/fstab.<jailname>, but iocage might have some other location for it.

The host's fstab filesystems are mounted very early during boot, the jail(s) haven't started yet, so its mountpoint probably doesn't exist. That will cause a boot failure and the host will be stuck in single user mode.
 
rather than using the jails fstab

which means sometimes the mounts
arent unmounted when you stop the jail

and can lead to resource errors

its better to define the mountpoints in the jails config
that way when you stop the jail all the mounts are unmounted

also i manually start the jail after logging in

i found if i tried to start the jail in my /etc/rc.conf
the jail would be started before the zfs datasets where mounted
or something along those lines


Code:
ubuntu {
  # STARTUP/LOGGING
  exec.start = "/bin/sh /etc/rc";
  exec.stop = "/bin/sh /etc/rc.shutdown";
  exec.consolelog = "/var/log/jail_console_${name}.log";

  # PERMISSIONS
  allow.raw_sockets;
  exec.clean;
  mount.devfs;
  devfs_ruleset = 4;

  # HOSTNAME/PATH
  host.hostname = "${name}";
  path = "/usr/local/jails/containers/${name}";

  # NETWORK
  ip4.addr = 192.168.1.155;
  interface = em0;

  # MOUNT
  mount += "devfs     $path/compat/ubuntu/dev     devfs     rw  0 0";
  mount += "tmpfs     $path/compat/ubuntu/dev/shm tmpfs     rw,size=1g,mode=1777  0 0";
  mount += "fdescfs   $path/compat/ubuntu/dev/fd  fdescfs   rw,linrdlnk 0 0";
  mount += "linprocfs $path/compat/ubuntu/proc    linprocfs rw  0 0";
  mount += "linsysfs  $path/compat/ubuntu/sys     linsysfs  rw  0 0";
  mount += "/tmp      $path/compat/ubuntu/tmp     nullfs    rw  0 0";
  mount += "/home     $path/compat/ubuntu/home    nullfs    rw  0 0";
}


 
I found the jails fstab file and added the mount point to it and when I restart the jail it fails to start with:

Code:
jail: ioc-qbittorrent: mount.fstab: /tank/iocage/jails/qbittorrent/root/mnt: not a mount point


its better to define the mountpoints in the jails config
that way when you stop the jail all the mounts are unmounted

So I'm assuming from your example that I should add this to the jails config?

Code:
mount += "/tank/Torrents     $/tank/iocage/jails/qbittorrent/root/mnt   nullfs    rw  0 0";
 
Ok I got it figured out. When all else fails read the man page.

Turns out iocage has a function built in for adding fstab entries for the jails. After some experimenting to figure out the correct syntax what ended up working was really simple. It's now mounted and functioning correctly.

Code:
iocage fstab -a qbittorrent /tank/Torrents /mnt nullfs rw 0 0
 
Remember: the `/etc/jail.conf` file can now have "include" statements so your main `/etc/jail.conf` can contain items common to all jails (your needs may very slightly):

Code:
# DEFAULT OPTIONS
# (COMMON TO ALL JAILS)

# STARTUP/LOGGING
exec.start = "/bin/sh /etc/rc";
exec.stop  = "/bin/sh /etc/rc.shutdown";
exec.consolelog = "/var/log/jail_console_${name}.log";

# PERMISSIONS
allow.raw_sockets;
exec.clean;

# PATH/HOSTNAME
path = "/usr/local/jails/containers/${name}";
host.hostname = "${name}";

# VNET/VIMAGE
vnet;
vnet.interface = "${epair}b";

# NETWORKS/INTERFACES
$ip             =   "192.168.1.${id}/24";
$epair          =   "epair${id}";
$gateway        =   "192.168.1.1";
$bridge         =   "bridge0";

# ADD TO bridge INTERFACE
exec.prestart   =   "/sbin/ifconfig ${epair} create up";
exec.prestart   +=  "/sbin/ifconfig ${epair}a up descr jail:${name}";
exec.prestart   +=  "/sbin/ifconfig ${bridge} addm ${epair}a up";
exec.start      +=  "/sbin/ifconfig ${epair}b ${ip} up";
exec.start      +=  "/sbin/route add default ${gateway}";
exec.poststop   =   "/sbin/ifconfig ${bridge} deletem ${epair}a";
exec.poststop   +=  "/sbin/ifconfig ${epair}a destroy";

.include "/etc/jail.conf.d/*.conf";

So the jail.conf in `/etc/jail.conf.d/` will look as minimal as:

Code:
classic {
    # NETWORKS/INTERFACES
    $id = "210";
}

or contain overrides to the variables defined in the `/etc/jail.conf` file.
 
I was a TrueNAS user as well and I switched over to stock FreeBSD and have been creating my jails with the base `jail.conf` method--which I found is MUCH, MUCH easier--for months now. If you feel like switching to the `jail.conf` method for managing jails, I have a script that will help you get organized called `jcreate` and help in creating a `jail.conf` file in the `/etc/jail.conf.d/` directory (the manpage will walk you through it all but it's real easy to "setup"). I also created a few simple examples you can look at in the `examples` directory (the examples are a bit more complicated--for demonstration purposes--than is actually needed, but they should stear you in the right direction).

You can find my helper script(s) here:

Victor also has nice collection of setup scripts you can use with my simple setup script (or with any jail manager).

I started creating my simple script to allow me to create "setup scripts" like Victor did, but he is much further along with his scripts than I am with mine.
 
Back
Top