0

I'm using Ubuntu 22.04 LTS, which came with memtest86+ v5 that does not support UEFI.

I'm trying to install memtest86+ v6 on Ubuntu 22.04 LTS and I downloaded its binary here.

I moved memtest64.efi to the EFI partition and added the following to /etc/grub.d/40_custom

menuentry 'Memtest86+ v6' {
  insmod part_gpt
  insmod fat
  set root='hd0,gpt1'
  chainloader (\$root)/EFI/memtest64.efi
}

Then ran update-grub. The entry showed on boot menu, but when I enter it:

Error: No Server is Specified

From GRUB console, I'm certain that hd0,gpt1 is the EFI partition.

Alternatively, I want GRUB to boot Memtest86+ from /boot folder, but I have no idea how to make GRUB find /boot.

******@Ubuntu-Portable:~$ sudo lsblk -o +fstype
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS            FSTYPE
sda           8:0    0 953.9G  0 disk                        
├─sda1        8:1    0   476M  0 part /boot/efi              vfat
├─sda2        8:2    0   250G  0 part /                      ext4
└─sda3        8:3    0 703.4G  0 part /media/****/****       exfat
sr0          11:0    1  1024M  0 rom                         
nvme0n1     259:0    0   128G  0 disk                        
├─nvme0n1p1 259:1    0   200M  0 part                        vfat
├─nvme0n1p2 259:2    0   128M  0 part                        
└─nvme0n1p3 259:3    0 127.7G  0 part                        ntfs

Update: this worked, but I still don't know how to boot from /boot instead of booting from efi partition.

menuentry 'Memtest86+ v6' {
  insmod part_gpt
  insmod fat
  insmod chain
  set root=(hd0,gpt1)
  chainloader /EFI/memtest64.efi
}

To keep things neat, I'd prefer everything done inside /etc/grub.d/40_custom

5
  • Can you enter interactive command mode (c on the menu selection) and verify the paths? set root=(hd0,gpt1) (note the different syntax) followed by ls /EFI/memtest64.efi could give insights.
    – Hermann
    May 18, 2023 at 13:22
  • @Hermann it returned memtest64.efi
    – 7E10FC9A
    May 18, 2023 at 14:01
  • In interactive mode, can you chainload and boot this way?
    – Hermann
    May 18, 2023 at 14:40
  • Your /boot is either a separate filesystem or part of your Linux root filesystem - which one is it? And which filesystem type is it (ext4, xfs, or something else)? The output of lsblk -o +fstype would be very helpful to see.
    – telcoM
    May 19, 2023 at 5:33
  • @telcoM, Linux root, but please note that there might be multiple storage devices with Linux installed on them in the boot environment. If the storage device that host the GRUB is always hd0, then the Linux root is hd0,gpt2
    – 7E10FC9A
    May 19, 2023 at 7:36

2 Answers 2

1

If you want to place your memtest64.efi to /boot instead of the EFI System Partition, something like this might do the job:

menuentry 'Memtest86+ v6' {
  insmod part_gpt
  insmod ext2
  insmod chain
  set root=(hd0,gpt2)
  chainloader /boot/memtest64.efi
}

But as you noted in the comments, this relies on the fact that the storage device is assumed to be (hd0).

When booting BIOS-style, this used to be a good assumption, because on BIOS (i386-pc) architecture version of GRUB, the storage device identifiers like (hd0) normally map directly to BIOS INT 13h disk numbers. In other words, (hd0) refers to disk 0x80.

On BIOS, the only reliable and compatible way to specify the disk to boot from was to rearrange the BIOS disk list to make the desired boot disk be disk 0x80 (and so disk (hd0) for GRUB), so that's what most BIOSes do when you select the disk to boot from; so in effect, on BIOS systems, although there is no universal way to be 100% sure which disk GRUB was started from, (hd0) is a very, very good guess that is almost always correct.

With UEFI, this can no longer be relied on. While some UEFI implementations may do the same, the UEFI systems I personally own don't, and the systems I've seen at work as a sysadmin generally don't seem to do that either.

So, instead of set root=(hd0,<partition ID>), you should use the search command of GRUB.

You could just search for a file in a known path (starting the pathname from the root of the filesystem the file is in, which might or might not be the Linux root filesystem):

search --no-floppy --file --set root /boot/memtest64.efi

Or you could find the UUID of the filesystem in question, and search for it, like most modern versions of grub[2]-mkconfig now do by default:

search --no-floppy --fs-uuid --set root 12345678-9abc-def0-1234-56789abcdef0

The --no-floppy tells GRUB to skip trying to search a floppy disk drive, and --set root causes the search command to set the root variable to point to the filesystem that satisfied the search condition.

So in a nutshell: use lsblk -o +uuid to find the UUID of the filesystem that contains the directory the memtest64.efi is in, then write a 40_custom snippet like this:

menuentry 'Memtest86+ v6' {
  insmod part_gpt
  insmod ext2
  insmod chain
  search --no-floppy --fs-uuid --set root <insert filesystem UUID here>
  chainloader /boot/memtest64.efi
}
2
  • works like charm, thanks! but why the ext2 when the actual filesystem is ext4?
    – 7E10FC9A
    May 19, 2023 at 11:53
  • 1
    ext2/ext3/ext4 filesystem family is backwards compatible to a significant extent, and GRUB's filesystem drivers are read-only (so much simpler than write-capable filesystem drivers). A GRUB driver that was originally developed for ext2 could read ext3 as-is and needed only minor enhancements to also handle ext4 filesystems, so the driver name was not changed. As far as I know, there is no separate ext4 filesystem module for GRUB, because the current ext2 module actually handles all the ext2/3/4 filesystem types sufficiently for boot purposes.
    – telcoM
    May 19, 2023 at 13:17
0

This is pretty much the default GRUB file for an EFI/GPT system:

if loadfont unicode ; then
    set gfxmode=1024x768,800x600,auto
    set gfxpayload=800x600,1024x768
    terminal_output gfxterm
fi

set default=0
set timeout=-1

insmod linux
insmod part_gpt
insmod fat
search --no-floppy --set=root --label "ESP"

menuentry "Start Memtest86+, use built-in support for USB keyboards" {
    linux /EFI/memtest86+/memtest keyboard=both
}
menuentry "Start Memtest86+, use BIOS legacy emulation for USB keyboards" {
    linux /EFI/memtest86+/memtest keyboard=legacy
}
menuentry "Start Memtest86+, disable SMP and memory identification" {
    linux /EFI/memtest86+/memtest nosmp nosm nobench
}
2
  • 1
    This is not the content of 40_custom I'm afraid
    – 7E10FC9A
    May 19, 2023 at 7:18
  • This perfectly works here, so I'm afraid I cannot relate. May 19, 2023 at 9:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .