From owner-freebsd-questions@freebsd.org Tue Mar 8 01:10:47 2016 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id F1FFBAC7869 for ; Tue, 8 Mar 2016 01:10:47 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mx02.qsc.de (mx02.qsc.de [213.148.130.14]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id BC24F849 for ; Tue, 8 Mar 2016 01:10:47 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from r56.edvax.de (port-92-195-185-40.dynamic.qsc.de [92.195.185.40]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx02.qsc.de (Postfix) with ESMTPS id 257E027666; Tue, 8 Mar 2016 02:10:38 +0100 (CET) Received: from r56.edvax.de (localhost [127.0.0.1]) by r56.edvax.de (8.14.5/8.14.5) with SMTP id u281Abj6003154; Tue, 8 Mar 2016 02:10:37 +0100 (CET) (envelope-from freebsd@edvax.de) Date: Tue, 8 Mar 2016 02:10:37 +0100 From: Polytropon To: Rick Miller Cc: FreeBSD Questions Subject: Re: When is /dev/random created? Message-Id: <20160308021037.84bd0d21.freebsd@edvax.de> In-Reply-To: References: Reply-To: Polytropon Organization: EDVAX X-Mailer: Sylpheed 3.1.1 (GTK+ 2.24.5; i386-portbld-freebsd8.2) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Mar 2016 01:10:48 -0000 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, ...