Cloning a hard disc
From NewbieDOC
- Chris Lale
- chrislale AT users DOT berlios DOT de
Go to NewbieDOC index
Revision History
Version 1.0 | 6th July 2005 | Revised by Chris Lale | ||||||||||
Initial release | ||||||||||||
| ||||||||||||
Version 1.1 | 7th February 2006 | Revised by Chris Lale | ||||||||||
Modified for NewbieDOC wiki by converting source to wikitext. Added a note about ddrescue. | ||||||||||||
| ||||||||||||
Version 1.2 | 15th November 2007 | Revised by Chris Lale | ||||||||||
Moved the section about compiling Pcopy to an appendix now that there is a Debian "pcopy" package in Etch. | ||||||||||||
| ||||||||||||
Version 1.3 | 26th November 2007 | Revised by Chris Lale | ||||||||||
Reformatted for newbiedoc package; Moved section on documentation of self-compiled version of Pcopy to Appendix B. | ||||||||||||
This HOWTO article explains how to make a clone of a hard disc. If the original hard disc is a failing disc, it must still be working and readable. The new disc must be at least as the same capacity as the original disc. These instructions have been tested on a Debian 3.1 (Sarge) system with IDE (ATA) hard discs.
1 IntroductionIf you are unlucky, your hard disc begins to fail after a few years. If you are lucky, it gives you warning that it is on the way out. The drive produces clunking noises when it spins up, or 1.1 Assumed hardware setupFor IDE (ATA) discs, this article assumes that the original IDE hard disc is the primary disc with the jumper set to master ( For SCSI discs and SATA discs the device names would be 2 Installing the Debian packagesInstall these packages.
3 Installing Pcopy
Note: It may be possible to use ddrescue instead of pcopy As user root: # aptitude install pcopy 4 Preparing to clone the discBefore you go any further you would be wise to take these precautions.
# dd if=/dev/hda of=/media/floppy/mbr.backup bs=512 count=1
# fsck -Cvf /dev/hda1
# fdisk -l /dev/hda | lpr
# /etc/init.d/networking stop
# /sbin/telinit 1 5 Copying the partition tableThe new disc must be large enough to accept all the partitions. If the new disc is larger than the old one you will be all right. Use $ su Password: # sfdisk -d /dev/hda | sfdisk /dev/hdb Checking that no-one is using this disk right now ... OK Disk /dev/hdb: 19457 cylinders, 255 heads, 63 sectors/track Old situation: Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0 Device Boot Start End #cyls #blocks Id System /dev/hdb1 0 - 0 0 0 Empty /dev/hdb2 0 - 0 0 0 Empty /dev/hdb3 0 - 0 0 0 Empty /dev/hdb4 0 - 0 0 0 Empty New situation: Units = sectors of 512 bytes, counting from 0 Device Boot Start End #sectors Id System /dev/hdb1 * 63 4176899 4176837 6 FAT16 /dev/hdb2 4369680 116262404 111892725 f W95 Ext'd (LBA) /dev/hdb3 4176900 4369679 192780 16 Hidden FAT16 /dev/hdb4 0 - 0 0 Empty /dev/hdb5 4369743 8594774 4225032 7 HPFS/NTFS /dev/hdb6 8594838 9655064 1060227 82 Linux swap /dev/hdb7 9655128 10281599 626472 83 Linux /dev/hdb8 10281663 18683594 8401932 83 Linux /dev/hdb9 18683658 28933064 10249407 83 Linux /dev/hdb10 28933128 35085959 6152832 83 Linux /dev/hdb11 35086023 36114119 1028097 83 Linux /dev/hdb12 36114183 37961594 1847412 6 FAT16 /dev/hdb13 37961658 82734749 44773092 83 Linux /dev/hdb14 82734813 86638544 3903732 83 Linux /dev/hdb15 86638608 87618509 979902 82 Linux swap /dev/hdb16 87618573 91843604 4225032 7 HPFS/NTFS /dev/hdb17 91843668 99747584 7903917 83 Linux /dev/hdb18 99747648 103972679 4225032 7 HPFS/NTFS /dev/hdb19 103972743 110495069 6522327 b W95 FAT32 /dev/hdb20 110495133 112744169 2249037 83 Linux /dev/hdb21 112744233 116262404 3518172 83 Linux Successfully wrote the new partition table Re-reading the partition table ... If you created or changed a DOS partition, # dd if=/dev/zero of=/dev/foo7 bs=512 count=1 (See 6 Copying the partitionsCopy the contents of each of the partitions from the old disc to the new disc using # pcopy -d /dev/hda3 /dev/hdb3 Copying from /dev/hda3 to /dev/hdb3 (start in 3 seconds)... ............................................................................................... /dev/hda3: Done. Copied 94 MB in 5 seconds (18 MB/s) # Repeat the copy process for each partition. 7 Testing the new discShut down the system. # shutdown now -P Unplug the computer from mains power. Remove the old disk. Remove the new disk and reposition the jumper to set it to master. Replace it using the cable connections of the old disc. Reconnect mains power, switch on and watch the computer boot. Everything should work identically to the original system. 8 Appendix A: Installing Pcopy from sourceThis is how you can compile Pcopy if your distribution does not have a debian "pcopy" package. 8.1 Downloading PcopyDownload the Pcopy source from ftp://ftp.lysator.liu.se/pub/unix/pcopy. If this link is broken, search for 8.2 Extracting the source filesOpen a terminal or a terminal window as a normal user. Move to the directory where you saved the tarball. For example, if you downloaded the Pcopy archive to $ cd /home/chris/download/pcopy/ Extract the source files. $ tar -xzvf pcopy-1.5.tar.gz This creates a new subdirectory, 8.3 Configuring the source code for your systemMove to the source directory and run the configure script. $ cd pcopy-1.5 $ ./configure loading cache ./config.cache checking for gcc... (cached) gcc checking whether the C compiler (gcc ) works... yes checking whether the C compiler (gcc ) is a cross-compiler... no checking whether we are using GNU C... (cached) yes checking whether gcc accepts -g... (cached) yes checking for a BSD compatible install... (cached) /usr/bin/install -c checking whether make sets ${MAKE}... (cached) yes checking size of long... (cached) 4 checking for lseek64... (cached) yes checking for llseek... (cached) yes checking for thr_create in -lthread... (cached) no checking for pthread_attr_init in -lpthread... (cached) yes creating ./config.status creating Makefile creating config.h $ 8.4 Compiling the source filesRun Make to select and compile the appropriate files. $make gcc -g -O2 -c -o pcopy.o pcopy.c gcc -o pcopy pcopy.o -lpthread $ 8.5 Installing the binary fileYou must become user root to do install $ su Password: # make install /usr/bin/install -c -m 755 pcopy /usr/local/bin/ athlon:/home/chris/download/pcopy/pcopy-1.5 # exit $ 8.6 Documentation8.6.1 Pcopy detailshttp://directory.fsf.org/sysadmin/Backup/pcopy.html 8.6.2 Manual pagesMan pages are available after you have installed the Debian packages.
$ pcopy -h
9 Appendix B: LicenceCopyright (c) 2005-2007 Chris Lale. chrislale AT users DOT berlios DOT de.
Go to NewbieDOC index |