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 virtual machine template using the virsh tool

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

Share

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

Today we introduce the use of virsh virtual machine management tool components to create virtual machine templates

First prepare the basic environment:

Install a virtual machine for Centos7.0 on vmware

Turn on the virtualization feature of CPU

Verify that the virtualization feature is turned on after installing the operating system

Use egrep-- color=auto "(svm | vmx)" / proc/cpuinfo to view

Install the tool components of libvirt

Yum install libvirt libvirt-client virt-manager virt-install

Because we are using libvirt components to manage kvm, we need to install qemu-kvm on the physical machine

Systemctl start libvirtd Startup Service

Configuration files for libvirt and libvirtd:

Daemon configuration file: / etc/libvirt/libvirt.conf

There is a configuration file for default.xml under the / etc/libvirt/qemu/networks/ directory

What is defined in this file is the basic configuration information of qemu virtual machines, for example, after installing libvirt, a bridge named bridge will be generated and an IP address will be generated, and the automatic allocation of dhcp services can also be realized.

Next, we use virt-install to create a virtual machine template image.

Production of Centso7.0 Image template

The following example creates a virtual machine named rhel7.0 with hypervisor kvm, memory size 512MB, and storage disk 20g image file / images/rhel7.0.img, which guides the startup installation process through an iso CD image, and the virtual machine network card connects to the bridging network named brnet0 on the physical host; the virtual machine video card type is cirrus.

Virt-install-- connect qemu:///system-- virt-type kvm-- name rhel7.0-- vcpus 1Maxvcpushes 4-- ram 512-- disk path=/image/rhel7.0.img,size=20,format=qcow2,bus=virtio,sparse-- network bridge=brnet0,model=virtio-- graphics vnc-- cdrom / tmp/CentOS-7.0-1406-x86_64-DVD.iso-- os-variant rhel7-- force-- video=cirrus

If the could not open disk image / root/CentOS-7-x86_64-DVD-1810.iso: Could not open'/ root/CentOS-7-x86_64-DVD-1810.iso': Permission denied field appears after executing the command

This indicates that there is a problem with the user's execution permission. You need to modify the / etc/libvirt/qemu.conf file, change the user corresponding to the user field to root, and then restart the libvirt service.

After the virtual machine is installed, go to the virtual machine to view the driver information

Using brctl to view the bridge information on the host computer, you can see that the network card of the virtual machine is mounted to the virbr.

We can see this virtual machine instance in the virt-manager image management tool after shutting down the virtual machine created by using the virsh tool component.

At this point, copy the / image/rhel7.0.img image file and upload it to the cloud platform.

The virt-install command has many options, which can be divided into the following categories, with a brief description of the common options in each category; general options: specify the name, memory size, VCPU number and characteristics of the virtual machine;-n NAME-name=NAME / / virtual machine name, which needs to be globally unique -r MEMORY-- ram=MEMORY, virtual machine memory size, in MB-- vcpus=VCPUS [, maxvcpus=MAX] [, sockets=#] [, cires=#] [, threads=#] / / VCPU number and county magistrate configuration;-cpu=CPU / / CPU mode and features, such as coreduo, can use qemu-kvm-cpu? To obtain the supported CPU mode; installation method: specify CD installation method, GuestOS type, etc.;-c CDROM,--cdrom=CDROM / / CD installation media;-l LOCATION,--location=LOCATION / / install source URL, support FTP\ HTTP and NFS, such as ftp://172.16.0.1/pub:-- pxe / / complete installation based on PXE -- livecd / / treat CD as LiveCD;-- os-type=DISTRO_VARIANT / / operating system type, such as Linux, unix or windows;-- os-variant=DISTRO_VARIANT / / variants 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.cfs"-- boot=BOOTOPTS / / specifies the configuration options after the installation process is complete, such as boot device order Boot the system using the specified one instead of following the kernel/initrd, etc.: for example:-- boot cdrom,hd,network: set the boot order -- boot kernel=KERNEL,initrd=INITRD,kernel_args= "console=/dev/ttyS0 / / specifies the kernel and initrd file of the boot system; storage configuration: specify storage type, location, attributes, etc.;-- disk=DISKOPTS / / specify storage device and its attributes; format is-- disk / some/storage/path,opt1=val1,opt2=val2, etc. Commonly used options are: device: device type, such as cdrom, disk or floppy, etc. The default is disk; bus: disk bus type, and its value can be ide,scsi,usb, virtio or xen Perms: access permission, such as rw, ro or sh (shared read / write). Default is rw; size: size of the new disk image, in GB; cache: cache model, with values of none,writethrouth (cache read) and writeback (cache read and write) Format: disk image format, such as raw,qcow2,vmdk; sparse: disk image uses sparse format, that is, no specified size of space is allocated immediately;-- nodisk: no local disk is used, which is 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 the virtual machine to the host host's network, where the NETWORK can be: bridge=BRIDGE: connected to a bridge device named "BRIDEFG" Network=NAME: connect to a network called "NAME"; other common options include the network device number seen in model:GuestOS, such as e1000, mac, rtl8139 or virtio, etc.; mac: fixed MAC address A random address is used when this option is omitted, but in any case, for KVM, the first three paragraphs must be 52:54:00-nonetworks: virtual machine does not apply to network function graphic configuration: define virtual machine display function related configuration, such as VNC related configuration -- 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 when it is started. TYPE: specifies the display type, which can be vnc,sdl,soice or none. By default, ask the port on which vnc; port:TYPE listens when it is vnc or spice. The IP address to be listened 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 monitoring service Windows2008 image production

Virt-install-- connect=qemu:///system-n "windows2008"-r 1024-- vcpus 1-- network bridge=virbr0,model=virtio-- disk path=/image/win08.img,format=qcow2,device=disk,bus=virtio,size=15,sparse-- cdrom / tmp/cn_windows_server_2008_r2_hpc_edition_with_service_pack_1_x64_dvd_700632.iso-- disk path=/tmp/virtio-win-1.7.4.iso,device=cdrom-- graphics vnc-- os-type windows-- boot cdrom,hd

After running the command to create a virtual machine, if the console displays as follows, the system does not take the image file of windows2008 as the first boot order, and you need to set the boot sequence.

Notice which cdrom is the image of windows2008, adjust it to the first boot order, shut down the virtual machine, and then start.

When the installation operating system selects the installation disk directory, it will prompt that there is no driver.

At this time, we need to load the driver in the image file of virtis and select the corresponding version.

After loading, the following information is displayed

View the driver loading information of windows2008 after the installation is complete

Right-click to update driver

Select virtio files for automatic retrieval by the system

Update all the drivers that need to be updated, then shut down the virtual machine and upload the win08.img disk file under the / image file to the cloud platform.

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