On 1/25/26 01:44, [email protected] wrote:
On Sat, Jan 24, 2026 at 07:01:00PM -0700, Tom Dial wrote:

On 1/24/26 07:33, Greg Wooledge wrote:
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.
I remember, a number of years ago, getting caught by exactly this, I believe on 
an earlier version of Debian.

Considering that things might have changed since then, I tried it, with the 
following results:

root@dyson:~# mkdir /mnt/test
root@dyson:~# cp /dev/sda1 /mnt/test
root@dyson:~# du /mnt/test
173870  /mnt/test
root@dyson:~# ll /mnt/test
total 173861
-rw-r----- 1 root root 535822336 Jan 24 18:22 sda1
root@dyson:~# ll /mnt/test/sda1
-rw-r----- 1 root root 535822336 Jan 24 18:22 /mnt/test/sda1
[...]

This behaviour doesn't apply when -r option is given. Then, special
files are copied as such *unless* you give option --copy-contents.

It's all in the docs, but...
My error, and thank you for the correction. It certainly is in the info docs, 
but is not mentioned in the man page for cp.
I really should reform what now is a bad habit and use "info" rather than 
"man," especially since it will fall back to manpages when necessary.

But I'll still use mount -bind to set up a chroot environment for the cited 
reason.

Tom Dial

   tomas@caliban:~$ mkdir /tmp/foo
   tomas@caliban:~$ sudo cp -r /dev/sda1 /tmp/foo
   [sudo] password for tomas:
   tomas@caliban:~$ ls -al /tmp/foo
   total 20
   drwxr-xr-x 2 tomas tomas  4096 Jan 25 09:39 .
   drwxrwxrwt 9 root  root  16384 Jan 25 09:39 ..
   brw-r----- 1 root  root   8, 1 Jan 25 09:39 sda1

The problem with -r is that it misses other (important) file attributes,
as has been said elsewhere in this thread. Still, bind mount is the
better option. Back then, long, long time ago, cp was the only available,
so those recipes still float around in the intrawebs, like ghost ships.

Harr!

Cheers

Reply via email to