Created
December 21, 2015 00:39
-
-
Save erincerys/0a4336066d680767a7ee to your computer and use it in GitHub Desktop.
Prepare a USB flash drive with syslinux and memtest86+ for RAM testing
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/bash | |
# Install dependencies for creating filesystem and installing bootloader | |
## This script is mostly system-independent, except for this part. Replace yaourt and the args with your own package manager | |
yaourt -S --noconfirm mtools syslinux dosfstools | |
# Plug in the flash drive, and find its device. Don't mount it. | |
lsblk | |
while [[ $(echo $FLASHDEV | grep -c \/dev\/sd[a-z]) -lt 1 && -b "$FLASHDEV" ]] ; do | |
read -p 'Which device (e.g. /dev/sdf)? ' FLASHDEV | |
done | |
# Get the mount point for future use | |
while [[ $(echo $FLASHMOUNT | grep -cE '^\/' -lt 1 && ! -b "$FLASHMOUNT" ]] ; do | |
read -p 'Where to mount (e.g. /media/flash)? ' FLASHDEV | |
done | |
# Write zeros to the flash drive | |
echo '[!] Writing zeros...' | |
dd if=/dev/zero of=$FLASHDEV | |
# Write the partition table | |
## http://xmodulo.com/how-to-run-fdisk-in-non-interactive-batch-mode.html | |
echo '[!] Writing partition table...' | |
echo "n | |
p | |
1 | |
a | |
t | |
6 | |
w | |
"| fdisk $FLASHDEV | |
# Make FAT16 file system | |
echo '[!] Making filesystem...' | |
mkdosfs $FLASHDEV | |
# Write syslinux to flash | |
echo '[!] Writing syslinux...' | |
syslinux $FLASHDEV | |
# Create mount point, mount! | |
mkdir -p $FLASHPOINT | |
mount ${FLASHDEV}1 $FLASHMOUNT | |
# Download memtest86+ bootable binary | |
echo '[!] Downloading Memtest86+ and copying...' | |
wget http://www.memtest.org/download/5.01/memtest86+-5.01.bin.gz | |
gunzip memtest86+-5.01.bin.gz | |
cp memtest86+-5.01.bin $FLASHMOUNT/ | |
# Find and install the MBR for syslinux to flash | |
echo '[!] Writing MBR...' | |
SYSLINUXMBR=`locate mbr.bin | grep \/mbr.bin` | |
dd ibs=440 count=1 f=$SYSLINUXMBR of=$FLASHDEV | |
# Copy modules for presenting the menu, and handling hardware detection | |
echo '[!] Copying modules...' | |
SYSLINUXMODULES=(`locate hdt.c32 | grep \/bios` `locate pci.ids` `locate menu.c32 | grep \/bios\/menu` `locate libutil.c32 | grep \/bios`) | |
i=0 | |
while [ $i -le $((${#SYSLINUXMODULES[@]} - 1)) ] ; do | |
cp ${SYSLINUXMODULES[$i]} ${FLASHMOUNT}/ | |
i=$(($i + 1)) | |
done | |
# Find the flash disk's UUID for syslinux configuration and write it | |
echo '[!] Writing syslinux configuration...' | |
FLASHUUID=$(ls -l /dev/disk/by-uuid | grep `echo $FLASHDEV | cut -d/ -f3` | grep -Po '[A-F0-9]{4}-[A-F0-9]{4}') | |
(cat << EOF | |
DEFAULT 1 | |
PROMPT 0 # Set to 1 if you always want to display the boot: prompt | |
TIMEOUT 30 | |
UI menu.c32 | |
MENU TITLE Memtest86+ | |
MENU COLOR border 30;44 #40ffffff #a0000000 std | |
MENU COLOR title 1;36;44 #9033ccff #a0000000 std | |
MENU COLOR sel 7;37;40 #e0ffffff #20ffffff all | |
MENU COLOR unsel 37;44 #50ffffff #a0000000 std | |
MENU COLOR help 37;40 #c0ffffff #a0000000 std | |
MENU COLOR timeout_msg 37;40 #80ffffff #00000000 std | |
MENU COLOR timeout 1;37;40 #c0ffffff #00000000 std | |
MENU COLOR msg07 37;40 #90ffffff #a0000000 std | |
MENU COLOR tabmsg 31;40 #30ffffff #00000000 std | |
LABEL 1 | |
MENU LABEL MemTest86+ | |
LINUX memtest86+-5.01.bin | |
APPEND root=UUID=$FLASHUUID | |
LABEL hdt | |
MENU LABEL Hardware Info | |
COM32 hdt.c32 | |
LABEL reboot | |
MENU LABEL Reboot | |
COM32 reboot.c32 | |
LABEL poweroff | |
MENU LABEL Poweroff | |
COM32 poweroff.c32 | |
EOF | |
) > ${FLASHMOUNT}/syslinux.cfg | |
# Unmount flash | |
umount $FLASHMOUNT | |
# Move flash over to computer to be tested, and boot! | |
echo '[!] Done!' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment