Make an image of a HD with all its partitions ?

Topics about disk partitioning (fdisk, parted, gparted, partimage), Volumes Management (lvm, evms, dmraid), Storage, file systems, ...
Post Reply
alcatel-lucent
Posts: 5
Joined: 02 Jun 2008, 17:51

Make an image of a HD with all its partitions ?

Post by alcatel-lucent » 02 Jun 2008, 17:56

Hi all,

I just love to use SRC for computers with 1 or 2 partitions.

I have another setting here, and I'd like to see if SRC could help me..

I have some linux HD with 10+ partitions (unknown, ext2, swap). Is there a way to have SRC take a full image of the HD with all its partitions, and restore everything on another HD of the same size ?

Thank you all

kfgz
Posts: 69
Joined: 02 Mar 2008, 18:00

Post by kfgz » 02 Jun 2008, 18:17

Code: Select all

dd if=/dev/sdX of=/dev/sdY
X - source, Y - destination

alcatel-lucent
Posts: 5
Joined: 02 Jun 2008, 17:51

Post by alcatel-lucent » 02 Jun 2008, 18:28

Hi ,

dd is ok if I want to make an image from 1 partition into another partition on the local HD.

What I am trying to do, is boot from SRC, and have it image ALL the partitions by itself on a remote server .... :)

alcatel-lucent
Posts: 5
Joined: 02 Jun 2008, 17:51

Post by alcatel-lucent » 03 Jun 2008, 17:04

I think I found my answer, with sfdisk, which can get the configuration from the command line. I can just write a small script.

Thank you for your help though

kfgz
Posts: 69
Joined: 02 Mar 2008, 18:00

Post by kfgz » 03 Jun 2008, 18:31

DD can copy whole disk, not only a partition.

alcatel-lucent
Posts: 5
Joined: 02 Jun 2008, 17:51

Post by alcatel-lucent » 03 Jun 2008, 19:04

Hi ,

Would System Rescue CD be able to do the same thing (copy a full HD?)
I have 15 partitions on each disk, 2 of them being unknown. SRC did not like that.

I like the fact that it does not copy the empty sectors, so it is faster. dd would copy everything....

thank you

sloter
Posts: 23
Joined: 27 Mar 2007, 10:22

Post by sloter » 04 Jun 2008, 09:36

1. Make copy of mbr from your source disk
dd if=/dev/hda of=boot.bin count=1

you'll copy your hdd structure to one file.

2. make copy of your source partitions using partimage

3. restore prepared mbr from file to your target computer

dd if=boot.bin of=/dev/hda

4. format partitions using mkfs

5. restore partition images to target disk

I hope this will help you. You can do script to automate this task.

alcatel-lucent
Posts: 5
Joined: 02 Jun 2008, 17:51

Post by alcatel-lucent » 04 Jun 2008, 16:55

Hello,

I'll check it out, thank you.

panschop
Posts: 1
Joined: 05 Feb 2009, 20:26

Post by panschop » 05 Feb 2009, 20:58

hi, i'm from chile, sorry buy my english, but i have some questions
kfgz wrote:DD can copy whole disk, not only a partition.

thats is all ??
no swap areas?
no partitions areas??
if it be ... is so great =)

or this is the way

1. Make copy of mbr from your source disk
dd if=/dev/hda of=boot.bin count=1

you'll copy your hdd structure to one file.

2. make copy of your source partitions using partimage

3. restore prepared mbr from file to your target computer

dd if=boot.bin of=/dev/hda

4. format partitions using mkfs

5. restore partition images to target disk


to do this, is from a live cd o can be do whit de system on normaly...

please helpme.

saludos

voelkerl
Posts: 4
Joined: 08 Jan 2009, 21:06

using dd to image a full disk over ssh ...

Post by voelkerl » 10 Feb 2009, 15:16

I've been using dd to do something like this for comptuers that I want to image. Basically the setup that I use has another comptuer to hold the "image" of the source hard disk.

Here's what I would run on the source computer after booting systemrescueCD ...

dd if=/dev/sda bs=128k | gzip -9 | ssh [email protected] "dd of=my_full_image.gz"

if you want a handy dandy status bar, you can use dcfldd instead of dd ...

dcfldd if=/dev/sda bs=128k | gzip -9 | ssh [email protected] "dd of=my_full_image.gz"

To get the image onto the target machine, just reverse the procedure, booting sysrescueCD on the target machine and use the command ....

ssh [email protected] "dd if=my_full_image.gz" | gunzip | dd of=/dev/sda bs=128k

