Operating system switching method and electronic device

By backing up the operating system to be replaced and modifying the boot items to switch to the target operating system, and combining it with lightweight containers for upgrades, the problems of high resource consumption and inflexible configuration in existing technologies are solved, and efficient and low-cost operating system switching and upgrades are achieved to ensure business continuity.

CN120653316APending Publication Date: 2025-09-16ZTE CORP
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202510763606.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-09
Publication Date
2025-09-16

AI Technical Summary

Technical Problem

Existing technologies consume too much resources when switching operating systems, and configuration and data migration are not flexible enough, which leads to increased costs and performance bottlenecks, especially in large-scale deployment environments, affecting business operations.

Method used

Back up the operating system to be replaced, use it as the target operating system, modify the boot item of the boot file, and switch by restarting the computing device. At the same time, use lightweight containers to upgrade and check component packages during the upgrade process to ensure business continuity.

Benefits of technology

It improves the flexibility of operating system configuration and data migration, reduces resource consumption, realizes efficient and low-cost system switching and upgrade, and ensures business continuity and high availability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120653316A_ABST
    Figure CN120653316A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides an operating system switching method and an electronic device, and the method comprises the steps: backing up a to-be-replaced operating system on computing equipment, and taking the backed-up to-be-replaced operating system as a target operating system; modifying a boot item of a boot file of the to-be-replaced operating system, and taking the target operating system as a starting target; and restarting the computing equipment, and switching the to-be-replaced operating system to the target operating system. By means of the method and device, the problems that resource consumption is too high and configuration and data migration are not flexible enough due to the fact that the target operating system is rebuilt or deployed in a brand new mode in the related technology are solved, the flexibility of configuration and data migration of the target operating system is improved, and the effect of reducing resource consumption is achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present invention relate to the field of communications, and in particular, to an operating system switching method and an electronic device. Background Art

[0002] In related technologies, when switching operating systems, methods such as rebuilding the target operating system or adopting image replacement are often used. Although these methods can achieve operating system switching, they expose significant defects in resource efficiency and configuration flexibility.

[0003] Rebuilding the target operating system is a resource-intensive activity, requiring the downloading, installation, and configuration of the entire operating system environment from scratch. This process places enormous pressure on network bandwidth, storage space, and CPU computing power. This high resource consumption not only increases costs but can also cause performance bottlenecks, impacting normal business operations, especially in large-scale deployment environments such as data centers or cloud computing platforms.

[0004] While image replacement can shorten deployment time, it struggles with complex configurations and personalized data. Images are typically standardized, making it difficult to accommodate the unique configurations and user data of each computing device. Therefore, even after the target operating system is deployed, additional time and effort is required for configuration tuning and data migration, which undoubtedly increases operational complexity and reduces efficiency. Summary of the Invention

[0005] The embodiments of the present invention provide an operating system switching method and an electronic device to at least solve the problems of excessive resource consumption and inflexible configuration and data migration in related technologies by reconstructing or completely deploying a target operating system.

[0006] According to one embodiment of the present invention, a method for switching an operating system is provided, comprising: backing up the operating system to be replaced on a computing device, and using the backed-up operating system to be replaced as a target operating system; modifying the boot item of the boot file of the operating system to be replaced, and using the target operating system as the startup target; and restarting the computing device to switch from the operating system to be replaced to the target operating system.

[0007] According to yet another embodiment of the present invention, a computer-readable storage medium is provided, in which a computer program is stored. The computer program is configured to execute the steps of any one of the above method embodiments when run.

[0008] According to another embodiment of the present invention, an electronic device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.

[0009] According to yet another embodiment of the present invention, a computer program product is provided, including a computer program. When the computer program is executed by a processor, the steps in any one of the above method embodiments are implemented.

[0010] Through the above-described embodiment of the present invention, by backing up the operating system to be replaced on the computing device, using the backed-up operating system to be replaced as the target operating system, modifying the boot entry of the boot file of the operating system to be replaced, using the target operating system as the startup target, and restarting the computing device to switch from the operating system to be replaced to the target operating system, the problems of excessive resource consumption and inflexible configuration and data migration in related technologies that involve rebuilding or completely re-deploying the target operating system can be solved, thereby improving the flexibility of the configuration and data migration of the target operating system and reducing resource consumption. BRIEF DESCRIPTION OF THE DRAWINGS

