OSTree Rollback Method, Device and Storage Medium

By using watchdogs to monitor the number of restarts and automatically rollback to the original version in Linux devices, the problem of the system not being able to be used normally in the new version is solved, ensuring system reliability and automatic rollback to a stable state.

CN119883302BActive Publication Date: 2025-08-01KYLIN CORP
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510352671.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-03-25
Publication Date
2025-08-01
Estimated Expiration
2045-03-25

AI Technical Summary

Technical Problem

After upgrading to the new version, due to problems and problems, the existing technology cannot be automatically rolled back to the original version, resulting in a hidden reliability risk.

Method used

When the new version of the system is started, use the watchdog to monitor the number of restarts. After exceeding the threshold, it will automatically roll back to the original version. The new version of the kernel and file system association content is deleted through OSTree, and the configuration file priority is modified to form the original version system startup menu.

Benefits of technology

It realizes that when the new version of the system cannot start normally, it will automatically roll back to the original version of the system to ensure the normal operation and avoid the inconvenience and reliability risks of manual operation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119883302B_ABST
    Figure CN119883302B_ABST
Patent Text Reader

Abstract

An embodiment of the present invention discloses an OSTree rollback method, device, and storage medium. The method includes: when starting for the first time after the new version is correctly configured, starting the new version system according to the startup menu item identifier, and when the new version system starts for more than the timing parameter by using a preset watchdog, triggering a restart; using a preset count variable to count the number of restarts, and when exceeding the preset restart threshold, setting the new version startup menu item identifier to false; starting the original version system according to the startup menu item identifier, and after the original version system starts normally, querying the rollback identifier, and when the rollback identifier is true, using OSTree to delete the content associated with the new version in the kernel, the startup temporary system file system, and the root file system from the memory, and deleting the configuration file corresponding to the new version, and at the same time modifying the priority content in the configuration file name corresponding to the original version system to form the startup menu of the original version system.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of OSTree, and particularly to an OSTree rollback method, device and storage medium. Background Art

[0002] In the fields of industrial control and robot control, the use of Linux embedded operating systems is increasing day by day. However, after the Linux system is deployed to terminal devices, the update and upgrade of the system image usually require re - physical deployment, which cannot ensure the best operation experience and system uptime. To improve the upgrade experience of the Linux system, realizing secure remote OTA upgrade has become an important requirement.

[0003] OStree is a technology for the deployment and update of operating systems and container binaries. It combines a Git - like model to commit and download bootable file system trees, and has a mechanism for deploying them and managing bootloader configurations. The Linux upgrade system based on OSTree has secure remote OTA upgrade, and the amount of data transmitted during the upgrade process is very small.

[0004] After OSTree is upgraded to a new version, if the new version has problems and cannot enter the system normally, users need to manually select the old - version system startup menu to enter the original system. However, in reality, there are a large number of Linux devices that are very inconvenient for users to directly access. For such devices, once there are problems with the upgraded new version, serious reliability hazards will occur. Summary of the Invention

[0005] Embodiments of the present invention provide an OSTree rollback method, device and storage medium to solve the technical problem in the prior art that when a Linux device is upgraded using OSTree, the new version system cannot be used normally due to problems.

[0006] In a first aspect, an OSTree rollback method provided by an embodiment of the present invention includes:

[0007] When starting for the first time after the new version is correctly configured, start the new version system according to the startup menu item identifier, and use a preset watchdog to trigger a restart when the startup of the new version system exceeds the timing parameter;

[0008] Use a preset counting variable to count the number of restarts. When the number of restarts exceeds a preset restart threshold, set the startup menu item identifier of the new version to false, set the startup menu item identifier of the original version system to true, and set the rollback identifier to true;

[0009] Start the original version system according to the startup menu item identifier. After the original version system starts up normally, query the rollback identifier. When the rollback identifier is true, use OSTree to delete the content associated with the new version from the kernel, the startup temporary system file system, and the root file system on the memory, and delete the configuration file corresponding to the new version. At the same time, modify the priority content in the configuration file name corresponding to the original version system to form the startup menu of the original version system.

[0010] In a second aspect, an embodiment of the present invention further provides an OSTree rollback device, including:

[0011] An identification module, configured to start the new version system according to the startup menu item identifier when the new version is started for the first time after being correctly configured, and use a preset watchdog to trigger a restart when the startup of the new version system exceeds the timing parameter;

[0012] A setting module, configured to use a preset counting variable to count the number of restarts, and when the number of restarts exceeds a preset restart threshold, set the startup menu item identifier of the new version to false, set the startup menu item identifier of the original version system to true, and set the rollback identifier to true;

[0013] A deletion module, configured to start the original version system according to the startup menu item identifier. After the original version system starts up normally, query the rollback identifier. When the rollback identifier is true, use OSTree to delete the content associated with the new version from the kernel, the startup temporary system file system, and the root file system on the memory, and delete the configuration file corresponding to the new version. At the same time, modify the priority content in the configuration file name corresponding to the original version system to form the startup menu of the original version system.

[0014] In a third aspect, an embodiment of the present invention further provides a storage medium containing computer-executable instructions, and the computer-executable instructions are used to execute the OSTree rollback method provided in the above embodiment when executed by a computer processor.

[0015] The OSTree rollback method, device, and storage medium provided by the embodiments of the present invention start the new version system according to the startup menu item identifier when the new version is started for the first time after being correctly configured. When the new version system starts for more than the timing parameter by using a preset watchdog, a restart is triggered; a preset counting variable is used to count the number of restarts. When the number of restarts exceeds the preset restart threshold, the startup menu item identifier of the new version is set to false, the startup menu item identifier of the original version system is set to true, and the rollback identifier is set to true; the original version system is started according to the startup menu item identifier. After the original version system starts normally, the rollback identifier is queried. When the rollback identifier is true, the content associated with the new version in the kernel, the startup temporary system file system, and the root file system is deleted from the memory by using OSTree, and the configuration file corresponding to the new version is deleted. At the same time, the priority content in the configuration file name corresponding to the original version system is modified to form the startup menu of the original version system. By forming the startup menu item of the new version system through the configuration information of the new version system, the new version system can be automatically started, and the startup situation of the new version can be monitored by using the watchdog compiled by the kernel. When the new version system cannot start normally, the influence of the new version system is eliminated by using OSTree. And the system startup menu is modified again, and the original version system is used as the new system startup item, so that when there is a problem with the new version system, the original version system can be used continuously. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] Other features, objects, and advantages of the present invention will become more apparent from the following detailed description of non-limiting embodiments read with reference to the accompanying drawings:

[0017] Figure 1 is a flowchart of the OSTree rollback method provided by Embodiment 1 of the present invention;

[0018] Figure 2 is a flowchart of the OSTree rollback method provided by Embodiment 2 of the present invention;

[0019] Figure 3 is a structural diagram of the OSTree rollback device provided by Embodiment 3 of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0020] The present invention will be further described in detail below with reference to the drawings and embodiments. It can be understood that the specific embodiments described herein are only for explaining the present invention and are not intended to limit the present invention. Additionally, it should be noted that for the sake of description, only parts related to the present invention are shown in the drawings rather than all the structures.

[0021] Embodiment 1

[0022] Figure 1The following is a flowchart of the OSTree rollback method provided in the first embodiment of the present invention. This embodiment is applicable to the situation where a new version is upgraded using Ostree in a Linux system and automatically rolled back to the original version system when the new version system is abnormal. This method can be executed by an OSTree rollback device, and specifically includes the following steps:

[0023] Step 110: When the new version is first started after being correctly configured, start the new version system according to the startup menu item identifier. When the new version system starts for more than the timing parameter using a preset watchdog, trigger a restart.

[0024] In this embodiment, the server stores the OSTree remote repository, and the Linux embedded operating system normally runs the original version system and can pull the OSTree file of the new version system from the server. After the pull is completed, configuration is performed. Taking the new version system as VersionC as an example, the following method is used to implement the pull and configuration:

[0025] ostreepullVersionC

[0026] ostreedeployversionC.

[0027] After correct configuration, a startup item for the new version system can be generated, and using the startup menu item identifier newly added in the bootloader, determine whether to start the original version system or the new version system according to the startup menu item identifier. Use the startup menu item identifier to identify that the new version system needs to be started currently and start the new version system.

[0028] Correspondingly, a watchdog program can be set in the kernel, and this watchdog program can trigger a system restart when the system startup times out. Correspondingly, the method further includes: adding a system service set in the system to be started in the early startup stage, responsible for regularly feeding the dog and monitoring the status of systemd and other startup services. So that when the system can start normally, regular dog feeding is performed to avoid restarting.

[0029] Step 120: Use a preset counting variable to count the number of restarts. When the number of restarts exceeds the preset restart threshold, set the new version startup menu item identifier to false, set the original version system startup menu item identifier to true, and set the rollback identifier to true.

[0030] In this system, a counting variable can be added to the system startup program to count the number of reboots. Then, it is determined whether the counting variable exceeds a preset reboot threshold, which can be set according to experience. Exemplarily, it can be set to 5. When it exceeds, the new version startup menu item identifier set in the startup program can be set to false, and correspondingly, the original version system startup menu item identifier can be set to true, and the added rollback identifier in the startup program can be set to true, so that when the system starts again, by searching for the rollback identifier, it can be determined that it is in the rollback state. Since the original version system can start normally, and the rollback operation can only be executed after the system starts normally. Otherwise, the new version system is still started normally according to the new version startup menu item identifier and the rollback identifier.

[0031] Step 130, start the original version system according to the startup menu item identifier. After the original version system starts normally, query the rollback identifier. When the rollback identifier is true, use OSTree to delete the content associated with the new version in the kernel, the startup temporary system file system, and the root file system from the memory, and delete the configuration file corresponding to the new version. At the same time, modify the priority content in the configuration file name corresponding to the original version system to form the startup menu of the original version system.

[0032] Each time the system starts, first determine which system is currently being started based on the startup menu item identifier in the system startup program, and then start the original version system normally. After the original version system starts normally, query the rollback identifier. When the rollback identifier is true, use OSTree to delete the content associated with the new version in the kernel, the startup temporary system file system, and the root file system from the memory. Exemplarily, the OSTree command can be used to delete the content associated with the new version in the kernel, the temporary root file system initramfs, and the root file system rootfs from the memory. And delete the startup configuration file entries / ostree-1-*.conf corresponding to the new version system. The modification of the priority content in the configuration file name corresponding to the new version can include: renaming the configuration file entries / ostree-2-*.conf corresponding to the original version system to entries / ostree-1-*.conf, and resetting the startup menu item according to the configuration file, so that only the startup menu of the original version system exists in the startup menu item.

[0033] Using the above method can ensure the success of the rollback and eliminate the impact of the problematic new version system on the startup system. And modify the startup menu so that the original version system can be started normally every time in the later stage, ensure that the system can automatically complete the rollback of the problem version system, and ensure the normal operation of the system.

[0034] In this embodiment, when the new version is correctly configured and starts for the first time, the new version system is started according to the startup menu item identifier. When the startup of the new version system exceeds the timing parameter by using the preset watchdog, a restart is triggered. The preset count variable is used to count the number of restarts. When the number of restarts exceeds the preset restart threshold, the startup menu item identifier of the new version is set to false, the startup menu item identifier of the original version system is set to true, and the rollback identifier is set to true. The original version system is started according to the startup menu item identifier. After the original version system starts normally, the rollback identifier is queried. When the rollback identifier is true, the content associated with the new version in the kernel, the startup temporary system file system, and the root file system is deleted from the memory by using OSTree, and the configuration file corresponding to the new version is deleted. At the same time, the priority content in the configuration file name corresponding to the original version system is modified to form the startup menu of the original version system. By forming the startup menu item of the new version system through the configuration information of the new version system, the new version system can be automatically started, and the watchdog compiled by the kernel is used to monitor the startup situation of the new version. When the new version system cannot start normally, the influence of the new version system is eliminated by using OSTree. And the system startup menu is modified again, and the original version system is used as the new system startup item, so that when the new version system has problems, the original version system can be continued to be used.

[0035] In a preferred embodiment of this embodiment, before the first start after the new version is correctly configured, the following steps can be further added to the method: after the new version system is pulled and configured, the startup configuration file generated when OSTree deploys the new version is parsed, and the startup attribute elements of the new version are read; using the template of the startup menu item, the startup attribute elements are filled as parameters to generate the startup menu item of the new version; the startup menu item identifier of the new version is set to true. Exemplarily, the startup configuration file entries / ostree-1-*.conf generated when OSTree deploys the new version system can be parsed, and the elements including the startup menu name, kernel path, kernel command line parameters, initial RAM file system path, rootfs path, etc. of the new version are read. According to the template of the startup menu item, the elements read in the previous step are used as parameters to generate a standard startup menu item, which is the startup menu entry of the new version system. By using the above method, the startup menu item can be automatically generated, the new version system can be started normally by using the startup menu item, and it is convenient for later adjustment and starting the original version system.

[0036] In another preferred embodiment of this embodiment, the method may further include the following steps: enabling soft lockup and hard lockup exception detection functions during kernel compilation, and adding hardware watchdog timing parameters to the kernel startup parameters; starting the software watchdog using initramfs, adding instructions and parameters for enabling the initramfs watchdog to the initramfs script, and correspondingly adding instructions for stopping the initramfs watchdog. Exemplarily, multiple types of watchdogs can be enabled in the system, including the kernel, initramfs, and service watchdogs. Optionally, start the kernel watchdog, enable the softlockup and hardlockup functions during kernel compilation, and add "watchdog_thresh=20" to the kernel startup parameters. If the kernel does not respond for more than 20s, the system will automatically trigger a reboot. Then start the initramfs software watchdog. Add "write 30 to / dev / watchdog" at the beginning of the initramfs script to enable the initramfs watchdog, and write "stop" to / dev / watchdog / at the end of the script to stop the initramfs watchdog. If the initramfs does not respond for more than 30s during execution, the system will automatically trigger a reboot.

[0037] Embodiment 2

[0038] Figure 2 FIG. is a schematic flowchart of the OSTree rollback method provided in Embodiment 2 of the present invention. This embodiment is optimized based on the above embodiment. The method may further include the following steps: creating an automatic rollback abstract class for encapsulating the processing logic corresponding to the OSTree rollback method, and opening external interfaces for key elements such as startup count, startup limit, and trigger condition abstract elements; reading the configuration file of the system service and reading the agreed bootloader type therein; setting the type processing method in the automatic rollback abstract class according to the agreed bootloader type.

[0039] See Figure 2 , the OSTree rollback method includes:

[0040] Step 210, create an automatic rollback abstract class for encapsulating the processing logic corresponding to the OSTree rollback method, and open external interfaces for key elements such as startup count, startup limit, and trigger condition abstract elements.

[0041] Since the bootloaders of devices may be different, such as grub, uboot, pmon, openSBI, and the ways they transmit information to the system service are different. Therefore, the OSTree rollback method provided in the above embodiment may not be applicable to devices with different architectures. Therefore, in this embodiment, optimization processing is performed.

[0042] Exemplarily, an automatic rollback abstract class can be created, which can be instantiated to implement the OSTree rollback method. The above processing logic is encapsulated through this class. At the same time, in order to facilitate users to flexibly customize the rollback conditions, corresponding interfaces are reserved for users to input some key elements. For example, abstract elements such as startup count, startup limit, and trigger conditions. That is, the number of times the new version system restarts, the timing parameters of the watchdog, and the trigger conditions for restart. Using the design structure, key elements affecting automatic rollback such as startup count and startup limit are abstracted into the abstract class bootloader_state, and different bootloaders implement bootloader_state_uboot_ext by defining their respective specific classes, which are methods describing the characteristics of different bootloaders. To solve the device independence problem. Define the abstract class bootloader_state, which includes the following key elements:

