Useful for those who dual boot with Windows.
Typical Uses: For when your computer now only boots into Windows. You cannot boot Linux.
Or, you have managed to damage your EFI partition contents.
It might be an idea to create a flashdrive **before** any Windows update borks Grub..
This creates a simple flashdrive boot device. Allows a booting choice of either using your system's 'grub.cfg' or a direct kernel boot.
It's often easier to fix Grub problems from within a running system.
Install UEFI and Legacy Grub to a flashdrive.
Format a flashdrive to fat32 and set the 'boot' and 'esp' flags. Note: Don't use GPT here. "USB Stick Formatter" ("Mintstick") is normally fine for this but I would recommend using Gparted for everything.
Edit 10/05/21 . I've found that with some flashdrives that you cannot set the 'boot' and 'esp' flags unless the partition & filesystem has been created with Gparted.
IMPORTANT: Use 'gparted' for this... 'Device', 'Create partition table'. Chooses 'msdos' and 'Apply'. 'Partition', 'New'. Select 'Fat32' and click 'Add'.
'Edit', 'Apply Operations'. Click on the partition graphic (the box with the text '/dev/sda1') to highlight it. 'Partition', 'Manage flags'. Select 'boot' & 'esp'
and click on close. Close Gparted.
I'll assume here that your flashdrive is seen as 'sda'. Use 'fdisk -l' to check.
Install UEFI and Legacy Grub:
Code: Select all
sudo su
mount /dev/sda1 /mnt
grub-install --boot-directory=/mnt/EFI/boot --efi-directory=/mnt --target=x86_64-efi /dev/sda
grub-install --boot-directory=/mnt/EFI/boot --target=i386-pc /dev/sda
sync
exit
sudo xed /mnt/EFI/boot/grub/grub.cfg
You'll need the filesystem UUID of your Linux installation and the full filenames of your kernel & initrd.
You can create a text file containing these using:
Code: Select all
blkid > myFilenames.txt
ls /boot/vmlinuz* >> myFilenames.txt
ls /boot/initrd* >> myFilenames.txt
The full kernel and initrd file names are similar to: 'vmlinuz-5.11.16-051116-generic' and 'initrd.img-5.11.16-051116-generic'.
Sample 'grub.cfg' using an example UUID and kernel/initrd names.
Code: Select all
menuentry "Boot using the system's grub.cfg." {
search --set=root --fs-uuid e8ab7adf-e4b4-43cc-8c43-bbef6d53f6f1
set prefix=($root)/boot/grub
configfile $prefix/grub.cfg
}
menuentry "Direct kernel boot." {
search --set=root --fs-uuid e8ab7adf-e4b4-43cc-8c43-bbef6d53f6f1
linux /boot/vmlinuz-5.11.16-051116-generic root=UUID=e8ab7adf-e4b4-43cc-8c43-bbef6d53f6f1
initrd /boot/initrd.img-5.11.16-051116-generic
}
menuentry "Direct kernel boot. Kernel & initrd symlink" {
search --set=root --fs-uuid e8ab7adf-e4b4-43cc-8c43-bbef6d53f6f1
linux /boot/vmlinuz root=UUID=e8ab7adf-e4b4-43cc-8c43-bbef6d53f6f1
initrd /boot/initrd
}
Unmount the flashdrive with:
Code: Select all
sudo umount /mnt
Bodge99.