Linux system abnormal device troubleshooting method, device and storage medium
By analyzing the set of abnormal devices in the kernel startup stage of the Linux system and matching it before device registration, the problem of difficulty in accurately detecting abnormal devices in the Linux system in the existing technology is solved, and accurate positioning and troubleshooting of abnormal devices is achieved to ensure the stable operation of the system.
Patent Information
- Application Number
- CN202411853935.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-17
- Publication Date
- 2025-04-01
- Estimated Expiration
- 2044-12-17
AI Technical Summary
It is difficult for the prior art to accurately detect abnormalities in specific devices in Linux systems, resulting in unstable factors during system startup or operation.
The pre-set set of exception devices is parsed during the kernel startup stage to obtain the set of exception devices; match the set of exception devices before each device is registered; return to the unauthorized error and skip the registration process when the match is successful; locate the abnormal devices in the set of exception devices.
It realizes accurate positioning and troubleshooting of abnormal devices in Linux systems, avoids the problem of disabling all devices of the same model, and ensures that the system is up and running normally.
Smart Images

Figure CN119311463B_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 troubleshooting abnormal devices in a Linux system. Background Art
[0002] When the Linux system is started or running, due to the hardware or software defects of one or some devices, the system and the kernel may become unstable during startup or operation. For example, during the loading of the device driver, the system may freeze or even freeze.
[0003] When debugging an exception, developers suspect that it may be strongly related to a certain device. The device needs to be shielded to prevent the device driver from being loaded into the kernel. In the prior art, the device can be shielded by editing the kernel configuration file (such as the .config file). However, using this method will directly disable the device driver when using the existing device disable function, making all devices of the same model unavailable. It is impossible to find out which specific device has the exception. Summary of the invention
[0004] The embodiment of the present invention provides a method, device and storage medium for checking abnormal devices in a Linux system, so as to solve the technical problem in the prior art that the Linux system cannot accurately check the abnormalities of specific devices.
[0005] In a first aspect, an embodiment of the present invention provides a method for troubleshooting abnormal devices in a Linux system, comprising:
[0006] In the kernel startup phase, a preset abnormal device set is parsed to obtain an abnormal device set;
[0007] Before each device is registered, matching the device with the abnormal device set;
[0008] When the matching is successful, an unauthorized error is returned to the successfully matched device to skip the registration process of the device, and the unmatched device is registered normally;
[0009] During the Linux system startup or operation, the abnormal device set is located to contain an abnormal device.
[0010] In a second aspect, an embodiment of the present invention further provides a Linux system abnormal device troubleshooting device, comprising:
[0011] A parsing module is used to parse a preset abnormal device set during the kernel startup phase to obtain an abnormal device set;
[0012] A matching module, used for matching each device with the abnormal device set before registering the device;
[0013] The registration module is used to return an unauthorized error to the successfully matched device when the match is successful, so as to skip the registration process of the device and perform normal registration on the pre-registered device that has not been successfully matched;
[0014] The positioning module is used to locate the abnormal device in the abnormal device set during the startup process or operation process of the Linux system.
[0015] In a third aspect, an embodiment of the present invention further provides a storage medium comprising computer executable instructions, which, when executed by a computer processor, are used to execute the method for troubleshooting abnormal devices in a Linux system as provided in the above embodiment.
[0016] The Linux system abnormal device troubleshooting method, device and storage medium provided by the embodiment of the present invention obtains an abnormal device set by parsing a preset abnormal device set during the kernel startup phase; before each device is registered, the device is matched with the abnormal device set; when the match is successful, a permission error is returned to the successfully matched device to skip the registration process of the device, and the unmatched device is normally registered; during the Linux system startup process or operation process, the abnormal device set is located to determine the presence of abnormal devices. Possible abnormal devices can be set in a preset abnormal device set. In the kernel startup phase, the abnormal device set is parsed, the abnormal devices in the abnormal device set are not registered, and whether there are abnormal devices in the abnormal device set is determined based on whether the system can be correctly started. Developers can find abnormal devices by continuously adjusting the abnormal device set. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Other features, objects and advantages of the present invention will become more apparent from the detailed description of non-limiting embodiments made with reference to the following drawings:
[0018] Figure 1 It is a flowchart of a method for troubleshooting abnormal devices in a Linux system provided by Embodiment 1 of the present invention;
[0019] Figure 2 It is a flowchart of a method for troubleshooting abnormal devices in a Linux system provided by Embodiment 2 of the present invention;
[0020] Figure 3 It is a structural diagram of a device for troubleshooting abnormal devices in a Linux system provided in Embodiment 3 of the present invention. DETAILED DESCRIPTION
[0021] The present invention will be further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the present invention, rather than to limit the present invention. It should also be noted that, for ease of description, only parts related to the present invention, rather than all structures, are shown in the accompanying drawings.
[0022] Embodiment 1
[0023] Figure 1 : is a flow chart of a method for troubleshooting abnormal devices in a Linux system provided by Embodiment 1 of the present invention. This embodiment is applicable to the case where abnormal devices are quickly troubleshooted in a Linux system. The method can be executed by an abnormal device troubleshooting device in a Linux system, and specifically includes the following steps:
[0024] Step 110, in the kernel startup phase, parse the preset abnormal device set to obtain the abnormal device set.
[0025] In the Linux kernel, the device driver and the device are in a one-to-many relationship, that is, multiple devices of the same model are loaded using the same device driver. When multiple devices of the same model use the same device driver, one or more of them may have an exception (such as causing a device driver error, or software and hardware communication abnormalities, etc.), resulting in a system error or even triggering system instability. When the existing device disable function is used, the device driver will be directly disabled, making all devices of the same model unavailable.
[0026] In this embodiment, before parsing the preset abnormal device set, the method may further add the following step: adding an abnormal filter device set through the Linux kernel startup item kernel command-line parameter. The user can check the setting parameters of the possibly abnormal device in advance. For example, the device name of the currently abnormal USB mouse device is "1-3.3". The USB mouse device name can be obtained in advance by adding the dyndbg="funcdevice_add +p" parameter in the GRUB startup item kernel command-line parameter to obtain all the device names that can be currently registered by the Linux system. Furthermore, the parameters of the possibly abnormal device can be found therefrom, and the abnormal filter device can be added using the parameters.
[0027] Exemplarily, in the UEFI GRUB interface, in the kernel command-line parameter setting of the kernel startup item, a filtering parameter for abnormal devices is added, such as "devices_filter=1-3.3", that is, the device name of the USB mouse device that is currently considered to be possibly abnormal is added to the abnormal device set.
[0028] Exemplarily, the kernel parameters defined in the kernel command-line parameters of the kernel startup item can be used to parse the pre-set abnormal device set. Optionally, the kernel command-line parameters of the kernel startup item can include: early_param(), which is used in the kernel to parse command line parameters at startup; module_param(), which is used to pass kernel parameters; core_param(), which is used to define core kernel parameters; __setup(), which is used to define kernel startup parameters.
[0029] The kernel command-line parameters are a unified list of kernel parameters implemented by __setup(), early_param(), core_param() and module_param() macros. The kernel can implement the parsing of the abnormal device set through the __setup() method. According to the parsing, the abnormal device set in the abnormal device set can be obtained. Optionally, the abnormal device set can be a set of the abnormal filtering parameters.
[0030] Step 120 : before each device is registered, the device is matched with the abnormal device set.
[0031] During the Linux kernel startup phase, each hardware device needs to be registered so that the kernel can identify and manage these devices. Before the device is registered, the pre-registered device is matched with the abnormal device set.
[0032] Step 130, when the matching is successful, a no-authority error is returned to the successfully matched device to skip the registration process of the device, and the unmatched device is registered normally.
[0033] When the device corresponding to the abnormal filtering parameter is enumerated and is ready to be registered, because its device name "1-3.3" matches the abnormal device, the "Operation not permitted" error is directly returned to skip the registration process of the device. Therefore, no data and nodes of the device will be applied in the kernel resources.
[0034] By using the above method, no resources related to the abnormal device can be retained under the Linux system; and the user can no longer perform related operations on the device, and other similar devices can be used normally.
[0035] Step 140: during the Linux system startup or operation, locate the abnormal device set to find an abnormal device.
[0036] If the Linux system can start normally or run normally, it can be explained that the abnormal device has been shielded by the above method and does not affect the normal startup of the system. Otherwise, if it is abnormal, it can be explained that there are other abnormal devices. Therefore, it can be determined that there are abnormal devices in the abnormal device set. Further, if there is only one device in the abnormal device set, the device can be located as an abnormal device.
[0037] The above method can not only accurately locate abnormal devices, but also will not affect the normal use of devices of the same type. In addition, in the case where some devices have multiple device drivers, users can freely choose the device driver they want. This meets part of the user's needs and realizes the ability to freely switch between multiple device drivers.
[0038] In this embodiment, the abnormal device set is obtained by parsing the preset abnormal device set in the kernel startup phase; before each device is registered, the device is matched with the abnormal device set; when the match is successful, the unauthorized error is returned to the successfully matched device to skip the registration process of the device and the unmatched device is normally registered; during the Linux system startup process or operation process, the abnormal device set is located to have abnormal devices. Possible abnormal devices can be set in the preset abnormal device set. In the kernel startup phase, the abnormal device set is parsed, the abnormal devices in the abnormal device set are not registered, and it is determined whether there are abnormal devices in the abnormal device set according to whether the system can be correctly started. Developers can find abnormal devices by constantly adjusting the abnormal device set. In a preferred implementation of this embodiment, the method can also add the following steps: when searching for a registered device using the bus driver matching rule, the device driver of the device is loaded. Optionally, the registered device can be tried to be found through the bus driver matching rule, and the driver of the device will not be loaded because the abnormal device is not registered. However, for multiple devices of the same type, because their device names are different, they will still load the drivers of other devices of the same type.
[0039] Embodiment 2
[0040] Figure 2 It is a flow chart of the method for troubleshooting abnormal devices in a Linux system provided by Embodiment 2 of the present invention. This embodiment is optimized based on the above embodiment. Exemplarily, the method may further add the following steps: when the system is unstable, determining possible abnormal devices; adding the possible abnormal devices to the abnormal device set, and the system also includes other devices of the same type as the possible abnormal devices.
[0041] See also Figure 2 , the Linux system abnormal device troubleshooting method comprises:
[0042] Step 210, when the system is unstable, determine a possible abnormal device; add the possible abnormal device to the abnormal device set, and the system also includes other devices of the same type as the possible abnormal device.
[0043] In this embodiment, developers can use this method to troubleshoot abnormal devices. Abnormal devices may cause the following defects: the device driver loading process is very time-consuming, resulting in a long system startup time; the device driver loading process, or when running under the system, triggers the read and write device register stuck abnormality, resulting in system pseudo-death, or even direct stuck and other abnormalities. The above situation can be considered as system instability.
[0044] When the system is unstable, the developer can determine the possible abnormal devices based on the devices currently loaded in the system, and add the possible abnormal devices to the abnormal device set. Optionally, the system also has devices of the same type as the possible abnormal devices, so that the devices can be started normally and it is convenient for developers to check the system status.
[0045] Step 220: During the kernel startup phase, a preset abnormal device set is parsed to obtain an abnormal device set.
[0046] Step 230 : before each device is registered, the device is matched with the abnormal device set.
[0047] Step 240, when the matching is successful, a permissionless error is returned to the successfully matched device to skip the registration process of the device, and the unmatched device is registered normally.
[0048] Step 250: during the Linux system startup process or operation process, locate the abnormal device set and find that there is an abnormal device.
[0049] This embodiment adds the following steps: when the system is unstable, determine possible abnormal devices; add the possible abnormal devices to the abnormal device set, and the system also includes other devices of the same type as the possible abnormal devices. This makes it easier for developers to add possible abnormal devices to the abnormal device set when the system is unstable, and to set up devices of the same type as the possible abnormal devices in the system. This makes it easier for developers to troubleshoot abnormal devices by constantly adjusting the possible abnormal devices in the abnormal device set. It also makes it easier for developers to view relevant device information after the system starts normally. This further clarifies the cause of system instability.
[0050] In a preferred implementation of this embodiment, the method may further add the following steps: when a new hot-plug device is inserted, the hot-plug device is matched with the abnormal filtering parameters in the abnormal device set; when the match is successful, for the device corresponding to the abnormal filtering parameters, an operation not allowed error is returned to skip the registration process of the device. After the Linux system is normally started, some hot-plug devices, such as USB mouse or keyboard, and hot-plug storage devices, are inserted. For hot-plug (USB) devices, each time they are unplugged and then plugged back in, the device needs to be re-registered, and the above-mentioned device registration process needs to be re-implemented. Because the hot-plug device is an abnormal device in the filtering parameters, it will not be loaded. Using the above method, hot-plug devices can be filtered and checked.
[0051] Embodiment 3
[0052] Figure 3 is a schematic diagram of the structure of the device for checking abnormal devices in a Linux system provided by the third embodiment of the present invention, see Figure 3 , the Linux system abnormal device troubleshooting device comprises:
[0053] The parsing module 310 is used to parse a preset abnormal device set in the kernel startup phase to obtain an abnormal device set;
[0054] A matching module 320, used for matching each device with the abnormal device set before registering the device;
[0055] The registration module 330 is used to return an unauthorized error to the successfully matched device when the matching is successful, so as to skip the registration process of the device and perform normal registration on the unmatched device;
[0056] The positioning module 340 is used to locate abnormal devices in the abnormal device set during the startup or operation of the Linux system.
[0057] The Linux system abnormal device troubleshooting device provided in this embodiment obtains an abnormal device set by parsing a pre-set abnormal device set during the kernel startup phase; before each device is registered, the device is matched with the abnormal device set; when the match is successful, an unauthorized error is returned to the successfully matched device to skip the registration process of the device, and the unmatched device is normally registered; during the Linux system startup process or operation process, the abnormal device set is located to contain abnormal devices. Possible abnormal devices can be set to a pre-set abnormal device set. In the kernel startup phase, the abnormal device set is parsed, the abnormal devices in the abnormal device set are not registered, and whether there are abnormal devices in the abnormal device set is determined based on whether the system can be started correctly. Developers can find abnormal devices by constantly adjusting the abnormal device set.
[0058] Based on the above embodiments, the device further includes:
[0059] The query module is used to query the existing devices when the Linux system cannot start normally, and adjust the abnormal device set according to the existing devices.
[0060] Based on the above embodiments, the device further includes:
[0061] Added a module for adding anomaly filter device sets through the Linux kernel boot item kernel command-line parameter.
[0062] Based on the above embodiments, the analysis module includes:
[0063] A parsing unit, used for parsing a preset abnormal device set by using kernel parameters defined in kernel command-line parameters of a kernel startup item;
[0064] The kernel command-line parameters of the kernel startup item include:
[0065] early_param(), used by the kernel to parse command line arguments at boot time;
[0066] module_param(), used to pass kernel parameters;
[0067] core_param(), used to define core kernel parameters;
[0068] __setup(), used to define kernel startup parameters.
[0069] Based on the above embodiments, the device further includes:
[0070] The driver loading module is used to use the bus driver matching rules to find the registered device and load the device driver of the device.
[0071] Based on the above embodiments, the device further includes:
[0072] A determination module is used to determine possible abnormal devices when the system is unstable;
[0073] The adding module is used to add the possible abnormal device to the abnormal device set. The system also includes other devices of the same type as the possible abnormal device.
[0074] Based on the above embodiments, the device further includes:
[0075] A hot-plug device matching module, used for matching the hot-plug device with the abnormal filtering parameters in the abnormal device set when a new hot-plug device is inserted;
[0076] The return module is used to return the operation not allowing errors to the device corresponding to the abnormal filtering parameter when the match is successful, so as to skip the registration process of the device.
[0077] The Linux system abnormal device troubleshooting device provided in the embodiment of the present invention can execute the Linux system abnormal device troubleshooting method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0078] Embodiment 4
[0079] Embodiment 4 of the present invention further provides a storage medium comprising computer executable instructions, wherein the computer executable instructions, when executed by a computer processor, are used to execute the method for troubleshooting abnormal devices in a Linux system as described in any one of the above embodiments.
[0080] The computer storage medium of the embodiment 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, device or device, or any combination thereof. More specific examples (non-exhaustive list) of computer-readable storage media include: an electrical connection with 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 thereof. In this document, a computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution system, device or device.
[0081] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, which carry computer-readable program code. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0082] Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
[0083] Computer program code for performing the operation of the present invention may be written in one or more programming languages or a combination thereof, including object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or device. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0084] Note that the above are only preferred embodiments of the present invention and the technical principles used. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection 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, and may include more other equivalent embodiments without departing from the concept of the present invention, and the scope of the present invention is determined by the scope of the appended claims.
Claims
1. A method for troubleshooting abnormal devices in a Linux system, characterized in that: include: In the kernel startup phase, a preset abnormal device set is parsed to obtain an abnormal device set; Before each device is registered, matching the device with the abnormal device set; When the matching is successful, an unauthorized error is returned to the successfully matched device to skip the registration process of the device, and the unmatched device is registered normally; During the Linux system startup or operation, the abnormal device set is located to contain an abnormal device.
2. The method according to claim 1, characterized in that The method further comprises: When the Linux system cannot be started normally, the existing devices are queried, and the abnormal device set is adjusted according to the existing devices.
3. The method according to claim 1, characterized in that Before parsing the preset abnormal device set, the method further includes: Add the exception device set through the Linux kernel startup item kernel command-line parameter.
4. The method according to claim 1, characterized in that: The analysis of the preset abnormal device set includes: Utilize kernel parameters defined in kernel command-line parameters of kernel startup item to parse pre-set abnormal device set; The kernel command-line parameters of the kernel startup item include: early_param(), used by the kernel to parse command line arguments at boot time; module_param(), used to pass kernel parameters; core_param(), used to define core kernel parameters; __setup(), used to define kernel startup parameters.
5. The method according to claim 1, characterized in that The method further comprises: The bus driver matching rules are used to find the registered device and load the device driver of the device.
6. The method according to claim 1, characterized in that The method further comprises: When the system is unstable, identify possible abnormal devices; The possibly abnormal device is added to the abnormal device set, and the system also includes other devices of the same type as the possibly abnormal device.
7. The method according to claim 1, characterized in that The method further comprises: When a new hot-plug device is inserted, matching the hot-plug device with the abnormal filtering parameters in the abnormal device set; When the match is successful, an unauthorized error is returned to the device corresponding to the abnormal filtering parameter to skip the registration process of the device.
8. A Linux system abnormal device troubleshooting device, characterized in that: include: A parsing module is used to parse a preset abnormal device set during the kernel startup phase to obtain an abnormal device set; A matching module, used for matching each device with the abnormal device set before registering the device; The registration module is used to return an unauthorized error to the successfully matched device when the match is successful, so as to skip the registration process of the device and perform normal registration on the pre-registered device that has not been successfully matched; The positioning module is used to locate the abnormal device in the abnormal device set during the startup process or operation process of the Linux system.
9. A storage medium containing computer executable instructions, characterized in that: The computer executable instructions are used to execute the Linux system abnormal device troubleshooting method as described in any one of claims 1-7 when executed by a computer processor.
Citation Information
Patent Citations
Mirror image file making and starting method of diskless system
CN109783117A
Operating system starting method and electronic equipment
CN113835761A