2

Must /dev/random and /dev/urandom be created each boot, or are they static files that can be put in a tar?

I am trying to understand if I need to recreate these each time the operating system starts, or if once created they do not need to be created again.

And related question, once created, can these two devices be put into a tar and restored?

3

/dev/random and /dev/urandom are device files; whether device files are created at system startup or persist across reboot may depend on your specific operating system. On most (may even all) Linux distributions /dev is a temporary (RAM-based) filesystem, and device files are generated at system startup and whenever a device is plugged in. You should not need to create them; the system should do it automatically.

I don't see any reason to do put them in a tar archive, but you can if you want to.

  • So if I was, for example, creating my own distro from scratch, then in the startup boot scripts would I recreate /dev/random and /dev/urandom, or would I be satisfied that they had been created when the system was first installed? – Duke Dougal Dec 1 '16 at 2:40
  • 2
    If you are creating your of distro from scratch then you must decide whether you will use udev / eudev to manage device files or not. As far as I know all distributions use one of those to manage device files dynamically. The reason behind managing device files dynamically is removable devices. Traditionally UNIX systems had a persistent /dev, and device files were created as needed by mknod; but that was a long time ago. – AlexP Dec 1 '16 at 2:46
  • Really, from scratch is more complicated than the answer. /dev usually exists but it is hidden very soon in the boot process. Additionally, there is a temporary filesystem (initramd) that probably need that device. Note: tar will not really work, you should mount the root filesystem (or remount read_write). – Giacomo Catenazzi Dec 1 '16 at 13:52
3

/dev/random and /dev/urandom are not ordinary files ... they are character special devices. In Linux, block special devices and character special devices are filesystem interfaces to an operating system device driver. If you run the command ls -l /dev you will see listings that have either a "b" [for block] or a "c" [for character] in the first column. By convention, these are placed in the /dev directory tree, but a special device can be created anywhere on the filesystem.

Block and character special devices are not created by copying or moving ... they are created using the mknod command.

Normally, /dev/random and /dev/urandom are created when the operating system is booted. The devices are created dynamically when the random number generator is running. If you reboot your Linux system and they are not being created automatically, then you need to check to see whether something was changed in the kernel configuration to disable it.

If the files are disappearing or get deleted by accident, they can be recreated as follows (as root):

/bin/mknod -m 0666 /dev/random c 1 8
/bin/mknod -m 0666 /dev/urandom c 1 9
/bin/chown root:root /dev/random /dev/urandom

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.