Automating erase disk


New Member
Jun 1, 2023
I do alot of testing of installs/re-installs that often use lots of vm's.
One of my optimizations in esxi was to just to recreate a empty disk.

gwest@Mac-Pro pocp % cat
ssh "cd /vmfs/volumes/datastore1/$1;rm $1.vmdk;rm $1.vmsd;rm $1-flat.vmdk;vmkfstools --createvirtualdisk 160G --diskformat thin $1.vmdk"
gwest@Mac-Pro pocp %

This gets a bit more fun. As the drive could be either a qcow2 or a lvm drive.
Anyone scripted this? Goal is to just make sure the drive looks empty, and can be done in seconds.
Seems like I need to parse the .conf file, find out if qcow or lvm, and then go from there.

I dont see any qm commands that let me touch drives.
Ok, qcow is trivial:
ssh "qm list | grep $1 | awk '{print \$1}'"

export vmid=$(./ $1)
echo $vmid
export drivepath="/impulse1/images/$vmid/vm-$vmid-disk-0.qcow2"
echo $drivepath
ssh "rm $drivepath"
ssh "qemu-img create -f qcow2 $drivepath $2"

Next step is to and figure out how to choose between automatically.
Getting closer:

Deleting a lvm was trivial
lvremove /dev/pve/vm-700-disk-0 -

But syntax/options for thin disk is avoiding me:
lvcreate -c 512K -L 200G --thinpool vm-700-disk-0 pve
Fixed it:
This will create a lvm after deleting old one.
Now only need to check if lvm or qcow2

export vmid=$(./ $1)
echo $vmid
export lvmname="vm-$vmid-disk-0"
export drivepath="/dev/pve/$lvmname"
echo $drivepath
ssh "lvremove $drivepath -y"
ssh "lvcreate -n $lvmname -V $2 pve/data"


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 yours easily in our online shop.

Buy now!