[0011] Figure 1 It is a hardware structure block diagram of a computer terminal on which the method embodiment of the present invention is executed;

[0012] Figure 2 is a flowchart of a method for switching an operating system according to an embodiment of the present invention (I);

[0013] Figure 3 is a structural block diagram of a switching device for an operating system according to an embodiment of the present invention;

[0014] Figure 4 is a schematic diagram of a target operating system construction process according to an embodiment of the present invention;

[0015] Figure 5 is a flowchart (II) of a method for switching an operating system according to an embodiment of the present invention;

[0016] Figure 6 is a schematic diagram of a process for backing up an operating system to be replaced according to an embodiment of the present invention;

[0017] Figure 7 is a schematic diagram of a process for upgrading a target operating system according to an embodiment of the present invention;

[0018] Figure 8 is a schematic diagram of system mounting according to an embodiment of the present invention;

[0019] Figure 9 FIG. 4 is a schematic diagram of system booting according to an embodiment of the present invention. DETAILED DESCRIPTION

[0020] Hereinafter, embodiments of the present invention will be described in detail with reference to the accompanying drawings and in combination with embodiments.

[0021] It should be noted that the terms "first", "second", etc. in the description and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.

[0022] The method embodiments provided in the embodiments of the present application can be executed in a mobile terminal, a computer terminal or a similar computing device. Taking running on a computer terminal as an example, Figure 1 This is a hardware block diagram of a computer terminal running the method embodiment of the present invention. Figure 1 As shown, the computer terminal may include one or more ( Figure 1 Only one is shown) a processor 102 (the processor 102 may include but is not limited to a microprocessor MCU or a programmable logic device FPGA and other processing devices) and a memory 104 for storing data. The computer terminal may also include a transmission device 106 and an input / output device 108 for communication functions. It will be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the above-mentioned computer terminal. For example, the computer terminal may also include Figure 1 More or fewer components than shown, or with Figure 1 Different configurations shown.

[0023] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the operating system switching method in the embodiment of the present invention. The processor 102 executes various functional applications and data processing by running the computer programs stored in the memory 104, that is, implementing the above-mentioned method. The memory 104 may include a high-speed random access memory and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely located relative to the processor 102, and these remote memories can be connected to the computer terminal via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0024] The transmission device 106 is used to receive or transmit data via a network. A specific example of the aforementioned network may include a wireless network provided by a computer terminal's communications provider. In one embodiment, the transmission device 106 includes a network interface controller (NIC), which can be connected to other network devices via a base station to enable communication with the Internet. In another embodiment, the transmission device 106 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.

[0025] Figure 2 Flowchart (1) of the method for switching an operating system according to an embodiment of the present invention, as shown in FIG. Figure 2 As shown, the process includes the following steps:

[0026] Step S202: back up the operating system to be replaced on the computing device, and use the backed up operating system to be replaced as the target operating system.

[0027] Exemplarily, the computing device may be the aforementioned computer terminal, or a virtual machine (eg, a Linux virtual machine). The following text takes the Linux virtual machine as an example to introduce the method for switching the operating system.

[0028] For example, by executing a backup command, the operating system to be replaced on the computing device is backed up, and the backed-up operating system to be replaced is used as the target operating system. The operating system to be replaced can be reused to maximize the use of existing system resources and configurations, avoid waste of resources and unnecessary cost expenditures, and improve the flexibility of the configuration and data migration of the target operating system.

[0029] In an exemplary embodiment, step S202 includes:

[0030] Receive target configuration files set by users;

[0031] Executing a first command in the operating system to be replaced according to the target configuration file to generate a first namespace;

[0032] Constructing a mount tree of the operating system to be replaced and a mount tree of the target operating system in the first namespace;

[0033] Copy the data of the mount tree of the operating system to be replaced to the mount tree of the target operating system;

[0034] Generate a boot file of the target operating system using the first preset template.

[0035] Exemplarily, the first command may be a namespace unshare command, the first namespace may be an independent command space, the boot file may be a related system boot file, and the first preset template may be a dracut template for generating a target operating system boot.

[0036] For example, based on the target configuration file set by the user, the namespace unshare command can be executed in the operating system to be replaced to generate an independent command space. Within this independent command space, the mount tree for the operating system to be replaced and the mount tree for the target operating system can be constructed. Based on the constructed mount trees, data is copied and synchronized from the mount tree to be replaced to the target mount tree. After data synchronization is complete, the relevant system boot files in the target operating system are recreated using the dracut template used to generate the target operating system boot files.

[0037] In an exemplary embodiment, constructing a mount tree of the target operating system in the first namespace includes:

[0038] Based on the target configuration file, copy the non-shared and non-excluded directories of the mount tree of the operating system to be replaced to the mount tree of the target operating system.

[0039] For example, users can configure a shared directory to specify a shared directory between the target system and the target system. This directory will not appear in the target mount tree. Mounts that are not configured for backup in the target configuration file (such as / etc / fstab) will automatically become shared mounts and can be accessed from both the target system and the target system. Users can also configure an excluded directory to specify a directory that is not to be backed up in the target operating system, i.e., the directory will be hidden when the target mount tree is built.

[0040] In an exemplary embodiment, copying data of the mount tree of the to-be-replaced operating system to the mount tree of the target operating system includes:

[0041] Copy the data of non-shared and non-excluded directories to the mount tree of the target operating system in batches according to the preset data size;

[0042] Verify the data after each batch is copied.

[0043] For example, the data copy may perform a full or incremental copy operation based on the file information at both ends and synchronize the file attributes, such as SELinux attributes.

[0044] Exemplarily, the preset data size can be a specific value (e.g., 1GB) or can be in file units. For example, each time 1GB of data in a non-shared, non-excluded directory is copied to the target operating system's mount tree, the integrity of the copied data and its file attributes are verified, and this process is repeated until all data is copied. In file units, each time a file in a non-shared, non-excluded directory is copied, its file attributes and integrity are verified after the file copy is complete, and this process is repeated until all files are copied.

[0045] In an exemplary embodiment, generating a boot file of a target operating system using a first preset template includes:

[0046] Execute the second command in the first namespace to root the mount tree of the target operating system, enter the target operating system, and adjust the mount file according to the target configuration file;

[0047] The third command is executed in the operating system to be replaced to generate a boot file of the target operating system through the first preset template.

[0048] Exemplarily, the second command may be a pivot_root command, the third command may be a boot file generation command, and the mount file may include boot target information, a grub file, and an fstab file.

[0049] For example, the pivot_root command can be executed in the first namespace to perform a root operation on the target mount tree to enter the file system of the target operating system, and the mount file (e.g., disk mount configuration) can be adjusted according to the target configuration file to ensure that the computing device can correctly mount the target operating system data and share the configured directory when it is started. For example, the command line configuration in the target operating system boot file settings can be set, and the target operating system boot target information, grub file, and fstab file can be adjusted to update the target operating system file mount.

[0050] Exemplarily, a boot file generation command is executed in the operating system to be replaced, and a boot file of the target operating system (eg, a boot image of the target operating system) is generated using a first preset template.

[0051] Step S204: modify the boot item of the boot file of the operating system to be replaced, and use the target operating system as the boot target.

[0052] Exemplarily, the boot item of the boot file of the operating system to be replaced is modified, and the boot target is changed to the target operating system to ensure correct booting of the target operating system.

[0053] In an exemplary embodiment, modifying the boot item of the boot file of the operating system to be replaced and setting the target operating system as the boot target includes:

[0054] Executing a fourth command in the operating system to be replaced to load a boot item of the boot file of the target operating system through the second preset template;

[0055] The fifth command is executed in the operating system to be replaced to write the boot item of the boot file of the target operating system into the startup target field.

[0056] Exemplarily, the fourth command may be a grub2-mkconfig command, the fifth command may be a system backup module command, and the second preset template may be a template for generating grub options for a target operating system.

[0057] For example, the grub2-mkconfig command is executed in the operating system to be replaced, and the boot entry of the boot file of the target operating system is loaded by generating a grub option template for the target operating system. If it is necessary to switch to the target operating system, the target operating system can be set as the next system startup target by using the system backup module command in the operating system to be replaced. This command will set the target operating system as the startup target by setting the saved_entry field in the grubenv file of the boot partition. After the computing device restarts, it will automatically switch to the target operating system.

[0058] Step S206: restart the computing device and switch from the operating system to be replaced to the target operating system.

[0059] For example, when the computing device restarts, the boot item configuration information in the grub file of the operating system to be replaced is used to jump to the grub file of the target operating system. The target operating system is booted by adding the target operating system boot file path and system configuration information to the grub file. During the boot process, the target operating system will mount the target operating system's file system according to the mount configuration file and complete the system startup.

[0060] In an exemplary embodiment, the method further comprises:

[0061] Upgrade the target operating system and update the upgraded target operating system to the target operating system.

[0062] For example, upgrading the target operating system without interrupting the services of the currently running operating system (the operating system to be replaced) can solve the problem that upgrade methods in related technologies are dependent on implementation conditions, are generally time-consuming and costly, and require interrupting system services during the process, which limits the large-scale and rapid updates of operating systems and significantly hinders the rapid development and implementation of businesses. Achieving efficient, secure, and low-cost operating system maintenance and upgrades while ensuring business continuity and improved user experience is particularly important for business scenarios that require high availability and rapid response.

[0063] In an exemplary embodiment, upgrading the target operating system and updating the upgraded target operating system to the target operating system includes:

[0064] Check the component packages of the target operating system and generate a detection report;

[0065] Upgrade the component packages that need to be upgraded according to the detection report.

[0066] For example, the component packages of the target operating system can be checked so that the component packages that need to be upgraded can be upgraded according to the generated detection report. For example, the generated detection report can be displayed to the user, and the user can decide to upgrade the component packages that need to be upgraded based on the detection report, or the system can upgrade the component packages that need to be upgraded according to the contents of the detection report.

[0067] In an exemplary embodiment, checking component packages of a target operating system and generating a detection report includes:

[0068] Executing a sixth command in the target operating system to generate a first container space;

[0069] The seventh command is executed in the first container space to inspect the component package and generate a test report.

[0070] Exemplarily, the sixth command may be a systemd-nspawn command, the first container space may be a lightweight container, and the seventh command may be a package manager command. For example, the systemd-nspawn command is executed on the target operating system to generate a first lightweight container. Within the container, the package manager command is executed to perform pre-upgrade actions on the target operating system files to complete component package dependency integrity checks, upgrade configuration checks, system software and hardware information collection and checks, and generate corresponding inspection reports.

[0071] In an exemplary embodiment, upgrading the component package that needs to be upgraded according to the detection report includes:

[0072] Executing the sixth command in the target operating system to generate a second container space;

[0073] According to the detection report, upgrade the component packages that need to be upgraded through the package manager.

[0074] Exemplarily, the sixth command may be a systemd-nspawn command, and the second container space may be a lightweight container. For example, the systemd-nspawn command is executed in the target operating system to generate a second lightweight container, and the component package is upgraded in the container. The process will install, uninstall, or upgrade the component dependency package according to the package manager. The package manager will use the component's own update strategy to update the configuration file of the corresponding component. When the package manager completes the component upgrade, it can perform adaptation migration through a customized configuration adapter module. At this point, the target system upgrade operation is completed. During the kernel component installation process, the boot file update is automatically triggered. In this process, the boot file information is automatically updated for the target operating system based on the dracut template (first preset template) for generating the target operating system boot, the grub option template (second preset template) for generating the target operating system, and the configuration content. After the target operating system is upgraded, the target operating system is set as the startup target in the operating system to be replaced by specifying it through grub, and the target operating system is entered after the computing device is restarted.

[0075] In an exemplary embodiment, the method further comprises:

[0076] In response to the target operating system not meeting the preset condition, modifying the boot item of the boot file of the target operating system and using the operating system to be replaced as the boot target;

[0077] Restart the computing device and switch back from the target operating system to the operating system to be replaced.

[0078] For example, if the target operating system does not meet preset conditions (e.g., an upgrade fails), the boot entry in the target operating system's boot file can be modified to use the replacement operating system as the boot target, restart the computing device, and switch back from the target operating system to the replacement operating system. This allows for a quick return to the original system (the replacement operating system), resolving the issue in related technologies where, when an upgrade fails, the system must be restored using pre-upgrade backup data in a specific recovery mode, increasing the cost of operating system upgrade and recovery.

