Migrating a Linux KVM machine to VMWare ESX

No comments:
There are several steps to move your linux kvm virtual machine to an VMWare ESX cluster.

The first step after shutting down the kvm instance is to convert its disk format to vmdk format. qemu-img tool makes this step easy.
On the kvm host:
# qemu-img convert -O vmdk kvm-image.img esx-image.vmdk -p

Now the vmdk file must be uploaded to esx host. In order to scp to esx host, sshd daemon must be started.
On esx host:
# service sshd restart
On kvm host:
# scp esx-image.vmdk user@esx-host:/path/to/datastore

It is time to create the esx virtual machine by using the vmdk file:
Using vSphere Client, right click on the desired host and select New Virtual Machine. In the Create New Virtual Machine wizard, select custom configuration. Provide detailed options in the later screens that suits you best. Then later in the Create a Disk screen, select Use an Existing Virtual Disk. Click Browse and navigate to the location of your existing vmdk file. Review the summary then finish.

After running newly created esx virtual machine, it is possible to encounter errors when starting or creating snapshots.
2016-08-18T06:12:50.598Z| vcpu-0| I120: DISKLIB-CHAINESX : ChainESXOpenSubChainNode: can't create multiextent node 7eea123d-esx-image-00001-s001.vmdk failed with error The system cannot find the file specified (0xbad0003, Not found)
2016-08-18T06:12:50.599Z| vcpu-0| I120: DISKLIB-CHAIN : "/vmfs/volumes/54525cc9-bd43329e8-3a47-b2ba3eef754a/esx-image/esx-image-00001.vmdk" : failed to open (The system cannot find the file specified).

That is because your virtual machine disks are of a hosted type. To resolve this issue you should convert virtual disks in hosted format to one of the vmfs formats. Hosted disks end with the -s00x.vmdk extension.

Open a ssh console to the ESXi host. Run this command to load the multiextent module:
# vmkload_mod multiextent
To convert virtual disks in hosted format to the VMFS format:
For a thick disk:
# vmkfstools -i esx-image.vmdk esx-image-new.vmdk -d zeroedthick
Or for a thin disk:
# vmkfstools -i esx-image.vmdk esx-image-new.vmdk -d thin
If conversion successful, Delete the hosted disk:
# vmkfstools -U esx-image.vmdk
Rename the new VMFS disk to the original name:
# vmkfstools -E esx-image-new.vmdk esx-image.vmdk
Unload the multiextent module:
# vmkload_mod -u multiextent

Script for Reporting vCpu Count Currently Running on a KVM Host

No comments:
This script is useful for listing total vcpus assigned to each domain that is currently running on kvm host.

KVM VCpu Pinning With Virsh

No comments:
CPU allocation to virtual guests with KVM Hypervisor can be done in different ways. In my example vcpu placement is static, but no cpuset is specified, so that domain process will be pinned to all the available physical CPUs. I want to change them and pin vcpus to available physical cpus.

Note: The followings are only examples. So give them a try on a test environment by substituting your values.

# virsh dumpxml test_kvm01
<domain type='kvm' id='18'>
<vcpu placement='static'>4</vcpu>

vcpu info can be listed using virsh vcpuinfo command:
# virsh vcpuinfo test_kvm01
CPU: 11
State: running
CPU time: 247454.2s
CPU Affinity: yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy

CPU: 11
State: running
CPU time: 845257.6s
CPU Affinity: yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy

CPU: 53
State: running
CPU time: 237962.2s
CPU Affinity: yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy

CPU: 51
State: running
CPU time: 226221.4s
CPU Affinity: yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy

Current vcpu pinning configuration can be obtained with the following command:
# virsh vcpupin test_kvm01
VCPU: CPU Affinity
0: 0-79
1: 0-79
2: 0-79
3: 0-79

With the same command a vcpu can be pinned to corresponding physical cpu:
# virsh vcpupin test_kvm01 0 10
# virsh vcpupin test_kvm01 1 11
# virsh vcpupin test_kvm01 2 12
# virsh vcpupin test_kvm01 3 13

Mounting ACL enabled File Systems

No comments:
Supporting ACLs for files or directories in which the partition contains must be mounted with the acl option.

# mount -t ext4 -o acl /dev/test_vg0/test_lv0 /test

If you want to make it persistent using /etc/fstab 

/dev/test_vg0/test_lv0 /test   ext4   acl   1 2

/test directory can be accessed via smb or nfs. Both file services support access control lists. When mounting /test from a nfs client noacl option must be used in order to disable ACLs.

Increasing KVM Guest CPU by using virsh

No comments:
First edit configuration xml using virsh edit. virsh edit opens an editor.

# virsh edit test_vm

When editor opens configuration xml, find containing vcpu placement element then change it according to your needs and save it.

<vcpu placement='static'>8</vcpu>

Then shutdown and start your vm:

# virsh shutdown test_vm
# virsh start test_vm

Making KVM Image File Sparse with virt-sparsify

No comments:
Sparse files use disk space more efficiently. Only metadata information is written to disk instead of the empty space that constitutes the block, using less disk space. Sparse term corresponds to thin-provisioned image in the VMware jargon. To sparsify a vm guest image first you shut the guest down. In my KVM Host there is a non-sparse kvm image file which is identified like this:

# ls -lsh
61G -rw-r--r-- 1 qemu qemu 60G Jun 22 08:15 SRVTEST01.img

As seen from the output of the ls command SRVTEST01.img guest image occupies all of the file. To make it sparse:

Sending Jboss Server Logs to Logstash Using Filebeat with Multiline Support

No comments:
In addition to sending system logs to logstash, it is possible to add a prospector section to the filebeat.yml for jboss server logs. Sometimes jboss server.log has single events made up from several lines of messages. In such cases Filebeat should be configured for a multiline prospector.

Filebeat takes lines do not start with a date pattern (look at pattern in the multiline section "^[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}" and negate section is set to true) and combines them with the previous line that starts with a date pattern.

server.log file excerpt where DatePattern: '.'yyyy-MM-dd-HH and ConversionPattern: %d %-5p [%c] %m%n

2014-06-10 00:30:22,452 ERROR [MainDeployer] Could not initialise deployment: file:/Development/jboss-4.2.3.GA/server/default/deploy/jbossws.sar/
java.lang.NoClassDefFoundError: javax/ejb/Stateless
at org.jboss.ejb3.EJB3Util.isStateless(
at org.jboss.ejb3.EJB3Deployer.hasEjbAnnotation(
at org.jboss.ejb3.EJB3Deployer.accepts(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(

Logstash filter: