LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-25-2012, 01:14 AM   #1
scandalist
Member
 
Registered: Apr 2011
Posts: 31

Rep: Reputation: 1
Cloning a drive with dd


I read on lifehacker that cloning a drive with Linux is easy as running this command.

Code:
dd if=/dev/sda of=/dev/sdb
Is this true? Apparently it is a bit for bit copy but I just can't imagine the process being this simple. Has anyone successfully cloned a drive with this method? I don't want to brick my data by using unsafe methods.
 
Old 06-25-2012, 01:39 AM   #2
EDDY1
LQ Addict
 
Registered: Mar 2010
Location: Oakland,Ca
Distribution: wins7, Debian wheezy
Posts: 6,841

Rep: Reputation: 649Reputation: 649Reputation: 649Reputation: 649Reputation: 649Reputation: 649
I myself use clonezilla-live & haven't had a problem
http://en.wikipedia.org/wiki/Clonezilla
http://clonezilla.org/
 
Old 06-25-2012, 02:32 AM   #3
descendant_command
Senior Member
 
Registered: Mar 2012
Posts: 1,876

Rep: Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643
Quote:
Originally Posted by scandalist View Post
I read on lifehacker that cloning a drive with Linux is easy as running this command.

Code:
dd if=/dev/sda of=/dev/sdb
Is this true? Apparently it is a bit for bit copy but I just can't imagine the process being this simple. Has anyone successfully cloned a drive with this method? I don't want to brick my data by using unsafe methods.
It certainly can be that easy.
That command gets EVERYTHING, MBR, partition layout and all.

There may be snags with different drive geometry, size etc. but you can try the clone before deleting the original ...
 
Old 06-25-2012, 05:50 AM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by scandalist View Post
I read on lifehacker that cloning a drive with Linux is easy as running this command.

Code:
dd if=/dev/sda of=/dev/sdb
Is this true? Apparently it is a bit for bit copy but I just can't imagine the process being this simple. Has anyone successfully cloned a drive with this method? I don't want to brick my data by using unsafe methods.
Yes, it is that simple.......BUT

You have to be absolutely sure that you have the correct device designations---there is no "undo".

You may want to set the block size for best speed. You can run trials like so:
Code:
dd if=/dev/sda of=/dev/sdb bs=M count=N
Start with M=2048 and keep the product of M*N the same---let's say ~ 100MBytes. As you change the block size, look at how long the operation takes. I don't remember the results the last time I tried this----it is useful to experiment a bit to see how it works and whether the block size makes any difference.

AND---the target drive has to be the same size as the source--or larger.

There is a megathread here somewhere--started by member "Awesome machine"----more than you ever wanted to know about "dd".

Last edited by pixellany; 06-25-2012 at 05:51 AM.
 
Old 06-25-2012, 06:39 AM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Curiousity got to me---on this machine (Lenovo laptop, 4G RAM), there is a dramatic increase in speed when the block size is larger than ~1K---I have no idea why.....
Code:
[root@herring-lap mherring]# dd if=/dev/sda7 of=/dev/sdb1 bs=256 count=128K
33554432 bytes (34 MB) copied, 23.7808 s, 1.4 MB/s
[root@herring-lap mherring]# dd if=/dev/sda7 of=/dev/sdb1 bs=512 count=64K
33554432 bytes (34 MB) copied, 23.241 s, 1.4 MB/s
[root@herring-lap mherring]# dd if=/dev/sda7 of=/dev/sdb1 bs=1024 count=32K
33554432 bytes (34 MB) copied, 6.2106 s, 5.4 MB/s
[root@herring-lap mherring]# dd if=/dev/sda7 of=/dev/sdb1 bs=2048 count=16K
33554432 bytes (34 MB) copied, 6.19044 s, 5.4 MB/s
[root@herring-lap mherring]# dd if=/dev/sda7 of=/dev/sdb1 bs=4096 count=8K
33554432 bytes (34 MB) copied, 6.11977 s, 5.5 MB/s
I have noticed that many people suggest a block size of 8192---seems like a good choice based on this quickie test.
 
Old 06-25-2012, 06:44 AM   #6
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,124

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Hmmmm - such (small) tests are meaningless unless in-storage buffers are purged.
drop-caches is useful these days, but I still prefer to reboot between any disk tests.

As for "dd", IMHO it should be avoided at all costs for non-forensic backups. Period.
 
Old 06-25-2012, 06:56 AM   #7
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
I have had the best results with block sizes between 8M and 32M.

Quote:
Originally Posted by syg00
As for "dd", IMHO it should be avoided at all costs for non-forensic backups. Period.
I am really curious for an explanation, like to share your wisdom?
 
Old 06-25-2012, 06:59 AM   #8
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by syg00 View Post
Hmmmm - such (small) tests are meaningless unless in-storage buffers are purged.
drop-caches is useful these days, but I still prefer to reboot between any disk tests.

As for "dd", IMHO it should be avoided at all costs for non-forensic backups. Period.
Well Hmmmmmm to you too......

<<begin dumb questions>>
What is an in-storage buffer?....drop-cache?
<<resume normal mode>>

What exactly is wrong with dd for backup? Beside---OP did not ask about backup---the question was about cloning a drive......dd do dat dandy....

Last edited by pixellany; 06-25-2012 at 07:00 AM.
 
Old 06-25-2012, 07:08 AM   #9
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,124

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Sorry - should have been "drop_caches" (underscore).

Disk read are buffered in page cache ("cached" in the free command et al). Subsequent reads to the same data may (will) be resolved from those buffers (in RAM), negating any disk read effects.
See drop_caches in "man proc" for how this can (now) be ameliorated.

"dd" copies everything blindly - including errors in the underlying filesystem. Makes backups (including clones) suspect at best.
 
Old 06-25-2012, 07:30 AM   #10
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
Quote:
Originally Posted by syg00 View Post
"dd" copies everything blindly - including errors in the underlying filesystem. Makes backups (including clones) suspect at best.
OK, that makes sense. So the solution to this would be to fsck all filesystems first, before you clone the disk using dd.
 
Old 06-25-2012, 07:41 AM   #11
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by syg00 View Post
Sorry - should have been "drop_caches" (underscore).

Disk read are buffered in page cache ("cached" in the free command et al). Subsequent reads to the same data may (will) be resolved from those buffers (in RAM), negating any disk read effects.
See drop_caches in "man proc" for how this can (now) be ameliorated.
Thank You!!
 
Old 06-25-2012, 08:00 AM   #12
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,124

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Quote:
Originally Posted by TobiSGD View Post
So the solution to this would be to fsck all filesystems first, before you clone the disk using dd.
Maybe. (or in my opinion "no").

fsck validates the filesystem, not the files/data within. That's why you can wind up with lots of "bit and pieces" of files in lost+found.
So, if the fsck is followed by remedial action on damaged files, then "dd" is fine. But a script that just fsck's then dd, uh-uh; still too risky.
 
Old 06-25-2012, 08:39 AM   #13
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
Wait, not one application I know of can deal with the data in the filesystem, I can't even imagine how that should be possible. So in your opinion even a simple backup scheme using cp isn't trustworthy, because the data may already be corrupted before the transfer?
 
Old 06-25-2012, 11:57 AM   #14
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,976

Rep: Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623
"I don't want to brick my data by using unsafe methods."

Well, I can say that if you ask then don't do it. dd had been known to bite most of us at one time or another.

EDDY1 posted an alternative to using a file based copy. As with dd and almost every other program there are many issues.

Issue tends to be size, geometry and then second is how the system boots. The geometry is sometimes difficult to fix while the boot naming tends to be more fixable.

I don't know of any fool proof way to copy a drive. I have used dd hundreds of times both directly and using G4U disks.

Like Porky says, When hunting for rabbits, you have to be vwery vwery cawful, hahahaha.

Last edited by jefro; 06-25-2012 at 12:00 PM.
 
Old 06-25-2012, 01:33 PM   #15
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Perhaps this field is already well-plowed,but:

If I have a drive with the essential data readable, and I then clone it for backup, it seems I have not lost anything----I still have a better backup than if I had done nothing.

---right?
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cloning dual-boot drive onto a smaller drive. Harju Linux - Newbie 4 05-29-2010 11:40 AM
cloning a drive with dd gdanko Linux - General 3 01-20-2010 01:11 PM
cloning drive but need advice peterb Linux - Newbie 11 10-15-2007 01:18 PM
Cloning onto drive that already has data tredontho Linux - General 5 07-26-2006 04:17 AM
Need help in cloning drive raddad51x Fedora 1 05-16-2006 01:31 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:59 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