Changing VMID of a VM

of course there is :)

you can use the CLI tool qmrestore. so if you've made a backup and the archive is called vzdump-qemu-666-2022_02_02-12_25_00.vma.zst then you can restore it to a new VMID:
Code:
qmrestore vzdump-qemu-666-2022_02_02-12_25_00.vma.zst 999

and it should make a new VM with the ID 999.


edit:
you can also do it over the GUI too.
instead of clicking the VM and restoring the backup there, you can click on the storage where you made the backup and restore it to an arbitrary VMID ;)

hope this helps!

Edit: ok I just tried this to test it and works all Backups are still in my backup drive.
Just needed to change my backup scheduler for the new VM ID and all works great thanks

Question?
If you do this via backup as mentioned. What happens to all the other VM backups?
are they still going to be associated with the new VM ID you changed it too ?
Obviously scheduler must be changed to new VM ID. But old backups are still accessible after you delete old VM ?
 
Last edited:
What happens to all the other VM backups?
are they still going to be associated with the new VM ID you changed it too ?
no. restoring the backup to another VM doesn't change the association of the backup file to the old VM.

But old backups are still accessible after you delete old VM ?
yes they should be still located on your backup storage
 
  • Like
Reactions: Spirog
Maybe my experience will be useful to someone. Needed to send backups from multiple servers (not in a cluster) to a single server PBS. I changed this script to suit my situation. The previous script did not work on my proxmox 7.1. And I had to make a massive change. I use only containers.

Bash:
#!/usr/bin/env bash

export oldVMID=$1 newVMID=$2 vgNAME=$3 ;  \
for i in $(lvs -a|grep $vgNAME | awk '{print $1}' | grep $oldVMID); \
do lvrename /dev/$vgNAME/vm-$oldVMID-disk-$(echo $i | awk '{print substr($0,length,1)}') /dev/$vgNAME/vm-$newVMID-disk-$(echo $i | awk '{print substr($0,length,1)}'); done; \

## for VM
#sed -i "s/$oldVMID/$newVMID/g" /etc/pve/qemu-server/$oldVMID.conf; \
#mv /etc/pve/qemu-server/$oldVMID.conf /etc/pve/qemu-server/$newVMID.conf; \

## for CT
sed -i "s/$oldVMID/$newVMID/g" /etc/pve/lxc/$oldVMID.conf; \
mv /etc/pve/lxc/$oldVMID.conf /etc/pve/lxc/$newVMID.conf; \

unset oldVMID newVMID vgNAME;

for a one-time run, you can use (102 to 202)
Bash:
/root/change_vmid.cmd 102 202 pve

for the mass this launch (104-109 to 204-209)
Bash:
for i in {4..9}; do /root/change_vmid.cmd 10$i 20$i pve; done
 
  • Like
Reactions: herzkerl and Spirog
Works like a charm. It boots and works fine.

For the people that asks for the VG, run lvs -a and the second column shows your VG.

Thanks for the script. I've do a sh script from it. It do a search if it's on a volume group. If not, it exits. Only put the old VMID and the New. The script does the rest

Code:
#!/bin/bash

echo Put the VMID to change
read oldVMID
case $oldVMID in
    ''|*[!0-9]*)
        echo bad input. Exiting
        exit;;
    *)
        echo Old VMID - $oldVMID ;;
esac
echo
echo Put the new VMID
read newVMID
case $newVMID in
    ''|*[!0-9]*)
        echo bad input. Exiting
        exit;;
    *)
        echo New VMID - $newVMID ;;
esac
echo

vgNAME="$(lvs --noheadings -o lv_name,vg_name | grep $oldVMID | awk -F ' ' '{print $2}' | uniq -d)"

case $vgNAME in
    "")
        echo Machine not in Volume Group. Exiting
        exit;;
    *)
        echo Volume Group - $vgNAME ;;
esac

for i in $(lvs -a|grep $vgNAME | awk '{print $1}' | grep $oldVMID);
do lvrename $vgNAME/vm-$oldVMID-disk-$(echo $i | awk '{print substr($0,length,1)}') vm-$newVMID-disk-$(echo $i | awk '{print substr($0,length,1)}');
done;
sed -i "s/$oldVMID/$newVMID/g" /etc/pve/qemu-server/$oldVMID.conf;
mv /etc/pve/qemu-server/$oldVMID.conf /etc/pve/qemu-server/$newVMID.conf;

echo Ta-Da!
Can you make this script work with zfs?
 
vim /etc/pve/nodes/proxmox/qemu-server/106.conf
Linea 8: scsi0: local-zfs:vm-104-disk-0,size=60G

Rename the conf file:
mv /etc/pve/nodes/proxmox/qemu-server/106.conf /etc/pve/nodes/proxmox/qemu-server/104.conf

List the ZFS volume or all:
zfs list -t all
...
rpool/data/vm-106-disk-0 1,11G 7,02T 1,10G -
...

Rename it with zfs rename:
zfs rename rpool/data/vm-106-disk-0 rpool/data/vm-104-disk-0

Host restart is not needed
qm start 104
 
Works like a charm. It boots and works fine.

For the people that asks for the VG, run lvs -a and the second column shows your VG.

Thanks for the script. I've do a sh script from it. It do a search if it's on a volume group. If not, it exits. Only put the old VMID and the New. The script does the rest

Code:
#!/bin/bash

echo Put the VMID to change
read oldVMID
case $oldVMID in
    ''|*[!0-9]*)
        echo bad input. Exiting
        exit;;
    *)
        echo Old VMID - $oldVMID ;;
esac
echo
echo Put the new VMID
read newVMID
case $newVMID in
    ''|*[!0-9]*)
        echo bad input. Exiting
        exit;;
    *)
        echo New VMID - $newVMID ;;
esac
echo

vgNAME="$(lvs --noheadings -o lv_name,vg_name | grep $oldVMID | awk -F ' ' '{print $2}' | uniq -d)"

case $vgNAME in
    "")
        echo Machine not in Volume Group. Exiting
        exit;;
    *)
        echo Volume Group - $vgNAME ;;
esac

for i in $(lvs -a|grep $vgNAME | awk '{print $1}' | grep $oldVMID);
do lvrename $vgNAME/vm-$oldVMID-disk-$(echo $i | awk '{print substr($0,length,1)}') vm-$newVMID-disk-$(echo $i | awk '{print substr($0,length,1)}');
done;
sed -i "s/$oldVMID/$newVMID/g" /etc/pve/qemu-server/$oldVMID.conf;
mv /etc/pve/qemu-server/$oldVMID.conf /etc/pve/qemu-server/$newVMID.conf;

echo Ta-Da!

This script works like a charm. I love it, Thank you very much!
 
Maybe my experience will be useful to someone. Needed to send backups from multiple servers (not in a cluster) to a single server PBS. I changed this script to suit my situation. The previous script did not work on my proxmox 7.1. And I had to make a massive change. I use only containers.

Bash:
#!/usr/bin/env bash

export oldVMID=$1 newVMID=$2 vgNAME=$3 ;  \
for i in $(lvs -a|grep $vgNAME | awk '{print $1}' | grep $oldVMID); \
do lvrename /dev/$vgNAME/vm-$oldVMID-disk-$(echo $i | awk '{print substr($0,length,1)}') /dev/$vgNAME/vm-$newVMID-disk-$(echo $i | awk '{print substr($0,length,1)}'); done; \

## for VM
#sed -i "s/$oldVMID/$newVMID/g" /etc/pve/qemu-server/$oldVMID.conf; \
#mv /etc/pve/qemu-server/$oldVMID.conf /etc/pve/qemu-server/$newVMID.conf; \

## for CT
sed -i "s/$oldVMID/$newVMID/g" /etc/pve/lxc/$oldVMID.conf; \
mv /etc/pve/lxc/$oldVMID.conf /etc/pve/lxc/$newVMID.conf; \

unset oldVMID newVMID vgNAME;

for a one-time run, you can use (102 to 202)
Bash:
/root/change_vmid.cmd 102 202 pve

for the mass this launch (104-109 to 204-209)
Bash:
for i in {4..9}; do /root/change_vmid.cmd 10$i 20$i pve; done

hello
I would like to test your script, but i need to create a sh file and copy it to the root folder?
can you explain me better?
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get your own in 60 seconds.

Buy now!