From 597016abdb7d3f2169905a7ebe93ebb1f9a4b674 Mon Sep 17 00:00:00 2001 From: Tero Huttunen Date: Thu, 1 Oct 2026 15:18:33 +0300 Subject: [PATCH] Add script to do vmdk files --- Dockerfile | 2 +- README.md | 12 +++++++++++ create-vmdk.sh | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 create-vmdk.sh diff --git a/Dockerfile b/Dockerfile index 9cc7aed..019e4c1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM debian:trixie RUN apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ - live-build ca-certificates debootstrap xorriso squashfs-tools dosfstools \ + live-build ca-certificates debootstrap xorriso squashfs-tools dosfstools qemu-utils \ && rm -rf /var/lib/apt/lists/* WORKDIR /work diff --git a/README.md b/README.md index 7064b4f..68c40c2 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,18 @@ docker build -t ep-eraser-builder . docker run --rm -v "$PWD:/work" ep-eraser-builder ``` +## VMware/VirtualBox disk + +Create a writable monolithic-sparse VMDK from the root ISO with `qemu-img` (`qemu-utils` on Debian): + +```sh +./create-vmdk.sh +``` + +The script defaults to `ep-eraser-amd64.hybrid.iso` and writes `ep-eraser-amd64.vmdk` plus a SHA-256 sidecar in the project root. You can pass an ISO path and output VMDK path explicitly. The VMDK contains the same live boot image, not an installed OS or persistent live session. Attach it as an existing disk in VMware or VirtualBox; ESXi may require importing it into a datastore with `vmkfstools`. + +The Docker builder includes `qemu-img` too. After building that image, run the converter with `docker run --rm -v "$PWD:/work" --entrypoint /work/create-vmdk.sh ep-eraser-builder`. + ## Use Boot the target machine from the image, inspect the disk list, and choose the exact device path. The program detects rotational media and presents the appropriate operation. Reboot after completion; do not remove the USB device until the result is shown. diff --git a/create-vmdk.sh b/create-vmdk.sh new file mode 100644 index 0000000..c6a9a97 --- /dev/null +++ b/create-vmdk.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env bash +set -Eeuo pipefail + +root=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) + +if [[ "${1:-}" == -h || "${1:-}" == --help ]]; then + printf 'Usage: %s [INPUT.iso] [OUTPUT.vmdk]\n' "$0" + printf 'Defaults: %s/ep-eraser-amd64.hybrid.iso and %s/ep-eraser-amd64.vmdk\n' "$root" "$root" + exit 0 +fi + +if (( $# > 2 )); then + printf 'Usage: %s [INPUT.iso] [OUTPUT.vmdk]\n' "$0" >&2 + exit 2 +fi + +input=${1:-"$root/ep-eraser-amd64.hybrid.iso"} +output=${2:-"$root/ep-eraser-amd64.vmdk"} + +command -v qemu-img >/dev/null 2>&1 || { + printf 'ERROR: qemu-img is required (install qemu-utils).\n' >&2 + exit 1 +} +command -v sha256sum >/dev/null 2>&1 || { + printf 'ERROR: sha256sum is required.\n' >&2 + exit 1 +} +[[ -f "$input" ]] || { + printf 'ERROR: ISO not found: %s\n' "$input" >&2 + exit 1 +} + +input=$(realpath -- "$input") +output=$(realpath -m -- "$output") +checksum="$output.sha256" + +for path in "$output" "$checksum"; do + if [[ -e "$path" || -L "$path" ]]; then + printf 'ERROR: refusing to overwrite existing file: %s\n' "$path" >&2 + exit 1 + fi +done + +mkdir -p -- "$(dirname -- "$output")" +temporary_output="$output.tmp.$$" +temporary_checksum="$checksum.tmp.$$" +trap 'rm -f -- "$temporary_output" "$temporary_checksum"' EXIT + +qemu-img convert -p -f raw -O vmdk -o subformat=monolithicSparse "$input" "$temporary_output" +hash=$(sha256sum < "$temporary_output") +printf '%s %s\n' "${hash%% *}" "$(basename -- "$output")" > "$temporary_checksum" +mv -- "$temporary_output" "$output" +mv -- "$temporary_checksum" "$checksum" +trap - EXIT + +qemu-img info "$output" +printf 'SHA-256: %s\n' "$checksum" \ No newline at end of file