Setup KVM with Ubuntu 14.04 in vsphere 6

Untitled Document Setup KVM with Ubuntu 14.04 in vsphere 6
1-install Utuntu
2-Create nested lab configuration file vmx for ESXI 6.0 nested virtualization Hyper-v

ssh to vsphere 6 and add this:
#vim /etc/vmware/config
Add this:
nce.enable = TRUE
hypervisor.cpuid.v0 = FALSE
featMask.vm.hv.capable ="Min:1"
vhv.enable= TRUE

save and exit.

3-Add more hard disk to ubuntu in vsphere size 30GB for vm
then use command format hdd
#mkfs.ext4 /dev/sdb =>formart hdd /dev/sdb for setup VMs
Mount new hdd to /data
#mkdir /data
#mount /dev/sdb /data
=>mount hdd sdb to /data

add auto mount when restart in:

#vim /etc/rc.local

add this text:

/bin/mount /dev/sdb /data/
check verify:
#df -h
it will show this:
/dev/sdb 30G 15G 13G 54% /data
- we increase in vshpere on vm guest first from hdd=30GB to 40GB
-reboot then:
#e2fsck -f /dev/sdb
#resize2fs /dev/sdb

check verify again: #df -h
check it increase or not.

4-Start install KVM
#sudo apt-get install qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils
To check if KVM has successfully been installed, run
#virsh -c qemu:///system list or virsh list
show like this:
Id Name State
----------------------------------------------------
7 xm9181_win7 running


Next we need to set up a network bridge on our server so that our virtual machines can
be accessed from other hosts as if they were physical systems in the network.

#vi /etc/network/interfaces
Before the modification, my file looks as follows:
#This file describes the network interfaces available on your system
#and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.0.100
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
gateway 192.168.0.1
dns-nameservers 8.8.8.8 8.8.4.4
I change it so that it looks like this:
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet manual
auto br0
iface br0 inet static
address 192.168.0.100
network 192.168.0.0
netmask 255.255.255.0
broadcast 192.168.0.255
gateway 192.168.0.1
dns-nameservers 8.8.8.8 8.8.4.4
bridge_ports eth0
bridge_stp off
Restart the network...
#/etc/init.d/networking restart
#ifconfig
root@server1:~# ifconfig

br0 Link encap:Ethernet HWaddr 00:1e:90:f3:f0:02
inet addr:192.168.0.100 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::21e:90ff:fef3:f002/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:29 errors:0 dropped:0 overruns:0 frame:0
TX packets:29 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1934 (1.9 KB) TX bytes:2844 (2.8 KB)

eth0 Link encap:Ethernet HWaddr 00:1e:90:f3:f0:02
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:44613 errors:0 dropped:0 overruns:0 frame:0
TX packets:23445 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:63663064 (63.6 MB) TX bytes:1792940 (1.7 MB)
Interrupt:41 Base address:0xa000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
virbr0 Link encap:Ethernet HWaddr 2a:4a:49:13:de:8f
inet addr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Before we start our first virtual machine, I recommend to reboot the system:
#reboot
we can destroy virbr0 becuase no need to use it:
#rm /etc/libvirt/qemu/networks/autostart/default.xml
If you don't do this, you might get an error like open /dev/kvm: Permission denied in the virtual machine
logs in the /var/log/libvirt/qemu/ directory.
now create hdd size for guest with name xm9181_win7_20g.qcow2

#qemu-img create -f qcow2 -o size=20G /data/sys/xm9181_win7_20g.qcow2
but we need to mount to /mnt/share from samba share iso from this ip,use command:
#mkdir -p /mnt/share
#mount -t cifs -o username=guest,password= //10.105.9.19/share /mnt/share


copy iso file in /mnt/share to /data

#cp /mnt/share/en_window_7_32_64bit.iso /data

Create Spece for VM ,ram,cpu,hdd path,cdrom

#virt-install --name=xm9181_win7 --ram=2048 --vcpus=1 --boot=cdrom \
--os-type windows --os-variant win7 \
--disk path=/data/sys/xm9181_win7_20g.qcow2,device=disk,cache=writeback,format=qcow2,bus=virtio \
--cdrom=/data/en_window_7_32_64bit.iso \
--network network:default,model=virtio \
--vnc --vncport=12345 --vnclisten=0.0.0.0 \
--accelerate --hvm --noautoconsole

=>#virt-install --os-variant list (check --os-variant list)

Afterwards, you can find an XML configuration file for the VM in /etc/libvirt/qemu/ (=> /etc/libvirt/qemu/):
#ls -l /etc/libvirt/qemu/
The disk images are located in the ubuntu-kvm/ subdirectory of our VM directory:
#ls -l /data/sys/
add window7 kvm driver in cdrom when setup because window need driver for detect hdd
#virsh attach-disk xm9181_win7 /data/virtio-win-0.1.102.iso hdc --type cdrom
=>virtio-win-0.1.102.iso we need to download driver for window 7

after detect hdd we need to attach window7.iso for continue setup
#virsh attach-disk xm9181_win7 /data/en_window_7_32_64bit.iso hdc --type cdrom

start guest
#virsh start xm9181_win7
then we need to download tightVNCviewer for remote by host ip and port IPHost:port (10.105.9.180:12345)
if we don't know the port by using netstat -tapn and find qemu-system-x8 program name
and then process setup window 7 if still not detect hdd we need to download kvm driver window 7

after completed setup we need to setup ip 10.105.9.181,gateway,dns in remote vm
but maybe not work yet and we need to edit network in host:
#vim /etc/libvirt/qemu/networks/xm9181_win7.xml
========before================
<interface type='network'>
<mac address='52:54:00:34:b9:74'/>
<source network='default'/>
<model type='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
=========after================
<interface type='bridge'>
<mac address='52:54:00:34:b9:74'/>
<source bridge='br0'/>
<model type='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
===========and then===================
define and restart guest again
#virsh define xm9181_win7.xml

#virsh start xm9181_win7

make autostart vm when host restart

#virsh autostart vm1

if you don't want to vm start when host restart:

#rm /etc/libvirt/qemu/autostart/vm_name

=================================================
Managing A VM
VMs can be managed through virsh, the "virtual shell". To connect to the virtual shell, run

#virsh --connect qemu:///system
This is how the virtual shell looks:
root@server1:~# virsh --connect qemu:///system
Welcome to virsh, the virtualization interactive terminal.
Type: 'help' for help with commands
'quit' to quit
virsh #
You can now type in commands on the virtual shell to manage your VMs.Run to list all command
virsh#help
.........
......
virsh#list --all =>shows all VMs, running and inactive:
Before you start a new VM for the first time, you must define it from its xml file
(located in the /etc/libvirt/qemu/ directory):
#define /etc/libvirt/qemu/vm1.xml
Now you can start the VM:
#start vm1
To stop a VM, run
#shutdown vm1
To immediately stop it (i.e., pull the power plug), run
#destroy vm1
Suspend a VM:
#suspend vm1
Resume a VM:
#resume vm1
These are the most important commands.
#quit
=====================================
https://www.howtoforge.com/virtualization-with-kvm-on-ubuntu-12.04-lts
http://xmodulo.com/use-kvm-command-line-debian-ubuntu.html