Link to home
Start Free TrialLog in
Avatar of sabecs
sabecs

asked on

Cloning Hard Disk - RedHat Linux ES 3.0

Hi,
I would like to clone my existing 80 Gig Hard Drive.
I have a second hard disk of same size and brand with some windows stuff on it that I no longer require.
I have installed the disk as Slave on my primary IDE and Linux picks it up OK.
# ls /proc/ide
drivers  hda  hdb  hdd  ide0  ide1  via

I am assuming my Master disk is hda & Backup disk is hdb.

# fdisk -l /dev/hda
 
Disk /dev/hda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot    Start       End    Blocks   Id  System
/dev/hda1   *         1        13    104391   83  Linux
/dev/hda2            14      9664  77521657+  83  Linux
/dev/hda3          9665      9729    522112+  82  Linux swap

# fdisk -l /dev/hdb
dos not return any output.

How do I go about cloning this disk. I have tried the "dd" command but get an error opening Slave Disk.
# dd if=/dev/hda of=/dev/hdb
dd: opening `/dev/hdb': Input/output error

Do I need to create a new partition and mount the Slave disk first ?

Could you please provide help as I am Linux newbie.

Thanks.



 
Avatar of jlevie
jlevie

Any "cloning" that you do must be done from a single user boot or from a boot from alternate media like a CD if you expect to be able to use the cloned disk. Otherwise files that change during the cloning  will render the clone unusable.

DD will work without any partitioning of the target. Try it from a boot from CD in rescue mode.

You could boot to single user mode.  Create matching partitions on the target with fdisk and make file systems on hdb1 & hdb2 and use 'mkswap /dev/hdb3'. Then:

mkdir /mnt/disk
mount /dev/hdb1 /mnt/disk
cd /mnt/disk
dump 0af - /dev/hda1| restore rf -
rm restoresymtable
cd /
umount /mnt/disk
mount /dev/hdb2 /mnt/disk
cd /mnt/disk
dump 0af - /dev/hda2| restore rf -
rm restoresymtable

There won't be an MBR on the target at that point, but then without edits to grub.conf, device.map, and fstab it won't be usable while it is hdb anyway. If you have to switch to that disk move it to hda, boot from CD in resuce mode and install a bootloader.

And the last choice is to convert the system to a software RAID 1 configuration. The it will always be an exact clone as long as the system is running.  
ASKER CERTIFIED SOLUTION
Avatar of wesly_chen
wesly_chen
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
> dd: opening `/dev/hdb': Input/output error
Please check the first item of my post. It looks like the OS didn't detect the /dev/hdb.

Wesly
Hey guys ! What's this "hdd" ?

There's a  chance that hdb is the cdrom and hdd is indeed your new disk.

Check this with a cat /proc/ide/hdd/media

It should show "disk".

Though Jlevie's method is surely the best and most secure, you could be doing it using dd on a live system if, and only if :

1) You do an init 3 so that you don't have any GUI running

2) You do all this from root on a terminal with no opened files.

3) You don't have any DB daemons running of stuff like that. Only minimal system

3) you do an fsck on your partitions afterwhile.

4) You don't have any cron script running at this time (do not do that around midnight)

There's a chance that some log files currently opened *may* need corrections, but, for a home user's box, the method usually works fine.

Of course, dd'ing one partition after the other is much better than dd'ing the whole disk at once (I'm not even sure that works).
Hi,

I would recommend that you do
dmesg | grep -i sec
or
fdisk -l

to check where your second disk is first.

Wesly
Avatar of sabecs

ASKER

Thanks for the feedback.
I have tried the command "dmesg | grep -i sec" as recommneded above by Wesly . results shown below.

# dmesg | grep -i sec
hda: 156301488 sectors (80026 MB) w/2048KiB Cache, CHS=9729/255/63, UDMA(100)
hdb:end_request: I/O error, dev 03:40 (hdb), sector 0
end_request: I/O error, dev 03:40 (hdb), sector 2
end_request: I/O error, dev 03:40 (hdb), sector 4
end_request: I/O error, dev 03:40 (hdb), sector 6
end_request: I/O error, dev 03:40 (hdb), sector 0
end_request: I/O error, dev 03:40 (hdb), sector 2
end_request: I/O error, dev 03:40 (hdb), sector 4
end_request: I/O error, dev 03:40 (hdb), sector 6
Initializing IPsec netlink socket
kjournald starting.  Commit interval 5 seconds
kjournald starting.  Commit interval 5 seconds
[root@sshost root]#
You know what would be nice ? It would be if requesters actually read the answers we send them....

> Check this with a cat /proc/ide/hdd/media

Have you done this ?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sabecs

ASKER

Thanks Alf666,  Sorry, I have tried your command, output is as follows.
#  cat /proc/ide/hdd/media
cdrom

Thanks jlevie,
I have tried with another new 80 Gig Hard drive and got the same output to the "# dmesg | grep -i sec" commnad.
I will check the jumpering and maybe move it to another IDE.

Hi,

   In addition to "dmesg | grep -i sec", is the second disk dectected by BIOS?

   Also, for some reason, Dell PC prefer to use "cable select" on both disk, disk 1 at the far end and disk 2 in the
middle of IDE cable. So if your PC is not a Dell PC, then check master/slave jumper setting.

   Check the IDE cable or switch IDE cable first, too.

Regards,

Wesly
Avatar of sabecs

ASKER

Thanks for the feedback, I ended up swapping backup drive to 2nd IDE as master and dd command worked perfectly.