A generic rescue system should boot in bios mode and in (u)efi mode. It should boot from usb and it should use the same boot menu config file for bios and for efi boot mode. Grub2 has a nice boot menu and supports bios and efi boot mode.
Because the installation scripts of grub2 might have side effects and might affect installed systems, only grub images (=files) are created.
(Installation for efi boot, if secure boot is disabled: copy grub core image to EFI/BOOT; bios boot: chainload from syslinux + ldbsd.com.)
Steps to create such an usb stick using linux (e.g. ubuntu or opensuse): bios boot and efi boot with disabled secure boot
(it is possible to use clonezilla stable (=debian version): choose run shell; sudo su; ifconfig eth0 YOURIP netmask YOURMASK; route add default gw YOURGATEWAYIP; use mc to edit /etc/resolv.conf: nameserver 8.8.8.8; apt-get update; apt-get install grub-efi; use wget to fetch other files)
- backup existing data because the usb stick will be repartitioned (erasing existing data)
- run linux and use gdisk to create a gpt partition table with one fat32 partition
(which will be marked bootable for bios boot). Run gdisk as root user:
gdisk /dev/sdX (X=your usb stick; ensure that you use the intended usb stick – and not an existing hard disk)
– p (prints existing partition table)
– o (creates a new empty partition table)
– n (create partition: use default start and end sectors, set type to 0700)
– x (switch to expert menu)
– a (add flags: use 2 = “legacy BIOS bootable”)
– w (writes the new partition table to the usb stick) - format the new partition with fat32 (and set partition label name to SPB2; this label will be used by grub2 to identify the partition)
mkfs.msdos -n SPB2 /dev/sdX1 (X=your usb stick) - mount the new partition and create some directories:
– mkdir mnt
– mount /dev/sdX1 mnt (X=your usb stick)
– mkdir -p mnt/EFI/BOOT
– mkdir -p mnt/grub/fonts
– mkdir syslinux
– mkdir mnt/grub/i386-pc (optionally for additional grub2 modules, bios mode)
– mkdir mnt/grub/x86_64-efi (optionally for additional grub2 modules, efi mode) - install syslinux (has to be version <5.0, binaries here: syslinux.zip) to the new partition /dev/sdX1 and copy the sylinux boot loader gptmbr.bin to /dev/sdX
– umount /dev/sdX1 (X=your usb stick)
– syslinux -d syslinux /dev/sdX1 (X=your usb stick)
– dd if=/usr/lib/syslinux/gptmbr.bin of=/dev/sdX
or
dd if=/usr/share/syslinux/gptmbr.bin of=/dev/sdX
– mount /dev/sdX1 mnt - contents of configuration file for grub core image in bios boot mode embed.cfg:
search.fs_label SPB2 root
set prefix=($root)/grub
configfile $prefix/grub.cfg - the configuration file for grub core image in efi boot mode embed_efi.cfg currently has the same contents as embed.cfg.
- both configuration files, embed.cfg and embed_efi.cfg are stored in mnt/grub/
- install grub2 (needs installed grub2 packets for i386-pc and for x86_64-efi;
e.g. apt-get install grub-pc and apt-get install grub-efi-amd64; older debian based linux calls grub2 grub and grub-1.x grub-legacy).
This step creates only grub image files (given by “-o”).
– cp /usr/share/grub/unicode2.pf2 mnt/grub/fonts/
or
cp /usr/share/grub2/unicode.pf2 mnt/grub/fonts
– grub-mkimage -O i386-pc -p /grub -c mnt/grub/embed.cfg -o mnt/grub/core.img configfile fat part_gpt part_msdos biosdisk cat echo test search search_label search_fs_uuid boot chain linux reboot halt normal vbe font gfxterm
or
grub2-mkimage ….
– grub-mkimage -O x86_64-efi -p /grub -c mnt/grub/embed_efi.cfg -o mnt/EFI/BOOT/bootx64.efi configfile fat part_gpt part_msdos cat echo test search search_label search_fs_uuid boot chain linux reboot halt normal efi_gop efi_uga font gfxterm
or
grub2-mkimage …. - in bios boot mode syslinux is used to chainload core.img of grub2 (with an intermediate ldbsd.com from grml project which does only work with syslinux versions <5.0)
– contents of syslinux.cfg (to be copied to mnt/syslinux/syslinux.cfg):
default grub2
timeout 1
totaltimeout 3
label grub2
say using bsd4grml/ldbsd.com as loader
kernel ldbsd.com
append echo Loading GRUB2…`machine exec grub /grub/core.img
– unpack ldbsd.com.zip and copy ldbsd.com to mnt/syslinux/ldbsd.com - finally we need grub.cfg (to be stored in mnt/grub/):
set menu_color_normal=white/black
set menu_color_highlight=black/light-gray
set default=0
loadfont ($root)/grub/fonts/unicode.pf2
if [ x$grub_platform = xefi ]; then
set gfxmode=auto
set gfxpayload=keep
set boottype=efi
else
set gfxmode=800x600x16
set gfxpayload=keep
set boottype=bios
fi
terminal_output gfxterm
menuentry “linux on sdb1 ($boottype; partition SPB2 on($root); $gfxmode)” {
linux ($root)/vmlinuz root=/dev/sb1 …
initrd ($root)/initrd
} - the example assumes that linux kernel and ramdisk are copied to mnt/
(that is, to the root directory of the usb stick) - both boot modes can be tested with virtualbox (>=4.2.12); system settings allow to switch to efi boot mode.
Give access to usb device with
VBoxManage internalcommands createrawvmdk -rawdisk /dev/sdX -filename raw_usb_sdX.vmdk
Blog of spblinux » Blog Archive » Atom N2600 Netbook with Ubuntu 14.4 and Windows 8.1 says:
[…] windows diskpart to create a primary ntfs formatted partition on the usb stick (compare with this post) and copy iso to usb with Windows 7 usb/dvd download tool; run bootsect.exe /nt60 X: /mbr to make […]
June 3, 2014, 19:55Kyvaith says:
Hi, I realy need help. Is there any way to get a el torito bootable ISO with GRUB bootloader, using hdiutil makehybrid on Mac OS? I need to create hybrid (ISO9660 and HFS+) ISO with hdiutil. I cannot use makeisofs, xorriso, genisoimage etc. I need blessed HFS+ partition in ISO, with is only possible with hdiutil on Mac (xorriso ahould be able to do this, but is buggy). Main issue with hdiutil is, there is no -boot-info-table switch. I’ve tried to apply info table manual to generated eltorito.img, but it won’t work, just hang on boot. Maby different stage1 boot loader, with chanload GRUB? I found two bootloaders that work with hdiutil – ISOLINUX.BIN (syslinux) and cdboot (Chameleon bootloader). But none of them is appropriate for my needs. There is also an eltorito.img bootloader with don’t work.
February 12, 2015, 16:27Archive with bootloaders: https://drive.google.com/file/d/0BxGYfgaJqEH2SVpvUmdiOW83UEU/view
Dirk says:
Hello, i tried this guide but am unable to boot in uefi mode. bios mode runs fine, in uefi mode all i can get is a black screen, same in virtualbox as in real boot from the pen-drive itself. secureboot should be disabled. checked out all steps once again but no luck. what am i doing wrong / what am i missing? please help
March 25, 2016, 09:37spblinux says:
Probably the next step is to test efi boot with some prebuilt efi boot image like an ubuntu install image. (Usually those iso image can be copied with dd to a usb stick).
May 14, 2016, 20:53anonymous says:
Hey, I followed all the steps above, but the last one proves to be quiet troublesome. How can I copy kernel and ramdisk to the root directory without compiling them myself? As far as I can see that would require much processing power as well as storage space which I don’t have as I’m using your guide to make a usb thumdrive with a working linux install efi bootable (currently it only boots legacy bios).
November 6, 2019, 15:05Is there a workaround or download page? Or can I compile them locally from the OS’s filesystem.
spblinux says:
… the idea is just to take existing kernel and ramdisk from an already running system; usually located in folder boot.
November 6, 2019, 16:08spblinux says:
Just used my own notes and had to discover that chainloading grub from syslinux usings ldbsd.com as described in this post works only if syslinux has a version below 5.0; post has been updated and a zipfile with syslinux binaries for linux (32bit and 64 bit) has been added. Official download, including source and binaries – but not linux 64 bit -, is here: https://mirrors.edge.kernel.org/pub/linux/utils/boot/syslinux/syslinux-4.07.tar.bz2
December 29, 2019, 21:23