Disclosure of Invention
The invention provides a hard disk binding starting method based on an Initrd file system, which solves the problem that hard disk binding needs additional assistance of customized hardware, can identify a risk point to prevent abnormal starting at the system starting stage, and ensures safe starting.
In order to achieve the above and other related objects, the present invention provides a hard disk binding startup method based on an Initrd file system, including:
writing a unique hard disk serial number in the computer system;
adding an authentication program of a hard disk serial number in an Initrd file system;
and starting the computer system, authenticating the hard disk serial number by the authentication program, normally starting the computer system if the hard disk serial number authenticated by the authentication program is consistent with the unique hard disk serial number, and shutting down the computer system if the hard disk serial number authenticated by the authentication program is inconsistent with the unique hard disk serial number.
Preferably, the writing of the unique hard disk serial number in the computer system specifically includes:
selecting a partition in the computer system as a particular partition;
acquiring the disk number of the disk where the specific partition is located;
acquiring a unique serial number of a hard disk according to the disk partition of the disk where the specific partition is located;
and writing the unique serial number of the hard disk into a mark file.
Preferably, the authentication program performs authentication of the hard disk serial number, and specifically includes:
detecting whether the computer system has the mark file or not, if so, performing the next authentication, and if not, shutting down the computer system;
detecting whether the specific partition exists, if so, detecting the disk number of a disk where the specific partition is located, and acquiring a corresponding hard disk serial number according to the disk number; if not, shutting down the machine;
and judging whether the hard disk serial number is consistent with the unique hard disk serial number, if so, successfully authenticating, normally starting the computer system, and if not, failing to authenticate, and shutting down the computer system.
Preferably, the corresponding hard disk serial number is obtained according to the disk number through an hdparm command.
Preferably, the method further comprises testing the hard disk binding start method, and specifically comprises:
manufacturing a mirrored system of the computer system;
and installing the mirror image system and restarting the system for testing.
Preferably, the manufacturing of the mirror image system of the computer system specifically includes:
writing the technology for writing the unique hard disk serial number in the computer system and the authentication technology of the authentication program into a binary package;
writing the binary package to a computer system and manufacturing a mirrored system of the computer system.
Preferably, the testing specifically comprises:
installing the mirror system;
normally starting without replacing the hard disk, and checking whether the prompt message is normal;
replacing the hard disk with the mark file, and checking whether the mirror image system can be normally started;
and replacing the hard disk with the specific partition, and checking whether the mirror image system can be normally started.
Based on the same inventive concept, the present invention also provides an electronic device comprising a processor and a memory, wherein the memory stores a computer program, and the computer program realizes the method of any one of the above items when being executed by the processor.
Based on the same inventive concept, the present invention further provides a readable storage medium, in which a computer program is stored, and the computer program, when executed by a processor, implements the method of any one of the above.
In conclusion, the invention provides a hard disk binding starting method based on the Initrd file system, which solves the problem that the hard disk binding needs additional assistance of hardware customization, identifies the risk point to prevent the abnormal starting condition in the system starting stage, and ensures the safe starting; furthermore, the key mark information of the hard disk comprises the serial number and the partition condition of the hard disk, so that the authentication of the hard disk is enhanced; still further, the invention is convenient for managing and transplanting the binary package in the writing and authentication process of the hard disk serial number to other platforms.
Detailed Description
The hard disk binding startup method based on the Initrd file system proposed by the present invention is further described in detail with reference to fig. 1-2 and the detailed description below. The advantages and features of the present invention will become more apparent from the following description. It is to be noted that the drawings are in a very simplified form and are all used in a non-precise scale for the purpose of facilitating and distinctly aiding in the description of the embodiments of the present invention. To make the objects, features and advantages of the present invention comprehensible, reference is made to the accompanying drawings. It should be understood that the structures, ratios, sizes, and the like shown in the drawings and described in the specification are only used for matching with the disclosure of the specification, so as to be understood and read by those skilled in the art, and are not used to limit the implementation conditions of the present invention, so that the present invention has no technical significance, and any structural modification, ratio relationship change or size adjustment should still fall within the scope of the present invention without affecting the efficacy and the achievable purpose of the present invention.
First, technical terms related to the present invention will be described.
initrd file system: refers to an initial root file system that is mounted into the system before the actual root file system is available. initrd is bound to the kernel and is loaded as part of the kernel boot process. The kernel will then load the module with this initrd file as part of its two-phase boot process, so that the real file system can be used later and the actual root file system mounted.
Hard disk binding: refers to the authentication of the unique identity of the hard disk firmware.
Referring to fig. 1, the present invention provides a hard disk binding startup method based on an Initrd file system, including the following steps:
and S100, writing the unique hard disk serial number into the computer system.
In this embodiment, as for step S100, specifically, based on an ARM/MIPS hardware platform and a software environment of a domestic standard kylin desktop operating system, writing a unique serial number into a hard disk is added in an installer, and the serial number is written into a designated file, so that the serial number is conveniently authenticated when the system is started.
The writing step comprises:
1) detecting whether the operating system uses a single disk or a double disk, and if the operating system uses a single disk, writing a subsequent hard disk serial number into a flag file, for example: (iv)/etc/HOMESILBLE; if it is a dual disc, another flag file is written, for example: /ete/HOMEDBLE.
2) Selecting a partition in the computer system as a particular partition;
3) acquiring the disk number of a disk where the specific partition (such as the HOME partition) is located;
4) acquiring a unique serial number of a hard disk according to the disk partition of the disk where the specific partition is located;
5) writing the unique serial number of the hard disk into a mark file to facilitate subsequent authentication;
s200, adding an authentication program of a hard disk serial number in an Initrd file system;
s300, starting the computer system, authenticating the hard disk serial number by the authentication program, normally starting if the hard disk serial number authenticated by the authentication program is consistent with the unique hard disk serial number, and shutting down if the hard disk serial number authenticated by the authentication program is inconsistent with the unique hard disk serial number.
In this embodiment, as for step S300, the serial number of the system hard disk authenticated in the initrd system includes a plurality of detailed steps, and the specific flow is as shown in fig. 2:
1) detecting and judging that the starting system is a mark file of a single disk or a double disk, if the mark file (such as/etc/HOMENGLE or/ete/HOMEDBLE) exists, giving related prompt information, continuing the next step, and if the mark file does not exist, shutting down the system after the prompt information;
2) judging whether the specific partition exists, if so, giving related prompt information and then carrying out next detection, and if not, shutting down the prompt information;
3) detecting the disk number of the disk where the specific partition (such as the HOME partition) is located when the system is started:
4) the hard disk serial number corresponding to the disk number is inquired through the hdparm command, which refers to the parameter for detecting, displaying and setting IDE or SCSI hard disk and is a common tool for testing the hard disk reading performance.
5) And comparing 4) whether the serial number read in the step is consistent with the serial number written in the mark file (/ etc/HOMESINGLE or/ete/HOMEDBLE) in the system, if the serial numbers are consistent, the hard disk is not replaced, the hard disk can be safely started, and if the serial numbers are not consistent, the information is prompted to be shut down.
In this embodiment, the method further includes testing the hard disk binding start method, and specifically includes:
1) manufacturing a mirrored system of the computer system;
2) and installing the mirror image system and restarting the system for testing.
In this embodiment, the manufacturing of the mirror system of the computer system specifically includes:
1) writing the technology for writing the unique hard disk serial number in the computer system and the authentication technology of the authentication program into a binary package;
2) writing the binary package to a computer system and manufacturing a mirrored system of the computer system.
In this embodiment, the testing specifically includes:
1) installing the mirror system;
2) normally starting without replacing the hard disk, checking whether the prompt message is normal, if normal, completing the first layer test, and performing the second layer test, if not, the technology of writing the unique hard disk serial number in the computer system or the authentication technology of the authentication program has problems.
Changing the hard disk with the mark file, checking whether the mirror system can be normally started, if the mirror system can be normally started, the technology of writing the unique hard disk serial number in the computer system or the authentication technology of the authentication program has problems, and if the mirror system can not be normally started, completing the second-layer test and carrying out a third-layer test;
and replacing the hard disk with the specific partition, checking whether the mirror system can be normally started, if the mirror system can be normally started, solving the problem in the technology of writing the unique hard disk serial number in the computer system or the authentication technology of the authentication program, and if the mirror system can not be normally started, completing the test of the third layer so as to complete the test of the method.
Based on the same inventive concept, the invention further provides an electronic device, which includes a processor and a memory, where the memory stores a computer program, and when the computer program is executed by the processor, the method for binding and starting a hard disk based on the Initrd file system is implemented.
The processor may be, in some embodiments, a Central Processing Unit (CPU), a controller, a microcontroller, a microprocessor (e.g., a GPU), or other data Processing chip. The processor is typically used to control the overall operation of the electronic device. In this embodiment, the processor is configured to run a program code stored in the memory or process data, for example, run a program code of the hard disk binding startup method based on the Initrd file system.
The memory includes at least one type of readable storage medium including a flash memory, a hard disk, a multimedia card, a card type memory (e.g., SD or DX memory, etc.), a Random Access Memory (RAM), a Static Random Access Memory (SRAM), a Read Only Memory (ROM), an Electrically Erasable Programmable Read Only Memory (EEPROM), a Programmable Read Only Memory (PROM), a magnetic memory, a magnetic disk, an optical disk, etc. In some embodiments, the storage may be an internal storage unit of the electronic device, such as a hard disk or a memory of the electronic device. In other embodiments, the memory may also be an external storage device of the electronic device, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like provided on the electronic device. Of course, the memory may also include both internal and external memory units of the electronic device. In this embodiment, the memory is generally used to store an operating method installed in the electronic device and various types of application software, such as a program code of a hard disk binding start method based on the Initrd file system. In addition, the memory may also be used to temporarily store various types of data that have been output or are to be output.
Based on the same idea, the invention further provides a readable storage medium, in which a computer program is stored, and when the computer program is executed by a processor, the hard disk binding starting method based on the Initrd file system is implemented.
The invention has the advantages that the hard disk binding starting method based on the Initrd file system is provided, the problem that the hard disk binding needs additional assistance of hardware customization is solved, the risk point is identified in the system starting stage to prevent abnormal starting, and safe starting is ensured; furthermore, the key mark information of the hard disk comprises the serial number and the partition condition of the hard disk, so that the authentication of the hard disk is enhanced; still further, the invention is convenient for managing and transplanting the binary package in the writing and authentication process of the hard disk serial number to other platforms.
While the present invention has been described in detail with reference to the preferred embodiments, it should be understood that the above description should not be taken as limiting the invention. Various modifications and alterations to this invention will become apparent to those skilled in the art upon reading the foregoing description. Accordingly, the scope of the invention should be determined from the following claims.