Some notes on manual operation of KVM/Qemu with open vswitch.
/etc/qemu-ifup:
#!/bin/bash
# logger shows that $1 is only supplied
logger "values = $1 $2 $3 $4 $5"
# a default bridge is set
BRIDGE=ovsbr0
# port name is similar to: tap-deb1-v90 [last digits are a vlan id]
VLAN=`echo $1 | awk '/tap-[A-Za-z0-9]+-v[0-9]+/ {split($0,A,"-"); print substr(A[3],2)}'`
logger "vlan = $VLAN"
ovs-vsctl --may-exist add-br $BRIDGE
if [[ "$VLAN" != "" ]]; then
ovs-vsctl --may-exist add-port $BRIDGE $1 tag=$VLAN
else
ovs-vsctl --may-exist add-port $BRIDGE $1
fi
ip link set dev $1 up
/etc/qemu-ifdown:
#!/bin/bash
# bridge needs to match that of the ifup script
BRIDGE=ovsbr0
ovs-vsctl --if-exists del-port $BRIDGE $1
Create a raw disk image of 8GB. QCow has compression/encryption overhead which isn't necessary in some instances. QEMU/Images references other formats, and describes how to use the loop interface to mount a raw image to view it.
qemu-img create -f raw images/deb1.img 8g
Initial build from a cd and prevent a reboot:
qemu-system-x86_64 \
-drive format=raw,file=images/deb1.img \
-cdrom /home/rpb/Downloads/debian-testing-amd64-netinst.iso \
-no-reboot \
-boot d \
-m 1024 \
-cpu kvm64 \
-name deb1 \
-no-reboot \
-enable-kvm \
-net nic,model=virtio \
-net tap,script=/etc/qemu-ifup,downscript=/etc/qemu-ifdown,ifname=tap-deb1-v90
Subsequent operations can be run without the -cdrom and -no-reboot operations. The ifname will be the interface name as show in 'ip link' and the last two digits are the vlan to be used by the qemu ifup/ifdown scripts.
For disk io optimization in a virtual machine, it is suggested by
Use elevator=noop For Linux Virtual Machines and KVM convert qcow2 disk images to raw disk images for performance to use raw disk images and to set the scheduler to none/noop:
# cat /sys/block/sda/queue/scheduler
[mq-deadline] none
# echo none > /sys/block/sda/queue/scheduler
# cat /sys/block/sda/queue/scheduler
[none] mq-deadline
Putting 'elevator=none' on the kernel command line via '/etc/default/grub' doesn't seem to work for me. Perhaps there is a newer flavour available.
A suggested command to test in qcow2, raw and host mode (generating 1.1GB of data):
dd if=/dev/zero of=test bs=64k count=16k conv=fdatasync
'-ctrl-grab' changes to right-control instead of Ctrl-Alt.
Image file examination commands:
# qemu-img info images/buckeye1.img
image: images/buckeye1.img
file format: raw
virtual size: 8.0G (8589934592 bytes)
disk size: 1.9G
# file images/buckeye1.img
images/buckeye1.img: DOS/MBR boot sector
# fdisk -lu images/buckeye1.img
Disk images/buckeye1.img: 8 GiB, 8589934592 bytes, 16777216 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x6e9340d7
Device Boot Start End Sectors Size Id Type
images/buckeye1.img1 * 2048 14680063 14678016 7G 83 Linux
images/buckeye1.img2 14682110 16775167 2093058 1022M 5 Extended
images/buckeye1.img5 14682112 16775167 2093056 1022M 82 Linux swap / Solaris
Standard Performance Evaluation Corporation: buried in there somewhere should be suggested configurations for guests and hosts.
Block layer statistics in /sys/block//stat: a note for future monitoring