LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (http://www.linuxquestions.org/questions/slackware-14/)
-   -   Cloning a drive. (http://www.linuxquestions.org/questions/slackware-14/cloning-a-drive-4175430971/)

13_ 10-07-2012 10:43 AM

Cloning a drive.
 
Hi, I was wondering if anyone could tell me the best way to clone a hard drive. I was looking at Clonezilla but was wondering if it could be done with dd within slackware.

Thanks.

Martinus2u 10-07-2012 11:01 AM

Quote:

Originally Posted by 13_ (Post 4799463)
wondering if it could be done with dd

yes but it only really makes sense if both drives have excatly the same size and geometry. Theoretically you have a few options using dd in case the second drive is larger. However, I would clearly advocate creating fresh filesystems and copying on file level.

13_ 10-07-2012 11:32 AM

So with different size drives this wouldn't work with dd?

mutput7 10-07-2012 11:41 AM

Not if the new drive if smaller.
If the new drive is larger, you can just
Code:

dd if=/dev/OLDDRIVE of=/dev/NEWDRIVE
And resize the new drive's partitions with (e.g.) GParted.
(Make ABSOLUTELY sure you don't mix them up!)

schneidz 10-07-2012 11:42 AM

with dd if you clone a 100 gb drive to a 10 gb drive it will get truncated and probably wont boot (like pouring a gallon of paint into a quart container -- you will get a lot of spillage).

if you clone a 10 gb drive to a 100 gb drive. it will boot up but will act as if it has only 10 gb of space (you will be wasting 90 gb). there are probably ways to use gparted to make the rest of the space useful (i think that is how some live-usb's do it).

manwichmakesameal 10-07-2012 11:44 AM

Couldn't you just mount both of them and use rsync?

escaflown 10-07-2012 11:51 AM

Quote:

Originally Posted by 13_ (Post 4799463)
Hi, I was wondering if anyone could tell me the best way to clone a hard drive. I was looking at Clonezilla but was wondering if it could be done with dd within slackware.

Thanks.

Using dd to clone a live partition/drive might not be a good practice. You might have to run dd from a live distribution to clone the drive while it is not in use.

mutput7 10-07-2012 11:57 AM

Quote:

Originally Posted by escaflown (Post 4799509)
Using dd to clone a live partition/drive might not be a good practice. You might have to run dd from a live distribution to clone the drive while it is not in use.

I can't believe I forgot that. If you use dd, you should also really try and make sure you do it from some LiveCD/DVD/USB or something.

13_ 10-07-2012 11:58 AM

So, if I used identical drives

dd=/dev/OLDDRIVE of=/dev/NEWDRIVE

would work? And the new cloned drive would boot?

mutput7 10-07-2012 12:02 PM

Quote:

Originally Posted by 13_ (Post 4799514)
So, if I used identical drives

dd=/dev/OLDDRIVE of=/dev/NEWDRIVE

would work? And the new cloned drive would boot?

I replaced a dying drive like this once, so I'm pretty sure it will work for you. Just remember that it's safest to do it from some live removable media. Good luck!

13_ 10-07-2012 12:06 PM

mutput, if I wanted to keep a clone image on spare drive how would you do that?

dd=/dev/OLDDRIVE of=/root/clone.iso

To use repeatedly.

mutput7 10-07-2012 12:10 PM

Quote:

Originally Posted by 13_ (Post 4799522)
mutput, if I wanted to keep a clone image on spare drive how would you do that?

dd=/dev/OLDDRIVE of=/root/clone.iso

To use repeatedly.

I'm not sure I understand, but if I do, then

dd if=/dev/OLDDRIVE of=/SPAREDRIVEMOUNT/path/to/backup.img.iso.bak.clone.drv

Should work for what I think you mean.

13_ 10-07-2012 12:14 PM

Yes, that's what I was meaning, thanks.

riwi 10-07-2012 04:54 PM

Quote:

Originally Posted by 13_ (Post 4799514)
So, if I used identical drives

dd=/dev/OLDDRIVE of=/dev/NEWDRIVE

would work? And the new cloned drive would boot?

I use this to backup my slackware systems.
Even from a booted drive it works OK.

After booting with the backed up drive it looks as if it was switched off suddenly so the filesystem check will repair any 'open' files.

https://wiki.archlinux.org/index.php/Disk_Cloning

Also add the bs=1M option so the copying will go faster.

You could also copy 'per partition' and MBR+partition table separately
like :
dd if=/dev/sda of=/dev/sdb bs=512 count=1
dd if=/dev/sda1 of=/dev/sdb1 bs=1M
dd if=/dev/sda2 of=/dev/sdb2 bs=1M
etc.

Nice trick (during copying):
find the pid of the dd process : ps -ef | grep dd
from another terminal : kill -s SIGUSR1 <pid>
That will print the amount of data copied so far.

Ofcourse if you could unmount the drive to be copied that is preferable.

schneidz 10-08-2012 09:31 AM

this thread has a lot of info on dd:
http://www.linuxquestions.org/questi...ommand-362506/


All times are GMT -5. The time now is 11:56 PM.