From b6a4e6a2a6b7c95b5403bbc79500b5298bc97595 Mon Sep 17 00:00:00 2001 From: "CanbiZ (MickLesk)" <47820557+MickLesk@users.noreply.github.com> Date: Wed, 18 Feb 2026 22:06:04 +0100 Subject: [PATCH] OPNSense: add disk space check | increase disk space (#12058) * Fix: Add disk space checking for OPNsense VM FreeBSD image decompression - Add check_disk_space() function to verify available storage - Check for 20GB before download and 15GB before decompression - Provide clear error messages showing available vs required space - Add proper error handling for unxz decompression failures - Clean up compressed .xz file after decompression to save space - Add progress messages for download and decompression steps Fixes issue where script fails at line 611 with 'No space left on device' when /tmp directory lacks sufficient space for ~10-15GB decompressed image. * Increase OPNsense VM disk size from 10GB to 20GB - Provides more space for system updates, logs, and package installations - 20GB is a more appropriate size for OPNsense production use --- vm/opnsense-vm.sh | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/vm/opnsense-vm.sh b/vm/opnsense-vm.sh index 82dceb44e..47a161ce1 100644 --- a/vm/opnsense-vm.sh +++ b/vm/opnsense-vm.sh @@ -91,6 +91,17 @@ function cleanup() { rm -rf $TEMP_DIR } +function check_disk_space() { + local path="$1" + local required_gb="$2" + local available_kb=$(df -k "$path" | awk 'NR==2 {print $4}') + local available_gb=$((available_kb / 1024 / 1024)) + if [ $available_gb -lt $required_gb ]; then + return 1 + fi + return 0 +} + TEMP_DIR=$(mktemp -d) pushd $TEMP_DIR >/dev/null function send_line_to_vm() { @@ -605,11 +616,41 @@ if [ -z "$URL" ]; then exit 1 fi msg_ok "Download URL: ${CL}${BL}${URL}${CL}" + +# Check available disk space (require at least 20GB for safety) +if ! check_disk_space "$TEMP_DIR" 20; then + AVAILABLE_GB=$(df -h "$TEMP_DIR" | awk 'NR==2 {print $4}') + msg_error "Insufficient disk space in temporary directory ($TEMP_DIR)." + msg_error "Available: ${AVAILABLE_GB}, Required: ~20GB for FreeBSD image decompression." + msg_error "Please free up space or ensure /tmp has sufficient storage." + exit 1 +fi + +msg_info "Downloading FreeBSD Image" curl -f#SL -o "$(basename "$URL")" "$URL" echo -en "\e[1A\e[0K" +msg_ok "Downloaded ${CL}${BL}$(basename "$URL")${CL}" + +# Check disk space again before decompression +if ! check_disk_space "$TEMP_DIR" 15; then + AVAILABLE_GB=$(df -h "$TEMP_DIR" | awk 'NR==2 {print $4}') + msg_error "Insufficient disk space for decompression." + msg_error "Available: ${AVAILABLE_GB}, Required: ~15GB for decompressed image." + exit 1 +fi + +msg_info "Decompressing FreeBSD Image (this may take a few minutes)" FILE=FreeBSD.qcow2 -unxz -cv $(basename $URL) >${FILE} -msg_ok "Downloaded ${CL}${BL}${FILE}${CL}" +if ! unxz -cv $(basename $URL) >${FILE}; then + msg_error "Failed to decompress FreeBSD image." + msg_error "This is usually caused by insufficient disk space." + df -h "$TEMP_DIR" + exit 1 +fi + +# Remove the compressed file to save space +rm -f "$(basename "$URL")" +msg_ok "Decompressed ${CL}${BL}${FILE}${CL}" STORAGE_TYPE=$(pvesm status -storage $STORAGE | awk 'NR>1 {print $2}') case $STORAGE_TYPE in @@ -649,7 +690,7 @@ qm set $VMID \ -boot order=scsi0 \ -serial0 socket \ -tags community-script >/dev/null -qm resize $VMID scsi0 10G >/dev/null +qm resize $VMID scsi0 20G >/dev/null DESCRIPTION=$( cat <