Saturday, July 11, 2009

Migrate Ubuntu from one hard drive to another

Recently I faced with need to migrate my KUbuntu from legacy hard drive to modern one.

Firstly I've repartitioned my “modern” drive. By the way, I have Windows installed on it.
Live CD was used (in my case Linux Mint 7) together with gparder tool
Should be run something like
sudo gparted
The same tool allowed me to create partition Ext3 for the new Ubuntu location

Mount just created partition
Mount old partition

mount ext3 [mount point] [device]
f.e.
sudo mount ext3 /media/new /dev/sdb3
sudo mount ext3 /media/old /dev/sda1

Copy everything from old to new.
Try to use rsync tool
f.e.
cd /media/old
rsync -rv ./ /media/new

Turn off computer and plug off old hard drive. It is because there is Grub loader already installed on it. Can make mess in future

Boot from live cd
Check hard drives and partitions
sudo fdisk -l
df

Mount new partition
sudo mount ext3 /media/new /dev/sda3 (After old drive was plugged off my new drive became sda)

Correct /media/new/etc/fstab to point to root / to /dev/sda3. Some other modification may be needed

Make sure there is correct mapping in the /media/new/boot/grub/device.map

Delete Grub menu.lst
sudo rm /media/new/boot/grub/menu.lst

Change root to /media/new
You have to mount the proc subsystem and udev inside /media/new also
sudo mount -t proc none /media/new/proc
sudo mount -o bind /dev /media/new/dev

Changing to new root
sudo chroot /media/new /bin/bash

Need to reinstall Grub
Switch to grub shell
sudo grub

Looking for location of grub
find /boot/grub/stage1

It found mine on (hd0,2)

Setting root to new partiotion
root (hd0,2)

Installing grub for the new hard drive
setup (hd0)
quit

Generate new grub menu list
sudo update-grub

Edit /boot/grub/menu.lst for your needs. It should point to (hd0,2) for Ubuntu
Add Windows menu item

Seems that's all
Now you have your custom Ubuntu running under new hard drive. Cool isn't it!
I can't imagine to do this with Windows.

0 comments: