LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 01-31-2007, 10:00 AM   #1
mkhan919
Member
 
Registered: Jan 2007
Location: Valbonne, France
Distribution: Mandriva 2008 (Free)
Posts: 135

Rep: Reputation: 15
Help with dd


okay first of all i apologize for putting up another dd question since there is a really wonderful thread already available at linuxquestions.org at
http://www.linuxquestions.org/questi...d.php?t=362506

however before i tried something i just wanted to be sure if that would work or not.

So here is what i want to do:

I have a toshiba machine with 60 GB hard disk . The partitions are are follows:

Device Boot Start End Blocks Id System
/dev/sda1 * 1 1341 10771551 7 HPFS/NTFS
/dev/sda2 1342 7296 47833537+ f W95 Ext'd (LBA)
/dev/sda5 1342 3253 15358108+ 7 HPFS/NTFS
/dev/sda6 3254 6204 23703876 7 HPFS/NTFS
/dev/sda7 6205 6982 6249253+ 83 Linux
/dev/sda8 6983 7113 1052226 82 Linux swap / Solaris
/dev/sda9 7114 7296 1469916 83 Linux


Now i wish to take the back of my hard disk so that if i loose data i can quickly restore it.
i know i can use dd if=/dev/sda of=/mnt/myexternaldrive/backup bs=4k

to take the back up.

My questions is it possible that after words i restore for example only /dev/sda1 (NTFS with the boot loader lilo).??/

if i can do that , then how would i access /dev/sda1 for restoring (i can mount the backup but how to access the partitions inside it????

Another thing i keep comming across with dd is that "hard disk should be exactly the same".. Does it mean i cannot backup my 60GB internal hardisk to my external 320GB hardisk??


And lastly, is the dd command present in linux LiveCD's like ubuntu or knoppix etc, since i would need to boot the system (and mount my external drive )before i can actually restore it?

Also, would i need to make partitions on the disk before restoring or would that be taken care of itself since i guess partition table would also be restored from the backup???


hmmm that turns out to be more than just one question but i hope you ppl dont mind..
Thnx

Last edited by mkhan919; 01-31-2007 at 10:10 AM.
 
Old 01-31-2007, 10:44 AM   #2
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
(1) You can dd the whole disk and this is usually the easiest.

(2) You can later restore selectively say only sda1. dd copies the entire partition including the boot sector. Therefore you Lilo will be restored as it is inside the sector 0 of hda1.

(3) When you restore sda1 you swap the devices from the input with the output. Thus using your original command it would be changed to
Code:
dd if=/mnt/myexternaldrive/sda1 of=/dev/sda1  bs=4k
(4)dd is just the carbon paper. You should have either the source exactly the same size as the target or the target bigger than the source if the whole disk is cloned. If you clone a larger disk into a smaller one, even if you have one byte, the big disk partition table will be cloned into the small disk, thereby making it an outcast. No operating system would want to read a disk that has a partition table larger than the physical size of the disk. You are then screwed if no operating system dares to read it.

For restoring a partition you need both partitions identical in size or the filing index will be messed up.

When a smaller disk is cloned into a large disk the extra capacity just become unallocated empty space which can be incoporated into existing partitions by resizing software like Gparted or Parted Magic.

(5) I have not met a Linux that has not got dd. It is nearly your God given right when using a Linux.

(6) When you restore a disk you write the whole disk including the partition table. Therefore there is no need to partition the target disk. However, as a word of caution, it pays to create just a partition in the target so that you can check it is using the correct geometry of 255 heads and 63 sectors, otherwise most raw disks can be cloned straight from a purchase.

Hope the above helps.

Last edited by saikee; 01-31-2007 at 10:48 AM.
 
Old 01-31-2007, 10:56 AM   #3
mkhan919
Member
 
Registered: Jan 2007
Location: Valbonne, France
Distribution: Mandriva 2008 (Free)
Posts: 135

Original Poster
Rep: Reputation: 15
Thnx and 1 last question

Thnx a lot for the information... Now i can happily get on with messing with my distro. Lol.

just 1 last question:

If i simply create a large enough Ext2 partition on the my external drive and the use dd to copy the entire laptop hardisk in a xyz.img file, all of the above things would still work. I think ext2 or ext3 does not have problems with large file sizes like 60 GB...???

Thank you very much again for your help.
 
Old 01-31-2007, 11:27 AM   #4
Quakeboy02
Senior Member
 
Registered: Nov 2006
Distribution: Debian Linux 11 (Bullseye)
Posts: 3,407

Rep: Reputation: 141Reputation: 141
"cp -a" works without the hazards of dd mistakes. The only thing it won't copy is your MBR.
 
Old 01-31-2007, 11:34 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
Quote:
Originally Posted by Quakeboy02
"cp -a" works without the hazards of dd mistakes. The only thing it won't copy is your MBR.
or your boot sectors...
or ANYTHING in the 63 or so unused sectors between partitions...

But, yes, you can certainly use file system commands and then back up mbr, etc. by other methods.

Last edited by pixellany; 01-31-2007 at 11:36 AM.
 
Old 01-31-2007, 11:36 AM   #6
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 mkhan919
If i simply create a large enough Ext2 partition on the my external drive and the use dd to copy the entire laptop hardisk in a xyz.img file, all of the above things would still work.
I have not tried it, but I am not sure this will work. Why not run some experiments?
 
Old 01-31-2007, 12:40 PM   #7
mkhan919
Member
 
Registered: Jan 2007
Location: Valbonne, France
Distribution: Mandriva 2008 (Free)
Posts: 135

Original Poster
Rep: Reputation: 15
Okay.. as suggest in the above post i am running an experiment...lol with a 10 GB partition containing windows XP.
This is what i did:

# dd if=/dev/sda1 of=/mnt/Temp/Win_c_Backup.img bs=4k
where /mnt/Temp is a 60 GB partition on my external USB Hardisk. The copying is still in progress but its tooooooo slow. Like it has taken already more than 10 mins and is till copying it. Just to verify i opened the drive and looked at it, and yes there is a file called win_c_backuo.img there but so far its size is only 2.8 GB after 10 mins... I had thought the copying would go may be a bit faster than that. Before , i tried a 5 GB partition and that time copying took only 5-8 mins ...
Any ideas on about how to speed things up..

Would it help if i increase the size mentioned in bs parameter???


Edited
****************
I read up on dd and i think that the bs parameter specifies the number of bytes to written to hard disk with a single system call. So i think here with the command that i have used , it meas 10GB /4K number of system calls. May be that is the reason for slow speed.


And the final result of the command is

[root@localhost Temp]# dd if=/dev/sda1 of=/mnt/Temp/Win_c_Backup.img bs=4k
2692887+1 records in
2692887+1 records out
11030068224 bytes (11 GB) copied, 5409.06 seconds, 2.0 MB/s

So it should speed things up if i change the value to something like 4k*10

Last edited by mkhan919; 01-31-2007 at 01:42 PM.
 
Old 01-31-2007, 01:50 PM   #8
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
Think I got about 20Mb/s when using dd from an internal disk to an external disk.

Internal to internal is about 50 to 55Mb/s using bs=32768.
 
Old 01-31-2007, 02:05 PM   #9
mkhan919
Member
 
Registered: Jan 2007
Location: Valbonne, France
Distribution: Mandriva 2008 (Free)
Posts: 135

Original Poster
Rep: Reputation: 15
Talking Job accomplished..

Thank you. yes you seem to be rite (in fact you are rite ..lol)
with bs = 2048k i ended up with 10 MB/s...

Thanks a lot for your help and input.

Last edited by mkhan919; 01-31-2007 at 02:07 PM.
 
  


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



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

All times are GMT -5. The time now is 10:35 PM.

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