cloning an entire drive

Place to discuss Debian Linux and Debian based distributions
Ice9
guru
guru
Posts: 577
Joined: Thu Jan 09, 2003 12:40 am
Location: Belgium
Contact:

cloning an entire drive

Post by Ice9 » Wed Jan 18, 2006 3:45 pm

I think my hard drive is about to give up on me.
And since I happen to have the exact same drive built in an external enclosure I would like to make an image of my current drive to the new one and swap them.

Could I just install it as slave on /dev/hdb and do

Code: Select all

dd if=/dev/hda of=/dev/hdb
Pull out /dev/hda, adjust the jumpers of the slave drive (hdb) to master and boot from the fresh drive?
I guess this would be too simple ... :?

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main » Wed Jan 18, 2006 4:02 pm

Actually if this is the *exact* same model with the *exact* same drive geometry you should be able to do this. However, if it is not the same you would want to create the partitions on the new drive and then dd the individual file systems from the old drive to the new one (dd if=/dev/hda1 of=/dev/hdb1). Even if they are the same I might suggest doing it this way. I have done this many a time. Just make sure the destination partitions are big enough to hold the file system you are dd'ing.

Ice9
guru
guru
Posts: 577
Joined: Thu Jan 09, 2003 12:40 am
Location: Belgium
Contact:

Post by Ice9 » Thu Jan 19, 2006 1:52 am

Ok, so I would dd every partition separately, but how about the MBR?
And are there other bits than the MBR I have to care about?

I'm planning to launch fdisk and write down the exact partition table to replicate it on the new drive but I don't remember seeing anything about the MBR in there ...

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main » Thu Jan 19, 2006 8:51 am

The only other think you have to do is reinstall GRUB (or LILO) to your boot sector. I usually just do this by physically configuring the new drive in it's final configuration (master/hda), booting from alternate media, mounting the root file system and chroot'ing to it, mount the /boot file system (if you have one) and then "grub-install /dev/hda". You should now be able to reboot and be right where you were on the old drive.

Ice9
guru
guru
Posts: 577
Joined: Thu Jan 09, 2003 12:40 am
Location: Belgium
Contact:

Post by Ice9 » Thu Jan 19, 2006 2:05 pm

booting from alternate media
You mean booting from a live cd? Or booting from a floppy drive?
mounting the root file system and chroot'ing to it
Erm ... chroot?

Edit:
Wouldn't it work if besides copying every partition I also did

Code: Select all

dd if=/dev/hda of=/dev/fd0 bs=512 count=1
and then boot from the floppy and reinstall grub?

Master of Reality
guru
guru
Posts: 562
Joined: Thu Jan 09, 2003 8:25 pm

Post by Master of Reality » Thu Jan 19, 2006 2:26 pm

you would have to do that before dding the filesystems over. You must also be sure its the same drive geometry and such though. I would think that if you did this you wouldnt need to reinstall grub. (This would also make the same partitions as on the first drive)


And alternate media could be a disc or floppy, most install discs will let you boot into a Linux thats already on the drive so that you could reinstall grub from there.

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main » Thu Jan 19, 2006 3:08 pm

I would not copy the entire boot sector from one drive to the other because the partition table is also stored in that area as m0r suggest. The execution addresses on the drive could be different from one to the other to if the geometry and partitions aren't in the exact same location as m0r suggests. You might get away with copying just the first 446 bytes (doesn't include the partition table). However, I would not do any of that and just do a grub-install. For instance in Fedora I would boot the rescue CD and:

# mount /dev/hda2 /mnt/root
# chroot /mnt/root
# mount /boot
# grub-install /dev/hda

This assumes your root file system is on /dev/hda2.

Ice9
guru
guru
Posts: 577
Joined: Thu Jan 09, 2003 12:40 am
Location: Belgium
Contact:

Post by Ice9 » Fri Jan 20, 2006 12:56 am

For instance in Fedora I would boot the rescue CD and
Well, that's something you can do when you install from physical media, but kinda difficult when doing a netinstall :wink:
In fact, I was never prompted to make a boot floppy ... I guess I could try and boot fro the minimal netinstall iso and see what I can do from there.
Or could I mount /root and consequently /boot from another "rescue source"?

Ice9
guru
guru
Posts: 577
Joined: Thu Jan 09, 2003 12:40 am
Location: Belgium
Contact:

Post by Ice9 » Fri Jan 20, 2006 2:30 am

Well, since I had an extra hour before leaving for work I figured it wouldn't hurt to tru and see if the floppy option worked out, if it didn't I could still swap my old drive back in and everything would be back to the way it was ...

So I tried it, ..., and it worked.
I'm now on the exat same system I was before but on a brand new drive.
I swapped the old drive in as slave on /dev/hdb to have extra storage space and voila!
I guess it didn't hurt to have the exact same drives as my hdparm output shows

Code: Select all

Icebox:~# hdparm /dev/hda

/dev/hda:
 multcount    =  0 (off)
 IO_support   =  0 (default 16-bit)
 unmaskirq    =  0 (off)
 using_dma    =  1 (on)
 keepsettings =  0 (off)
 readonly     =  0 (off)
 readahead    = 256 (on)
 geometry     = 65535/16/63, sectors = 156301488, start = 0
Icebox:~# hdparm /dev/hdb

/dev/hdb:
 multcount    =  0 (off)
 IO_support   =  0 (default 16-bit)
 unmaskirq    =  0 (off)
 using_dma    =  1 (on)
 keepsettings =  0 (off)
 readonly     =  0 (off)
 readahead    = 256 (on)
 geometry     = 65535/16/63, sectors = 156301488, start = 0
Both 80GB WD Caviars with 8MB cache.

Anyway, as it turns out the drive wasn't even faulty as far as I can tell now, or I would have reall bad luck and have the same stuff happening on my new drive.
The thing that happens with my pc is that my graphics hang every 10 seconds or so, be it a screensaver, a game or whatever graphical app that should be fluid.
I already swapped graphics several times and even added more memory, from 384 to 512 just to be sure it wasn't that.
So I thought it might be bad performance from the hard drive with periodic disk accesses or something similar (I had that happen to me with Windows years ago) and swapped the drive succesfully, only to see that the problem remains.
Any idea what could cause this - besides the motherboard being faulty?

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main » Fri Jan 20, 2006 8:39 am

Open a couple of windows and have top running in one and iostat/vmstat running in another and see if some process is using resources at that interval. That would be a start.

Ice9
guru
guru
Posts: 577
Joined: Thu Jan 09, 2003 12:40 am
Location: Belgium
Contact:

Post by Ice9 » Fri Jan 20, 2006 3:34 pm

didn't know about iostat/vmstat so I'll try that right away, but I already watched the" processes with top before and nothing really obvious stood out so if I can't find anyting with iostat/vmstat I guess I'll have to live with this until I can afford a new pc :?

Edit:

I just ran glxgears and I can actually see the wheels briefly stopping every two seconds.
Monitored it with top and couldn't see anythin special at that interval :cry:

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main » Fri Jan 20, 2006 4:37 pm

Does it happen exactly at the top of a minute? If so it may be cron job related.

Ice9
guru
guru
Posts: 577
Joined: Thu Jan 09, 2003 12:40 am
Location: Belgium
Contact:

Post by Ice9 » Fri Jan 20, 2006 4:41 pm

I let glxgears run for quite a long time now and the wheels still stop briefly every two seconds.
It's continuous, that's what led me to believe that it was hardware related ...

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main » Fri Jan 20, 2006 5:57 pm

A slow/bad hard drive shouldn't cause a problem with glxgears (at least I wouldn't think it would). Maybe you have some other X app/applet that is causing the pause. Do you have a lot of eye candy running? What window manager are you using?

Ice9
guru
guru
Posts: 577
Joined: Thu Jan 09, 2003 12:40 am
Location: Belgium
Contact:

Post by Ice9 » Sat Jan 21, 2006 2:01 am

I'm running KDE and turned most of the eye candy stuff like bouncing cursors off.
I'm also running superkaramba, but thats fairly recent and I've had this problem for as long as I can remember.
I remember running RH9 on this machine and having to stop playing lbreakout2 because of the freezes every couple of seconds.

Post Reply