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

Create a kvm virtual machine using the virt-install command on centos7

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

Share

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

Use the virt-install command to create a virtual machine

The virt-install command can not only run interactively, but also create and deploy the virtual machine system automatically. With kickstart technology, the operating system of the virtual machine can be installed unattended. This command provides many options, and you can use virt-install-- help to view options and help

Command format:

Virt-install [options]

-h View help

-- connect=CONNECT connection is not the default hypervisor, which defaults to qemu:///system

-n name new virtual machine host instance name

-r MEMORT virtual machine memory settings

-- arch=ARCH cpu architecture

-- machine=MACHINE virtual machine simulator type, Xen or KVM, etc.

-- number of vcpus=VCPUS virtual hosts CPU

-c CDROM sets the CD image or CD device path

-l LOCATION specifies the installation source path

-- pxe starts using pxe protocol

-- import imports existing virtual machines

-x EXTRA additional kernel parameters, such as-x "ks= http://server/server.ks"

-- os-type=Type operating system type, such as linux, windwos, etc.

-- disk=DISKOPTS sets virtual machine disk, such as-- disk / dev/storage/path

-w NETWORK sets virtual machine network, such as-w bridge=br0

-- noneworks virtual machine does not set any network interface

-m MAC sets the virtual machine MAC address

-- vnc settings to view virtual machines through vnc

-- hvm uses full virtualization technology

-- paravirt uses paravirtualization technology

-- soundhw MODEL sets up sound card devices

-- autostart sets the virtual machine to boot

Examples of official help documents are as follows:

1) install fedora 13, use virtio-driven disks and network card devices, create storage files for 8GB, install the operating system using CDROM, and view the virtual machine interface using VNC

Virt-install-- connect qemu:///system-- virt-type kvm-- name demo-- ram 500-- disk path=/var/lib/libvirt/images/demo.img,size=8-graphics vnc-- cdrom / dev/cdrom-- os-variant fedora13

2) install Fedora9, use LVM partition, set the virtual machine network to boot from PXE, and use vnc to connect to the virtual machine interface:

Virt-install-- connect qemu:///system-- name demo-- ram 500-- disk path=/dev/HostVG/DemoVM-- virt-type qemu-- graphics vnc-- os-variant fedora9

3) install the virtual machine on the real disk, use the default QEMU hypervisor, and use the SDL connection virtual machine interface to initialize and install remotely

Virt-install-connect qemu:///system-name demo-disk path=/dev/hdc-network brige=eno1-arch ppc64-graphics sdl-location / linux/core/6/x86_64/os/

The following is a diagram for installing a ubuntu virtual machine locally

Virt-install\-- connect qemu:///system # connection defaults to native hypervisor\-- virt-type kvm # virtualization type is kvm\-- vcpus=1 # vcpu is 1\-- name Unbuntu16 # Virtual machine name\-- ram 512 # memory size\-- cdrom / var/lib/libvirt/images/ubuntu-16.04.5-server-amd64.iso # specifies to boot using the cdrom CD-ROM drive Specify the image path\-- disk path=/var/lib/libvirt/images/ubuuntu16.img,size=50,format=qcow2,bus=virtio # specify the hard disk path and size Format is qcow2, bus type is virtio\-- network bridge=br0 # specify virtual network type as bridge br0\-- os-type=linux # specify virtual machine operating system type as linux

Then jump out of the installation interface

Then use virt-manger to view the virtual machine hardware options, consistent with the command line configuration

II. Virsh command

Virsh is a very excellent command line management tool for hypervisor and virtual hosts. It is a command provided by libvirt-client software. You can use this command line tool to replace the virt-manager tool with a graphical interface.

Syntax virsh [options] command [parameters]

Cd changes the current directory

Connect connect (reconnect) to hypervisor

Echo echo parameter

Exit exits this non-interactive terminal

Help Printing help

Pwd output current directory

Quit exits this non-interactive terminal

Common commands:

List lists the running virtual machines

The following domain is actually the virtual machine in the middle finger of domain,kvm

Autostart-automatically start a domain, configure virtual machine self-boot,-- disable means disable self-startup

Connect-Connect (reconnect) to hypervisor

Domain information in dumpxml-XML, outputting configuration files in XML format for specific virtual machines

