Last active
May 2, 2025 07:34
-
-
Save NotYusta/2254074e61513cc36fd27b9a3624dd99 to your computer and use it in GitHub Desktop.
Proxmox Automatic Boot Order - <vm-id>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Check if exactly one argument (vm-id) is provided | |
if [ $# -ne 1 ]; then | |
echo "Usage: $0 <vm-id>" | |
exit 1 | |
fi | |
VMID="$1" | |
# Function to set boot order for disks first, then network | |
set_boot_order() { | |
local config_file="/etc/pve/qemu-server/$VMID.conf" | |
# Check if config file exists | |
if [ ! -f "$config_file" ]; then | |
echo "Error: Config file for VMID $VMID not found at $config_file" | |
return 1 | |
fi | |
# Get disks (scsiX) | |
disks=$(grep -oP '^scsi\d+' "$config_file") | |
# Get network interfaces (netX) | |
networks=$(grep -oP '^net\d+' "$config_file") | |
# If no disks or networks found, warn and exit | |
if [ -z "$disks" ]; then | |
echo "Warning: No disks found in $config_file" | |
fi | |
if [ -z "$networks" ]; then | |
echo "Warning: No network interfaces found in $config_file" | |
fi | |
# Start building boot order, disks first | |
boot_order="" | |
# Add disks to boot order | |
for disk in $disks; do | |
boot_order="${boot_order}${disk};" | |
done | |
# Add networks to boot order | |
for net in $networks; do | |
boot_order="${boot_order}${net};" | |
done | |
# Remove trailing semicolon | |
boot_order=${boot_order%;} | |
# Set boot order using qm command | |
echo "Setting boot order for VMID $VMID to: $boot_order" | |
qm set "$VMID" -boot order="$boot_order" | |
} | |
# Execute the boot order setup | |
set_boot_order | |
echo "Boot order set for VMID $VMID." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment