1

Topic: gparted to copy a partition from one drive to another and MBR?

My current HDD is beginning to click when idle and I'm fearing that it will no longer work so I want to backup the drive to a brand-new HDD of the same size. It has three partitions on it currently:

/dev/sda1 is NTFS and contains Windows XP
/dev/sda2 is NTFS and contains a large data partition
/dev/sda3 is ext3 and contains my /boot for LINUX

(LINUX stuff resides on a 2nd smaller HDD).

Can gparted copy these partitions and retain the MBR on the disk so that I can literally swap the "bad" one for the new one once I'm finished? I don't want to reinstall either Windows or LINUX.

2

Re: gparted to copy a partition from one drive to another and MBR?

Hello graysky,

Can gparted copy these partitions and retain the MBR on the disk so that I can literally swap the "bad" one for the new one once I'm finished? I don't want to reinstall either Windows or LINUX.

Yes, but you should know the pitfalls.

Regards
cmdr

3

Re: gparted to copy a partition from one drive to another and MBR?

Since I'm not resizing or moving, I shouldn't have to mess with XP's registry at all, no?  According to your guide (if I have it all right):

1) Plug in both drives and boot from the gparted livecd
2) Select all three partition from disk #1 and copying them to disk #2
3) Use gparted to set the boot flag to the first partition on my drive

Do I have this right?

4 (edited by cmdr 2009-03-20 17:56:59)

Re: gparted to copy a partition from one drive to another and MBR?

Hello graysky,

1) Plug in both drives and boot from the gparted livecd
2) Select all three partition from disk #1 and copying them to disk #2
3) Use gparted to set the boot flag to the first partition on my drive

In principle, yes.
Concerning 2), you can't select more than one partition to clone in one step, but you can do a batch job ( collecting all cloning steps, before you start with "Apply"). The target drive should be blank.

Since your source drive might crash any time soon, you should perhaps consider to use "Clonezilla" instead, because it only clones used sectors and doesn't do a sector-per-sector copy like "Gparted". Your decision should depend on the amount of free space, the source drive still has.

A sector-per-sector copy with physically identical source and target HDDs is also possible with Terminal command "dd" ( contained on "GParted Live CD" )

Example ( source: /dev/sda; target: /dev/sdb; size: 200 GB =186.26 GiB =  390,625,000 blocks; "fdisk -l -u /dev/sda" gives you the number of blocks) :

dd if=/dev/sda of=/dev/sdb bs=512 count=390625000

Regards
cmdr

5 (edited by graysky 2009-03-20 21:54:53)

Re: gparted to copy a partition from one drive to another and MBR?

Thanks for the clarification. 
As to clonezilla, my understanding is that it will write the partition to an image file.  The user then has to restore the image file to the live disc.  This seems time consuming for my task as I just want to do a partition-to-partition write.  Can you verify that I am correct about this?

I think I'll try gparted first before trying the dd command of which I haven't used before.  Below is a screenshot of the source drive in gparted.

http://img12.imageshack.us/img12/263/gparted.png

If I'm understanding the procedure correctly, I simply need to queue up all three partitions for a copy to the new drive, then allow the batch to run.  When it finishes, all I need to do is add the 'boot' and 'lba' flags to the first partition and that should be it, right?

6

Re: gparted to copy a partition from one drive to another and MBR?

graysky wrote:

As to clonezilla, my understanding is that it will write the partition to an image file.  The user then has to restore the image file to the live disc.  This seems time consuming for my task as I just want to do a partition-to-partition write.  Can you verify that I am correct about this?

Yes, you are right.

Concerning your screenshot  : you can't work with "GParted" on a mounted drive, i.e. you can't use "GParted" contained in your Linux distro for cloning the whole disk. You need the Live CD, unless you can unmount (with "GParted") the ext3 boot partition on sda !

If I'm understanding the procedure correctly, I simply need to queue up all three partitions for a copy to the new drive, then allow the batch to run.  When it finishes, all I need to do is add the 'boot' and 'lba' flags to the first partition and that should be it, right?

Totally right.

Regards
cmdr

7 (edited by graysky 2009-03-20 22:21:07)

Re: gparted to copy a partition from one drive to another and MBR?

Cool, thanks for the help w/ this.  I'll try it as soon as my replacement drive arrives... perhaps I'll just do the 1st partition, then make an empty partition for the large data partition (the 2nd one), and do the 3rd partition.

I'll just dump the 2nd partition via rsync in the GUI.

8

Re: gparted to copy a partition from one drive to another and MBR?

