LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-20-2011, 04:25 PM   #1
ifatfirst
LQ Newbie
 
Registered: Jul 2011
Posts: 5

Rep: Reputation: Disabled
Trouble with permissions when using dd across a network


I am struggling to get dd to restore a disk image across a network. I imaged a hard drive using dd to an external drive but no longer have that drive. The image file itself is on another machine and the only drives I have are the single internal drives of each machine so I am trying to run the command over the network

Code:
ssh user@192.168.1.66 dd if=Desktop/todo/Laptop/image.img of=/dev/sda
Running the command I'm prompted for the password for 'user' and after entering it get the error:
Code:
dd: /dev/sda: Permission denied
I've tried booting the machine I need to restore from a Knoppix disc then used the "root terminal". I have also tried a standard terminal on both Knoppix and Ubuntu (in both cases running the OS from CD) running "sudo -i" before the ssh/dd combination.

The permissions on /dev/sda appear to be correct - root has rw access.

I assume the problem is that the credentials for the remote account "user" are being used for "dd". Is this a syntax problem or do I have to change the permissions on sda to give write access to everyone? I don't know if changing the permissions affects only the running Linux or if anything is written to disk so I'd prefer not to make changes until I'm sure I'll be able to restore the image.

Thanks
 
Old 07-20-2011, 06:00 PM   #2
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,982

Rep: Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626
http://www.ndchost.com/wiki/server-a...etcat-over-ssh
Try something like this maybe.


dd if=/dev/sda | ssh username@servername.net "dd of=/dev/sdb"
 
Old 07-21-2011, 08:29 AM   #3
ifatfirst
LQ Newbie
 
Registered: Jul 2011
Posts: 5

Original Poster
Rep: Reputation: Disabled
Thanks for the tip jefro.

I had a look at the link you included and tried netcat first but couldn't get it to work.

Going back to ssh I had to jump through a couple of hoops - running the command from the machine where the image was stored didn't work at first because something somewhere did not like the fact that Knoppix has a nul root password, once I changed it I managed to get it running with
Code:
dd if=Desktop/todo/Laptop/image.img | ssh root@192.168.1.68 "dd of=/dev/sda"
Now I just have to keep my fingers crossed that it will finish in less time than it would have taken me to order a USB drive and do everything locally 'cos it's a large, uncompressed image.
 
Old 07-21-2011, 12:48 PM   #4
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Fedora38
Posts: 6,147

Rep: Reputation: 435Reputation: 435Reputation: 435Reputation: 435Reputation: 435
I know you have marked this post as "solved", but you may be in for a l-o-n-g wait for that command to finish.

netcat really is the way to go if you are on your LAN (this basic method isn't safe over the big bad interweb).

Boot the laptop from a live CD.
On the laptop (the destination for the image), as root:

1] Make sure /dev/sda has no partitions mounted, unmount them if necessary.
2] Start netcat listening on port 1010:
Code:
nc -l 1010  | dd of=/dev/sda
On server (as root)
Code:
dd if=/home/username/Desktop/todo/Laptop/image.img bs=16M | nc IP.OF.LAP.TOP  1010
When the server has finished sending, dd will report the number of bytes transferred but the laptop will still be listening, so you need to do a CTRL-C on the laptop to terminate the listening command.

That's it.

Cross fingers and reboot the laptop.
 
Old 07-21-2011, 02:17 PM   #5
ifatfirst
LQ Newbie
 
Registered: Jul 2011
Posts: 5

Original Poster
Rep: Reputation: Disabled
Yep, I realise it is going to take time. I tried netcat earlier but couldn't get it to work. The method I used was almost identical to the one you suggest, I just chose a different port and used a relative path to the image file rather than an absolute one. There were no error messages when I started the laptop listening, nor when I started sending the file. The terminals did not return to a prompt as expected, but when I checked the port using tcpdump there didn't seem to be any traffic and the laptop hard disk showed no activity. I'm using Mac OS X on the 'server' - only the laptop is running Linux - but as far as I know there is no difference in netcat on OS X. What I didn't do was make sure /dev/sda wasn't mounted. I can't remember if running Knoppix from CD automatically mounts the machine's hard drive or not (and can't test it until the restore has finished).

I will give it another go if the ssh method fails but it's been running for a few hours now and judging by Activity Monitor, may only have an hour or two to go (as long as it doesn't slow down).

Thanks for the advice anyway.
 
Old 07-21-2011, 03:34 PM   #6
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Fedora38
Posts: 6,147

Rep: Reputation: 435Reputation: 435Reputation: 435Reputation: 435Reputation: 435
Thanks for the update.

Looks like you have been running for about 6hrs now.

Be patient, or try netcat. I have used it to do exactly what you are trying (but in reverse: I imaged a friend's virus-broken windows laptop [booted to a live linux distro] over my LAN to recover their personal data), it worked, and was very fast.

For the record, setting bs=a_big_number (16M in my post above) for the dd command speeds things up a lot, never mind the netcat business, which also helps.

Please let us know how you get on.

Best wishes.
 
Old 07-21-2011, 04:27 PM   #7
ifatfirst
LQ Newbie
 
Registered: Jul 2011
Posts: 5

Original Poster
Rep: Reputation: Disabled
It finally finished - after nearly 8 hours! ... which I suppose isn't bad as the image was 250GB and I had forgotten to specify the block size (I noticed about 2 hours in and decided to let it run) so it was using the default 512. The 100Mb connection was almost saturated (one way at least) for the whole time.

... and the machine boots

While I was not in a hurry the lessons I've learnt from this are:

- don't forget to set block size for dd
- zero slack space before imaging and compress to reduce the size of the image - the aim was a backup of config and applications not data which I backup separately

I'll try netcat next time.

Thanks for the help. I don't use Linux (nor the OS X terminal) often enough for these things to come to me without thinking and tend to forget what I know so all guidance is useful and welcome.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Trouble with permissions Adol Linux - Newbie 10 05-05-2011 09:19 AM
Having a little bit of trouble with the permissions on my network share mpriddy Linux - General 1 04-22-2009 06:36 PM
How to set up network permissions for user accounts. Restrict network access. r00tb33r Linux - Networking 7 02-04-2007 09:10 PM
Trouble with file permissions daekpon Linux - General 8 03-15-2004 10:57 AM
Folder Permissions Trouble 69_rs_ss Linux - General 3 01-16-2004 06:23 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration