1

I would like to mount /dev/shm in a freebsd jail. Every time I attempt to, I get these errors:

[root@gaming /]# mount -t tmpfs tmpfs /dev/shm
mount: /dev/shm: No such file or directory
[root@gaming /]# touch /dev/shm
touch: /dev/shm: Operation not supported
[root@gaming /]#

Jail works perfectly, I just can't figure out how to get devfs to automagically create a directory.

Thanks.

brendan
  • 13
  • 4

2 Answers2

2

If you want to use tmpfs inside jail it is better to add line like

tmpfs /jails/foo.example.org/tmp tmpfs rw,size=524288000 0 0

to the jail's fstab file.

citrin
  • 469
  • 2
  • 5
1

It is possible to provide the Linux applications in the jail with the needed /dev/shm.
Install /usr/ports/emulators/linux_base-c7.
Add in /etc/fstab:

tmpfs  /compat/linux/dev/shm    tmpfs    rw,mode=1777    0 0
tmpfs  /tmp                     tmpfs    rw,mode=1777    0 0

Add in /etc/devfs.conf:

link /tmp shm

In /etc/jail.conf for jail my_jail add:

devfs_ruleset = 4;
mount.devfs;
mount.fstab = /etc/fstab.my_jail;
allow.mount;
allow.mount.devfs;

Add in /etc/fstab.my_jail:

tmpfs  /opt/jails/my_jail/tmp                     tmpfs   rw,late,mode=1777 0 0
tmpfs  /opt/jails/my_jail/compat/linux/dev/shm    tmpfs   rw,mode=1777      0 0
devfs  /opt/jails/my_jail/dev                     devfs   rw,late           0 0

Create the not yet existing mount points for the tmpfs devices with mode=1777.
You can provide further devices in jails /compat/linux/dev by using symbolic links, e.g. for providing a working /dev/null device use

sudo ln -s /dev/null /opt/jails/my_jail/compat/linux/dev/null

I tested the usability of /dev/shm in the jail by running a Linux python with this script:

#!/usr/bin/env python
import multiprocessing

lock = multiprocessing.Lock()
print("lock: %s" % lock)
q = multiprocessing.Queue()
print ("q: %s" % q)

If /dev/shm is available in jail then it returns something like

lock: <Lock(owner=None)>
q: <multiprocessing.queues.Queue object at 0x80088ef90>

If /dev/shm is not availabe, then it returns

Traceback (most recent call last):
  File "sem-test.py", line 4, in <module>
    lock = multiprocessing.Lock()
  File "/usr/lib/python2.7/multiprocessing/__init__.py", line 176, in Lock
    return Lock()
  File "/usr/lib/python2.7/multiprocessing/synchronize.py", line 147, in __init__
    SemLock.__init__(self, SEMAPHORE, 1, 1)
  File "/usr/lib/python2.7/multiprocessing/synchronize.py", line 75, in __init__
    sl = self._semlock = _multiprocessing.SemLock(kind, value, maxvalue)
OSError: [Errno 38] Function not implemented
lgnom
  • 13
  • 3