A method, device, equipment, medium and program for handling abnormal startup of an operating system
By hashing the external initramfs file at the start of the operating system and determining the cause based on the hash value of the decompression failure, the problem of inefficient decompression of the external initramfs file at the start of the operating system is solved, and fast and accurate fault location and automated recovery are achieved.
Patent Information
- Application Number
- CN202510213090.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-26
- Publication Date
- 2025-06-10
- Estimated Expiration
- 2045-02-26
AI Technical Summary
During the operating system startup process, when the external initramfs file decompression fails, the existing technology is difficult to quickly and accurately locate the causes of abnormalities, resulting in inefficient processing, complex system maintenance, and lack of an automated recovery mechanism, which increases system downtime and maintenance costs.
When the operating system is started, the external initramfs file is loaded through the boot loader and the hash check function is executed to obtain the hash value of the file. After decompression fails, determine the reason for decompression failure based on the comparison result of the hash value and the expected hash value, and report the problem to the corresponding processing object.
It realizes the rapid and accurate positioning of the causes of the decompression failure of external initramfs files, avoids the dependence of manual inspection, improves processing efficiency, and reduces system downtime and maintenance costs.
Smart Images

Figure CN119690733B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and particularly to a method, device, equipment, medium and program for handling abnormal startup of an operating system. Background Art
[0002] The external Initramfs file system is an Initial RAM File System, which is used as a temporary carrier of the root file system during the startup process of the operating system. In domestic operating systems, the startup process of the operating system kernel depends on external initramfs files to load necessary drivers and perform initialization operations. The decompression of the external initramfs file is a key link in the startup process. However, during the loading process, due to various reasons, the decompression may fail, thus affecting the normal startup of the system.
[0003] After the existing abnormal handling mechanism discovers that the decompression of the external initramfs file fails, it usually relies on various human resources to check one by one. Since the root cause of the abnormality is difficult to quickly determine, the allocation and handling efficiency of the abnormality are low, which not only prolongs the time to solve the problem, but also increases the complexity of system maintenance, thereby affecting the normal operation of the system and user experience. In addition, currently, when the decompression of the external initramfs file fails, the system overly relies on restarting the system and lacks an automated recovery mechanism. This not only results in longer system downtime, but also increases the maintenance cost.
[0004] Therefore, when the decompression of the external initramfs file fails, how to quickly and accurately locate the cause of the abnormality, allocate the decompression failure problem to a reasonable handling object, and enhance the recovery ability of the system through an effective recovery mechanism has become a technical problem that needs to be solved urgently. Summary of the Invention
[0005] Based on this, in view of the above technical problems, it is necessary to provide a method for handling abnormal startup of an operating system to quickly and accurately locate the cause of compression failure when the compression of the external initramfs file fails.
[0006] In a first aspect, the present invention provides a method for handling abnormal startup of an operating system, the method comprising:
[0007] When the operating system starts up, the boot loader loads the external initramfs file into memory and passes the starting address of the external initramfs file to the operating system kernel;
[0008] By executing a hash check function, perform a hash check on the external initramfs file to obtain the hash value of the external initramfs file;
[0009] The operating system kernel decompresses the external initramfs file to the root file system according to the starting address;
[0010] When it is determined that the external initramfs file cannot be decompressed normally, the reason for the decompression failure is determined according to the comparison result between the hash value of the external initramfs file and the expected hash value;
[0011] According to the reason for the decompression failure, the decompression failure problem is reported to the corresponding processing object.
[0012] In one embodiment, the hash verification function includes a first processing function, a second processing function, and a third processing function; the external initramfs file is verified by the hash verification function to obtain the hash value of the external initramfs file, including:
[0013] By executing the first processing function, a hash transformation object is created; the hash transformation object includes calculation-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, in the hash descriptor structure, the metadata and the external initramfs file data are input into the calculation-related functions to calculate the hash value of the external initramfs file;
[0016] After the calculation is completed, the hash transformation object and the hash descriptor structure are released.
[0017] In one embodiment, determining that the external initramfs file cannot be decompressed normally includes:
[0018] Before the operating system kernel first decompresses the external initramfs file, the recorded decompression times in the decompression counter are initialized to 0, and each time the operating system kernel decompresses the external initramfs file, the recorded decompression times are incremented by 1;
[0019] When the operating system kernel fails to decompress the external initramfs file, it is determined whether the external initramfs file cannot be decompressed normally according to the relationship between the recorded decompression times and the preset decompression times.
[0020] In one embodiment, determining whether the external initramfs file cannot be decompressed normally according to the relationship between the recorded decompression times and the preset decompression times includes:
[0021] If the recorded decompression times are less than the preset decompression times, then decompress the external initramfs file again;
[0022] If the recorded decompression times are equal to the preset decompression times, then it is determined that the external initramfs file cannot be decompressed normally.
[0023] In one embodiment, according to the comparison result between the hash value of the external initramfs file and the expected hash value, the reason for decompression failure is determined, including:
[0024] If the hash value of the external initramfs file is inconsistent with the expected hash value, then it is determined that the reason for decompression failure is that the external initramfs file is corrupted;
[0025] If the hash value of the external nitramfs file is consistent with the expected hash value, then it is determined that the reason for decompression failure is an abnormal operating system kernel startup process.
[0026] In one embodiment, according to the reason for decompression failure, the decompression failure problem is reported to the corresponding processing object, including:
[0027] If it is determined that the reason for decompression failure is that the external initramfs file is corrupted, then the decompression failure problem is reported to the first processing object;
[0028] If it is determined that the reason for decompression failure is an abnormal operating system kernel startup process, then the decompression failure problem is reported to the second processing object.
[0029] In a second aspect, the present invention also provides an operating system startup exception handling device, and the device includes:
[0030] A loading module, configured to, when the operating system starts up, the boot loader loads the external initramfs file into the memory and passes the starting address of the external initramfs file to the operating system kernel;
[0031] A hash verification module, configured to perform a hash verification on the external initramfs file by executing a hash verification function to obtain the hash value of the external initramfs file;
[0032] A decompression module, configured to the operating system kernel decompresses the external initramfs file into the root file system according to the starting address;
[0033] A determination module, configured to, when it is determined that the external initramfs file cannot be decompressed normally, determine the reason for decompression failure according to the comparison result between the hash value of the external initramfs file and the expected hash value;
[0034] A reporting module, configured to report the decompression failure problem to the corresponding processing object according to the reason for decompression failure.
[0035] Thirdly, the present invention further provides a computer device, including a memory and a processor. The memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0036] When the operating system starts, the boot loader loads the external initramfs file into the memory and passes the starting address of the external initramfs file to the operating system kernel;
[0037] By executing a hash verification function, perform hash verification on the external initramfs file to obtain the hash value of the external initramfs file;
[0038] The operating system kernel decompresses the external initramfs file into the root file system according to the starting address;
[0039] When it is determined that the external initramfs file cannot be decompressed normally, determine the reason for decompression failure according to the comparison result between the hash value of the external initramfs file and the expected hash value;
[0040] Report the decompression failure problem to the corresponding processing object according to the reason for decompression failure.
[0041] Fourthly, the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the following steps are implemented:
[0042] When the operating system starts, the boot loader loads the external initramfs file into the memory and passes the starting address of the external initramfs file to the operating system kernel;
[0043] By executing a hash verification function, perform hash verification on the external initramfs file to obtain the hash value of the external initramfs file;
[0044] The operating system kernel decompresses the external initramfs file into the root file system according to the starting address;
[0045] When it is determined that the external initramfs file cannot be decompressed normally, determine the reason for decompression failure according to the comparison result between the hash value of the external initramfs file and the expected hash value;
[0046] Report the decompression failure problem to the corresponding processing object according to the reason for decompression failure.
[0047] Fifth aspect, the present invention further provides a computer program product, including a computer program which, when executed by a processor, implements the following steps:
[0048] When the operating system starts, the boot loader loads the external initramfs file into the memory and passes the starting address of the external initramfs file to the operating system kernel;
[0049] By executing a hash verification function, perform a hash verification on the external initramfs file to obtain the hash value of the external initramfs file;
[0050] The operating system kernel decompresses the external initramfs file into the root file system according to the starting address;
[0051] When it is determined that the external initramfs file cannot be decompressed normally, determine the reason for the decompression failure according to the comparison result between the hash value of the external initramfs file and the expected hash value;
[0052] According to the reason for the decompression failure, report the decompression failure problem to the corresponding processing object.
[0053] The above operating system startup exception handling method, device, equipment, medium and program, when the operating system starts, the boot loader loads the external initramfs file into the memory and passes the starting address of the external initramfs file to the operating system kernel; by executing a hash verification function, perform a hash verification on the external initramfs file to obtain the hash value of the external initramfs file, so as to use this hash value as the basis for determining the reason for the decompression failure in the future; the operating system kernel decompresses the external initramfs file into the root file system according to the starting address; when it is determined that the external initramfs file cannot be decompressed normally, determine the reason for the decompression failure according to the comparison result between the hash value of the external initramfs file and the expected hash value, replacing the way of manually checking the reason for the decompression failure, and can quickly and accurately locate the reason for the decompression failure; according to the reason for the decompression failure, report the decompression failure problem to the corresponding processing object, so as to handle the decompression failure problem targeted and avoid waste of resources. BRIEF DESCRIPTION OF THE DRAWINGS
[0054] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or related technologies, the following will briefly introduce the drawings required for describing the embodiments of the present invention or related technologies. Obviously, the drawings in the following description are only some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other related drawings can also be obtained based on these drawings.
[0055] Figure 1 It is a schematic flow chart of an operating system startup exception handling method in an embodiment. Specific implementation manners
[0056] Next, in combination with the accompanying drawings in the embodiments of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described. Many specific details are set forth in the following description in order to fully understand the present invention, but the present invention can also be implemented in other ways different from those described herein. Those skilled in the art can make similar promotions without departing from the connotation of the present invention. Therefore, the present invention is not limited by the specific embodiments disclosed below.
[0057] In an alternative embodiment, as Figure 1 shown, a method for handling operating system startup exceptions is provided. In this embodiment, the method includes the following steps:
[0058] S110, when the operating system starts up, 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] Among them, the operating system can be a Linux operating system or the like. The loader can be a BIOS (Basic Input / Output System, basic input and output system), etc. The starting address of the external initramfs file can be allocated according to the configuration and startup situation of the operating system.
[0060] S120, by executing a hash verification function, perform a hash verification on the external initramfs file to obtain the hash value of the external initramfs file.
[0061] Among them, the hash value (Hash Value) is also called a hash value, which refers to a unique numerical value obtained by calculating data. The hash verification function can be understood as a function for obtaining the hash value of the external initramfs file. Optionally, the hash verification function can include a first processing function, a second processing function, and a third processing function, etc. Among them, the first processing function can select the crypto_alloc_shash function; the second processing function can select the kzalloc function; the third processing function can select the crypto_shash_digest function.
[0062] In an alternative embodiment, the method for obtaining the hash value of the external initramfs file can include the following steps:
[0063] S121, by executing the first processing function, create a hash transformation object;
[0064] Among them, the hash transformation object can be understood as the abstract object of the hash algorithm. The hash transformation object may include calculation-related functions and metadata. Further, the calculation-related functions can be understood as functions used for hash value calculation, such as SHA-1 (Secure Hash Algorithm 1, etc.). The metadata can be understood as the parameters participating in the calculation of the hash value.
[0065] S122, by executing the second processing function, create a hash descriptor structure and bind the hash descriptor structure to the hash transformation object.
[0066] Among them, the hash descriptor structure can be understood as a temporary working space for hash calculation. In the hash descriptor structure, the context information of the hash calculation can be saved.
[0067] S123, by executing the third processing function, in the hash descriptor structure, input the metadata and the external initramfs file data into the calculation-related functions to calculate the hash value of the external initramfs file.
[0068] Exemplarily, the external initramfs file data in the memory can be loaded through the third processing function, and the metadata and the external initramfs file data are input as parameters into the calculation-related functions, thereby calculating the hash value of the external initramfs file.
[0069] S124, after the calculation is completed, release the hash transformation object and the hash descriptor structure.
[0070] It can be understood that by releasing the hash transformation object and the hash descriptor structure, memory leakage can be prevented.
[0071] S130, the operating system kernel decompresses the external initramfs file into the root file system according to the starting address.
[0072] Among them, the root file system can be understood as the file system that is first mounted when the operating system starts. The root file system can provide the basic environment required for the operation of the operating system. Optionally, the root file system can be a Rootfs system, and the Rootfs system may include the core components and user space programs necessary when the operating system starts.
[0073] S140, when it is determined that the external initramfs file cannot be decompressed normally, determine the reason for the decompression failure according to the comparison result between the hash value of the external initramfs file and the expected hash value.
[0074] Among them, the expected hash value can be understood as the reference value of the hash value of the external initramfs file.
[0075] In an alternative embodiment, the method for determining whether the external initramfs file cannot be decompressed properly may include the following steps:
[0076] S141, before the operating system kernel decompresses the external initramfs file for the first time, initialize the number of decompression records in the decompression counter to 0, and increment the number of decompression records by 1 each time the operating system kernel decompresses the external initramfs file.
[0077] The decompression counter can be understood as a counter built into the operating system, which is used to record the number of times the operating system kernel decompresses the external initramfs file during a single startup process of the operating system.
[0078] S142, when the operating system kernel fails to decompress the external initramfs file, determine whether the external initramfs file cannot be decompressed properly according to 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 decompresses the external initramfs file.
[0080] Optionally, if the recorded number of decompressions is less than the preset number of decompressions, decompress the external initramfs file again; if the recorded number of decompressions is equal to the preset number of decompressions, determine that the external initramfs file cannot be decompressed properly.
[0081] It can be understood that, compared with restarting the system, the efficiency of decompressing the external file again is obviously higher. However, when the recorded number of decompressions is equal to the preset number of decompressions, it means that the problem of the external initramfs file decompression failure cannot be solved by decompressing again, so it can be determined that the external initramfs file cannot be decompressed properly.
[0082] In another alternative embodiment, if the hash value of the external initramfs file is inconsistent with the expected hash value, it is determined that the reason for the decompression failure is that the external initramfs file is corrupted; if the hash value of the external initramfs file is consistent with the expected hash value, it is determined that the reason for the decompression failure is an abnormal startup process of the operating system kernel.
[0083] It can be understood that since the hash values calculated from the same data are the same, when the hash value of the external initramfs file is inconsistent with the expected hash value, it indicates that the data of the data file in the external initramfs file has changed before decompression. Therefore, it can be determined that the reason for the decompression failure is that the external initramfs file is damaged. Exemplarily, when the BIOS loads the external file into memory, the external initramfs file is damaged. In contrast, when the hash value of the external initramfs file is consistent with the expected hash value, it indicates that the external initramfs file is not damaged before decompression, that is, the decompression failure has nothing to do with the external initramfs file itself. Therefore, it can be determined that the reason for the decompression failure is an abnormal kernel startup process.
[0084] S150. Report the decompression failure problem to the corresponding processing object according to the reason for the decompression failure.
[0085] Optionally, the processing object can be a pre-set processing program or a processing person. Exemplarily, for the scenario where the processing object is a processing person, the following logic can be used to report the decompression failure problem:
[0086] If it is determined that the reason for the decompression failure is that the external initramfs file is damaged, report the decompression failure problem to the first processing object;
[0087] If it is determined that the reason for the decompression failure is an abnormal operating system kernel startup process, report the decompression failure problem to the second processing object.
[0088] Among them, the first processing object can be a firmware engineer, and the second processing object can be an operating system kernel engineer. By reporting the decompression failure problems caused by different decompression failure reasons to the appropriate processing objects, the solution efficiency of the decompression failure problems can be improved and resource waste can be avoided.
[0089] In this embodiment, when the operating system starts, the boot loader loads the external initramfs file into memory and passes the starting address of the external initramfs file to the operating system kernel; by executing a hash verification function, the external initramfs file is hash-verified to obtain the hash value of the external initramfs file, so as to use this hash value as the determination basis for the decompression failure reason in the future; the operating system kernel decompresses the external initramfs file into the root file system according to the starting address; when it is determined that the external initramfs file cannot be decompressed normally, the decompression failure reason is determined according to the comparison result between the hash value of the external initramfs file and the expected hash value, replacing the way of manually checking the decompression failure reason, and the decompression failure reason can be quickly and accurately located; according to the decompression failure reason, the decompression failure problem is reported to the corresponding processing object, so as to handle the decompression failure problem targeted and avoid resource waste.
[0090] It should be understood that although the steps in the flowcharts involved in the above embodiments are shown in sequence according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless there is a clear description in this article, the execution of these steps has no strict order limit, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above embodiments may include multiple steps or multiple stages. These steps or stages are not necessarily executed 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 executed alternately or alternately with at least a part of other steps or steps or stages in other steps.
[0091] The technical features of the above embodiments can be combined arbitrarily. For the sake of concise description, not all possible combinations of the technical features in the above embodiments are described. However, as long as the combinations of these technical features do not conflict, they should be considered as the scope recorded in the present invention.
[0092] The above-described embodiments only represent several implementation manners of the present invention. The description is relatively specific and detailed, but it should not be construed as a limitation on the scope of the present invention. It should be noted that for those of ordinary skill in the art, without departing from the concept of the present invention, several deformations and improvements can still be made, and these all belong to the protection scope of the present invention. Therefore, the protection scope of the present invention should be subject to the appended claims.
Claims
1. A method for handling an operating system startup exception, characterized in that: The method comprises: When the operating system starts, the boot loader loads the external initramfs file into the memory and passes the starting address of the external initramfs file to the operating system kernel; By executing the hash verification function, the external initramfs file is hash-verified to obtain the hash value of the external initramfs file; The operating system kernel decompresses the external initramfs file into the root file system according to the starting address; After determining that the external initramfs file cannot be decompressed normally, determining the reason for the decompression failure according to the comparison result of the hash value of the external initramfs file and the expected hash value; the determining the reason for the decompression failure according to the comparison result of 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, determining that the reason for the decompression failure is that the external initramfs file is damaged; if the hash value of the external initramfs file is consistent with the expected hash value, determining that the reason for the decompression failure is that the operating system kernel startup process is abnormal; According to the decompression failure reason, the decompression failure problem is reported to the corresponding processing object.
2. The method according to claim 1, characterized in that The hash check function includes a first processing function, a second processing function and a third processing function; the method of performing a hash check on the external initramfs file by executing the hash check function to obtain a hash value of the external initramfs file includes: By executing the first processing function, a hash transformation object is created; the hash transformation object includes a calculation-related function 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, in the hash descriptor structure, the metadata and the external initramfs file data are input into the calculation related function to calculate the hash value of the external initramfs file; After the computation is complete, the hash transform object and hash descriptor structure are released.
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 recorded is increased by 1 each time the operating system kernel decompresses the external initramfs file; When the operating system kernel fails to decompress the external initramfs file, it is determined whether the external initramfs file cannot be decompressed normally according to the relationship between the recorded decompression times and the preset decompression times.
4. The method according to claim 3, characterized in that The step of determining whether the external initramfs file cannot be decompressed normally according to the relationship between the recorded decompression times and the preset decompression times includes: If the recorded decompression times are less than the preset decompression times, the external initramfs file is decompressed again; If the recorded decompression times are equal to the preset decompression times, 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 problem to a corresponding processing object according to the decompression failure reason includes: If it is determined that the decompression failure is caused by the damage of the external initramfs file, the decompression failure problem is reported to the first processing object; If it is determined that the decompression failure is caused by an abnormal operating system kernel startup process, the decompression failure problem is reported to the second processing object.
6. An operating system startup exception handling device, characterized in that: The device comprises: A loading module is used for the boot loader to load the external initramfs file into the memory when the operating system starts, and pass the starting address of the external initramfs file to the operating system kernel; A hash check module is used to perform a hash check on an external initramfs file by executing a hash check function to obtain a hash value of the external initramfs file; A decompression module is used for the operating system kernel to decompress the external initramfs file into the root file system according to the starting address; A determination module is used to determine the reason for the decompression failure according to the comparison result of the hash value of the external initramfs file and the expected hash value after determining that the external initramfs file cannot be decompressed normally; the determination of the reason for the decompression failure according to the comparison result of 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, determining that the reason for the decompression failure is that the external initramfs file is damaged; if the hash value of the external initramfs file is consistent with the expected hash value, determining that the reason for the decompression failure is that the operating system kernel startup process is abnormal; The reporting module is used to report the decompression failure problem to the corresponding processing object according to the decompression failure reason.
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, the steps of the method according to any one of claims 1 to 5 are implemented.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.
9. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.
Citation Information
Patent Citations
Offline authentication system and method thereof
CN110324315A
Security analysis method for firmware of embedded equipment
CN111428233A