Skip to content

Instantly share code, notes, and snippets.

@bactisme
Last active February 10, 2017 15:44
Show Gist options
  • Save bactisme/6960a007f68c29af0f96ac9e3330ac24 to your computer and use it in GitHub Desktop.
Save bactisme/6960a007f68c29af0f96ac9e3330ac24 to your computer and use it in GitHub Desktop.
On a proxmox 4.x environnement, this script look for vm and mount their disk on a host mount point
#!/bin/bash
# On proxmox 4.x, with a thinlvm setup, mount all running vm disk
BASE=/mnt
LVM_BASE=/dev/pve
#VMS=$(pct list|grep "running"|cut -d' ' -f1)
VMS=$(pct list|grep -v "VMID"|cut -d' ' -f1)
for VMID in $VMS
do
disk=$(pct config $VMID|grep "rootfs")
d=$(echo \"$disk\"|sed -e 's/.*\(vm-.*\),.*/\1/')
if [ ! -d $BASE/$d ]; then
mkdir $BASE/$d
fi
if mount | grep $BASE/$d > /dev/null; then
echo "!! $BASE/$d already mounted"
else
mount $LVM_BASE/$d $BASE/$d
echo "OK Mount $LVM_BASE/$d on $BASE/$d"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment