• Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial News Comments FAQ Related Articles

How to Create and Manage KVM Virtual Machine through Command Line in Linux

{{postValue.id}}

To Create and Manage KVM Virtual Machine through Command Line in Linux

In this article we will discuss about creating and Managing virtual machine through command line.

To manage virtual guest machines we use “ virsh” command.

[root@linuxhelp ~]# man virsh

“ virt-install” command used to install the virtual machine.

[root@linuxhelp ~]# man virt-install

“ qemu-img” command is used for creating disk image.

[root@linuxhelp ~]# man qemu-img

Configure the Storage Pool before creating virtual machines, here we are going to store the image file for the virtual machines.
Now run the following command to define storage pool.

[root@linuxhelp ~]# virsh pool-define-as centosvm dir - - - - " /var/lib/libvirt/images/centosvm/" 
Pool centosvm defined

To view the list of created pool storage.

[root@linuxhelp ~]# virsh pool-list --all
Name State Autostart
-----------------------------------------
centosvm inactive no
default active yes

Now run the following command to build the created storage pool.

[root@linuxhelp ~]# virsh pool-build centosvm
Pool centosvm built

Activate the storage pool.

[root@linuxhelp ~]# virsh pool-start centosvm 
Pool centosvm started
[root@linuxhelp ~]# virsh pool-list --all
Name State Autostart
-----------------------------------------
centosvm active no
default active yes

To start the storage pool service automatically, run the autostart command.

[root@linuxhelp ~]# virsh pool-autostart centosvm
Pool centosvm marked as autostarted
[root@linuxhelp ~]# virsh pool-list --all
Name State Autostart
-----------------------------------------
centosvm active yes
default active yes

Now the storage pool is configured. Run the following command to view the information about the storage pool.

[root@linuxhelp ~]# virsh pool-info centosvm 
Name: centosvm 
UUID: 737f134e-ee87-489e-8326-a2c7eaea2526 
State: running 
Persistent: yes 
Autostart: yes 
Capacity: 17.55 GiB 
Allocation: 11.29 GiB 
Available: 6.26 GiB

Create Disk image for the virtual machine.

[root@linuxhelp ~]# qemu-img create -f raw /var/lib/libvirt/images/centosvm.img 10G
Formatting ' /var/lib/libvirt/images/centosvm.img' , fmt=raw size=10737418240

Create a new virtual machine through a command line using virt-install command.
Mention the below options to install the virtual machine.

--name : Name for the virtual machine.
--disk path : Location of disk image.
--graphics spice : To connect to graphical console “ spice”
--vpcu : Number of virtual cpu’ s.
--ram : Amount of ram to allocate for guest.
--location : source path of installation packages.
--network :For virtual network.


Create-Manage-KVM-Virtual-Machine-through-Command-Line-Linux-virt-install

Choose the requirement for the installation and complete the process.
Create-Manage-KVM-Virtual-Machine-through-Command-Line-Linux-requirement

Create-Manage-KVM-Virtual-Machine-through-Command-Line-Linux-configuration

After the virtual machine is created run the following command to view the status of all virtual machines.

[root@linuxhelp ~]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 2     centos7                        running

Run the below command to edit the configuration file located in /etc/libvirt/qemu/centos7.xml

[root@linuxhelp ~]# virsh edit centos7

View the Virtual Machine’ s information, by running the following command.

[root@linuxhelp ~]# virsh dominfo centos7
Id:             2
Name:           centos7
UUID:           23af0e98-cc4b-4e27-a594-301137883bb8
OS Type:        hvm
State:          running
CPU(s):         1
CPU time:       177.5s
Max memory:     1048576 KiB
Used memory:    1048576 KiB
Persistent:     yes
Autostart:      disable
Managed save:   no
Security model: selinux
Security DOI:   0
Security label: system_u:system_r:svirt_t:s0:c19,c176 (enforcing)

To display the CPU and Memory Usage for virtual machines.

[root@linuxhelp ~]# virt-top

Shutdown the virtual machine, by using the following command.

[root@linuxhelp ~]# virsh shutdown (or) turn off centos7
Domain centos7 is being shutdown

To reboot the virtual machine.

[root@linuxhelp ~]# virsh reboot centos7
Domain centos7 is being rebooted

Finally start the virtual machine.

[root@linuxhelp ~]# virsh start centos7
Domain centos7 started

Tags:
connor
Author: 

Comments ( 0 )

No comments available

Add a comment
{{postCtrl.cmtErrMsg}}

Frequently asked questions ( 5 )

Q

How to convert VMware machines to virt-manager?

A

Enable IDE in the registry. Start the machine and execute mergeide.reg. See the ProxMox wiki for very detailed instructions.
Remove VMware tools via the Control Panel.
Please run the followi

Q

Whether the KVM can install on windows?

A

KVM is only for the linux based os

Q

I wanna install KVM on Ubuntu?

A

refer the link as follow for install KVM "https://www.linuxhelp.com/install-kvm-virtualization-extension-ubuntu/"

Q

Why does Qubes use virtualization?

A

We believe that this is currently the only practically viable approach to implementing strong isolation while simultaneously providing compatibility with existing applications and drivers.

Q

How to set Virtual NAT and Route based networking?

A

Any host running the libvirt daemon can manage and create virtual networks. Libvirt virtual networks use firewall rules to act as a router, providing VMs transparent access to the host machin

Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help Luke ?
workbench for debian

I am using workbench in CentOS whereas now I need to use Debian Operating system so could you please help to install and use in Debian?

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.