[0079] In an exemplary embodiment, in response to the target operating system not meeting a preset condition, modifying a boot item of a boot file of the target operating system and using the operating system to be replaced as a startup target includes:

[0080] Test the business procedures of the target operating system;

[0081] In response to the test result of the business program not meeting the preset condition, the boot item of the boot file of the target operating system is modified, and the operating system to be replaced is used as the startup target.

[0082] For example, the business program can be tested on the target operating system. If the target operating system does not run as expected (for example, the component package upgrade fails, etc.), the operating system to be replaced can be set as the startup target, and the computing device can be restarted to enter the operating system to be replaced.

[0083] In an exemplary embodiment, the operating system to be replaced and the target operating system are in the same partition.

[0084] Exemplarily, the operating system to be replaced and the target operating system can be in the same partition, without the need for an independent backup partition and without the need for partition reconstruction of the existing system, thereby improving the overall performance of the system.

[0085] Exemplarily, the operating system to be replaced and the target operating system may also be in the same partition. For example, the operating system to be replaced may be backed up in a designated external storage, thereby achieving flexible storage of the target system backup.

[0086] Through the above steps, the problems of excessive resource consumption and inflexible configuration and data migration in related technologies through rebuilding or newly deploying the target operating system, as well as the problems of the existing system upgrade method requiring business interruption before component upgrade and time-consuming recovery after system upgrade failure are solved. This improves the flexibility of configuration and data migration of the target operating system, reduces resource consumption, and improves efficiency without interrupting business for upgrades.

[0087] Through the description of the above embodiments, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus the necessary general hardware platform, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for enabling a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods of various embodiments of the present invention.

[0088] This embodiment also provides an operating system switching device, which is used to implement the above-mentioned embodiments and preferred embodiments. Details already described will not be repeated here. As used below, the term "module" may refer to a combination of software and / or hardware that implements a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, implementation using hardware, or a combination of software and hardware, is also possible and contemplated.

[0089] Figure 3 is a structural block diagram of a switching device for an operating system according to an embodiment of the present invention. Figure 3As shown, the device 30 includes a system backup module 32 , a system upgrade module 34 , and a system switching module 36 . Figure 4 FIG. 1 is a schematic diagram of a target operating system construction process according to an embodiment of the present invention. Figure 4 shown.

[0090] The system backup module 32 is used to back up the operating system to be replaced and generate a target operating system.

[0091] The system upgrade module 34 is used to upgrade the target operating system.

[0092] The system switching module 36 is used to switch the operating system to be replaced to the target operating system, and when the target operating system does not meet the preset conditions, switch back to the operating system to be replaced.

[0093] It should be noted that the above modules can be implemented through software or hardware. For the latter, it can be implemented in the following ways, but not limited to: the above modules are all located in the same processor; or the above modules are located in different processors in any combination.

[0094] Figure 5 Flowchart (II) of the method for switching an operating system according to an embodiment of the present invention, as shown in FIG. Figure 5 As shown, the process includes the following steps:

[0095] Step S502, prepare the target operating system: install the backup program in the server or virtual machine system, configure the backup strategy and storage path, the user configures the backup target in the form of partition mounting and device, and sets the target configuration file.

[0096] For example, if the backup target is configured as root mounts backed up to the / dev / mapper / cl-root partition, the backup data will be created in the / dev / mapper / cl-root partition. Users can configure shared directories to specify directories shared by the target and target operating systems. These directories will not appear in the target source mount tree. Mounts not configured for backup in / etc / fstab will automatically become shared mounts and can be accessed on the target backup system. Users can also configure excluded directories to exclude from the target source backup, meaning that these directories are hidden when the target source mount tree is built.

[0097] Step S504: Generate the target operating system. When generating the target operating system, the mount tree for the target operating system and the mount tree for the target operating system are constructed in a separate command space (the first namespace) based on the configuration in the backup module. After the mount tree is constructed, data can be copied from the target mount tree to the target mount tree. This data copy is performed in a full or incremental manner based on the file information on both ends, and file attributes, such as SELinux attributes, are synchronized.

