A memory tester for the days of UEFI
For the longest time, memtest86+
was a standard for testing sticks of RAM that one suspects may be faulty. I haven't used it in a while, but when I do use it I find that an OS-independent tool (i.e. one that you boot into instead of your normal operating system) is the most reliable way to identify faults with RAM.
It may surprise you, but I've had this post mostly written up for about 2 years...! I remembered about this post recently, and decided to rework some of it and post it here.
Since UEFI was invented (Unified Extensible Firmware Interface) and replaced the traditional BIOS for booting systems around the world, booting memtest86+ suddenly became more challenging, as it is not currently compatible with UEFI. Now, it has been updated to support UEFI though, so I thought I'd write a blog post about it - mainly because there are very rarely guides on booting images like memtest86+ from a multiboot flash drive, like the one I have blogged about before.
Before we begin, worthy of note is memtest86. While it has a very similar name, it is a variant of memtest86+ that is not open source. I have tried it though, and it works well too - brief instructions can be found for it at the end of this blog post.
I will assume that you have already followed my previous guide on setting up a multiboot flash drive. You can find that guide here:
Multi-boot + data + multi-partition = octopus flash drive 2.0?
Alternatively, anywhere you can find a grub config file you can probably follow this guide. I have yet to find an actually decent reference for the grub configuration file language, but if you know of one, please do post it in the comments.
Memtest86+ (the open source one)
Personally, I recommend the open-source Memtest86+. Since the update to version 7.0, it is now compatible with both BIOS and UEFI-based systems without any additional configuration, which is nice. See the above link to one of my previous blog posts if you would like a flash drive that boots both BIOS and UEFI grub at the same time.
To start, visit the official website, and scroll down to the download section. From here, you want to download the "Binary Files (.bin/.efi) For PXE and chainloading" version. Unzip the file you download, and you should see the following files:
memtest32.bin
memtest32.efi
memtest64.bin
memtest64.efi
....discard the files with the .efi
file extension - these are for booting directly instead of being chainloaded by grub. As the names suggest, the ones with 64
in the filename are the ones for 64-bit systems, which includes most systems today. Copy these to the device of your choice, and the open up your relevant grub.cfg
(or equivalent grub configuration file - /etc/default/grub
on an already-installed system) for editing. Then, somewhere in there add the following:
submenu "Memtest86+" {
if loadfont unicode ; then
set gfxmode=1024x768,800x600,auto
set gfxpayload=800x600,1024x768
terminal_output gfxterm
fi
insmod linux
menuentry "[amd64] Start Memtest86+, use built-in support for USB keyboards" {
linux /images/memtest86/memtest64.bin keyboard=both
}
menuentry "[amd64] Start Memtest86+, use BIOS legacy emulation for USB keyboards" {
linux /images/memtest86/memtest64.bin keyboard=legacy
}
menuentry "[amd64] Start Memtest86+, disable SMP and memory identification" {
linux /images/memtest86/memtest64.bin nosmp nosm nobench
}
}
...replace /images/memtest86/memtest64.bin
with the path to the memtest64.bin
(or memtest32.bin
) file, relative to your grub.cfg
file. I forget where I took the above config file from, but I can't find it in my history.
If you are doing this on an installed OS instead of a USB flash drive, then things get a little more complicated. You will need to dig around and find what your version of grub considers paths to be relative to, and put your memtest64.bin
file somewhere nearby. If you have experience with this, then please do leave a comment below.
This should be all you need. For those using a grub setup for an already-installed OS (e.g. via /etc/default/grub
), then you will need to run a command for your changes to take effect:
sudo update-grub
Adding shutdown/reboot/reboot to bios setup/firmware options
Another thing I discovered recently is how to add options to my grub menu to reboot, shutdown, and reboot into firmware settings. rEFInd (an alternative bootloader to grub that I like very much, but I haven't yet explored for booting multiple ISOs on a flash drive) has these in its menus by default, but grub doesn't - so since I discovered how to do it recently I thought I'd include the config here for reference.
Simply add the following somewhere in your grub configuration file:
menuentry "Reboot" {
reboot
}
menuentry "Shut Down" {
halt
}
menuentry "UEFI Firmware / BIOS Settings" {
fwsetup
}
Bonus: Memtest86 (non open-source)
I followed [https://www.yosoygames.com.ar/wp/2020/03/installing-memtest86-on-uefi-grub2-ubuntu/] this guide, but ended up changing a few things, so I'll outline the process here. Again, I'll assume you alreaady have a multiboot flash drive.
Firstly, download memtest86-usb.zip
and extract the contents. Then, find the memtest86-usb.img
file and find the offset of the partition that contains the actual EFI image that is the memtest86 program:
fdisk -lu memtest86-usb.img
Disk memtest86-usb.img: 500 MiB, 524288000 bytes, 1024000 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 68264C0F-858A-49F0-B692-195B64BE4DD7
Device Start End Sectors Size Type
memtest86-usb.img1 2048 512000 509953 249M Microsoft basic data
memtest86-usb.img2 514048 1023966 509919 249M EFI System
Then, take the start position of the second partition (the last line that is highlighted), and multiply it by 512
, the sector size. In my case, the number is 263192576
. Then, mount the partition into a directory you have already created:
sudo mount -o loop,offset=263192576 memtest86-usb.img /absolute/path/to/dir
Then, browse the contents of the mounted partition and copy the EFI/BOOT
directory off to your flash drive, and rename it to memtest86
or something.
Now, update your grub.cfg
and add the following:
menuentry "memtest86" {
chainloader /images/memtest/BOOTX64.efi
}
....replacing /images/memtest/BOOTX64.efi
with the path to the BOOTX64.efi
file that should be directly in the BOOT
directory you copied off.
Finally, you should be able to try it out! Boot into your multiboot flash drive as normal, and then select the memtest86
option from the grub menu.
Extra note: booting from hard drives
This post is really turning into a random grab-bag of items in my grub config file, isn't it? Anyway, An option I don't use all that often (but is very useful when I do need it), are options to boot from the different hard drives in a machine. Since you can't get grub to figure out how many there are in advance, you have to statically define them ahead of time:
submenu "Boot from Hard Drive" {
menuentry "Hard Drive 0" {
set root=(hd0)
chainloader +1
}
menuentry "Hard Drive 1" {
set root=(hd1)
chainloader +1
}
menuentry "Hard Drive 2" {
set root=(hd2)
chainloader +1
}
menuentry "Hard Drive 3" {
set root=(hd3)
chainloader +1
}
}
....chainloading (aka calling another bootloader) is a wonderful thing :P
Of course, expand this as much as you like. I believe this approach also works with specific partitions with the syntax (hd0,X)
, where X
is the partition number starting from 0.
Again, add to your grub.cfg
file and update as above.
Conclusion
This post is more chaotic and disorganised than I expected, but I thought it would be useful to document some of the tweaks I've made to my multiboot flash drive setup over the years - something that has more proven its worth many many times since I first set it up.
We've added a memory (RAM) tester to our setup, using the open-source Memtest86+, and the alternative non-open-source version. We've also added options to reboot, shutdown, and enter the bios/uefi firmware settings.
Finally, we took a quick look at adding options to boot from different hard drives and partitions. If anyone knows how to add a menu item that could allow one to distinguish between different hard disks, partitions, their sizes, and their content more easily, please do leave a comment below.
Sources and further reading
- Answer to Linux on UEFI - how to reboot to the UEFI setup screen like Windows 8 can? on SuperUser, part of the Stack Exchange network
- Answer to How to turn off the computer from the GRUB screen in dual boot on Ask Ubuntu, part of the Stack Exchange network
- memtest86+ (open source version)
- memtest86 (not open source)
- Multi-boot + data + multi-partition = octopus flash drive 2.0?