1825576 Members
1862 Online
109682 Solutions
New Discussion

Disk Cloning using Linux

 
kenny chia
Regular Advisor

Disk Cloning using Linux

Hi
lets say I want to clone a hard disk to another identical disk using Linux. This is how I plan to do it.

1. Setup a system in the following manner
hda : Red Hat 8.0
hdb : Disk I want to clone
hdc : Disk I want to clone to

2. Copy the contents from hdb to hdc using the commands

cp /dev/hdb /dev/hdc

Will this work?
All Your Bases Are Belong To Us!
10 REPLIES 10
Bill Douglass
Esteemed Contributor

Re: Disk Cloning using Linux

Use dd to do a low-level copy like this.


dd if=/dev/hdb of=/dev/hdc bs=64k

Depending on available memory, you can increase the bs (blocksize) parameter.

dd is best used when copying disk images. See the dd manpage for more info.
Steven E. Protter
Exalted Contributor

Re: Disk Cloning using Linux

I think the dd command is the way to go. You can however boot your system with a windows 98 boot disk and a different disk containing Norton Ghost and duplicate disks quite nicely.

I use it as a substitute in Linux to Ignite backups which I use in HP-UX.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Sergejs Svitnevs
Honored Contributor

Re: Disk Cloning using Linux

"dd" wastes a great deal of space. I suggest you PartImage (http://www.partimage.org/) as more intellegent backup solution.

Regards,
Sergejs

Jerome Henry
Honored Contributor

Re: Disk Cloning using Linux

On your specs, be aware that your disks are not bootable.
I would stick on the dd command, which can be not space water if you use the right argument on it. Have a man dd for details, but to be short don't use bs unless you know hdb sector and block size (if so, use it !), and if both disks are the same, and don't use sync to avoir blanc octects and space wasting.
hth
J
You can lean only on what resists you...
Caesar_3
Esteemed Contributor

Re: Disk Cloning using Linux

Hello!

If the disks in the same size you can
use "dd".

If not you can do this (in the end you can
write a script that will do this)
What you need to do is to build the hdc
just like the hdb, you can do it by "sfdisk"
after you need to mount the whole tree of hdb
and hdc and copy the hdb tree to hdc tree
(by cp, cpio, tar or dump)
after you will finish the copy made
put the hdc disk as the hda
but with the rescue disk, mount the whole
tree and install the boot loader (lilo/grub)
If you want to put the disk as hdb/hdc etc.
you will need to change the /etc/fstab for.

Good luck!

Caesar
Jarle Bjorgeengen
Trusted Contributor

Re: Disk Cloning using Linux

Here is another way:

fdisk /dev/hdc --> Make same partitions as hdb.
mk(whateverfs you want on your new disk) /dev/hdc[1-X]
mount /dev/hdc[1-X] /mnt/[1-X]
Do this for each of the partition

cd (root of fs to copy from)
find . |cpio -pdumv (destination mountpoint)

if it is a bootable disk:
chroot (directory of where new / is, make sure that new /boot is mounted correctly relative to new / )
edit /etc/fstab (in chrooted env) to fit the new disk names a.s.o.)
edit lilo.conf/grub.conf and run lilo/grub-install.

Rgds Jarle
twang
Honored Contributor

Re: Disk Cloning using Linux

In my experience, i always use dd to clone whole disk bit by bit as:
dd if=/dev/hdb of=/dev/hdc bs=1024k
because dd will scan whole disk, therefore it may use relatively long time even you only use 10% of the diskspace. to save time insuch situation, you can consider using cpio or tar.
kenny chia
Regular Advisor

Re: Disk Cloning using Linux

Hi Twang,
You mean to get an image, I could actually do

tar -cvzf image.tar.gz /dev/hdb

and when I need to clone to another hard drive /dev/hdc

tar -xvzf image.tar.gz - >> /dev/hdc

I just untar the image and output the data to /dev/hdc?
All Your Bases Are Belong To Us!
twang
Honored Contributor

Re: Disk Cloning using Linux

Hi Kenny,
Share my experience, sometimes i need to clone data or application from our production environment to another test machine, in such case i usually break the disk mirror and use those disks on test environment.
Sometimes, i only to copy the data from production system to test system. if this is the case, i usually use dd to clone whole disk or i use cpio to copy the datafiles only.

Hope the experience could help.
twang
Jarle Bjorgeengen
Trusted Contributor

Re: Disk Cloning using Linux

Hi,

tar -cvzf image.tar.gz /dev/hdb

will give you a gzipped tar file with only the /dev/hdb DEVICE-FILE, not the contents of it.

Rgds Jarle