FreeBSD - Hard Drive Copy (using dd)


2005-04-08

WARNING: back up your data before doing this!

I ran out of space on my hard drive so I bought an 80GB Western Digital Scorpio (WD800VE). I chose Western Digital because they have always been reliable drives for me (although this is one of their first laptop drives so we’ll see. It has a 3-year warranty). The Scorpio model is an 80GB 5400RPM (an upgrade from my current 40GB 4200RPM) with about the same power draw, yet faster than most 5400RPM drives. It is very quiet, you can hear the faint sound with your ear right up next to it.

I also bought an iTank to assist with the transfer. Entirely USB powered but it eats up two of my notebook’s three USB ports. The Blue LED on the iTank is very annoying (whatever happened to the dim-red LEDs?) because of it’s brightness. Perfect for lighting up the room (although the light flickers as it is being accessed).

Anyway, the howto.

Put the drive in the iTank, plug the iTank into the USB ports, and boot into FreeBSD.

dmesg shows that my drive was detected!

# dmesg |grep WD
da0:  Fixed Direct Access SCSI-0 device

so it is on da0

# dmesg |grep da0
da0 at umass-sim0 bus 0 target 0 lun 0
da0:  Fixed Direct Access SCSI-0 device
da0: 1.000MB/s transfers
da0: 76319MB (156301488 512 byte sectors: 255H 63S/T 9729C)

That’s good. Now for the fun.

FreeBSD fdisk seemed to have trouble with the way my BIOS does stuff or the drive’s geometry or sometihng so I installed the linux-fdisk port.

# portinstall linux-fdisk

Note: Since I am going to use dd to copy it is important that the size of the old partition and new partition is EXACTLY the same. My current drive is ad0 so I checked the old drive, like this:

# fdisk-linux ad0

and typed “p” to print the partition table. which showed this:

Disk /dev/ad0: 40.0 GB, 40007761920 bytes
255 heads, 63 sectors/track, 4864 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot    Start       End    Blocks   Id  System
/dev/ad0s1             1      3576  28724188+   c  Win95 FAT32 (LBA)
/dev/ad0s2   *      3577      4850  10233405   a5  FreeBSD
/dev/ad0s3          4852      4852      8032+  1e  Hidden Win95 FAT16 (LBA)
/dev/ad0s4          4855      4864     80325   83  Linux

I am only going to copy over my WindowsXP partition, but the same steps can be used to copy any partition over. Notice the start cylinder is 1 and the end is 3576. These are the values I use later. Anyway, exit the linux-fdisk, and run it again for the new drive.

# fdisk-linux da0
type "p" to print the partition table (delete any existing partitions).
type "n to add a new partition.  then I did 1 for the primary partition.

I just typed the same numbers as above for my start and end cylinders when creating the new partition on the new drive so that the new one would be exactly the same.

I didn’t worry about making it bootable since i am planning to install FreeBSD and Gentoo and I will use one of their bootloaders. But if you did want to make it bootable you would just type a->1 to toggle the boot flag. if you have more partitions to copy over just create them the same way (make sure they are of the same size).

copying the data: My Windows XP partition is on /dev/ad0s1 and the new one I just created is /dev/da0s1. So to copy I just use this:

# dd if=/dev/ad0s1 of=/dev/da0s1

note that if you mix up if and of you will lose all your data so be careful.

this can take a LONG time.

I didn’t need to do this, because I was just going to install FreeBSD, but you can copy over the old MBR from your old drive if you like. this is done by copying the first 512 bytes.

# dd if=/dev/ad0 of=/dev/da0 bs=512 count=1

once agian, if you goof up this you can lose your data or make neither drive bootable.

when it’s done, i just take the new 80GB western digital drive, pop in the FreeBSD cd to install FreeBSD and it loads the bootloader. if all you had on your computer was Windows you could just boot right up off of it.

References: Most of this quick howto would not have been possible without Martin McKeay’s experiences: http://www.mckeay.net/secure/archives/000273.html

Hardware: I bought the WD800VE from ZipZoomFly

And the iTank came from Newegg.com