[0043] Boot counter: Records the number of times the system has been started.

[0044] Boot limit: Sets the maximum number of failed startups allowed.

[0045] Rollback trigger condition: When the startup count exceeds the startup limit, the rollback operation is triggered.

[0046] Step 220, read the configuration file of the system service, and read the agreed bootloader type therein; set the type processing method in the automatic rollback abstract class according to the agreed bootloader type.

[0047] When starting the system service, read the configuration file of the system service, where the agreed bootloader type is used to create the corresponding method in bootloader_state_uboot_ext and obtain the corresponding value from / boot / uboot.cnt.

[0048] Step 230, instantiate an object corresponding to the type using the type processing method.

[0049] Using the content returned by the described type of processing method, the bootloader adopted by the current system can be determined. And corresponding classes are instantiated to process the object of the bootloader. Exemplarily, it may include: initializing the boot pointer to a null value, where the boot pointer is used to point to the state object of the agreed bootloader; determining the type of the object according to the pointing of the boot pointer. Using the type of the object in the memory pointed to by the pointer. The code first initializes a pointer named bootloader (type bootloader_state*) to NULL, and the role of this pointer is to point to the created bootloader state object in the future. Subsequently, different values of the bootloader_type string variable are used to determine which instance of the bootloader state class to create. For example: according to the characteristics of different bootloaders, specific classes are defined to implement the functions of the abstract class bootloader_state. For example:

[0050] bootloader_state_grub: For the GRUB bootloader, read and write the startup counter through the grubenv configuration file.

[0051] bootloader_state_uboot: For the U-Boot bootloader, read and write the startup counter through environment variables or configuration files.

[0052] bootloader_state_pmon: For the PMON bootloader, read and write the startup counter through a specified file.

[0053] bootloader_state_opensbi: For the OpenSBI bootloader, read and write the startup counter through NVMe or other storage media.

[0054] Step 240, when starting for the first time after the new version is correctly configured, start the new version system according to the startup menu item identifier, and use the preset watchdog to trigger a restart when the startup of the new version system exceeds the timing parameter.

[0055] Step 250, use the preset count variable to count the number of restarts. When the number of restarts exceeds the preset restart threshold, set the startup menu item identifier of the new version to false, set the startup menu item identifier of the original version system to true, and set the rollback identifier to true.

[0056] Step 260: Start the original version system according to the startup menu item identifier. After the original version system starts up normally, query the rollback identifier. When the rollback identifier is true, use OSTree to delete the content associated with the new version from the kernel, the startup temporary system file system, and the root file system in the memory, and delete the configuration file corresponding to the new version. At the same time, modify the priority content in the configuration file name corresponding to the original version system to form the startup menu of the original version system.

[0057] In this embodiment, the following steps are added: Create an automatic rollback abstract class for encapsulating the processing logic corresponding to the OSTree rollback method, and open the external interfaces of the key elements, namely, the startup count, the startup limit, and the trigger condition abstract elements; Read the configuration file of the system service and read the agreed bootloader type therein; Set the type processing method in the automatic rollback abstract class according to the agreed bootloader type; Instantiate the object corresponding to the type using the type processing method. Instantiate the object corresponding to the type using the type processing method. The OSTree rollback method can be implemented for different platforms to achieve cross-platform generality.

[0058] Embodiment III

[0059] Figure 3 is the structural schematic diagram of the OSTree rollback device provided by Embodiment III of the present invention. Refer to Figure 3 , the OSTree rollback device includes:

[0060] An identification module 310, configured to start the new version system according to the startup menu item identifier when the new version is started for the first time after being correctly configured, and use a preset watchdog to trigger a restart when the startup of the new version system exceeds the timing parameter;

[0061] A setting module 320, configured to use a preset count variable to count the number of restarts, and when the number of restarts exceeds a preset restart threshold, set the startup menu item identifier of the new version to false, set the startup menu item identifier of the original version system to true, and set the rollback identifier to true;

[0062] A deletion module 330, configured to start the original version system according to the startup menu item identifier. After the original version system starts up normally, query the rollback identifier. When the rollback identifier is true, use OSTree to delete the content associated with the new version from the kernel, the startup temporary system file system, and the root file system in the memory, and delete the configuration file corresponding to the new version. At the same time, modify the priority content in the configuration file name corresponding to the original version system to form the startup menu of the original version system.

[0063] The OSTree rollback device provided in this embodiment starts the new version system according to the startup menu item identifier when the new version is correctly configured and starts for the first time. When the new version system starts and exceeds the timing parameter, the preset watchdog is used to trigger a restart. The preset counting variable is used to count the number of restarts. When the number of restarts exceeds the preset restart threshold, the new version startup menu item identifier is set to false, the original version system startup menu item identifier is set to true, and the rollback identifier is set to true. The original version system is started according to the startup menu item identifier. After the original version system starts normally, the rollback identifier is queried. When the rollback identifier is true, the content associated with the new version in the kernel, the startup temporary system file system, and the root file system is deleted from the memory using OSTree, and the configuration file corresponding to the new version is deleted. At the same time, the priority content in the configuration file name corresponding to the original version system is modified to form the startup menu of the original version system. By forming the startup menu item of the new version system through the configuration information of the new version system, the new version system can be automatically started, and the watchdog compiled by the kernel is used to monitor the startup situation of the new version. When the new version system cannot start normally, the influence of the new version system is eliminated using OSTree. And the system startup menu is modified again, and the original version system is used as the new system startup item, so that when there is a problem with the new version system, the original version system can be used continuously.

[0064] Based on the above embodiments, the device further includes:

[0065] A parsing module, configured to parse the startup configuration file generated when deploying the new version of ostree after the new version system is pulled for configuration, and read the new version startup attribute elements;

[0066] A filling module, configured to use the template of the startup menu item, fill in the startup attribute elements as parameters, and generate a new version startup menu item;

[0067] A setting module, configured to set the new version startup menu item identifier to true.

[0068] Based on the above embodiments, the device further includes:

[0069] An adding module, configured to enable the soft lockup and hard lockup exception detection functions during kernel compilation, and add the hardware watchdog timing parameter to the kernel startup parameters;

[0070] A startup module, configured to start the software watchdog using initramfs, add instructions and parameters for enabling the initramfs watchdog to the initramfs script, and correspondingly add instructions for stopping the initramfs watchdog.

[0071] Based on the above embodiments, the judgment module further includes:

[0072] The service item addition module is used to add and set system services in the system, start in the early startup stage, be responsible for regularly "feeding the dog", and monitor the status of systemd and other startup services.

[0073] Based on the above embodiments, the deletion module includes:

[0074] The naming unit is used to name the configuration file entries / ostree-2-*.conf corresponding to the original version system as entries / ostree-1-*.conf, and reset the startup menu item according to the configuration file, so that only the startup menu of the original version system will exist in the startup menu item.

[0075] Based on the above embodiments, the device further includes:

[0076] The class creation module is used to create an automatic rollback abstract class, which is used to encapsulate the processing logic corresponding to the OSTree rollback method, and open the external interfaces of the key elements of startup count, startup limit, and trigger condition abstract elements;

[0077] The reading module is used to read the configuration file of the system service and read the agreed bootloader type therein;

[0078] The method setting module is used to set the type processing method in the automatic rollback abstract class according to the agreed bootloader type;

[0079] The instantiation module is used to instantiate the object corresponding to the type by using the type processing method.

[0080] Based on the above embodiments, the instantiation module includes:

[0081] The initialization unit is used to initialize the boot pointer to a null value, and the boot pointer is used to point to the status object of the agreed bootloader;