Create-create a domain from a XML file, a new virtual machine

Define-define (but not start) a domain from an XML file

Destroy-destroy (stop) domain

Dominfo-Domain Information

Domid-converts a domain name or UUID to a domain id

Domstate-Domain statu

Edit-Edit the XML configuration for a domain

Reboot-restart a domain

Shutdown-close a domain

Destroy-destroy (stop) domain

Start-start a (previously defined) inactive domain

Save-saves the state of a domain to a file

Restore-restore a domain from a state that exists in a file

Screenshot-extract the screenshot of the current domain console and save it to a file

Suspend-suspends a domain

Resume-restore a domain

Setmem-change the allocation of memory

Setmaxmem-change the maximum memory limit

Setvcpus-change the number of virtual CPU

Vcpuinfo-detailed domain vcpu information

Attach-device-add devices from a XML file

Net-create-create a network from a XML file

Net-dumpxml-output network information in XML format

Net-list-list the network

Net-start-start a (previously defined) inactive network

Iface-define- uses XML files to define host network interfaces

Iface-list-list of physical host interfaces

Snapshot-create-generate a snapshot using XML

Snapshot-delete-Delete a domain snapshot

Snapshot-dumpxml-backup xml for domain snapshot

Snapshot-list-lists snapshots for the domain

1) View the list of currently running virtual machines, and view the list of all virtual machines

2) set the virtual machine to boot automatically

3) back up the virtual machine configuration file and save the configuration file as ubuntu.xml

Virsh dumpxml ubuntu16 > ubntu16.xml

4) View the basic information of the virtual machine

Virsh dominfo 6

5) set the virtual memory size, maximum memory and the number of vcpu, and the next restart will take effect

Virsh setmaxmem ubuntu16 1048576-- config # unit is kB-- config is effective for next launch virsh setmem ubuntu16 1048576-- configvirsh setvcpus unbuntu16 2-- config

III. Virtual storage

Kvm storage pool is a file, directory or storage device managed by libvirt. The storage pool can be located locally or shared through the network, and the storage pool can eventually be used by virtual machines. The default libvirt uses a directory-based storage pool design, and the / var/lib/libvirt/images directory is the default storage pool. A local storage pool can be a local directory, disk device, physical partition, or LVM volume, but the local storage pool is not suitable for large-scale product deployments and does not support virtual machine migration. The network sharing storage pool uses standard network protocols to share storage devices, which supports protocols such as SAN,IP-SAN,NFS,GFS2. In kvm virtualization technology, a storage pool can contain multiple storage volumes, which are regarded as physical hardware storage devices for virtual machines.

3.1 create directory-based virtual storage pools and volumes

Create a directory

Mkdir / var/lib/libvirt/test

Modify file security related attributes

Chown root.root / var/lib/libvirt/test/chmod 700 / var/lib/libvirt/test/

Create a storage pool using the virsh command

Virsh pool-define-as test-type dir-target / var/lib/libvirt/test/ # create a storage pool of directory type virsh pool-build test # build pool virsh pool-start test # activate virsh pool-autostart test # automatically activate virsh pool-list

You can also create a storage pool in a way defined by xml, first creating an xml document named test

# cat test # definition type is directory test # definition name is test / var/lib/libvirt/test # definition directory 0700-1-1

Then call the pool-create command to load the xml file

Virsh pool-create testvirsh pool-list

Then create a storage volume with a format of qcow2 and a size of 10G

Virsh vol-create-as test vol-test.qcow2 10G-- format qcow2 virsh vol-list test # View the volumes under the pool

Virsh attach-disk\-- domain ubuntu16 # specify the virtual machine\-- source / var/lib/libvirt/test/vol-test.qcow2 # specify the path of the volume\-- target vdb # specify the vdb that identifies the hard disk as the virtual machine\-- targetbus virtio # bus protocol\-- driver qemu # driver type\-- subdriver qcow2 # driver type of disk source\-- sourcetype block # disk source mode file that is file device Block is a block device\-- cache none # does not need to cache\-- persistent # will make this operation take effect on both the running virtual machine and the xml file of the virtual machine\-config # the next restart will take effect

When you log in to the virtual machine, you can see that the hard disk has been added.

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