Home > file systems, howto > Swap Hard Drives with Ubuntu 6.10

Swap Hard Drives with Ubuntu 6.10

January 16th, 2007 Leave a comment Go to comments

I recently upgrade my main workstation’s hard drive under Ubuntu 6.10 and noticed a couple things changed during the process. Here are my instructions for a fast and reliably hard drive swap. I’m using SATA drives without LVM using the default Ubuntu install and partition options for this howto.

  1. Prepare
    1. Shutdown your machine and install your new hard drive. Don’t mess with your current hard drive (yet)
    2. Find a LiveCD, I used the Ubuntu 6.10 LiveCD, it matched my OS, but it doesn’t have to. Knoppix should work fine.
    3. Boot using your LiveCD
    4. After booting, open a terminal and “sudo su” to become root
  2. Setup your new drive
    1. Use cfdisk /dev/sda to look at your partitions on your current drive. I have sda1 of type linux as most of my current drive, and a 6 GB sda5 as linux swap at the end
    2. Duplicate this on your new drive using cfdisk /dev/sdb, adjusting for space as necessary. I created a new primary partition using cfdisk using all but 6 GB of space, then a new logical partition using the rest of the space. You must create the partitions in this order to get the right numbering
    3. make the primary partition to bootable
    4. set the swap partition as type 82 (linux swap)
    5. save and quit
    6. create filesystems on the new partitions using mkfs.ext3 /dev/sdb1 and mkswap /dev/sdb5
  3. Copy data
    1. Make directories to mount your old and new partitions, in this case, /mnt/sda1 and /mnt/sdb1
    2. Mount your drives to these partitions using mount /dev/sda1 /mnt/sda1 and mount /dev/sdb1 /mnt/sdb1
    3. Copy all your data from your old drive to your new drive using cp -a /mnt/sda1/* /mnt/sdb1/ . The -a will preserve owners, permissions, date, etc.
    4. Get up and do something else. It took 70 minutes for my machine to copy about 150 GB of data from one drive to the other
  4. Fix the boot options
    1. This is where Ubuntu 6.10 differs from previous versions. Fstab and menu.lst both use UUID numbers to find partitions. To get the UUID number of your new partitions, run vol_id /dev/sdb1 and vol_id /dev/sdb5 . Copy these numbers into their appropriate places in your /mnt/sdb1/etc/fstab and /mnt/sdb1/boot/grub/menu.lst files. You may need to dig around the menu.lst to find all the entries.
    2. Now install grub onto the MBR of the new drive to make it bootable. To do this I first chroot into my new system using chroot /mnt/sdb1 /bin/bash . Now that you’re in the new system, run grub. Inside grub, run setup (hd1,0) then root (hd1) . This will differ if you have a different drive setup. Quit grub (quit).
  5. Finish up
    1. Logout of your chroot (logout), unmount your mounted drives umount /dev/sda1 and umount /dev/sdb1, and shutdown your computer. Disconnect your old drive, plug your new drive into the old drive’s cable, and start your computer back up. If everything went well, it will boot back up as if nothing happened.
Categories: file systems, howto
  1. No comments yet.
  1. No trackbacks yet.