Friday, May 1, 2009

Install Ubuntu 9.04 on hard disk partition using ISO image without CD

[ Found this Ubuntu page with a "safer" (official) solution. Follow those steps for better guarantees. :) ]

Problem


Your desktop/laptop has a partition where you want to install Ubuntu 9.04. You have downloaded the Ubuntu 9.04 Desktop ISO image which is a LiveCD. But you cannot burn the image on to a CD - either your CD writer is not functioning properly or you do not have a spare CD - or may be you do not want to use a CD to begin with.

Your machine boots using GRUB.

Say you do not want to use a NetBoot approach, and do not want to download/use an Alternate CD ISO image. For various different installation options, check the official Ubuntu pages on installation.

I assume you know how to install Ubuntu to a partition from a LiveCD desktop, but this time, you do not want to burn a CD.


Solution

[ I found this procedure here and followed this procedure for installation on my laptop. Usual Disclaimer : Your mileage may vary. :)]

The ISO image you have downloaded is a LiveCD - a LiveCD can be used to boot up your machine in Ubuntu without an installation, and you can also install it on to the hard disk from the LiveCD desktop.

Step 1 : First you need to decide where you want to store the ISO image and Ubuntu boot-up files, for use by the Ubuntu installation. The important point to remember is that the partition where you store these files should not be the same as the partition where you want to install Ubuntu; since the installation will format the partition where Ubuntu is to be installed. The partition can be a vfat or ext partition.

For instance, let us assume you want to install Ubuntu to a partition called /dev/sda2 (Second Partition if you look at the Hard Disk Layout in a tool such as GParted or Partition Manager). That partition will be formatted during installation.
And say you have a FAT partition (that you use to store and share data between Linux and Windows) /dev/sda7. And you decide to store the ISO image and other Ubuntu boot files for installation, in the file system on /dev/sda7.

Step 2 : Create a directory in the ; lets name it Ubuntu904.
$ mkdir /Ubuntu904

Step 3 : Extract and Store the Ubuntu boot files into Ubuntu904 directory. Say the name of the ISO image file is Ubuntu904.iso.
$ mount -o loop /Ubuntu904.iso /media/cdrom
$ cp /media/cdrom/casper/vmlinuz /Ubuntu904
$ cp /media/cdrom/casper/initrd.gz /Ubuntu904

Step 4 : Copy the ISO image into the Ubuntu904 directory.
$ cp /Ubuntu904.iso /Ubuntu904

So the Ubuntu904 directory now has the ISO image Ubuntu904.iso, the vmlinuz file and the initrd.gz file.

Step 5 : Put an entry into GRUB to boot from the LiveCD ISO image. Note that you might want to have superuser privileges to edit GRUB menu. Edit /boot/grub/menu.lst and add this entry at the end :
title Install Ubuntu 9.04
root (hd0,6)
kernel /vmlinuz boot=casper iso-scan/filename=/Ubuntu904.iso
initrd /initrd.gz


Note the (hd0,6) entry above. This is the partition number where you have stored the Ubuntu boot files and ISO image. You have stored it in /dev/sda7 (7th partition on your only hard drive), which in (hdA,B) notation, would translate to (hd0,6) if the hard disk you are operating on is the only hard drive. This is because hard disk partition numbers in (hdA,B) format start from 0 and not 1.

Once you have added an entry like the above, save the menu.lst file and reboot.

Step 6 : On reboot, you will see the "Install Ubuntu 9.04" entry in the GRUB menu. Selecting that will make the system boot using the Ubuntu ISO image (LiveCD image) and will give you a Ubuntu 9.04 LiveCD Desktop - just as if you would have burned a LiveCD and booted from it.

Step 7 : Once the desktop is up, open a Terminal and unmount the /dev/sda7 partition.
$ umount -l /dev/sda7

Step 8 : Now proceed to click on the "Installer" icon on the desktop and install Ubuntu as you would have from the LiveCD desktop. In the partitioning step, select the Advanced Layout (Manual) option and then you can select the /dev/sda2 partition to put Ubuntu Root (/) on to.