[0082] The pointing unit is used to determine the type of the object according to the pointing of the boot pointer.

[0083] Based on the above embodiments, the instantiation module further includes:

[0084] The first read and write unit is used to read and write the startup counter through the grubenv configuration file for the GRUB bootloader;

[0085] The second read and write unit is used to read and write the startup counter through the environment variable or configuration file for the U-Boot bootloader;

[0086] A third read and write unit, configured to read and write a startup counter for the PMON bootloader by specifying a file;

[0087] A fourth read and write unit, configured to read and write a startup counter for the OpenSBI bootloader through an NVMe or other storage medium.

[0088] The OSTree rollback device provided by the embodiments of the present invention can execute the OSTree rollback method provided by any embodiment of the present invention, and has functional modules and beneficial effects corresponding to the execution of the method.

[0089] Embodiment 4

[0090] Embodiment 4 of the present invention further provides a storage medium including computer-executable instructions, and the computer-executable instructions are used to execute any of the OSTree rollback methods provided by the above embodiments when executed by a computer processor.

[0091] The computer storage medium of the embodiments of the present invention can be any combination of one or more computer-readable media. The computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples (non-exhaustive list) of the computer-readable storage medium include: an electrical connection having one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this document, the computer-readable storage medium can be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.

[0092] The computer-readable signal medium can include a data signal propagated in a baseband or as part of a carrier wave, which carries the computer-readable program code. Such a propagated data signal can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The computer-readable signal medium can also be any computer-readable medium other than the computer-readable storage medium, and the computer-readable medium can send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.

[0093] The program code included on the computer-readable medium can be transmitted by any suitable medium, including but not limited to wireless, wire, optical cable, RF, etc., or any suitable combination of the above.

[0094] Computer program code for performing the operations of the present invention may be written in one or more programming languages or combinations thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and also including conventional procedural programming languages such as the "C" language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, execute as a stand-alone software package, partly on the user's computer and partly on a remote computer, or execute entirely on the remote computer or device. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0095] Note that the above is only a preferred embodiment of the present invention and the technical principles applied. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein. Various obvious changes, re-adjustments, and substitutions can be made by those skilled in the art without departing from the protection scope of the present invention. Therefore, although the present invention has been described in detail through the above embodiments, the present invention is not limited to the above embodiments. Without departing from the concept of the present invention, more other equivalent embodiments may be included, and the scope of the present invention is determined by the scope of the appended claims.

Claims

1. An OSTree rollback method, characterized in that, Including: After the new version system pulls the configuration, parse the startup configuration file generated when the ostree deploys the new version, and read the startup property elements of the new version; Use the template of the startup menu item to fill in the startup property elements as parameters to generate a new version startup menu item; Set the new version startup menu item flag to true; When the new version is started for the first time after being correctly configured, start the new version system according to the startup menu item flag. When the new version system starts and exceeds the timing parameter, trigger a restart using the preset watchdog; Use the preset counting variable to count the number of restarts. When the number of restarts exceeds the preset restart threshold, set the new version startup menu item flag to false, set the original version system startup menu item flag to true, and set the rollback flag to true; Start the original version system according to the startup menu item flag. After the original version system starts normally, query the rollback flag. When the rollback flag is true, use OSTree to delete the content associated with the new version in the kernel, the startup temporary system file system, and the root file system from the memory, delete the configuration file corresponding to the new version, and at the same time modify the priority content in the configuration file name corresponding to the original version system to form the original version system startup menu; Create an automatic rollback abstract class to encapsulate the processing logic corresponding to the OSTree rollback method, and open the external interfaces of the key elements startup count, startup limit, and trigger condition abstract elements; Read the configuration file of the system service and read the agreed bootloader type therein; Set the type processing method in the automatic rollback abstract class according to the agreed bootloader type; Instantiate an object corresponding to the type using the type processing method; The instantiating an object corresponding to the type using the type processing method includes: Initialize the boot pointer to a null value, and the boot pointer is used to point to the status object of the agreed bootloader; Determine the type of the object according to the pointing of the boot pointer; The setting the type processing method in the automatic rollback abstract class according to the agreed bootloader type includes: For the GRUB bootloader, read and write the startup counter through the grubenv configuration file; For the U-Boot bootloader, read and write the startup counter through the environment variable or configuration file; For the PMON bootloader, read and write the startup counter through the specified file; For the OpenSBI bootloader, read and write the startup counter through the NVMe or other storage media.

