Skip to content

Instantly share code, notes, and snippets.

@wmil
Last active May 31, 2023 15:58
Show Gist options
  • Select an option

  • Save wmil/bef82ffc6881c656d9ca1b1ce2268e29 to your computer and use it in GitHub Desktop.

Select an option

Save wmil/bef82ffc6881c656d9ca1b1ce2268e29 to your computer and use it in GitHub Desktop.
Ubuntu Server 22.04 LTS, Stuck at GRUB

Environment

  • Dual boot Windows 11 and Ubuntu
  • Windows 11 is existing, on nvme0n1
  • Ubuntu Server 22.04 LTS is newly installed, on nvme1n1
  • Previously installed (and removed) multiple Linux on nvme1n1

Finding

  • Ubuntu installed shim boot files into existing EFI file system nvme0n1p1
  • The EFI file system is tainted with old boot files from previous installations
  • The installed Ubuntu boot files, especially grub.cfg, is incorrect
  • Ubuntu installed real boot files into /boot aka nvme1n1p2, an ext4 file system partition, with vmlinuz, initrd, GRUB menu, etc.
  • We should have the shim boot files point to the real boot files in /boot

GRUB Shell

# List partitions
ls

# List content in partition
# Note the trailing slash
# Try different partitions, yours may not be (hd3,gpt2)
ls (hd3,gpt2)/
ls (hd3,gpt2)/grub

# Boot from (hd3,gpt2)
set prefix=(hd3,gpt2)/grub
set root=(hd3,gpt2)
insmod linux
insmod normal
normal

Fix

sudo mkdir /mnt/winboot
sudo mount /dev/nvme0n1p1 /mnt/winboot/
cd /mnt/winboot/EFI

# Observe!
ls
efibootmgr

# Remove obsolete EFI entries
sudo rm -rf debian
sudo efibootmgr -Bb 0000

# Show grub.cfg
cat ubuntu/grub.cfg

# Find partition UUID
# Note the UUID for the partition mounted at /boot, to be used in correct grub.cfg
lsblk -o NAME,SIZE,MOUNTPOINT,UUID

# Edit the grub.cfg
sudo vi ubuntu/grub.cfg

Example grub.cfg

search.fs_uuid 00000000-0000-0000-0000-000000000000 root
set prefix=($root)'/grub'
configfile $prefix/grub.cfg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment