WhatsApp Group

The next version of Ubuntu is here!

Sunday, 4 November 2018

How to configure Base System for KVM based Virtual machine and installing VM In Ubuntu 18.04


Call Sysadmin: *****************************************************************************************************
How to configure Base System for KVM based Virtual machine and installing VM In Ubuntu 18.04

Requirements:

1. Ubuntu 18.04 LTS 64 bit Desktop System (you can use server too).
2. Minimum 8GiB RAM, 1TiB HDD and I/O MMU virtualization (AMD-Vi and Intel VT-d) Chipset.
3. Gigabyte Ethernet Adapter.

Verifying Hardware

Open a terminal and insert this command:

# lscpu

In Output,if showing Virtualization: VT-x, then your Hardware support Virtualization.


Installing required packages in base system:

Open a terminal and insert these commands:

# apt-get update
#apt-get upgrade -y
#apt-get install qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils tightvncserver -y

Now Configure Bridge Network
For this, open a file /etc/network/interfaces

# vim /etc/network/interfaces

auto lo
iface lo inet loopback
#####################
auto lo
iface lo inet loopback
auto br0
iface br0 inet static
address YOUR IP ADDRESS
netmask YOUR SUBNET MASK
network YOUR NETWORK
broadcast LAST IP ADDRESS OF YOUR NETWORK
gateway YOUR GATEWAY
dns-nameservers 8.8.8.8
bridge_ports YOUR ETHERNET ADAPTER NAME
bridge_stp off
bridge_maxwait 0

Now create directories then create qcow2 file (Disk) and xml file.

# mkdir ~/vm; ~/vm/qcow2; ~/vm/xml
# qemu-img create -f qcow2 disk.qcow2 125G
Create a xml file for defining your Virtual system:

# vim ~/vm/xml/first_vm.xml

[domain type='kvm']
[name]first_vm[/name]
[uuid]d846fc14-c72a-3a38-8c8c-113f1e9a1002[/uuid]
[memory unit='KiB']4194304[/memory]
[currentMemory unit='KiB']4194304[/currentMemory]
[vcpu placement='static']2[/vcpu]
[os]
[type arch='x86_64' machine='pc-i440fx-bionicbeaver']hvm[/type]
[boot dev='cdrom'/]
[boot dev='hd'/]
[/os]
[features]
[acpi/]
[/features]
[clock offset='utc'/]
[on_poweroff]destroy[/on_poweroff]
[on_reboot]restart[/on_reboot]
[on_crash]destroy[/on_crash]
[devices]
[emulator]/usr/bin/kvm[/emulator]
[disk type='file' device='disk']
[driver name='qemu' type='qcow2'/]
[source file='/home/linux4it/vm/disk/disk.qcow2'/]
[target dev='hda' bus='ide'/]
[address type='drive' controller='0' bus='0' target='0' unit='0'/]
[/disk]
[disk type='file' device='cdrom']
[driver name='qemu' type='raw'/]
[source file='/home/linux4it/Ubuntu-18.04-LTS-Server.iso'/]
[target dev='hdc' bus='ide'/]
[readonly/]
[address type='drive' controller='0' bus='1' target='0' unit='0'/]
[/disk]
[controller type='usb' index='0' model='piix3-uhci']
[address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/]
[/controller]
[controller type='pci' index='0' model='pci-root'/]
[controller type='ide' index='0']
[address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/]
[/controller]
[interface type='bridge']
[mac address='aa:54:6d:64:7a:a8'/]
[source bridge='br0'/]
[model type='rtl8139'/]
[address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/]
[/interface]
[input type='mouse' bus='ps2'/]
[input type='keyboard' bus='ps2'/]
[graphics type='vnc' port='-1' autoport='yes' listen='0.0.0.0']
[listen type='address' address='0.0.0.0'/]
[/graphics]
[video]
[model type='cirrus' vram='16384' heads='1' primary='yes'/]
[address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/]
[/video]
[memballoon model='virtio']
[address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/]
[/memballoon]
[/devices]
[/domain]


Use "<" and ">" in place of "[" and "]" in your xml file


For Youtube Video(Installing Package and configuring Bridge Network), Click here


For Youtube Video(Creating qcow2 file), Click here


For Youtube Video(Creating xml file -Part1), Click here

For Youtube Video(Creating xml file -Part2), Click here

Now define xml file.

# virsh define [PATH OF YOUR XML FILE]


For Youtube Video(Define your xml file and start your VM - Part-01), Click here

For Youtube Video(Define your xml file and start your VM - Part-02), Click here

Now Boot your VM through ISO file and install the OS (Ubunru 18.04 LTS 64 bit Server).

Open your running VM through VNC Viewer:
# vncviewer [YOUR BASE SYSTEM IP:5900]
Now follow the onscreen instructions
All processes are shown in below linked youtube videos.

For Youtube Video(Installing your VM - Part-01), Click here

For Youtube Video(Installing your VM - Part-02), Click here

For Youtube Video(Installing your VM - Part-03), Click here

After finishing the VM installation, destroy your running VM by using this command:
# virsh destroy [YOUR RUNNING VM NAME]
Now remove CD drive from your defined xml file, by removing mentioned file and boot record.
# vim /etc/libvirt/qemu/[YOUR DEFINED XML FILE NAME]

[domain type='kvm']
[name]first_vm[/name]
[uuid]d846fc14-c72a-3a38-8c8c-113f1e9a1002[/uuid]
[memory unit='KiB']4194304[/memory]
[currentMemory unit='KiB']4194304[/currentMemory]
[vcpu placement='static']2[/vcpu]
[os]
[type arch='x86_64' machine='pc-i440fx-bionicbeaver']hvm[/type]
[boot dev='cdrom'/]
[boot dev='hd'/]
[/os]
[features]
[acpi/]
[/features]
[clock offset='utc'/]
[on_poweroff]destroy[/on_poweroff]
[on_reboot]restart[/on_reboot]
[on_crash]destroy[/on_crash]
[devices]
[emulator]/usr/bin/kvm[/emulator]
[disk type='file' device='disk']
[driver name='qemu' type='qcow2'/]
[source file='/home/linux4it/vm/disk/disk.qcow2'/]
[target dev='hda' bus='ide'/]
[address type='drive' controller='0' bus='0' target='0' unit='0'/]
[/disk]
[disk type='file' device='cdrom']
[driver name='qemu' type='raw'/]
[source file='/home/linux4it/Ubuntu-18.04-LTS-Server.iso'/]
[target dev='hdc' bus='ide'/]
[readonly/]
[address type='drive' controller='0' bus='1' target='0' unit='0'/]
[/disk]

[controller type='usb' index='0' model='piix3-uhci']
[address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/]
[/controller]
[controller type='pci' index='0' model='pci-root'/]
[controller type='ide' index='0']
[address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/]
[/controller]
[interface type='bridge']
[mac address='aa:54:6d:64:7a:a8'/]
[source bridge='br0'/]
[model type='rtl8139'/]
[address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/]
[/interface]
[input type='mouse' bus='ps2'/]
[input type='keyboard' bus='ps2'/]
[graphics type='vnc' port='-1' autoport='yes' listen='0.0.0.0']
[listen type='address' address='0.0.0.0'/]
[/graphics]
[video]
[model type='cirrus' vram='16384' heads='1' primary='yes'/]
[address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/]
[/video]
[memballoon model='virtio']
[address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/]
[/memballoon]
[/devices]
[/domain]

In above mentioned file, remove RED contents from your defined file and save it.

Now again define your saved XML file and start your vm

# virsh define /etc/libvirt/qemu/[YOUR DEFINED XML FILE NAME]

# virsh start [YOUR DEFINED VM NAME]

For Youtube Video, Click here

Hence You can use your installed VM.

********************************************************************

आप हमें YouTube पर भी, देख और सुन सकतें हैं।
मेरे YouTube Chanel को देखने हेतु, यहाँ click करें।
आपकी टिप्पणियाँ और सुझाव की,मैं सराहना करता हूँ।
आप मुझे,ajay.karn@gmail.com पर लिख सकते हैं।


HOME





© Ajay Kumar Karn-2018-19



No comments:

Post a Comment