LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Permission denied using sudo dd command with pv (https://www.linuxquestions.org/questions/linux-software-2/permission-denied-using-sudo-dd-command-with-pv-4175648105/)

Tem2 02-11-2019 08:53 PM

Permission denied using sudo dd command with pv
 
Trying to use dd command (my first effort with this command) to back up my system partition to a separate partition on the same hard disk.

sudo dd if=/dev/sda1 | pv | dd of=/dev/sda3
dd: failed to open '/dev/sda3': Permission denied
0 B 0:00:00 [ 0 B/s] [<=>

It runs ok without the pv option:
sudo dd if=/dev/sda1 of=/dev/sda3

MadeInGermany 02-11-2019 09:23 PM

The sudo ends at the pipe.
Either have two sudos:
Code:

sudo dd if=/dev/sda1 | pv | sudo dd of=/dev/sda3
Or pass the piped commands to a root shell (then even the pv runs as root)
as an argument
Code:

sudo sh -c "dd if=/dev/sda1 | pv | dd of=/dev/sda3"
or from stdin
Code:

echo "dd if=/dev/sda1 | pv | dd of=/dev/sda3" | sudo sh
Bash also takes
Code:

sudo sh <<< "dd if=/dev/sda1 | pv | dd of=/dev/sda3"

Tem2 02-11-2019 11:01 PM

Quote:

Originally Posted by MadeInGermany (Post 5960837)
The sudo ends at the pipe.
Either have two sudos:
Code:

sudo dd if=/dev/sda1 | pv | sudo dd of=/dev/sda3
Or pass the piped commands to a root shell (then even the pv runs as root)
as an argument
Code:

sudo sh -c "dd if=/dev/sda1 | pv | dd of=/dev/sda3"
or from stdin
Code:

echo "dd if=/dev/sda1 | pv | dd of=/dev/sda3" | sudo sh
Bash also takes
Code:

sudo sh <<< "dd if=/dev/sda1 | pv | dd of=/dev/sda3"

Thanks! I used 2 sudos.


All times are GMT -5. The time now is 07:33 AM.