Created
October 11, 2021 13:51
-
-
Save mawillcockson/a5b48cb9c76d547ec1029e5c34c71f02 to your computer and use it in GitHub Desktop.
Create bootable memtest86+ USB (doesn't work?) From: https://superuser.com/a/1603573
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -eu | |
leave() { | |
if [ -n "${TMPDIR:+"set"}" ]; then | |
sudo umount "${TMPDIR}" || true | |
rm -rf "${TMPDIR}" | |
unset -v TMPDIR || true | |
fi | |
} | |
trap leave EXIT | |
log() { | |
printf '%s%s\n' "--LOG-- " "$@" | |
} | |
TMPDIR="$(mktemp -d)" | |
echo "temporary directory is ${TMPDIR}" | |
log "Install required tools" | |
sudo apt update | |
sudo apt install -y parted dosfstools gzip tar wget | |
log "Define USB device, memtest86+ version and SYSLINUX version" | |
lsblk | |
echo "enter drive in form of /dev/sdX where X is a letter from a - z" | |
printf '%s' ">> " | |
read -r USB | |
MEM=5.31b | |
SYS=6.03 | |
log "Download URLs" | |
MEMTESTBIN_URL="http://www.memtest.org/download/${MEM}/memtest86+-${MEM}.bin.gz" | |
SYSLINUX_URL="https://www.kernel.org/pub/linux/utils/boot/syslinux/syslinux-${SYS}.tar.xz" | |
log "Partition USB and create 4MB FAT16 filesystem" | |
sudo parted -s "${USB}" mklabel msdos mkpart primary fat16 2048s 5mib set 1 boot on | |
sync; sync; sync | |
sudo mkfs.vfat -nMT86PLUS "${USB}1" | |
mkdir "${TMPDIR}/mount" | |
sudo mount "${USB}1" "${TMPDIR}/mount" | |
log "Download and install memtest86+ binary" | |
wget -qO- "${MEMTESTBIN_URL}" | gzip -d | sudo tee "${TMPDIR}/mount/mt86plus" > /dev/null | |
log "Create SYSLINUX configuration file to start memtest86+ binary" | |
printf '%s' "PROMPT 0 | |
TIMEOUT 0 | |
DEFAULT mt86plus | |
LABEL mt86plus | |
kernel mt86plus | |
" | sudo tee "${TMPDIR}/mount/syslinux.cfg" | |
log "Download SYSLINUX, install MBR code and install SYSLINUX to USB" | |
mkdir "${TMPDIR}/syslinux" | |
wget -qO- "${SYSLINUX_URL}" | tar -xJpf - -C "${TMPDIR}/syslinux" | |
sudo dd bs=440 if="${TMPDIR}/syslinux/syslinux-${SYS}/bios/mbr/mbr.bin" of="${USB}" status=progress | |
sudo "${TMPDIR}/syslinux/syslinux-${SYS}/bios/linux/syslinux" -i -s "${USB}1" | |
sudo umount "${TMPDIR}/mount" | |
log "Cleanup" | |
echo "done!" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment