4

pv is program running above dd. I am cloning my old HDD to a new SSD. It's 500GB of data. I tried to run the following command to copy sda to sdb:

ubuntu@ubuntu:/$ sudo pv < /dev/sda > /dev/sdb
bash: /dev/sda: Permission denied

Using dd command did not produce this error.

I am running the system Ubuntu from the DVD. sda is the main laptop harddrive connected over SATA, sdb is SSD drive connected over USB using USB-SATA converter.

karel
  • 114,770

1 Answers1

12

The redirections above are setup by your shell before forking and execing sudo. You may want something like the following:

sudo bash -c 'pv < /dev/sda > /dev/sdb'

This will cause bash to be run by sudo. Bash will execute the parameter to the -c arg as a command in that shell rather than running interactively.

The dd command worked because presumably you didn't use redirections with it.

Also, pv doesn't run above dd. The pv command does lots of things, including showing progress of its output to stdout or rate limiting its output.

ckujau
  • 341
Wren T.
  • 459
  • Thank you. And can you reassure me that the pv </dev/sda >/dev/sdb copies from sda to sdb? It would be nasty if I got all my sourcecode and personal data accidentally deleted. – Tomáš Zato Dec 11 '15 at 12:47
  • 1
    I would look into rsync for that use case. – Wren T. Dec 13 '15 at 19:28