# How to mount devfs in a jails/chroot



## jyavenard (Dec 3, 2013)

Hi

I'm trying to mount /dev in a chroot environment.

I am doing:

```
chroot /mnt/pool/jails/ports
mount -t devfs devfs /dev
```

The problem is that /dev now contains devices that are linked to the absolute path, and as such, not accessible via chroot like:

```
lrwxr-xr-x   1 root  wheel            9 Dec  3 11:44 ugen0.1 -> /mnt/pool/jails/ports/dev/usb/0.1.0
lrwxr-xr-x   1 root  wheel            9 Dec  3 11:44 ugen0.2 -> /mnt/pool/jails/ports/dev/usb/0.2.0
lrwxr-xr-x   1 root  wheel            9 Dec  3 11:44 ugen0.3 -> /mnt/pool/jails/ports/dev/usb/0.3.0
```

How can I mount /dev so the links appears to be all within /dev? Obviously, I can create a symbolic link in /mnt/pool/jails/ports/dev to /dev ; but that's not elegant, and I'm sure there are better ways...

Thank you in advance.


----------



## SirDice (Dec 3, 2013)

Mount devfs(5) before chrooting.


----------



## fonz (Dec 4, 2013)

Note to add: although the OP only mentions chroot, the subject of the thread also mentions jails. In case of a jail, just set it in (the host's) /etc/rc.conf and let jail(8) figure it out. For example:

```
jail_devfs_enable="YES"
jail_devfs_ruleset="devfsrules_jail"
```
Note that the directives above apply to all jails. You can also make them specifically apply to (a) certain jail(s):

```
jail_foo_devfs_enable="YES"
jail_foo_devfs_ruleset="devfsrules_jail"
```


----------



## scottro (Dec 4, 2013)

Note that before adding a line about a ruleset, you have to add one to /etc/devfs.rules.   Mounting devfs inside a jail can create vulnerabilities, so after mounting (from the host), assuming you've added the default jail ruleset from /etc/defaults/devfs.rules to /etc/devfs.rules you can immediately put the ruleset into play with 
`devfs -m /jails/myjail/dev rule -s 4 applyset`

(Assuming you left the default ruleset number as 4).


----------

