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 -L 50G -n ljunix.vmserver-1 kvm
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,
Creates a bridge between the Guest machine and Host machine.
--hvm
Hardware-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.
To list the VM's and its states in your hypervisor use the below command.
$ virsh list --all
[jhony@ljunix~]$ virsh list --all
Id Name State
----------------------------------------------------
1 ljunix.vmserver-1 running
- ljunix.vmserver-2 shut off
3 ljunix.vmserver-3 running
- ljunix.vmserver-4 shut off
To start a VM use the below command,
$ virsh start VM_Name
[jhony@ljunix~]$ virsh start ljunix.vmserver-2
Domain ljunix.vmserver-2 started
To stop a VM use the below command,
$ virsh shutdown VM_Name
[jhony@ljunix~]$ virsh shutdown ljunix.vmserver-3
Domain ljunix.vmserver-3 is being shutdown
[jhony@ljunix~]$ virsh list --all
Id Name State
----------------------------------------------------
1 ljunix.vmserver-1 running
5 ljunix.vmserver-2 running
- ljunix.vmserver-3 shut off
- ljunix.vmserver-4 shut off
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.
$ virsh undefine VM_Name
[jhony@ljunix~]$ virsh undefine ljunix.vmserver-3
Domain ljunix.vmserver-3 has been undefined
[jhony@ljunix~]$ virsh list --all
Id Name State
----------------------------------------------------
1 ljunix.vmserver-1 running
5 ljunix.vmserver-2 running
- ljunix.vmserver-4 shut off
We can release the logical volume used by the destroyed VM using lvremove command.
$ lvremove path_to_the_logical_volume
[jhony@ljunix~]$ lvremove /dev/kvm/ljunix.vmserver-3
Do you really want to remove active logical volume kubemaster3? [y/n]: y
Logical volume "kubemaster3" successfully removed
Comments