Boot Linux directly from iso img file in GRUB 2
Boot Linux directly from iso img file in GRUB 2
I have the habbit of trying out new versions of linux and that used to cause the trouble of burning CD or DVD or making the usb bootable but one day, while searching the web I got this idea of trying or installing ubuntu directly from the image ( .iso )file.here is the brief description given,as i did with ubuntu but will work with most of the flavors of linux.
1. Download the .iso file of your favorite os from corresponding sites.if you already have then skip the step.
for downloading ubuntu click this link.
for downloading fedora click here.
for other search the web.... :-D
2. Copy .iso file to the root of your disk or inside the folder at the root of disk.
/ is root or /your_folder/
su cp <iso file name> / Example: $su cp ubuntu-12.04-desktop-i386.iso /
su cp <iso file name> /<your folder name> Example: $su cp ubuntu-12.04-desktop-i386.iso /live
3. Now extract the kernel image and initrd file from the iso using some utility either graphical or via command line.(do this step before copying the iso image to the / partition otherwise you will have to give the root permission and graphical tools wont work due to lack of permission)
Path to the kernel and initrd image in different flavors:
Flavor Kernel initrd img
| Fedora | /isolinux/vmlinuz | /isolinux/initrd.img |
| RHEL5/CentOS5 | /isolinux/vmlinuz | /isolinux/initrd.img |
| openSUSE | /boot/i386/loader/linux | /boot/i386/loader/initrd |
| Mandriva | /i586/isolinux/alt0/vmlinuz | /i586/isolinux/alt0/all.rdz |
| Ubuntu | /casper/vmlinuz | /casper/initrd.gz |
| Debian | /install.386/vmlinuz | /isolinux/initrd.img |
commands to extract the files from iso:
# mount -o loop /home/ubuntu12.10.iso /media/iso
# cd /media/iso/casper
# cp vmlinuz initrd.gz /new/here /new is folder where is i have kept the iso and kernel and initrd image,
or do it graphically.
or do it graphically.
4. open the terminal and become the root and type in -:
#vi /etc/grub.d/40_custom
and paste the following lines into that file
menuentry ISO Ubuntu 12.10
{
isofile=ubuntu-12.10-desktop-i386.iso
loopback loop (sd0,2)/new/$isofile
linux (loop) /new/vmlinuz boot=casper iso-scan/filename=/new/$isofile noprompt noeject
initrd (loop) /new/initrd.lz
}
now real task comes in to picture that is customizing above code as per your machine.
first line is menuentry is keyword remains same and ISO file name it could be whatever you want.
second line after the braces either give the file name with full path or just give the file name and later specify the path everytime as I did.
third line loopback loop goes same and (sd0,2) this is the path of /boot partition. sda (which is nothing but our systems primary hard disk) is written as sd0 in GRUB2 and 2 is the second partion of sda (primary hard disk) so in short my /boot is second partition of my primary hard disk.sd0 will remain same in all new systems since all use SCSI HDD and only your partition number will change so find out that.
NOTE: if your system use IDE HDD then use hd0 instead of sd0 and partition number starts with 0 partition 1 will be treated as 0 and partition 2 as 1 etc.

for check your systems /boot partition open terminal and typein
lsblk
it gives /boot to be mounted on sda2
a in sda is replaced with 0 and 2 is the partition number thus address becomes (sd0,2)
or
sudo fdisk -l
now mount each partition one by one and check which matches with /boot partition and translate the path by above given rule and replace (sd0,2) with your path.and change the new to your folder name.
NOTE: if you havent created a separate /boot partition during installing linux then your /boot address will be same as of / (root) partition.
Only for GEEKS -: for lengthy and more descriptive tutorial about grub and grub2 click here and here
fourth line goes same Except change the name of vmlinuz as per your linux flavor and new to your folder name.
fifth is also same except change the initrd image name as per your linux flavor.
5. Update the grub
ubuntu user just type in terminal : sudo update-grub
fedora user just type in terminal: sudo grub2-mkconfig -o /boot/grub2/grub.cfg
And you are all set now reboot the system and see the mazik. 8-). and do let me know if you face any problem implementing it
#vi /etc/grub.d/40_custom
and paste the following lines into that file
menuentry ISO Ubuntu 12.10
{
isofile=ubuntu-12.10-desktop-i386.iso
loopback loop (sd0,2)/new/$isofile
linux (loop) /new/vmlinuz boot=casper iso-scan/filename=/new/$isofile noprompt noeject
initrd (loop) /new/initrd.lz
}
now real task comes in to picture that is customizing above code as per your machine.
first line is menuentry is keyword remains same and ISO file name it could be whatever you want.
second line after the braces either give the file name with full path or just give the file name and later specify the path everytime as I did.
third line loopback loop goes same and (sd0,2) this is the path of /boot partition. sda (which is nothing but our systems primary hard disk) is written as sd0 in GRUB2 and 2 is the second partion of sda (primary hard disk) so in short my /boot is second partition of my primary hard disk.sd0 will remain same in all new systems since all use SCSI HDD and only your partition number will change so find out that.
NOTE: if your system use IDE HDD then use hd0 instead of sd0 and partition number starts with 0 partition 1 will be treated as 0 and partition 2 as 1 etc.

for check your systems /boot partition open terminal and typein
lsblk
it gives /boot to be mounted on sda2
a in sda is replaced with 0 and 2 is the partition number thus address becomes (sd0,2)
or
sudo fdisk -l
now mount each partition one by one and check which matches with /boot partition and translate the path by above given rule and replace (sd0,2) with your path.and change the new to your folder name.
NOTE: if you havent created a separate /boot partition during installing linux then your /boot address will be same as of / (root) partition.
Only for GEEKS -: for lengthy and more descriptive tutorial about grub and grub2 click here and here
fourth line goes same Except change the name of vmlinuz as per your linux flavor and new to your folder name.
fifth is also same except change the initrd image name as per your linux flavor.
5. Update the grub
ubuntu user just type in terminal : sudo update-grub
fedora user just type in terminal: sudo grub2-mkconfig -o /boot/grub2/grub.cfg
And you are all set now reboot the system and see the mazik. 8-). and do let me know if you face any problem implementing it
Comments
Post a Comment