Use grub to make a BIOS/UEFI bootable USB flash

How to do things, solutions, recipes, tutorials
Post Reply
Message
Author
jafadmin
Posts: 1249
Joined: Thu 19 Mar 2009, 15:10

Use grub to make a BIOS/UEFI bootable USB flash

#1 Post by jafadmin »

Do this to your USB Flash using gparted and grub-install from a linux distro:
Image
Add this to the grub.cfg in the root of sdX1:

Code: Select all

set root=(hd0,msdos2)
configfile /boot/grub/grub.cfg
Add this to the /boot/grub/grub.cfg of sdX2:

Code: Select all

set timeout=5
set default=0

# Boot a puppy example
menuentry 'BionicPup64 8.0' {
	linux	/BionicPup64/vmlinuz   psubdir=BionicPup64 pmedia=usbflash pfix=fsck
	initrd	/BionicPup64/initrd.gz
}

# Boot an ISO file example
menuentry "linuxmint-19.2-mate-64bit ISO" {
	set isofile="/ISOs/linuxmint-19.2-mate-64bit.iso"
	loopback loop $isofile
	linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile liveimg noprompt noeject quiet splash --
	initrd (loop)/casper/initrd.lz
}
A BIOS machine will boot directly to partition 2 (sdX2), and a UEFI machine will boot to partition 1 (sdX1) and get transfered to the grub.cfg on partition 2 (sdX2)

Those entries boot puppies and ISO's that are on the ext3 partition. This is really important with large ISO's as Grub4Dos requires them to be on a fat32 and occupy only 1 extent. Grub will boot regardless of how many extents.

So for multiple large ISO's, ext3 and grub works better.

3guesses
Posts: 172
Joined: Tue 30 Sep 2014, 20:22

#2 Post by 3guesses »

Hi jafadmin,

Thanks for this post - this is of GREAT interest to me! One question: what is bootx64.efi (on sdX1)? Is it a Grub2 EFI bootloader? And if so, where do you get it from??? I believe there is one in /efi/boot/ in the Bionic Puppy 8.0 iso - should we use that?

Thanks :D

Also, would it not be better/safer to set root using the UUID of sdX2 rather than with (hd0,msdos2) in /grub.cfg on sdX1?

Also #2, is it better/necessary to use ext3 rather than ext4 for sdX2? I don't know enough (anything) about the difference between the two filesystems...

Also #3, I believe that under Windows XP it is only possible to view/access the first partition on a USB flash drive, so if you wanted to be able to access the main partition (containing the ISO files, the main grub.cfg, etc) from XP then it would be better to have the main partition as the 1st partition on the flash drive and the ESP as the 2nd partition. And if the ESP is only used for the Grub2 EFI bootloader it can be really minimal in size (much smaller than 250MB!).

Also #4, it might be nicer (more convenient) to have the main grub.cfg in the root directory of sdX2 (rather than in /boot/grub) - I think you can specify that via command-line argument to grub-install? Else, make /boot/grub/grub.cfg on sdX2 redirect to /grub.cfg (similar to the one on sdX1)? A nice bit of symmetry... 8)

Also #5, ... nah, I got nothing :wink: :lol:

EDIT I got an also #5! Should the USB flash drive be formatted to GPT or MBR? Or does it not matter?

EDIT Also #6, you might want a bootia32.efi in /EFI/boot on sdX1 so that it can be used on 32-bit EFI systems?

EDIT Also #7, I got an "error: cannot find EFI directory" when I ran the grub-install command from antiX19, so I did the following:
- mkdir /mnt/USBESP
- mount /dev/sdX1 /mnt/USBESP
- added "--efi-directory=/mnt/USBESP" to the grub-install command
This then worked. However, it also overwrote the contents of the /EFI/boot directory on sdX1... So then I created a /boot/grub/grub.cfg (just in case that is where it would look for it) that simply redirected to /grub.cfg on the ESP.

3guesses
Posts: 172
Joined: Tue 30 Sep 2014, 20:22

antiX-19_x64-full.iso

#3 Post by 3guesses »

