LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
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 11-05-2003, 05:52 AM   #1
danishmr
LQ Newbie
 
Registered: May 2002
Location: Lahore, Pakistan
Posts: 26

Rep: Reputation: 15
How to make an exact copy of a Hard Disk


Hi,

I need to make an exact copy from one hardisk to another. How can this be done on linux, can the 'dd' command be used?

Also, does it matter if the hard disk are or different size as in if the target harddisk is bigger than the source.
 
Old 11-05-2003, 10:09 AM   #2
spurious
Member
 
Registered: Apr 2003
Location: Vancouver, BC
Distribution: Slackware, Ubuntu
Posts: 558

Rep: Reputation: 31
Try partimage, a partition imaging tool, similar to Norton Ghost.

Last edited by spurious; 11-05-2003 at 10:10 AM.
 
Old 11-05-2003, 10:46 AM   #3
/bin/bash
Senior Member
 
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802

Rep: Reputation: 46
Yes dd will work as long as the destination drive is as big as or bigger than the source:

dd if=/dev/hda of=/dev/hdb
 
Old 11-05-2003, 12:47 PM   #4
danishmr
LQ Newbie
 
Registered: May 2002
Location: Lahore, Pakistan
Posts: 26

Original Poster
Rep: Reputation: 15
Thankyou for the reply guys. So dd will work by simply by giving 'dd if=/dev/hda of=/dev/hdb'. Will it make any difference if the hard disk as SCSII Hardisk? Also is there any need to give anysort of parameter like sector size and things like that, casue I'm really impressed if it this simple!!
 
Old 11-05-2003, 03:17 PM   #5
/bin/bash
Senior Member
 
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802

Rep: Reputation: 46
I don't think it maters if the drive is scsi or ide, I have only done this with ide drives myself.

By default dd uses block size of 512 bytes which will work with most hard drives. If in doubt do a fdisk -l /dev/scd0 and look to see what the units are. Below mine says Units = cylinders of 16065 * 512 = 8225280 bytes. That means 16065 X 512bytes = 8225280 bytes. So the default 512 is OK. If yours has something other than 512 you can add a bs=1024 for example. You don't need a count because dd will stop when it reaches the end of the drive.

Code:
# fdisk -l /dev/hda

Disk /dev/hda: 41.1 GB, 41110142976 bytes
255 heads, 63 sectors/track, 4998 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot    Start       End    Blocks   Id  System
/dev/hda1             1      1274  10233373+   b  Win95 FAT32
/dev/hda2   *      1275      1401   1020127+  4d  QNX4.x
/dev/hda3          1402      1783   3068415   4f  QNX4.x 3rd part
/dev/hda4          1784      4998  25824487+   5  Extended
/dev/hda5   *      1784      2420   5116671   83  Linux
/dev/hda6          2421      3312   7164958+  83  Linux
/dev/hda7          3313      3821   4088511   83  Linux
/dev/hda8          3822      3948   1020096   83  Linux
/dev/hda9          3949      3998    401593+  83  Linux
/dev/hda10  *      4249      4502   2040223+  83  Linux
/dev/hda11         3999      4248   2008093+  83  Linux
/dev/hda12         4503      4998   3984088+  83  Linux
 
Old 11-06-2003, 03:46 AM   #6
Y0jiMb0
Member
 
Registered: Jul 2003
Location: Valencia (Spain)
Distribution: slackware 11, FEDORA CORE 4, RHEL3, Gentoo...
Posts: 361

Rep: Reputation: 30
Hi!
I 'will' (when I buy my new HD ) have the same problem. My hdc is 20GB and I'd like to replace it. Maybe 20GB => 120GB, but I'd like to keep all (information, OS, ...).
Quote:
Yes dd will work as long as the destination drive is as big as or bigger than the source:

