4 ms·
You can create sockets and fifos anywhere. Device nodes are the only special ones which are generally confined to specific locations.
by cperciva 5y ago
You can create sockets and fifos anywhere. Device nodes are the only special ones which are generally confined to specific locations.
- deleted 5y ago[deleted]
- umanwizard 5y agoI think on BSDs at least you can theoretically put device nodes wherever you want (but there’s no good reason not to put them in /dev where everything expects them to be).
- skissane 5y agoI'm pretty sure on Linux too there is nothing stopping you from putting a device node in any directory either. By convention they live in /dev (or its subdirectories), but there is nothing technically enforcing that convention. (udev assumes they live under /dev. I'm not sure if /dev is hardcoded in udev or configurable. But you don't have to use udev anyway, you can create device nodes manually.)
- yjftsjthsd-h 5y agoYeah, it's just a mknod away provided your filesystem isn't mounted nodev
- tremon 5y agoRunning a service inside a chroot might require some combination of /dev/{null,random,console,log} to be present inside the chroot, and bind-mounting /dev exposes the entire underlying system (raw disk nodes) inside the chroot. So there's actually a good reason for being able to create device nodes outside /dev.
- cperciva 5y agoOn FreeBSD you can mount devfs but tell it to only expose a subset of the device nodes, for exactly this reason.
- kragen 5y agoYeah, I used to do this to NFS-export a root filesystem for my diskless Sun-3. The NFS server was running Linux and the Sun was running IIRC NetBSD, so some of the device numbers in the Sun's /dev needed to be different. Pretty rickety setup but it worked okay. I don't recall ever accidentally overwriting my root filesystem or hanging up the modem line by accessing the bogus device nodes.
- rwmj 5y agoWe actually use this too (https://libguestfs.org/nbdkit-file-plugin.1.html#PARAMETERS https://libguestfs.org/nbdkit-file-plugin.1.html#PARAMETERS with "dir" parameter). It allows you to create a directory of devices to export. Symlinks are supported and generally better though.
- cperciva 5y agoFrom FreeBSD 6.0 onwards, device nodes can only exist in devfs. (Ok, technically you can create them elsewhere, but you can't use them to access devices.)
- umanwizard 5y agoI see. I’m more familiar with OpenBSD which I don’t think has such a restriction. (Though I could be wrong).
- ben_bai 5y agoThat's why most partitions have the nodev mount option. An (one of the rreasons) why there is pushback on a single big partition for everything.