Virtual machine mirror image file generation method and device, electronic equipment and storage medium
By receiving cloud instructions on the edge physical machine, determining partition information and exporting it while compressing, the problems of low efficiency and large size of virtual machine image file production are solved, and efficient image file generation and compression are achieved.
Patent Information
- Application Number
- CN202510127949.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-27
- Publication Date
- 2025-05-13
AI Technical Summary
In an edge computing environment, virtual machine image files are inefficient and large in image volume. The existing technology lacks effective compression capabilities, resulting in waste of storage and transmission resources.
By receiving the mirror production instructions of the cloud server, obtaining the location information of the virtual machine system disk, determining the partition information, identifying the largest partition, and performing compression and exporting operations on the edge physical machine to generate the mirror file of the system disk.
It significantly improves the production efficiency of virtual machine image files, greatly compresses the volume of the image files, saving storage space and transmission bandwidth.
Smart Images

Figure CN119987948A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, and in particular to the fields of edge computing, virtual machine technology, and virtualized storage. It can be used in application scenarios such as virtual machine image production, and specifically relates to a method, device, electronic device, and storage medium for generating a virtual machine image file. Background Art
[0002] In the edge computing environment, virtual machines are one of the main application forms. Limited by the resources of the edge computing cluster, virtual machines mainly rely on local storage. Therefore, how to improve the efficiency of virtual machine image file production and compress the size of virtual machine images has become a technical problem that needs to be solved urgently. Summary of the invention
[0003] The present invention provides a method, device, electronic device and storage medium for generating a virtual machine image file.
[0004] According to one aspect of the present disclosure, a method for generating a virtual machine image file is provided, which is applied to an edge physical machine, and includes: receiving an image production instruction sent by a cloud server; obtaining location information of a system disk of the virtual machine; determining partition information of the system disk based on the location information; identifying the largest partition of the system disk based on the partition information; and compressing and exporting the largest partition to obtain an image file of the system disk.
[0005] According to another aspect of the present disclosure, there is provided a virtual machine image file generation device, which is applied to an edge physical machine, and includes: an instruction receiving module, which is used to receive an image production instruction sent by a cloud server; a disk positioning module, which is used to obtain the location information of the system disk of the virtual machine; an information determination module, which is used to determine the partition information of the system disk based on the location information; a partition identification module, which is used to identify the largest partition of the system disk based on the partition information; and an image production module, which is used to compress and export the largest partition to obtain an image file of the system disk.
[0006] According to another aspect of the present disclosure, there is provided an electronic device, comprising:
[0007] At least one processor: and
[0008] a memory communicatively connected to the at least one processor; wherein,
[0009] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute any method in the embodiments of the present disclosure.
[0010] According to another aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to enable the computer to execute any method according to the embodiments of the present disclosure.
[0011] According to another aspect of the present disclosure, a computer program product is provided, including a computer program, which implements any method according to the embodiments of the present disclosure when executed by a processor.
[0012] The solution disclosed in the present invention can improve the efficiency of making virtual machine image files and significantly compress the size of virtual machine image files.
[0013] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0014] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present disclosure.
[0015] Figure 1 It is a flowchart of a method for generating a virtual machine image file according to an embodiment of the present disclosure;
[0016] Figure 2 is a schematic diagram of an interface of a management console according to an embodiment of the present disclosure;
[0017] Figure 3 is a schematic diagram of an interface for creating a custom image according to an embodiment of the present disclosure;
[0018] Figure 4 It is a structural schematic diagram of a virtual machine image file generating device according to an embodiment of the present disclosure;
[0019] Figure 5 is a schematic diagram of a scenario in which a virtual machine image file is generated according to an embodiment of the present disclosure;
[0020] Figure 6 It is a structural diagram of an electronic device used to implement the method for generating a virtual machine image file according to an embodiment of the present disclosure. DETAILED DESCRIPTION
[0021] The following is a description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope of the present disclosure. Similarly, for the sake of clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0022] The term "and / or" in this article is only a description of the association relationship of associated objects, indicating that there may be three relationships. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. The term "at least one" in this article means any combination of at least two of any one or more of a plurality of. For example, including at least one of A, B, and C can mean including any one or more elements selected from the set consisting of A, B, and C. The terms "first" and "second" in this article refer to multiple similar technical terms and distinguish them. They do not mean to limit the order or to limit them to only two. For example, the first feature and the second feature refer to two types / two features. The first feature can be one or more, and the second feature can also be one or more.
[0023] In addition, in order to better illustrate the present disclosure, numerous specific details are given in the following specific embodiments. It should be understood by those skilled in the art that the present disclosure can also be implemented without certain specific details. In some examples, methods, means, components and circuits well known to those skilled in the art are not described in detail in order to highlight the subject matter of the present disclosure.
[0024] Before introducing the technical solutions of the embodiments of the present disclosure, the technical terms that may be used in the present disclosure are further explained:
[0025] Virtual machine: A simulated computer system created on physical hardware through virtualization technology. It uses a virtualization layer to abstract physical resources and allocate them to multiple independent virtual environments. Each virtual machine can run an independent operating system and application programs, which are isolated from each other and do not interfere with each other. Virtual machines are divided into system virtual machines and process virtual machines. Among them, system virtual machines can simulate a complete hardware environment to support the operating system, while process virtual machines can provide a running environment for specific applications. Virtual machine technology is widely used in server integration, development and testing, cloud computing and other fields, with advantages such as efficient resource utilization, flexible deployment and strong isolation.
[0026] Virtual machine image: A file or collection of files that contains the complete state of a virtual machine, usually used to create and deploy virtual machine instances. It stores information such as the virtual machine's operating system, applications, configuration files, and virtual hardware settings, similar to a system backup of a physical machine. Virtual machine images are portable and reproducible, and can quickly deploy the same or similar virtual machine environments. They are widely used in cloud computing, virtualization platforms, and system migration scenarios, significantly improving resource management and operation and maintenance efficiency.
[0027] Edge computing: A distributed computing paradigm that migrates data processing and analysis from the centralized cloud to the edge of the network, close to the data source or terminal device. By performing computing tasks on edge nodes, edge computing can reduce data transmission latency, reduce bandwidth consumption, and improve real-time performance and privacy protection. It is suitable for scenarios such as the Internet of Things, smart manufacturing, and autonomous driving that require low latency and high reliability. Edge computing works in conjunction with cloud computing to form an integrated "cloud-edge-end" architecture, optimizing resource utilization and system response efficiency.
[0028] Edge physical machine: refers to a physical server or computing device deployed in an edge computing environment, usually located at the edge of the network close to the data source or terminal device. Unlike virtual machines, edge physical machines run directly on hardware, providing higher computing performance and resource exclusivity. It is used to handle tasks that require high real-time, low latency, and high reliability, such as IoT data analysis, industrial automation, and smart transportation. Edge physical machines reduce dependence on centralized clouds through localized data processing, optimize bandwidth utilization and response speed, and are an indispensable core component in edge computing architecture.
[0029] Cloud server: refers to the remote computing resources provided in a cloud computing environment, usually deployed in a centralized data center. It divides the physical server into multiple virtual servers through virtualization technology to provide users with elastic and scalable computing, storage and network services. Cloud servers support on-demand resource allocation, and users can dynamically adjust the configuration according to business needs without worrying about the underlying hardware maintenance. In the edge computing architecture, cloud servers work together with edge nodes to handle non-real-time, high-complexity computing tasks, as well as data storage and large-scale analysis, forming a "cloud-edge-end" integrated distributed computing model.
[0030] In the related art, one of the core products of edge computing is virtual machines. However, in edge computing clusters, virtual machines usually rely on local storage, which leads to the problem of excessive image size under the system architecture based on edge virtual machine custom images. In order to save storage space and reduce the bandwidth and time costs in the image transmission process, it is urgent to effectively compress the virtual machine image. In the prior art, most of the public implementation schemes lack the ability to compress images, and can only simply export the user system disk as an image, resulting in a large image size; further, some schemes that support compression have insufficient compression rates and cannot significantly reduce the image size, which still puts great pressure on storage and transmission resources. At the same time, during the compression process, the virtual machine user needs to cooperate in executing specific commands in the virtual machine to facilitate subsequent compression, which not only increases the user's operating burden and interpretation cost, but also limits the practicality of the solution. Therefore, the prior art has the defect of insufficient compression capability for custom images of virtual machines in edge computing scenarios.
[0031] In order to at least partially solve one or more of the above problems and other potential problems, the present disclosure proposes a method for generating a virtual machine image file, which can ensure that the image size is greatly compressed while the image data is complete and without user intervention.
[0032] The present disclosure provides a method for generating a virtual machine image file. Figure 1 It is a flowchart of a method for generating a virtual machine image file according to an embodiment of the present disclosure. The method for generating a virtual machine image file can be applied to a virtual machine image file generating device. The virtual machine image file generating device is located in an electronic device. The electronic device includes but is not limited to fixed devices and / or mobile devices. For example, fixed devices include but are not limited to servers, and the server can be a cloud server or an ordinary server. For example, mobile devices include but are not limited to: mobile phones, tablet computers. In some possible implementations, the method for generating a virtual machine image file can also be implemented by a processor calling computer-readable instructions stored in a memory. For example Figure 1 As shown, the virtual machine image file generation method is applied to an edge physical machine, including:
[0033] S101, receiving an image creation instruction sent by a cloud server;
[0034] S102, obtaining location information of the system disk of the virtual machine;
[0035] S103, determining partition information of the system disk based on the location information;
[0036] S104, identifying the largest partition of the system disk based on the partition information;
[0037] S105, compressing and exporting the largest partition to obtain an image file of the system disk.
[0038] In the disclosed embodiment, the image production instruction refers to an operation command initiated by the cloud server and sent to the edge physical machine, which is used to trigger the generation process of the virtual machine image file. The instruction may include: image generation task identifier, virtual machine identification information, compression parameters, output path, etc. The instruction is the communication medium between the cloud server and the edge physical machine. Through the instruction, the cloud server can remotely control the edge physical machine to complete the virtual machine image generation task.
[0039] In the disclosed embodiments, the system disk of a virtual machine refers to a disk or partition that is pre-established in an edge physical machine and can be used as a virtual machine operating system to store and run core files, boot programs, and key system data. In particular, in an edge physical machine environment, the system disk of a virtual machine usually exists in the form of a virtual disk file or a directly mapped physical disk. These virtual disk files or physical disks are located in the local storage device or network storage device of the edge physical machine. Generally, when a user needs to create a virtual machine image file, the system disk of the virtual machine can be located in the local storage device of the edge physical machine, such as a mechanical hard disk and a solid-state hard disk.
[0040] In the disclosed embodiment, the location information of the system disk of the virtual machine refers to information used to locate and identify the specific storage location of the system disk of the virtual machine in the edge physical machine. For example, if the system disk of the virtual machine is a physical disk of the edge physical machine, the location information may be the device path of the physical disk; similarly, if the system disk of the virtual machine is a virtual disk file, the location information may be the storage path of the file.
[0041] In the embodiment of the present disclosure, the partition information of the system disk refers to the disk partition structure of the virtual machine system disk and its related attribute information. The partition information can determine the layout of the system disk, so as to identify the largest partition and perform subsequent compression and export operations.
[0042] In the embodiment of the present disclosure, the largest partition refers to the partition with the largest capacity on the virtual machine system disk. This partition is usually the main partition for storing operating system core files, user data or application programs.
[0043] In the disclosed embodiment, the operation of exporting while compressing is a technology that compresses data while reading and directly writes it into a target file. The core feature of this operation is data streaming, that is, data is compressed in real time during transmission, rather than reading the complete data first and then compressing it. Exemplarily, while reading data block by block from the system disk partition of the virtual machine, the read data can be compressed in real time using a compression algorithm.
[0044] In the embodiment of the present disclosure, after receiving the image creation instruction, the location path of the virtual machine system disk to be created as an image can be obtained. Subsequently, the partition status of the corresponding disk is determined according to the path, and then the partition with the largest capacity is selected. Finally, data is read from the selected partition, and the read data is compressed in real time using a compression algorithm until an image file is generated.
[0045] The technical solution of the disclosed embodiment realizes the automation of image generation by receiving instructions from the cloud server, reduces manual intervention, and improves the efficiency of image production. At the same time, by supporting remote management of virtual machine image generation tasks on edge physical machines from the cloud, it can be applied to distributed environments. By obtaining the location information of the system disk, it is ensured that subsequent operations are targeted at the correct disk device or file, avoids misoperation, and is compatible with multiple storage types. By determining the partition information, the detailed structure of the system disk can be deeply understood, thereby ensuring that the accuracy of image generation is improved in complex scenarios with multiple partitions and multiple file systems. By identifying the largest partition, the main partition storing the operating system and user data can be determined, and then compressed and exported for it, which can significantly reduce the size of the image file, while avoiding unnecessary processing of small partitions such as boot partitions and recovery partitions, saving computing resources and time. By compressing and exporting at the same time, there is no need to wait for all data to be read, and large-capacity data can be processed, and there is no need to load the entire data set into the memory, reducing the occupation of system resources, and thus being able to efficiently and reliably generate virtual machine image files in the edge computing environment.
[0046] In some embodiments, the image making instruction is sent by the management console to the cloud server; the management console generates the image making instruction after receiving the request to create a custom image initiated by the user.
[0047] In the disclosed embodiments, the management console refers to a user interface or management platform for managing and controlling virtual machine image generation tasks. The management console can serve as a bridge between the user and the cloud server, responsible for receiving the user's operation requests and converting them into specific instructions and sending them to the cloud server. Exemplarily, the management console can be a software system or platform, provided in the form of a web page or website (Web) interface, a command line tool, or an application programming interface (Application Programming Interface, API). The above is only an exemplary description and is not intended to limit all possible situations in which the management console can be presented, but it is not exhaustive here.
[0048] In the disclosed embodiment, the management console can accept a request from a user to create a custom image. Further, the management console can also generate an image creation instruction according to the user request. Furthermore, the management console can also send the generated image creation instruction to the cloud server, so that after the cloud server receives the instruction, it triggers the edge physical machine to execute the image generation task.
[0049] For example, the process of generating the image creation instruction can be triggered by the user entering the operation interface of the management console after purchasing the virtual machine, and then clicking the "Create Custom Image" button on the operation interface. The above is only an exemplary description and is not intended to limit all possible situations for generating the image creation instruction, but it is not exhaustive here.
[0050] In this way, the management console can send image creation instructions to the cloud server based on the user's operation, and the cloud server then instructs the edge physical machine to start creating virtual machine image files. During the entire image creation process, the edge physical machine adopts fully automated operation without manual intervention, which not only improves production efficiency, but also helps optimize the process and potentially reduces the size of the image file.
[0051] In some embodiments, before performing the compression and export operation on the largest partition, the method further includes: setting all unallocated data blocks on the largest partition to 0.
[0052] In the disclosed embodiment, unallocated data blocks refer to disk space that is not occupied by any file or directory. These data blocks may contain residual data of previously deleted files, or completely unused blank areas. Specifically, unallocated data blocks may contain random or meaningless data, which usually cannot be effectively compressed. If these data are compressed and exported directly, the size of the image file will increase unnecessarily and the compression efficiency will be reduced. Setting all unallocated data blocks to 0 can ensure that the data in these areas is unified and can be efficiently compressed.
[0053] In the disclosed embodiment, the process of setting all unallocated data blocks on the largest partition to 0 can first check whether the contents of the unallocated data blocks in the largest partition have been set to 0. If it is detected that there are data blocks in the unallocated data blocks that are not set to 0, the clearing operation continues.
[0054] In this way, by setting all unallocated data blocks on the largest partition to 0, it can be ensured that the unallocated data blocks after being cleared to zero occupy very little space after compression, and can even be compressed to an almost negligible size, significantly reducing the size of the generated image file and saving storage space.
[0055] In some embodiments, setting all unallocated data blocks on the largest partition to 0 includes: determining the unallocated data blocks on the largest partition; traversing all unallocated data blocks in the largest partition, and setting the contents of all unallocated data blocks to 0 to ensure that the image file does not contain useless or sensitive information, thereby improving data security and consistency.
[0056] In the process of determining the unallocated data blocks on the largest partition in the disclosed embodiment, the file system tool can be used to identify the unallocated data blocks. For example, in the Linux operating system, the fstrim command can be used to reclaim unused block resources in the file system, which can identify and mark the unallocated data blocks. The above is only an exemplary description and is not intended to limit all possible situations for determining the unallocated data blocks on the largest partition, but it is not exhaustive here.
[0057] In the disclosed embodiment, in the process of traversing all unallocated data blocks in the largest partition and setting the contents of all unallocated data blocks to 0, the first control instruction or tool can be used to fill the unallocated data blocks with 0. Exemplarily, the first control instruction can be a command to set the unused portion to zero (zerofree). Similarly, the first control instruction can also be other commands that can achieve filling the unallocated data blocks with 0. The above is only an exemplary description and is not intended to limit all possible situations of the first control instruction, but it is not exhaustive here.
[0058] In this way, by determining the unallocated data blocks, the area that needs to be cleared can be accurately located, avoiding unnecessary operations on the allocated data blocks, thereby reducing processing time and improving overall production efficiency. By traversing all unallocated data blocks in the largest partition, it is ensured that all useless data is cleared to avoid omissions, thereby improving the data consistency of the image file.
[0059] In some embodiments, the image creation instruction carries the metadata of the virtual machine, and obtains the location information of the system disk of the virtual machine, including: based on a preset correspondence, determining the location information of the system disk matching the metadata on the edge physical machine; wherein the preset correspondence records the location information of the system disk allocated to different virtual machines on the edge physical machine.
[0060] In the disclosed embodiments, meta information refers to descriptive information or attribute information related to a virtual machine, which is used to describe key attributes of the virtual machine, such as configuration, state, storage location, etc. In particular, the meta information itself is not the actual data of the virtual machine, but a structured description of the data.
[0061] In the disclosed embodiment, the preset correspondence exists in the edge physical machine. Generally, in a virtualized environment, the edge physical machine is usually responsible for running multiple virtual machines. Each virtual machine requires a system disk to store the operating system and application data. In order to effectively manage these resources, the system will establish a preset correspondence to record the mapping relationship between each virtual machine and its system disk. When it is necessary to find the system disk location of a virtual machine, it is only necessary to find the corresponding system disk location information in the preset correspondence based on the meta information of the virtual machine.
[0062] In this way, by presetting the corresponding relationship, the meta information of the virtual machine is associated with the location information of the system disk, ensuring that the location information of the system disk can be accurately and quickly located, avoiding errors caused by manual operation. By presetting the corresponding relationship and meta information, the automatic query and matching of the system disk location information is realized, thereby reducing manual intervention and improving the automation of the image generation task, which is particularly suitable for large-scale edge computing scenarios. At the same time, it can significantly reduce the query time of the system disk location information and improve the execution efficiency of the image generation task.
[0063] In some embodiments, determining the partition information of the system disk based on the location information includes: locating the system disk based on the location information; acquiring partition layout data of the system disk; and extracting and displaying the partition information of the system disk based on the partition layout data.
[0064] In the disclosed embodiment, locating the system disk based on location information refers to the process of finding the target disk device or file according to the specific storage location or identification information of the system disk, and the storage location of the system disk can be determined according to the type of location information. Exemplarily, the type of location information may include device path, file path, and network storage identification, etc. The above is only an exemplary description and is not intended to limit all possible situations of the location information type, but it is not exhaustive here.
[0065] In the disclosed embodiment, the process of obtaining the partition layout data of the system disk may first send a second control instruction to the system disk, where the second control instruction is used to request the display of the partition information of the system disk; and then receive the partition layout data returned by the system disk. The partition layout data includes key information such as the starting position of the system disk partition, the partition size, and the partition file system type, and may also include information such as the partition table type, partition number, and partition end position. Exemplarily, the second control instruction may be a command that enables the operating system to reread the partition table (partprobe). Similarly, the second control instruction may also be other commands that can realize the request to display the partition information of the system disk. The above is only an exemplary description and is not intended to limit all possible situations of the second control instruction, but it is not exhaustive here.
[0066] In the disclosed embodiment, the process of extracting and displaying the partition information of the system disk based on the partition layout data can first parse the key information from the partition layout data, then organize the partition information into a table or structured format, and finally output the formatted information to the console, log file or user interface.
[0067] In this way, the system disk is accurately located through location information, and partition information is extracted based on partition layout data, which can ensure the accuracy and completeness of partition information and avoid errors caused by manual operation. The acquisition and display of partition information through automated tools and scripts can reduce manual intervention and improve the degree of task automation, which is particularly suitable for large-scale edge computing scenarios. Centralized management of partition information through automated tools and scripts can support the operation of multiple virtual machines and multiple edge nodes, thereby simplifying the management of multiple virtual machines and multiple edge nodes and reducing the complexity of operation and maintenance.
[0068] In some embodiments, identifying the largest partition of the system disk based on the partition information includes: parsing the partition information to extract size information of each partition on the system disk; traversing the size information of all extracted partitions to identify the largest partition.
[0069] In the disclosed embodiment, the process of parsing the partition information to extract the size information of each partition on the system disk can first extract the size information of each partition from the partition layout data, and then uniformly convert the size information of each partition into the same unit to facilitate subsequent comparison. Further, a third control instruction can be used to traverse the size information of all extracted partitions to identify the largest partition. Exemplarily, the third control instruction can be a command for managing the disk partition table (partx), and can also be obtained using other commands for managing disk partitions in the Linux system. The above is only an exemplary description and is not intended to limit all possible situations of the third control instruction, but it is not exhaustive here.
[0070] In this way, by parsing the partition information through automated tools and accurately identifying the largest partition based on the partition size information, it is possible to ensure that the identification result of the largest partition is accurate, avoid errors caused by manual operations, and thus reduce human intervention and improve the degree of task automation, which is particularly suitable for large-scale edge computing scenarios.
[0071] In some embodiments, the largest partition is compressed and exported to obtain an image file of the system disk, including: determining a target compression algorithm based on at least one of the size and data type of the largest partition; selecting a disk image format that supports compression as an output format, applying the target compression algorithm while reading the system disk, and exporting the compressed data as an image file.
[0072] In the disclosed embodiment, the process of determining the target compression algorithm according to at least one of the size and data type of the largest partition can select a compression algorithm according to the size and / or data type of the largest partition in combination with the image usage requirements. Exemplarily, if the largest partition is large, an algorithm with a higher compression ratio can be selected to reduce the size of the image file; if the largest partition is small, an algorithm with a faster compression speed can be selected to speed up task execution. Similarly, if the largest partition contains a large amount of duplicate data, an algorithm with a higher compression ratio can be selected; if the largest partition contains random data, an algorithm with a faster compression speed can be selected. In particular, other methods can also be used to select a compression algorithm according to at least one of the size and data type of the largest partition. The above is only an exemplary description and is not intended to limit all possible situations for selecting a compression algorithm, but it is not exhaustive here.
[0073] In the disclosed embodiment, a disk image format that supports compression is selected as the output format, a target compression algorithm is applied while reading the system disk, and the compressed data is exported as an image file. The process can first select a disk image format that supports compression according to the target compression algorithm and the requirements of the virtualization environment, and then use some tools or scripts or a fourth control instruction to compress while reading the system disk data, and write the compressed data to the image file. Exemplarily, the fourth control instruction can be a disk image management tool (Qemu-img) command, or it can be implemented using other commands in the prior art for creating, converting, modifying, and checking various disk image formats. The above is only an exemplary description and is not intended to limit all possible situations of the fourth control instruction, but it is not exhaustive here.
[0074] In this way, by selecting the most suitable compression algorithm based on the size and data type of the largest partition, the compression efficiency can be improved, ensuring the best balance between compression rate and compression speed. By using efficient compression algorithms and compression formats, the size of image files can be significantly reduced, storage space can be saved, and storage costs can be reduced. By using the streaming processing method of compressing and exporting at the same time, the intermediate steps and resource usage can be reduced, which can improve the efficiency of task execution and reduce processing time and resource consumption.
[0075] In some embodiments, after the user issues an instruction to create an image, the virtual machine is shut down in conjunction, the instruction to create an image is passed from the cloud to the edge, and the edge compression component starts working. Subsequently, after obtaining the location of the user's system disk, use the partprobe command on the physical machine to act on the system disk block device to display all partitions of the system disk. Next, use the partx command to obtain the largest system partition. If the user's system disk can have multiple partitions, select the largest partition used by the file system. Then use the zerofree command to act on the largest partition. The zerofree command can set all unallocated block devices on the file system to 0. This can eliminate residual data in the file system and allow unused space to be compressed. Finally, use the Qemu-img command to compress and export the system disk to generate a virtual machine image file.
[0076] In some embodiments, to solve the problem of low compression efficiency of hard disk drives (HDDs), the virtual machine disk can be sparsified first. For example, when there is a large amount of unused space in the virtual machine disk image, you can use the command line tool (virt-sparsify) to compress it to free up storage space on the host. The first compression is achieved by using the command line tool to organize the data in the hard disk and convert it into a solid state drive (SSD) storage mode; then, execute steps S101 to S105 in the disclosed embodiment to achieve the second compression.
[0077] In the process of generating a virtual machine image using the prior art, when the user disk has a total of 100G and 34G has been used, the size of the completed image is about 71G. When the method for generating a virtual machine image file in the embodiment of the present disclosure is used, when the user disk has a total of 100G and 34G has been used, the size of the completed image is about 26G. Therefore, the method for generating a virtual machine image file in the embodiment of the present disclosure can significantly reduce the image size.
[0078] Figure 2 A schematic diagram of the interface of the management console of the embodiment of the present disclosure is shown. Figure 2As shown in the figure, after purchasing a virtual machine, users will be granted access to the management console. On the operation interface of the management console, users first need to log in to the management console of the virtual machine using the provided credentials. In the console interface, users select the target virtual machine for which they want to create a custom image from the list of virtual machines. After selecting the virtual machine, users can find and click the "Create Custom Image" button in the corresponding operation menu or setting area. This step will start the image creation process. After clicking the button, the system may ask the user to confirm or enter some parameters for image creation, such as image name, description, whether to include data disk images, etc. These parameters help users better manage and identify subsequently generated images.
[0079] Figure 3 A schematic diagram of an interface for creating a custom image according to an embodiment of the present disclosure is shown. Figure 3 As shown in the figure, after the user clicks the "Create Custom Image" button, he can follow the prompts on the interface to fill in the image file name, select the image type, and then initiate a request to create a custom image. Once all the necessary information is confirmed, the system will start to create the system disk image of the virtual machine. After the image is created, the system will notify the user that the image has been generated and provide options for downloading, storing, or applying.
[0080] It should be understood that Figure 2 and Figure 3 The schematic diagram shown is only exemplary and not restrictive, and it is scalable, and those skilled in the art can Figure 2 and Figure 3 Various obvious changes and / or substitutions can be made to the examples, and the resulting technical solutions still fall within the scope of the disclosure of the embodiments of the present disclosure.
[0081] The present disclosure provides a virtual machine image file generation device, such as Figure 4 As shown, the device may include: an instruction receiving module 401, used to receive an image creation instruction sent by a cloud server; a disk positioning module 402, used to obtain the location information of the system disk of the virtual machine; an information determination module 403, used to determine the partition information of the system disk based on the location information; a partition identification module 404, used to identify the largest partition of the system disk based on the partition information; and an image creation module 405, used to compress and export the largest partition to obtain an image file of the system disk.
[0082] In some embodiments, the image making instruction is sent by the management console to the cloud server; the management console generates the image making instruction after receiving the request to create a custom image initiated by the user.
[0083] In some embodiments, the virtual machine image file generation device further includes: a data processing module, configured to set all unallocated data blocks on the largest partition to 0.
[0084] In some embodiments, the data processing module includes: a data determination submodule, used to determine the unallocated data blocks on the largest partition; a data assignment submodule, used to traverse all unallocated data blocks in the largest partition and set the contents of all unallocated data blocks to 0.
[0085] In some embodiments, the image creation instruction carries metadata of the virtual machine, and the disk positioning module 402 includes: an information matching submodule, which is used to determine the location information of the system disk matching the metadata on the edge physical machine based on a preset correspondence; wherein the preset correspondence records the location information of the system disk allocated to different virtual machines on the edge physical machine.
[0086] In some embodiments, the information determination module 403 includes: a system positioning submodule, used to locate the system disk based on the location information; a partition acquisition submodule, used to obtain the partition layout data returned by the system disk; and an information extraction submodule, used to extract and display the partition information of the system disk based on the partition layout data.
[0087] In some embodiments, the partition identification module 404 includes: a partition parsing submodule for parsing partition information to extract size information of each partition on the system disk; and a partition determination submodule for traversing the size information of all extracted partitions to identify the largest partition.
[0088] In some embodiments, the image production module 405 includes: an algorithm determination submodule, which is used to determine the target compression algorithm based on at least one of the size of the largest partition and the data type; an image export submodule, which is used to select a disk image format that supports compression as the output format, apply the target compression algorithm while reading the system disk, and export the compressed data as an image file.
[0089] For the description of specific functions and examples of each module and submodule of the device in the embodiment of the present disclosure, reference can be made to the relevant description of the corresponding steps in the above method embodiment, which will not be repeated here.
[0090] The virtual machine image file generation device in the embodiment of the present disclosure can implement an automated image generation process on an edge physical machine, thereby reducing manual intervention, greatly improving the efficiency of image production, and significantly compressing the size of the virtual machine image file.
[0091] The present disclosure provides a schematic diagram of a scenario for generating a virtual machine image file, such as Figure 5 shown.
[0092] As mentioned above, the method for generating a virtual machine image file provided by the embodiment of the present disclosure is applied to electronic devices. The electronic devices are intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, servers, blade servers, mainframe computers, and other suitable computers.
[0093] Specifically, the electronic device can perform the following operations:
[0094] Receive the image creation instruction sent by the cloud server;
[0095] Get the location information of the system disk of the virtual machine;
[0096] Determine partition information of the system disk based on the location information;
[0097] Identify the largest partition of the system disk based on the partition information;
[0098] Compress and export the largest partition at the same time to obtain the image file of the system disk.
[0099] Specifically, Figure 5 As shown, first, the user accesses the management and control platform of the cloud server to initiate a custom image production request, and the management and control platform of the cloud server sends the request as an image production instruction to the edge physical machine; then, the edge physical machine, as an electronic device, executes the operations of steps S102 to S105 in the embodiment of the present disclosure, and stores the generated image file in the database; finally, the edge physical machine reads the generated image file and sends an image production completion notification to the management and control platform, so that the management and control platform displays the notification to the user.
[0100] It should be understood that Figure 5 The scene diagram shown is only illustrative and not restrictive. Those skilled in the art can Figure 5 Various obvious changes and / or substitutions can be made to the examples, and the resulting technical solutions still fall within the scope of the disclosure of the embodiments of the present disclosure.
[0101] In the technical solution disclosed herein, the acquisition, storage and application of user personal information involved are in compliance with the provisions of relevant laws and regulations and do not violate public order and good morals.
[0102] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium and a computer program product.
[0103] Figure 6A schematic block diagram of an example electronic device 600 that can be used to implement an embodiment of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital assistants, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or required herein.
[0104] like Figure 6 As shown, the device 600 includes a computing unit 601, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 602 or a computer program loaded from a storage unit 608 to a random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the device 600 can also be stored. The computing unit 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.
[0105] A number of components in the device 600 are connected to the I / O interface 605, including: an input unit 606, such as a keyboard, a mouse, etc.; an output unit 607, such as various types of displays, speakers, etc.; a storage unit 608, such as a disk, an optical disk, etc.; and a communication unit 609, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 609 allows the device 600 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0106] The computing unit 601 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 601 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSP), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 601 performs the various methods and processes described above, such as a virtual machine image file generation method. For example, in some embodiments, the virtual machine image file generation method may be implemented as a computer software program, which is tangibly included in a machine-readable medium, such as a storage unit 608. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 600 via the ROM 602 and / or the communication unit 609. When the computer program is loaded into the RAM 603 and executed by the computing unit 601, one or more steps of the virtual machine image file generation method described above may be performed. Alternatively, in other embodiments, the computing unit 601 may be configured to execute the virtual machine image file generation method in any other appropriate manner (for example, by means of firmware).
[0107] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0108] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0109] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or device, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory, a read-only memory, an erasable programmable read-only memory (EPROM), a flash memory, an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0110] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a cathode ray tube (CRT) or a liquid crystal display (LCD) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0111] The systems and techniques described herein can be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: Local Area Networks (LANs), Wide Area Networks (WANs), and the Internet.
[0112] A computer system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The relationship of client and server is generated by computer programs running on respective computers and having a client-server relationship with each other. The server may be a cloud server, a server of a distributed system, or a server combined with a blockchain.
[0113] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and this document does not limit this.
[0114] The above specific implementations do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the principles of the present disclosure shall be included in the protection scope of the present disclosure.
Claims
1. A method for generating a virtual machine image file, applied to an edge physical machine, comprising: Receive the image creation instruction sent by the cloud server; Get the location information of the system disk of the virtual machine; Determine partition information of the system disk based on the location information; Identify the largest partition of the system disk based on the partition information; The largest partition is compressed and exported at the same time to obtain the image file of the system disk.
2. The method according to claim 1, wherein: The image making instruction is sent by the management console to the cloud server; the management console generates the image making instruction after receiving a request to create a custom image initiated by a user.
3. The method according to claim 1, wherein: Before performing the compression and export operation on the largest partition, the method further includes: Set all unallocated blocks on the largest partition to zero.
4. The method according to claim 3, wherein: The step of setting all unallocated data blocks on the largest partition to 0 includes: Determining unallocated data blocks on the largest partition; All unallocated data blocks in the largest partition are traversed, and the contents of all unallocated data blocks are set to 0.
5. The method according to claim 1, wherein: The image creation instruction carries the meta information of the virtual machine, and the obtaining the location information of the system disk of the virtual machine includes: Based on a preset correspondence, the location information of the system disk matching the meta-information on the edge physical machine is determined; wherein the preset correspondence records the location information of the system disks allocated to different virtual machines on the edge physical machine.
6. The method according to claim 1, wherein: The determining the partition information of the system disk based on the location information includes: Based on the location information, locate the system disk; Acquire partition layout data of the system disk; The partition information of the system disk is extracted and displayed based on the partition layout data.
7. The method according to claim 1, wherein: The identifying the largest partition of the system disk based on the partition information includes: Parsing the partition information to extract size information of each partition on the system disk; The size information of all extracted partitions is traversed to identify the largest partition.
8. The method according to claim 1, wherein: The step of compressing and exporting the largest partition to obtain the image file of the system disk includes: Determining a target compression algorithm according to at least one of the size and data type of the largest partition; A disk image format that supports compression is selected as the output format, the target compression algorithm is applied while reading the system disk, and the compressed data is exported as the image file.
9. A virtual machine image file generation device, applied to an edge physical machine, comprising: An instruction receiving module is used to receive an image creation instruction sent by a cloud server; The disk location module is used to obtain the location information of the system disk of the virtual machine; An information determination module, used to determine the partition information of the system disk based on the location information; A partition identification module, used to identify the largest partition of the system disk based on the partition information; The image making module is used to compress and export the largest partition at the same time to obtain the image file of the system disk.
10. The device according to claim 9, wherein: The image making instruction is sent by the management console to the cloud server; the management console generates the image making instruction after receiving a request to create a custom image initiated by a user.
11. The device according to claim 9, wherein: The device also includes: The data processing module is used to set all unallocated data blocks on the largest partition to 0.
12. The device according to claim 11, wherein The data processing module comprises: A data determination submodule, used for determining unallocated data blocks on the largest partition; The data assignment submodule is used to traverse all unallocated data blocks in the largest partition and set the contents of all unallocated data blocks to 0.
13. The device according to claim 9, wherein: The image creation instruction carries the meta information of the virtual machine, and the disk positioning module includes: The information matching submodule is used to determine the location information of the system disk matching the meta-information on the edge physical machine based on a preset correspondence relationship; wherein the preset correspondence relationship records the location information of the system disk allocated to different virtual machines on the edge physical machine.
14. The device according to claim 9, wherein: The information determination module comprises: A system positioning submodule, used for positioning the system disk based on the position information; A partition acquisition submodule, used to acquire the partition layout data returned by the system disk; The information extraction submodule is used to extract and display the partition information of the system disk based on the partition layout data.
15. The device according to claim 9, wherein: The partition identification module includes: A partition parsing submodule, used for parsing the partition information to extract the size information of each partition on the system disk; The partition determination submodule is used to traverse the size information of all extracted partitions to identify the largest partition.
16. The device according to claim 9, wherein: The image making module comprises: An algorithm determination submodule, used for determining a target compression algorithm according to at least one of the size and data type of the largest partition; The image export submodule is used to select a disk image format that supports compression as an output format, apply the target compression algorithm while reading the system disk, and export the compressed data as the image file.
17. An electronic device comprising: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 8.
18. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to cause the computer to execute the method according to any one of claims 1 to 8.
19. A computer program product comprising a computer program stored on a storage medium, the computer program implementing the method according to any one of claims 1 to 8 when executed by a processor.