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 - 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 12-14-2006, 05:59 PM   #1
nkoplm
Member
 
Registered: May 2005
Distribution: Fedora
Posts: 92

Rep: Reputation: 15
using dd to restore a partition


Well there is good news and bad news for me.
- The good news is that i screwed up my windows partition.
- The bad news is now i have to fix it.

Im running a dual boot winxp/fc6. i decided i wanted to clear out my windows partition and start with a fresh copy.

luckily i had the foresight to do:
dd if=/dev/sda2 of=mybackupimage.img
( with the partition unmounted, running as root)
when i first installed. ( im completely noob at dd so i hope that will work for a partition restore )

so now, instead of being logical and smart, i just decided to try
dd if=mybackupimage.img of=/dev/sda2
( with the partition unmounted, running as root)
makes sense no?... well apparently not windows will not boot.

help! ( how ) can i restore from this image? or must i reinstall the painfull and long way?
 
Old 12-14-2006, 06:38 PM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
If you haven't changed the size of the parition, the problem may be with the MBR that you boot with rather than the parition itself. Can you mount the windows partition some where such as under /mnt, and then poke around to see if the files and directories are there?

You may simply need to check the contents of your grub or lilo configuration and rerun grub-install or lilo to get back to where you were before.

In windows itself, if you have changed the paritioning, then a drive that used to be the D: drive may now be the E: drive. This might cause problems. Also, windows tends to prefer to be on the first partition of the first drive, but I think you can install XP elsewhere.

