Skip to content

Instantly share code, notes, and snippets.

@plaffitt
Created August 29, 2025 10:06
Show Gist options
  • Save plaffitt/396dd53fda51719a69cf57b592e10275 to your computer and use it in GitHub Desktop.
Save plaffitt/396dd53fda51719a69cf57b592e10275 to your computer and use it in GitHub Desktop.
Setup Ubuntu & MEMTEST86+ with Ventoy
#!/bin/bash
set -euo pipefail
VENTOY_VERSION="${VENTOY_VERSION:-1.1.07}"
MEMTEST_VERSION="${MEMTEST_VERSION:-7.20}"
UBUNTU_VERSION="${UBUNTU_VERSION:-25.04}"
show_help() {
cat <<EOF
Usage: $0 COMMAND [ARGS]
COMMANDS
download Download the specified version
install DEVICE Install Ventoy with Ubuntu and MEMTEST86+ on the specified device (ERASE EVERYTHING!)
update DEVICE Update Ventoy with Ubuntu and MEMTEST86+ on the specified device
--help Show this help message
EOF
}
download() {
mkdir -p bin
pushd bin
echo "--- Downloading Ventoy $VENTOY_VERSION..."
wget --continue "https://freefr.dl.sourceforge.net/project/ventoy/v${VENTOY_VERSION}/ventoy-${VENTOY_VERSION}-linux.tar.gz"
tar -xzf "ventoy-${VENTOY_VERSION}-linux.tar.gz"
echo "--- Downloading MEMTEST86+ $MEMTEST_VERSION..."
wget --continue "https://www.memtest.org/download/v${MEMTEST_VERSION}/mt86plus_${MEMTEST_VERSION}_64.iso.zip"
unzip -o "mt86plus_${MEMTEST_VERSION}_64.iso.zip"
echo "--- Downloading Ubuntu $UBUNTU_VERSION..."
wget --continue "https://releases.ubuntu.com/${UBUNTU_VERSION}/ubuntu-${UBUNTU_VERSION}-desktop-amd64.iso"
popd
}
install() {
local flag="$1"
local device="$2"
mkdir -p mount
if mount | grep -q "${device}1"; then
echo "--- Unmounting ${device}1..."
sudo umount -v "${device}1"
fi
echo "--- Installing Ventoy on $device..."
sudo "./bin/ventoy-${VENTOY_VERSION}/Ventoy2Disk.sh" "$flag" "$device"
sudo mount -v -o "uid=$(id -u),gid=$(id -g)" "${device}1" ./mount
if [[ "$flag" = "-I" ]]; then
echo "--- Creating ubuntu persistence filesystem..."
dd if=/dev/zero of=./mount/ubuntu-persistence.dat bs=1M count=16384 status=progress
mkfs.ext4 -L casper-rw ./mount/ubuntu-persistence.dat
fi
cat >./mount/ventoy.json <<EOF
{
"persistence": [
{
"image": "/ubuntu-${UBUNTU_VERSION}-desktop-amd64.iso",
"backend": "/ubuntu-persistence.dat"
}
]
}
EOF
rsync -avh --info=progress2 ./bin/memtest.iso "./bin/ubuntu-${UBUNTU_VERSION}-desktop-amd64.iso" ./mount
echo "--- Wait until the filesystem is fully unmounted..."
sudo umount -v "${device}1"
rm -d ./mount
}
if [[ $# -eq 0 ]]; then
show_help
exit 1
fi
case "$1" in
download)
download
;;
install)
if [[ $# -lt 2 ]]; then
echo "Error: missing DEVICE"
exit 1
fi
install -I "$2"
;;
update)
if [[ $# -lt 2 ]]; then
echo "Error: missing DEVICE"
exit 1
fi
install -u "$2"
;;
--help | -h)
show_help
;;
*)
echo "Unknown command: $1"
show_help
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment