When is /dev/random created?

Polytropon freebsd at edvax.de
Tue Mar 8 01:10:48 UTC 2016

On Mon, 7 Mar 2016 19:04:57 -0500, Rick Miller wrote:
> Hi all,
> I was intrigued when I noticed an mfsBSD disk image did not have
> /dev/random and decided to check the distribution from which the image was
> installed.  dev/ existed only in base.txz and as an empty directory.

That's correct. /dev is a mountpoint for a virtual file system
for the device files. Example output from the "mount -v" command:

	devfs on /dev (devfs, local, multilabel)

So when devfs is started, /dev gets populated.

> Does this mean /dev/random is created on boot?

Yes. The whole /dev content is under management of devfs (and devd).

> /etc/rc.d/random exists as
> a typical start script, but doesn't appear to test the existent, much less
> create, /dev/random.

It contains the following sequence in the feed_dev_random() function:

	cat "${1}" | dd of=/dev/random bs=8k 2>/dev/null

So this one creates /dev/random if it doesn't already exist.
However, I think the devfs initialization already makes sure
the device file exists. The magic should be located somewhere
in the kernel virtual file system sources...

> Section 5.12, Random Number Generator of the D&I of FreeBSD, while it
> touched on /dev/random, didn't describe when or how it is created.
> So, at what point does /dev/random get created when it doesn't exist?

When /etc/rc.d/random is executed. The function random_start()
tests for write access to /dev/random:

	if [ -w /dev/random ]; then

and then feeds it:

	feed_dev_random "${seedfile}"

where the called function would perform

	cat "${1}" | dd of=/dev/random bs=8k 2>/dev/null

As mentioned, that would create /dev/random, but the test of -w
already implies that it exists (-w = exists and can be written to).

Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...

More information about the freebsd-questions mailing list