Partial success!  New drive arrived.  Copied over the first partition, add the lba and boot flag, made a blank partition for the big one and copied over the 3rd partition.  Entire operation took 15 min.  Swapped out the old 750 gig drive for the new one and booted.  I was presented with the Windows boot loader (some how GRUB didn't get copied).

At this point I think I should just boot into my Lenny recovery CD and reinstall grub, no?

9

Re: gparted to copy a partition from one drive to another and MBR?

Hello graysky,

At this point I think I should just boot into my Lenny recovery CD and reinstall grub, no?

This is your first option, but I have a second, which doesn't overwrite your XP Master Boot Record, so that a rollback is very easy. If you are familiar with GRUB, I have nothing to tell you about "menu.lst". You need it as well with my solution. Download Grub4DOS, extract only GRLDR and put it to the root folder of your boot partition, where NTLDR is also located . and - of course - "menu.lst". Rename NTLDR to XPLDR and GRLDR to NTLDR. Correct "menu.lst" and be sure that line feed is single 0x0A and not 0x0D/0x0A as with Windows. Just reboot and enjoy your GRUB bootmanager.

Regards
cmdr

10

Re: gparted to copy a partition from one drive to another and MBR?

Thanks for the reply, cmdr.  I think I'll just go the Debian recovery option and reinstall GRUB.  I'm just curious why setting the boot and lba flags within gparted didn't take care of that.  After all, my 'old' drive booted into GRUB, not XP.

11

Re: gparted to copy a partition from one drive to another and MBR?

It's your choice ... and farewell to the XP Master Boot Record !

Good luck !
cmdr

12 (edited by graysky 2009-05-28 22:27:41)

Re: gparted to copy a partition from one drive to another and MBR?

Here is how I fixed it - whole thing took 2 minutes.

An important point that cmdr linked to in his post applies only if you're moving a Windows system partition.  I quote,

"You simply have to delete ONE Registry key BEFORE you use "GParted":

HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices

(Start - Run "regedit" - Search "mounteddevices"- Delete whole key)

NOTE: BE SURE, NOT TO ALTER ANYTHING ELSE, THERE IS NO "UNDO" !
      Don't worry, this  Registry key regenerates "slim"
      (not connected drives have gone) on next boot. If you changed drive
      letter assignment before, i.e. "renamed" a drive to a new drive letter,
      this has also gone afterwards. Drives are redetected and "named" in
      Windows-given sequence.

      AVOID RUNNING INTO NEW TROUBLE : DO NOT CONNECT (ON ONE
      SYSTEM) SOURCE DRIVE AND TARGET DRIVE OF A CLONED PAIR
      SIMULTANEOUSLY OR SEQUENTIALLY, IF YOU RUN WINDOWS.
      Duplicate Drive IDs are not allowed under Windows !
      You MUST change one ID at least (HowTo below !)."

With that out of the way, here is what I did.  Remember my disk layout:

graysky wrote:

It has three partitions on it currently:

/dev/sda1 is NTFS and contains Windows XP
/dev/sda2 is NTFS and contains a large data partition
/dev/sda3 is ext3 and contains my /boot for LINUX

(LINUX stuff resides on a 2nd smaller HDD).

Booted to a live CD (ubuntu has a nice one)

$ sudo mount /dev/sda3 /mnt
$ sudo grub
<<from within grub>>
> root (hd0,2)
> setup (hd0)
> exit
$ sudo umount /dev/sda3
$ sudo reboot

If you have more questions, see this article which I'll quote below in case it gets removed.

http://www.sorgonet.com/linux/grubrestore/ wrote:

HOWTO Restore GRUB

You have windows 98 and linux on the same hard disk and you choose GRUB as boot loader.At boot time you see a menu to choose windows or linux.
But one day you reinstall windows 98 and it rewrites your MBR and the menu has gone, now you only can boot windows.

What to do:
Put the redhat boot disk you created on the installation on the floppy drive, boot the system and run grub command

Remember that for grub (hd0,1) means hda (primary controller master), second partition.

Now we need to tell grub where are the grub files:

If you know where they are, type something like:
root (hd0,1)

else if you have no idea, type:
find /boot/grub/stage1
and then the root command with the correct parameters:

setup (hd0)
to install it on hd0, that is MBR of the first HD.

type quit and reboot.
The menu will appear again.

13

Re: gparted to copy a partition from one drive to another and MBR?

Just moved systems to a larger faster drive and was very glad I took the time to post the above smile  Gparted rocks.

14

Re: gparted to copy a partition from one drive to another and MBR?

graysky wrote:

Just moved systems to a larger faster drive and was very glad I took the time to post the above smile  Gparted rocks.

it seems that the latest version of clonezilla does entire disk-to-disk copy(at least i saw it in the options i was given to choose from when using it).