Creating and Running Virtual Machines in LINUX - KVM - Cli Mode


    In this article we will be seeing how to run multiple virtual machines in our host machine through cli mode.

Creating Logical volume for the Virtual Machine:

    Since the VM needs physical requirements such as Hard-disk, Memory, CPU. We will allocate those from the host machine. For HD we will create a logical volume using the below command,



lvcreate command use to create the logical volume.
-L stands for the size of the HD interms of GB
-n is for the Virtual Machine name.
kvm is the default path for the volumes being stored. The file path is /dev/kvm


Installing the Virtual Machine:

    Now our VM has some physical volume to run the installation, Since our Hypervisor is KVM we will be installing Kernel based virtual machines through virt command.

    virt-install is a command line tool which provides an easy way to provision operating systems into virtual machines.

    The following command will install a Centos 7 machine from the official Centos site,



FlagDescription
--nameName of your VM.
--ramRAM for your VM(in Megabytes).
--vcpusNumber of virtual CPU's.
--disk pathLogical Volume path.
--locationISO Image location.
--vncEnables Virtual Network Computing
--noautoconsoleAuto console will be disabled.
--os-typeProbably Linux.
--networkCreates a bridge between the Guest machine and Host machine.
--hvmHardware-assisted Virtual Machine.

         With the above command we have launched a Centos 7 machine with 2 GB RAM and 2 VCPU's. You can also define different configuration and IOS images.

    The installation runs on the background and to complete the installation you have to use a GUI interface. That can be done using a Virtual Manager for linux users.

    For Centos images click here.

    For Ubuntu images click here.

To list the VM's and its states in your hypervisor use the below command.





To start a VM use the below command,





To stop a VM use the below command,








Deleting a Virtual Machine:

    Before deleting a VM you have to undefine it. The undefine allows you to edit your VM configuration such as Name, RAM, VCPU,etc.,. We will see this is detail on upcoming articles. Use the following command to undefine a VM.







    Now you can delete your VM using destroy command,





    We can release the logical volume used by the destroyed VM using lvremove command.





    Feel free to ask if you have any questions.

Comments

Popular Posts on this blog

How to Install LAMP Stack on Linux - Ubuntu 17.04

Apache Webserver - Installation from source (tar.gz and tar.bz2)

Replacing Commands for Linux Files - Using Perl and Sed

How to install Docker on Ubuntu-17.04

Setting up a Mail server using Roundcube - Part-3 - Centos 7

Blog Top Sites

Blog Log