Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Quick and dirty disk cloning
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
divideby0
n00b
n00b


Joined: 25 May 2004
Posts: 6
Location: Alexandria, VA

PostPosted: Thu Jan 06, 2005 12:01 am    Post subject: Quick and dirty disk cloning Reply with quote

Hi everyone. Thanks for all the great tips and tricks you've posted. This one may be obvious to some of you but it is handy in a pinch. As most of these postings, this comes with 'don't blame me if your box blows up' disclaimer. All I can tell you is that it worked for me, and should work for you too, but I can't guarantee anything.

At work today we got in a dozen new laptops and we were given a very tight schedule to get them out to our coworkers. We have a certain set of apps and such that we install on each new machine (unfortunately Windows), but usually they are in such small batches that we build them up one at a time. We had the advantage of all the laptops having the same hardware, but it seemed redundant to repeat the same install a dozen times, so we came up with a quick and dirty method of cloning the disks. These were Windows laptops, but the procedure will work for just about any hardware. Note that our particular method required an NFS server machine, but that can be avoided if necessary (more on that later).

After we had the first laptop built the way we wanted it, the first step was to boot to a live Linux CD. (We used knoppix but a LiveCD will work too). Assuming that the NFS share is already mounted at /mnt/temp, execute:

Code:
dd if=/dev/hdx bs=16k | gzip -z9 - > /mnt/temp/hdx-image.gz


This reads 16k blocks from /dev/hdx (adjust for your hard drive) and passes them to gzip which reads the stdin and zips to a file on the NFS mount. The reason we decided to use gzip was because the laptops had 30GB drives but only used about 5GB, so we didn't want to waste about 25GB storing empty space! This process took well under an hour with a newer Dell laptop and a 100Mbit network connection to the NFS server.

Once the dump finished, we booted the other machines into Knoppix and executed the following (again, assuming your NFS share is mounted at /mnt/temp):

Code:
gunzip -d -c /mnt/temp/hdx-image.gz > /dev/hdx


which decompresses the image and writes it directly onto the other hard drive. Since you are performing these operations on the drive itself and not the individual partitions, the partitioning table, bootloader, etc. are preserved. Also since we had a pretty beefy (RAID-5) NFS server, we were able to write to multiple machines at once. YMMV.

If you want to get really crazy, you can try this (totally untested) other method I came up with.... using ssh. In this method you don't need an NFS server or anything like that.

On the machine with the drive you want to clone, execute:

Code:
 dd if=/dev/hdx bs=16k | ssh -9 root@[targetmachine] 'cat - > /dev/hdx'


This method only works for one clone from the host machine to the target machine. If you have another machine that doesn't have NFS but has lots of storage you can execute:

Code:
 dd if=/dev/hdx bs=16k | gzip -9 - | ssh root@[storagemachine] 'cat - > /path/to/wherever/hdx-backup.gz


and on the target machines execute:

Code:
 ssh root@[storagemachine] 'gunzip -d -c /path/to/wherever/hdx-backup.gz' > /dev/hdx


Once again I didn't get to try this method, so there might be a typo in there somewhere. Hope this helps someone.
Back to top
View user's profile Send private message
ToeiRei
Veteran
Veteran


Joined: 03 Jan 2005
Posts: 1191
Location: Austria

PostPosted: Thu Jan 06, 2005 12:14 am    Post subject: Reply with quote

another way would be using netcat for transfer - maybe with less overhead.

Rei
_________________
Please stand by - The mailer daemon is busy burning your messages in hell...
Back to top
View user's profile Send private message
ChojinDSL
l33t
l33t


Joined: 07 Jul 2003
Posts: 784

PostPosted: Thu Jan 06, 2005 6:49 am    Post subject: Reply with quote

Question. Can you use "cat /dev/hdx" instead of dd?
I mean whats the difference?

If I do "cat /dev/hdx > Backup.iso" wouldnt that work as well?
I'm guessing I could also pipe that into gzip.

Any drawbacks to this?
Back to top
View user's profile Send private message
at6
Tux's lil' helper
Tux's lil' helper


Joined: 28 Nov 2002
Posts: 78
Location: /dev/null

PostPosted: Thu Jan 06, 2005 9:53 am    Post subject: Reply with quote

thanks mate. great tip!

it's also a good backup solution, with the option of easy recovering.

best regards
marc
_________________
debian: stable but lame! suse: unstable and lame! gentoo: stable and only 4 geeks!
Gadget tests!
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum