Linux System Boot Protection Method, Device and Storage Medium
By setting the size and generation strategy of restart protection file group in the Linux system, the system cannot be started due to disk space occupied by logs, data, configuration files and cache files, and the normal startup and stable operation of the system are achieved.
Patent Information
- Application Number
- CN202510258426.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-06
- Publication Date
- 2025-07-08
- Estimated Expiration
- 2045-03-06
AI Technical Summary
The existing technology cannot effectively solve the problem that the Linux system cannot be started due to the occupancy of system disk space by logs, data, configuration files and cache files.
By setting the size of the restart protection file group, the restart protection file group is gradually generated when the available storage space on the system disk is greater than the preset threshold, and the preset number of restart protection files will be quickly generated when the space is insufficient to avoid generating a large number of files at once and affecting the normal use of the system.
It effectively avoids the exhaustion of system disk space, ensures that the Linux system can start normally, and generates file groups in stages to reduce the impact on the normal use of the system.
Smart Images

Figure CN119739436B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of Linux systems, and in particular, to a method, device, and storage medium for protecting the startup of a Linux system. Background Art
[0002] During the system startup process, if the system disk space is exhausted due to logs, data, configuration files, and cache files generated by users' daily use or third-party system applications, the system will fail to start.
[0003] In the prior art, tools for automatically managing a large number of log files are usually used to effectively manage log files. For example, Logrotate supports functions such as periodic rotation, compression, deletion, and email notification. This tool aims to simplify the management of systems that generate a large number of log files and help system administrators effectively manage log files in an automated manner, thus avoiding the problem of excessive disk space occupied by overly large log files. However, this method only supports space limitation for log files and cannot solve the problem that the file system fails to start after the disk is full due to data, configuration files, cache files, etc. generated by third-party system applications. Summary of the Invention
[0004] Embodiments of the present invention provide a method, device, and storage medium for protecting the startup of a Linux system to solve the technical problem that in the prior art, the Linux system fails to start normally due to various files generated by logs and third-party system applications filling up the system disk.
[0005] In a first aspect, embodiments of the present invention provide a method for protecting the startup of a Linux system, including:
[0006] Setting the size of the restart protection file group according to the storage space of the system disk;
[0007] When the available storage space of the system disk is greater than a preset first space threshold, it is determined as the fast recording state.
[0008] When in the fast recording state, determine the number of restart protection file groups to be generated according to the recorded system startup times, and generate corresponding restart protection file groups on the system disk.
[0009] When the available storage space of the system disk is less than a preset second space threshold, it is determined as the state of hitting the disk space barrier.
[0010] When in the state of hitting the disk space barrier, each time the system starts up, generate a preset number of restart protection file groups on the system disk, and the preset number is greater than the maximum number of restart protection files generated in the fast recording state.
[0011] In a second aspect, an embodiment of the present invention further provides a Linux system startup protection device, including:
[0012] A setting module, configured to set the size of the restart protection file group according to the storage space of the system disk;
[0013] A first generation module, configured to determine it as the fast recording state when the available storage space of the system disk is greater than a preset first space threshold. When in the fast recording state, determine the number of restart protection files generated in the restart protection file group according to the recorded number of system startups, and generate corresponding numbers of restart protection files on the system disk;
[0014] A determination module, configured to determine it as the state of hitting the disk space barrier when the available storage space of the system disk is less than a preset second space threshold;
[0015] A second generation module, configured to generate a preset number of restart protection files on the system disk each time the system starts up when in the state of hitting the disk space barrier, and the preset number is greater than the maximum number of restart protection files generated in the fast recording state.
[0016] In a third aspect, an embodiment of the present invention further provides a storage medium containing computer-executable instructions, and the computer-executable instructions are used to execute the Linux system startup protection method provided in the above embodiment when executed by a computer processor.
[0017] The Linux system startup protection method, device and storage medium provided by the embodiments of the present invention set the size of the restart protection file group according to the storage space of the system disk; when the available storage space of the system disk is greater than a preset first space threshold, determine it as the fast recording state. When in the fast recording state, determine the number of restart protection file groups generated according to the recorded number of system startups, and generate corresponding numbers of restart protection file groups on the system disk; when the available storage space of the system disk is less than a preset second space threshold, determine it as the state of hitting the disk space barrier; when in the state of hitting the disk space barrier, generate a preset number of restart protection file groups on the system disk each time the system starts up, and the preset number is greater than the maximum number of restart protection files generated in the fast recording state. The restart protection file group can be utilized to achieve the purpose of normal startup by deleting some restart protection file groups when the storage space of the system disk is tight. And the restart protection file group can be generated in stages according to the usage state of the system disk, avoiding generating a large number of restart protection file groups at one time and affecting the normal use of the Linux system. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] By reading the detailed description of the non-limiting embodiments with reference to the following drawings, other features, objectives and advantages of the present invention will become more obvious:
[0019] Figure 1 It is a schematic flow chart of the Linux system startup protection method provided in the first embodiment of the present invention;
[0020] Figure 2 It is a schematic diagram of the number of protection files created in the Linux system startup protection method provided in the first embodiment of the present invention;
[0021] Figure 3 It is a schematic flow chart of the Linux system startup protection method provided in the second embodiment of the present invention;
[0022] Figure 4 It is a schematic diagram of the creation and recovery of restart protection files in the restart protection file group in the Linux system startup protection method provided in the second embodiment of the present invention;
[0023] Figure 5 It is a schematic structural diagram of the Linux system startup protection device provided in the third embodiment of the present invention. Detailed implementation manners
[0024] The present invention will be further described in detail below with reference to the accompanying drawings and embodiments. It can be understood that the specific embodiments described herein are only used to explain the present invention, rather than limiting the present invention. In addition, it should be noted that, for the sake of description, only parts related to the present invention are shown in the drawings rather than all structures.
[0025] Embodiment 1
[0026] Figure 1 It is a flow chart of the Linux system startup protection method provided in the first embodiment of the present invention. This embodiment is applicable to the situation where logs, data, configuration files, and cache files generated during the use of the Linux system are excessive, resulting in insufficient system storage capacity and affecting the normal startup of the Linux system. This method can be executed by the Linux system startup protection device, and specifically includes the following steps:
[0027] Step 110, set the size of the restart protection file group according to the storage space of the system disk.
[0028] The startup of the Linux operating system begins with the self-check stage of the BIOS (Basic Input / Output System) or UEFI (Unified Extensible Firmware Interface). This stage ensures the integrity and functionality of all key hardware components through a series of diagnostic tests, laying the foundation for the subsequent system loading.
[0029] Subsequently, control is transferred to GRUB (GRand Unified Bootloader), which is the system's boot loader. GRUB is responsible for loading the Linux kernel and its matching initial memory file system (initramfs) from the storage medium according to the user's choice or the preset boot sequence configuration. initramfs is a temporary root file system that provides the necessary drivers and tools at the beginning of system startup so that the system can perform necessary initialization operations before the official root file system is mounted.
[0030] As the kernel starts, initramfs is decompressed and mounted as a temporary root file system, providing a necessary operating environment for the further initialization process of the system. At this stage, systemd, as the system initialization daemon and service manager, is started by the kernel as the first user-mode process (PID 1).
[0031] systemd reads system and service configuration files, builds a startup dependency graph, and uses advanced parallel startup strategies to speed up the service startup process. With all necessary services and daemons started and configured, systemd guides the system to the preset target state. These target states define the operating mode of the system, such as multi-user.target represents a multi-user command line interface mode, and graphical.target represents a mode that includes a graphical user interface. Once the system reaches the predetermined target state, users can access the system through the login interface and perform various tasks and applications.
[0032] During the system startup process, if the system disk space is exhausted due to logs, data, configuration files, and cache files generated by daily user use or third-party system applications, the system will fail to start. Specifically, it may be caused by the following reasons: The startup activities of system services and key applications are monitored by the system, and the relevant information is written to the log file. The log entry contains the service startup time, status (success or failure), and possible error information and debugging data, providing system administrators with in-depth system behavior analysis and potential problem diagnosis. It is particularly important to note that the continuous logging depends on sufficient space on the storage medium (especially the hard disk). Insufficient hard disk space will directly lead to log writing failure, which may lead to two serious consequences: first, the system service cannot start normally or maintain stable operation due to the lack of log records; second, the user may not be able to access the file system because the dependent system service (such as the log service) failed to start successfully.
[0033] In the daily operation and maintenance of the system, in addition to key program logging, it is also necessary to consider the impact of a series of key data components created during program operation on the system disk resources. Specifically, the program generates various types of files, including but not limited to database files, configuration files, and cache files. These files play a crucial role in the normal operation of the system but also occupy a certain amount of disk space. The logs or other behaviors of third-party applications will inevitably lead to the problem of system disk space exhaustion.
[0034] To avoid the problem of system disk space exhaustion, in this embodiment, a protection space can be set in the system disk space to prevent startup failures caused by space exhaustion. Further, considering that setting up a protection space requires separate separation and real-time monitoring of space usage to determine whether to cancel the protection space, and after cancellation, a protection space needs to be set again according to the newly added logs and data components. The above operations are not only complex but also not flexible enough.
[0035] Preferably, the system disk space can be protected in the form of a file group. The file group includes several files of a certain size without substantial content, such as files filled with 0 throughout their content.
[0036] In this embodiment, the size of the file group can be set according to the disk space. Exemplarily, it can be calculated as the product of the system disk space and a preset ratio as the size of the file group.
[0037] Further, it is also possible to count the size increase of the log each time, as well as the quantity and size of various files generated by frequently used data components, and determine the size of each protection file in the file group based on the statistical data. This is to facilitate the deletion of files in the protection file group later. Exemplarily, the size of the smallest file can be determined by combining the usage frequency of the data component and the total size increase of the statistical log each time. Further, considering the preset range of the number of file groups, the size of the file can be determined according to a certain multiple of the size of the smallest file.
[0038] Step 120, when the available storage space on the system disk is greater than a preset first space threshold, it is determined as the fast recording state. In the fast recording state, the number of restart protection files in the restart protection file group is determined according to the recorded number of system startups, and the corresponding number of restart protection files is generated on the system disk.
[0039] In this embodiment, if all the files in the complete restart protection file group are used to preempt the system disk resources at an early stage, and at this time, there is no situation of tight system storage space, it will affect the normal use of the system. Therefore, in this embodiment, a progressive method is adopted to establish the protection files in the restart protection group.
[0040] Exemplarily, first, it is determined whether the storage space of the current system disk is greater than a preset space threshold. If it is greater, it can be considered that the system disk space is relatively sufficient, and it is determined as the fast recording state. In this state, most of the protection files can be created.
[0041] Exemplarily, the number of protection files in the restart protection file group is determined according to the recorded number of system startups. Optionally, the following method can be adopted to implement it:
[0042] , where N is the total number of restart protection file groups, X is the number of system startups, M is the total number of system startups required to generate all restart protection file groups set, and y is the number of restart protection file groups generated.
[0043] It can be seen from the above formula that the protection files can be gradually established in the way of the first-order difference of the line function. Figure 2 It is a schematic diagram of the number of protection files created in the Linux system startup protection method provided in the first embodiment of the present invention. Refer to Figure 2 , with N being 20 and M being 5, determine the number of protection files established in each stage. From Figure 2 It can be seen that in the first M startups, most of the protection files are gradually created before the device user has not used a large amount of disk space, so as to avoid the impact of the protection file creation process on the normal use of the system.
[0044] Exemplarily, when in the fast recording state, generating the corresponding number of restart protection files on the system disk may further include: generating a fast establishment feature file; writing the [FileNum] field to the fast establishment feature file, and writing the total number of preset restart protection file groups as a parameter to the [FileNum] field; writing the [Estimated] field to the fast establishment feature file, and writing the expected total number of times to generate all restart protection file groups as a parameter to the [Estimated] field; writing the [StartsNum] field to the fast establishment feature file, and after each startup, writing the recorded number of startups as a parameter to the [StartsNum] field. In this embodiment, since the protection files need to be gradually generated in stages in the fast recording state. By using each field of the fast establishment feature file, various parameters can be written, and some parameters can be flexibly modified according to each stage, so that in the later stage, at each startup, by querying various parameters of the fast establishment feature file, the restart protection file corresponding to the current startup can be established, and after the establishment is completed, the parameters of the corresponding fields are modified. Usually, the fast establishment feature file can be generated when the system is started for the first time.
[0045] Step 130: When the available storage space on the system disk is less than a preset second space threshold, it is determined that the disk space barrier state is hit.
[0046] If, when the system starts up, it is found that the available storage space on the system disk is already insufficient, system startup problems may occur in a short period. And at this time, when the protection files in the restart protection file group have not been created or have not all been created, the current state can be determined as the disk space barrier state.
[0047] Correspondingly, the [DiskWaterMark] field in the quick establishment feature file can be used to query the preset second space threshold, and it is determined whether the disk space barrier state is hit according to the second space threshold.
[0048] Step 140: When the disk space barrier state is hit, each time the system starts up, a preset number of restart protection files are generated on the system disk, and the preset number is greater than the maximum number of restart protection files generated in the quick record state.
[0049] When the disk space barrier state is hit, if the restart protection files are still created in the same way as in the quick record state, it may not be possible to complete the creation of all protection files. Therefore, in this embodiment, another method is adopted to generate the restart protection files. Exemplarily, a fixed number of protection files are created in a fixed quantity manner. And this quantity is greater than the maximum number of restart protection files generated in the quick record state. So as to quickly complete the creation of the restart protection file group in the disk space barrier state.
[0050] Furthermore, the preset number can be determined according to the remaining space in the current disk space barrier state and the size of the protection files, to determine the number of times the system can start up normally, and the preset number is determined according to the number of times and the number of remaining protection files to be created. So as to complete the quick establishment of the restart protection files without affecting the normal operation and startup of the system.
[0051] Correspondingly, [Finished] can be written to the quick establishment feature file to mark the completion status of generating a preset number of restart protection file groups on the system disk.
[0052] In this embodiment, the size of the restart protection file group is set according to the storage space of the system disk; when the available storage space of the system disk is greater than a preset first space threshold, it is determined to be in the fast recording state. When in the fast recording state, the number of restart protection file groups to be generated is determined according to the recorded system startup times, and the corresponding number of restart protection file groups is generated on the system disk; when the available storage space of the system disk is less than a preset second space threshold, it is determined to be in the state of hitting the disk space barrier; when in the state of hitting the disk space barrier, each time the system starts up, a preset number of restart protection files are generated on the system disk, and the preset number is greater than the maximum number of restart protection files generated in the fast recording state. The restart protection file groups can be used to achieve the purpose of normal startup by deleting some of the restart protection files in the restart protection file groups when the storage space of the system disk is tight. And the restart protection file groups can be generated in stages according to the usage status of the system disk, avoiding generating a large number of restart protection files at one time and affecting the normal use of the Linux system.
[0053] In a preferred implementation manner of this embodiment, the method may further include the following steps: before each system shutdown, detect whether the system partition is in the resource exhaustion stage. When in the resource exhaustion stage, delete the protection files in the restart protection file group. Optionally, it can be determined whether it is in the resource exhaustion stage according to whether the free space in the system partition is less than a preset space threshold, or the ratio of the free space to the system partition space is less than a preset ratio threshold. Before each system shutdown, detect whether the system partition is in the resource exhaustion stage. When in the resource exhaustion stage, some or all of the restart protection files in the restart protection file group need to be deleted. So that the system can start up normally next time. Optionally, the number of restart protection files to be deleted can be determined according to the resource exhaustion stage.
[0054] Embodiment 2
[0055] Figure 3 FIG. is a schematic flowchart of the Linux system startup protection method provided by Embodiment 2 of the present invention. This embodiment is optimized based on the above embodiment. The method may further include the following steps: when detecting the event of deleting the restart protection file group during the previous shutdown, determine the space occupancy rate of the current system disk; when the space occupancy rate is greater than a preset occupancy rate threshold, determine it to be in the slow recovery state; when in the slow recovery state, record the system restart times. When the system restart times reach a preset number threshold, attempt to restore the restart protection files in the restart protection file group again.
[0056] See Figure 3 , the Linux system startup protection method includes:
[0057] Step 210, set the size of the restart protection file group according to the storage space of the system disk.
[0058] Step 220: When the available storage space of the system disk is greater than a preset first space threshold, it is determined to be in the fast recording state. When in the fast recording state, the number of restart protection files in the restart protection file group is determined according to the recorded number of system startups, and the corresponding number of restart protection files is generated on the system disk.
[0059] Step 230: When the available storage space of the system disk is less than a preset second space threshold, it is determined to be in the state of hitting the disk space barrier.
[0060] Step 240: When in the state of hitting the disk space barrier, each time the system starts up, a preset number of restart protection files are generated on the system disk, and the preset number is greater than the maximum number of restart protection files generated in the fast recording state.
[0061] Step 250: When detecting the event of deleting restart protection files during the previous shutdown, determine the space occupancy rate of the current system disk.
[0062] In this embodiment, deleting restart protection files during the previous shutdown may be the situation where all or part of the restart protection files are deleted when the remaining space of the system is insufficient. When this event is detected, an alarm will be issued during the startup of the current system. The user may clean up the system space, resulting in a relatively large remaining space of the system. At this time, the deleted restart protection files can be quickly restored. In addition, it is also possible that no processing is performed. Therefore, it is necessary to detect the space occupancy rate of the current system disk to determine whether the user has cleaned up the system space.
[0063] Step 260: When the space occupancy rate is greater than a preset occupancy rate threshold, it is determined to be in the slow recovery state.
[0064] The slow recovery state is applicable to attempting to restore restart protection files when the user has not performed any processing on the system disk.
[0065] Step 270: When in the slow recovery state, record the number of system restarts. When the number of system restarts reaches a preset number threshold, attempt to restore the restart protection files in the restart protection file group again.
[0066] Figure 4 It is a schematic diagram of the creation and recovery of restart protection files in the restart protection file group in the Linux system startup protection method provided by the second embodiment of the present invention. See Figure 4, in the quick recording state and the state of hitting the disk space barrier, a restart protection file is gradually generated. When the event of deleting the restart protection file during the previous shutdown is detected, the time interval for attempting to restore the restart protection file is increased by K times, that is, the restart protection file is attempted to be restored again after K restarts. In an actual usage scenario, when the disk space is insufficient once and the creation of the actual protection file fails because the remaining space of the system is already less than the size of a restart protection file, a restart protection file is attempted to be created each time the system is powered on. Due to the write amplification problem of the disk, it will cause problems such as system lag and prevent successful creation. Since the user will eventually find that the disk space is severely insufficient within K restarts and perform operations such as removing unnecessary files, and due to the system lag and previous correct warnings, the user will discover this problem. After K startups, the restart protection file is created again. In this way, even if the customer does not clean up, it will not cause abnormal lag each time the system is powered on.
[0067] Exemplarily, before, [TouchOff] can be written to the quick establishment feature file to mark whether the restart protection mechanism is triggered; [RebootNumber] can be written to the quick establishment feature file to mark the number of restart protection files to be restored; [RecoverSusecess] can be written to the quick establishment feature file to mark whether the restart protection file to be restored is successfully created. In the slow recovery stage, by reading [TouchOff], it can be determined whether the event of deleting the restart protection file during the previous shutdown occurred, and by reading the [RebootNumber] field, the number of restart protection files to be restored can be obtained, and the [RecoverSusecess] field is used to mark whether the restart protection file to be restored is successfully created.
[0068] This embodiment adds the following steps: when the event of deleting the restart protection file group during the previous shutdown is detected, determine the space occupancy rate of the current system disk; when the space occupancy rate is greater than the preset occupancy rate threshold, determine it as the slow recovery state; when in the slow recovery state, record the number of system restarts, and when the number of system restarts reaches the preset number threshold, attempt to restore the restart protection files in the restart protection file group again. This avoids system lag problems.
[0069] Embodiment Three
[0070] Figure 5 is a schematic structural diagram of the Linux system startup protection device provided by Embodiment Three of the present invention. Refer to Figure 5 , the Linux system startup protection device includes:
[0071] A setting module 310, configured to set the size of the restart protection file group according to the storage space of the system disk;
[0072] The first generation module 320 is configured to determine the fast recording state when the available storage space of the system disk is greater than a preset first space threshold. When in the fast recording state, it determines the number of restart protection files in the restart protection file group according to the recorded number of system startups, and generates the corresponding number of restart protection files on the system disk;
[0073] The determination module 330 is configured to determine the disk space barrier hit state when the available storage space of the system disk is less than a preset second space threshold;
[0074] The second generation module 340 is configured to generate a preset number of restart protection files on the system disk each time the system starts up when in the disk space barrier hit state, and the preset number is greater than the maximum number of restart protection files generated in the fast recording state.
[0075] The Linux system startup protection device provided in this embodiment sets the size of the restart protection file group according to the storage space of the system disk; when the available storage space of the system disk is greater than a preset first space threshold, it determines the fast recording state. When in the fast recording state, it determines the number of restart protection file groups to be generated according to the recorded number of system startups, and generates the corresponding number of restart protection file groups on the system disk; when the available storage space of the system disk is less than a preset second space threshold, it determines the disk space barrier hit state; when in the disk space barrier hit state, a preset number of restart protection file groups are generated on the system disk each time the system starts up, and the preset number is greater than the maximum number of restart protection files generated in the fast recording state. The restart protection file group can be used to achieve the purpose of normal startup by deleting some restart protection file groups when the storage space of the system disk is tight. And it can generate restart protection file groups in stages according to the usage status of the system disk, avoiding generating a large number of restart protection file groups at one time and affecting the normal use of the Linux system.
[0076] Based on the above embodiments, the device further includes:
[0077] The space occupancy rate determination module is configured to determine the space occupancy rate of the current system disk when detecting the event of deleting restart protection files during the previous shutdown;
[0078] The slow recovery state determination module is configured to determine the slow recovery state when the space occupancy rate is greater than a preset occupancy rate threshold;
[0079] The attempt to recover module is configured to record the number of system restarts when in the slow recovery state, and attempt to recover the restart protection files in the restart protection file group when the number of system restarts reaches a preset number threshold.
[0080] Based on the above embodiments, the first generation module includes:
[0081] A determination unit, configured to determine the number of restart protection file groups to be generated according to the recorded number of system startups.
[0082] It is implemented in the following manner:
[0083] , where N is the total number of restart protection file groups, X is the number of system startups, M is the total number of system startups set required to generate all restart protection file groups, and y is the number of restart protection file groups to be generated.
[0084] Based on the above embodiments, the first generation module includes:
[0085] A padding file generation unit, configured to generate padding files with zero information amount and a preset size corresponding to the number;
[0086] An alarm feature file generation unit, configured to generate an alarm feature file;
[0087] A first field writing unit, configured to write the [RemoveFileLastReboot] field to the alarm feature file and adjust the status value of the [RemoveFileLastReboot] field according to the detection result of the event of deleting the restart protection file group during the previous shutdown.
[0088] Based on the above embodiments, the first generation module includes:
[0089] A quick establishment feature file generation unit, configured to generate a quick establishment feature file;
[0090] A second field writing unit, configured to write the [FileNum] field to the quick establishment feature file and write the total number of preset restart protection files as a parameter to the [FileNum] field;
[0091] A third field writing unit, configured to write the [Estimated] field to the quick establishment feature file and write the expected total number of times required to generate all restart protection file groups as a parameter to the [Estimated] field;
[0092] A fourth field writing unit, configured to write the [StartsNum] field to the quick establishment feature file and write the recorded number of startups as a parameter to the [StartsNum] field after each startup;
[0093] A fourth field writing unit, configured to write the [DiskWaterMark] field to the quick establishment feature file and write the second space threshold corresponding to the disk space barrier state as a parameter to the [DiskWaterMark] field;
[0094] The fifth field writing unit is configured to write the [NormalEstablishNum] field to the fast establishment feature file, and write the number of file blocks established each time the disk space barrier state is hit as a parameter to the [NormalEstablishNum] field.
[0095] Based on the above embodiments, the first generation module includes:
[0096] The sixth field writing unit is configured to write [Finished] to the fast establishment feature file, which is used to mark the completion status of generating a preset number of restart protection file groups on the system disk.
[0097] Based on the above embodiments, the second generation module includes:
[0098] The seventh field writing unit is configured to write [TouchOff] to the fast establishment feature file, which is used to mark whether the restart protection mechanism is triggered;
[0099] The eighth field writing unit is configured to write [RebootNumber] to the fast establishment feature file, which is used to mark the number of restart protection files restored;
[0100] The ninth field writing unit is configured to write [RecoverSusecess] to the fast establishment feature file, which is used to mark whether the restart protection files that need to be restored are successfully created.
[0101] The Linux system startup protection device provided by the embodiments of the present invention can execute the Linux system startup protection method provided by any embodiment of the present invention, and has the corresponding functional modules and beneficial effects for executing the method.
[0102] Embodiment 4
[0103] Embodiment 4 of the present invention further provides a storage medium containing computer-executable instructions, and the computer-executable instructions are used to execute any one of the Linux system startup protection methods provided by the above embodiments when executed by a computer processor.
[0104] The computer storage medium of the embodiments of the present invention may adopt any combination of one or more computer-readable media. The computer-readable medium may be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples (non-exhaustive list) of the computer-readable storage medium include: an electrical connection having one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this document, the computer-readable storage medium may be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.
[0105] The computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries computer-readable program code. Such a propagated data signal may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The computer-readable signal medium may also be any computer-readable medium other than the computer-readable storage medium, which can send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0106] The program code contained on the computer-readable medium may be transmitted by any appropriate medium, including but not limited to wireless, wire, optical fiber cable, RF, etc., or any suitable combination of the above.
[0107] The computer program code for performing the operations of the present invention may be written in one or more programming languages or combinations thereof. The programming languages include object-oriented programming languages such as Java, Smalltalk, C++, and also include conventional procedural programming languages such as the "C" language or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, executed as an independent software package, partially on the user's computer and partially on a remote computer, or entirely on the remote computer or device. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (for example, by connecting through the Internet service provider through the Internet).
[0108] Note that the above is only the preferred embodiment of the present invention and the technical principles applied. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein. Various obvious changes, re-adjustments and substitutions can be made by those skilled in the art without departing from the protection scope of the present invention. Therefore, although the present invention has been described in more detail through the above embodiments, the present invention is not limited to the above embodiments. Without departing from the concept of the present invention, more other equivalent embodiments can be included, and the scope of the present invention is determined by the scope of the appended claims.
Claims
1. A method for protecting the startup of a Linux system, characterized in that Including: Set the size of the restart protection file group according to the storage space of the system disk; When the available storage space of the system disk is greater than the preset first space threshold, it is determined to be in the fast recording state. When in the fast recording state, determine the number of restart protection files generated in the restart protection file group according to the recorded number of system startups, and generate the corresponding number of restart protection files on the system disk; When the available storage space of the system disk is less than the preset second space threshold, it is determined to be in the state of hitting the disk space barrier; When in the state of hitting the disk space barrier, each time the system starts up, a preset number of restart protection files are generated on the system disk, and the preset number is greater than the maximum number of restart protection files generated in the fast recording state.
2. The method according to claim 1, wherein The method further includes: When detecting the event of deleting the restart protection file during the previous shutdown, determine the space occupancy rate of the current system disk; When the space occupancy rate is greater than the preset occupancy rate threshold, it is determined to be in the slow recovery state; When in the slow recovery state, record the number of system restarts. When the number of system restarts reaches the preset number threshold, attempt to recover the restart protection files in the restart protection file group again.
3. The method according to claim 1, characterized in that, The method further includes: Before each system shutdown, detect whether the system partition is in the stage of resource exhaustion. When in the stage of resource exhaustion, delete the protection files in the restart protection file group.
4. The method according to claim 1, wherein The determining the number of the restart protection file group generated according to the recorded number of system startups includes: Implemented in the following way: , where N is the total number of restart protection file groups, X is the number of system startups, M is the set total number of system startups required to generate all restart protection file groups, and y is the number of generated restart protection file groups.
5. The method according to claim 1, characterized in that The generating the corresponding number of restart protection files on the system disk includes: Generate padding files with zero information volume and a preset size; Generate an alarm feature file; Write the [RemoveFileLastReboot] field to the alarm feature file, and adjust the status value of the [RemoveFileLastReboot] field according to the detection result of the event of deleting the restart protection file group during the previous shutdown.
6. The method according to claim 1, characterized in that, When in the fast recording state, when generating the corresponding number of restart protection files on the system disk, it further includes: Generate a fast establishment feature file; Write the [FileNum] field to the fast establishment feature file, and write the total number of preset restart protection files as a parameter to the [FileNum] field; Write the [Estimated] field to the fast establishment feature file, and write the expected total number of times to generate all restart protection file groups as a parameter to the [Estimated] field; Write the [StartsNum] field to the fast establishment feature file, and after each startup, write the recorded number of startups as a parameter to the [StartsNum] field; Write the [DiskWaterMark] field to the fast establishment feature file, and write the second space threshold corresponding to the disk space barrier state as a parameter to the [DiskWaterMark] field; Write the [NormalEstablishNum] field to the fast establishment feature file, and write the number of file blocks established each time in the state of hitting the disk space barrier as a parameter to the [NormalEstablishNum] field.
7. The method according to claim 6, characterized in that When in the state of not hitting the disk space barrier, each time the system starts up, a preset number of restart protection files are generated on the system disk, and it further includes: Write [Finished] to the quick establishment feature file to mark the completion status of generating a preset number of restart protection file groups on the system disk.
8. The method according to claim 2, wherein When in the quick recording state, a corresponding number of restart protection files are generated on the system disk, and it further includes: Write [TouchOff] to the quick establishment feature file to mark whether the restart protection mechanism is triggered; Write [RebootNumber] to the quick establishment feature file to mark the number of restart protection files recovered; Write [RecoverSusecess] to the quick establishment feature file to mark whether the restart protection files that need to be recovered are successfully created.
9. A Linux system startup protection device, characterized in that, It includes: A setting module for setting the size of the restart protection file group according to the storage space of the system disk; A first generation module for determining the quick recording state when the available storage space on the system disk is greater than a preset first space threshold. When in the quick recording state, determine the number of restart protection files in the restart protection file group to be generated according to the recorded number of system startups, and generate a corresponding number of restart protection files on the system disk; A determination module for determining the state of hitting the disk space barrier when the available storage space on the system disk is less than a preset second space threshold; A second generation module for generating a preset number of restart protection files on the system disk each time the system starts up when in the state of hitting the disk space barrier, and the preset number is greater than the maximum number of restart protection files generated in the quick recording state.
10. A storage medium containing computer-executable instructions, characterized in that, The computer-executable instructions are used to execute the Linux system startup protection method as described in any one of claims 1-8 when executed by a computer processor.
Citation Information
Patent Citations
Intelligent gateway disaster recovery method and device, electronic equipment and storage medium
CN114866404A
Vehicle machine system restarting method, device and equipment and storage medium
CN117493079A