[0098] Step S506, system boot settings: After data synchronization is completed, the backup module adjusts the disk mount configuration (mount file) of the target operating system according to the configuration to ensure that the target operating system can correctly mount the system backup data and share the configured directory when it starts. After data synchronization is completed, the relevant system boot files in the target operating system will use the dracut template (first preset template) used to generate the target operating system boot to re-produce the relevant boot files, and set the corresponding file path in the startup configuration of the operating system to be replaced, and automatically add the target operating system boot information in the grub file by adding a sub-page. Step S508, target operating system upgrade: After configuring the upgrade target source, the upgrade module will use the package manager to perform component package upgrade operations on the target operating system in the container space (second container space).

[0099] Step S510: Switch to the target operating system: Once the upgrade is complete, the upgraded target operating system can be set as the boot target using a tool and the computing device can be restarted at an appropriate time. Upon restart, the upgraded target operating system will automatically be booted. If the target operating system does not meet the system upgrade expectations after switching to the target operating system, the target operating system's boot file can be modified and the device can be restarted to switch back to the target operating system.

[0100] Figure 6 FIG. 1 is a flow chart of backing up an operating system to be replaced according to an embodiment of the present invention. Figure 6 shown.

[0101] Step S601, deploy the system backup module through the component package manager in the operating system to be replaced. The system backup module will provide relevant backup operation commands, a dracut template for generating the target operating system boot (first preset module), a grub option template for generating the target operating system (second preset module) and related startup services.

[0102] Step S602: The system backup module commands the configuration of the mount of the operating system to be replaced and the target storage partition that needs to be backed up, and excludes or shares the user data directory as needed.

[0103] Step S603, execute the system backup module backup command, the system backup module uses the namespace unshare command (first command) to build the system mount tree to be replaced and the target system mount tree in an independent command space (first namespace) according to the target configuration file set by the user, and then masks them through the empty folder bind method according to the sharing and exclusion directories configured by the user.

[0104] Step S604: Based on the constructed mount tree, copy and synchronize files from the mount tree of the operating system to be replaced to the mount tree of the target operating system. After the files are copied, verify their file attributes and integrity. Repeat this process until all files are copied.

[0105] Step S605: After the data is copied, the target mount tree is rooted using the pivot_root command (second command) in the first namespace, the target operating system's file system is entered, the command line configuration in the target system boot file setting is set, the target operating system boot target information, the grub file, and the file mount of the target operating system are updated in fstab, and then the boot file generation command (third command) is executed to generate the relevant boot files of the target operating system, such as the boot image of the target operating system. After the boot file generation of the target operating system is completed, the grub2-mkconfig command (fourth command) is executed on the operating system to be backed up to load the boot item of the boot file of the target operating system by generating the target operating system grub option template (second preset template).

[0106] Step S606, after the target operating system is built, if you need to switch to the target system, you can set the target operating system as the startup target through the system backup module command (fifth command). This command will set the target operating system as the startup target by setting the saved_entry field in the grubenv file of the boot partition. After the computing device restarts, it will automatically switch to the target operating system.

[0107] Step S607: When there is no need to switch the operating system, the current system (the operating system to be replaced) can continue to run. When there is a need to switch, step S606 can be executed to switch the system.

[0108] Step S608, when the computing device is restarted, jump to the grub file of the target operating system through the boot item configuration information in the grub file of the operating system to be replaced, and boot the target operating system through this file plus the target operating system boot file path and system configuration information.

[0109] In step S609 , the target operating system mounts the file system of the target operating system according to the mount configuration file during the boot process and completes the system startup.

[0110] Figure 7 FIG. 1 is a flow chart of upgrading the target operating system according to an embodiment of the present invention. Figure 7 shown.

[0111] Step S701 : Backing up the target configuration file set by the user on the operating system to be replaced to generate a target operating system.

[0112] In step S702, the upgrade module takes the target operating system file as the target, executes the systemd-nspawn command (sixth command) in the target operating system to generate a lightweight container (first container space), and performs a pre-upgrade action on the target operating system file in the container by executing the package manager command (seventh command) to complete the component package dependency integrity check, upgrade configuration check, system software and hardware information collection and inspection, etc., and generate a corresponding inspection report.

