If you have enough free space on a second hard disk, you can use GParted (part of every Ubuntu live CD) to copy & paste your Ubuntu partition:
- Open GParted from a live CD session: System > Administration > Partition Editor
- In the top right corner select your internal hard disk.
- Select the partition you want to copy (right-click > "Copy"):
- In the top right corner select your external/backup hard disk.
- Paste the copied partition into unallocated space (right-click > "Paste"):
- Click on "Apply" and wait while GParted copies the partition.
After you successfully copied your Ubuntu partition to the backup hard disk, you can use GParted to delete all the other partitions on your internal hard disk (just select them, right-click > "Delete" > "Apply").
To restore you backup, repeat the steps in the other direction (backup disk -> internal hard disk). When this is done, you can resize the partition (select, right-click > "Resize/Move" > "Apply") and finally create a new Swap partition (see this question to determine the right size for that partition).
After that you should be able to boot Ubuntu, but it will probably complain, because it cannot find the old Swap partition. You can easily fix this by updating the two files where your old Swap partition is referenced to:
- Find the new UUID (Universally Unique Identifier):
- In a terminal run:
sudo blkid | grep swap
- That's it - that long number is the UUID.
- Replace the UUID in
- Open those files from a terminal:
gksudo gedit /etc/fstab /etc/initramfs-tools/conf.d/resume
- Now update the UUID in
/etc/fstab where it says "swap" and replace the UUID in
/etc/initramfs-tools/conf.d/resume. Save both and quit.
- Finally run
sudo update-initramfs -c -k all
Done. Wasn't that easy?