Mirror switching method and electronic device
By setting image corruption and error count variables during the BMC bootloader loading phase, the system automatically identifies and switches to a backup image, solving the problem of BMC image abnormal operation caused by fatal errors that cannot be identified in existing technologies, thus improving the reliability and operational efficiency of BMC.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- INSPUR SUZHOU INTELLIGENT TECH CO LTD
- Filing Date
- 2026-05-20
- Publication Date
- 2026-07-31
AI Technical Summary
Existing dual-image switching solutions cannot identify BMC image malfunctions caused by fatal errors in the kernel or applications, resulting in high maintenance costs and unreliability.
By setting a corrupted image variable value during the bootloader loading stage, and performing boot and read/write partition verification during the kernel and application space stages, the system can automatically identify image anomalies and switch to a backup image. By combining the image error count variable value, the system can determine the randomness of image boot anomalies, thereby achieving self-repair and self-upgrade.
It enables accurate and rapid identification of BMC image malfunctions caused by fatal kernel or application errors, and automatically switches to a backup image, reducing maintenance costs and improving BMC reliability and operational efficiency.
Smart Images

Figure CN122220148B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer application technology, and in particular to a mirror switching method and electronic device. Background Technology
[0002] The Baseboard Management Controller (BMC) is a microcontroller specifically designed for monitoring and managing servers. Using a single BMC architecture means that when the BMC crashes or a mirrored area becomes corrupted, engineer intervention is required for analysis and resolution, resulting in high maintenance costs.
[0003] Current dual-image switching solutions typically involve manual handling or simple partition cyclic redundancy check (CRC) verification, switching images when a check fails. However, this approach has several limitations, failing to identify BMC image malfunctions caused by fatal kernel or application errors. Summary of the Invention
[0004] This application provides an image switching method and electronic device to at least solve the problem of abnormal operation of BMC images caused by fatal errors that fail to recognize some kernels or applications in related technologies.
[0005] This application provides a mirror switching method, including: When booting from the master image, the value of the first image corruption variable corresponding to the master image is obtained during the bootloader loading phase; When the value of the first image damage variable is the image undamaged state value, the value of the first image damage variable is changed from the image undamaged state value to the image damage state value; Perform kernel and application space stage startup and read / write partition verification, and detect the corrupted variable values of the first image; When the detection result indicates that the value of the first image damage variable remains the same as the image damage state value, switch to the backup image for startup.
[0006] This application also provides an electronic device, including: a memory for storing a computer program; and a processor for implementing the steps of any of the above-described mirror switching methods when executing the computer program.
[0007] This application addresses the issue of abnormal startup of the primary image by setting a first image corruption variable value. During the bootloader loading phase, when the first image corruption variable value is determined to be the image undamaged state value, it is converted from the undamaged state value to the corrupted state value. Kernel and application space startup and read / write partition verification are then performed. Based on the state of the first image corruption variable value, the startup status of the kernel and application space stages and the read / write partition verification results are identified. If either the kernel or application space stage experiences a startup anomaly, or the read / write partition verification result indicates image corruption, the first image corruption variable value remains the corrupted state value, indicating a startup anomaly for the primary image, and the system switches to a backup image for startup. This achieves accurate and rapid identification of BMC image anomalies caused by fatal errors in the kernel or applications. In scenarios of startup anomalies or image corruption, the primary BMC image automatically switches to a backup image. Therefore, it solves the technical problem of failing to identify BMC image anomalies caused by fatal errors in the kernel or applications, significantly improving the reliability of the BMC firmware and resolving issues related to abnormal startup, operation, and corruption. Attached Figure Description
[0008] To more clearly illustrate the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0009] Figure 1 A flowchart illustrating the implementation of a mirror switching method provided in this application embodiment; Figure 2 A flowchart illustrating the implementation of another mirror switching method provided in this application embodiment; Figure 3 This is a structural block diagram of a mirror switching device provided in an embodiment of this application. Detailed Implementation
[0010] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the protection scope of this application.
[0011] It should be noted that, in the description of this application, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. The terms "first," "second," etc., in this application are used to distinguish similar objects and are not used to describe a specific order or sequence.
[0012] To enable those skilled in the art to better understand the present application, the present application will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0013] The embodiments of this application provide a mirror switching method, and the method is described in detail in conjunction with the execution flow of the mirror switching method.
[0014] See Figure 1 , Figure 1 This is a flowchart illustrating an implementation of a mirror switching method provided in this application. The method may include the following steps.
[0015] S101: When booting from the master image, obtain the first image corruption variable value corresponding to the master image during the bootloader loading phase.
[0016] The primary and backup images for BMC are pre-configured, and BMC boots from the primary image by default. When BMC boots from the primary or backup image for the first time, two environment variables are added to the u-boot general bootloader during the bootloader loading phase: the first image corruption variable value (Image1Damage) corresponding to the primary image and the second image corruption variable value (Image2Damage) corresponding to the backup image. These variables are used to record the current image corruption and running status, and their initial value is set to "yes". Except for the first boot from the primary or backup image, if the system boots again, these environment variables already exist and will not be overwritten.
[0017] When booting from the master image, the first image corruption variable value corresponding to the master image is obtained during the bootloader loading phase.
[0018] S102: When the value of the first image damage variable is the image undamaged state value, change the value of the first image damage variable from the image undamaged state value to the image damage state value.
[0019] After obtaining the first image corruption variable value corresponding to the main image during the bootloader loading phase, the first image corruption variable value is detected. When the first image corruption variable value is the image undamaged state value, the first image corruption variable value is changed from the image undamaged state value to the image corruption state value, thereby preparing for the subsequent kernel stage and application space stage boot and read-write (RW) partition verification.
[0020] S103: Performs kernel and application space stage startup and read / write partition verification, and detects corrupted variable values in the first image.
[0021] BMC image booting includes the bootloader loading stage, kernel stage, and application space stage. After converting the first image corruption variable value from an uncorrupted state to a corrupted state, the kernel stage and application space stage booting and partition read / write verification are performed, and the first image corruption variable value is checked to obtain the detection result.
[0022] The read / write partition is used to store BMC operation and configuration data.
[0023] S104: When the detection result shows that the value of the first image is damaged and the image remains damaged, switch to the backup image for startup.
[0024] After detecting the corrupted variable value of the first image and obtaining the detection result, if the detection result shows that the corrupted variable value of the first image remains in the image corruption state, it indicates that there is a startup anomaly in either the kernel stage or the application space stage, or the read / write partition verification result shows that the image is corrupted, and the system switches to the backup image for startup. This enables intelligent switching to the backup image in scenarios such as BMC primary image corruption or severe program malfunction.
[0025] This application addresses the issue of abnormal boot status of the primary image by setting a first image corruption variable value. During the bootloader loading phase, if the first image corruption variable value is determined to be the image undamaged state, it is converted from the undamaged state to the corrupted state value. Kernel and application space boot processes and read / write partition verification are then performed. Based on the state of the first image corruption variable value, the boot status of the kernel and application space stages and the read / write partition verification results are identified. If either the kernel or application space stage experiences a boot anomaly, or the read / write partition verification result indicates image corruption, the first image corruption variable value remains unchanged, indicating a boot anomaly in the primary image, and the system switches to a backup image. This achieves accurate and rapid identification of BMC image anomalies caused by fatal errors in the kernel or applications. In scenarios of boot anomalies or image corruption, the primary BMC image automatically switches to a backup image. Therefore, it solves the technical problem of failing to identify BMC image anomalies caused by fatal errors in the kernel or applications, significantly improving the reliability of the BMC firmware and addressing issues of abnormal boot, operation, and corruption.
[0026] See Figure 2 , Figure 2 This is a flowchart illustrating another mirror switching method provided in an embodiment of this application. The method may include the following steps: S201: When booting from the master image, obtain the first image corruption variable value corresponding to the master image during the bootloader loading phase.
[0027] S202: When the value of the first image damage variable is the image undamaged state value, change the value of the first image damage variable from the image undamaged state value to the image damage state value.
[0028] S203: Performs kernel and application space stage startup and read / write partition verification, and detects corrupted variable values in the first image.
[0029] S204: When the detection result shows that the value of the first image damage variable changes from the image damage status value to the image undamaged status value, it is determined that the main image starts normally.
[0030] After detecting the value of the first image's corrupted variable and obtaining the detection result, when the detection result shows that the value of the first image's corrupted variable changes from a corrupted image state value to an uncorrupted image state value, it indicates that both the kernel stage and the application space stage have started abnormally, and the read / write partition verification result shows that the image is uncorrupted, thus confirming that the main image starts normally.
[0031] S205: Clear the error count variable value of the first image corresponding to the primary image to zero.
[0032] Among them, normal startup of the main image includes normal startup after retry; the error count variable value of the first image is used to record the number of times the main image has started abnormally.
[0033] When BMC boots from the primary or standby image for the first time, it adds two environment variables: the first image error count variable (Image1ErrCnt) and the second image error count variable (Image2ErrCnt). These variables are used to record the number of consecutive failures of the primary and standby images, respectively. The initial value of these two environment variables is set to 0. Except for the initial boot from the primary or standby image, if the system boots again, these environment variables will already exist and will not be overwritten.
[0034] After confirming that the primary image has started normally, the error count variable corresponding to the primary image is cleared to zero. By clearing the error count variable corresponding to the primary image in a timely manner, the impact on the recording results of the number of consecutive failures of the primary image during the subsequent boot process of the BMC from the primary image is avoided.
[0035] S206: When the detection result shows that the value of the first image damage variable remains the same as the image damage status value, the value of the first image error count variable corresponding to the main image is updated.
[0036] After detecting the first image corruption variable value and obtaining the detection result, if the detection result shows that the first image corruption variable value remains the image corruption state value, it indicates that the main image has an abnormal startup. The error count variable value of the first image corresponding to the main image is updated, such as incrementing the error count variable value of the first image by 1.
[0037] S207: Determine whether the value of the first image error count variable obtained from the update is greater than or equal to the preset value. If not, proceed to step S208; if yes, proceed to step S209.
[0038] After updating the error count variable value of the first image corresponding to the main image, it is determined whether the updated error count variable value of the first image is greater than or equal to the preset value. If not, step S208 is executed to avoid the randomness of the main image startup exception. If yes, it means that the randomness of the main image startup exception has been largely eliminated, and step S209 is executed.
[0039] It should be noted that the preset value can be set and adjusted according to the actual situation. This application embodiment does not limit this, such as it can be set to 3.
[0040] S208: Reboot the main image and return to step S203.
[0041] When the error count variable value of the first image obtained from the update is less than the preset value, in order to avoid the randomness of the main image startup failure, the main image is restarted and the execution step S203 is returned to perform a new round of main image restart.
[0042] The main reasons for abnormal startup of the main image include the following four: (1) If a serious error occurs during kernel operation during startup, the BMC will trigger its own watchdog timer, thereby triggering the BMC restart. That is, after the BMC's watchdog is triggered, it notifies the Complex Programmable Logic Device (CPLD), and the CPLD will send a restart signal to the BMC. The value of the first image corruption variable remains the image corruption state value, i.e., "yes". (2) Various services in the application layer will start in a certain order. If the service of the critical business fails to start during this process, and the daemon process still fails after trying to restart the service a preset number of times, the watchdog will be triggered, thereby triggering the BMC to restart. The value of the first image corruption variable remains the image corruption state value, i.e. "yes". (3) If the boot, kernel, or read-only (ro) file system partitions are damaged during the boot process, the kernel or application layer will not be able to run normally, which will also trigger the watchdog, thereby triggering the BMC to restart. The value of the first image damage variable remains the image damage status value, i.e., "yes". (4) If the kernel and all application services start normally, it means that the boot, kernel, and ro partitions of the main image are normal. Then compare the contents of these partitions of the main image and the standby image respectively. If the contents of a certain area are inconsistent, the contents of the main image are synchronized to the standby image. Check whether the RW partition is corrupted. If it is corrupted, the value of the first image corruption variable remains the image corruption status value, i.e., "yes". If it is not corrupted, the value of the first image corruption variable changes from the image corruption status value to the image uncorrupted status value "no", and the value of the first image error count variable is cleared to zero.
[0043] Methods for detecting RW partition corruption can include (1) checking the kernel log dmsg, because when the RW partition is abnormal, the kernel will print corresponding error messages, such as node read error (most common), garbage collection (GC) failure, file system conversion to read-only mode, space exhaustion, etc.; (2) checking the number of error correction codes (ECC) and bad blocks; (3) checking the remaining RW partition space to confirm whether space is critical. This achieves fast and accurate detection of RW partition corruption.
[0044] S209: Switch to the backup image for booting.
[0045] When the updated error count variable value of the first image is greater than or equal to the preset value, it indicates that the randomness of the primary image startup failure has been largely eliminated, and the system switches to the backup image for startup. By setting the image error count variable value to record the number of times the image attempts to start, an image startup failure is only indicated when the image error count variable value exceeds the preset value. This largely eliminates the randomness of the primary image startup failure and improves the accuracy of judging the image startup status.
[0046] S210: When it is determined that the backup image has failed to boot, the read / write partition of the primary image is erased.
[0047] After switching to the backup image for booting, the values of the second image corruption variables can be checked. If a corruption variable value is detected, the backup image booting is considered abnormal. When the backup image booting is determined to be abnormal, the read / write partitions of the primary image are erased.
[0048] S211: Clear the value of the first image error count variable to zero, and keep the value of the first image damage variable as the image damage status value.
[0049] After erasing the read / write partitions of the primary image, the error count variable of the first image is cleared to zero, while the value of the first image corruption variable remains the image corruption status value.
[0050] S212: Erase the read / write partition of the backup image, clear the error count variable value of the second image corresponding to the backup image to zero, and keep the second image damage variable value corresponding to the backup image as the image damage status value.
[0051] After clearing the error count variable of the first image to zero and keeping the first image damage variable value as the image damage status value, the read / write partition of the backup image is erased, and the error count variable of the second image corresponding to the backup image is cleared to zero and the second image damage variable value corresponding to the backup image is kept as the image damage status value.
[0052] S213: Set the read / write partition clear variable value to true and boot from the master image.
[0053] After clearing the error count variable for the second image corresponding to the standby image to zero, and keeping the second image corruption variable value for the standby image at the image corruption status value, the read / write partition clear variable value (clearRW) is set to true. For example, clearRW can be set to 1, and then the system boots from the primary image. By erasing the read / write partitions of both the primary and standby images when both the primary and standby images fail to boot, setting the read / write partition clear variable value to true, and booting from the primary image, basic automatic repair is achieved, improving operational efficiency and BMC reliability.
[0054] S214: Determine if the main image has started normally. If yes, proceed to step S215; otherwise, proceed to step S216.
[0055] After booting from the primary image, determine whether the primary image boots normally. If it does, the primary repair is successful, and proceed to step S215. If not, the primary image still boots abnormally after the primary repair, and proceed to step S216.
[0056] S215: Set the value of the read / write partition clear variable to false to confirm that the primary repair was successful.
[0057] Once the primary image is confirmed to be booting normally, set the value of the read / write partition clear variable to false, such as setting clearRW to 0, to confirm that the primary repair was successful.
[0058] S216: Boot from the backup image.
[0059] If the primary image fails to boot, it indicates that the primary image still fails to boot after the initial repair, and the system will boot from the backup image. By setting the read / write partition clear variable to false when the primary image boots normally, the initial automatic repair is confirmed to be successful, improving operational efficiency and BMC reliability.
[0060] S217: Determine whether the backup image has started normally. If yes, return to step S215; otherwise, proceed to step S218.
[0061] After booting from the backup image, determine whether the backup image boots normally. If it does, set the value of the read / write partition clear variable to false to confirm that the primary repair was successful. If not, it means that the primary repair failed and proceed to step S218.
[0062] For example, if clearRW is 1, Image1ErrCnt ≥3, Image2ErrCnt ≥3, Image1Damage is "yes", and Image2Damage is "yes", it indicates that the initial repair has failed.
[0063] S218: Perform image re-burning.
[0064] When it is determined that the backup image fails to boot, it indicates that the initial repair has failed. The image is then re-burned, thus achieving automatic repair for different scenarios of image corruption.
[0065] In one specific embodiment of this application, step S218 may include the following steps: Step 1: Download the new image to the preset memory address from the preset Simple File Transfer Protocol server, which belongs to the same network segment as the primary and backup images; Step 2: Read the new image from the preset memory address, write the new image to the first flash memory corresponding to the master image, and boot from the new image in the first flash memory.
[0066] For ease of description, the two steps above can be combined for explanation.
[0067] The new image is pre-stored on a pre-defined Trivial File Transfer Protocol (TFTP) server located on the same network segment as the primary and backup images. For example, the Internet Protocol (IP) of the TFTP server is set to xx.xx.xx.100. After the initial repair fails, the new image is downloaded from the pre-defined TFTP server on the same network segment as the primary and backup images to a pre-defined memory address. The new image is then read from the pre-defined memory address and written to the first flash memory corresponding to the primary image. The system then boots from the new image in the first flash memory.
[0068] In one specific embodiment of this application, after booting from a new image in the first flash memory, the method may further include the following steps: When booting is complete, the new image will be synchronized from the first flash memory to the second flash memory corresponding to the backup image.
[0069] After booting from the new image in the first flash memory, once booting is complete, it indicates that BMC can boot based on the new image and synchronize the new image from the first flash memory to the second flash memory corresponding to the backup image. This allows for the upgrade and repair of both images even in the event of complete failure, achieving a complete automatic upgrade and repair even in the extremely dire situation where both BMC images are severely damaged.
[0070] The embodiments of this application largely solve the problems of abnormal startup, operation and corruption of BMC images, and perform self-repair and self-upgrade. There is no need for maintenance personnel to analyze and replace BMC boards on-site, which greatly ensures the reliability of BMC, ensures the stable operation of out-of-band management and monitoring of the server, and also greatly reduces maintenance costs and improves maintenance efficiency.
[0071] In one specific embodiment of this application, after step S209, the method may further include the following steps: Step 1: When the backup image starts normally, set the value of the second image corruption variable corresponding to the backup image to the image undamaged status value, and clear the value of the second image error count variable corresponding to the backup image to zero; Step 2: Synchronize all image partitions of the backup image to the primary image; Step 3: Set the value of the first image damage variable to the value of the image undamaged state, and clear the value of the first image error count variable to zero.
[0072] For ease of description, the three steps above can be combined for explanation.
[0073] After determining that BMC failed to boot from the primary image, when the backup image boots normally, the value of the second image corruption variable corresponding to the backup image is set to the image undamaged status value, the value of the second image error count variable corresponding to the backup image is cleared to zero, all image partitions of the backup image are synchronized to the primary image, the value of the first image corruption variable is set to the image undamaged status value, and the value of the first image error count variable is cleared to zero.
[0074] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods according to the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method.
[0075] Embodiments of this application also provide a mirror switching device.
[0076] See Figure 3 , Figure 3 This application provides a structural block diagram of a mirror switching device, which may include: The first image corruption variable value acquisition module 31 is used to acquire the first image corruption variable value corresponding to the main image during the bootloader loading stage when booting from the main image. The image damage status value conversion module 32 is used to convert the first image damage variable value from the image undamaged status value to the image damage status value when the first image damage variable value is the image undamaged status value. The first image corruption variable value detection module 33 is used to perform kernel stage and application space stage startup and read / write partition verification, and to detect the first image corruption variable value; The backup image switching module 34 is used to switch to the backup image for startup when the detection result shows that the first image is corrupted and the variable value remains corrupted.
[0077] This application addresses the issue of abnormal boot status of the primary image by setting a first image corruption variable value. During the bootloader loading phase, if the first image corruption variable value is determined to be the image undamaged state, it is converted from the undamaged state to the corrupted state value. Kernel and application space boot processes and read / write partition verification are then performed. Based on the state of the first image corruption variable value, the boot status of the kernel and application space stages and the read / write partition verification results are identified. If either the kernel or application space stage experiences a boot anomaly, or the read / write partition verification result indicates image corruption, the first image corruption variable value remains unchanged, indicating a boot anomaly in the primary image, and the system switches to a backup image. This achieves accurate and rapid identification of BMC image anomalies caused by fatal errors in the kernel or applications. In scenarios of boot anomalies or image corruption, the primary BMC image automatically switches to a backup image. Therefore, it solves the technical problem of failing to identify BMC image anomalies caused by fatal errors in the kernel or applications, significantly improving the reliability of the BMC firmware and addressing issues of abnormal boot, operation, and corruption.
[0078] In one specific embodiment of this application, the backup mirror switching module 34 may include: The first image error count variable value update submodule is used to update the first image error count variable value corresponding to the main image; The judgment submodule is used to determine whether the updated value of the first image error count variable is greater than or equal to the preset value; The standby image switching submodule is used to switch to the standby image for startup when the error count variable value of the first image obtained from the update is greater than or equal to a preset value. The repeat execution submodule is used to restart the main image when the error count variable value of the first image obtained from the update is less than the preset value, and to repeatedly execute the steps of kernel stage and application space stage startup and read / write partition verification.
[0079] In one specific embodiment of this application, the device may further include: The first zeroing module is used to set the value of the second image corruption variable corresponding to the backup image to the image undamaged status value after switching to the backup image for booting, and to clear the value of the second image error count variable corresponding to the backup image to zero when the backup image boots normally. The first image synchronization module is used to synchronize each image partition of the backup image to the main image. The second zeroing module is used to set the value of the first image damage variable to the value of the image undamaged state, and to clear the value of the first image error count variable to zero.
[0080] In one specific embodiment of this application, the device may further include: The primary image read / write partition erasure module is used to erase the primary image's read / write partitions when the boot failure of the backup image is determined after switching to the backup image for booting. The first image damage status value holding module is used to clear the first image error count variable value to zero and keep the first image damage variable value as the image damage status value. The second image damage status value retention module is used to erase the read and write partitions of the backup image, clear the error count variable value of the second image corresponding to the backup image to zero, and keep the second image damage variable value corresponding to the backup image as the image damage status value. The main image boot module is used to set the read / write partition clear variable value to true and boot from the main image.
[0081] In one specific embodiment of this application, the device may further include: The first judgment module is used to determine whether the main image has started normally after the read / write partition clear variable value is set to true and the main image is started. The first primary repair success confirmation module is used to set the read / write partition clear variable value to false when it is determined that the main image has started normally, thus confirming that the primary repair has been successful. The backup image boot module is used to boot from the backup image when the main image is found to be booting abnormally.
[0082] In one specific embodiment of this application, the device may further include: The second judgment module is used to determine whether the backup image has started normally after booting from the backup image; The repeat execution module is used to repeatedly execute the steps of setting the read / write partition clear variable value to false to confirm that the initial repair was successful when it is determined that the backup image has started normally. The re-burning module is used to re-burn the image when it is determined that the backup image has failed to boot.
[0083] In one specific embodiment of this application, the reprogramming module may include: The image download submodule is used to download new images from a preset Simple File Transfer Protocol server that belongs to the same network segment as the main image and the backup image to a preset memory address; The new image boot submodule is used to read a new image from a preset memory address, write the new image to the first flash memory corresponding to the main image, and boot from the new image in the first flash memory.
[0084] In one specific embodiment of this application, the device may further include: The second image synchronization module is used to synchronize the new image from the first flash memory to the second flash memory corresponding to the backup image after the boot process is complete.
[0085] In one specific embodiment of this application, the device may further include: The module for determining normal startup of the main image is used to determine that the main image has started normally when the detection result after detecting the value of the first image's damaged variable changes from a damaged state value to an undamaged state value. The third zeroing module is used to clear the value of the first image error count variable corresponding to the main image; where normal startup of the main image includes normal restart; the value of the first image error count variable is used to record the number of times the main image has abnormal startup.
[0086] For a description of the features in the embodiment corresponding to the mirror switching device, please refer to the relevant description of the embodiment corresponding to the mirror switching method, which will not be repeated here.
[0087] Embodiments of this application also provide an electronic device, including a memory and a processor, wherein the memory stores a computer program and the processor is configured to run the computer program to perform the steps in any of the above-described mirror switching method embodiments.
[0088] Embodiments of this application also provide a computer-readable storage medium storing a computer program, wherein the computer program is configured to execute the steps in any of the above-described mirror switching method embodiments when it runs.
[0089] In one exemplary embodiment, the aforementioned computer-readable storage medium may include, but is not limited to, various media capable of storing computer programs, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard disk, magnetic disk, or optical disk.
[0090] Embodiments of this application also provide a computer program product, which includes a computer program that, when executed by a processor, implements the steps in any of the above-described mirror switching method embodiments.
[0091] Embodiments of this application also provide another computer program product, including a non-volatile computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps in any of the above-described mirror switching method embodiments.
[0092] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0093] The mirror switching method and electronic device provided in this application have been described in detail above. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the embodiments above are only intended to help understand the method and core ideas of this application. It should be noted that those skilled in the art can make several improvements and modifications to this application without departing from the principles of this application, and these improvements and modifications also fall within the protection scope of this application.
Claims
1. A mirror switching method, characterized by, include: When booting from the master image, the value of the first image corruption variable corresponding to the master image is obtained during the bootloader loading phase; When the value of the first image damage variable is the image undamaged state value, the value of the first image damage variable is changed from the image undamaged state value to the image damage state value; Perform kernel and application space stage startup and read / write partition verification, and detect the corrupted variable values of the first image; When the detection result indicates that the value of the first image damage variable remains the same as the image damage state value, switch to the backup image for startup. After detecting the corrupted variable value of the first image, the process also includes: If there is no damage, the value of the first image damage variable changes from the image damage status value to the image undamaged status value; When the detection result shows that the value of the first image damage variable changes from the image damage status value to the image undamaged status value, it is determined that the main image starts normally. The error count variable value corresponding to the main image is cleared to zero; wherein, the normal startup of the main image includes normal restart after retry; the error count variable value of the first image is used to record the number of times the main image has abnormal startup.
2. The mirror switching method according to claim 1, characterized by, Switching to the backup image for booting includes: Update the error count variable value of the first image corresponding to the main image; Determine whether the updated first image error count variable value is greater than or equal to the preset value; If so, switch to the backup image for booting; If not, the main image is restarted, and the steps of performing kernel stage and application space stage startup and read / write partition verification are repeated.
3. The mirror switching method according to claim 2, wherein After switching to the backup image for booting, the following is also included: When the backup image starts normally, the value of the second image damage variable corresponding to the backup image is set to the value of the image not being damaged, and the value of the second image error count variable corresponding to the backup image is cleared to zero; Synchronize all image partitions of the backup image to the primary image; Set the value of the first image damage variable to the value of the image undamaged state, and clear the value of the first image error count variable to zero.
4. The mirror switching method according to claim 2 or 3, characterized in that, After switching to the backup image for booting, the following is also included: When it is determined that the backup image has an abnormal startup, the read / write partition of the primary image is erased; Clear the value of the first image error count variable to zero, and keep the value of the first image damage variable at the value of the image damage status; The read / write partition of the backup image is erased, and the error count variable value of the second image corresponding to the backup image is cleared to zero, while the damage variable value of the second image corresponding to the backup image is kept at the image damage status value; Set the read / write partition clear variable value to true and boot from the master image.
5. The mirror switching method according to claim 4, characterized in that, After setting the read / write partition clear variable to true and booting from the master image, the process also includes: Determine whether the main image has started normally; If so, set the value of the read / write partition clear variable to false to confirm that the initial repair was successful; If not, then boot from the backup image.
6. The mirror switching method according to claim 5, characterized in that, After booting from the backup image, the following is also included: Determine whether the backup image has started normally; If so, then execute the step of setting the value of the read / write partition clear variable to false to confirm that the initial repair was successful; If not, then re-flash the image.
7. The mirror switching method according to claim 6, characterized in that, Perform image re-burning, including: Download the new image to the preset memory address from a preset Simple File Transfer Protocol server that belongs to the same network segment as the primary image and the backup image; The new image is read from the preset memory address and written into the first flash memory corresponding to the master image, and the system boots from the new image in the first flash memory.
8. The mirror switching method according to claim 7, characterized in that, After booting from the new image in the first flash memory, the following is also included: When the boot process is complete, the new image will be synchronized from the first flash memory to the second flash memory corresponding to the backup image.
9. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor, configured to implement the steps of the mirror switching method as described in any one of claims 1 to 8 when executing the computer program.