Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 8 Mar 2016 02:10:37 +0100
From:      Polytropon <freebsd@edvax.de>
To:        Rick Miller <vmiller@hostileadmin.com>
Cc:        FreeBSD Questions <freebsd-questions@freebsd.org>
Subject:   Re: When is /dev/random created?
Message-ID:  <20160308021037.84bd0d21.freebsd@edvax.de>
In-Reply-To: <CAHzLAVFJ%2BYAUjEDCvPzhuSYNM9FyhoZ5=M_kLOXwDrEU6bHS0Q@mail.gmail.com>
References:  <CAHzLAVFJ%2BYAUjEDCvPzhuSYNM9FyhoZ5=M_kLOXwDrEU6bHS0Q@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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).


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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20160308021037.84bd0d21.freebsd>