So I had to do this recently and found this thread had useful info spread through it. I put together this "how-to" that might be useful.
The process can be divided into 7 main steps:
1. Physically Install your new drive in the machine
2. partition and format the new drive
3. Move your linux swap
4. Copy the old file system to the new drive
5. Change fstab on the new drive so it mounts the new drive as root
6. install the bootloader on the new drive
7. Change the bios so it boots from the new drive
I will expand on these steps below
1. Physically Install your new drive in the machine
Plug it in.
2. partition and format the new drive
partition and format it using System>Administration>Gparted and/or System>Administration>Disk Utility
You probably want to move the linux swap to your new drive too. So you should use Gparted to create two partitions on your HD.
One large one: with an Ext3 or Ext4 files system on board and with a boot flag set on it (use Gparted . Manage Flags to set the boot flag). The size of this partition can be =[total disk size - swap size (eg 6gig)]
A second partition for the linux swap: This needs to be created inside an extended partition. So create an extended partition using Gparted. And then create a linux swap partition inside this extended partition.
Use GParted to format the paritition to linux-swap.
https://help.ubuntu.com/community/SwapFaq discusses how much swap you might want. I have a about 6gig.
Make sure you can mount your new large partition - Use Disk Utility to test mount it.
While you are in disk utility make note of what device your new drive attaches to the system as and what device your old drive comes in as. The addition of a new drive can change the device labelling.
I note that my old drive is /dev/sda1 and my new partition where I want my new install to be is /dev/sdc2.
My new swap is /dev/sdc5
I did things incrementally. So at this point I want to see if we can successfully move the swap to the new disk.
in a terminal window type:
The results returns info about all the partitions your system can see. The results on my system included
Code:
/dev/sdc5: UUID="0aad67ee-f3cc-45c4-ad55-92da827fde1f" TYPE="swap"
/dev/sda5: UUID="471c8224-aefa-45e0-b711-9debc98cb254" TYPE="swap"
one of these is the existing swap partition - /dev/sda5
and the other one is my new swap on /dev/sdc5
So we need to change the /etc/fstab (file system table) so that we will boot to the new swap.
backup fstab:
Code:
cd /etc
sudo cp fstab fstab_bu
edit fstab:
There will be line in fstab that mounts your existing swap
eg
Code:
UUID=471c8224-aefa-45e0-b711-9debc98cb254 none swap sw 0 0
- note how the UUID of this line matches the UUID for sda5 as returned by blkid
duplicate this line
Comment out one of the duplicates with a hash
edit the other one so the UUID matches the UUID of the new swap partition as returned by blkid
And you end up with:
Code:
#UUID=471c8224-aefa-45e0-b711-9debc98cb254 none swap sw 0 0
UUID=0aad67ee-f3cc-45c4-ad55-92da827fde1f none swap sw 0 0
Save the modified fstab
Now Reboot.
After the system comes back in a terminal do
and it should return something like
Code:
Filename Type Size Used Priority
/dev/sdc5 partition 6209080 0 -1
Which tells me that my swap is on /dev/sdc5 - my new partition.
So we have successfully moved our swap to our new drive.
4. Copy the old file system to the new drive
Now we move the main boot partition.
use sudo blkid to get the UUID of the new drive
eg
Code:
/dev/sda1: UUID="a45017f8-cff6-4bee-8369-f8b288ea0ca9" SEC_TYPE="ext2" TYPE="ext3" <- current drive
/dev/sdc2: UUID="30c4ac3a-5da9-4e68-ba6e-6d9f30c23117" SEC_TYPE="ext2" TYPE="ext3" <- new drive
Also check how your grub is setup
run grub:
at the grub> prompt
Code:
grub> find /boot/grub/stage1
Mine returns:
(hd0,0)
This means we are booting from /dev/sda1 (hd0 = a and ,0 means partition 0 which is the 1 in the sda1.)
quit grub with the quit command.
Now we want to copy all the files from the old to the new drive and we want to do this while none of the files are in use.
So we need to boot to a live CD of Ubuntu.
after the live CD of Ubuntu starts open a terminal
pwd
returns "/home/ubuntu/"
make a directory for mounting the new disk
mount the new disk. mine has a ext3 file system and the new disk is /dev/sdc2 - yours might be different
Code:
sudo mount -t ext3 /dev/sdc2 newdisk
mount the old (existing) disk at the /mnt directory. my old disk is /dev/sda1 - yours might be different.
Code:
sudo mount -t ext3 /dev/sda1 /mnt
Now we can see our old disk at /mnt and our new disk at /home/ubuntu/newdisk
Now we need to copy the files from our old to our new disk. Various posts to this thread offer up various copy commands that can be used
sudo cp -axuv /mnt/* /home/ubuntu/newdisk
or
sudo cp -a /mnt/* /home/ubuntu/newdisk
or
sudo cp -vax /mnt/* /home/ubuntu/newdisk
or
sudo cp -av /mnt/* /home/ubuntu/newdisk
or
sudo cp -rpf /mnt/* /home/ubuntu/newdisk
you can decide what is the best copy command. I used the first one -axuv
There is not much difference between these commands
one critical thing is the -a switch which makes it do recursive copy of directories, preserving the file mode ownership and timestamps and not following the symbolic links in the source.
I chose the one with x in it because I did not want to copy my /home folder that actually lives on a different file system. But leave the x out if you would like to merge partitions from the source
man page on cp tells me
-v, --verbose explain what is being done
-a = --archive same as -dpR
-d same as --no-dereference –preserve=links
--no-dereference never follow symbolic links in SOURCE
-v, --verbose explain what is being done
-x, stay on this file system
--preserve[=ATTR_LIST]
preserve the specified attributes (default: mode,owner‐
ship,timestamps), if possible additional attributes: context,
links, all
-p same as –preserve=mode,ownership,timestamps
-u, --update copy only when the SOURCE file is newer than the destination
file or when the destination file is missing
-R, -r, --recursive copy directories recursively
-f, --force if an existing destination file cannot be opened, remove it and try again
Various posts mention that you do not want to copy /tmp , /dev
/proc and /sys but create directorys for them. The trouble with creating directories for these by hand is getting the directory permissions correct. So what I did was copy these directories too but then I deleted the files from them on the /home/ubuntu/newdisk
delete files from /home/ubuntu/newdisk/tmp and /home/ubuntu/newdisk/dev
Running nautilus as root can be handy for this:
I found that /proc and /sys did not have any files
5. Change fstab on the new drive so it mounts the new drive as root
Now we want to modify the /etc/fstab that will be the fstab when our new drive boots up. we want to tell it which
disk to mount as root
Code:
gksudo /home/ubuntu/newdisk/etc/fstab
This fstab file will be copy of your old one. Find the line in it that mounts root (look for the / )
mine is
Code:
UUID=a45017f8-cff6-4bee-8369-f8b288ea0ca9 / ext3 relatime,errors=remount-ro 0 1
which is the UUID of /dev/sda1 identified previously by blkid
Duplicate this line. Comment one of them out and edit the other one pasting in the UUID of the new drive
Thus:
Code:
#UUID=a45017f8-cff6-4bee-8369-f8b288ea0ca9 / ext3 relatime,errors=remount-ro 0 1
UUID=30c4ac3a-5da9-4e68-ba6e-6d9f30c23117 / ext3 relatime,errors=remount-ro 0 1
6. install the bootloader on the new drive
Now we need to setup the bootloader on the new drive to boot from the correct partition.
modify the menu.lst on the new drive in /boot/grub by putting the above UUID in place as described below.
Backup the old menu.lst to /boot/grub/menu_bu1.lst
Code:
sudo cp /home/ubuntu/newdisk/boot/grub/menu.lst /home/ubuntu/newdisk/boot/grub/menu_bu.lst
edit the menu.lst
Code:
gksudo gedit /home/ubuntu/newdisk/boot/grub/menu.lst
towards the end of the menu.lst file you see "## ## End Default Options ##"
and after this is a list of kernals you can currently boot to. If the start of the file says default 0 then the first item in the list is the kernal that will boot by default.
We need to make this the kernal that lives on the new drive. So I copy the first two titles and change the titles on them to something appropriate - eg add new drive to the title.
And you replace the UUID on the kernal line and the UUID on the uuid line with the UUID of the new drive as returned by blkid above
eg:
Code:
title Ubuntu 10.04.1 LTS, kernel 2.6.32-23-generic - new drive
uuid 30c4ac3a-5da9-4e68-ba6e-6d9f30c23117
kernel /boot/vmlinuz-2.6.32-23-generic root=UUID=UUID=30c4ac3a-5da9-4e68-ba6e-6d9f30c23117 ro quiet splash
initrd /boot/initrd.img-2.6.32-23-generic
quiet
title Ubuntu 10.04.1 LTS, kernel 2.6.32-23-generic (recovery mode) new drive
uuid 30c4ac3a-5da9-4e68-ba6e-6d9f30c23117
kernel /boot/vmlinuz-2.6.32-23-generic root=UUID=UUID=30c4ac3a-5da9-4e68-ba6e-6d9f30c23117 ro single
initrd /boot/initrd.img-2.6.32-23-generic
We also need to run grub to set up the master boot record correctly on the new drive.
so...
Code:
cd /home/ubuntu/newdisk/boot/grub/
sudo grub
at the grub prompt
Code:
grub> find /boot/grub/stage1
Mine returned
(hd0,0)
(hd2,1)
What I think this means is that there are now two options where you could boot from hd0,0 and hd2,1. hd0,0 was what grub reported before and is /dev/sda1
hd2,1 is the new drive
hd2 = disk c (a=0,b=1,c=2).
The ,1 is partition 2
so hd2,1 = /dev/sdc2 = our new disk
So we want to set up hd2 to boot from - so at the grub prompt type
It reports something like
Code:
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 (hd2)"... 20 sectors are embedded.
succeeded
Running "install /boot/grub/stage1 (hd2) (hd2)1+20 p (hd2,1)/boot/grub/stage2
/boot/grub/menu.lst"... succeeded
Done.
quit grub.
7. Change the bios so it boots from the new drive
We are almost done now. There are two bootable disks on the system now. And it is now up to the computers bios as to which one will boot the PC. So we need to shut down the live CD and remove the disk and restart the PC.
If you just let the PC boot it should boot fine from your old drive which you have not changed. - This is a back-out strategy.
However, if you boot and then hit the del key (or whatever it is that you do to enter your computers bios set up) you can then change what disk the PC boots from first. You need to select the new disk as the first boot disk.
If you do this then it should boot up off your new drive.
You can check after you log in by using the disk utility to check if your new drive is mounted at root (/)
If you fail to boot to the new drive then use the bios settings to put the old one back.
and ... post to this thread maybe.