dd if=/dev/hda of=/dev/hdb
QUESTION(S):
Would it mean a conflict with BIOS? (BIOS looks at the HD and sees the structure, but the beginning of the new HD has the structure information of the old one, What then?)
Will I be able to create new partitions in the free space?
(If not I'm wasting 100GB!!!)
I ask, because I had (have) many problems doing such 'simple' things with harddisks...
Regards

PS
I don't know too much about these questions; sorry about my imprecise language

Last edited by Y0jiMb0; 11-06-2003 at 03:59 AM.
 
Old 11-06-2003, 09:42 PM   #7
/bin/bash
Senior Member
 
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802

Rep: Reputation: 46
I have done it at work going from 3G drive to 20G and yes the extra space is wasted. There are ways to retrieve it if you need to. Our machines only require the 3G and since you can't hardly find a 3G drive any more we just buy 20G.

You could first partition the new drive and create a 20G partition then you would copy like this:
dd if=/dev/hda of=/dev/hdb1
However; if hda has partitions then that wouldn't work, you would have to create the same size partitions and copy them individually.

It may end up easier to just do like spurious suggested and use partimage.
 
Old 11-06-2003, 10:15 PM   #8
2damncommon
Senior Member
 
Registered: Feb 2003
Location: Calif, USA
Distribution: Debian Wheezy
Posts: 2,839

Rep: Reputation: 48
Quote:
I have done it at work going from 3G drive to 20G and yes the extra space is wasted.
Unless it really doesn't matter, there is no reason for the wasted space. At least not that much.
I would use dd partition by partition and copy it onto a slightly larger new partition. You would still have wasted space, but not 17 GB.
Doing this you would want to create new partitions before copying your old data to them and would need to be able to write your boot manager to the new hard disk.
 
Old 11-06-2003, 10:57 PM   #9
/bin/bash
Senior Member
 
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802

Rep: Reputation: 46
It's not that the space is wasted it's that it's not required. If I install the software off a CD it will create 3 partitions and they will use 3G of space. So when I make a backup I just use dd if=/hda of=/hdb, it's much quicker than partitioning and the 17G will never be used anyway.
 
Old 11-06-2003, 11:16 PM   #10
2damncommon
Senior Member
 
Registered: Feb 2003
Location: Calif, USA
Distribution: Debian Wheezy
Posts: 2,839

Rep: Reputation: 48
Quote:
Originally posted by 2damncommon
Unless it really doesn't matter....
Quote:
Originally posted by /bin/bash
It's not that the space is wasted it's that it's not required.
Okay.
Just curious now.
Is this, like, a custom install, firewall software, or a particular program or distro?

I wonder why hard disk makers do not make a one platter drive available. There are lots of times when the smallest disk available now is way to big.

Last edited by 2damncommon; 11-06-2003 at 11:18 PM.
 
Old 11-07-2003, 02:12 AM   #11
Y0jiMb0
Member
 
Registered: Jul 2003
Location: Valencia (Spain)
Distribution: slackware 11, FEDORA CORE 4, RHEL3, Gentoo...
Posts: 361

Rep: Reputation: 30
Thank you, /bin/bash and 2damncommon for your comments and the instructive discussion

Let's suppose (as is the case) I only want (need) the 18GB hdc3 partition from hdc(20GB) to the new hd (120GB), and moreover I have mandrake on hdc3 and, of course I would like to preserve it; afterwards I'd like to work with it again,
what can I do?
As I see in the partimage home page it is like dd but it's optimized to work only with partittions (is not 'the same', I mean I'm not sure if it is 'much better' for the use I'm thinking about)
Correct me (please), but what I think is to use 'dd', but what do I do with the very first part of the new HD?
I'm pretty sure that I'd have serious problems in with it. (in fact, right now I have a nasty problem with boot sectors, MBRs, etc... )
Regards
 
Old 11-07-2003, 06:30 AM   #12
markus1982
Senior Member
 
Registered: Aug 2002
Location: Stuttgart (Germany)
Distribution: Debian/GNU Linux
Posts: 1,467

Rep: Reputation: 46
you could also go for dump. for instance:

dump -0 -z9 -f hda1.dump /dev/hda1
 
Old 11-07-2003, 08:25 AM   #13
2damncommon
Senior Member
 
Registered: Feb 2003
Location: Calif, USA
Distribution: Debian Wheezy
Posts: 2,839

Rep: Reputation: 48
The kicker to using dd is that when you copy hdc3 to the new drive, it will still want to be hdc3. So you would want to put some planning into how you are going to partition the drive so it is most useful for you.
What I would think about doing:
Make a boot floppy. Confirm it works. It should be able to boot hdc3 on either drive. (after being copied by dd, of course). You can rewrite your boot manager after booting with the floppy or from another system.
Before using dd to copy Mandrake over, you may want to check /etc/fstab and comment out or delete anything but your Linux partiton, floppy, and CD. Is your swap going to be in the same place?
Before rewriting your boot manager, check that configuration file also.
A reinstall might be just as easy.
 
Old 11-07-2003, 04:49 PM   #14
/bin/bash
Senior Member
 
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802

Rep: Reputation: 46
Quote:
Okay.
Just curious now.
Is this, like, a custom install, firewall software, or a particular program or distro?
It's much worse than a custom install it's an "automated custom install", once you press the y key to continue it's all over. 3 partitions, 3G, thats all you get no matter what size drive you use. I know it's stupid but I just push the y key I didn't write the install script, somebody "really smart" did
 
Old 11-07-2003, 07:02 PM   #15
moses
Senior Member
 
Registered: Sep 2002
Location: Arizona, US, Earth
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152

Rep: Reputation: 46
If you're copying/mirroring data from a small HD to a larger one, I suggest you use tar (or something else like it). You won't waste any space and you can exactly mirror the data.
On the new disk make partitions slightly larger than on your old disk, then do the following:
Code:
cd /old/partition/mount/point; tar pcf - . | (cd /new/partition/mount/point; tar xf -)
This will take some time, but it should do what you need. You can read the man page to check that you don't need to include other options. . .
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
make exact copy of a hard disk in fedora AQG Linux - Hardware 6 08-07-2005 05:11 PM
Creating an EXACT copy of a disk elluva Linux - Software 5 10-15-2004 12:21 AM
Make a copy of entire hard disk jeucken Linux - Software 1 03-22-2004 05:55 AM
Exact hard drive copy messenjah Linux - Hardware 5 09-19-2003 05:40 PM
exact hard drive copy cbe Linux - General 5 11-21-2001 11:54 AM


All times are GMT -5. The time now is 11:34 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration