diff --git a/README.md b/README.md index 68c40c2..b1a8e2a 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ docker build -t ep-eraser-builder . docker run --rm -v "$PWD:/work" ep-eraser-builder ``` -## VMware/VirtualBox disk +## VMware/VirtualBox images Create a writable monolithic-sparse VMDK from the root ISO with `qemu-img` (`qemu-utils` on Debian): @@ -42,6 +42,16 @@ The script defaults to `ep-eraser-amd64.hybrid.iso` and writes `ep-eraser-amd64. 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`. +Create an ESXi-importable OVA with its own OVF descriptor and stream-optimized disk: + +```sh +./create-ova.sh +``` + +The default output is `ep-eraser-amd64.ova` plus a SHA-256 sidecar. Import it in ESXi with **Deploy OVF Template**; VirtualBox can import the same OVA. The appliance defaults to BIOS boot and 2 CPUs/2 GiB RAM. It runs the same temporary live environment, not an installed persistent OS. Wiping host disks from a VM requires separately attaching the target disk through supported passthrough/RDM; the OVA disk itself is the protected boot medium. Use physical boot media for direct hardware wiping. + +To build the OVA in Docker, use `docker run --rm -v "$PWD:/work" --entrypoint /work/create-ova.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-ova.sh b/create-ova.sh new file mode 100644 index 0000000..fd59a89 --- /dev/null +++ b/create-ova.sh @@ -0,0 +1,155 @@ +#!/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.ova]\n' "$0" + printf 'Defaults: %s/ep-eraser-amd64.hybrid.iso and %s/ep-eraser-amd64.ova\n' "$root" "$root" + exit 0 +fi + +if (( $# > 2 )); then + printf 'Usage: %s [INPUT.iso] [OUTPUT.ova]\n' "$0" >&2 + exit 2 +fi + +input=${1:-"$root/ep-eraser-amd64.hybrid.iso"} +output=${2:-"$root/ep-eraser-amd64.ova"} + +for command_name in qemu-img sha256sum tar stat realpath; do + command -v "$command_name" >/dev/null 2>&1 || { + printf 'ERROR: %s is required.\n' "$command_name" >&2 + exit 1 + } +done +[[ -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 + +input_bytes=$(stat -c %s -- "$input") +if (( input_bytes % 1048576 != 0 )); then + printf 'ERROR: ISO size must be a whole number of MiB for OVF disk capacity.\n' >&2 + exit 1 +fi +disk_capacity_mib=$((input_bytes / 1048576)) + +mkdir -p -- "$(dirname -- "$output")" +temp_dir=$(mktemp -d) +temp_ova="$output.tmp.$$" +temp_checksum="$checksum.tmp.$$" +trap 'rm -rf -- "$temp_dir"; rm -f -- "$temp_ova" "$temp_checksum"' EXIT + +ovf_name=ep-eraser-amd64.ovf +disk_name=ep-eraser-amd64-disk1.vmdk +manifest_name=ep-eraser-amd64.mf +disk_path="$temp_dir/$disk_name" + +qemu-img convert -p -f raw -O vmdk -o subformat=streamOptimized "$input" "$disk_path" +disk_file_bytes=$(stat -c %s -- "$disk_path") + +cat > "$temp_dir/$ovf_name" < + + + + + + Virtual disk information + + + + Logical networks + + Network connection for EP Eraser + + + + EP Eraser live environment + EP Eraser + + 64-bit Linux + Debian Live + + + Virtual hardware requirements + + Virtual Hardware Family + 0 + EP Eraser + vmx-10 + + + hertz * 10^6 + Number of virtual CPUs + 2 virtual CPUs + 1 + 3 + 2 + + + byte * 2^20 + Memory Size + 2048 MB of memory + 2 + 4 + 2048 + + + 0 + SCSI Controller + SCSI Controller 0 + 3 + lsilogic + 6 + + + 0 + EP Eraser live disk + ovf:/disk/disk1 + 4 + 3 + 17 + + + 0 + true + VM Network + Network Adapter 1 + 5 + E1000 + 10 + + + + + +EOF + +ovf_hash=$(sha256sum "$temp_dir/$ovf_name" | awk '{print $1}') +disk_hash=$(sha256sum "$disk_path" | awk '{print $1}') +printf 'SHA256(%s)= %s\nSHA256(%s)= %s\n' "$ovf_name" "$ovf_hash" "$disk_name" "$disk_hash" > "$temp_dir/$manifest_name" + +tar --format=ustar -C "$temp_dir" -cf "$temp_ova" "$ovf_name" "$disk_name" "$manifest_name" +hash=$(sha256sum < "$temp_ova") +printf '%s %s\n' "${hash%% *}" "$(basename -- "$output")" > "$temp_checksum" +mv -- "$temp_ova" "$output" +mv -- "$temp_checksum" "$checksum" +trap - EXIT + +printf 'Created OVA: %s\nSHA-256: %s\n' "$output" "$checksum" \ No newline at end of file