Another thing to watch is what the filesystem is that you used to store the image on. For some filesystems such as fat32 you are limited to 2GB. You might also face that limit if you save to a samba share. If you wanted to save a large image to an externel usb drive that already has stuff on it ( so you don't have the reformatting option ), you could use the split command to break up the image on the destination. To restore then you would use the cat command with a wildcard and pipe that to the dd command using the of= option. The input in this case would come from the standard input.

Last edited by jschiwal; 12-14-2006 at 06:43 PM.
 
Old 12-14-2006, 07:03 PM   #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
Sounds a huge understaking to me to dd a Windows partition into a file inside Linux as Win2k or XP (for older version there is no need to dd it as their system files can be moved around) is about twice the size of an average installed Linux. Also dd doesn't compress and the image and so the file must be large enough to store the entire sda2 partition including every its empty space.

Still I would have though the command would work if (a) sda2 has not been changed in size or location in the hard disk. (b) The image file has been captured in full.
 
Old 12-14-2006, 07:20 PM   #4
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
If you want to use compression, you can pipe the output to bzip2 or gzip. The amount of size reduction will depend on how full the drive was. If you use split to break up the image and save it to an externel drive, you can then use par2 to add redundancy incase one of the files are damaged.

I'm not a big fan of saving images, but after initially installing a system, it can get you back in business quickly after a hard drive failure.
 
Old 12-14-2006, 09:25 PM   #5
nkoplm
Member
 
Registered: May 2005
Distribution: Fedora
Posts: 92

Original Poster
Rep: Reputation: 15
thanks for the replies.

let me summarize what i have figgured out so far (still not working):

partition is still the same size and location.
the problem is not the MBR, because i already have grub installed and, and i am booting my OS from the grub command line myself.

trying to boot from grub command line
Code:
rootnoverify
chainloader +1
boot
[ this gives some error about the partition is not in a proper executable format or something ]




trying to mount
file system type IS vfat. specificly chosen to make sure it was accessable under linux.

Code:
[root@localhost tmp]# mount /dev/sda2 /mnt/sda2 -t vfat
mount: wrong fs type, bad option, bad superblock on /dev/sda2, missing codepage or other error In some cases useful info is found in syslog - try dmesg | tail or so
[root@localhost tmp]# dmesg | tail
FAT: invalid media value (0x24) VFS: Can't find a valid FAT filesystem on dev sda2. hfs: unable to find HFS+ superblock FAT: invalid media value (0x24) VFS: Can't find a valid FAT filesystem on dev sda2. FAT: invalid media value (0x24) VFS: Can't find a valid FAT filesystem on dev sda2.


here is fdisk and parted information:

Code:
Device Boot      Start         End      Blocks   Id  System
/dev/sda2              10        1279    10201275    c  W95 FAT32 (LBA) <<< looks a-o-k
/dev/sda3            1280        9721    67810365    f  W95 Ext'd (LBA)
/dev/sda4            9722        9729       64260   de  Dell Utility
/dev/sda5            1280        1407     1028128+  82  Linux swap / Solaris
/dev/sda6            3321        5233    15366141    b  W95 FAT32
/dev/sda7            5234        9721    36049828+  83  Linux
/dev/sda8   *        1408        3320    15366141   83  Linux
Code:
Number  Start   End     Size    Type      File system  Flags
 2      74.0MB  10.5GB  10.4GB  primary                lba  <<< looks fine
 3      10.5GB  80.0GB  69.4GB  extended               lba  
 5      10.5GB  11.6GB  1053MB  logical   linux-swap        
 8      11.6GB  27.3GB  15.7GB  logical   ext3         boot 
 6      27.3GB  43.0GB  15.7GB  logical   fat32  
 7      43.0GB  80.0GB  36.9GB  logical   ext3 
 4      80.0GB  80.0GB  65.8MB  primary   fat16

still does not work

Last edited by nkoplm; 12-15-2006 at 12:12 AM.
 
Old 12-14-2006, 10:52 PM   #6
nkoplm
Member
 
Registered: May 2005
Distribution: Fedora
Posts: 92

Original Poster
Rep: Reputation: 15
My partition is 10GB but the image file is only 1.3GB this is becaue i recall doing something to not save free space into the image when i created it. (in order to keep the file size smaller)

could this have something to do with it?
 
Old 12-14-2006, 11:47 PM   #7
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 nkoplm
My partition is 10GB but the image file is only 1.3GB this is becaue i recall doing something to not save free space into the image when i created it. (in order to keep the file size smaller)

could this have something to do with it?
Yes!! But what did you do? You initially showed us the dd command you used, which would have kept the file size the same.

Where is sda1? Was Windows always on sda2?
 
Old 12-15-2006, 12:09 AM   #8
nkoplm
Member
 
Registered: May 2005
Distribution: Fedora
Posts: 92

Original Poster
Rep: Reputation: 15
Sorry about the error on the initial dd command. I did it about a year and a half ago, and was just going from memory. its just too bad that i dont remember the correct command that i used. doesn't dd have a built in option for removing free space? i looked through the man page, but nothing caught my eye. surely it does somewhere. i dont recall any other tool i might have used. (on the very small off chance that i did use something else, it still would have been somethign that came with my distro, not 3rd paryy.)


as for sda1... thats a good point, i dont know why i dont have one. i never really thought about this before.

my hard drive has been in this setup since i bought the computer and configured it. I made only one change ever. it involved sda6 and sda7.

sda6 was fat32 and sda7 was ext3
i took all files off both drives and reformatted so that
sda6 is now ext3 and sda7 is now vfat
neither of these partitions have ever had operationg systems on them.


windows was always sda2

.
 
Old 12-15-2006, 12:38 AM   #9
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
I've just been re-reading the dd man pages. there are lots of options, but none look like just skipping empty data areas.

My sense is that the easy way out of this will be simply to re-install.
 
Old 12-15-2006, 06:49 AM   #10
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
If you compressed the image, you might be able to use the "file" command to find out.

Filesystems can be analyzed with "file -s <imagefile>"

So if gzip was used, then you can use: zcat <imagefile> | dd of=/dev/hda2 bs=512
If bzip2 was used, then you can use: bzcat <imagefile> | dd of=/dev/hda2 bs=512
 
  


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
How to restore partition table without a CDROM? welson_sun Fedora - Installation 2 10-11-2005 03:30 PM
ext3 partition table restore pats Linux - General 1 07-22-2005 10:44 PM
HDD forensics... How to restore a partition? Thetargos Linux - Hardware 2 07-02-2004 03:59 PM
Why can't I restore a partition table backup containing a reiser partition? oldweasel Linux - Software 2 05-23-2004 12:11 AM
using dd to backup/restore windows partition win32sux Linux - General 9 01-26-2004 03:27 AM

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

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