Skip to content

Instantly share code, notes, and snippets.

@ljjjustin
Created March 1, 2019 12:14
Show Gist options
  • Save ljjjustin/3cf6dd1c8789000d8d85eade6a68362b to your computer and use it in GitHub Desktop.
Save ljjjustin/3cf6dd1c8789000d8d85eade6a68362b to your computer and use it in GitHub Desktop.
add vdb to vm
#!/bin/bash
pushd /var/lib/libvirt/images &> /dev/null
for vm in $(virsh list --all | grep win2008 | awk '{print $2}')
do
disk_path="${vm}-vdb.qcow2"
if [ ! -e ${disk_path} ]; then
qemu-img create -f qcow2 ${disk_path} 200G
fi
if virsh domblklist ${vm} | grep -w vdb; then
continue
fi
virsh attach-disk ${vm} --driver qemu --subdriver qcow2 \
--source /var/lib/libvirt/images/${disk_path} --target vdb --persistent
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment