5

A wrongly written script deleted /dev/null on my system. I did find an answer here and tried it out. But as soon as I write something to the new /dev/null, the system crashes. I'm afraid that answer's not for BSD.

Can anyone help?

It's FreeBSD 10.3

  • 2
    What did you try? Using mknod or MAKEDEV? – cuonglm Mar 31 '17 at 4:51
5

On FreeBSD:

mknod /dev/null c 15 0 root:wheel
chmod 0666 /dev/null

As you found out, numbers 15 and 0 are not portable to other systems.

  • Is this portable to all BSD-based systems? – iBug Mar 31 '17 at 22:55
  • 2
    @iBug Nope. OpenBSD f.i. needs 2 and 2. – Satō Katsura Apr 1 '17 at 4:53
6

The command for creating device node entries is mknod on pretty much all unix systems. The device numbers are completely depend on the unix variant, so you need to look them up in the documentation. On some systems, man 4 null (the null man page in section 4 “special files”) will tell you what the device numbers are. (Devices are in section 4 on BSD and Linux, but the section number can vary on other Unix variants, for example it's section 7 on Solaris.)

If the man pages don't tell you, look for a MAKEDEV command, usually located in /dev. This is usually a shell script where you can easily find out the device number, or run it as cd /dev && ./MAKEDEV null.

Some modern unix systems don't use MAKEDEV because device nodes are created automatically. This is the case on Linux systems (except some embedded systems) with udev, and also on FreeBSD with devfs. How to re-create an entry that's normally created automatically depends on the automatic device creation system. On FreeBSD, you can simply give the device name to the mknod command: mknod /dev/null.

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.