User:Hackbyte/Memtest from EFI boot selection

From Funtoo
Jump to: navigation, search

How to create a MemTest boot option directly as EFI Boot Entry.

The idea is to have Package:Memtest86+ available direct from your BIOS even before grub is loaded, or if you directly boot EFI stub kernel without grub at all. So you can select it by going to the boot selection menu (like with pressing F-8 at initialisation time).

You need to download memtest directly from the homepage, that way you can get a newer free to use version than usual repos are allowed to provide.

You can find it here: https://www.memtest86.com/downloads/memtest86-usb.zip

After that, unzip it into a folder and cd in to there.

Now we need to open the included .img file (which you normally just would write on to a usb drive) to grab some of it's contents. The easiest way is to use Linux Loop Mount capabilities.

But there could be a catch. If your loop module is configured with max_part=0, you can not simply connect the image file to a loop device and access it's contents like a cdrom or partition image, because it is actually a whole disk image including it's own GPT partition header.

So, especially in that case, we need to "address" a specific "sector" within the image.

see (thx krish!!) https://www.yosoygames.com.ar/wp/2020/03/installing-memtest86-on-uefi-grub2-ubuntu/ (https://www.linuxquestions.org/questions/linux-general-1/how-to-mount-img-file-882386/ ## old)


Get your memtest86-usb.img online as loop device like:

root # mount -o loop,offset=263192576 /home/user/opt/memtest/memtest86-usb.img /mnt/memtest/

copy over everything from:

user $ ls -la /mnt/memtest/EFI/BOOT/
total 4684
drwxr-xr-x 3 root root    4096 May  7 23:38 .
drwxr-xr-x 3 root root    4096 May  7 23:38 ..
-rwxr-xr-x 1 root root 1144864 May  7 23:38 BOOTIA32.efi
-rwxr-xr-x 1 root root 1260640 May  7 23:38 BOOTX64.efi
drwxr-xr-x 2 root root    4096 May  7 23:38 Benchmark
-rwxr-xr-x 1 root root    4181 May  7 23:38 blacklist.cfg
-rwxr-xr-x 1 root root    6823 May  7 23:38 mt86.png
-rwxr-xr-x 1 root root 2358510 May  7 23:38 unifont.bin

to your /boot/EFI/memtest dir

like:

root # mkdir /boot/EFI/memtest
root # cp -r /mnt/memtest/EFI/BOOT/ /boot/EFI/memtest


afterwards you need to add your memtest to your (U)EFI boot menu using efibootmgr like this:

root # efibootmgr -c -d /dev/sda -p 1 -L "memtest"  -l "\EFI\memtest\BOOTX64.efi"


Now you should find a new "memtest" boot entry in your UEFI setup which you can select to boot and have memtest at hand, whenever you need it. ;)