Random notes from mg

a blog by Marius Gedminas

Marius is a Python hacker. He works for Programmers of Vilnius, a small Python/Zope 3 startup. He has a personal home page at http://gedmin.as. His email is marius@gedmin.as. He does not like spam, but is not afraid of it.

Mon, 03 May 2010

Booting ISO images from a USB drive

Dear lazyweb, I would like to download an arbitrary ISO image (say, a Ubuntu 10.04 Desktop CD) into a directory of a USB flash drive, and then make that USB flash drive boot that ISO image. I do not want to

I just want a bootloader on the USB to read the VFAT filesystem, mount the ISO image as a loop device, then chain-load the bootloader from that ISO. Bonus points for having a menu letting me choose one of several ISO images. Running a script to edit a text file (say, grub's config) to get that menu is fine.

Is this even possible? If not, can I at least have two out of three (no partition/extraction, but skipping intrinsic bootloader is fine)?

Solution that I finally chose (from Ubuntu forums):

Plug in USB key. Find out the mount point (/media/disk) and the device name (/dev/sdx) of the USB key with

$ mount|grep /media

Install GRUB 2 into the USB key with

$ sudo grub-install --root-directory=/media/usbdisk /dev/sdx

If it says something about embedding being impossible and falling back to UNRELIABLE blocklist-based setup, run

$ sudo grub-install --root-directory=/media/usbdisk /dev/sdx --force

Download a CD image, let's say ubuntu-10.10-desktop-i386.iso. Put it into /media/usbdisk/ubuntu/.

Create a text file /media/usbdisk/boot/grub/grub.cfg with

menuentry "Ubuntu 10.10 (x86 desktop livecd)" {
    set isofile="/ubuntu/ubuntu-10.10-desktop-i386.iso"
    loopback loop $isofile
    linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile quiet splash noprompt --
    initrd (loop)/casper/initrd.lz
}

You can have as many ISO images as you want, just make sure to add a menuentry for each. There's no need to run grub-install again after adding or removing a .iso file. Oh, and if you want to use an ISO file for a different distribution, you'll have to figure out the correct linux and initrd lines somehow.

Update: Ubuntu 13.04 changed the name of the kernel -- use (loop)/casper/vmlinuz.efi instead of (loop)/casper/vmlinuz.

I tested it with the following images

This solution skips the CD-ROM's boot menu. I haven't found a better one.

posted at 20:24 | tags: , | permanent link to this entry | 23 comments
Use BootMyISO from http://www.pendrivelinux.com
Comes with a menu, and you can add your own ISOs. And for me, this one actually works :)
posted by Koen at Mon May 3 22:40:12 2010
I got something similar working with Grub for DOS thanks to a little utility found at http://www.pendrivelinux.com/boot-multiple-iso-from-usb-multiboot-usb/

I had to go in and edit the menu.lst to suit the images I am using but that aside it was rather easy to setup. The only downside was that the utility only runs in windows... although I see no reason it would need to assuming one could install Grub on the key some other way...

HTH!

Cheers,
Tim
posted by Tim at Mon May 3 22:53:23 2010
I can tell that your linux-fu is much stronger than mine. Would something like this work for you?
http://www.pendrivelinux.com/boot-multiple-iso-from-usb-multiboot-usb/
You drop .ISOs onto a usb device, then, from the site, "MultiBootISOs Works by using Syslinux  to chainload GRUB4DOS."
I haven't used this but I have used their pendrivelinux (just updated to include lucid lynx). I used it to create a Mint 8 bootable SD card that included persistent storage.
btw, their usb creator was a standalone exe (no install needed). Not sure if it's the same for multibootisos.exe.
good luck.
posted by fluke at Tue May 4 00:59:51 2010
I'ts doable using grub2, with some configuration magic.

I think this will help you: http://rww.dreamwidth.org/3100.html
posted by Olivier at Tue May 4 10:58:44 2010
posted by TGM at Tue May 4 13:46:35 2010
Oops - I meant this one...

http://rww.dreamwidth.org/3100.html
posted by TGM at Tue May 4 13:52:10 2010
The MultiBootISOs thing is very intriguing, but it requires me to find a Windows machine and download/run random exe files from the Internet.  Not gonna happen.

I ended up following this recipe: http://ubuntuforums.org/showthread.php?t=1288604 (which I found linked from a comment at http://rww.dreamwidth.org/3100.html) with a slight twist: I had to add '--force' to grub-install, since it said embedding wasn't possible and it had to fall back to UNRELIABLE blocklist-based setup.

Will boot now and see if it works.  Thanks everyone for answers!
posted by Marius Gedminas at Wed May 5 18:05:21 2010
http://liveusb.info/dotclear/

sorry it's in french, but this solution seems quite flexible.
posted by tshirtman at Thu May 6 00:20:21 2010
Mariau, did it work?

