Saturday, April 24, 2010

How to install linux from hard disk (save your cd's & dvd's)

A couple of months ago,while i was looking for a shift from mandriva to backtrack my laptops cdrom went down. So i googled for "installing linux from iso image without burning cd" etc etc...
But a lot of those articles were missing the exact how to or shall i say the proper procedure and explanation.
After tinkering for a while i got the installation working on my system. Here's a how to on how i did the same.

My environment :
Host = mandriva 2010 ,
Iso image = backtrack.iso ,
Only single hard disk on my system.

Partition table :

Filesystem Size Used Avail Use% Mounted on
/dev/sda1 20G 20G 670M 97% /
/dev/sda5 79G 79G 479M 100% /home

Herein my i have 2 seperate partitions for root and home.
But for installing another distro I need to have another partiotion. So im going to make another partition using cfdisk utilty (you can also use graphical qtparted)of 10 Gb, type = ext3 (you can choose ext4,xfx etc). After that my partition table read :

Filesystem Size Used Avail Use% Mounted on
/dev/sda1 20G 20G 670M 97% /
/dev/sda5 79G 79G 479M 100% /home
/dev/sda6 9.6G 100M 9.5G 1% /mnt/backtrack

First of all u need to copy or move the iso image to your host linux.
Suppose your iso image is in /home. Then proceed as following
Move the iso image to root partiotion

$] sudo mv backtrack.iso /
Now i will mount this iso image to a mount point (/mnt/iso)
$] sudo mkdir /mnt/iso
$] sudo mount -o loop /backtrack.iso /mnt/iso

Why we mounted the image is so that we can copy the initrd.gz(initial ram disk) and vmlinuz(statically linked executable file which contains the Linux kernel). Now that the image is mounted at /mnt/iso, so we will copy the desired files to root (i.e. / ) partition.

$] sudo cp /mnt/iso/boot/vmlinuz /
$] sudo cp /mnt/iso/boot/initrd.gz /

**NOTE: For ubuntu based systems you can substitute the "boot" with "casper" in above commands
**NOTE : Since backtrack is based on slackware so vmlinuz and initrd.gz are located inside boot directory of the iso image, for other distributions you can find them as : -

$] cd /mnt/iso
$] find . -name vmlinuz
$] find . -name initrd*

Now we will edit our /boot/grub/menu.lst and insert an entry for location of initrd.gz, vmlinuz and iso image.

If you have followed this tuturial throughout,then you need to edit /boot/grub/menu.lst as follows : -

Make a backup of original menu.lst before making any changes to it
$] sudo cp /boot/grub/menu.lst /boot/grub/menu.lst.orig
$] sudo vi /boot/grub/menu.lst
Now add the following entry (after the last entry already present in menu.lst)

title install bt4
root (hd0,0)
kernel (hd0,0)/vmlinuz ramdisk_size=9999 root=/dev/ram0 rw rootdelay=20 nocd iso-scan/filename=(hd0,0)/bt4-beta.iso
initrd (hd0,0)/initrd.gz

**NOTE :
  • You can write anything after title,coz whatever you write after title is what gets displayed at grub boot prompt when you reboot your system.
  • If your iso image,vmlinuz and initrd.gz are at other location, for instance /home, then replace "(hd0,0)/vmlinuz" with "(hd0,0)/home/vmlinuz" & "(hd0,0)/initrd.gz" with "(hd0,0)/initrd.gz"

Thats it !!!!! We are done . Now reboot your system and select the title and you are ready to rock...
In case you faced any problems leave your comments & I assure of a promt reply.