/etc/systemd/system/.systemctl list-units '*searchterm*' or systemctl list-unit-files '*searchterm*'?#!/bin/bash
echo "=== VM Startup Delay Diagnostic Script ==="
echo "Host: $(hostname)"
echo "Date: $(date)"
echo
###############################################################################
# SECTION 1: Check enabled systemd units that may introduce delays
###############################################################################
echo ">>> Checking enabled systemd units..."
systemctl list-unit-files --state=enabled | grep -Ei "hook|wait|delay|custom|local"
echo
###############################################################################
# SECTION 2: Check systemd unit files for explicit 'sleep' commands
###############################################################################
echo ">>> Searching systemd units for 'sleep' statements..."
grep -Rnw "/etc/systemd" -e "sleep" 2>/dev/null
grep -Rnw "/usr/lib/systemd" -e "sleep" 2>/dev/null
echo
###############################################################################
# SECTION 3: Check scripts that may run on boot
###############################################################################
echo ">>> Searching /usr/local/bin and /root for scripts containing 'sleep'..."
grep -Rnw "/usr/local/bin" -e "sleep" 2>/dev/null
grep -Rnw "/root" -e "sleep" 2>/dev/null
echo
###############################################################################
# SECTION 4: Check cron jobs for delays
###############################################################################
echo ">>> Checking cron for delay-related commands..."
grep -Rnw "/etc/cron" -e "sleep" 2>/dev/null
crontab -l 2>/dev/null | grep -i sleep
echo
###############################################################################
# SECTION 5: Check global and per-VM hook scripts in Proxmox
###############################################################################
echo ">>> Checking Proxmox hookscript references..."
grep -Rnw "/etc/pve" -e "hookscript" 2>/dev/null
echo
echo ">>> Checking hookscript references in VM configurations..."
grep -Rnw "/etc/pve/qemu-server" -e "hookscript" 2>/dev/null
echo
###############################################################################
# SECTION 6: Identify slow systemd services (≥3s startup time)
###############################################################################
echo ">>> Listing slow systemd services..."
systemd-analyze blame | head -20
echo
###############################################################################
# SECTION 7: Check logs for VM-related delays
###############################################################################
echo ">>> Scanning logs for VM startup delays..."
journalctl -u pvedaemon.service --since "today" | grep -Ei "delay|sleep|wait|timeout"
echo
echo "=== Completed diagnostics ==="
echo
We use essential cookies to make this site work, and optional cookies to enhance your experience.