I recently caused a bit of havoc on one of my machines by causing the /dev/null file’s permissions to be reset to -rw-r–r–. How I was able to do this is beyond the scope of this little howto, but how will you repair/recreate this file if it breaks? And what about /dev/zero ?
To recreate /dev/null do the following (I placed the commands on one line, seperate by a semicolon ‘;’ to ensure they get run quickly and have as little effect on the running system as possible:
[root@techedemic]# rm /dev/null ; mknod -m 0666 /dev/null c 1 3 ; rm: remove regular empty file `/dev/null'? yes |
Then just check that everything is fine
[root@techedemic]# ls -al /dev/null crw-rw-rw- 1 root root 1, 3 May 30 12:01 /dev/null |
To recreate /dev/zero do the following – notice only the ‘3’ changes to a ‘5’:
[root@techedemic]# rm /dev/zero ; mknod -m 0666 /dev/zero c 1 3 ; rm: remove regular empty file `/dev/zero'? yes |
Then just check that everything is fine
[root@techedemic]# ls -al /dev/zero crw-rw-rw- 1 root root 1, 5 May 30 12:08 /dev/zero |
I was still sceptical about /dev/zero after the above, because I regulary use it for various things. As such, I did the following test using dd:
# The following command should write three 'zero' or '0x00' characters to /var/tmp/tmpfile (not '0', that's something different) [root@techedemic]# dd if=/dev/zero of=/var/tmp/tmpfile bs=1 count=3 3+0 records in 3+0 records out 3 bytes (3 B) copied, 3.8553e-05 s, 77.8 kB/s [root@techedemic]# vim /var/tmp/tmpfile # You should see the following inside the file: ^@^@^@ |
thank you for your post, i accidently destroyed /dev/null and could recreate it with your help.
Thanks for the notes! Your command to recreate /dev/zero is wrong though. You have here:
rm /dev/zero ; mknod -m 0666 /dev/zero c 1 3 ;
when it should be
rm /dev/zero ; mknod -m 0666 /dev/zero c 1 5 ;
It was kind of confusing because I copied and pasted. Can you please fix it so other “copiers” like me don’t get burned? Thank! 😀