Renaming a Proxmox VE Node 🌱

I recently upgraded my homelab Proxmox host server and wanted to repurpose my existing server to use as a testing environment. Below are the steps I used to rename the old Proxmox instance. These steps worked for me. Please let me know in the comments if you try these steps and any issues arise that I didn't have in my environment.

NOTE: Renaming a node that is part of a cluster is not recommended. These steps are intended for standalone nodes. Always make backups of important VMs before attempting to modify the Proxmox host.

  1. Log into ProxMox VE, either at the console, via SSH or the web UI and launch the web shell
  2. Run the following commands, alternatively you can manually edit each file mentioned with nano or vi and replace the old hostname with the new one
    # set the old hostname and write to ini
    echo "OLD_HOSTNAME=$(hostname)" > ~/pmrename.ini
    # set the new hostname in ini, update as needed
    echo "NEW_HOSTNAME=vm-dev" >> ~/pmrename.ini
    # read variables from ini
    source <(grep = ~/pmrename.ini)
    # edit hostname file
    sed -i.bak "s/$OLD_HOSTNAME/$NEW_HOSTNAME/gi" /etc/hostname
    # edit hosts file
    sed -i.bak "s/$OLD_HOSTNAME/$NEW_HOSTNAME/gi" /etc/hosts
    # edit mailname if it exists
    [ -e "/etc/mailname" ] && sed -i.bak "s/$OLD_HOSTNAME/$NEW_HOSTNAME/gi" /etc/mailname
    # edit if it exists
    [ -e "/etc/postfix/" ] && sed -i.bak "s/$OLD_HOSTNAME/$NEW_HOSTNAME/gi" /etc/postfix/
    # copy config files to new node name
    cp "/var/lib/rrdcached/db/pve2-node/$OLD_HOSTNAME" "/var/lib/rrdcached/db/pve2-node/$NEW_HOSTNAME" -r
    cp "/var/lib/rrdcached/db/pve2-storage/$OLD_HOSTNAME" "/var/lib/rrdcached/db/pve2-storage/$NEW_HOSTNAME" -r
    cp "/var/lib/rrdcached/db/pve2-$OLD_HOSTNAME" "/var/lib/rrdcached/db/pve2-$NEW_HOSTNAME" -r
    # reboot
    reboot now
  3. Wait for the Proxmox host to come back up
  4. Log back in and continue with the following commands
    # read variables from ini
    source <(grep = ~/pmrename.ini)
    # update storage config
    sed -i.bak "s/nodes $OLD_HOSTNAME/nodes $NEW_HOSTNAME/gi" /etc/pve/storage.cfg
    # mv vm configs
    mv /etc/pve/nodes/$OLD_HOSTNAME/qemu-server/*.conf /etc/pve/nodes/$NEW_HOSTNAME/qemu-server/
    # mv ct configs
    mv /etc/pve/nodes/$OLD_HOSTNAME/lxc/*.conf /etc/pve/nodes/$NEW_HOSTNAME/lxc/
  5. Test that Proxmox web UI and all VMs are working as intended

Cleaning Up

  1. After fully testing everything is working, run the following commands to clean up backup files
    # read variables from ini
    source <(grep = ~/pmrename.ini)
    rm /etc/hostname.bak && rm /etc/hosts.bak
    [ -e "/etc/mailname.bak" ] && rm /etc/mailname.bak
    [ -e "/etc/postfix/" ] && rm /etc/postfix/
    rm /var/lib/rrdcached/db/pve2-node/$OLD_HOSTNAME -r
    rm /var/lib/rrdcached/db/pve2-storage/$OLD_HOSTNAME -r
    rm /var/lib/rrdcached/db/pve2-$OLD_HOSTNAME -r
    rm /etc/pve/nodes/$OLD_HOSTNAME -r
    rm /etc/pve/storage.cfg.bak
    rm ~/pmrename.ini