Kvm notes sandbox: различия между версиями
Zombah (обсуждение | вклад) (add host vnc ssh forward) |
Zombah (обсуждение | вклад) |
||
(не показано 25 промежуточных версий этого же участника) | |||
Строка 1: | Строка 1: | ||
==Good links== | |||
[https://doc.opensuse.org/documentation/leap/virtualization/html/book.virt/book.virt.html openSUSE Guide] <br/> | |||
[https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Virtualization_Administration_Guide/index.html RHEL Guide] <br/> | |||
==Host setup== | |||
Remember to enable virtualization inside bios: <br/> | |||
for hp proliats it is: <br/> | |||
<pre> | |||
Advanced options -> Processor Options -> Intel(R) Virtualization Technology and No-Excecute Memory Protection | |||
</pre> | |||
Install kvm patterns: <br/> | |||
<pre> | |||
# zypper in -t pattern kvm_server | |||
# zypper in -t pattern kvm_tools | |||
# zypper in spice-vdagent | |||
</pre> | |||
===Host IOMMU=== | |||
Add to host cmdline 'GRUB_CMDLINE_LINUX_DEFAULT' in ''/etc/default/grub'' file: <br/> | |||
<pre> | |||
intel_iommu=on console=ttyS0 | |||
</pre> | |||
or for AMD host system: <br/> | |||
<pre> | |||
amd_iommu=on console=ttyS0 | |||
</pre> | |||
===Host I/O Scheduler=== | |||
IBM KVM best practices guide recomends to use Deadline scheduler. <br /> | |||
https://www.ibm.com/support/knowledgecenter/linuxonibm/liaat/liaatbpblockioperf.htm | |||
Add to 'GRUB_CMDLINE_LINUX_DEFAULT' inside ''/etc/default/grub'': <br /> | |||
<pre> | |||
elevator=deadline | |||
</pre> | |||
==Forward kvm host qemu vnc with ssh== | ==Forward kvm host qemu vnc with ssh== | ||
<pre> | <pre> | ||
$ ssh -L 5900:localhost:5900 <kvm-host-ip> -N | $ ssh -L 5900:localhost:5900 <kvm-host-ip> -N | ||
</pre> | |||
==Create guest== | |||
<pre> | |||
virt-install \ | |||
--virt-type kvm \ | |||
--name basebox_opensuse42_2 \ | |||
--description "My basebox openSUSE 42.2" \ | |||
--os-type=Linux \ | |||
--os-variant=opensuse42.2 \ | |||
--ram=2048 --vcpus=2 \ | |||
--disk path=/home/kvm/images/basebox_opensuse42_2.img,device=disk,bus=virtio,size=20,sparse=true,format=raw,cache=none \ | |||
--disk path=/home/kvm/openSUSE-Leap-42.2-DVD-x86_64.iso,device=cdrom \ | |||
--graphics spice,listen=172.16.1.78 \ | |||
--network bridge:br0 | |||
</pre> | |||
==Virsh== | |||
---- | |||
===List all guests even not started=== | |||
<pre> | |||
# virsh list --all | |||
</pre> | |||
===Guest migration=== | |||
Dump config | |||
<pre> | |||
# virsh dumpxml --migratable <guest-name> >guest-name.xml | |||
</pre> | |||
Restore guest config on new host | |||
<pre> | |||
# virsh define guest-name.xml | |||
</pre> | |||
===Edit guest with virsh=== | |||
<pre> | |||
# virsh edit guest-name | |||
</pre> | |||
===Attach block device to guest=== | |||
Create xml config for example vda.xml | |||
<pre> | |||
<disk type='block' device='disk'> | |||
<driver name='qemu' type='raw' cache='none'/> | |||
<source dev='/dev/sda5'/> | |||
<target dev='vda' bus='virtio'/> | |||
</disk> | |||
</pre> | |||
Permanently attach block device to already existing domain | |||
<pre> | |||
# virsh attach-disk <domain-name> vda.xml --persistent | |||
</pre> | |||
===Connect to console with virsh=== | |||
Add serial console to guest, virsh edit guest | |||
<pre> | |||
<devices> | |||
<serial type='pty'> | |||
<target port='0'/> | |||
</serial> | |||
<console type='pty'> | |||
<target type='serial' port='0'/> | |||
</console> | |||
</pre> | |||
connect to guest console: <br/> | |||
<pre> | |||
# virsh console guest-name | |||
</pre> | |||
===Clonning guest=== | |||
It it possible to clone with virsh dumpxml, but dont forget to change uuid, mac and vm name. <br/> | |||
==KVM basebox notes== | |||
# Add console=ttyS0 into bootloader cmdline for virsh console to work. (require syslinux package) | |||
# Install package rsyslog (this probably will remove systemd-logger package) and start rsyslog.service | |||
==Test disk performance== | |||
Test with iozone: <br/> | |||
<pre> | |||
$ iozone -a -i0 -i1 -i2 -s512M -r64k | |||
</pre> | |||
Test with dd: <br/> | |||
<pre> | |||
# dd if=/dev/sda1 of=/dev/null bs=1M count=1024 iflag=direct skip=1024 | |||
# dd if=/dev/zero of=test bs=1M count=1024 oflag=direct | |||
</pre> | </pre> |
Текущая версия от 21:14, 31 октября 2017
Good links
Host setup
Remember to enable virtualization inside bios:
for hp proliats it is:
Advanced options -> Processor Options -> Intel(R) Virtualization Technology and No-Excecute Memory Protection
Install kvm patterns:
# zypper in -t pattern kvm_server # zypper in -t pattern kvm_tools # zypper in spice-vdagent
Host IOMMU
Add to host cmdline 'GRUB_CMDLINE_LINUX_DEFAULT' in /etc/default/grub file:
intel_iommu=on console=ttyS0
or for AMD host system:
amd_iommu=on console=ttyS0
Host I/O Scheduler
IBM KVM best practices guide recomends to use Deadline scheduler.
https://www.ibm.com/support/knowledgecenter/linuxonibm/liaat/liaatbpblockioperf.htm
Add to 'GRUB_CMDLINE_LINUX_DEFAULT' inside /etc/default/grub:
elevator=deadline
Forward kvm host qemu vnc with ssh
$ ssh -L 5900:localhost:5900 <kvm-host-ip> -N
Create guest
virt-install \ --virt-type kvm \ --name basebox_opensuse42_2 \ --description "My basebox openSUSE 42.2" \ --os-type=Linux \ --os-variant=opensuse42.2 \ --ram=2048 --vcpus=2 \ --disk path=/home/kvm/images/basebox_opensuse42_2.img,device=disk,bus=virtio,size=20,sparse=true,format=raw,cache=none \ --disk path=/home/kvm/openSUSE-Leap-42.2-DVD-x86_64.iso,device=cdrom \ --graphics spice,listen=172.16.1.78 \ --network bridge:br0
Virsh
List all guests even not started
# virsh list --all
Guest migration
Dump config
# virsh dumpxml --migratable <guest-name> >guest-name.xml
Restore guest config on new host
# virsh define guest-name.xml
Edit guest with virsh
# virsh edit guest-name
Attach block device to guest
Create xml config for example vda.xml
<disk type='block' device='disk'> <driver name='qemu' type='raw' cache='none'/> <source dev='/dev/sda5'/> <target dev='vda' bus='virtio'/> </disk>
Permanently attach block device to already existing domain
# virsh attach-disk <domain-name> vda.xml --persistent
Connect to console with virsh
Add serial console to guest, virsh edit guest
<devices> <serial type='pty'> <target port='0'/> </serial> <console type='pty'> <target type='serial' port='0'/> </console>
connect to guest console:
# virsh console guest-name
Clonning guest
It it possible to clone with virsh dumpxml, but dont forget to change uuid, mac and vm name.
KVM basebox notes
- Add console=ttyS0 into bootloader cmdline for virsh console to work. (require syslinux package)
- Install package rsyslog (this probably will remove systemd-logger package) and start rsyslog.service
Test disk performance
Test with iozone:
$ iozone -a -i0 -i1 -i2 -s512M -r64k
Test with dd:
# dd if=/dev/sda1 of=/dev/null bs=1M count=1024 iflag=direct skip=1024 # dd if=/dev/zero of=test bs=1M count=1024 oflag=direct