Abnormal startup processing method and apparatus for operating system, and device, medium and program
Patent Information
- Application Number
- PCT/CN2025/144289
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2025-02-26
- Filing Date
- 2025-12-22
- Publication Date
- 2026-09-03
Smart Images

Figure CN2025144289_03092026_PF_FP_ABST
Abstract
Description
A method, apparatus, device, medium, and program for handling operating system startup exceptions. Technical Field
[0001] This invention relates to the field of computer technology, and more specifically to a method, apparatus, device, medium, and program for handling operating system startup exceptions. Background Technology
[0002] The external initramfs file system is an initial RAM file system that serves as a temporary carrier for the root file system during the operating system's boot process. In domestically produced operating systems, the kernel boot process relies on the external initramfs file to load necessary drivers and perform initialization operations. Decompressing the external initramfs file is a critical step in the boot process; however, during loading, decompression may fail for various reasons, thus affecting the normal system startup.
[0003] Existing exception handling mechanisms typically rely on a tedious process of troubleshooting each case after an external initramfs file decompression failure is detected. Because the root cause of the exception is difficult to determine quickly, the allocation and handling of exceptions are inefficient. This not only prolongs problem-solving time but also increases the complexity of system maintenance, ultimately impacting normal system operation and user experience. Furthermore, current systems rely too heavily on system restarts after external initramfs file decompression failures, lacking automated recovery mechanisms. This leads to even longer system downtime and increases maintenance costs. Technical issues
[0004] Therefore, when the decompression of an external initramfs file fails, how to quickly and accurately locate the cause of the exception, assign the decompression failure to the appropriate handling object, and enhance the system's recovery capability through an effective recovery mechanism has become an urgent technical problem to be solved. Technical solutions
[0005] Therefore, it is necessary to provide an operating system startup exception handling method to address the above-mentioned technical problems, so as to quickly and accurately locate the cause of compression failure when the compression of external initramfs files fails.
[0006] In a first aspect, the present invention provides an operating system startup exception handling method, the method comprising:
[0007] When the operating system starts, the bootloader loads the external initramfs file into memory and passes the starting address of the external initramfs file to the operating system kernel;
[0008] The hash value of the external initramfs file is obtained by executing a hash verification function.
[0009] The operating system kernel decompresses the external initramfs file into the root file system based on the starting address;
[0010] Once it is determined that the external initramfs file cannot be decompressed normally, the reason for the decompression failure is determined by comparing the hash value of the external initramfs file with the expected hash value.
[0011] Based on the reason for the decompression failure, the decompression failure issue will be reported to the corresponding handling object.
[0012] In one embodiment, the hash verification function includes a first processing function, a second processing function, and a third processing function; the hash verification function performs hash verification on the external initramfs file to obtain the hash value of the external initramfs file, including:
[0013] A hash transformation object is created by executing the first processing function; the hash transformation object includes computation-related functions and metadata.
[0014] By executing the second processing function, a hash descriptor structure is created, and the hash descriptor structure is bound to the hash transformation object;
[0015] By executing the third processing function, the metadata and external initramfs file data are input into the calculation-related function in the hash descriptor structure to calculate the hash value of the external initramfs file;
[0016] After the calculation is complete, release the hash transformation object and the hash descriptor structure.
[0017] In one embodiment, determining that the external initramfs file cannot be properly decompressed includes:
[0018] Before the operating system kernel decompresses the external initramfs file for the first time, the decompression counter is initialized to 0, and the decompression count is incremented by 1 each time the operating system kernel decompresses the external initramfs file.
[0019] When the operating system kernel fails to decompress an external initramfs file, it determines whether it is unable to decompress the external initramfs file normally by comparing the recorded number of decompression attempts with the preset number of decompression attempts.
[0020] In one embodiment, determining whether an external initramfs file cannot be decompressed normally is based on the relationship between the recorded number of decompressions and a preset number of decompressions, including:
[0021] If the recorded number of decompressions is less than the preset number of decompressions, then the external initramfs file will be decompressed again;
[0022] If the recorded number of decompressions equals the preset number of decompressions, then it is determined that the external initramfs file cannot be decompressed normally.
[0023] In one embodiment, the reason for decompression failure is determined based on a comparison between the hash value of the external initramfs file and the expected hash value, including:
[0024] If the hash value of the external initramfs file is inconsistent with the expected hash value, then the reason for the decompression failure is that the external initramfs file is corrupted.
[0025] If the hash value of the external nitramfs file matches the expected hash value, then the decompression failure is due to an abnormality in the operating system kernel startup process.
[0026] In one embodiment, based on the reason for decompression failure, the decompression failure is reported to the corresponding processing object, including:
[0027] If the decompression failure is determined to be due to a corrupted external initramfs file, the decompression failure issue will be reported to the first processing object.
[0028] If the decompression failure is determined to be due to an abnormality in the operating system kernel startup process, the decompression failure issue will be reported to the second processing object.
[0029] Secondly, the present invention also provides an operating system startup exception handling device, the device comprising:
[0030] The loading module is used by the bootloader to load the external initramfs file into memory when the operating system starts, and to pass the starting address of the external initramfs file to the operating system kernel.
[0031] The hash verification module is used to perform hash verification on external initramfs files by executing a hash verification function to obtain the hash value of the external initramfs files;
[0032] The decompression module is used by the operating system kernel to decompress external initramfs files into the root file system based on the starting address;
[0033] The determination module is used to determine the reason for decompression failure when it is determined that the external initramfs file cannot be decompressed normally, based on the comparison result between the hash value of the external initramfs file and the expected hash value;
[0034] The reporting module is used to report decompression failure issues to the corresponding processing objects based on the reason for the decompression failure.
[0035] Thirdly, the present invention also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to perform the following steps:
[0036] When the operating system starts, the bootloader loads the external initramfs file into memory and passes the starting address of the external initramfs file to the operating system kernel;
[0037] The hash value of the external initramfs file is obtained by executing a hash verification function.
[0038] The operating system kernel decompresses the external initramfs file into the root file system based on the starting address;
[0039] Once it is determined that the external initramfs file cannot be decompressed normally, the reason for the decompression failure is determined by comparing the hash value of the external initramfs file with the expected hash value.
[0040] Based on the reason for the decompression failure, the decompression failure issue will be reported to the corresponding handling object.
[0041] Fourthly, the present invention also provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, performs the following steps:
[0042] When the operating system starts, the bootloader loads the external initramfs file into memory and passes the starting address of the external initramfs file to the operating system kernel;
[0043] The hash value of the external initramfs file is obtained by executing a hash verification function.
[0044] The operating system kernel decompresses the external initramfs file into the root file system based on the starting address;
[0045] Once it is determined that the external initramfs file cannot be decompressed normally, the reason for the decompression failure is determined by comparing the hash value of the external initramfs file with the expected hash value.
[0046] Based on the reason for the decompression failure, the decompression failure issue will be reported to the corresponding handling object.
[0047] Fifthly, the present invention also provides a computer program product, including a computer program that, when executed by a processor, performs the following steps:
[0048] When the operating system starts, the bootloader loads the external initramfs file into memory and passes the starting address of the external initramfs file to the operating system kernel;
[0049] The hash value of the external initramfs file is obtained by executing a hash verification function.
[0050] The operating system kernel decompresses the external initramfs file into the root file system based on the starting address;
[0051] Once it is determined that the external initramfs file cannot be decompressed normally, the reason for the decompression failure is determined by comparing the hash value of the external initramfs file with the expected hash value.
[0052] Based on the reason for the decompression failure, the decompression failure issue will be reported to the corresponding handling object.
[0053] The aforementioned operating system startup exception handling method, device, equipment, medium, and program, during operating system startup, loads the external initramfs file into memory and passes the starting address of the external initramfs file to the operating system kernel. A hash verification function is executed to perform a hash check on the external initramfs file, obtaining its hash value, which is subsequently used to determine the cause of decompression failure. The operating system kernel decompresses the external initramfs file to the root file system based on the starting address. When it is determined that the external initramfs file cannot be decompressed normally, the cause of decompression failure is determined by comparing the hash value of the external initramfs file with the expected hash value, replacing manual troubleshooting and enabling rapid and accurate location of the cause of decompression failure. Based on the cause of decompression failure, the problem is reported to the corresponding processing object, thereby addressing the decompression failure problem specifically and avoiding resource waste. Attached Figure Description
[0054] To more clearly illustrate the technical solutions in the embodiments of the present invention or related technologies, the drawings used in the description of the embodiments of the present invention or related technologies will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0055] Figure 1 is a flowchart illustrating an operating system startup exception handling method in one embodiment. The best embodiment of the present invention
[0056] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Many specific details are set forth in the following description to provide a thorough understanding of the present invention. However, the present invention may also be implemented in other ways different from those described herein. Those skilled in the art can make similar extensions without departing from the spirit of the present invention. Therefore, the present invention is not limited to the specific embodiments disclosed below.
[0057] In an optional embodiment, as shown in FIG1, an operating system startup exception handling method is provided. In this embodiment, the method includes the following steps:
[0058] S110: When the operating system starts, the bootloader loads the external initramfs file into memory and passes the starting address of the external initramfs file to the operating system kernel.
[0059] The operating system can be Linux, etc. The loader can be BIOS (Basic Input / Output System), etc. The starting address of the external initramfs file can be allocated according to the operating system configuration and boot settings.
[0060] S120 performs a hash check on the external initramfs file by executing a hash check function to obtain the hash value of the external initramfs file.
[0061] The hash value, also known as a hash table, is a unique numerical value obtained by calculating data. The hash verification function can be understood as a function used to obtain the hash value of an external initramfs file. Optionally, the hash verification function can include a first processing function, a second processing function, and a third processing function. The first processing function can be the `crypto_alloc_shash` function; the second processing function can be the `kzalloc` function; and the third processing function can be the `crypto_shash_digest` function.
[0062] In one alternative embodiment, the method for obtaining the hash value of an external initramfs file may include the following steps:
[0063] S121, Create a hash transformation object by executing the first processing function;
[0064] In this context, a hash transformation object can be understood as an abstract object of a hash algorithm. A hash transformation object can include computation-related functions and metadata. Furthermore, computation-related functions can be understood as functions used to calculate the hash value, such as SHA-1 (Secure Hash Algorithm 1, etc.). Metadata can be understood as parameters involved in calculating the hash value.
[0065] S122, by executing the second processing function, a hash descriptor structure is created and the hash descriptor structure is bound to the hash transformation object.
[0066] The hash descriptor structure can be understood as a temporary workspace used for hash calculations. The hash descriptor structure stores the context information for the hash calculations.
[0067] S123, by executing the third processing function, in the hash descriptor structure, the metadata and external initramfs file data are input into the calculation related function to calculate the hash value of the external initramfs file.
[0068] For example, external initramfs file data in memory can be loaded through a third processing function, and the metadata and external initramfs file data can be input as parameters into the calculation-related function to calculate the hash value of the external initramfs file.
[0069] S124, after the calculation is complete, release the hash transformation object and the hash descriptor structure.
[0070] Understandably, memory leaks can be prevented by releasing the hash transformation object and the hash descriptor structure.
[0071] S130: The operating system kernel decompresses the external initramfs file into the root file system based on the starting address.
[0072] The root file system can be understood as the first file system mounted when the operating system boots up, providing the basic environment required for the operating system to run. Optionally, the root file system can be a Rootfs system, which may include the core components and user-space programs necessary for the operating system to boot.
[0073] S140. After determining that the external initramfs file cannot be decompressed normally, the reason for the decompression failure is determined by comparing the hash value of the external initramfs file with the expected hash value.
[0074] The expected hash value can be understood as a reference value for the hash value of the external initramfs file.
[0075] In one alternative embodiment, the method for determining whether an external initramfs file cannot be properly decompressed may include the following steps:
[0076] S141: Before the operating system kernel decompresses the external initramfs file for the first time, the number of decompressions recorded in the decompression counter is initialized to 0, and the number of decompressions recorded is incremented by 1 each time the operating system kernel decompresses the external initramfs file.
[0077] The decompression counter can be understood as a built-in counter of the operating system, used to record the number of times the operating system kernel decompresses the external initramfs file during a single operating system startup process.
[0078] S142, when the operating system kernel fails to decompress the external initramfs file, determine whether it is impossible to decompress the external initramfs file normally based on the relationship between the recorded number of decompressions and the preset number of decompressions.
[0079] The preset number of decompressions can be understood as the upper limit of the number of times the operating system can decompress external initramfs files.
[0080] Optionally, if the recorded number of decompressions is less than the preset number of decompressions, the external initramfs file will be decompressed again; if the recorded number of decompressions is equal to the preset number of decompressions, it will be determined that the external initramfs file cannot be decompressed normally.
[0081] Understandably, re-extracting external files is more efficient than restarting the system. However, when the recorded number of decompressions equals the preset number, it indicates that re-extracting is no longer sufficient to resolve the issue of external initramfs file decompression failure, thus confirming that the external initramfs file cannot be decompressed normally.
[0082] In another alternative embodiment, if the hash value of the external initramfs file is inconsistent with the expected hash value, the reason for the decompression failure is determined to be that the external initramfs file is corrupted; if the hash value of the external initramfs file is consistent with the expected hash value, the reason for the decompression failure is determined to be that the operating system kernel boot process is abnormal.
[0083] Understandably, since the same data will produce the same hash value, when the hash value of the external initramfs file is inconsistent with the expected hash value, it indicates that the data in the external initramfs file changed before decompression. Therefore, it can be determined that the decompression failure is due to a corrupted external initramfs file. For example, the external initramfs file may be corrupted when the BIOS loads the external file into memory. Conversely, when the hash value of the external initramfs file is consistent with the expected hash value, it indicates that the external initramfs file was not corrupted before decompression. In other words, the decompression failure is unrelated to the external initramfs file itself, and therefore, it can be determined that the decompression failure is due to an abnormal kernel boot process.
[0084] S150, based on the reason for the decompression failure, report the decompression failure to the corresponding processing object.
[0085] Optionally, the processing target can be a pre-defined processing program or a processing user. For example, in a scenario where the processing target is a processing user, the following logic can be used to report decompression failures:
[0086] If the decompression failure is determined to be due to a corrupted external initramfs file, the decompression failure issue will be reported to the first processing object.
[0087] If the decompression failure is determined to be due to an abnormality in the operating system kernel startup process, the decompression failure issue will be reported to the second processing object.
[0088] The first processing target can be a firmware engineer, and the second processing target can be an operating system kernel engineer. By reporting decompression failures caused by different reasons to the appropriate processing target, the efficiency of resolving decompression failures can be improved, and resource waste can be avoided.
[0089] In this embodiment, when the operating system starts, the bootloader loads the external initramfs file into memory and passes the starting address of the external initramfs file to the operating system kernel. A hash verification function is executed to perform a hash check on the external initramfs file, obtaining its hash value, which is then used as the basis for determining the cause of decompression failure. The operating system kernel decompresses the external initramfs file to the root file system based on the starting address. When it is determined that the external initramfs file cannot be decompressed normally, the cause of decompression failure is determined by comparing the hash value of the external initramfs file with the expected hash value. This replaces the manual troubleshooting method and can quickly and accurately locate the cause of decompression failure. Based on the cause of decompression failure, the problem is reported to the corresponding processing object, thereby addressing the decompression failure problem specifically and avoiding resource waste.
[0090] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.
[0091] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this invention.
[0092] The embodiments described above are merely illustrative of several implementations of the present invention, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of the present invention. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of the present invention, and these modifications and improvements all fall within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the appended claims.
Claims
1. A method for handling operating system startup exceptions, characterized in that, The method includes: When the operating system starts, the bootloader loads the external initramfs file into memory and passes the starting address of the external initramfs file to the operating system kernel; The hash value of the external initramfs file is obtained by executing a hash verification function. The operating system kernel decompresses the external initramfs file into the root file system based on the starting address; Once it is determined that the external initramfs file cannot be decompressed normally, the reason for the decompression failure is determined by comparing the hash value of the external initramfs file with the expected hash value. This determination includes: if the hash value of the external initramfs file is inconsistent with the expected hash value, the reason for the decompression failure is determined to be that the external initramfs file is corrupted; if the hash value of the external initramfs file is consistent with the expected hash value, the reason for the decompression failure is determined to be an abnormality in the operating system kernel boot process. Based on the reason for the decompression failure, the decompression failure issue will be reported to the corresponding processing object.
2. The method according to claim 1, characterized in that, The hash verification function includes a first processing function, a second processing function, and a third processing function; the step of performing hash verification on the external initramfs file by executing the hash verification function to obtain the hash value of the external initramfs file includes: A hash transformation object is created by executing a first processing function; the hash transformation object includes computation-related functions and metadata. By executing the second processing function, a hash descriptor structure is created, and the hash descriptor structure is bound to the hash transformation object; By executing the third processing function, the metadata and external initramfs file data are input into the calculation-related function in the hash descriptor structure to calculate the hash value of the external initramfs file; After the calculation is complete, release the hash transformation object and the hash descriptor structure.
3. The method according to claim 1, characterized in that, The determination that the external initramfs file cannot be decompressed normally includes: Before the operating system kernel decompresses the external initramfs file for the first time, the number of decompressions recorded in the decompression counter is initialized to 0, and the number of decompressions is incremented by 1 each time the operating system kernel decompresses the external initramfs file; When the operating system kernel fails to decompress an external initramfs file, it determines whether it is unable to decompress the external initramfs file normally by comparing the recorded number of decompression attempts with the preset number of decompression attempts.
4. The method according to claim 3, characterized in that, The step of determining whether an external initramfs file cannot be decompressed normally based on the relationship between the recorded number of decompressions and the preset number of decompressions includes: If the recorded number of decompressions is less than the preset number of decompressions, then the external initramfs file will be decompressed again; If the recorded number of decompressions equals the preset number of decompressions, then it is determined that the external initramfs file cannot be decompressed normally.
5. The method according to claim 1, characterized in that, The step of reporting the decompression failure to the corresponding processing object based on the reason for the decompression failure includes: If the decompression failure is determined to be due to a corrupted external initramfs file, the decompression failure issue will be reported to the first processing object. If the decompression failure is determined to be due to an abnormality in the operating system kernel startup process, the decompression failure issue will be reported to the second processing object.
6. An operating system startup exception handling device, characterized in that, The device includes: The loading module is used by the bootloader to load the external initramfs file into memory when the operating system starts, and to pass the starting address of the external initramfs file to the operating system kernel. The hash verification module is used to perform hash verification on external initramfs files by executing a hash verification function to obtain the hash value of the external initramfs files; The decompression module is used by the operating system kernel to decompress the external initramfs file into the root file system according to the starting address; The determination module is used to determine the cause of decompression failure when it is determined that the external initramfs file cannot be decompressed normally, based on a comparison between the hash value of the external initramfs file and the expected hash value. The determination of the cause of decompression failure based on the comparison between the hash value of the external initramfs file and the expected hash value includes: if the hash value of the external initramfs file is inconsistent with the expected hash value, the cause of decompression failure is determined to be that the external initramfs file is corrupted; if the hash value of the external initramfs file is consistent with the expected hash value, the cause of decompression failure is determined to be an abnormality in the operating system kernel boot process. The reporting module is used to report the decompression failure to the corresponding processing object based on the reason for the decompression failure.
7. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 5.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 5.
9. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 5.