Rsync works, but cp doesn't

Hello all, this is a “why is this happening?” post, not a “I need help to fix it” post. I managed to solve my issue, but I don’t understand why it works.

I have a Raspberry Pi running Manjaro that has an external (usb) hard disk attached. I recently bought a new hard disk with more space to replace it. Now both hard drives are attached and I want to copy from one disk to another.

Both hard drives are ext4 drives mounted with “rw,nosuid,nodev,noexec,relatime”. I ran chown to own the mount folders.

Using cp to copy files gives errors of the form:

cp -raf externalhdd_old/big_folder externalhdd_new/
cp: error writing 'externalhdd_new/big_folder/big_file': Read-only file system
cp: preserving times for 'externalhdd_new/big_folder/big_file': Read-only file system
cp: cannot create directory 'externalhdd_new/big_folder/big_folder2': Input/output error

I know that the filesystem is not readonly:

lrwxrwxrwx  1 pi   pi     17 Nov 20  2020 externalhdd_old
lrwxrwxrwx  1 pi   pi     28 Jul  2 12:52 externalhdd_new

When I use rsync, it just works! rsync does something right that cp doesn’t, but I don’t know why!

Any thoughts, ideas?

Your interpretation of that output is incorrect. Your output is showing two symbolic links. The permissions on symbolic links are…

  • … applicable to the symlink only, not to what the link points at;

  • … never read by the system. They are there for the proper operation of the filesystem, but they are never interpreted by the kernel; and

  • … irrelevant with regard to whether a filesystem is mounted read-only or read/write.

There are no spaces in between the target and the source in your command, which causes the shell to interpret that as if there’s an argument missing.

How the shell behaves in that regard depends upon the shell itself. I do not know which shell the ARM versions of Manjaro use, and the official ISOs for x86-64 are now all using zsh inside their graphical terminal emulators, with bash as the system’s own shell, but I have no real experience with zsh and I use bash for everything.

I hope you are not powering the disks over USB - the PI is not designed to provide power to external harddisks.

You need to chown everytning below the mountpoint - use the -R argument.

1 Like

That is exactly what I’m doing. A single usb hard disk worked fine for years, but maybe 2 is too much.

Also, I noticed that rsync also fails from time to time and I need to restart it. (disk becomes inaccessible and I need to run mount -a)

What method would you recommend for moving from old to new hard disk?

I :heart: rsync !

For most purposes rsync is better.

  • you can checksum after copy
  • you can resume after the copy was interrupted
  • you can get stats while copying (without cost)
  • you can copy hardlinks and softlinks without breaking them
  • you can prevent it from traversal to other volumes while copying
  • you can limit bandwidth on slow connections
  • you can copy from one pc to another (encrypted and compressed)
  • you can dry-run (test what would be copied)
  • you can copy /dev !

But please be careful, not to copy / (because of /proc /sys /mnt /run …)
And when using btrfs, exclude /.snapshots and /home/.snapshots !

Just stop it crossing filesystem boundaries. :slight_smile:

--one-file-system, -x    don't cross filesystem boundaries
1 Like