[0113] In step S703, the upgrade module targets the target operating system file and executes the systemd-nspawn command on the target operating system to generate a lightweight container (second container space) for component upgrade. This process will install, uninstall, or upgrade the component dependency package according to the package manager. The package manager will use the component's own update strategy to update the configuration file of the corresponding component. After the package manager completes the component upgrade, it can perform adaptation migration through the customized configuration adapter module. At this point, the target system upgrade operation is completed. During the kernel component installation process, the update of the boot file will be automatically triggered. In this process, the boot file information will be automatically updated based on the dracut template (first preset template) used to generate the target operating system boot, the template (second preset template) used to generate the target operating system grub option, and the configuration content for the target operating system boot. The target operating system can notify the operating system to be replaced after the upgrade is completed.

[0114] Step S704: After the target operating system is upgraded, the target operating system is set as the startup target in the operating system to be replaced by specifying it through grub, and the computing device is restarted to enter the target operating system.

[0115] Step S705, test the business program on the target operating system. If the target operating system does not run as expected (for example, component package upgrade fails, etc.), you can set the operating system to be replaced as the startup target and restart the computing device to enter the operating system to be replaced.

[0116] Figure 8 is a schematic diagram of system mounting according to an embodiment of the present invention, such as Figure 8 As shown, / is the root partition, / var is the variable data partition, / boot is the boot partition, and the corresponding / dev / mapper / cl-root root partition is

[0117] / dev / mapper / cl-var is the variable data partition, and / dev / vda1 is the boot partition.

[0118] Step S801 : constructing a backup source mount of the operating system SYS0 to be replaced according to the target configuration file set by the user, and shielding the corresponding directory according to the sharing and exclusion directory settings in the user configuration.

[0119] Shield non-backup directories while maintaining the continuity of shared directories, so that business-critical directories are not affected during the backup process, ensuring both data integrity and business continuity.

[0120] Step S802: Construct a backup target mount of the target operating system SYS1 according to the user backup configuration.

[0121] By precisely defining the target mount point, SYS1 can be used not only as a backup for SYS0 but also as an independent, operational operating system environment, making it possible to upgrade the system without interrupting business operations.

[0122] Note that this process uses backing up the SYS1 system in SYS0 as an example, but the process can also be used to back up the SYS0 system in SYS1. The mount operation uses the Linux system namespace feature to prevent mount information from being leaked externally.

[0123] Figure 9 Schematic diagram of system booting according to an embodiment of the present invention, such as Figure 9 shown.

[0124] Step S901: After the backup data integrity verification is completed, the unshare and pivot_root command functions provided by the Linux system are used to generate an initrd image and a grub file containing the backup file path in SYS1.

[0125] SYS1 not only exists as a backup copy, but is also configured as an operating environment with independent boot capabilities, ready to receive subsequent upgrade operations and eventually become the main system for business operations.

[0126] Step S902: Add a target operating system boot entry to the grub file of SYS0, and select the system through the saved_entry field in the grubenv file.

[0127] The saved_entry field in the grubenv file provides a mechanism for users to select the upgraded system as the next boot target. This simplifies the system switchover process and gives users the flexibility to freely select the boot target before and after the upgrade, ensuring business continuity and high system availability.

[0128] An embodiment of the present invention further provides a computer-readable storage medium, in which a computer program is stored. The computer program is configured to execute the steps of any one of the above method embodiments when running.

[0129] In an exemplary embodiment, the computer-readable storage medium may include, but is not limited to, various media that can store computer programs, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk, or an optical disk.

[0130] An embodiment of the present invention further provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.

[0131] In an exemplary embodiment, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.

[0132] For specific examples in this embodiment, reference may be made to the examples described in the above embodiments and exemplary implementation modes, and this embodiment will not be described in detail here.

[0133] Obviously, those skilled in the art will appreciate that the various modules or steps of the present invention described above can be implemented using a general-purpose computing device, can be centralized on a single computing device, or can be distributed across a network of multiple computing devices. They can be implemented using program code executable by the computing device, and thus, can be stored in a storage device and executed by the computing device. In some cases, the steps shown or described herein can be performed in a different order than that shown, or can be fabricated as separate integrated circuit modules, or multiple modules or steps can be fabricated as a single integrated circuit module. Thus, the present invention is not limited to any particular combination of hardware and software.

[0134] The above are merely preferred embodiments of the present invention and are not intended to limit the present invention. Those skilled in the art will readily appreciate that various modifications and variations of the present invention are possible. Any modifications, equivalent substitutions, or improvements made within the principles of the present invention are intended to be within the scope of protection of the present invention.

