On Sat, Jan 24, 2026 at 16:09:12 +0500, Alexander V. Makartsev wrote:
> "cp -r /dev/ /tmp/RFS/dev/"  is wrong! Don't do that.
> Think about it, "cp" command will copy block devices such as /dev/sda like
> files into /tmp/RFS, basically into itself until it runs out of free space.

A reasonable guess, but it's not correct.

hobbit:~$ mkdir d1
hobbit:~$ mkfifo d1/pipe
hobbit:~$ cp -r d1 d2
hobbit:~$ ls -l d1 d2
d1:
total 0
prw-rw-r-- 1 greg greg 0 Jan 24 09:25 pipe|

d2:
total 0
prw-rw-r-- 1 greg greg 0 Jan 24 09:25 pipe|

=============================

hobbit:~$ ls -l /dev/null
crw-rw-rw- 1 root root 1, 3 Jan 14 18:21 /dev/null
hobbit:~$ sudo mknod d1/null c 1 3
[sudo] password for greg: 
hobbit:~$ sudo rm -rf d2
hobbit:~$ sudo cp -r d1 d2
hobbit:~$ ls -l d1 d2
d1:
total 0
crw-r--r-- 1 root root 1, 3 Jan 24 09:27 null
prw-rw-r-- 1 greg greg    0 Jan 24 09:25 pipe|

d2:
total 0
crw-r--r-- 1 root root 1, 3 Jan 24 09:27 null
prw-r--r-- 1 root root    0 Jan 24 09:27 pipe|

=============================

Of course, the bind mount solution is better than the cp solution in
this case.  But the cp solution isn't as wrong as you believed.  One
would probably want to use -a instead of -r, though, to copy the
permissions and ownerships.

Reply via email to