2. The method according to claim 1, wherein The method further includes: Enable the soft lockup and hard lockup exception detection functions during kernel compilation, and add the hardware watchdog timing parameter to the kernel startup parameters; Use initramfs to start the software watchdog, use the initramfs script to add instructions and parameters for enabling the initramfs watchdog, and correspondingly add instructions for stopping the initramfs watchdog.

3. The method according to claim 2, characterized in that, The method further includes: Add a system service setting in the system to start in the early startup stage, be responsible for regularly feeding the watchdog, and monitoring the status of systemd and other boot services.

4. The method according to claim 1, wherein Modifying the priority content in the configuration file name corresponding to the new version includes: Renaming the configuration file entries / ostree-2-*.conf corresponding to the original version system to entries / ostree-1-*.conf, and resetting the boot menu item according to the configuration file, so that only the boot menu of the original version system exists in the boot menu item.

5. An OSTree rollback device, characterized in that, Including: A parsing module, which is used to parse the boot configuration file generated when the new version is deployed by ostree after the new version system is pulled with the configuration, and read the new version boot property element; A filling module, which is used to fill the boot property element as a parameter by using the template of the boot menu item to generate a new version boot menu item; A setting module, which is used to set the new version boot menu item flag to true; An identification module, which is used to start the new version system according to the boot menu item flag when the new version is started for the first time after being correctly configured, and trigger a restart when the new version system starts for more than the timing parameter by using a preset watchdog; A setting module, which is used to count the number of restarts by using a preset counting variable, and when the number of restarts exceeds the preset restart threshold, set the new version boot menu item flag to false, set the original version system boot menu item flag to true, and set the rollback flag to true; A deletion module, which is used to start the original version system according to the boot menu item flag, query the rollback flag after the original version system starts normally, and when the rollback flag is true, use OSTree to delete the content associated with the new version in the kernel, the boot temporary system file system, and the root file system from the memory, delete the configuration file corresponding to the new version, and at the same time modify the priority content in the configuration file name corresponding to the original version system to form the original version system boot menu; A class creation module, which is used to create an automatic rollback abstract class, which is used to encapsulate the processing logic corresponding to the OSTree rollback method, and open the external interfaces of the key elements of the start count, start limit, and trigger condition abstract elements; A reading module, which is used to read the configuration file of the system service and read the agreed boot loader type therein; A method setting module, which is used to set the type processing method in the automatic rollback abstract class according to the agreed boot loader type; An instantiation module, which is used to instantiate an object corresponding to the type by using the type processing method; The instantiation module includes: An initialization unit, which is used to initialize the boot pointer to a null value, and the boot pointer is used to point to the status object of the agreed boot loader; A pointing unit, which is used to determine the type of the object according to the pointing of the boot pointer; The instantiation module also includes: A first read and write unit, which is used to read and write the boot counter through the grubenv configuration file for the GRUB boot loader; A second read and write unit, which is used to read and write the boot counter through the environment variable or configuration file for the U-Boot boot loader; A third read and write unit, which is used to read and write the boot counter through a specified file for the PMON boot loader; A fourth read and write unit for reading and writing a boot counter for the OpenSBI bootloader via NVMe or other storage media.

6. A storage medium containing computer-executable instructions, characterized in that, The computer-executable instructions, when executed by a computer processor, are used to perform the OSTree rollback method according to any one of claims 1-4.

Citation Information

Patent Citations

  • System upgrading method and device in Internet of Things equipment, equipment and storage medium

    CN112527322A

  • Linux kernel automatic rollback recovery method based on embedded system

    CN115794237A