• Categories
    Category
  • Categories
    Category
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial Comments FAQ Related Articles

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

624

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

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

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

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

How to add and remove local storage repository in xenserver
How to add and remove local storage repository in xenserver
Jul 1, 2016
How to Install Proxmox VE in Linux
How to Install Proxmox VE in Linux
Jul 19, 2016
How to Create and Manage KVM Virtual Machine through Command Line in Linux
How to Create and Manage KVM Virtual Machine through Command Line in Linux
Jul 4, 2016
How to install KVM - Virtualization extension in Ubuntu
How to install KVM - Virtualization extension in Ubuntu
Jul 29, 2016
How to create virtual machine in Xenserver using XenCenter tool
How to create virtual machine in Xenserver using XenCenter tool
Jul 2, 2016
How to Migrate Virtual Machines using RHEV clusters
How to Migrate Virtual Machines using RHEV clusters
Jul 15, 2016
How to Setup RedHat Enterprise Virtualization Hypervisor in Linux
How to Setup RedHat Enterprise Virtualization Hypervisor in Linux
Jul 2, 2016
How to Execute PHP Codes in Linux through Command Line
How to Execute PHP Codes in Linux through Command Line
Jun 1, 2016

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

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

KVM
christian class=
Error: No active connection to install on
May 9, 2017
KVM
issacjoseph class=
cannot create a snapshot on kvm
Apr 16, 2018
Virtual memory statistics
william class=
Failed to connect socket to /var/run/libvirt/libvirt-sock: No such file or directory
May 9, 2017
KVM
cameron class=
is it possible to suspend VMs in KVM
May 9, 2017
KVM
dylan class=
qemu-kvm: could not open disk image /CentOS-6.8-x86_64-bin-DVD1.iso: Permission denied
May 9, 2017
KVM
brayden class=
how to shutdown the virtual machine from command-line in KVM
May 8, 2017
KVM
oliver class=
How to check the details of VM in KVM
May 9, 2017
Virtual appliance
elijah class=
How to import Virtual Box VM using VMWare
Nov 20, 2019
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 Ganesh Konka ?
Zentya 6.1 http proxy configuration

please send link for creating zentyal 6.1 for http proxy and firewall as gateway.

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.