Claims

1. A method for switching an operating system, characterized in that: include: Backing up the operating system to be replaced on the computing device, and using the backed-up operating system to be replaced as the target operating system; Modify the boot item of the boot file of the operating system to be replaced, and use the target operating system as the boot target; Restart the computing device and switch from the operating system to be replaced to the target operating system.

2. The method according to claim 1, characterized in that The method further comprises: The target operating system is upgraded, and the upgraded target operating system is updated to the target operating system.

3. The method according to claim 1, characterized in that The method further comprises: In response to the target operating system not meeting a preset condition, modifying a boot item of a boot file of the target operating system and using the operating system to be replaced as the startup target; Restart the computing device and switch from the target operating system back to the operating system to be replaced.

4. The method according to claim 1, wherein Backing up the operating system to be replaced on the computing device and using the backed up operating system to be replaced as the target operating system includes: Receive target configuration files set by users; According to the target configuration file, executing a first command in the operating system to be replaced to generate a first namespace; Constructing a mount tree of the operating system to be replaced and a mount tree of the target operating system in the first namespace; Copying data of the mount tree of the operating system to be replaced to the mount tree of the target operating system; A boot file of the target operating system is generated using a first preset template.

5. The method according to claim 4, characterized in that Constructing the mount tree of the target operating system in the first namespace includes: According to the target configuration file, the non-shared and non-excluded directories of the mount tree of the to-be-replaced operating system are copied to the mount tree of the target operating system.

6. The method according to claim 5, characterized in that Copying data of the mount tree of the to-be-replaced operating system to the mount tree of the target operating system includes: Copying the data of the non-shared and non-excluded directories to the mount tree of the target operating system in batches according to a preset data size; Verify the data after each batch is copied.

7. The method according to claim 4, characterized in that Generating the boot file of the target operating system by using the first preset template includes: executing a second command in the first namespace to root the mount tree of the target operating system, enter the target operating system, and adjust the mount file according to the target configuration file; A third command is executed in the operating system to be replaced to generate a boot file of the target operating system through a first preset template.

8. The method according to claim 1, characterized in that Modifying the boot item of the boot file of the operating system to be replaced and using the target operating system as the boot target includes: Executing a fourth command in the operating system to be replaced to load a boot item of the boot file of the target operating system through the second preset template; The fifth command is executed in the operating system to be replaced to write the boot item of the boot file of the target operating system into the startup target field.

9. The method according to claim 2, characterized in that Upgrading the target operating system, and updating the upgraded target operating system to the target operating system includes: Checking the component packages of the target operating system and generating a detection report; The component packages that need to be upgraded are upgraded according to the detection report.

10. The method according to claim 9, characterized in that Checking the component packages of the target operating system and generating a detection report includes: Executing a sixth command in the target operating system to generate a first container space; The seventh command is executed in the first container space to inspect the component package and generate the inspection report.

11. The method according to claim 9, characterized in that Upgrading the component packages that need to be upgraded according to the test report includes: executing a sixth command in the target operating system to generate a second container space; According to the detection report, the component packages that need to be upgraded are upgraded through the package manager.

12. The method according to claim 3, characterized in that In response to the target operating system not meeting a preset condition, modifying a boot item of a boot file of the target operating system to use the operating system to be replaced as the startup target includes: Testing the business program of the target operating system; In response to the test result of the business program not meeting a preset condition, the boot item of the boot file of the target operating system is modified, and the operating system to be replaced is used as the startup target.

13. The method according to claim 1, wherein The operating system to be replaced and the target operating system are in the same partition.

14. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, wherein the computer program implements the steps of the method described in any one of claims 1 to 13 when executed by a processor.

15. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 13 are implemented.

16. 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 described in any one of claims 1 to 13 are implemented.

Citation Information

Patent Citations

  • Method and device for upgrading unix-like operating system

    CN103777987A

  • HDFS containerization service system, method, device and equipment and storage medium

    CN114691357A

  • Operation system migration method and device, computing equipment and storage medium

    CN115617488A

  • Operation system migration method and device, equipment and storage medium

    CN117453295A

  • Modified Representation Of Backup Copy On Restore

    US20200257594A1