LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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 02-19-2006, 08:45 AM   #1
paraiso
Member
 
Registered: Apr 2005
Distribution: Fedora Core 4
Posts: 88

Rep: Reputation: 15
Question HDisk image with dd command


Hi!

I heard the dd command can make an image of an entire harddisk. What is the procedure ? I 'd like to make an image of my entire harddrive (hda) to a second slave IDE (hdb). Is the process similar to tool like ghost where you have to boot from a boot disk? I know about partimage but I'd rather try dd.

Thanks in advance for your help
 
Old 02-19-2006, 09:02 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
dd is the ultimate power tool. It will copy **anything** to **anything**, and will also quite happily destroy your entire system.....Proceed with caution

basic format:
dd <input> <output> <blocksize> <#ofblocks> <offset>

example:
dd if=/dev/hda1 of=backupfile bs=512 count=100

This copies the first 100 blocks (blocksize 512) from partition 1 of hda to a new file called "backupfile" (Better, I think, to use a full pathname---eg: /home/user/backupfile)
Instead of "of", you can also pipe, eg:
dd if=/dev/hda1 bs=512 count=100 | backupfile
OR,
dd if=/dev/hda1 bs=512 count=100 |hexdump -C| more (to read the data on the fly)


Beyond this example, I suggest you read man dd and run some tests** to be sure you understand how it works.

**On a system with all data backed up....
 
Old 02-19-2006, 09:24 AM   #3
saikee
Senior Member
 
Registered: Sep 2005
Location: Newcastle upon Tyne UK
Distribution: Any free distro.
Posts: 3,398
Blog Entries: 1

Rep: Reputation: 113Reputation: 113
pixellany has given a good run down of dd.

Just make sure your "target" hdb is bigger than the "source" hda. Best is identical size.

I use bs=32768 which is 64 sector x 512 bytes per Sector. This is about the optimum. Not specifying bs will make dd to default to 512 bytes in each transfer and slows it down.

I often have cloned 300Gb disk with about 60 partitions (mix of Dos, Windows and Linux inside) by
Code:
dd if=/dev/hda of=/dev/hdb bs=32768
If you clone the whole disk it will boot as the original. It is impossible to make dd not producing a 100% mirror image because no filing system is involved and the disk binary patterns are faithfully duplicated.

Should try to clone XP with dd sometime and appreciate how ignorant PC users are being milked by big corporations for doing simple backups.

Remember dd copies only the binary patterns of the hard disk and so an operating system totally foreign to Linux will still be replicated. Kind of magic, isn't it?

Last edited by saikee; 02-19-2006 at 09:29 AM.
 
Old 02-19-2006, 09:29 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 saikee
Should try to clone XP with dd sometime and appreciate how ignorant PC users are being milked by big corporations for doing simple backups.
Not sure what you are saying here---maybe you mean Symantec selling something like Ghost when we do it for free with dd?
 
Old 02-19-2006, 09:34 AM   #5
saikee
Senior Member
 
Registered: Sep 2005
Location: Newcastle upon Tyne UK
Distribution: Any free distro.
Posts: 3,398
Blog Entries: 1

Rep: Reputation: 113Reputation: 113
pixellany,

Exactly! It is only one line of command and dd has been in existence as long as PC.

Nowaday dd is available in every Linux Live CD, so a Windows user can backup his/her XP without Linux being installed or have any knowledge to run Linux!

In my signature I described dd could work faster and able to cope with more difficult cases than the commercial software.

I used Ghost exclusively before coming into Linux and now I have not had a need to use Ghost again except for bench mark dd's performance.

People who use Ghost should know the cloning is also done by copying the binary pattern sector by sector using a DOS program. Ghost is quite respectable in its abity and speed because one can also use hard disk manufacturer's softeware to clone disks at possibly 1/3 to 1/10 the speed and still be unsuccessful in the end. In Linux dd is just a tiny part of the weaponry available.

Last edited by saikee; 02-19-2006 at 09:48 AM.
 
Old 02-19-2006, 09:44 AM   #6
paraiso
Member
 
Registered: Apr 2005
Distribution: Fedora Core 4
Posts: 88

Original Poster
Rep: Reputation: 15
Thanks a lot pixellany and saikee for your help.
Two more questions:

- Can I do the cloning from the harddrive that I want to backup (hda). I mean if I execute the command dd if=/dev/hda of=/dev/hdb bs=32768 from the Linux OS (hda) I want to clone?

- Do I have to format the hdb in ext3 ?

cheers
 
Old 02-19-2006, 10:03 AM   #7
saikee
Senior Member
 
Registered: Sep 2005
Location: Newcastle upon Tyne UK
Distribution: Any free distro.
Posts: 3,398
Blog Entries: 1

Rep: Reputation: 113Reputation: 113
From my exeperience the answer is yes because dd is reading from a "raw" device.

Since submiiting a long train of data in a once-through operation the cache memory is not going to be effectively and so it is not a bad idea to use a Live CD to do the job. I find over 50Mb/s transfer rate possible and therefore running from a hard disk gains very little.

There is definitely no need to format and I don't even partition the target disk. In cloning the whole disk the MBR, boot sector, partition table, filing indices are all data are "mirrored" 100%.

You never need to format in dd but if you only clone one partition then you need to ensure the target partition "identical" in size to the source partition.

If the boot loader is not required and you are only interested in the files then Linux has better back up commands like tar, cpio and rsync to name a few. Those are the ones you can play tones with.

Last edited by saikee; 02-19-2006 at 10:05 AM.
 
Old 02-19-2006, 10:16 AM   #8
paraiso
Member
 
Registered: Apr 2005
Distribution: Fedora Core 4
Posts: 88

Original Poster
Rep: Reputation: 15
Thanks again for your comprehensive answers! dd seems excellent, it's just what I was looking for, simple and efficient.
 
Old 02-19-2006, 12:11 PM   #9
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 paraiso
Thanks a lot pixellany and saikee for your help.
Two more questions:

- Can I do the cloning from the harddrive that I want to backup (hda). I mean if I execute the command dd if=/dev/hda of=/dev/hdb bs=32768 from the Linux OS (hda) I want to clone?

- Do I have to format the hdb in ext3 ?

cheers
**I think** the only thing that can happen in copying from the same disk from which you are running the command...IS: Whenever the OS is running (and any apps), certain files--eg logfiles are being updated on the fly---sometimes in background. What this means is that the clone may not be perfect.
The above is normally of no consequence--eg if you just want critical files backed up.
 
Old 02-19-2006, 02:49 PM   #10
paraiso
Member
 
Registered: Apr 2005
Distribution: Fedora Core 4
Posts: 88

Original Poster
Rep: Reputation: 15
Just tried dd but I got this message:

# dd if=/dev/hda of=/dev/hdb
dd: writing to `/dev/hdb': No space left on device
156250001+0 records in
156250000+0 records out

The harddrives are identicals, same brand and same space capacity.

Is that normal that my second partition (hda2) has a file type unknown instead of ext3 ? I am using Fedora core 4
 
Old 02-19-2006, 02:59 PM   #11
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,128

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Quote:
Originally Posted by paraiso
dd seems excellent, it's just what I was looking for, simple and efficient.
Very true - maybe too true.
The use of "dd" has probably broken more systems than it has saved. Not the fault of the command, but its (mis-)use.

Try this link for more info than you ever imagined about dd.
 
Old 02-19-2006, 03:00 PM   #12
saikee
Senior Member
 
Registered: Sep 2005
Location: Newcastle upon Tyne UK
Distribution: Any free distro.
Posts: 3,398
Blog Entries: 1

Rep: Reputation: 113Reputation: 113
Do a
Code:
fdisk -l
to show us the two 80Gb disks have identical sizes.
 
Old 02-19-2006, 03:17 PM   #13
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,128

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
And of course, that 80Gig is a marketing number - 156250000 512-byte records gets you somewhere around 74.5Gig.
I would guess that's not always the same, although you would expect to get the same number of cylinders from the one manufacturer.
 
Old 02-19-2006, 03:25 PM   #14
paraiso
Member
 
Registered: Apr 2005
Distribution: Fedora Core 4
Posts: 88

Original Poster
Rep: Reputation: 15
Here is the result with fdisk:

Disk /dev/hda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hda1 * 1 13 104391 83 Linux
/dev/hda2 14 9729 78043770 8e Linux LVM

Disk /dev/hdb: 80.0 GB, 80000000000 bytes
255 heads, 63 sectors/track, 9726 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
Old 02-19-2006, 03:33 PM   #15
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,128

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Well, ain't that a bitch !!!!.
Have a look at the respective cylinder count.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Command Line Image Editing fractal_chaos Linux - Software 8 10-03-2005 05:33 PM
Changing the tux image on the command prompt Oholiab Slackware 3 03-06-2005 09:16 AM
What can I do about hdisk errors like this? jmartinph Slackware 3 02-28-2005 03:12 AM
View image from command line? Rotwang Linux - General 1 03-22-2004 02:51 AM
Boot to different image from command line markb Linux - General 8 04-06-2003 08:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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