Virtual machine migration method and device, electronic equipment and storage medium
Through the dual file injection mechanism, the drivers are automatically installed for the virtual machine using the libguestfs tool and LiveOS image, which solves the stability problems caused by hardware configuration differences after the virtual machine migration, and achieves stable operation and business continuity of the virtual machine.
Patent Information
- Application Number
- CN202510473093.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-16
- Publication Date
- 2025-07-18
AI Technical Summary
During the virtual machine migration process, hardware driver incompatibility and system startup failure caused by hardware configuration differences affect the stable operation and business continuity of the virtual machine.
The dual file injection mechanism is adopted, and the driver is automatically installed for the virtual machine using the libguestfs tool and LiveOS image, ensuring that the driver files are successfully injected into the virtual machine, and the automatic installation of the driver is achieved by modifying the boot self-start service.
Ensure that virtual machines can operate stably after migration, reduce the risk of failure caused by hardware configuration differences, ensure business continuity and stability, and improve the flexibility and efficiency of enterprise IT resource management.
Smart Images

Figure CN120335935A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of virtualization technology, and in particular, to a virtual machine migration method, apparatus, electronic device, and storage medium. Background Art
[0002] Due to various factors such as cost, performance, and functional characteristics, enterprises often mix multiple virtualization platforms in their IT (Information Technology) architectures. During the development of enterprise business, it may be necessary to re-plan and integrate IT resources, that is, migrate from the original virtualization platform to other virtualization platforms. However, due to differences in the hardware abstraction layer, different virtualization platforms abstract virtual machine hardware in different ways, and due to this difference, the following problems occur: (1) Hardware driver incompatibility: Due to differences in hardware configurations of different virtualization platforms, the migrated virtual machine may lack the hardware drivers required by the new platform or some configurations may become invalid due to changes in device types. For example, if the type of the virtual machine network card changes before and after migration, the IP configuration inside the virtual machine will be lost, resulting in the inability to run the business normally; (2) System startup failure: In some cases, large differences in hardware configurations may cause the virtual machine to fail to start normally on the new platform. For example, if the storage controller type of the new platform is incompatible with the original platform, the virtual machine cannot recognize the storage device and thus cannot load the operating system. Summary of the Invention
[0003] This application provides a virtual machine migration method, apparatus, electronic device, and storage medium to at least solve the problem in the related art that the virtual machine cannot run stably due to differences in hardware configurations after the virtual machine migration is completed.
[0004] This application provides a virtual machine migration method, including:
[0005] Responding to receiving a virtual machine migration request, migrating the target virtual machine;
[0006] Responding to the completion of the migration of the target virtual machine, obtaining the driver installation file of the target virtual machine, and injecting the driver installation file into the target virtual machine based on the first file injection mechanism;
[0007] Responding to the failure of injecting the driver installation file, injecting the driver installation file into the target virtual machine based on the second file injection mechanism;
[0008] Installing the target driver based on the driver installation file and the driver installation script.
[0009] This application also provides a virtual machine migration apparatus, including:
[0010] A migration module, configured to migrate a target virtual machine in response to receiving a virtual machine migration request;
[0011] A first injection module, configured to obtain a driver installation file of the target virtual machine in response to the completion of the migration of the target virtual machine, and inject the driver installation file into the target virtual machine based on a first file injection mechanism;
[0012] A second injection module, configured to inject the driver installation file into the target virtual machine based on a second file injection mechanism in response to the failure of injecting the driver installation file;
[0013] An installation module, configured to install a target driver based on the driver installation file and a driver installation script.
[0014] This application further provides an electronic device, including: a memory, configured to store a computer program; a processor, configured to implement the following steps of a virtual machine migration method when executing the computer program:
[0015] Migrate a target virtual machine in response to receiving a virtual machine migration request;
[0016] Obtain a driver installation file of the target virtual machine in response to the completion of the migration of the target virtual machine, and inject the driver installation file into the target virtual machine based on a first file injection mechanism;
[0017] Inject the driver installation file into the target virtual machine based on a second file injection mechanism in response to the failure of injecting the driver installation file;
[0018] Install a target driver based on the driver installation file and a driver installation script.
[0019] This application further provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the following steps of a virtual machine migration method are implemented:
[0020] Migrate a target virtual machine in response to receiving a virtual machine migration request;
[0021] Obtain a driver installation file of the target virtual machine in response to the completion of the migration of the target virtual machine, and inject the driver installation file into the target virtual machine based on a first file injection mechanism;
[0022] Inject the driver installation file into the target virtual machine based on a second file injection mechanism in response to the failure of injecting the driver installation file;
[0023] Install a target driver based on the driver installation file and a driver installation script.
[0024] The present application also provides a computer program product, including a computer program which, when executed by a processor, implements the following steps of the virtual machine migration method:
[0025] In response to receiving a virtual machine migration request, migrate the target virtual machine;
[0026] In response to the completion of the migration of the target virtual machine, obtain the driver installation file of the target virtual machine, and inject the driver installation file into the target virtual machine based on the first file injection mechanism;
[0027] In response to the failure of injecting the driver installation file, inject the driver installation file into the target virtual machine based on the second file injection mechanism;
[0028] Install the target driver based on the driver installation file and the driver installation script.
[0029] Through the dual file injection mechanism set in the present application, it can ensure that after the virtual machine migration is completed, various drivers required by the platform virtual machine are automatically installed for the virtual machine, so that the virtual machine can run stably, reduce the failure risk caused by hardware configuration differences, ensure the continuity and stability of the service, and improve the flexibility and efficiency of enterprise IT resource management. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] In order to more clearly illustrate the embodiments of the present application, the following will briefly introduce the drawings required in the embodiments. Obviously, the drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0031] Figure 1 It is an application environment diagram of a virtual machine migration method provided by an embodiment of the present application;
[0032] Figure 2 It is a schematic overall flow diagram of a virtual machine migration method provided by an embodiment of the present application;
[0033] Figure 3 It is another schematic overall flow diagram of a virtual machine migration method provided by an embodiment of the present application;
[0034] Figure 4 It is a structural block diagram of a virtual machine migration device provided by an embodiment of the present application;
[0035] Figure 5 It is an internal structure diagram of an electronic device in an embodiment. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0036] The following will clearly and completely describe the technical solutions in the embodiments of the present application in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments in the present application without creative efforts fall within the protection scope of the present application.
[0037] It should be noted that in the description of the present application, the terms "include", "comprise" or any other variant thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements but also includes other elements not expressly listed, or further includes elements inherent to such a process, method, article or device. The terms "first", "second", etc. in the present application are used to distinguish similar objects, rather than to describe a specific order or sequence.
[0038] It should be noted that the terms "S1", "S2", etc. are only used for the purpose of describing steps, not specifically referring to the meaning of order or sequence, nor used to limit the present application. They are only used to conveniently describe the method of the present application and cannot be understood as indicating the sequence of steps. In addition, the technical solutions between the various embodiments can be combined with each other, but it must be based on the ability of those of ordinary skill in the art to implement. When the combination of technical solutions results in contradictions or cannot be implemented, it should be considered that such a combination of technical solutions does not exist and is not within the protection scope required by the present application.
[0039] With the rapid development of information technology, virtualization technology has been widely used in enterprise data centers and cloud computing fields. Numerous virtualization platforms have emerged in the market. Each of these platforms has its own characteristics and advantages in different application scenarios and industries. According to the background technology, enterprises often mix and use multiple virtualization platforms in their IT (Information Technology) architectures considering various factors such as cost, performance, and functional characteristics. During the business development process of enterprises, they may re-plan and integrate IT resources. For example, if the original virtualization platform cannot meet the business growth requirements in terms of performance, cost control, etc., the enterprise decides to migrate to a more suitable platform to improve the overall operation efficiency. However, due to the differences in the hardware abstraction layer, different virtualization platforms abstract the virtual machine hardware in different ways. For example, the virtual hardware model provided by VMware vSphere (a virtualization platform) for virtual machines is different from that of KVM (Keyboard Video Mouse, an open-source system virtualization module) in terms of device types, parameter settings, etc. Taking the network card as an example, VMware vSphere may default to using an E1000 virtual network card, while KVM may use a virtio network card. These two network cards have different driver requirements and performance performances, and due to this difference, problems such as hardware driver incompatibility and system startup failure occur.
[0040] To solve the above technical problems, the present application provides a virtual machine migration method, device, electronic device, and storage medium. Through the set dual file injection mechanism, it can ensure that after the virtual machine migration is completed, the driver programs required for various platform virtual machines are automatically installed for the virtual machine, so that the virtual machine can run stably, reduce the failure risk caused by hardware configuration differences, ensure the continuity and stability of the business, and improve the flexibility and efficiency of enterprise IT resource management.
[0041] In order to enable those skilled in the art of this technical field to better understand the solution of the present application, the present application will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0042] The virtual machine migration method provided by the present application can be applied to an application environment as Figure 1 shown. Among them, the terminal 102 communicates with the data processing platform set on the server 104 through the network. Among them, the terminal 102 can be, but is not limited to, various personal computers, laptop computers, smart phones, tablet computers, and portable wearable devices, and the server 104 can be implemented by an independent server or a server cluster composed of multiple servers.
[0043] As Figure 2 shown, the embodiment of the present application provides a virtual machine migration method. Taking this method as an example applied to Figure 1Taking the terminal in [ ] as an example, the method includes the following steps:
[0044] S1: In response to receiving a virtual machine migration request, migrate the target virtual machine.
[0045] It should be noted that a virtual machine (VM) is a software system based on virtualization technology. By simulating the hardware environment of a physical computer, multiple operating systems can run independently on the same physical machine; a virtual machine has complete hardware functions, including a CPU (Central Processing Unit), memory, storage, and network interfaces, etc. A virtual machine can run in a completely isolated environment, enabling users to run multiple operating systems and applications on a physical computer simultaneously without interference from each other; the operation of a virtual machine depends on a software called a "hypervisor". The hypervisor is responsible for allocating the resources of the physical computer (such as CPU, memory, storage, etc.) to the virtual machine and managing the creation, operation, and destruction of the virtual machine. In this way, the virtual machine can perform various operations like a physical computer, such as installing an operating system, running applications, and connecting to the network; virtual machine technology is widely used in various scenarios, including multi-operating system testing: users can run different operating systems (such as Windows, Linux, macOS) on the same physical computer for software testing or development; resource isolation and optimization: virtual machines can allocate physical resources to multiple users or environments, thereby improving the utilization rate and flexibility of hardware resources; security experiments: virtual machines provide an isolated environment where users can perform high-risk operations (such as virus testing or system experiments) without affecting the security of the physical computer; the virtual machine migration request is sent from the user side, and this request includes the source host and destination host identifiers to migrate the virtual machine in the source host to the target host. Virtual machine migration generally includes three types: cold migration, hot migration, and fault migration. Among them, cold migration is performed when the virtual machine is powered off, usually including backing up the virtual machine files, transferring the files to the new host server, and reconfiguring and starting the virtual machine; hot migration is performed when the virtual machine is running, without interrupting the operation and service of the virtual machine, and is suitable for load balancing and fault recovery; fault migration is triggered after the node where the virtual machine is located fails to ensure the continuity of the service. This application can be applicable to various virtual machine migration types. Therefore, no specific restrictions are imposed on the above virtual machine migration types.
[0046] S2: In response to the completion of the target virtual machine migration, obtain the driver installation file of the target virtual machine, and inject the driver installation file into the target virtual machine based on the first file injection mechanism.
[0047] It should be noted that the driver installation file of the virtual machine is generally a file in the.pkg format. This file cannot be directly injected through the virtual machine's optical drive. Therefore, it needs to be converted into an.ISO image file before injection; the first file injection mechanism refers to injecting the required files of the virtual machine into the virtual machine through the virtual machine image management tool.
[0048] S3: In response to the failure of injecting the driver installation file, based on the second file injection mechanism, inject the driver installation file into the target virtual machine.
[0049] It should be noted that the second file injection mechanism refers to injecting the required files of the virtual machine into the virtual machine by mounting the LiveOS image. Among them, the LiveOS image is a special Linux operating system image, mainly used to create bootable CDs, DVDs or USB devices. Users can directly boot and run a complete operating system environment from these devices without prior installation on the hard disk.
[0050] S4: Install the target driver based on the driver installation file and the driver installation script.
[0051] It should be noted that the driver installation script is used to execute the driver installation file to install the target driver. The virtual machine driver installation script refers to a script used for automated installation and management of virtual machine driver programs. These scripts usually contain a series of commands for downloading, decompressing and installing the driver programs required by the virtual machine.
[0052] In the above embodiment, through the dual injection method of the libguestfs tool and mounting the LiveOS image, it is ensured that the migrated virtual machine can successfully inject the driver file, so as to ensure the stable operation of the virtual machine, reduce the risk of failures caused by hardware configuration differences, guarantee the continuity and stability of the business, and improve the flexibility and efficiency of enterprise IT resource management.
[0053] In some specific embodiments, before migrating the target virtual machine, it further includes:
[0054] Obtain the configuration file of the target virtual machine. Among them, the configuration file of the virtual machine is a file used to define and configure the running parameters of the virtual machine. Different types of virtual machine platforms use different configuration file formats;
[0055] Based on the configuration file of the target virtual machine, detect and determine whether there is a driver corresponding to the target virtual machine in the target virtual machine;
[0056] In response to the existence of a driver corresponding to the target virtual machine, migrate the target virtual machine;
[0057] In response to the non - existence of a driver corresponding to the target virtual machine, mark the target virtual machine based on a preset identifier. In response to the completion of the marking, migrate the target virtual machine, where the preset identifier can be set according to actual requirements and is only used to indicate that the virtual machine has a driver. The specific identifier is not specifically limited here.
[0058] Specifically, as Figure 3 shown, before migrating the target virtual machine, automatically identify whether the virtual machine on the migration source - side virtualization platform has the drivers required by the virtual machine, that is, determine whether the virtual machine has the drivers required by the virtual machine by identifying the default virtual machine network card and disk driver types on the migration source - side virtualization platform. If it exists, directly migrate without any operation. If there is a driver missing, mark the virtual machine for driver injection after the virtual machine migration is completed.
[0059] In the above - mentioned implementation manner, by detecting the virtual machine in advance, mark the virtual machine without a driver, so as to determine whether driver injection needs to be performed after migration, improving the accuracy of driver injection.
[0060] In some specific implementation manners, before obtaining the driver installation file of the target virtual machine, it further includes:
[0061] Detect whether a preset identifier exists in the target virtual machine, where the preset identifier is the identifier marked above;
[0062] In response to the existence of the preset identifier in the target virtual machine, obtain the driver installation file of the target virtual machine. When it is detected that the preset identifier exists in the target virtual machine, it means that there is no driver in the target virtual machine and the driver needs to be installed. At this time, obtain the driver installation file of the target virtual machine.
[0063] In the above - mentioned implementation manner, based on the set identifier, determine whether to obtain the driver installation file of the virtual machine. When the preset identifier exists, obtain the driver installation file to install the driver of the virtual machine, improving the accuracy and efficiency of driver installation.
[0064] In some specific implementation manners, when obtaining the driver installation file of the target virtual machine, injecting the driver installation file into the target virtual machine based on the first file - injection mechanism includes:
[0065] Inject the driver installation file of the target virtual machine into the target virtual machine based on the virtual - machine image management tool, where the virtual - machine image management tool refers to the libguestfs tool. The libguestfs tool is a set of C - language APIs under Linux used to access the disk image file of the virtual machine;
[0066] In response to the completion of the injection of the driver installation file, the method further includes:
[0067] Obtain the driver installation script and service configuration file corresponding to the driver installation file. Among them, the driver installation script can be written by those skilled in the art or automatically written by a computer, and the corresponding programming language can be selected according to actual needs. For example, for a Linux virtual machine, the Linux shell language is used to write the driver automatic installation script. To ensure that the driver can be automatically loaded after the virtual machine boots, the script for automatically installing the driver also needs to be set to start at boot; the service configuration file refers to the rc-local service configuration file. Among them, the rc-local service configuration file is used to automatically execute the driver installation script when the virtual machine starts. The execution logic of rc-local is different for different distributions, so it is necessary to distinguish among the three major categories of Red Hat, SUSE, and Ubuntu, and the other distributions all follow the logic of these three distributions. Using the rc-local service built into Linux can enable the virtual machine to automatically install the driver after booting. The rc-local service configuration file is a script used to execute custom commands when the system starts in the Linux system. The above scripts are all written in Linux shell;
[0068] Based on the virtual machine image management tool, inject the driver installation script and service configuration file into the target virtual machine, that is, use the virtual machine image management tool to inject the driver installation file, driver installation script, and rc-local service configuration file into the virtual machine system disk;
[0069] In response to the completion of the injection of the driver installation script and service configuration file, modify the service that starts automatically at boot based on the service configuration file to implement the automatic injection operation of the driver, and run the driver installation script to execute the driver installation file, that is, modify the rc-local.service of the Linux built-in service that starts automatically at boot, so that the virtual machine can run the written automatic installation driver script immediately after booting.
[0070] In the above embodiment, when there is a driver missing, for the problem of driver missing in the migration source virtual machine, after the migration is completed, the libguestfs tool is used to inject the driver-related files, so that the virtual machine can automatically run the driver installation script after booting, to ensure the stable operation of the virtual machine, reduce the risk of failures caused by hardware configuration differences, and ensure the continuity and stability of the business.
[0071] In some specific embodiments, in response to the failure of injecting the driver installation file, based on the second file injection mechanism, injecting the driver installation file into the target virtual machine includes:
[0072] In response to the failure of injecting the driver installation file, mount the operating system image. Among them, the operating system image refers to the LiveOS image, including:
[0073] Set an operating system image, where the operating system image includes at least driver installation files, driver installation scripts, and service configuration files;
[0074] Set a self-start script for the operating system image;
[0075] In response to the target virtual machine being started, based on the self-start script of the operating system image, identify and determine the destination system disk of the target virtual machine, and mount the operating system image;
[0076] In response to the completion of mounting the operating system image, copy the driver installation files, driver installation scripts, and service configuration files to the destination system disk;
[0077] After injecting the driver installation files into the target virtual machine, the method further includes:
[0078] Modify the boot self-start service based on the service configuration file;
[0079] In response to the completion of modifying the boot self-start service, shut down the target virtual machine and unmount the operating system image;
[0080] In response to the completion of unmounting the operating system image, start the target virtual machine through the destination system disk and run the driver installation script to execute the driver installation files.
[0081] In some specific embodiments, installing the target driver based on the driver installation files and the driver installation script includes:
[0082] Obtain the process in the service configuration file;
[0083] Install the target driver based on the process, the driver installation files, and the driver installation script.
[0084] Specifically, when the libguestfs tool injects files into a virtual machine, it depends on the kernel functions of the host where the virtual machine is located. If some file systems or features inside the virtual machine are not in the host compatibility list, libguestfs cannot successfully inject files into the virtual machine. In this case, the method of mounting the LiveOS image is used to inject files into the virtual machine, including: first, it is necessary to customize the LiveOS image, integrate the driver installation file, the driver installation script, and the rc-local configuration file; write the self-start script of the LiveOS image so that after the virtual machine mounting the image starts, it can automatically identify the original system disk of the virtual machine and mount it, and copy the above three files to the system disk; after the copying is completed, the virtual machine automatically shuts down and unmounts the LiveOS image; after the injection of the above three files is completed, the virtual machine starts through the system disk. At this time, according to the rc-local configuration file, the driver installation script is automatically executed to complete the injection of the driver.
[0085] In the above implementation, due to the limitations of the libguestfs tool and the diversity of Linux distributions, when the libguestfs tool fails to inject files into the virtual machine disk, the method of mounting the LiveOS image is used to replace the libguestfs tool to complete the injection of the driver installation file and the driver installation script. This function requires customizing the boot operation logic of the LiveOS image so that when the virtual machine starts from the LiveOS image, it can automatically identify the original system disk of the virtual machine and inject the driver installation file and the installation script into it, and modify the boot operation service rc-local.service of the original system so that after the virtual machine exits the LiveOS image and starts from the original system disk, it can still automatically install the hardware driver. Based on the automatic injection driver script of the mounted LiveOS image, it replaces the function of the libguestfs tool as a redundant configuration to improve the robustness of the automatic driver injection function.
[0086] In some specific implementations, after mounting the operating system image, the virtual machine migration method further includes:
[0087] Obtain the compatibility list of the host where the target virtual machine is located, and determine whether the compatibility list includes the target file system and / or feature inside the target virtual machine;
[0088] In response to the compatibility list not including the target file system and / or feature inside the target virtual machine, inject the virtual machine driver-related files through the mounted operating system image;
[0089] In response to the target file system and / or feature inside the target virtual machine being included in the compatibility list, perform a marking on the target virtual machine. The identifier of the marking can be set according to actual requirements, such as the number of times, etc.;
[0090] In response to the number corresponding to the identifier of the first marking being greater than the first preset threshold, perform a second marking on the target virtual machine. The identifier of the second marking can be set according to actual requirements and can be used to indicate that the target file system and / or feature inside the virtual machine exists multiple times in the compatibility list. The first preset threshold can be set according to actual requirements;
[0091] When migrating the target virtual machine again, if the identifier of the second marking is detected and the injection of files into the virtual machine disk by the libguestfs tool fails, inject files into the virtual machine disk again by the libguestfs tool until the number of file injection times reaches the second preset threshold. The second preset threshold can be set according to actual requirements, such as 3 times, etc.;
[0092] When the number of file injection times reaches the second preset threshold and the injection still fails, mount the operating system image and inject the virtual machine driver-related files through the mounted operating system image.
[0093] In the above embodiment, by detecting the target virtual machine after mounting the operating system image, determine whether the target file system and / or feature inside the virtual machine is included in the compatibility list, and mark the virtual machine that is detected to include the target file system and / or feature multiple times, so that when the file injection fails next time, increase the number of injection times of the libguestfs tool, improve the probability of successful one-time injection, and avoid resource waste caused by mounting the operating system image.
[0094] In some specific embodiments, after installing the target driver based on the driver installation file and the driver installation script, the method further includes:
[0095] In response to the completion of the installation of the target driver, run the target driver;
[0096] In response to the normal operation of the target driver, clean up the driver installation file and the driver installation script, and restore the service configuration file.
[0097] Specifically, after detecting the normal operation of the driver, start cleaning up the driver installation file and the driver installation script, and restore the rc-local configuration file, without affecting the operation of the original boot services and preventing the driver from being repeatedly installed with the next boot.
[0098] In the above embodiments, after the driver installation is completed, perform the cleaning operation after installation to remove unnecessary driver installation files and installation scripts during the virtual machine operation, and modify the rc-local.service startup service to prevent the virtual machine from reinstalling the driver every time it boots, so as to ensure the stable operation of the virtual machine and improve the stability of the virtual machine operation.
[0099] In the above virtual machine migration method, it includes: in response to receiving a virtual machine migration request, migrating the target virtual machine; in response to the completion of the target virtual machine migration, obtaining the driver installation file of the target virtual machine, and injecting the driver installation file into the target virtual machine based on the first file injection mechanism; in response to the failure of injecting the driver installation file, injecting the driver installation file into the target virtual machine based on the second file injection mechanism; installing the target driver based on the driver installation file and the driver installation script. In view of the problem of driver missing in the virtual machine at the migration source end, after the migration is completed, this application uses two methods, namely libguestfs and mounting a custom LiveOS image, to ensure that the driver installation file and the driver automatic installation script can be successfully injected into the virtual machine, and modify the startup service of the linux virtual machine, so that the virtual machine can automatically run the driver installation script after booting, complete the injection of the driver of the migrated virtual machine, thereby ensuring the stable operation of the virtual machine, reducing the failure risk caused by hardware configuration differences, guaranteeing the continuity and stability of the service, and improving the flexibility and efficiency of enterprise IT resource management.
[0100] Through the description of the above embodiments, those skilled in the art can clearly understand that the method according to the above embodiments can be implemented by means of software plus a necessary general hardware platform. Of course, it can also be implemented by hardware, but in many cases the former is a better implementation.
[0101] It should be understood that although Figures 2 - 3 the steps in the flowchart are shown in sequence according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless clearly stated in this article, the execution of these steps has no strict order limit, and these steps can be executed in other orders. Moreover, Figures 2 - 3 at least a part of the steps in
[0102] may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily executed at the same moment, but can be executed at different moments. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed alternately or in turn with at least a part of other steps or sub-steps or stages of other steps.
[0102] The embodiments of the present application also provide a virtual machine migration device, as Figure 4As shown in the figure, it includes a migration module, a first injection module, a second injection module, and an installation module, where:
[0103] The migration module is used to migrate the target virtual machine in response to receiving a virtual machine migration request;
[0104] The first injection module is used to obtain the driver installation file of the target virtual machine in response to the completion of the migration of the target virtual machine, and inject the driver installation file into the target virtual machine based on the first file injection mechanism;
[0105] The second injection module is used to inject the driver installation file into the target virtual machine based on the second file injection mechanism in response to the failure of injecting the driver installation file;
[0106] The installation module is used to install the target driver based on the driver installation file and the driver installation script.
[0107] As a preferred implementation manner, in the embodiment of the present invention, the virtual machine migration device further includes a first detection module, and the first detection module is specifically used for:
[0108] Obtain the configuration file of the target virtual machine;
[0109] Based on the configuration file of the target virtual machine, detect and determine whether there is a driver corresponding to the target virtual machine in the target virtual machine;
[0110] In response to the existence of a driver corresponding to the target virtual machine, migrate the target virtual machine;
[0111] In response to the non-existence of a driver corresponding to the target virtual machine, mark the target virtual machine based on a preset identifier, and in response to the completion of the marking, migrate the target virtual machine.
[0112] As a preferred implementation manner, in the embodiment of the present invention, the virtual machine migration device further includes a second detection module, and the second detection module is specifically used for:
[0113] Detect whether there is a preset identifier in the target virtual machine;
[0114] In response to the existence of a preset identifier in the target virtual machine, obtain the driver installation file of the target virtual machine.
[0115] As a preferred implementation manner, in the embodiment of the present invention, the first injection module is specifically used for:
[0116] Inject the driver installation file of the target virtual machine into the target virtual machine based on the virtual machine image management tool;
[0117] In response to the completion of injecting the driver installation file, the method further includes:
[0118] Obtain the driver installation script and service configuration file corresponding to the driver installation file;
[0119] Based on the virtual machine image management tool, inject the driver installation script and service configuration file into the target virtual machine;
[0120] In response to the completion of injecting the driver installation script and service configuration file, modify the boot self-start service based on the service configuration file, and run the driver installation script to execute the driver installation file.
[0121] As a preferred implementation manner, in the embodiment of the present invention, the second injection module is specifically used for:
[0122] In response to the failure of injecting the driver installation file, mount the operating system image, including:
[0123] Set the operating system image, where the operating system image includes at least the driver installation file, driver installation script, and service configuration file;
[0124] Set the self-start script of the operating system image;
[0125] In response to the startup of the target virtual machine, based on the self-start script of the operating system image, identify and determine the destination end system disk of the target virtual machine, and mount the operating system image;
[0126] In response to the completion of mounting the operating system image, copy the driver installation file, driver installation script, and service configuration file to the destination end system disk;
[0127] After injecting the driver installation file into the target virtual machine, the method further includes:
[0128] Modify the boot self-start service based on the service configuration file;
[0129] In response to the completion of modifying the boot self-start service, shut down the target virtual machine and unmount the operating system image;
[0130] In response to the completion of unmounting the operating system image, start the target virtual machine through the destination end system disk, and run the driver installation script to execute the driver installation file.
[0131] As a preferred implementation manner, in the embodiment of the present invention, the installation module is specifically used for:
[0132] Obtain the process in the service configuration file;
[0133] Based on the process, driver installation file, and driver installation script, install the target driver.
[0134] As a preferred implementation manner, in the embodiment of the present invention, the virtual machine migration device further includes a cleaning module, and the cleaning module is specifically used for:
[0135] In response to the completion of target-driven installation, run the target driver;
[0136] In response to the normal operation of the target driver, clean up the driver installation files and the driver installation script, and restore the service configuration file.
[0137] For the description of the features in the corresponding embodiments of the virtual machine migration device, reference can be made to the relevant descriptions in the corresponding embodiments of the virtual machine migration method, which will not be elaborated here one by one. Each module in the above virtual machine migration device can be implemented in whole or in part by software, hardware, and their combination. The above modules can be embedded in the processor of the electronic device in hardware form or independent of it, or stored in the memory of the electronic device in software form, so that the processor can call and execute the operations corresponding to each of the above modules.
[0138] In one embodiment, an electronic device is provided. The electronic device can be a terminal, and its internal structure diagram can be as Figure 5 shown. The electronic device includes a processor, a memory, a network interface, a display screen, and an input device connected through a system bus. Among them, the processor of the electronic device is used to provide computing and control capabilities. The memory of the electronic device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the electronic device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, it implements a * method. The display screen of the electronic device can be a liquid crystal display screen or an electronic ink display screen. The input device of the electronic device can be a touch layer covering the display screen, or a button, a trackball, or a touchpad provided on the housing of the electronic device, or an external keyboard, touchpad, or mouse, etc.
[0139] Those skilled in the art can understand that Figure 5 the structure shown in
[0140] is only a block diagram of some structures related to the solution of this application, and does not constitute a limitation on the electronic device to which the solution of this application is applied. The specific electronic device may include more or fewer components than those shown in the figure, or combine some components, or have a different component layout.
[0141] S1: In response to receiving a virtual machine migration request, migrate the target virtual machine.
[0142] S2: In response to the completion of the target virtual machine migration, obtain the driver installation file of the target virtual machine, and inject the driver installation file into the target virtual machine based on the first file injection mechanism.
[0143] S3: In response to the failure of injecting the driver installation file, inject the driver installation file into the target virtual machine based on the second file injection mechanism.
[0144] S4: Install the target driver based on the driver installation file and the driver installation script.
[0145] An embodiment of the present application further provides a computer-readable storage medium, in which a computer program is stored. Wherein, the computer program is set to execute the steps in the embodiment of the virtual machine migration method when running, including:
[0146] S1: In response to receiving a virtual machine migration request, migrate the target virtual machine.
[0147] S2: In response to the completion of the target virtual machine migration, obtain the driver installation file of the target virtual machine, and inject the driver installation file into the target virtual machine based on the first file injection mechanism.
[0148] S3: In response to the failure of injecting the driver installation file, inject the driver installation file into the target virtual machine based on the second file injection mechanism.
[0149] S4: Install the target driver based on the driver installation file and the driver installation script.
[0150] In an exemplary embodiment, the above computer-readable storage medium may include, but is not limited to: various media such as USB flash drives, read-only memories (ROM for short), random access memories (RAM for short), external hard drives, magnetic disks, or optical discs that can store computer programs.
[0151] An embodiment of the present application further provides a computer program product. The above computer program product includes a computer program, and when the computer program is executed by a processor, it implements the steps in the embodiment of the virtual machine migration method, including:
[0152] S1: In response to receiving a virtual machine migration request, migrate the target virtual machine.
[0153] S2: In response to the completion of the target virtual machine migration, obtain the driver installation file of the target virtual machine, and inject the driver installation file into the target virtual machine based on the first file injection mechanism.
[0154] S3: In response to the failure of injecting the driver installation file, inject the driver installation file into the target virtual machine based on the second file injection mechanism.
[0155] S4: Install the target driver based on the driver installation file and the driver installation script.
[0156] An embodiment of the present application further provides another computer program product, including a non-volatile computer-readable storage medium storing a computer program. When the computer program is executed by a processor, the steps in the embodiment of the virtual machine migration method are implemented, including:
[0157] S1: In response to receiving a virtual machine migration request, migrate the target virtual machine.
[0158] S2: In response to the completion of the migration of the target virtual machine, obtain the driver installation file of the target virtual machine, and inject the driver installation file into the target virtual machine based on the first file injection mechanism.
[0159] S3: In response to the failure of injecting the driver installation file, inject the driver installation file into the target virtual machine based on the second file injection mechanism.
[0160] S4: Install the target driver based on the driver installation file and the driver installation script.
[0161] Those skilled in the art can further realize that the units and algorithm steps of each example described in combination with the embodiments disclosed in this article can be implemented by electronic hardware, computer software, or a combination of the two. To clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described according to functions in the above description. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Skilled professionals can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of this application.
[0162] The above has introduced in detail a virtual machine migration method, device, electronic device, and storage medium provided by this application. Specific examples are used in this article to elaborate on the principle and implementation manner of this application. The description of the above embodiments is only used to help understand the method and its core idea of this application. It should be noted that for those of ordinary skill in the art in this technical field, without departing from the principle of this application, several improvements and modifications can be made to this application, and these improvements and modifications also fall within the protection scope of the claims of this application.
Claims
1. A virtual machine migration method, characterized in that, The method includes: In response to receiving a virtual machine migration request, migrating the target virtual machine; In response to the completion of the migration of the target virtual machine, obtaining the driver installation file of the target virtual machine, and injecting the driver installation file into the target virtual machine based on a first file injection mechanism; In response to the failure of injecting the driver installation file, injecting the driver installation file into the target virtual machine based on a second file injection mechanism; Installing the target driver based on the driver installation file and the driver installation script.
2. The virtual machine migration method according to claim 1, wherein Before migrating the target virtual machine, the method further includes: Obtaining the configuration file of the target virtual machine; Based on the configuration file of the target virtual machine, detecting and determining whether there is a driver corresponding to the target virtual machine in the target virtual machine; In response to the existence of the driver corresponding to the target virtual machine, migrating the target virtual machine; In response to the non-existence of the driver corresponding to the target virtual machine, marking the target virtual machine based on a preset identifier, and in response to the completion of the marking, migrating the target virtual machine.
3. The virtual machine migration method according to claim 2, wherein Before obtaining the driver installation file of the target virtual machine, the method further includes: Detecting whether the preset identifier exists in the target virtual machine; In response to the existence of the preset identifier in the target virtual machine, obtaining the driver installation file of the target virtual machine.
4. The virtual machine migration method according to claim 1, wherein Obtaining the driver installation file of the target virtual machine and injecting the driver installation file into the target virtual machine based on a first file injection mechanism includes: Injecting the driver installation file of the target virtual machine into the target virtual machine based on a virtual machine image management tool; In response to the completion of injecting the driver installation file, the method further includes: Obtaining the driver installation script and the service configuration file corresponding to the driver installation file; Injecting the driver installation script and the service configuration file into the target virtual machine based on the virtual machine image management tool; In response to the completion of injecting the driver installation script and the service configuration file, modifying the boot self-start service based on the service configuration file, and running the driver installation script to execute the driver installation file.
5. The virtual machine migration method according to claim 1, wherein In response to the failure of injecting the driver installation file, injecting the driver installation file into the target virtual machine based on a second file injection mechanism includes: In response to the failure of injecting the driver installation file, mounting the operating system image, including: Setting the operating system image, where the operating system image at least includes a driver installation file, a driver installation script, and a service configuration file; Setting the self-start script of the operating system image; In response to the target virtual machine having been started, based on the self-start script of the operating system image, identifying and determining the destination end system disk of the target virtual machine, and mounting the operating system image; In response to the completion of mounting the operating system image, copying the driver installation file, the driver installation script, and the service configuration file to the destination end system disk; After injecting the driver installation file into the target virtual machine, the method further includes: Modifying the boot self-start service based on the service configuration file; In response to the completion of the modification of the self-starting service at boot, shut down the target virtual machine and uninstall the operating system image; In response to the completion of the uninstallation of the operating system image, start the target virtual machine through the destination system disk and run the driver installation script to execute the driver installation file.
6. The virtual machine migration method according to claim 4 or 5, characterized in that Based on the driver installation file and the driver installation script, the installation of the target driver includes: Obtain the process in the service configuration file; Based on the process, the driver installation file, and the driver installation script, install the target driver.
7. The virtual machine migration method according to claim 4 or 5, characterized in that After installing the target driver based on the driver installation file and the driver installation script, the method further includes: In response to the completion of the installation of the target driver, run the target driver; In response to the normal operation of the target driver, clean up the driver installation file and the driver installation script, and restore the service configuration file.
8. A virtual machine migration device, characterized in that, The device includes: A migration module, configured to migrate the target virtual machine in response to receiving a virtual machine migration request; A first injection module, configured to obtain the driver installation file of the target virtual machine in response to the completion of the migration of the target virtual machine, and inject the driver installation file into the target virtual machine based on the first file injection mechanism; A second injection module, configured to inject the driver installation file into the target virtual machine based on the second file injection mechanism in response to the failure of injecting the driver installation file; An installation module, configured to install the target driver based on the driver installation file and the driver installation script.
9. An electronic device, characterized in that, including: A memory, configured to store a computer program; A processor, configured to implement the steps of the virtual machine migration method according to any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, characterized in that, A computer program is stored in the computer-readable storage medium, wherein the computer program implements the steps of the virtual machine migration method according to any one of claims 1 to 7 when executed by a processor.