Can Grub2 chainload ISO bootloader already?
Until recent times it was only GRUB4Dos who could.
posted by s2 at Sat May 8 10:34:12 2010
The USB drive boots (although there's a scarily-long pause with a black text-mode screen and a blinking cursor; in my first attempt I thought it didn't work and rebooted before Ubuntu had a chance to initialize its boot splash).

It's not really chainloading, though; grub2 boots the kernel and initramfs directly and requires the OS to do its own ISO-image loading.
posted by Marius Gedminas at Sat May 8 19:47:30 2010
> there's a scarily-long pause
> with a black text-mode screen

Does it do some disk activity?  Then maybe it is: https://bugs.launchpad.net/ubuntu/+source/grub2/+bug/420933

> It's not really chainloading, though

Ah, it's a pity. I've talked to some italian guy "cod" who was interested in writing BIOS Disk emulation from an ISO (several months ago).  So it could work with any bootable CD/DVD image.

Judging from his site, he hasn't made a progess since:
http://my.opera.com/wolfcod/blog/

But you could probably contact him to be sure, if interested. 

OTOH, Grub4Dos can emulate BIOS disk/ATAPI also, so it's possible the code to be backported to Grub2 in some future:
https://gna.org/projects/grub4dos/
posted by s2 at Sun May 9 18:14:56 2010
Grub4DOS does INT 13h disk emulation, but this only works for ancient OSes -- neither Windows nor Linux  use the BIOS to access CD-ROMs after entering protected mode.

Since I wasn't planning to boot MS-DOS from a CD, I didn't research whether Grub2 supports that or not.
posted by Marius Gedminas at Sun May 9 19:56:27 2010
OK, I see now, Mariau.  I gave it a second thought and it seems to me the solution will need either firmware level CD-ROM emulator or the bootkit capable of virtualizing x86 machine.

As for the first, I know of specialized USB sticks:
ww w.hsc-us.c om/Embedded/udrw/index.htm

Plus I've heard (from the same italian guy), some KINGSTONs also provides similar functionality in their firmwares.

Now for the second:
en.wikipedia.o rg/wiki/X86_virtualization

If you're lucky to get hardware assisted (native) virtualization (on latest x86* CPUs) running, then the needed bootkit will probably be thin, nice and give you near-native performance.

But should you use full virtualization or even paravirtualization (on older CPUs), the performance in guest OS would drop significantly, I believe (like it being run inside Qemu running on the same machine).  I mean, not only virtual CD/DVD transfers would suffer, but the whole OS execution too :(

So you are left with two pratical choices: AMD-V/Intel VT-x bootkit or USB firmware level CD/DVD-ROM emulator.

Do you like any of these two?  Or have you some other thoughts accumulated by the time? :)
posted by s2 at Tue Oct 19 23:33:06 2010
I guess you don't :)
posted by s2 at Sat Nov 6 10:15:51 2010
Yes, that sounds like lots of work for little benefit.  I'm only interested in booting Linux CDs, and those usually support a native boot-from-iso-image option.  All I lose is the CD boot menu.
posted by Marius Gedminas at Sat Nov 6 16:34:31 2010
Added a TL;DR version of the forum instructions to this post.  The original instructions are excellent, but long.  Go there if you want to know how to boot non-Ubuntu ISO images.
posted by Marius Gedminas at Fri Dec 3 21:24:32 2010
FWIW, there are some HowTo (in russian) on the second way I offered.  They are UFD-controller specific, but sometimes it's better than nothing:

http://flashboot.ru/index.php?name=iflash

http://flashboot.ru/index.php?name=News&op=article&sid=33

http://flashboot.ru/index.php?name=News&op=article&sid=29

http://flashboot.ru/index.php?name=News&op=article&sid=23
posted by s2 at Wed Jan 12 23:41:33 2011
Sorry, I forgot to add: this is MS way ;(
posted by s2 at Wed Jan 12 23:45:09 2011
I copied ubuntu 10.04 os files in my computer from my friend cd. now i want to install it with my pendrive. But it didn't works. it asks iso image.  i just tried from many softwares but those are also asks .iso image type file.I didn't find such image file in ubuntu os files. how can i get it? plz help me.
posted by Keerthana N at Fri May 11 21:02:59 2012
This technique continues to work fine with all Ubuntu versions up to and including 12.10.

Incidentally you can test the bootable USB stick by doing
sudo umount /media/usbdisk
sudo kvm -hdb /media/sdx
posted by Marius Gedminas at Fri Oct 19 18:09:40 2012
Urk, make that last line
sudo kvm -hdb /dev/sdx
posted by Marius Gedminas at Thu Jan 3 20:44:56 2013
here is a good way to run linux(ubuntu/bt) without usb in windows ,it do not uses iso emulation like grub[grab it you will find it interesting][1]



http://www.hk416.co.nf/booter.html


  [1]: http://www.hk416.co.nf/booter.html
posted by manox at Sat Apr 12 03:57:50 2014
« I do not want to
3. skip the ISO's bootloader and directly boot the kernel+initramfs from the ISO (eliminates this recipe, and this recipe) »

this means you want a hdd chainload solution a la winxp mode but not for hdd partition but for iso images

very nice indeed, this is what i am looking for also, because iso boot solutions with kernel + initrd has too many variations, look here if you don't trust me:
stressat.blogspot.ro/2014/04/boot-iso-images-from-hdd-grub2.html

pure chaos not so?

what i need, we are in 2014 now, is a simple grub2 iso chainload solution, aka winxp hdd solution, something like this:

from the oldies and goldies winxp chainload solution
### BEGIN /etc/grub.d/09_windoze ###
menuentry "win_xp (on /dev/sda1)" --class windows --class os {
insmod part_msdos
insmod ntfs
set root='(hd0,msdos1)'
search --no-floppy --fs-uuid --set=root ntfs_uui_blablabla
drivemap -s (hd0) ${root}
chainloader +1
}
### END /etc/grub.d/09_windoze ###

to a more general grub2 iso chainload boot solution, something like this:

menuentry "generic_live_distro_001" {
insmod loopback
insmod chainload
insmod iso
loopback loop /boot/iso/generic_live_distro_001.iso
set root=(loop)/
drivemap -s (hd0) ${root}
chainloader +1
}

then we can skip any linux and initrd custom options termodinamic and just boot, i mean chainload, the fcking iso! from the cloud, from the net, from the old an rusted hdd or usb and so on!

right now, i mean third semester of 2014, this is still a pipe dream because chainloading iso images is not a simple and standardized  thing:

www.lucas-nussbaum.net/blog/?p=485#comment-22649
« slh wrote on 05/25/10 at 10:25 pm :

Like Colin Watson already mentioned, to chainload an ISO from grub2 is unfortunately not possible (yet/ ever?), as it would require grub2 to intercept not only BIOS calls for emulating a CD drive from the given ISO (so the embedded ElTorio bootloader can take over), but also to fool higher level driver OS drivers. While kernel and initramfs can be loaded through grub2′s loopback option, grub.cfg still needs to know about their exact location inside the ISO. Additionally the initramfs must be able to find the root device itself, which unfortunately rules out generic solutions and makes it not only dependent on proper OS/ initramfs support, but also highly distribution specific.

For sidux, we have solved this through the custom grub2-fll-fromiso package mentioned by iria.
Vcs-Svn: svn://svn.berlios.de/fullstory/grub2-fll-fromiso/trunk
Vcs-Browser: http://svn.berlios.de/svnroot/repos/fullstory/grub2-fll-fromiso/trunk/
This package plugs into update-grub (Debian specific), searches for ISOs matching a given regexp below the configured directories and then looks inside the ISOs (through genisoimage’s isoinfo, to avoid having to mount it) for kernel and initramfs files, matching a hardcoded regexp (vmlinuz, initrd.img) for the file names. Once these are known, an appropriate stanza can be written to grub.cfg (the example is slightly more complex than necessary, given that the ISOs are stored on LVM2):

### BEGIN /etc/grub.d/60_fll-fromiso ###
menuentry "sidux-2009-04-moros-kde-lite-amd64-200912310312 (vmlinuz0.amd)" {
insmod iso9660
insmod lvm
insmod ext2
set root='(vg-challenger-pyfll)'
search --no-floppy --fs-uuid --set 5050dfe1-96ac-4680-a093-6fdef64c5c56
loopback loop /sidux-2009-04-moros-kde-lite-amd64-200912310312.iso
linux (loop)/boot/vmlinuz0.amd fromhd=/dev/mapper/vg--challenger-pyfll fromiso=/sidux-2009-04-moros-kde-lite-amd64-200912310312.iso boot=fll lang=de_DE TZ=Europe/Berlin quiet noeject hostname=challenger username=slh
initrd (loop)/boot/initrd0.amd
}
### END /etc/grub.d/60_fll-fromiso ###

The drawback, besides having to call update-grub for updating grub.cfg, is, that this needs a lot of cooperation from the affected live ISOs and exact knowledge about distribution specific boot parameters. In case of sidux, these are fromhd= (the block device which holds the ISO), fromiso= (path to the ISO, relative to the afforementioned block device) and boot=fll, which calls the live-sidux specific initramfs scripts to locate root device and evaluate boot parameters. lang=, TZ=, hostname=, username= and the default quiet and noeject parameters are optional and configurable.

While this works reliably for sidux and could be enhanced to cover additional distributions providing similar functionality, it still depends on a lot of cooperation from the live ISO and its initramfs implementation – in addition to a positive distribution recognition. Unfortunately these boot parameters for finding the root device from non-ElTorito block devices vary greatly between live distributions, if they’re implemented in the given distribution at all. »
posted by totedati at Thu Aug 14 19:36:43 2014

Name (required)


E-mail (will not be shown)


URL


Comment (some HTML allowed)