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

The use of virt-install, virsh and virt-manager tools of kvm virtual machine in centos environment

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

Share

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

The use of virt-install, virsh and virt-manager tools of kvm virtual machine in centos6.7 environment

1. The use of virt-install tools

2. Use of the virsh command

3. The use of virt-manager graphical interface tools

1. The use of virt-install tools

Virt-install is a command-line tool that can create virtual machines and complete GuestOS installation for KVM, Xen, or other libvrit API-enabled hypervisor; in addition, it can support text or graphical installation interfaces based on serial console, VNC, or SDL. The installation process can be implemented using local installation media such as CDROM, or through network means such as NFS, HTTP, or FTP services. For network installation, virt-install can automatically load the necessary files to start the installation process without providing additional boot tools. Of course, virt-install also supports the PXE installation process, or you can directly start the installation process using an existing disk image.

The virt-install command has a number of options, which can be broadly divided into the following categories, with a brief description of the common options in each category.

# # General options: specify the name, memory size, number and characteristics of VCPU, etc.

-n NAME,-- name=NAME: virtual machine name, which needs to be globally unique

-r MEMORY,-- ram=MEMORY: internal size of virtual machine in MB; n-- vcpus=VCPUS [, maxvcpus=MAX] [, sockets=#] [, cores=#] [, threads=#]: number of VMs and related configurations

-- cpu=CPU:CPU mode and features, such as coreduo, etc. You can use qemu-kvm-cpu? To get the supported CPU mode

# # installation method: specify installation method, GuestOS type, etc.

-c CDROM,-- cdrom=CDROM: CD installation media

-l LOCATION,-- location=LOCATION: install source URL, which supports FTP, HTTP, NFS, etc., such as ftp://172.16.0.1/pub

-- pxe: complete the installation based on PXE

-- livecd: treat CD as LiveCD

-- os-type=DISTRO_TYPE: operating system type, such as linux, unix, windows, etc.

-- os-variant=DISTRO_VARIANT: a variant of a certain type of operating system, such as rhel5, fedora8, etc.

-x EXTRA,-- extra-args=EXTRA: additional options for passing to the kernel when installing GuestOS in the manner specified by-- location, such as specifying the location of the kickstart file,-- extra-args "ks= http://172.16.0.1/class.cfg"

-- boot=BOOTOPTS: specify the configuration options after the installation process is completed, such as specifying the boot device order, booting the system using the specified rather than installed kernel/initrd, etc.; for example:

-- boot cdrom,hd,network: specify the boot order

-- boot kernel=KERNEL,initrd=INITRD,kernel_args= "console=/dev/ttyS0": specify the kernel and initrd file of the boot system

# # Storage configuration: specify storage type, location, attributes, etc.

-- disk=DISKOPTS: specify the storage device and its attributes; format is-- disk / some/storage/path,opt1=val1,opt2=val2, etc. Common options are:

Device: device type, such as cdrom, disk, floppy, etc. Default is disk

Bus: disk summary type, whose value can be ide, scsi, usb, virtio, or xen

Perms: access rights, such as rw, ro, or sh (read / write of the share). Default is rw.

Size: the size of the new disk image in GB

Cache: cache model, whose values are none, writethrouth (cache read), and writeback (cache read and write)

Format: disk image format, such as raw, qcow2, vmdk, etc.

Sparse: the disk image uses a sparse format, that is, no space of the specified size is allocated immediately

-- nodisks: do not use local disks and are commonly used in LiveCD mode

# # Network configuration: specify the network type and interface properties of the network interface, such as MAC address, driver mode, etc.

-w NETWORK,-- network=NETWORK,opt1=val1,opt2=val2: connect a virtual machine to the network of the host, where NETWORK can be:

Bridge=BRIDGE: connect to a bridge device named "BRIDEG"

Network=NAME: connect to a network named "NAME"

# # other commonly used options are:

Network device models seen in model:GuestOS, such as E1000, rtl8139, virtio, etc.

Mac: fixed MAC address; random address will be used when this option is omitted, but in any case, for KVM, the first three paragraphs must be 52:54:00

-- nonetworks: virtual machines do not use network features

# # graphic configuration: define configurations related to virtual machine display, such as VNC

-- graphics TYPE,opt1=val1,opt2=val2: specifies the configuration related to the graphics display. This option does not configure any display hardware (such as graphics cards), but only specifies the interface to access the virtual machine after it is started.

TYPE: specifies the display type, which can be vnc, sdl, spice, none, etc. The default is vnc

The port on which port:TYPE is listening when it is vnc or spice

The IP address to listen to when listen:TYPE is vnc or spice. The default is 127.0.0.1. You can define a new default value by modifying / etc/libvirt/qemu.conf.

When password:TYPE is vnc or spice, specify the authentication password for the remote access listening service

-- noautoconsole: disable automatic connection to the console of the virtual machine

# # device options: specify text console, sound device, serial interface, parallel interface, display interface, etc.

-- serial=CHAROPTS: attach a serial device to the current virtual machine. Depending on the device type, you can use different options in the format "--serial type,opt1=val1,opt2=val2,...", for example:

-- serial pty: create pseudo terminal

-- serial dev,path=HOSTPATH: attach host devices to this virtual machine

-- video=VIDEO: specifies the video card device model. Available values are cirrus, vga, qxl or vmvga.

# # Virtualization platform: virtualization model (hvm or paravirt), simulated CPU platform type, simulated host type, hypervisor type (such as kvm, xen or qemu, etc.) and current virtual machine UUID, etc.

-v,-- hvm: specifies the use of full virtualization when the physical machine supports both full virtualization and paravirtualization

-p,-- paravirt: specifies the use of paravirtualization

-- virt-type: the hypervisor used, such as kvm, qemu, xen, etc. All available values can be obtained using the 'virsh capabilities' command

# # other:

-- autostart: specifies whether the virtual machine starts automatically after physical startup

-- print-xml: if the virtual machine does not require the installation process (--import,-- boot), the generated XML is displayed instead of creating the virtual machine; by default, this option still creates a disk image

-- force: forbids commands from entering interactive mode. If you need to answer yes or no options, the automatic answer is yes.

-- dry-run: performs the whole process of creating a virtual machine, but does not actually create the virtual machine, change the device configuration information on the host, and notify libvirt of the requirements it has created

-d,-- debug: displays debug information

Although the virt-install command has many options similar to the above, in practice, the only options that must be provided are-- name,-- ram,-- disk (but-- nodisks) and options related to the installation process. In addition, it is sometimes necessary to use the bracket-- connect=CONNCT option to specify a connection to a non-default hypervisor.

The following example creates an image file / var/lib/libvirt/images/rhel5.8.img named rhel5 with a hypervisor of KVM, a memory size of 512MB, and a disk of 8 gigabytes, and guides the startup installation process through the boot.iso CD image.

# virt-install\

-- connect qemu:///system\

-- virt-type kvm\

-- name rhel5\

-ram 512\

-- disk path=/var/lib/libvirt/images/rhel5.img,size=8\

-- graphics vnc\

-- cdrom / tmp/boot.iso\

-- os-variant rhel5

The following example creates a virtual machine named rhel6 with two virtual CPU installed as FTP, and specifies the location of the ks file, the disk image file in a sparse format, and connects to the bridge network named brnet0 on the physical host:

# virt-install\

-- connect qemu:///system\

-- virt-type kvm\

-- name rhel6\

-- ram 1024\

-- vcpus 2\

-- network bridge=brnet0\

-- disk path=/VMs/images/rhel6.img,size=120,sparse\

-- location ftp://172.16.0.1/rhel6/dvd\

Extra_args "ks= http://172.16.0.1/rhel6.cfg"\"

-- os-variant rhel6\

-- force

The following example creates a virtual machine named rhel5.8 with a disk image file of sparse mode format of qcow2 and bus type of virtio. The installation process does not launch the graphical interface (--nographics), but starts a serial terminal to display the installation process in character form in the current text mode, and the virtual machine graphics card type is cirrus:

# virt-install\

-- connect qemu:///system\

-- virt-type kvm\

-- name rhel5.8\

-- vcpus 2 Maxvcpushes 4\

-ram 512\

-- disk path=/VMs/images/rhel5.8.img,size=120,format=qcow2,bus=virtio,sparse\

-- network bridge=brnet0,model=virtio

-- nographics\

-- location ftp://172.16.0.1/pub\

-extra-args "ks= http://172.16.0.1/class.cfg console=ttyS0 serial"\

-- os-variant rhel5\

-- force\

-- video=cirrus

The following example creates a virtual machine named rhel5.8 using an existing disk image file (which already has an installed system):

# virt-install\

-- name rhel5.8

-- ram 512

-- disk / VMs/rhel5.8.img

-- import

After each virtual machine is created, its configuration information is saved in the / etc/libvirt/qemu directory with the same file name as the virtual machine and a format of XML.

2. Use of the virsh command

Common virsh commands:

Virsh start x starts an inactive virtual machine named x

Virsh list lists virtual machines

Virsh create x.xml creates a virtual machine (after creation, the virtual machine executes immediately and becomes the active host)

Virsh suspend x pauses the virtual machine

Virsh resume x starts a paused virtual machine

Virsh shutdown x shuts down the virtual machine normally

Virsh destroy x forces the virtual machine to shut down

# virsh undefine x Delete Virtual Machine

Virsh dominfo x displays basic information of virtual machines

Virsh domname 2 displays the virtual machine name with id number 2

Virsh domid x displays the virtual machine id number

Virsh domuuid x displays the uuid of the virtual machine

Virsh domstate x displays the current status of the virtual machine

Virsh dumpxml x displays the current configuration file of the virtual machine (it may be different from the configuration when defining the virtual machine, because when the virtual machine starts, the virtual machine needs to be assigned the id number, uuid, VPN port number, and so on)

Virsh setmem x 512000 sets the memory size for inactive virtual machines

Virsh edit x edit configuration file (usually just after the virtual machine has been defined)

The example 1:virsh command adds a bridge:

# service libvirtd start

You can view help

# virsh help iface-bridge

You can add a bridge directly through the command of virsh

# virsh iface-bridge eth0 br0

Created bridge br0 with attached device eth0

Bridge interface br0 started

# ifconfig

3. The use of virt-manager graphical interface tools

A little bit.

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

Servers

Wechat

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

12
Report