Skip to content

Instantly share code, notes, and snippets.

@goffinet
Last active January 30, 2017 16:38
Show Gist options
  • Select an option

  • Save goffinet/e619dbc758d38abd79d98a405ca97ab0 to your computer and use it in GitHub Desktop.

Select an option

Save goffinet/e619dbc758d38abd79d98a405ca97ab0 to your computer and use it in GitHub Desktop.
kvm libvirt add storage
#!/bin/bash
# Variables
guest=$1
disk=/var/lib/libvirt/images/$2.img
# Create 4G Spare Disk with dd
dd if=/dev/zero of=$disk bs=1M seek=4096 count=0
# Or create a qcow2 disk
qemu-img create -f qcow2 -o preallocation=metadata $disk 4G
# Attach the disk on live guest with persistence
virsh attach-disk $guest $disk vdb --cache none --live --persistent
# Detach the disk
virsh detach-disk $guest $disk --persistent --live
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment