I just moved my IDE boot drive to a SATA drive, so I thought I'd detail the process in case anyone else is interested. This howto uses the simple case of one root partition and one swap partition.
Partitioning the new drive:
First, decide on the amount of swap space you'll need. Subtract that from
the size of the drive and creat the first partition with that size. I'm
using an 80GB drive, and I want about 1GB swap space, so my first partition
will be a 79GB primary Linux partition.
Code:
n: new partition
p: primary partition
1: partition number 1
1: First cylinder
+79G: Last cylinder or +size (etc)
Now, create the swap partition. First is the extended partition where it resides.
Code:
n: new partition
e: extended partition
2: partition number
<enter>: first cylinder (default)
<enter>: last cylinder (default)
Next is the actual swap partition.
Code:
n: new partition
l: logical partition
<enter>: first cylinder (defaults to first cyl of extended partition)
<enter>: last cylinder (default)
Change the type of the partition created for swap to "Linux swap" type.
Code:
t: change type of partition
5: partition number
hex code: 82 (Linux swap)
List the partition for a look before writing it.
Code:
p:
Disk /dev/sda: 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/sda1 1 9606 77160163+ 83 Linux
/dev/sda2 9607 9729 987997+ 5 Extended
/dev/sda5 9607 9729 987966 82 Linux swap / Solaris
It's what I want, so write it and exit fdisk.
Copy the MBR from your booted IDE drive to the new SATA drive
Code:
# dd if=/dev/hda of=/dev/sda bs=446 count=1
WARNING: be VERY sure you get the if and of right!!!
Copy the "/" partition to the new drive:
Mount the new root partition
Code:
# mount /dev/sda1 /mnt
Copy the data
Stop udev so that the "/dev" directory can be copied
Code:
# /etc/init.d/udev stop
Copy the /dev partition
Code:
# cp -axu /dev /mnt
Restart udev
Code:
# /etc/init.d/udev start
Make a swap partition out of /dev/sda5
Chroot into /mnt to make double damned sure you don't wack your root for this. Be ABSOLUTELY SURE that you run this command before proceeding!!!
Change the mount table (/etc/fstab) for the new drive to these values:
Code:
proc /proc proc defaults 0 0
/dev/sda1 / ext3 defaults,errors=remount-ro 0 1
/dev/sda5 none swap sw 0 0
Change /boot/grub/device.map to these values:
Code:
(hd0) /dev/sda
(hd1) /dev/sdb
Change the appropriate root sections of the menu.lst file:
Code:
### BEGIN AUTOMAGIC KERNELS LIST
...
# kopt=root=/dev/sda1 ro
title Debian GNU/Linux, kernel 2.6.19.5-k7
root (hd0,0)
kernel /boot/vmlinuz-2.6.19.5-k7 root=/dev/sda1 ro
initrd /boot/initrd.img-2.6.19.5-k7
savedefault
### END DEBIAN AUTOMAGIC KERNELS LIST
NOTE: change all the /dev/hda1 to /dev/sda1 in the AUTOMAGIC KERNELS LIST
NOTE: leave the hash ("#") in front of "kopt=root=/dev/sda1 ro"
Run grub to fixup a few things. I'm not an expert on this, but it's required or the thing won't boot.
Code:
grub> device (hd0) /dev/sda
NOTE: If this responded with an error, check to see that the /dev directory
really was copied, above.
Code:
grub> setup (hd0)
Checking if "/boot/grub/stage1" exists... yes
Checking if "/boot/grub/stage2" exists... yes
Checking if "/boot/grub/e2fs_stage1_5" exists... yes
Running "embed /boot/grub/e2fs_stage1_5 (hd0)"... 16 sectors are embedded.
succeeded
Running "install /boot/grub/stage1 (hd0) (hd0)1+16 p (hd0,0)/boot/grub/stage2
/boot/grub/menu.lst"... succeeded
Done.
Tell grub to do its thing to make it bootable.
Code:
# update-grub
Searching for GRUB installation directory ... found: /boot/grub
Searching for default file ... found: /boot/grub/default
Testing for an existing GRUB menu.lst file ... found: /boot/grub/menu.lst
Searching for splash image ... none found, skipping ...
Found kernel: /boot/vmlinuz-2.6.19.5-k7
Found kernel: /boot/vmlinuz-2.6.19.4-k7
Found kernel: /boot/vmlinuz-2.6.19.3-k7
Found kernel: /boot/vmlinuz-2.6.19.2-k7
Found kernel: /boot/vmlinuz-2.6.18-386
Found kernel: /boot/vmlinuz-2.6.18-4-k7
Found kernel: /boot/vmlinuz-2.6.18-3-k7
Updating /boot/grub/menu.lst ... done
And, it's time for the moment of truth! Reboot the sytem, and change the BIOS so that it boots from your SATA drive. Don't be surprised if a full fsck is run on /dev/sda1 during boot. Also, don't be surprised that a big red "failed" is displayed just before the sytem reboots after the fsck. That's normal.
And, the system should reboot onto the SATA drive. At least, mine did.