/dev/null damaged after cp to it

Well, I've found out that cp some_file /dev/null destroys /dev/null as a special node, but makes it a usual file which is overfulled easily on my OpenWRT device. How's that possible? And how to fix it?

I don't know if the same methods work on OpenWrt for fixing a broken /dev/null as are typical for the big distros... but try this:

mknod /dev/null c 1 3
chmod 666 /dev/null

^^^ This is sourced from the page below, I haven't tried it myself.

1 Like

Well, this somehow "works", but next cp destroys it again:

root@OpenWrt:/mnt/sda1/vsftp# ls -l /dev/null
crw-rw-rw-    1 root     root        1,   3 Sep 10 11:59 /dev/null
root@OpenWrt:/mnt/sda1/vsftp# cp -v Frgive_2_theo.mkv /dev/null
cp: write error: No space left on device
root@OpenWrt:/mnt/sda1/vsftp# ls -l /dev/null
-rw-r--r--    1 root     root        524288 Sep 10 14:37 /dev/null
root@OpenWrt:/mnt/sda1/vsftp# rm /dev/null ; mknod /dev/null c 1 3 ; chmod a+w /dev/null
root@OpenWrt:/mnt/sda1/vsftp# ls -l /dev/null
crw-rw-rw-    1 root     root        1,   3 Sep 10 14:37 /dev/null

By the way, dd of=/dev/null does not destroy this special node.

What are you trying to achieve here?

Redirecting things to /dev/null swallows them and makes them disappear; copying /dev/null to an existing file truncates the file to zero bytes.

Copying a file to /dev/null overwrites the target with the file contents, which is as you've found undesirable.


On other Linux and Unix-like systems copying file to /dev/null just measures time of reading the file, haven't seen that it substitutes special none with that file!
For example it is a well-known way to make 2-pass encoding, when the first pass goes to /dev/null And this is done usually without destroying anything or overfull problems. How to overcome such undesirable and unusual behaviour of OpenWRT?

I would guess that the reason is something strange in the busybox implementation of 'cp'.

root@router5:~# which cp
root@router5:~# ls -l /bin/cp
lrwxrwxrwx    1 root     root             7 Sep  8 19:46 /bin/cp -> busybox



Oh, I see. Thank you. Hope, other programs, like ffmpeg manage special nodes POSIX-like, and not like this bug.