Friday, 6 May 2016

Coming soon! grub2 UEFI-booting from linux ISO files using E2B

Currently you cannot directly boot from an ISO file via UEFI using Easy2Boot - you have to convert the ISO to a .imgPTN file first.

However, grub2 can UEFI-boot and can run linux ISOs (some of which will run even if the ISOs do not support UEFI-booting and do not contain an \EFI folder!).

The reason E2B does not use this mechanism is that some UEFI systems will only UEFI-boot from a USB disk containing both MBR and UEFI boot files - even if the system is set to boot from Legacy/BIOS devices.

This means that if you had grub2 UEFI boot files on your FAT32 E2B drive, then you can never boot to the E2B menu on these systems!


I recently tried this project (which seems to have 'borrowed' my E2B scripts and my Clover development work without any attribution!) and was inspired to develop my own grub2 system that I could add to E2B.

Another issue with grub2 booting, is that, like most other USB multiboot solutions, special cheat codes are required for each ISO, and therefore this changes the menu text depending on what specific ISO is used. In many cases, each ISO requires it's own bespoke menu!

And there are other complications too, such as Fedora, Gentoo and CentOS ISO files not booting from an NTFS partition!

Also, booting LiveCDs is OK using the grub2 'loop' method, but booting Linux Install ISOs usually causes problems, because the install code cannot find the 'CD'.

The menu must match a specific ISO!

Many grub2 menus seem to require you to specify the CDLABEL, which will obviously change depending on what the actual ISO is! For example:

menuentry "Fedora Live Workstation FAT32-only" --class fedora {
set isofile="$isopath/fedora-workstation.iso"
loopback loop $isofile
probe -u (loop) --set=loopuuid
set id=LABEL=Fedora-Live-WS-i686-23-10
linux (loop)/isolinux/vmlinuz0 root=live:$id  iso-scan/filename=$isofile rootfstype=auto ro rd.live.image xquiet nosplash  rhgb rd.luks=0 rd.md=0 rd.dm=0 nomodeset
initrd (loop)/isolinux/initrd0.img
}

However, I worked out a way around this which I have not seen mentioned anywhere else, by obtaining the UUID of the loop volume - this new method works and you don't need to know the label of the CD...

menuentry "Fedora Live Workstation FAT32-only" --class fedora {
set isofile="$isopath/fedora-workstation.iso"
loopback loop $isofile
probe -u (loop) --set=loopuuid
set id=UUID=$loopuuid
linux (loop)/isolinux/vmlinuz0 root=live:$id  iso-scan/filename=$isofile rootfstype=auto ro rd.live.image xquiet nosplash  rhgb rd.luks=0 rd.md=0 rd.dm=0 nomodeset
initrd (loop)/isolinux/initrd0.img
}

The new grub2 solution for E2B

I will release a UEFI_PTN2.imgPTNLBAa23 partition image file soon for Beta testing (I may change the name!).

Your E2B USB drive should have two primary partitions:
Partition 1: E2B Primary partition
Partition 2: FAT32 or NTFS Primary partition (user files, backups, etc.)

When you select the UEFI_PTN2 file and switch it in, you will get:
Partition 1: UEFI FAT32 Primary partition (the image file)
Partition 2: FAT32 or NTFS Primary partition (user files, backups, etc.)  <i.e. unchanged>

Your second partition should preferably be formatted as FAT32, because Gentoo, Fedora and Centos will not boot from an ISO on an NTFS partition (and probably exFAT either). However, you can use NTFS for the 2nd partition if you also want to keep large files such as backups on this partition, just bear in mind that some ISOs may not work on NTFS volumes via grub2 (but will work if you MBR-boot and use E2B to boot them).

Note: Due to the common BIOS bug of not being able to access sectors past 137GB on a USB drive, you should bear in mind that if Partition 2 extends beyond 137GB from the start of the USB disk, then MBR\Legacy booting may not work correctly (e.g. crash or no menu entries!). However, UEFI-booting should work OK (assuming that is not buggy too on your system!).

You can use a Fixed or Removable E2B USB drive, although if you use a Removable USB drive, the second partition will not be accessible from Windows unless you temporarily swap over the E2B partition with the second partition using for instance, the RMPrepUSB - Ctrl-O feature.

You can use Easeus Home Partition Master to shrink and create a 2nd partition on a Removable USB flash drive.

