How to Use the command line tool in Linux to manage the KVM Virtual Environment

Source: Internet
Author: User

How to Use the command line tool in Linux to manage the KVM Virtual Environment

In the fourth part of our KVM series, we will discuss how to manage the KVM environment on the command line interface. We use the 'virt-install' and virsh command line tools to create and configure virtual machines and storage pools, and use the qemu-img command line tool to create and manage Disk Images.

KVM Management in Linux

There are no new concepts in this article. We just use the command line tool to repeat what we have done before, and there are no preconditions. They are all the same process, we have discussed this in previous articles.

Step 1: configure the storage pool

The Virsh command line tool is a user interface for managing virsh customer domains. The virsh program can run the given command and its parameters in the command line.

In this section, we use it to create a storage pool for our KVM environment. For more information about this tool, use the following command.

# man virsh

1. Use the virsh command with pool-define-as to define a new storage pool. You need to specify the name, type, and type parameters.

In this example, the name is Spool1 and the type is directory. By default, You can provide five parameters for this type:

  • Source-host
  • Source-path
  • Source-dev
  • Source-name
  • Target

For the directory type, we need to use the last parameter "target" to specify the path of the storage pool. Other parameter items can be filled.

# virsh pool-define-as Spool1 dir - - - - "/mnt/personal-data/SPool1/"

Create a new storage pool

2. view all our storage pools in the environment. Run the following command.

# virsh pool-list --all

List all storage pools

3. Now we have constructed the storage pool. Use the following command to construct the storage pool we just defined.

# virsh pool-build Spool1

Create a storage pool

4. Use the virsh command with the pool-start parameter to activate and start the storage pool we just created and constructed.

# virsh pool-start Spool1

Activate storage pool

5. view the status of the storage pool in the environment. Run the following command.

# virsh pool-list --all

View storage pool status

You will find that the Spool1 status has changed to activated.

6. Configure Spool1 so that it can be automatically started by the libmongod service each time.

# virsh pool-autostart Spool1

Configure the KVM storage pool

7. Finally, let's take a look at the information of our new storage pool.

# virsh pool-info Spool1

View KVM storage pool information

Congratulations! Spool1 is ready for use. Next we will try to create a storage volume to use it.

Step 2: configure the storage volume/disk image

Now it's time to create a disk image. Use the qemu-img command to create a new disk image in Spool1. For more details, see the man manual.

# man qemu-img

8. We should specify "create, check,…" after the qemu-img command ,..." Operation, disk image format, path and size of the disk image you want to create.

# qemu-img create -f raw /mnt/personal-data/SPool1/SVol1.img 10G

Create a storage volume

9. You can obtain some information about your new disk image by using the qemu-img command with info.

View storage volume information

Warning do not use the qemu-img command to modify the image being used by a running Virtual Machine or any other process. The image will be damaged.

Now it is time to create a virtual machine.

Step 3: Create a VM

10. Now the last step is complete. In the last step, we will use the virt-install command to create a virtual machine. Virt-install is a command line tool used to create a new KVM virtual machine. It uses the "libvirt" Management Library. For more details, see the man manual.

# man virt-install

To create a new KVM virtual machine, you need to use commands with all the following information.

  • Name: Name of the VM.
  • Disk Location: the Location of the Disk image.
  • Graphics: how to connect to a VM, usually SPICE.
  • Vcpu: Number of virtual CPUs.
  • Ram: The size of allocated memory in megabytes.
  • Location: Specifies the installation Source Path.
  • Network: Specifies the virtual Network, usually the virbr0 bridge.

    Virt-install -- name = rhel7 -- disk path =/mnt/personal-data/SPool1/SVol1.img -- graphics spice -- vcpu = 1 -- ram = 1024 -- location =/run/media/ dos/9e6f605a-f502-4e98-826e-e6376caea288/rhel-server-7.0-x86_64-dvd.iso -- network bridge = virbr0

Create a new Virtual Machine

11. You will see a pop-up virt-vierwer window, as if you are communicating with the virtual machine through it.

Virtual Machine Startup Program

Virtual Machine Installation Process

Conclusion

The above is the last part of our KVM tutorial. Of course we haven't completely covered all of them yet. We just played a side ball, so now it's your turn to make good use of these rich resources to do what you want to do.

  • KVM Getting Started Guide
  • KVM Virtualization Deployment and Administration Guide

-------------------------------------- Split line --------------------------------------

How to add a hard disk for a Linux Virtual Machine in KVM

Getting started with Linux: KVM for Virtual Machine experience

RHEL6 KVM virtualization creates a bridge NIC-Bridge

RedHat Linux KVM Virtual Machine bridging

Installation/bridging settings of KVM in CentOS 5.6/virtual machine creation and operation

The/bin/qemu-KVM problem cannot be found when the kvm virtual machine is installed with libvirt In Ubuntu.

Install and configure the KVM Virtual Machine in RedHat6.5

-------------------------------------- Split line --------------------------------------

This article permanently updates the link address:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.