Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use command line tools to manage virtual machine environment under Linux system

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article focuses on "how to use command-line tools to manage virtual machine environment under the Linux system". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to manage the virtual machine environment with command-line tools under the Linux system.

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 storage pools for our KVM environment. For more information about this tool, use the following command.

The code is as follows:

# man virsh

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

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

Source-host

Source-path

Source-dev

Source-name

Target

For directory types, we need to specify the path to the storage pool with the last parameter "target", and we can populate the other parameters with "-".

The code is as follows:

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

Create a new storage pool

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

The code is as follows:

# virsh pool-list-all

List all storage pools

3. Now let's construct the storage pool, using the following command to construct the storage pool we just defined.

The code is as follows:

# virsh pool-build Spool1

Construct a storage pool

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

The code is as follows:

# virsh pool-start Spool1

Activate Storage Pool

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

The code is as follows:

# virsh pool-list-all

View storage pool statu

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

6. Configure Spool1 so that it can be self-started by the libvirtd service every time.

The code is as follows:

# virsh pool-autostart Spool1

Configure KVM Storage Pool

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

The code is as follows:

# virsh pool-info Spool1

View KVM storage pool information

Congratulations, Spool1 is ready to stand by. Let's try to create a storage volume to use it.

Step 2: configure the storage volume / disk image

Now that it's your turn to qemu-img, create a new disk image in Spool1 with the disk command. For more details, you can check the man manual.

The code is as follows:

# man qemu-img

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

The code is as follows:

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

Create a storage volum

9. You can get 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 an image that is being used by a running virtual machine or any other process, as it will be corrupted.

Now it's time to create a virtual machine.

Step 3: create a virtual machine

10. Now for the last step, we will use the virt-install command to create the 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 the man manual.

The code is as follows:

# man virt-install

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

Name: the name of the virtual machine.

Disk Location: location of the disk image.

Graphics: how to connect to VM, usually SPICE.

Vcpu: the number of virtual CPU.

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=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 launcher

At this point, I believe you have a deeper understanding of "how to use command-line tools to manage virtual machine environment under the Linux system". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report