Friday, 24 August 2018

grub: how to boot into ISO partition


I have copied an ISO file into a partition (i.e. dd if=isofile of=/dev/sdb1). How can I boot into that partition via GRUB?


When I try just with chainloader (hd1,0)+1, it says unknown executable format.



Answer



See my answer on your boot-from-ISO-files question. Using that as a starting point, I ran some tests with an old hard-drive. I've previously configured Grub2 to boot a multi-ISO flash drive, so what I did was:




  1. Create a couple of partitions on an old hard drive. This was done using a USB-to-IDE adapter, so the drive appears as /dev/sdb.



    • Partition 1: FAT32, ~2GB in size

    • Partition 2: unformatted





  2. Mounted the first partition to /mnt and installed a copy of Grub from my system onto the drive:


    sudo grub-install --no-floppy --root-directory=/mnt /dev/sdb




  3. "Burned" an ISO to the second partition:


    sudo dd if=avg.iso /dev/sdb2




  4. This is an AVG virus-scanner ISO; on my multi-ISO flash drive, I use this to boot the ISO directly:


    menuentry "AVG Rescue CD" {
    loopback loop /iso/avg.iso
    linux (loop)/isolinux/vmlinuz max_loop=255 vga=791 init=linuxrc iso-scan/filename=/iso/avg.iso
    initrd (loop)/isolinux/initrd.lzm
    }

    In order to make this work from a hard drive partition, we need to nix the loopback command and set the root device and such. My attempts to have Grub2 discover the root device automagically all failed, so I pointed it at the partition directly. This works, but watch out for Grub's device enumeration; the drive you're trying to boot from may not be (hd0). Here's a working entry for the ISO partition:


    menuentry "AVG Rescue CD" {
    linux (hd0,2)/isolinux/vmlinuz max_loop=255 vga=791 init=linuxrc
    initrd (hd0,2)/isolinux/initrd.lzm
    }

    This results in a bootable ISO-on-partition.




This works because Grub2 can read ISO9660 filesystems, because this particular ISO is loading an OS that can cope with an ISO on a partition, and because practically everything the kernel loads is in the initrd.




If you're using Grub4DOS or Grub 1, you may be able to pull a similar trick with the chainloader. Presuming that this works to boot the Win7 ISO directly (source):


title Windows 7
map (hd0,0)/win7.iso (hd32)
map --hook
chainloader (hd32)

You may have luck with this modification (assuming you "burned" the ISO to the second primary partition, (hd0,1); otherwise substitute the proper partition):


title Windows 7
map (hd0,1) (hd32)
map --hook
chainloader (hd32)

You may also get away with this:


title Windows 7
chainloader (hd0,1)

However, the ISO isn't really configured to boot from a drive, so you may run into other problems.


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...