Quote:
Originally Posted by hisnumber666
speaking of dd... i havent had much success copying partitions from one device to the other directly... i have been trying to move my current linux installation to another hard drive, but every time something goes wrong. i got crc errors, dd runs out of space on target partition (even though the actual block size was the same)
|
I will bet that you tried, for instance, dd if=/dev/hda1 of=somethingorother...
Well guess what. That doesn't work. But, then, you knew that, didn't you?
When you do that you aren't picking up the actual ends of the partition.
To actually get an image of the partition, what you do is first run fdisk -l /dev/hda.
Take this result and compute the exact location of the partition on the disk, then use those values in dd.
For example, on my linux system, the system partition is located on /dev/sdc2. So, fdisk gives me this:
Code:
Disk /dev/sdc: 18.3 GB, 18351959040 bytes
255 heads, 63 sectors/track, 2231 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdc1 * 1 261 2096451 7 HPFS/NTFS
/dev/sdc2 262 1495 9912073+ 83 Linux
/dev/sdc3 1496 2231 5911920 f W95 Ext'd (LBA)
/dev/sdc5 1496 1750 2048256 7 HPFS/NTFS
/dev/sdc6 1751 2005 2048256 7 HPFS/NTFS
/dev/sdc7 2006 2231 1815313+ 6 FAT16
This output specifies the # heads, the # of sectors/track, and the number of cylinders on the drive. For each partition, fdisk lists the starting cylinder and the ending cylinder, and the size in sectors; by default the formatting tools will use cylinder boundaries. Linux uses sectors that are 1024 bytes, which is 2 - 512 byte blocks. dd wants the starting sector and the size of the partition, in appropriate units. Default size for dd is blocks of 512 bytes.
To get the starting sector of the partition, take the end cylinder of the previous partition. Multiply that number by the number of sectors/track, then by the number of heads. This gives the first sector of the last track of the previous partition. Now add in the number of sectors/track to this number and the result is the first sector of the first track of the first cylinder of the next partition.
To get the size of the partition, subtract the beginning cylinder from the end cylinder and add one (to get the cylinder count). Then multiply this number by the sectors/track and the # heads. Then subtract the sectors/track from the result to get the total sectors in the partition.
The size of the partition may also be determined in sectors by taking the size listed by fdisk (in "blocks"), multiplying it by 2, and adding 1. I often compute it both ways just to make sure there is no mistake.
So, for my particular case where I want to use dd to image my system partition, I establish that the starting sector of the partition is 4193028 and the length of the partition in sectors is 19824147.
Thus, the dd command to do this partition is:
dd if=/dev/sdc of=/mnt/sdb1/sysimage bs=512 skip=4193028 count=19824147
Works perfectly. This is how I routinely backup. makes restoration easy; the restore is:
dd if=/mnt/sdb1/sysimage of=/dev/sdc bs=512 seek=4193028 count=19824147
Oh, by the way. The astute reader will note that most of this disk is formatted for Windows.
Well, the system has 4 hard drives in it and they are all a mishmash of windows and linux, except sdb which is all Linux. The system can dual-boot but I haven't booted Windows NT for years. Instead, I run VMware and routinely have Windows 2000 up and running in Linux.