Partition 2 (preferably FAT32)

I am still working on the details, but Partition 2 will contain a folder (e.g. \ISO) and you will place all your bootable ISOs inside this single folder. 

Of course, you can add your own personal files and folders to other areas of the partition as usual.

There will also be configuration folders in which you can place addition grub2 .cfg files which contain additional grub2 menu entries. In this way, you can add more menu items to the menu system and more ISOs without needing to modify the menus inside the .imgPTN file.

There is currently 5 menus (suggestions welcome for others):

You will also be able to change the default menu entries and timeouts for each menu by adding defaults.txt files.

This list and the menus may change before the first beta release...

How to use the new grub2 system

If you wanted add a Fedora Live CD ISO, just copy it to the \ISO folder on the 2nd partition and rename it to fedora-workstation.iso.  For a gentoo ISO, rename it to  this project page , for avg, rename it to avg.iso. All filenames should be in lower case.

If an ISO is not present, then the menu entry for it will not appear in the menu.

Also, if some ISOs are 64-bit bootable only, they they will not be listed if you boot on a 32-bit system. So the menu entries may change depending on whether you UEFI-boot or MBR-boot because the menu can detect what mode it is in and suppress menu items that will not work in that environment.

For a provisional list see the list on this project page (windows files will not be supported).

There are quite a few menu entries to test and improve and many of the menus used by that project do not seem to work (it doesn't help that they don't specify the exact ISO that we are supposed to choose!).

Adding extra ISOs

If a particular ISO is not supported, or you want to add another ISO of the same type (e.g. Fedora 23 and Fedora 22), then you simply add a .cfg file, e.g. \ISO\cfg\linux\Myfedora22.cfg and copy your ISO file to the \ISO folder. These user .cfg files will automatically be included in the menu each time you load the menu. Here is an example menu .cfg file:

\ISO\cfg\linux\Myfedora22.cfg 
if [ -e "$isofpath/fedora22.iso" ]; then
menuentry "Fedora 22 Live Workstation, FAT32-only UEFI)" --class fedora {
set isofile="$isopath/fedora22.iso"
set root=$root2
loopback loop $isofile
probe -u (loop) --set=loopuuid
set id=UUID=$loopuuid
linux (loop)/isolinux/vmlinuz0 root=live:$id  iso-scan/filename=$isofile rootfstype=auto ro rd.live.image xquiet nosplash  rhgb rd.luks=0 rd.md=0 rd.dm=0 nomodeset
initrd (loop)/isolinux/initrd0.img
}
fi

Note: This has now changed, .grub2 will be used as the file extension to avoid confusion with E2B .cfg files.

So by switching to the UEFI_PTN2 .imgPTN file, you will then be able to UEFI-boot to a grub2 menu and then select from a wide variety of linux-based ISOs in the grub2 menu, that are located on the 2nd partition.

Note that, unlike E2B, the menu is not dynamic because most menus are very specific for each ISO, however you can add extra menu items using your own .cfg files. I may provide templates at a later date.

You can also MBR-boot to the E2B CSM menu which is inside the UEFI-PTN2 image, and then switch to the grub2 menu system (i.e. the same grub2 one you would get if you UEFI-booted).

Here are some early screenshots:

The CSM menu will allow you to switch to the grub2 menu in MBR\Legacy mode,
or you can use the Clover menu entries to boot to the grub2 menu in UEFI-mode.
Either menu will get you to the grub2 Main menu shown below...


The UEFI_PTN2 Main menu.
A default timeout can be set and default menu item.
This is what you will see if you UEFI-boot from the E2B USB drive.


This is the Linux Menu.
As I have many ISOs present for testing, there are quite a few menu entries!

Note that you can add a 'partition 2' menu (.mnu file) to your normal E2B menu, this will allow you to MBR-boot any of the ISOs on the 2nd partition, from within E2B.

Feedback (or 'call to action'!)

If you have any comments or suggestions please let me know (see link at top-left of this blog page).

If you have a favourite LiveCD ISO that is not mentioned in the list on  this project page then please also let me know.

Also, I would welcome any working grub2 direct-iso boot menus that you have tested and know work (please give exact ISO name, URL if possible and if it works on NTFS or not).

Once the first Beta is released, I will be asking you to help me test the menus using any Live ISOs that you may have, and if possible, to send me your menu corrections, if required.

thanks,
Steve