How to Manage KVM Virtual Environments with Command Line Tools in Linux

  

There is no new concept in this article. We just use command line tools to repeat what we have done before. There are no preconditions, they are all the same. The process, we have discussed the previous articles.

Step 1: Configure the storage pool

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

In this section, we will use it to create a storage pool for our KVM environment. To find out more about this tool, use the following command.

# man virsh

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

In this example, we take the name as Spool1 and the type is the directory. By default you can provide five parameters to this type:

  • source-host
  • source-path
  • source-dev
  • source -name
  • target

    For the directory type, we need to specify the path of the storage pool with the last parameter <;target”, we can use other parameters (“-” To fill.

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


    Create a new storage pool
    >

    2. To view all of our storage pools in the environment, use the following command.

    # virsh pool-list --all


    List all storage pools

    3. Now let’s construct the storage pool. Use the following command to construct the storage pool we just defined.

    # virsh pool-build Spool1


    Constructing 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


    Activating a Storage Pool

    5. To view the status of a storage pool in your environment, use the following command.

    # virsh pool-list --all


    View storage pool status

    You will find that the status of Spool1 has become activated .

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

    # virsh pool-autostart Spool1


    Configuring KVM Storage Pools

    7. Finally, take a look at our new storage pool information. Let's go.

    # virsh pool-info Spool1


    View KVM Storage Pool Information

    Congratulations, Spool1 is ready to go, then we Try creating a storage volume to use it.

    Step 2: Configure Storage Volume/Disk Image

    Now it's time to disk image, create a new disk image in Spool1 with the qemu-img command. For more details, check out the man page.

    # man qemu-img

    8. We should specify the operation after the qemu-img command, create, check, … & rdquo; and so on, the disk image format, the disk image you want to create Path and size.

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


    Creating a Storage Volume

    9. By using the qemu-img command with info, you can get some information about your new disk image.


    View Storage Volume Information

    Warning: Do not use the qemu-img command to modify a running virtual machine or any other process. The image used, the image will be destroyed.

    It's time to create a virtual machine.

    Step 3: Create a virtual machine

    10. Now to the last step, in the final step, we will use the virt-install command to create a virtual machine. Virt-install is a command-line tool for creating new KVM virtual machines that uses the “libvirt” hypervisor library. For more details, you can also check out the man page.

    # man virt-install

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

  • Name: The name of the virtual machine.
  • Disk Location: The location of the disk image.
  • Graphics : How to connect to a VM, usually SPICE.
  • vcpu : The number of virtual CPUs.
  • ram : The amount of allocated memory in megabytes.
  • Location : Specify the installation source path.
  • Network : Specifies a virtual network, usually a virbr0 bridge.

    virt-install –name=rhel7 –disk path=/mnt/personal-data/SPool1/SVol1.img –graphics spice –vcpu=1 –ram=

  • Copyright © Windows knowledge All Rights Reserved