Disclosure of Invention
The embodiment of the invention provides a method and a device for automatically burning a virtual machine system and application thereof, aiming at the problems of high tolerance, high cost, high risk, low efficiency and the like existing in the prior art.
The core technology of the invention mainly utilizes a Linux maintenance mode to realize automatic recording and installation of a virtual machine system through a series of scripts, and comprises the steps of creating a virtual machine, setting virtual equipment, entering the maintenance mode, performing recording operation, cleaning, deleting an optional virtual machine and the like, thereby solving a plurality of problems of the existing virtual machine recording method.
In a first aspect, the present invention provides a method for automating a virtual machine system, the method comprising the steps of:
s00, creating or downloading and executing a first script;
s10, creating a virtual machine with default parameters, and setting the number of virtual CD-ROM and the number of virtual hard disks to be two;
s20, filling an image file of a Linux system in a mode to be maintained into a first virtual CD-ROM, filling an image file of a virtual machine system to be recorded into a second virtual CD-ROM, and setting the capacities of two virtual hard disks according to requirements;
S30, setting a starting sequence, and setting and activating the virtual machine according to the first virtual drive, the second virtual drive, the first virtual hard disk and the second virtual hard disk;
S40, after the virtual machine is started, entering a command line interface of a maintenance mode of Linux;
S50, creating or downloading and executing a second script;
s60, recording the virtual machine system to be recorded from the second virtual drive into the first virtual hard disk by using a recording command;
And S70, closing the virtual machine after the successful burning.
Further, in step S20, the capacity of the first virtual hard disk is set to be more than twice of the image file of the virtual machine system to be recorded, and the capacity of the second virtual hard disk is set to be more than 32 GB.
Further, between the step S10 and the step S20, file detection is carried out, wherein the file detection comprises a virtual machine system file to be recorded and a Linux file with a maintenance mode; if the file does not exist, downloading and decompressing from the network.
Further, in step S60, before recording, it is detected whether all virtual hard disks and virtual optical drives are loaded successfully, and the number is greater than or equal to 2;
if yes, automatically matching the virtual hard disk with the virtual CD-ROM, and matching according to the capacity and the type; if not, reporting error and exiting the recording flow.
Further, the method also comprises S80, after the virtual machine is closed, creating or downloading and executing a third script;
And S90, deleting all the virtual CD-ROM and restarting the virtual machine to enter a virtual machine system installation interface, and taking the second virtual hard disk as an installation disk of the system.
Further, a fourth script is further included, which deletes the corresponding virtual machine by responding to the virtual machine ID input by the user, or deletes all virtual machines by responding to all deletion instructions input by the user.
Further, in step S00, a temporary file storage server is stored in the local area network, and all scripts and image files are stored on the temporary file storage server.
In a second aspect, the present invention provides an apparatus for an automated virtual machine system, including:
The temporary file storage server module is used for storing all scripts and mirror image files;
the local area network module is used for providing local network service and is used for data interaction between the temporary file storage server module and the virtual machine module;
the virtual machine module is used for creating a virtual machine with default parameters and setting the number of virtual CD-ROM and virtual hard disk to two; filling an image file of a Linux system in a mode to be maintained into a first virtual drive, filling an image file of a virtual machine system to be recorded into a second virtual drive, and setting capacities of two virtual hard disks according to requirements; setting a starting sequence, setting and activating a virtual machine according to the first virtual drive, the second virtual drive, the first virtual hard disk and the second virtual hard disk; after the virtual machine is started, a command line interface of a maintenance mode of Linux is entered; creating or downloading and executing a second script; the virtual machine system to be recorded is recorded from the second virtual CD driver into the first virtual hard disk by using the recording command; and closing the virtual machine after the successful burning.
In a third aspect, the invention provides an electronic device comprising a memory in which a computer program is stored and a processor arranged to run the computer program to perform the method of automatically burning a virtual machine system as described above.
In a fourth aspect, the present invention provides a readable storage medium having stored therein a computer program comprising program code for controlling a process to execute a process comprising a method of automatically burning a virtual machine system according to the above.
The main contributions and innovation points of the invention are as follows:
1. compatibility promotion
In the prior art, only a few virtual machine management systems are supported by adopting a self-contained recording command, and the rest virtual machine management systems and most virtual machine management software are required to be recorded by installing a specific third-party recording tool on an additional computer, so that the universality is not high. The invention realizes the burning of the virtual machine system in Proxmox VE through the specific script and flow, does not depend on the specific virtual machine management system or the additional computer, and greatly improves the compatibility. Therefore, the currently mainstream virtual machine management system directly installed on the main board, such as ProxmoxVE, VMwareEsxi, unraid, and the virtual machine management software installed on the host machine, such as ParallelsDesktop, VMwareFusion, VMwareWorkstationPlayer, oracleVMVirtualBox, can adopt the method of the invention, the specific platform only needs to be specifically trimmed, the basic steps are consistent, and the method is not limited to the specific platform and the specific equipment, and has extremely strong universality.
2. Cost reduction
In the prior art, some recording methods require preparing external storage equipment, so that the expenditure cost is increased; corresponding tools and methods are often replaced when different platforms are replaced, so that the learning cost is increased; many methods can only be manually operated at the interface and cannot be automated, thus increasing the time cost. According to the invention, the required script and mirror image file can be obtained through the temporary file storage server in the local area network without additional external storage equipment, so that the expenditure cost is reduced. Meanwhile, the whole burning and installing process is high in automation degree, and learning cost and time cost are reduced. The used various files and the started virtual disk can be deleted directly, so that the capacity of the local hard disk is saved. The effect of slimming and no mark is achieved.
3. Risk reduction
In the prior art, the working state of external equipment is influenced by the environment, the burning failure can be caused by high temperature, low temperature, power failure, poor contact and the like, the data loss, abnormal burning and the like can be caused by an incorrect operation mode, uncontrollable results can be caused by a poor memory chip and materials, and the stability is not strong. The invention performs the recording operation in the virtual machine, is not influenced by external environment factors, and reduces the risk of recording failure. Meanwhile, through strict detection and matching steps, the accuracy and stability of the burning process are ensured.
4. Efficiency improvement
In the prior art, many recording methods require specific operation steps to be performed; some methods also check whether the burning is successful manually; one storage device can only be used for installing one virtual machine, and cannot be automated and synchronously recorded by a plurality of virtual machine systems; in the process of burning, complicated and trivial operations such as connection, identification, reading, removal and the like of storage equipment are required to be continuously carried out on different platforms, and the efficiency is low. According to the invention, through automatic script execution, except that manual selection and manual input are needed for entering a maintenance mode of Linux, other operations are completely automated, and manual intervention and manual correction are not needed; the storage device connection/removal operation does not need to be frequently performed; the limitation that one storage device can only be connected with one virtual machine is avoided; the storage equipment is prevented from being emptied and formatted into a specific format, any system can be randomly recorded, and the system is flexible and free; in addition, synchronous recording and deployment of a plurality of virtual machine systems can be simultaneously carried out, and the efficiency is improved by 90% compared with the prior art.
The details of one or more embodiments of the invention are set forth in the accompanying drawings and the description below to provide a more thorough understanding of the other features, objects, and advantages of the invention.
Detailed Description
Reference will now be made in detail to exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, the same numbers in different drawings refer to the same or similar elements, unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with one or more embodiments of the present specification. Rather, they are merely examples of apparatus and methods consistent with aspects of one or more embodiments of the present description as detailed in the accompanying claims.
It should be noted that: in other embodiments, the steps of the corresponding method are not necessarily performed in the order shown and described in this specification. In some other embodiments, the method may include more or fewer steps than described in this specification. Furthermore, individual steps described in this specification, in other embodiments, may be described as being split into multiple steps; while various steps described in this specification may be combined into a single step in other embodiments.
Example 1
The invention aims to provide a method for automatically burning a virtual machine system, which is realized through a maintenance mode of Linux self, specifically, referring to fig. 1, taking an open source virtual machine management system ProxmoxVE, which uses RockyLinux to automatically burn an OpenWrt virtual machine system, and temporarily disposes a local area network script storage service, and directly downloading a script when in use as an example:
the first step, create or download and execute the following script [ s1_create.sh ] in ProxmoxVE to implement the automatic creation and setting of virtual machines, the script content of s1_create.sh is as follows:
#!/bin/bash
#ScriptName:s1_create.sh
The technology point 1 step-is used for automatically creating and setting the virtual machine under the PVE virtual management system.
#Author:Candy
#Date:2024-08-06
#################################
Parameter configuration #)
#################################
readonlyVM_NAME="OpenWrt"
readonlyVM_CPU=1
readonlyVM_MEMORY=2048
# Is used to guide the capacity of the mounted boot disk after recording.
readonlyVM_BOOT_DISK=5
# Disk capacity size for virtual machine system installation and use.
readonlyVM_HARD_DISK=16
aliasLOG='f(){echo[$(TZ=UTC-8date"+%H:%M:%S")]:$1;};f'
#################################
Procedure #
#################################
# One test file
LOG "= = = = = = = = = = = = = = = = =" whether or not there is a file detection of= = = = = = = = = "
readonlyISO_PATH="/var/lib/vz/template/iso"
LOG "local file save path: $ { ISO_PATH }. "
And (1) detecting the file of the virtual machine system to be recorded.
readonlyBURN_SYSTEM_NAME="OpenWrt"
readonlyBURN_SYSTEM_FILE="openwrt-23.05.3-x86-64-generic-ext4-combined-efi.img"
readonlyBURN_SYSTEM_LINK="https://downloads.openwrt.org/releases/23.05.3/targets/x86/64/${BURN_SYSTEM_FILE}.gz"
LOG "the name of the virtual machine system to be recorded is: the { BURN_SYSTEM_NAME }. "
LOG' the virtual machine system file to be recorded is: the { BURN_SYSTEM_FILE }. "
LOG' detects whether the virtual machine system file to be recorded exists in the local machine: "
if[-e"${ISO_PATH}/${BURN_SYSTEM_FILE}"];then
LOG' the virtual machine system file to be recorded exists, and the next step is continued. "
else
LOG "virtual machine system files to be burned do not exist, and will be downloaded from the network. "
wget-P${ISO_PATH}${BURN_SYSTEM_LINK}
LOG' the downloading of the virtual machine system file to be recorded is completed. "
LOG' the virtual machine system file to be recorded starts to decompress. "
gzip-d${ISO_PATH}/${BURN_SYSTEM_FILE}.gz
LOG' the decompression of the virtual machine system file to be recorded is completed, and the next step is continued. "
fi
And # 2. Detecting the Linux file with the maintenance mode.
readonlyRESCUE_LINUX_NAME="RockyLinux"
readonlyRESCUE_LINUX_FILE="Rocky-9.4-x86_64-minimal.iso"
readonlyRESCUE_LINUX_LINK="https://download.rockylinux.org/pub/rocky/9/isos/x86_64/${RESCUE_LINUX_FILE}"
LOG "Linux name with maintenance mode: $ { RESCUE _LINUX_NAME }. "
The LOG "Linux file with maintenance mode is: $ { RESCUE _LINUX_FILE }. "
LOG "detects whether a Linux file with a maintenance mode exists in the local machine: "
if[-e"${ISO_PATH}/${RESCUE_LINUX_FILE}"];then
The LOG "Linux file with maintenance mode exists and continues to the next step. "
else
LOG "Linux files with maintenance mode do not exist and will be downloaded from the network. "
wget-P${ISO_PATH}${RESCUE_LINUX_LINK}
LOG Linux file with maintenance mode is downloaded completely, and the next step is continued "
fi
LOG "= = = = = = = = = = = = = = = = = = = = =" after the file detection is completed "
# II, create default virtual machine
LOG "= = = = = = = = = = = = = = = = = =" virtual machine start creation= = = = = = = = = "
The # 1 acquires the next available virtual machine ID.
VM_ID=$(pveshget/cluster/nextid)
echo"newVM${VM_ID}:-id${VM_ID}"
# 2. Create a blank virtual machine.
qmcreate${VM_ID}--name${VM_NAME}
echo"createVM${VM_ID}:-name${VM_NAME}"
# 3 Setting default CPU.
qmset${VM_ID}--cpux86-64-v2-AES--cores${VM_CPU}--sockets${VM_CPU}
And # 4, setting a default memory.
qmset${VM_ID}--memory${VM_MEMORY}
# 5 An EFI hard disk was set.
qmset${VM_ID}--efidisk0local-lvm:0,efitype=4m,size=4M,pre-enrolled-keys=no
# 6 Default BIOS is set.
qmset${VM_ID}--biosovmf
# (7) Default machine type is set.
qmset${VM_ID}--machineq35
# 8 Set SCSI controller.
qmset${VM_ID}--scsihwvirtio-scsi-single
# 9 Set up network.
qmset${VM_ID}--net0virtio,bridge=vmbr0,firewall=1
Dynamic adjustment ThinPool for # 10, with version set-up required.
#lvmconfig--withcomments--typediffactivation/thin_pool_autoextend_threshold=80
#lvmconfig--withcomments--typediffactivation/thin_pool_autoextend_percent=20
LOG "= = = = = = = = = = virtual machine creation completion = = = = = = = = = = = = ="
# Three, key setpoint settings
LOG "= = = = = = = = = = = = = = = = =" set by the core set point start= = = = = = = = = = = "
The # 1 creates and fills in a Linux system image of the virtual drive 1 as a mode to be maintained.
qmset${VM_ID}--ide0local:iso/Rocky-9.4-x86_64-minimal.iso,media=cdrom
And (2) creating and filling the virtual drive 2 as a virtual machine system image to be recorded.
qmset${VM_ID}--ide1local:iso/openwrt-23.05.3-x86-64-generic-ext4-combined-efi.img,media=cdrom
And # 3, creating a blank virtual hard disk 1 for storing the recorded data of the virtual machine system image file.
qmset${VM_ID}--scsi0local-lvm:${VM_BOOT_DISK},iothread=1,size=${VM_BOOT_DISK}G
# 4 Creating a blank virtual hard disk 1 for installation of the virtual machine system.
qmset${VM_ID}--scsi1local-lvm:${VM_HARD_DISK},iothread=1,size=${VM_HARD_DISK}G
The # 5 sets the start-up order (virtual drive 1, virtual drive 2, virtual hard disk 1, virtual hard disk 2) and activates the virtual device.
qmset${VM_ID}--bootorder=ide0--bootdiskscsi0
LOG "= = = = = = = = = = = = = = = = = = =" after the core set point is set.
# Four virtual machine operation
The #1 prompts countdown.
LOG "= = = = = = = = = = = = = = = = = =" virtual machine start-up= = = = = = = = = "
TIME_COUNTDOWN=5
while[${TIME_COUNTDOWN}-gt0];do
LOG "virtual machine $ { VM_NAME }: $ { VM_ID } will start after $ { TIME_ COUNTDOWN } s, please switch to the maintenance mode of Linux-! "
sleep1
TIME_COUNTDOWN=$((TIME_COUNTDOWN-1))
done
LOG "= = = = = = = = = = = = = = = = = =" virtual machine start completion= = = = = = = = = "
The # 2 starts the virtual machine.
qmstart${VM_ID}。
After the virtual machine is started, the prompt can be carried out for the next step.
In this embodiment, the first script (s1_create.sh) has the following general idea:
Firstly, parameter configuration is carried out, wherein the parameter configuration comprises virtual machine names, a CPU, a memory, a starting disk, system installation disk capacity and the like. And then carrying out file detection, wherein the file detection comprises a virtual machine system file to be recorded and a Linux file with a maintenance mode. If the file does not exist, downloading and decompressing from the network. Then create a default virtual machine, including get virtual machine ID, create a blank virtual machine, set CPU, memory, BIOS, machine type, etc. And finally, setting key set points, including creating a virtual CD-ROM, filling corresponding mirror image files, creating a blank virtual hard disk for burning and installing a virtual machine system, setting a starting sequence and activating virtual equipment.
In this embodiment, the means for setting up the temporary script storage service in the local area network is the prior art, and steps and principles are not repeated here, and the temporary script storage service can be set up on a device running the virtual machine (a system set up by using virtual machine software to set up or a host device running the virtual machine) or a computer with moderate performance is selected as a server, so that stable network connection and enough storage space are ensured to store scripts and image files.
Secondly, after the virtual machine is started, a command line interface in a maintenance mode of Linux is manually selected across different systems, (because the command line interface is an operation interface in the prior art, drawings and specific redundant functions are not needed), and the operation steps are as follows:
a) The "Enter" key is pressed after the Troubleshooting- > option is selected at RockyLinx install interface.
B) Select RescueaRockyLinuxsystem option, press "Enter" key.
C) After loading is finished, pressing the '1' key, pressing the 'Enter' key to Enter the command line interface of the maintenance mode.
Thirdly, creating or downloading and executing the following script [ s2_burn. Sh ] to realize an automatic burning system, wherein the script content of the s2_burn. Sh is as follows:
#!/bin/bash
#ScriptName:s2_brun.sh
And (2) the technical point is used for automatically recording the virtual machine under the PVE virtual management system.
# Is stored in maintenance mode of Linux:
# - > either a temporary file server is deployed, downloaded into maintenance mode (advice) with wget commands.
# - > Either newly build shellscript files in maintenance mode, hand-make all commands.
And # because of the maintenance mode Chinese messy codes, the log is output by English.
#Author:Candy
#Date:2024-08-07
#################################
Parameter configuration #)
#################################
readonlyVM_NAME="OpenWrt"
# Is the same as the variable defined in create.sh for automatically matching the loaded virtual boot hard disk.
readonlyVM_BOOTDISK=5
# Is the same as the variable defined in create. Sh, which is used to automatically match the virtual use hard disk loaded.
readonlyVM_HARDDISK=16
#################################
Step # of # recording
#################################
And (1) detecting whether all the virtual hard disks are loaded successfully, wherein the number is more than or equal to 2.
echo
echo"========STARTCheckingDisks========"
DISKS_COUNT=$(lsblk-oTYPEawk'$1=="disk"{count++}END{printcount}')
if["${DISKS_COUNT}"-lt2];then
echo"Failedtoloaddisks,exitburning."
exit1
fi
echo"Therequired${DISKS_COUNT}numberofdiskshavebeenloaded."
echo"========ENDCheckingDisks========"
echo
And (2) detecting whether all virtual drives are successfully loaded, wherein the number is more than or equal to 2.
echo"========STARTCheckingCDROMs========"
CDROMS_COUNT=$(lsblk-oTYPEawk'$1=="rom"{count++}END{printcount}')
if["${CDROMS_COUNT}"-lt2];then
echo"Failedtoloadcdroms,exitburning."
exit1
fi
echo"Therequired${CDROMS_COUNT}numberofcdromshavebeenloaded."
echo"========ENDCheckingCDROMs========"
echo
And # 3. Automatically matching the virtual hard disk.
echo"========STARTMatchingDisks========"
echo"Automaticallymatchdisknamesbasedontheircapacity:"
NAME_BOOTDISK=$(lsblk-oNAME,SIZE,TYPEawk-vsize="${VM_BOOTDISK}G"'$2==size&&$3=="disk"{print$1}')
NAME_HARDDISK=$(lsblk-oNAME,SIZE,TYPEawk-vsize="${VM_HARDDISK}G"'$2==size&&$3=="disk"{print$1}')
echo"Thematchedbootdisk1is\"${NAME_BOOTDISK}\",harddisk2is\"${NAME_HARDDISK}\"."
if[-z"${NAME_BOOTDISK}"][-z"${NAME_HARDDISK}"];then
echo"Failedtomatchdisks,exitburning."
exit1
fi
echo"========ENDMatchingDisks========"
echo
And # 4. Automatically matching the virtual drive.
echo"========STARTMatchingCDROMs========"
echo"Automaticallymatchcdromnamesbasedontheirtype:"
NAME_RESCUECDROM=$(lsblk-oNAME,TYPE,MOUNTPOINTawk-vmp="/run/install/repo"'$2=="rom"&&$3==mp{print$1}')
NAME_SYSTEMCDROM=$(lsblk-oNAME,TYPE,MOUNTPOINTawk'$2=="rom"&&$3==""{print$1}')
echo"Thematchedrescuecdrom1is\"${NAME_RESCUECDROM}\",systemcdrom2is\"${NAME_SYSTEMCDROM}\"."
if[-z"${NAME_RESCUECDROM}"][-z"${NAME_SYSTEMCDROM}"];then
echo"Failedtomatchcdroms,exitburning."
exit1
fi
echo"========ENDMatchingCDROMs========"
echo
And # 5, realizing automatic burning by using a primary burning command.
echo"========STARTBurning========"
echo"Burnvirtualmachine'ssystemfromSystemCD-ROM(/dev/${NAME_SYSTEMCDROM})toBootableDisk(/dev/${NAME_BOOTDISK}):"
ddif=/dev/${NAME_SYSTEMCDROM}of=/dev/${NAME_BOOTDISK}bs=4Mstatus=progress
if[$?-eq0];then
echo"Congratulations,virtualmachine'ssystem\"${VM_NAME}\"isburnedsuccessful!"
echo"Pleaseshutdownthisvirtualmachine."
echo"Andexecute\"clean.sh\"onthehostmachinetoproceedwiththesubsequentoperations."
echo"========ENDBurning========"
echo
read-p"ShutdownNow?(y/n):"answer
case${answer}in
[Yy]*)
echo"Shutdownthisvirtualmachinein3s..."
sleep3
shutdown-hnow
;;
[Nn]*)
echo"Cancel.Pleasemanuallyshutdown."
;;
*)
echo"Invalidinput,pleaseenteryorn."
;;
esac
else
echo"Burningfailed,pleasetryagain."
echo"========ENDBurning========"
fi
After the smooth execution, the recording is started.
In this embodiment, the rough idea of the second script (s2_burn.sh) is:
Firstly, whether all virtual hard disks and virtual CD-ROM are loaded successfully or not is detected, and the number is more than or equal to 2. And then automatically matching the virtual hard disk with the virtual CD-ROM, and matching according to the capacity and the type. And finally, realizing automatic recording by using a primary recording command, and recording the virtual machine system from the system CD-ROM to the starting disk. If the recording is successful, prompting the user to close the virtual machine and executing the subsequent cleaning operation. If the recording fails, the user is prompted to try again.
And fourthly, creating or downloading and executing the following script (s3_clean.sh) after closing the virtual machine to realize automatic cleaning before subsequent installation, wherein the specific codes of the s3_clean.sh are as follows:
#!/bin/bash
#ScriptName:s3_clean.sh
and 3. The technology point is used for automatically cleaning the virtual machine under the PVE virtual management system.
#Author:Candy
#Date:2024-08-08
#################################
Parameter configuration #)
#################################
readonlyVM_NAME="OpenWrt"
# Is the same as the variable defined in create.
readonlyVM_BOOT_DISK=5
# Is the same as the variable defined in create.
readonlyVM_HARD_DISK=16
#################################
Procedure #
#################################
echo
Echo "= = = = = = = = = = = = = = = =" virtual machine cleaning start= = = = = = = "
The # 1 searches for a previously created virtual machine according to the name.
VM_ID=$(qmlistgrep-i${VM_NAME}awk'{print$1}')
if[-z"${VM_ID}"];then
Echo "> > > > > > error: the assigned "$ { VM_NAME }" virtual machine cannot be found. "
Echo "= = = = = = = = = = = = = = = = = =" virtual machine cleaning failure = = = = = = = = = = ".
exit1
fi
Echo "> > > > > find virtual machine" $ { VM_NAME }: $ { VM_ID }. "
The virtual machine is stopped # 2.
Echo "> > > > > stopping the virtual machine $ { vm_id }. "
qmstop${VM_ID}
And # 3, deleting all virtual drives.
CDROMS=$(qmconfig${VM_ID}grep-oP'^(idesatascsi)\d+:.*cdrom'cut-d:-f1)
forCDROMin${CDROMS};do
qmset${VM_ID}-delete${CDROM}
Echo "> > > > > virtual drive" $ { CDROM } "has been deleted from virtual machine" $ { VM_NAME }: $ { VM_ID } ". "
done
And # 4, searching the virtual hard disk.
ID_BOOTDISK=$(echo$(qmconfig${VM_ID}grep-E"size=${VM_BOOT_DISK}G")awk-F:'{print$1}')
if[-z"${ID_BOOTDISK}"];then
Echo "> > > > > > error: the specified boot disk cannot be found. "
Echo "= = = = = = = = = = = = = = = = = =" virtual machine cleaning failure = = = = = = = = = = ".
exit1
fi
Echo "> > > > > finds the boot disk: $ { ID_ BOOTDISK }. "
ID_HARDDISK=$(echo$(qmconfig${VM_ID}grep-E"size=${VM_HARD_DISK}G")awk-F:'{print$1}')
if[-z"${ID_HARDDISK}"];then
Echo "> > > > > > error: the specified system disk cannot be found. "
Echo "= = = = = = = = = = = = = = = = = =" virtual machine cleaning failure = = = = = = = = = = ".
exit1
fi
Echo "> > > > > finds the system disk: $ { ID_ HARDDISK }. "
The # 4 sets the start-up order (virtual start-up hard disk 1, virtual blank hard disk 2) and activates the virtual device.
qmset${VM_ID}--bootorder="${ID_BOOTDISK};${ID_HARDDISK}"--bootdisk${ID_BOOTDISK}
Echo "= = = = = = = = = = = = = = = = = = =" after virtual machine cleaning is completed= = = = = = = = = = = = ".
Echo "> > > > > starting the virtual machine $ { vm_id }. "
qmstart${VM_ID}
Echo "> > > > virtual machine $ { vm_id } has been started, please continue with the installation of the virtual machine system. "
echo
After the smooth execution, the virtual machine system can be installed.
In this embodiment, the general idea of the third script (s3_clean. Sh) is:
First, searching the virtual machine created before according to the name, and if not, exiting. And then stopping the virtual machine and deleting all the virtual CD-ROM. And searching the virtual hard disk, and if the virtual hard disk is not found, exiting. And finally setting a starting sequence, activating the virtual equipment, starting the virtual machine, and prompting the user to continue the installation of the virtual machine system.
Fifthly, implementing automatic test by the aid of the script (s4_degrading. Sh), wherein specific codes of the s4_degrading. Sh are as follows:
#!/bin/bash
#ScriptName:s4_destroy.sh
And 4. The technology point is used for deleting the virtual machine under the PVE virtual management system.
#Author:Candy
#Date:2024-08-09
#################################
Parameter configuration #)
#################################
aliasLOG='f(){echo[$(TZ=UTC-8date"+%H:%M:%S")]:$1;};f'
#################################
Procedure #
#################################
LOG "= = = = = = = = = = = = = = = = = =" start delete virtual machine= = = = = = = = = "
Read-p "> > > please input the virtual machine ID to be deleted (delete all input 0):" VM_ID
if["${VM_ID}"-eq0];then
qmlistawk'NR>1'whileIFS=read-rline;do
NAME=$(echo"$line"awk'{print$2}')
ID=$(echo"$line"awk'{print$1}')
LOG "is deleting virtual machine $ { NAME }: $ { ID }. "
qmstop${ID}
sleep3
qmdestroy${ID}--purge
LOG "virtual machine $ { NAME }: $ { ID } has been deleted. "
done
else
VM_NAME=$(qmconfig"${VM_ID}"grepnameawk-F':''{print$2}')
if[-z"${VM_NAME}"];then
LOG "virtual machine $ { VM_ID } does not exist ≡ -! "
exit1
fi
LOG "is deleting virtual machine $ { VM_NAME } $ { VM_ID }. "
qmstop${VM_ID}
sleep3
qmdestroy${VM_ID}--purge
LOG "virtual machine $ { VM_NAME }: $ { VM_ID } has been deleted. "
fi
LOG "= = = = = = = = = = = = = = = = = =" delete virtual machine completion= = = = = = = = = "
In this embodiment, the general idea of the fourth script (s4_release. Sh) is:
The user may input the virtual machine ID to be deleted, and delete all virtual machines if 0 is input. The virtual machine is stopped first, then deleted and related data is purged.
Through the steps, the automatic recording and mounting of the virtual machine system in Proxmox VE are realized, the compatibility is improved, the cost is reduced, the risk is reduced, and the efficiency is improved.
The codes of the command line interface in the diagram shown in the implementation are all required by the code specification, so that the codes cannot be translated into Chinese, and only the content of the comment part can be written into Chinese.
Example two
Based on the same conception, the invention also provides a device for automatically burning the virtual machine system, which comprises:
The temporary file storage server module is used for storing all scripts and mirror image files;
the local area network module is used for providing local network service and is used for data interaction between the temporary file storage server module and the virtual machine module;
the virtual machine module is used for creating a virtual machine with default parameters and setting the number of virtual CD-ROM and virtual hard disk to two; filling an image file of a Linux system in a mode to be maintained into a first virtual drive, filling an image file of a virtual machine system to be recorded into a second virtual drive, and setting capacities of two virtual hard disks according to requirements; setting a starting sequence, setting and activating a virtual machine according to the first virtual drive, the second virtual drive, the first virtual hard disk and the second virtual hard disk; after the virtual machine is started, a command line interface of a maintenance mode of Linux is entered; creating or downloading and executing a second script; the virtual machine system to be recorded is recorded from the second virtual CD driver into the first virtual hard disk by using the recording command; and closing the virtual machine after the successful burning.
Example III
This embodiment also provides an electronic device, referring to fig. 2, comprising a memory 404 and a processor 402, the memory 404 having stored therein a computer program, the processor 402 being arranged to run the computer program to perform the steps of any of the method embodiments described above.
In particular, the processor 402 may include a Central Processing Unit (CPU), or an application specific integrated circuit (ApplicationSpecificIntegratedCircuit, abbreviated as ASIC), or may be configured as one or more integrated circuits that implement embodiments of the present invention.
The memory 404 may include, among other things, mass storage 404 for data or instructions. By way of example, and not limitation, memory 404 may comprise a hard disk drive (HARDDISKDRIVE, abbreviated HDD), a floppy disk drive, a solid state drive (SolidStateDrive, abbreviated SSD), flash memory, an optical disk, a magneto-optical disk, a magnetic tape, or a Universal Serial Bus (USB) drive, or a combination of two or more of these. Memory 404 may include removable or non-removable (or fixed) media, where appropriate. Memory 404 may be internal or external to the data processing apparatus, where appropriate. In a particular embodiment, the memory 404 is a Non-Volatile (Non-Volatile) memory. In particular embodiments, memory 404 includes Read-only memory (ROM) and Random Access Memory (RAM). Where appropriate, the ROM may be a mask-programmed ROM, a programmable ROM (ProgrammableRead-only memory, abbreviated PROM), an erasable PROM (ErasableProgrammableRead-only memory, abbreviated EPROM), an electrically erasable PROM (ElectricallyErasableProgrammableRead-only memory, abbreviated EEPROM), an electrically rewritable ROM (ElectricallyAlterableRead-only memory, abbreviated EAROM) or a FLASH memory (FLASH), or a combination of two or more of these. The RAM may be a static random access memory (StaticRandom-access memory, abbreviated SRAM) or a dynamic random access memory (DynamicRandomAccessMemory, abbreviated DRAM) where the DRAM may be a fast page mode dynamic random access memory 404 (FastPageModeDynamicRandomAccessMemory, abbreviated FPMDRAM), an extended data output dynamic random access memory (ExtendedDateOutDynamicRandomAccessMemory, abbreviated EDODRAM), a synchronous dynamic random access memory (SynchronousDynamicRandom-access memory, abbreviated SDRAM), or the like, where appropriate.
Memory 404 may be used to store or cache various data files that need to be processed and/or used for communication, as well as possible computer program instructions for execution by processor 402.
The processor 402 reads and executes the computer program instructions stored in the memory 404 to implement any of the methods of automating the virtual machine system of the above embodiments.
Optionally, the electronic apparatus may further include a transmission device 406 and an input/output device 408, where the transmission device 406 is connected to the processor 402 and the input/output device 408 is connected to the processor 402.
The transmission device 406 may be used to receive or transmit data via a network. Specific examples of the network described above may include a wired or wireless network provided by a communication provider of the electronic device. In one example, the transmission device includes a network adapter (Network Interface Controller, simply referred to as a NIC) that can connect to other network devices through the base station to communicate with the internet. In one example, the transmission device 406 may be a Radio Frequency (RF) module, which is configured to communicate with the internet wirelessly.
The input-output device 408 is used to input or output information.
Example IV
The present embodiment also provides a readable storage medium having stored therein a computer program comprising program code for controlling a process to execute a process comprising a method of an automated virtual machine system according to embodiment one.
It should be noted that, specific examples in this embodiment may refer to examples described in the foregoing embodiments and alternative implementations, and this embodiment is not repeated herein.
In general, the various embodiments may be implemented in hardware or special purpose circuits, software, logic or any combination thereof. Some aspects of the invention may be implemented in hardware, while other aspects may be implemented in firmware or software which may be executed by a controller, microprocessor or other computing device, although the invention is not limited thereto. While various aspects of the invention may be illustrated and described as block diagrams, flow charts, or using some other pictorial representation, it is well understood that these blocks, apparatus, systems, techniques or methods described herein may be implemented in, as non-limiting examples, hardware, software, firmware, special purpose circuits or logic, general purpose hardware or controller or other computing devices, or some combination thereof.
Embodiments of the invention may be implemented by computer software executable by a data processor of a mobile device, such as in a processor entity, or by hardware, or by a combination of software and hardware. Computer software or programs (also referred to as program products) including software routines, applets, and/or macros can be stored in any apparatus-readable data storage medium and they include program instructions for performing particular tasks. The computer program product may include one or more computer-executable components configured to perform embodiments when the program is run. The one or more computer-executable components may be at least one software code or a portion thereof. In this regard, it should also be noted that any block of the logic flow as in fig. 1 may represent a procedure step, or interconnected logic circuits, blocks and functions, or a combination of procedure steps and logic circuits, blocks and functions. The software may be stored on physical media such as memory chips or memory blocks implemented within the processor, magnetic media such as hard or floppy disks, and optical media such as, for example, DVDs and data variants thereof, CDs, etc. The physical medium is a non-transitory medium.
It should be understood by those skilled in the art that the technical features of the above embodiments may be combined in any manner, and for brevity, all of the possible combinations of the technical features of the above embodiments are not described, however, they should be considered as being within the scope of the description provided herein, as long as there is no contradiction between the combinations of the technical features.
The foregoing examples illustrate only a few embodiments of the invention, which are described in greater detail and are not to be construed as limiting the scope of the invention. It should be noted that it will be apparent to those skilled in the art that various modifications and improvements can be made without departing from the spirit of the invention, which are within the scope of the invention. Accordingly, the scope of the invention should be assessed as that of the appended claims.