I suppose you could also boot up the "target PC" with sysrescue as well, fire up the ssh server on the target machine (give yourself root access over ssh), and just image directly to the machine ...

dd if=/dev/sda bs=128k | gzip -9 | ssh [email protected] "gunzip | dd of=/dev/sda"

I suppose you could remove the gzip and gunzip business, but of course you'll see much more traffic over your ssh connection.

admin
Site Admin
Posts: 2715
Joined: 17 Jul 2003, 09:44

Post by admin » 10 Feb 2009, 21:51

You can also use fsarchiver which is in sysresccd to save file system images of your filesystems, it supports multiple filesystems per archive. It's still under heavy development anyway so we have to make tests to be sure you can restore your data.

dgerman
Posts: 13
Joined: 15 Dec 2006, 18:09
Location: New Jersey, USA

Post by dgerman » 17 Feb 2009, 01:24

You might also check out

g4u http://www.feyrer.de/g4u/ BSD based

g4l http://www.mepis.org/docs/en/index.php/G4l

partimage new generation https://launchpad.net/partimage-ng

jharris1993
Posts: 3
Joined: 09 Oct 2009, 05:17

Re: using dd to image a full disk over ssh ...

Post by jharris1993 » 09 Oct 2009, 13:53

voelkerl wrote:I've been using dd to do something like this for comptuers that I want to image. Basically the setup that I use has another comptuer to hold the "image" of the source hard disk.

Here's what I would run on the source computer after booting systemrescueCD ...

dd if=/dev/sda bs=128k | gzip -9 | ssh [email protected] "dd of=my_full_image.gz"
In my case I have a 1 terabyte drive set up as 1 gig unused (for me to play with), 1 gig swap, and the rest mounted on "/".

Since I'm running the Ubuntu 9.04 live CD on the system I'm trying to back up, and I have a 2nd 1T drive on a USB adapter, I tried running this:

Code: Select all

dd /if=/dev/sda bs=128k | gzip -9 | dd of=/media/Backup/test_backup.gz
It appears to be working - but it's taking forever. (right now, it's at almost 10 hours of run-time and has generated about 200 gigs of output file.)

I can take drive snapshots of Windows boxes in about one ninth of the time.

Any ideas on how to take a drive snapshot that would be useful as a bare-metal restore - and not spend a week doing it?

Thanks!

Jim

jharris1993
Posts: 3
Joined: 09 Oct 2009, 05:17

Re: Make an image of a HD with all its partitions ?

Post by jharris1993 » 09 Oct 2009, 19:18

OK - here's the Real Deal. . .

First: Trying to image a hard drive of ANY size using "dd" is for the BIRDS! I tried that, using dd piped to gzip, and after more than ten hours, it had hardly begun to backup a 1 terabyte drive with three partitions on it.

I have found a better way - it's still a bit messy, but it DOES work - I'm posting this using the restored system even as we speak. . . .

Note that this was done on a system that had Ubuntu 9.04 installed on it.

Needed materials:
1. A recent copy of System Rescue CD burnt to hard media (or otherwise available - I burned it to a CD)
2. A copy of the Ubuntu 9.04 installation DVD. (or CD - I used the DVD for the install, and it worked for the recovery.)
3. Some place to put the saved image. I used a spare 1T drive plugged into a USB adapter, formatted as one large ext2 partition.
4. A fair amount of luck. No kidding! You go messing with partition tables and MBR's, and you'd better be - at the very least - on speaking terms with Lady Luck. . . . :-D

=======================
Backing Up the System
=======================

Note: This assumes you know something about the structure of your system. Gparted is a great graphical tool to let you know what - and how - the stuff on your drives is set up.

1. Perform an orderly shut-down, making sure the CD-ROM drive is open.
2. Make sure that whatever you're going to use as the target is attached.
3. Install System Rescue CD, close the CD-ROM, and restart the system booting to the default.
4. From the root prompt, create a mount-point for the image drive - in my case I created a mount-point on /mnt called "Backup" (/mnt/Backup)
5. Mount the backup drive on that mount-point. (I ran "mount -t ext2 /dev/sdb1 /mnt/Backup" because the USB device showed up on /dev/sdb, and I knew it was formatted as ext2)
6. Run "partimage"

Partimage will begin to run within the console session you are in. If you don't know what "ncurses" is, just think of the old DOS tools.

Partimage will then show you the partitions you have on your various drives.
In my case - I had three partitions on /dev/sda - sda1, sda2 and sda3. Sda1 was an empty partition, sda2 was set up as Linux Swap, and sda3 was the main partition.

7. I used partimage to create a single backup of partition /dev/sda3 on /mnt/Backup as "test_backup". (I won't walk you through partimage, it is (with respect to backups) pretty self-explanatory.

Partimage took about 20 minutes to backup about 17 gigs of data. It should be noted at this point that partimage created a file called "test_backup.000" - you need to know the *actual* file name created when you go to restore it.

==================================

To test this, I then rebooted the system, and removed the USB device. Once the System Restore CD was back up and running - I nuked the hard drive I just imaged by "dd'ing" from /dev/zero to the device with a bs=4M and count=100. Takes about 2 minutes or so to wipe out the first few hundred megs. . .

Don't try this at home kiddies - this should ONLY be done by trained professionals!! (laughing)

Seriously - dd'ing /dev/zero to your hard drive is a great way to trash it. In my case, that is precisely what I wanted to do - I wanted to simulate a "bare metal" restore to a brand-new hard drive. In any event, when you run dd, you better be damn sure about what you're doing. This is why I - the rocket scientist ( :-p ) that I am - take the precaution of TURNING OFF and PHYSICALLY REMOVING the backup drive before I do something like this. . . Have *I* ever accidentally trashed an irreplaceable drive? Who ME? Nahh! I wouldn't do something stupid like that!!!

===================
Restoring the backed up image
===================

(This assumes that the "defective" hard drive has been replaced, etc. etc. etc.)

1. Connect the device with the backup image to your system.
2. Boot the System Rescue CD
3. Once it finishes booting - mount the device with the saved image as noted above.
4. Navigate to the saved image directory and verify the saved image file is visible, and note the filename it was saved under.
5. Launch partimage.

Note:
Because your new drive does not have any existing partitions on it yet, it will not be visible in the partition list. Pick the partition where the image is stored for the time being.

Also, you will need to enter the full pathname (in my case "/mnt/Backup/test_image.000" on the line requesting the image filename.

6. Select "restore MBR from image file" below, and then continue.
7. On the next screen, on the left hand side, select the device you will be restoring the MBR to (the target of this operation) - and on the right side, select the MBR to restore. In this case, there should only be one to restore.
8. Down below, select "Restore the entire MBR" - and then allow it to continue.
9. You will receive some weird errors - especially one that says the disks are not the same size (in my case, it was the exact same drive! - so some of these messages need help. You can ignore them after taking a careful look.
10 Allow it to restore.

Once the restore is done, you will return to your terminal prompt down at the bottom of the screen.

Restart partimage.

You will notice - this time - when partimage starts that you have all your partitions back on /dev/sda (or whatever)

You can then use partimage to select the partition to restore - in my case it's /dev/sda3 - and the file to restore from (/mnt/Backup/test_image.000), and let it go.

The partition will restore very quickly - about 2.2 Gbytes/second on my machine - with a total time of just a tad over 7 minutes in my case.

Once this is done, you're *ALMOST* finished - but there are still some manual fix-ups you need to do.

===================
Post Restore Fixups
===================

1. Since I did not save the swap partition - ergo it was not restored - I needed to "makeswap" (sp?) to re-create the actual swap partition structure.

2. Even though you restored "the entire MBR" - you may not be able to boot back into the restored partition. I would suggest doing a shutdown at this point - remove the System Rescue CD - and let it try to boot.
Did it boot?
If yes, then you're done!
If not, you will have to restore the boot loader and re-link it to your partition.
In my case, when I did my trial boot, all I got was a screen full of the word "GRUB".

3. In my case, the boot attempt failed, so I needed to fixup the boot process. To do this, I rebooted using the Ubuntu 9.04 install DVD that I used to install the original system with.

4. From the initial menu, I selected "Rescue Broken System" - and then allowed the system to re-boot.
5. You will be asked where the root of your system should be - in my case it was /dev/sda3 so I selected that.
6. Next you will get a short menu of things to do - and I selected "Reinstall GRUB"
7 GRUB will want to know where to put itself, so I selected the *DEVICE* (/dev/sda) so that GRUB would re-install into the MBR of the drive.
8. Once that was done, I shut down, removed the Ubuntu DVD, and re-booted.

Vola!

A restored system!

OK, it's not as easy as Drive Image, but it works, and it's a lot less time consuming than a multi-day dd session.

I do not know if partimage exists on the Ubuntu DVD, if it does, you could theoretically work directly off of that.

What say ye?

Jim

Post Reply