Backup Proxmox server: start KVM at boot

Proxmox is a great virtualization platform which I am using for a few years now and I’m very familiar with it.

I’ve setup a Proxmox HA cluster which works great, but there are situations where cluster is just too much and all you need is a backup Proxmox server sitting there offline waiting to jump-in in case of primary server failure.

At one client I’ve made a setup of two bare metal Proxmox servers, each running it’s own Proxmox software (no cluster mode) with network storage (NAS) and synchronized/duplicated KVM configuration in /etc/pve/qemu-server.

Backup server (proxmox2) is mostly offline (powered off), but sometimes the client powers it up and uses the KVM with some special software, which is only used once/twice a month.

So, I’ve setup a script which runs at startup and checks which KVMs must be run on that server. It searches the KVM config files for a note: “autostart: proxmox2”. If this is found, it starts the KVM. On the primary server the note is: “autostart: proxmox1”.

Here is the script, just save it into /etc/init.d/start-kvm, chmod it 755 and add it to startup (update-rc.d start-kvm defaults). Now go to you Proxmox GUI and add into KVM’s Notes: “autostart: <youserver’s hostname>” (without “”).

#!/bin/sh
### BEGIN INIT INFO
# Provides: start-kvm
# Required-Start:    +iscsi pve-cluster cman clvm $network $local_fs $remote_fs
# Required-Stop:     +iscsi pve-cluster cman clvm $network $local_fs $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start KVMs
### END INIT INFO

case "$1" in
        start)
                HOSTNAME=`/bin/hostname`
                RUNCOUNT=`/bin/grep "autostart%3A ${HOSTNAME}$" /etc/pve/qemu-server/* -l | /usr/bin/wc -l`
                if [ ${RUNCOUNT} -gt 0 ]; then
                        cd /etc/pve/qemu-server
                        VMIDS=`/bin/grep "autostart%3A ${HOSTNAME}$" -l * | /usr/bin/awk -F"." '{print $1}'`
                        for vmid in ${VMIDS}
                        do
                                echo "Starting VM ${vmid}"
                                /usr/sbin/qm start ${vmid}
                        done
                fi
        ;;
        stop)
        ;;
        *)
        ;;
esac
exit 0

If you have a better idea, please use comments below and share…. thank you!

Leave a Reply

Your email address will not be published. Required fields are marked *