OK, so I tried using this method to boot the antiX 19 ISO (antiX-19_x64-full.iso) from USB via EFI (on my Asus T100TA), but without success - each time Grub2 bombed out with "error no suitable video mode found", so I added the "insmod all_video" command to the entries, but then the kernel just bombed out very early on. These are the entries from grub.cfg:

Code: Select all

menuentry "(1) antiX-19_x64-full.iso" {
insmod all_video
   set isofile="/ISO/antiX-19_x64-full.iso"
   loopback loop $isofile
   linux (loop)/antiX/vmlinuz boot=antiX iso-scan/filename=$isofile liveimg noprompt noeject quiet splash --
   initrd (loop)/antiX/initrd.gz
}

menuentry "(2) antiX-19_x64-full.iso" {
insmod all_video
   set isofile="/ISO/antiX-19_x64-full.iso"
   loopback loop $isofile
   linux (loop)/antiX/vmlinuz boot=antiX iso-scan/filename=$isofile liveimg noprompt noeject quiet splasht disable=lxF menus --
   initrd (loop)/antiX/initrd.gz
}

menuentry "(3) antiX-19_x64-full.iso" {
insmod all_video
   set isofile="/ISO/antiX-19_x64-full.iso"
   loopback loop $isofile
   linux (loop)/antiX/vmlinuz boot=antiX iso-scan/filename=$isofile quiet splasht disable=lxF menus --
   initrd (loop)/antiX/initrd.gz
}

menuentry "(4) antiX-19_x64-full.iso" {
   set isofile="/ISO/antiX-19_x64-full.iso"
   loopback loop $isofile
   set root=(loop)
   configfile /boot/grub/grub.cfg
}

menuentry "(5) antiX-19_x64-full.iso" {
   set isofile="/ISO/antiX-19_x64-full.iso"
   loopback loop $isofile
   set root=(loop)
   configfile (loop)/boot/grub/grub.cfg
}
Looking at the menu entry in jafadmin's original post, I guessed that it was trying to reproduce what was in the grub menu entry in the Linux Mint ISO, so it seemed sensible to me just to redirect to the grub.cfg in the antiX 19 ISO - this is what entries (4) and (5) above were attempting to do. They do achieve this, but then when you try to boot into antiX you get the same "no suitable video mode found" error.

For reference, here is the grub.cfg from the antiX 19 ISO:

Code: Select all

#------------------------------------------------------------------
# file: /boot/grub/grub.cfg for the Live version of antiX
#
# This file can get updated automatically on a LiveUSB via the save
# feature in the text menus.  It is possible to break these updates
# by editing this file.
#------------------------------------------------------------------


# search --no-floppy --set=root --fs-uuid %UUID%
set timeout=60
set gfxmode=1024x768
#set gfxpayload="3200x1800;2560x1440;2160x1440;1920x1080;1600x1200;1600x1050;1600x900;1440x900;1366x768;1280x1024;1280x800;1280x720;1024x768;auto"
set gfxpayload="2048x2048;2048x1280;2048x1080;1920x1080;1600x900;1600x1200;1600x1050;1500x1000;1440x960;1440x900;1368x912;1366x768;1280x800;1280x720;1280x1024;1200x800;1024x768;auto"
set default=1


# load defaults
#
if [ -s $prefix/config/defaults.cfg ]; then
source $prefix/config/defaults.cfg
fi


menuentry " antiX-19 x64-full (16 October 2019)" {
linux /antiX/vmlinuz quiet splasht disable=lxF
initrd /antiX/initrd.gz
}

#--custom  menuentry " Custom" {
#--custom  linux /antiX/vmlinuz quiet
#--custom  initrd /antiX/initrd.gz
#--custom  }

menuentry " antiX-19 x64-full Customize Boot (text menus)" {
linux /antiX/vmlinuz quiet splasht disable=lxF menus
initrd /antiX/initrd.gz
}

submenu ">>> Advanced Options for antiX-19 x64-full <<<" {

menu_color_normal=white/black
menu_color_highlight=yellow/light-gray

menuentry " antiX-19 x64-full Failsafe" {
linux /antiX/vmlinuz quiet splasht disable=lxF failsafe
initrd /antiX/initrd.gz
}

menuentry "antiX-19 x64-full Create Bootchart" {
linux /antiX/vmlinuz quiet splasht disable=lxF bootchart initcall_debug printk.time=y
initrd /antiX/initrd.gz
}

menuentry " antiX-19 x64-full (1024x768)" {
linux /antiX/vmlinuz quiet splasht disable=lxF
initrd /antiX/initrd.gz
}

menuentry " Power Off" --hotkey=P {
halt
}

menuentry " Reboot"  --hotkey=R {
reboot
}

if [ -f /boot/grub/theme/help.txt ]; then
menuentry " Help" --hotkey=H {
cat /boot/grub/theme/help.txt
echo -n "Press <Enter> to continue "
read xxx_help
}
fi
}


# load boot menus
#
if [  -f  $prefix/config/bootmenu.cfg ]; then
source $prefix/config/bootmenu.cfg
fi
I don't have much experience of Grub2, so I am grasping at straws a little here. Some help would be appreciated :P

enrique
Posts: 595
Joined: Sun 10 Nov 2019, 00:10
Location: Planet Earth

#4 Post by enrique »

Just in case try to force a mode by appending "video=LVDS-1:800x600@60 "

if need more info see http://murga-linux.com/puppy/viewtopic. ... 62#1048762

User avatar
ivs
Posts: 10
Joined: Fri 13 Mar 2020, 14:38

#5 Post by ivs »

Hi Jafadmin,

I'm Running BionicPup64-8.0 On A USB. I Have A 500 GB Drive Windows 10 Installed.
I Want To Run Windows 10 From USB BionicPup64-8.0 Grub Menu.
Can I Do This ?
I Do Not Want To Install Grub On My Disk.
I Put All Sort Of Entries In The Menu, Like Following.
And I'm Not 100 % Sure Of What I'm Doing Too.
Keep Saying Invalid EFI File Path Etc.
Hope You Can Help Me With This.
Thanks.

menuentry "Start Windows 100 " --class windows --class os {
insmod part_msdos
insmod ntfs
set root='(hd0,msdos1)'
search --no-floppy --fs-uuid --set=root 6278DB1B78DAED33
chainloader +1
}
menuentry "Start Windows 10.a" {
insmod ntfs
insmod chain
root (hd0,0)
chainloader +1
}
menuentry "Start Windows 10.1" {
insmod ntfs
insmod chain
rootnoverify (hd0,0)
chainloader /bootmgr
}
menuentry "Start Windows 10.2" {
insmod ntfs
insmod chain
root (hd0,0)
chainloader /bootmgr
}

root# parted /dev/sda -l
Model: ATA WDC WD5000AADS-0 (scsi)
Disk /dev/sda: 500GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 32.3kB 1020MB 1020MB primary ntfs boot
2 1020MB 361GB 360GB primary ntfs
3 361GB 431GB 70.8GB primary ntfs
Model: SanDisk Ultra (scsi)
Disk /dev/sdb: 30.8GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number Start End Size Type File system Flags
1 1049kB 30.8GB 30.8GB primary fat32 boot, lba

User avatar
Mike Walsh
Posts: 6351
Joined: Sat 28 Jun 2014, 12:42
Location: King's Lynn, UK.

#6 Post by Mike Walsh »

3guesses wrote:Hi jafadmin,

Thanks for this post - this is of GREAT interest to me! One question: what is bootx64.efi (on sdX1)? Is it a Grub2 EFI bootloader? And if so, where do you get it from??? I believe there is one in /efi/boot/ in the Bionic Puppy 8.0 iso - should we use that?
@ 3guesses:-

You may find the following to be of use. I had to undergo a rapid 'crash-course' in this stuff when I got my new HP tower back in January..... :roll:

https://drive.google.com/file/d/1rTL8nR ... sp=sharing

The enclosed grub.cfg file gives some examples that may prove useful.


Mike. :wink:

Post Reply