# Jail mounted base nullfs sometimes not un-mounted after jail stop



## Roy Chan (Feb 2, 2019)

Hello all,

I follow the handbook (https://www.freebsd.org/doc/handbook/jails-application.html) and set up a nginx jail. I use a standard `base` partition mounted as read-only nullfs, and a `skel` partition mounted as read-write nullfs. My fstab is shown as follows:

```
/data/jail/template/base /data/jail/jails/nginx nullfs ro 0 0
/data/jail/skels/nginx /data/jail/jails/nginx/skel nullfs rw 0 0
```

I specified this fstab file in my jail.conf:

```
exec.start = "/bin/sh /etc/rc";
exec.stop = "/bin/sh /etc/rc.shutdown && sleep 1";
exec.clean;
mount.devfs;

nginx {
    host.hostname = nginx;
    ip4.addr = 192.168.10.1;
    path = "/data/jail/jails/nginx";
    mount.fstab = "/data/jail/fstabs/nginx.fstab";
}
```

Within the jail, I use port to installed www/nginx with the default option. Everything works fine, but when I trigger `service jail stop nginx`, sometimes the base partition could not be un-mounted.

I used `jail -v` to check the output. Sometimes the jail could be stopped with everything clean, but sometimes the output was like:

```
nginx: run command: /sbin/umount /data/jail/jails/nginx/dev
nginx: run command: /sbin/umount -t nullfs /data/jail/jails/nginx/skel
nginx: run command: /sbin/umount -t nullfs /data/jail/jails/nginx
umount: unmount of /data/jail/jails/nginx failed: Device busy
jail: nginx: /sbin/umount -t nullfs /data/jail/jails/nginx: failed
```

After this, `jls` doesn't show this jail. However, the base partition is still mounted. I have no idea why. I've checked the opened files but no files were open. However, when I un-mount the file system from the host system, it was processed smoothly without any difficulties.

This problem sometimes happens but I haven't caught its pattern. I'm not sure if this is an Nginx issue or a jail issue, or just a fault in my configuration. I've checked multiple similar discussions but did not find a solution:









						Solved - [Solved] Jail shutdown does not unmount
					

When I stop/shutdown jails, the mounts specified in /etc/fstab.jailname do not get unmounted. The explanation by Jamie (maintainer of jails) for the problem is: If you want to keep track of such things for proper handling in later removal, you should put those options in /etc/jail.conf (or some...




					forums.freebsd.org
				











						Cannot cleanly stop jails after using graphical applications
					

Starting and stopping the jail works fine when I stick to console apps. I can also successfully launch and use graphical jailed apps on the host display using e.g., jailme 1 firefox, but I cannot cleanly stop the jail after closing jailed graphical apps from my host X display.  Here is my...




					forums.freebsd.org
				











						Jail root nullfs won't unmount Device Busy
					

I recently upgraded my server from FreeBSD 9.0 to FreeBSD 10.0. After the upgrade I converted all of my old jails from using /etc/rc.conf to using /etc/jail.conf. However when I attempt to stop some jails they refuse to unmount their root filesystem which is a read-only nullfs mount that points...




					forums.freebsd.org
				





			Jail fails to unmount a directory
		


It would be great if you could leave some possible solutions or general ideas about this annoying problem. Many thanks!


----------

