Skip to content

Instantly share code, notes, and snippets.

@ilude
Last active January 2, 2017 07:38
Show Gist options
  • Select an option

  • Save ilude/28806cb1f980fb7b89ad89c7f79b0329 to your computer and use it in GitHub Desktop.

Select an option

Save ilude/28806cb1f980fb7b89ad89c7f79b0329 to your computer and use it in GitHub Desktop.
KVM Notes
# https://help.ubuntu.com/community/KVM/Installation
sudo apt-get install qemu-kvm libvirt-bin bridge-utils
sudo usermod -a -G libvirtd $USER
sudo systemctl start libvirtd
sudo systemctl enable libvirtd
# autostart on boot
virsh autostart <domain-id>
# change cdrom
virsh change-media db12-dev hdc /pool/iso/VISUALERP800_Install_win.iso
1. Ensure the ACPI is enabled in your virtual machine settings.
2. Login to your Windows guest and launch Group Policy Object Editor (gpedit.msc).
3. Locate the following key and change the settings to enabled.
Computer Configuration\Windows Settings\
Security Settings\Local Policies\Security Options\
Shutdown: Allow system to be shut down without having to log on
4. If you want to be able shutdown guest even there is a logged in user add the following to file ShutdownWarningDialogTimeout.reg and enter it into windows registry.
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows]
"ShutdownWarningDialogTimeout"=dword:00000001
qemu-img create -f qcow2 /pool/vms/db-data.qcow2 200G
qemu-img create -f qcow2 /pool/vms/db-log.qcow2 200G
qemu-img create -f qcow2 /pool/vms/db-backup.qcow2 200G
virsh attach-disk db12-dev --source /pool/vms/db-data.qcow2 --target vdd --type qcow2 --persistent
virsh attach-disk db12-dev --source /pool/vms/db-log.qcow2 --target vde --type qcow2 --persistent
virsh attach-disk db12-dev --source /pool/vms/db-backup.qcow2 --target vdf --type qcow2 --persistent
# on windows guest: run sysprep
C:\Windows\System32\Sysprep\sysprep.exe /generalize /shutdown /oobe
# on host: clone the image
virt-clone --original win12 --name db12-dev --file /pool/vms/db12-dev.qcow2
# set max memory to new value if needed
virsh setmaxmem db12-dev 16G --config
virsh dumpxml db12-dev > /pool/vms/db12-dev.xml
# hardware addresses need to be removed, libvirt will assign new addresses automatically
sed -i /uuid/d /pool/vms/db12-dev.xml
sed -i '/mac address/d' /pool/vms/db12-dev.xml
virsh define /pool/vms/db12-dev.xml
virsh start this-vm
from xml.etree import ElementTree as ET
import sys
import libvirt
conn = libvirt.open()
domain = conn.lookupByName(sys.argv[1])
#get the XML description of the VM
vmXml = domain.XMLDesc(0)
root = ET.fromstring(vmXml)
#get the VNC port
graphics = root.find('./devices/graphics')
port = graphics.get('port')
print port
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment