Image generation method, device, equipment, storage medium and program product
By copying and sequentially running configuration script files in a virtual machine and using interrupt flags for debugging, the problem of low efficiency in traditional image generation is solved and the efficiency of image production is improved.
Patent Information
- Application Number
- CN202510866380.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-26
- Publication Date
- 2025-09-30
- Estimated Expiration
- 2045-06-26
AI Technical Summary
In traditional image generation methods, the configuration of customized content requires manual debugging, resulting in low image generation efficiency. Debugging cannot be interrupted and requires repeated iterations to complete.
By copying the configuration script file in the virtual machine and running the script file in sequence according to the sequence identifier and the interrupt identifier, the interrupt script file is introduced for debugging to generate the target image.
This eliminates the need to wait for image generation to be completed before debugging, avoiding repeated debugging and improving image production efficiency.
Smart Images

Figure CN120371328B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of cloud computing technology, and in particular to a mirror generation method, apparatus, device, storage medium, and program product. Background Art
[0002] An image is a file or data set containing an operating system, software, configuration information, and other content. It can be used to quickly create and deploy computer systems or application environments. For example, a bare metal image is a system image for a bare metal server. It contains the operating system and possibly pre-installed basic software and configuration information. Bare metal servers, in a cloud computing environment, provide users with direct access to and use of physical servers without the need for virtualization technology to share hardware resources among multiple users.
[0003] Traditionally, images are typically created using image generation tools and exported in a pre-defined format. The image creation process typically consists of two phases: the first phase involves installing the ISO system file (a disc image file) on the virtual machine and exporting the base image. The second phase involves configuring customized content (such as partitions and drivers) within the installed virtual machine and exporting the customized image. This second phase typically automates image configuration by pre-configuring customized content such as scripts, drivers, and software packages.
[0004] Traditionally, the second phase of script and driver installation required manual debugging. Each customization required recreating and exporting the image, and debugging again after the image was created, without interruption. Complex customizations required repeated debugging, leading to inefficient image generation. Summary of the Invention
[0005] Based on this, it is necessary to provide a mirror image generation method, device, equipment, storage medium and program product to address the above technical problems, which can improve the efficiency of image generation.
[0006] In a first aspect, the present application provides a method for generating an image, comprising:
[0007] Copy each configuration script file to a virtual machine; wherein the virtual machine is created based on a base image; the base image provides a basic operating system environment for the virtual machine;
[0008] Running each configuration script file in sequence according to a sequence identifier of each configuration script file and an interrupt identifier of an interrupt script file in each configuration script file to implement configuration of the base image; wherein the interrupt identifier is used to indicate that the configuration script file after the interrupt script file is interrupted in order to debug the configuration script file before the interrupt script file;
[0009] After all configuration scripts are executed, the target image is generated based on the configured base image.
[0010] In one embodiment, the step of sequentially running each configuration script file according to a sequence identifier of each configuration script file and an interrupt identifier of an interrupt script file in each configuration script file includes:
[0011] According to the sequence identifier of each configuration script file, run each configuration script file in sequence;
[0012] In the process of sequentially running each configuration script file, if an interruption mark is identified, the configuration script file after the interruption script file is interrupted, and the configuration script file before the interruption script file is debugged;
[0013] After the configuration script file before the interruption script file is debugged, if a continue running instruction is obtained, the configuration script file after the interruption script file will continue to run.
[0014] In one embodiment, the base image includes a public key for connecting to the virtual machine; and running each configuration script file in sequence according to a sequence identifier of each configuration script file and an interrupt identifier of an interrupt script file in each configuration script file includes:
[0015] Controlling the virtual machine to sequentially execute each configuration script file according to a sequence identifier of each configuration script file through a first session connection; wherein the first session connection is a session connection with the virtual machine established using a private key that matches the public key;
[0016] During the process of the virtual machine sequentially running each configuration script file, if an interruption mark is identified, the execution of the configuration script file following the interruption script file is interrupted;
[0017] Debugging the configuration script file before the interruption script file through a second session connection; wherein the second session connection is a session connection with the virtual machine established using a private key matching the public key;
[0018] After the configuration script file preceding the interruption script file is debugged, if a continuing execution instruction triggered based on the first session connection is obtained, the configuration script file following the interruption script file continues to be executed.
[0019] In one embodiment, generating a target image based on the configured base image includes:
[0020] Obtaining a log file; wherein the log file includes data records of configuring the base image;
[0021] Verify the configured base image based on the log file;
[0022] If the verification passes, the public key in the configured base image is deleted to obtain the target image.
[0023] In one embodiment, the interrupt flag is established in the following manner:
[0024] Determine the sequence identifier and file identifier of the configuration script file that needs to be debugged;
[0025] The interruption identifier is obtained by combining the sequence identifier, the file identifier and the interruption function identifier of the configuration script file that needs to be debugged.
[0026] In one embodiment, each configuration script file includes a common script file and a customized script file; the interruption script file belongs to the common script file;
[0027] The step of copying each configuration script file to the virtual machine includes:
[0028] Copying the customized script file to the image production directory, and copying the public script file to the image production directory through the soft link corresponding to the public script file; wherein the soft link corresponding to the public script file includes the storage path of the public script file and the path of the image production directory;
[0029] The public script file and the customized script file are copied from the image production directory to the virtual machine through virtualization software.
[0030] In a second aspect, the present application further provides an image generation device, comprising:
[0031] An acquisition module is used to copy each configuration script file to a virtual machine; wherein the virtual machine is created based on a base image; the base image provides a basic operating system environment for the virtual machine;
[0032] A running module, configured to run each configuration script file in sequence according to a sequence identifier of each configuration script file and an interrupt identifier of an interrupt script file in each configuration script file, so as to configure the base image; wherein the interrupt identifier is used to indicate that the configuration script file after the interrupt script file is interrupted in order to debug the configuration script file before the interrupt script file;
[0033] The generation module is used to generate the target image according to the configured base image after all configuration script files have been run.
[0034] In a third aspect, the present application further provides a computer device comprising a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0035] Copy each configuration script file to a virtual machine; wherein the virtual machine is created based on a base image; the base image provides a basic operating system environment for the virtual machine;
[0036] Running each configuration script file in sequence according to a sequence identifier of each configuration script file and an interrupt identifier of an interrupt script file in each configuration script file to implement configuration of the base image; wherein the interrupt identifier is used to indicate that the configuration script file after the interrupt script file is interrupted in order to debug the configuration script file before the interrupt script file;
[0037] After all configuration scripts are executed, the target image is generated based on the configured base image.
[0038] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the following steps are implemented:
[0039] Copy each configuration script file to a virtual machine; wherein the virtual machine is created based on a base image; the base image provides a basic operating system environment for the virtual machine;
[0040] Running each configuration script file in sequence according to a sequence identifier of each configuration script file and an interrupt identifier of an interrupt script file in each configuration script file to implement configuration of the base image; wherein the interrupt identifier is used to indicate that the configuration script file after the interrupt script file is interrupted in order to debug the configuration script file before the interrupt script file;
[0041] After all configuration scripts are executed, the target image is generated based on the configured base image.
[0042] In a fifth aspect, the present application further provides a computer program product, comprising a computer program, which, when executed by a processor, implements the following steps:
[0043] Copy each configuration script file to a virtual machine; wherein the virtual machine is created based on a base image; the base image provides a basic operating system environment for the virtual machine;
[0044] Running each configuration script file in sequence according to a sequence identifier of each configuration script file and an interrupt identifier of an interrupt script file in each configuration script file to implement configuration of the base image; wherein the interrupt identifier is used to indicate that the configuration script file after the interrupt script file is interrupted in order to debug the configuration script file before the interrupt script file;
[0045] After all configuration scripts are executed, the target image is generated based on the configured base image.
[0046] The above-mentioned image generation method, device, equipment, storage medium and program product copies each configuration script file to the virtual machine; according to the sequence identifier of each configuration script file and the interrupt identifier of the interrupt script file in each configuration script file, each configuration script file is run in sequence to realize the configuration of the basic image; after each configuration script file has been run, the target image is generated according to the configured basic image. The above-mentioned scheme introduces an interrupt script file, which can interrupt the execution of the script during the execution of each configuration script file to interrupt the execution of the configuration script file after the interrupt script file, so as to debug the configuration script file before the interrupt script file; there is no need to debug after the target image is completed, which avoids the problem of repeated debugging, thereby improving the efficiency of image production. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] In order to more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the following briefly introduces the drawings required for use in the embodiments of the present application or related technical descriptions. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying any creative work.
[0048] Figure 1 Schematic diagram of a process for generating an image in one embodiment;
[0049] Figure 2 A schematic diagram of a process for sequentially running configuration script files in one embodiment;
[0050] Figure 3 A schematic diagram of a flow chart for sequentially executing configuration script files in another embodiment;
[0051] Figure 4 A schematic diagram of a process for generating a target image in one embodiment;
[0052] Figure 5 A schematic diagram of a process for generating an interruption flag in one embodiment;
[0053] Figure 6A schematic diagram of a process for copying configuration script files to a virtual machine in one embodiment;
[0054] Figure 7 Schematic diagram of a flow chart of a mirror image generation method according to another embodiment;
[0055] Figure 8 is a structural block diagram of an image generation device in one embodiment;
[0056] Figure 9 FIG. 1 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0057] In order to make the purpose, technical solutions and advantages of this application more clear, the following further describes this application in detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain this application and are not intended to limit this application.
[0058] The image generation method provided in the embodiment of the present application can be applied to the application scenario of making a system image. The method can be executed by a server or a terminal with a certain computing power.
[0059] The server can be a standalone physical server, a server cluster or distributed system consisting of multiple physical servers, or a cloud server providing cloud computing services. Terminals can include, but are not limited to, various personal computers, laptops, smartphones, tablets, IoT devices, and portable wearable devices. IoT devices can include smart speakers, smart TVs, smart air conditioners, smart car devices, and projectors. Portable wearable devices can include smart watches, smart bracelets, and head-mounted devices. Head-mounted devices can include virtual reality (VR) devices, augmented reality (AR) devices, smart glasses, and more.
[0060] In an exemplary embodiment, Figure 1 As shown, a mirror generation method is provided, which is described by taking the application of the method to a server as an example, and includes the following steps:
[0061] S101, copy each configuration script file to the virtual machine.
[0062] For example, the process of generating an image file may involve two stages, wherein the first stage may be to install an ISO system file on a virtual machine and export a base image, wherein the ISO system file is a CD image file containing an operating system installation program and related files.
[0063] In the first stage, you can first download the system ISO file and check the checksum. A checksum is a string calculated based on the file content using a preset algorithm, such as Message-Digest Algorithm 5 (MD5), Secure Hash Algorithm 1 (SHA-1), or Secure Hash Algorithm 256-bit (SHA-256). Different file contents generate different checksums, and even minor changes in the file content can result in completely different checksums. Therefore, by comparing the checksum of the downloaded file with the official checksum, you can determine whether the file was downloaded incorrectly or tampered with.
[0064] Secondly, you can install the system in a Quick Emulator (QEMU) virtual machine using automated installation methods such as kickstart or preseed. After shutting down the virtual machine, save the virtual machine image as a base image. The base image can be in raw image format (raw) or qcow2 format. qcow2 is a disk image format that supports dynamic allocation, copy-on-write, and snapshots.
[0065] In the second stage, first, the base image can be downloaded to a new virtual machine, that is, a new virtual machine can be created based on the base image, that is, the virtual machine is created based on the base image; the base image provides the basic operating system environment for the virtual machine.
[0066] Then, each configuration script file can be copied to the virtual machine. Each configuration script file is used to perform system configuration, service and process configuration, security hardening, file and directory operation settings, containerization configuration, and automated test integration on the base image. After the base image is configured based on each configuration script file, an image file in a preset format is exported to obtain the target image file.
[0067] Based on this, in the second stage, each configuration script file needs to be copied to the virtual machine. Each configuration script file is usually saved in the image production directory. Each configuration script file needs to be copied to the virtual machine to configure the basic image using each configuration script file.
[0068] S102 , running each configuration script file in sequence according to the sequence identifier of each configuration script file and the interruption identifier of the interruption script file in each configuration script file, so as to realize the configuration of the basic image.
[0069] For example, each configuration script file can be named according to a unified naming format, which needs to include a sequence identifier so that each configuration script file can be run in sequence. Furthermore, if the configuration script file is an interruption script file, the interruption script file's naming format needs to include an interruption identifier. The interruption identifier is used to indicate that the configuration script file after the interruption script file is interrupted, so that the configuration script file before the interruption script file can be debugged.
[0070] Exemplarily, each configuration script file can be named in the format of "[0-9]+[0-9]+script name". For example, the name of a configuration script file is "12-config-dns.sh", where "12" is used to indicate the execution order of the configuration script file. If it is necessary to execute an interrupt operation after the configuration script file named "12-config-dns.sh", an interrupt script file can be placed after the configuration script file. The interrupt script file can be named "12-config-dns-hold.sh" to indicate that the interrupt operation is executed after the configuration script file named "12-config-dns.sh". "12-config-dns-hold.sh" has the "hold" identifier, so the name of the interrupt script file can be used as the interrupt identifier.
[0071] For example, each configuration script file can be run sequentially based on its sequence identifier and the interrupt identifier of the interrupt script file within each configuration script file. For example, each configuration script file can be run sequentially based on its sequence identifier; during the execution of each configuration script file, if the interrupt identifier of the interrupt script file within the configuration script file is identified, the execution of the configuration script file after the interrupt script file needs to be interrupted to debug the configuration script file before the interrupt script file. After all configuration script files have completed execution, the configuration of the base image is complete.
[0072] S103: After all configuration script files have been executed, a target image is generated according to the configured base image.
[0073] Exemplarily, after each configuration script file has been executed, i.e., after the configuration operations for the base image have been completed according to each configuration script file, a target image can be generated based on the configured base image. For example, the configured base image can be converted into a preset image format to obtain the target image. Preset image formats include, but are not limited to, qcow2, raw, and compressed read-only file systems such as squashfs.
[0074] The above-mentioned image generation method copies each configuration script file into the virtual machine; according to the sequence identifier of each configuration script file and the interrupt identifier of the interrupt script file in each configuration script file, each configuration script file is run in sequence to realize the configuration of the basic image; after each configuration script file has been run, the target image is generated according to the configured basic image. The above-mentioned scheme introduces an interrupt script file, which can interrupt the execution of the script during the execution of each configuration script file to interrupt the execution of the configuration script file after the interrupt script file, so as to debug the configuration script file before the interrupt script file; there is no need to debug after the target image is completed, which avoids the problem of repeated debugging, thereby improving the efficiency of image production.
[0075] In some optional implementations, during the execution of each configuration script file, an interruption script file may be performed to debug the configuration script file; and when a continue execution instruction is identified, the subsequent configuration script file may continue to execute.
[0076] Based on this, see Figure 2 , Figure 2 A flowchart of running each configuration script file in sequence is provided, which specifically includes the following steps:
[0077] S201 , running each configuration script file in sequence according to the sequence identifier of each configuration script file.
[0078] Exemplarily, each configuration script file can be named according to the naming format of "[0-9]+[0-9]+script name", where "[0-9]+[0-9]" is the sequential identifier of each configuration script file, which is used to indicate the running order of each configuration script file. Therefore, each configuration script file can be run in sequence according to the sequential identifier of each configuration script file.
[0079] S202 : During the process of sequentially running each configuration script file, if an interruption mark is identified, the configuration script file following the interruption script file is interrupted, and the configuration script file before the interruption script file is debugged.
[0080] If a hold flag is detected while running each configuration script file, the configuration script file after the hold flag can be halted and the configuration script file before the hold flag can be debugged. The hold flag is included in the name of the hold script file. If a file name containing the hold flag is detected, it is considered that a hold flag has been detected. The configuration script file after the hold flag can be halted and the configuration script file before the hold flag can be debugged.
[0081] For example, by adding the startup parameter HOLD variable, an interrupt script file for debugging intervention can be added to support pausing the image configuration process during the automated image production process, facilitating troubleshooting, testing the installation process of drivers and software packages, updating software packages and scripts, and other operations.
[0082] Exemplarily, after interrupting the execution of the configuration script file after the interruption script file, the server may automatically debug the configuration script file before the interruption script file; or may send a debugging prompt message to the debugger to prompt the debugger to debug the configuration script file before the interruption script file.
[0083] S203: After the configuration script file before the interruption script file is debugged, if a continue execution instruction is obtained, the configuration script file after the interruption script file is continued to execute.
[0084] After the configuration script file before the interrupt script file is debugged, a continue-run instruction can be automatically generated or a continue-run instruction can be sent to the server. If the continue-run instruction is obtained, the configuration script file after the interrupt script file can be continued to run.
[0085] The continue running instruction may be customized and may be set to a specified field or instruction information. For example, the continue running instruction may be set to "continue".
[0086] In an embodiment of the present application, by setting an interrupt script file, it is possible to interrupt the execution of the configuration script file after the interrupt script file when an interrupt identifier is identified, and debug the configuration script file before the interrupt script file. In this way, there is no need to debug the configuration script file after the target image is produced, avoiding the problem of repeated debugging, thereby improving the efficiency of image production.
[0087] In some optional implementations, the server can run and debug each configuration script file separately through different session connections. That is, running and debugging each configuration script file can be performed using different session connections to achieve isolation between script file running and debugging, thereby improving the efficiency of generating the target image.
[0088] Illustratively, during the process of generating the base image, a session connection public key may be injected into the virtual machine that has downloaded the base image, so that each configuration script file may be run and debugged based on different session connections.
[0089] Based on this, see Figure 3 , Figure 3 Another flowchart for running each configuration script file in sequence is provided, which specifically includes the following steps:
[0090] S301 , controlling a virtual machine to sequentially execute each configuration script file according to a sequence identifier of each configuration script file through a first session connection.
[0091] For example, the virtual machine Internet Protocol (IP) of the virtual machine that has downloaded the base image can be determined. A first session connection can then be established based on the virtual machine IP and a private key that matches the public key. Specifically, the first session connection is a session connection with the virtual machine established using the private key that matches the public key. The first session connection can be understood as a process used to run various configuration script files. The first session connection can be a Secure Shell (SSH) connection.
[0092] Based on this, the first session connection can be used to control the virtual machine to sequentially execute each configuration script file according to the sequence identifier of each configuration script file. Each configuration script file can also be named according to the naming format of "[0-9]+[0-9]+script name", where "[0-9]+[0-9]" is the sequence identifier of each configuration script file, which is used to indicate the execution order of each configuration script file. In this way, each configuration script file can be executed in sequence according to the sequence identifier of each configuration script file, so as to configure the base image using each configuration script file.
[0093] S302 : When the virtual machine sequentially executes each configuration script file, if an interruption mark is identified, the execution of the configuration script file following the interruption script file is interrupted.
[0094] Furthermore, when the virtual machine sequentially executes each configuration script file, if an interruption flag is recognized, the execution of the configuration script file following the interruption script file can be interrupted. The interruption script file name includes a "hold" field. If a file name containing the "hold" field is recognized, it is considered that an interruption flag has been recognized, and the execution of the configuration script file following the interruption script file can be interrupted.
[0095] S303: Debug the configuration script file before the interruption script file through the second session connection.
[0096] For example, a second session connection can also be established based on the virtual machine IP and the private key that matches the public key, that is, the second session connection is a session connection with the virtual machine established using the private key that matches the public key. The second session connection can also be an SSH connection.
[0097] Based on this, the configuration script file before the interruption script file can be automatically debugged through the second session connection; or a debugging prompt message can be sent to the debugger to prompt the debugger to debug the configuration script file before the interruption script file through the second session connection. This achieves the isolation of the running configuration script file and the debugging configuration script file, thereby improving the efficiency of generating the target image.
[0098] S304: After debugging of the configuration script file preceding the interruption script file is completed, if a continuing execution instruction triggered by the first session connection is obtained, then the configuration script file following the interruption script file is continued to be executed.
[0099] For example, after debugging the configuration script file preceding the interruption script file is complete, a continue execution instruction can be automatically generated based on the first session connection, or a continue execution instruction can be sent to the server based on the first session connection. If the continue execution instruction is received, the configuration script file following the interruption script file can be continued to execute. In this way, the subsequent configuration script file can continue to execute using the first session connection.
[0100] In the embodiment of the present application, by setting different session connections, the isolation of running each configuration script file and debugging each configuration script file is achieved, thereby improving the generation efficiency of the target image.
[0101] For example, in Figure 3 On the basis of the illustrated embodiment, the configured base image may be verified before generating the target image to improve the reliability of the target image.
[0102] Based on this, see Figure 4 , Figure 4 A flowchart for generating a target image is provided, which specifically includes the following steps:
[0103] S401, obtaining a log file.
[0104] For example, log files can include data records of base image configuration. For example, the process of configuring a base image typically generates a large amount of log information, which records various operations and events during the image creation process, such as software package installation, configuration script file modifications, and system parameter settings. By reviewing the log files, you can understand whether errors occurred during the image creation process, which steps took a long time, and other information, helping to optimize the image creation process and resolve potential issues.
[0105] Typically, log files are stored in a specified file, and you can directly view the file to obtain the log content.
[0106] S402: Verify the configured base image based on the log file.
[0107] Based on this, the configured base image can be verified based on the log file. For example, a hash algorithm (such as MD5 or SHA-256) can be used to calculate the hash value of the configured base image and compare it with a pre-provided or known correct hash value. If the two hash values are the same, it indicates that the configured base image has not been altered during transmission or storage, and the verification is considered passed. If they are different, the configured base image may be damaged and needs to be re-created or downloaded, and the verification is considered failed.
[0108] S403: If the verification passes, delete the public key in the configured base image to obtain the target image.
[0109] For example, if the verification passes, the public key in the configured base image can be deleted, and the configured base image can be converted into a preset image format to obtain the target image. The preset image format includes but is not limited to qcow2, raw, squashfs, etc.
[0110] In the embodiment of the present application, the configured base image is verified, and a target image is generated if the verification passes, thereby improving the reliability of the target image.
[0111] In some optional implementations, the interrupt flag can be set according to the file name of the configuration script file that needs to be debugged, so that the interrupt script file can be run after the configuration script file that needs to be debugged, so as to interrupt the running of the configuration script file after the interrupt script file and debug the configuration script file before the interrupt script file.
[0112] Based on this, participating Figure 5 , Figure 5 A flowchart for generating an interruption flag is provided, which specifically includes the following steps:
[0113] S501: Determine the sequence identifier and file identifier of the configuration script file that needs to be debugged.
[0114] For example, the sequence identifier and file identifier of the configuration script file to be debugged can be determined first. The configuration script file can be named according to the naming format of "[0-9]+[0-9]+script name", where "[0-9]+[0-9]" can be understood as the sequence identifier and "script name" can be understood as the file identifier.
[0115] Typically, you can pre-set configuration script files that require debugging. For example, if the configuration script files "12-config-dns.sh" and "17-install-nvidia-fabricmanager.sh" require debugging, you can execute an interrupt script file after the configuration script file "12-config-dns.sh," and another interrupt script file after the configuration script file "17-install-nvidia-fabricmanager.sh." The sequence identifier and file identifier of the configuration script file "12-config-dns.sh" are "12" and "config-dns.sh," respectively; the sequence identifier and file identifier of the configuration script file "17-install-nvidia-fabricmanager.sh" are "17" and "install-nvidia-fabricmanager.sh," respectively.
[0116] S502: Combine the sequence identifier, file identifier, and interrupt function identifier of the configuration script file to be debugged to obtain an interrupt identifier.
[0117] For example, the sequence identifier, file identifier, and interrupt function identifier of the configuration script file to be debugged may be combined to obtain an interrupt identifier, wherein the interrupt function identifier is "hold".
[0118] For example, the hold script file executed after the configuration script file 12-config-dns.sh has the hold flag 12-config-dns-hold.sh; the hold script file executed after the configuration script file 17-install-nvidia-fabricmanager.sh has the hold flag 17-install-nvidia-fabricmanager-hold.sh.
[0119] In an embodiment of the present application, the sequence identifier and file identifier of the debugged configuration script file and the interrupt function identifier are combined to generate an interrupt identifier of the interrupt script file, which can interrupt the running of the configuration script file after the interrupt script file and debug the configuration script file before the interrupt script file.
[0120] In some optional implementations, to improve the efficiency of image maintenance and updates, configuration scripts can be divided into public and customized scripts. The interrupt script is a public script. Public scripts are commonly used when creating all image files, while customized scripts are private scripts that require flexible configuration based on image requirements when creating an image file.
[0121] For example, public script files can be understood as highly versatile scripts that can be shared and reused across multiple systems, environments, or projects, and are typically used to implement common configuration, management, and maintenance tasks. For example, public script files may include common component scripts, network configuration scripts, security configuration scripts, Network Time Protocol (NTP) and Domain Name System (DNS) default configuration scripts, and log cleanup scripts.
[0122] Customized script files are scripts tailored for specific customers, projects, or environments. They typically include customer-provided drivers, software, or customized requirements. For example, customized script files include proprietary hardening scripts, proprietary drivers, and software installation scripts.
[0123] Among them, private hardening scripts can include customized security policies (for example, adjusting kernel parameters and file permissions according to the customer's industry (such as finance and healthcare)) and private protocol support (for example, integrating customer-specified encryption protocols or authentication methods).
[0124] Private driver and software installation scripts include hardware driver installation (for example, automated deployment of NVIDIA Graphics Processing Unit (NVIDIA GPU) drivers and InfiniBand Architecture (InfiniBand) network card drivers), specific software deployment (for example, installation of customer-provided private software (such as customized databases and middleware)), and dependency management (for example, automatic installation of runtime libraries and frameworks required by the software).
[0125] Based on this, see Figure 6 , Figure 6 A flowchart for copying configuration script files to a virtual machine is provided, which specifically includes the following steps:
[0126] S601, copy the customized script file to the image production directory, and copy the public script file to the image production directory through the soft link corresponding to the public script file.
[0127] For example, customized script files can be stored directly in the image creation directory. If stored in other paths, the customized script files need to be copied to the image creation directory. Public script files are usually stored in the public script directory. The public script files can be copied to the image creation directory through the soft link corresponding to the public script files.
[0128] The soft link corresponding to the public script file includes the storage path of the public script file and the path of the image creation directory. A soft link, also known as a symbolic link, is a special file that contains a reference to another file or directory. Similar to a shortcut, a soft link allows access to a file or directory in one location from another. Soft links do not occupy actual file storage space; they simply record the path information of the target file or directory. When accessing a soft link, the system finds the corresponding target file or directory based on the path information in the link and performs the operation. In Linux, you can use the ln -s command to create a soft link.
[0129] S602, using virtualization software, copy the public script file and the customized script file from the image creation directory to the virtual machine.
[0130] For example, virtualization software can be used to copy the public and customized script files from the image creation directory to the virtual machine. The virtualization software can use the Secure Copy (SCP) protocol, a command-line tool for securely copying files over a network. The server can automatically invoke the SCP command to copy the public and customized script files from the image creation directory to the virtual machine.
[0131] In an embodiment of the present application, the efficiency of image maintenance and updating is improved by dividing each configuration script file into a public script file and a customized script file; and the public script file and the customized script file can be copied from the image production directory to the virtual machine through virtualization software to facilitate the generation of the target image.
[0132] For example, see Figure 7 , Figure 7 This article provides a flowchart of another image generation method, which is described in two stages. The method includes the following steps:
[0133] Phase 1:
[0134] S701, download the ISO system file and check the checksum.
[0135] S702: Install the ISO system file in the virtual machine and inject a public key for connecting to the virtual machine.
[0136] S703: Shut down the virtual machine, save the image, and obtain the base image.
[0137] Phase 2:
[0138] S704: Download the base image to the new virtual machine and obtain the identifier of the virtual machine.
[0139] The identifier of the virtual machine may be the virtual machine IP address.
[0140] S705: Copy the customized script file to the image production directory, and soft link the public script file to the image production directory.
[0141] S706 , connecting to the virtual machine based on the first session connection, and copying each configuration script file to the virtual machine.
[0142] Among them, each configuration script file includes a common script file, a customized script file, and a driver software package.
[0143] S707: Based on the first session connection, run each configuration script file in sequence according to the sequence identifier of each configuration script file.
[0144] S708, determine whether all configuration script files have been executed. If so, execute S713; if not, execute S709.
[0145] S709, determine whether it is an interrupt script file, if so, execute S710, if not, execute S707.
[0146] S710, interrupting the execution of the configuration script file following the interruption script file.
[0147] S711: Debug the configuration script file before the interruption script file based on the second session connection.
[0148] S712 , after debugging of the configuration script file before the interruption script file is completed, after obtaining a continuing execution instruction triggered by the first session connection, continue to execute S707 .
[0149] S713: Verify the configured base image based on the log file.
[0150] S714: If the verification passes, delete the public key in the configured base image, and convert the configured base image into a preset format to obtain the target image.
[0151] In the embodiment of the present application, on the one hand, the configuration script file of the second phase is divided into multiple scripts according to the configuration content and function, and some common configurations are extracted as public script files, which are linked to the image production directory through soft links to facilitate subsequent image maintenance and updates. On the other hand, the formatted script is named "[0-9]+[0-9]+script name" and automatically executed according to the order of the script file name, thereby controlling the execution order of the script. In addition, the startup parameter HOLD variable is added to add a public script hold.sh for debugging intervention, which supports pausing the configuration process of the image during the automated image production process, facilitating troubleshooting, testing the installation process of drivers and software packages, updating software packages and scripts, and other operations; after the test is completed, the previous image configuration process can be continued, and the debugging and production process of the image can be completed at one time. This method improves the efficiency and flexibility of image production, shortens the image production cycle, reduces resource consumption, can respond to customer needs more quickly, and provide high-quality customized services, thereby improving customer satisfaction.
[0152] The following describes the steps for creating a bare metal image, using the example of creating a bare metal image. Assuming the image customization requirement is for Community Enterprise Operating System 7.6 (CentOS 7.6), you must install the NVIDIA Graphics Driver (nvidia-driver) (version 535), the Compute Unified Device Architecture 12.2 (cuda-12.2), the appropriate NVIDIA Unified Fabric Manager (nvidia-fabricmanager) package, and change the SSH port to 10000.
[0153] The specific steps include:
[0154] S01, manually configure the soft link of the required public script file and write the private script file of the image.
[0155] In addition to the common bare metal configuration scripts, you can add soft link configurations as needed:
[0156] Run the command install-nvidia-driver-535.sh->create the directory. 15-install-nvidia-driver-535.sh is used to install the nvidia-driver.
[0157] install-cuda-12-2.sh->create directory. Among them, 16-install-cuda-12-2.sh is used to install cuda-12.2.
[0158] You need to write a private script:
[0159] 17-install-nvidia-fabricmanager.sh is used to install nvidia-fabricmanager.
[0160] 29-config-ssh.sh is used to change the SSH port to 10000.
[0161] S02, start the image automatic production process, set the startup parameter HOLD variable to 17-install-nvidia-fabricmanager.sh, this parameter will soft link the public script hold.sh->17-install-nvidia-fabricmanager-hold.sh in the image production directory when the automatic production process starts. The hold.sh script contains the hold_on() function.
[0162] In step 3, download the system ISO file and check the checksum. Install the system in a QEMU virtual machine using an automated installation method such as kickstart or preseed. After shutting down the virtual machine, save the virtual machine image as the base image. (During the automated installation configuration, an SSH public key is injected into the virtual machine for connecting to the virtual machine in the second phase.)
[0163] S04: Copy the base image of the first stage, automatically start the virtual machine, and obtain the virtual machine IP.
[0164] S05, use the corresponding SSH private key to connect to the virtual machine, and copy a series of scripts (private scripts and public scripts) and driver software packages in the image production directory into the virtual machine.
[0165] S06, executes the script for modifying the image through SSH. When the hold_on() function in the 17-install-nvidia-fabricmanager-hold.sh script is executed, the script execution of the current SSH connection (hereinafter referred to as SSH-1 connection) is suspended.
[0166] In S07, manually verify the installation of nvidia-fabricmanager (installed using 17-install-nvidia-fabricmanager.sh) using a new SSH connection to the virtual machine (referred to as SSH-2) and debug the software. If the installed version is incompatible with the current nvidia-driver version, use SCP to copy the compatible nvidia-fabricmanager package to the virtual machine and manually install, debug, and verify the software.
[0167] S08: After the verification is complete, close the SSH-2 connection and enter the specified string "continue" in the SSH-1 connection to resume the automated image creation process.
[0168] S09: After all scripts have finished running, extract the log of image creation and verify the image; delete temporary files such as the image SSH public key in the image.
[0169] S10, shut down the virtual machine, save the image, and convert the image to an image format (raw, qcow2, squashfs, etc.) to obtain the target image CentOS-7.6@cuda-12.2.qcow2.
[0170] It should be understood that, although the various steps in the flowcharts involved in the various embodiments described above are displayed in sequence according to the instructions of the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and these steps can be executed in other orders. Moreover, at least a portion of the steps in the flowcharts involved in the various embodiments described above can include multiple steps or multiple stages, and these steps or stages are not necessarily executed and completed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a portion of steps or stages in other steps.
[0171] Based on the same inventive concept, embodiments of the present application also provide an image generation device for implementing the aforementioned image generation method. The solution provided by this device is similar to the solution described in the aforementioned method. Therefore, the specific limitations of one or more of the following embodiments of the image generation device can be found in the above-described limitations of the image generation method and will not be further elaborated here.
[0172] In an exemplary embodiment, Figure 8 As shown, a mirror image generation device is provided, comprising:
[0173] The acquisition module 10 is used to copy each configuration script file to the virtual machine; wherein the virtual machine is created based on the base image; the base image provides a basic operating system environment for the virtual machine;
[0174] The running module 20 is used to run each configuration script file in sequence according to the sequence identifier of each configuration script file and the interruption identifier of the interruption script file in each configuration script file to implement the configuration of the base image; wherein the interruption identifier is used to indicate that the configuration script file after the interruption script file is interrupted to debug the configuration script file before the interruption script file;
[0175] The generation module 30 is used to generate a target image according to the configured basic image after all configuration script files have been executed.
[0176] The image generation device copies each configuration script file into a virtual machine; based on the sequence identifier of each configuration script file and the interrupt identifier of the interrupt script file in each configuration script file, each configuration script file is sequentially executed to configure the base image; after each configuration script file has been executed, a target image is generated based on the configured base image. The above solution introduces an interrupt script file, which can interrupt the execution of the script during the execution of each configuration script file, thereby interrupting the execution of the configuration script file after the interrupt script file, so as to debug the configuration script file before the interrupt script file; there is no need to debug after the target image is completed, avoiding the problem of repeated debugging, thereby improving the efficiency of image production.
[0177] In one embodiment, the operation module 20 is specifically configured to:
[0178] According to the sequential identifier of each configuration script file, each configuration script file is run in sequence; in the process of running each configuration script file in sequence, if an interrupt identifier is recognized, the configuration script file after the interrupt script file is interrupted, and the configuration script file before the interrupt script file is debugged; after the configuration script file before the interrupt script file is debugged, if a continue running instruction is obtained, the configuration script file after the interrupt script file is continued to run.
[0179] In one embodiment, the base image includes a public key for connecting to the virtual machine; the execution module 20 is specifically configured to:
[0180] Through a first session connection, the virtual machine is controlled to run each configuration script file in sequence according to the sequence identifier of each configuration script file; wherein the first session connection is a session connection between the virtual machine established by using a private key that matches the public key; in the process of the virtual machine running each configuration script file in sequence, if an interrupt identifier is recognized, the configuration script file after the interrupt script file is interrupted; through a second session connection, the configuration script file before the interrupt script file is debugged; wherein the second session connection is a session connection between the virtual machine established by using a private key that matches the public key; after the configuration script file before the interrupt script file is debugged, if a continue running instruction triggered by the first session connection is obtained, the configuration script file after the interrupt script file is continued to run.
[0181] In one embodiment, the generating module 30 is specifically configured to:
[0182] Obtain a log file; wherein the log file includes data records for configuring the base image; based on the log file, verify the configured base image; if the verification passes, delete the public key in the configured base image to obtain the target image.
[0183] In one embodiment, the apparatus further comprises a establishing module for:
[0184] Determine the sequence identifier and file identifier of the configuration script file that needs to be debugged; combine the sequence identifier, file identifier and interrupt function identifier of the configuration script file that needs to be debugged to obtain an interrupt identifier.
[0185] In one embodiment, each configuration script file includes a common script file and a customized script file; the interruption script file belongs to the common script file; the acquisition module 10 is specifically used to:
[0186] Copy the customized script file to the image production directory, and copy the public script file to the image production directory through the soft link corresponding to the public script file; the soft link corresponding to the public script file includes the storage path of the public script file and the path of the image production directory; through the virtualization software, copy the public script file and the customized script file from the image production directory to the virtual machine.
[0187] Each module in the above-mentioned image generation device can be implemented in whole or in part through software, hardware, or a combination thereof. Each module can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the corresponding operations of each module.
[0188] In an exemplary embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as shown in FIG. Figure 9 As shown. The computer device includes a processor, a memory, an input / output (I / O) interface, and a communication interface. The processor, memory, and I / O interface are connected via a system bus, and the communication interface is connected to the system bus via the I / O interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operation of the operating system and computer program in the non-volatile storage medium. The database of the computer device is used to store script files and image file data. The I / O interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, it implements a method for generating an image.
[0189] Those skilled in the art will understand that Figure 9 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than shown in the figure, or combine certain components, or have a different component arrangement.
[0190] In an exemplary embodiment, a computer device is provided, including a memory and a processor. The memory stores a computer program, and the processor implements the steps of the image generation method described in any of the above embodiments when executing the computer program.
[0191] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of the image generation method described in any of the above embodiments are implemented.
[0192] In one embodiment, a computer program product is provided, including a computer program. When the computer program is executed by a processor, the steps of the image generation method described in any of the above embodiments are implemented.
[0193] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.
[0194] Those skilled in the art will understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. In particular, any reference to memory, database, or other media used in the embodiments provided in this application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The databases involved in the various embodiments provided herein may include at least one of a relational database and a non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the various embodiments provided herein may be, but are not limited to, general-purpose processors, central processing units (CPUs), graphics processing units (GPUs), digital signal processors (DSPs), programmable logic devices (PLDs), quantum computing-based data processing logic devices, artificial intelligence (AI) processors, and the like.
[0195] The technical features of the above embodiments can be combined arbitrarily. In order to make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0196] The above-described embodiments merely represent several implementation methods of the present application. While the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the present application. It should be noted that a person of ordinary skill in the art may make various modifications and improvements without departing from the spirit of the present application, and these modifications and improvements fall within the scope of protection of the present application. Therefore, the scope of protection of the present application shall be determined by the appended claims.
Claims
1. A mirror image generation method, characterized in that: The method comprises: Copy each configuration script file to a virtual machine; wherein the virtual machine is created based on a base image; the base image provides a basic operating system environment for the virtual machine; Running each configuration script file in sequence according to a sequence identifier of each configuration script file and an interrupt identifier of an interrupt script file in each configuration script file to implement configuration of the base image; wherein the interrupt identifier is used to indicate that the configuration script file after the interrupt script file is interrupted in order to debug the configuration script file before the interrupt script file; After all configuration script files have been run, the target image is generated according to the configured base image; The step of sequentially running each configuration script file according to the sequence identifier of each configuration script file and the interruption identifier of the interruption script file in each configuration script file includes: According to the sequence identifier of each configuration script file, run each configuration script file in sequence; In the process of sequentially running each configuration script file, if an interruption mark is identified, the configuration script file after the interruption script file is interrupted, and the configuration script file before the interruption script file is debugged; After the configuration script file before the interruption script file is debugged, if a continue running instruction is obtained, the configuration script file after the interruption script file will continue to run.
2. The method according to claim 1, characterized in that Each configuration script file is used to perform system configuration, service and process configuration, security hardening, file and directory operation settings, containerization configuration, and automated test integration on the base image.
3. The method according to claim 1, characterized in that The base image includes a public key for connecting to the virtual machine; The step of sequentially running each configuration script file according to the sequence identifier of each configuration script file and the interruption identifier of the interruption script file in each configuration script file includes: Controlling the virtual machine to sequentially execute each configuration script file according to a sequence identifier of each configuration script file through a first session connection; wherein the first session connection is a session connection with the virtual machine established using a private key that matches the public key; During the process of the virtual machine sequentially running each configuration script file, if an interruption mark is identified, the execution of the configuration script file following the interruption script file is interrupted; Debugging the configuration script file before the interruption script file through a second session connection; wherein the second session connection is a session connection with the virtual machine established using a private key matching the public key; After the configuration script file preceding the interruption script file is debugged, if a continuing execution instruction triggered based on the first session connection is obtained, the configuration script file following the interruption script file continues to be executed.
4. The method according to claim 3, characterized in that Generating a target image according to the configured base image includes: Obtaining a log file; wherein the log file includes data records of configuring the base image; Verify the configured base image based on the log file; If the verification passes, the public key in the configured base image is deleted to obtain the target image.
5. The method according to claim 1, characterized in that The interrupt flag is established in the following way: Determine the sequence identifier and file identifier of the configuration script file that needs to be debugged; The interruption identifier is obtained by combining the sequence identifier, the file identifier and the interruption function identifier of the configuration script file that needs to be debugged.
6. The method according to claim 1, wherein Each configuration script file includes a common script file and a customized script file; The interruption script file belongs to the public script file; The step of copying each configuration script file to the virtual machine includes: Copying the customized script file to the image production directory, and copying the public script file to the image production directory through the soft link corresponding to the public script file; wherein the soft link corresponding to the public script file includes the storage path of the public script file and the path of the image production directory; The public script file and the customized script file are copied from the image production directory to the virtual machine through virtualization software.
7. A mirror image generation device, characterized in that: The device comprises: An acquisition module is used to copy each configuration script file to a virtual machine; wherein the virtual machine is created based on a base image; the base image provides a basic operating system environment for the virtual machine; A running module, configured to run each configuration script file in sequence according to a sequence identifier of each configuration script file and an interrupt identifier of an interrupt script file in each configuration script file, so as to configure the base image; wherein the interrupt identifier is used to indicate that the configuration script file after the interrupt script file is interrupted in order to debug the configuration script file before the interrupt script file; The generation module is used to generate the target image according to the configured base image after all configuration script files have been run; The operation module is used to: According to the sequence identifier of each configuration script file, run each configuration script file in sequence; In the process of sequentially running each configuration script file, if an interruption mark is identified, the configuration script file after the interruption script file is interrupted, and the configuration script file before the interruption script file is debugged; After the configuration script file before the interruption script file is debugged, if a continue running instruction is obtained, the configuration script file after the interruption script file will continue to run.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
10. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.