The linux system starting method of anti-power down
Technical field
The present invention relates to a kind of starting method of linux system, especially a kind of starting method of anti-power down.
Background technology
In the similar Linux custom-built system such as information issuing system and set-top-box system, in practical application, all can there is such class demand, be exactly after the direct power-off of user, operating system in box still can normally start, do not allow to occur causing file system corruption, the situation that causes operating system normally to start because of power down suddenly.
To this class situation, general way is, adopt log type file system, based on daily record, disk is checked to reparation, significantly reduce file system needed time of consistance for recovery file system when running into the uncertain events such as disconnection fault, can say, this method can solve under the general-purpose operating system substantially, causes damaging the problem of file system during unexpected powering-off state.Yet, in the Linux custom-built systems such as information issuing system and set-top-box system, what user often adopted is the shutdown mode of direct power-off, when there is the situation of so frequent power-off, adopt log type file system to enable disk check faster and repair, also still can not avoid the loss of file system and the problem of imperfection completely, this problem is that user is receptible anything but in the middle of practical application.Meanwhile, along with the increase that these mistakes are accumulated over a long period, the continuous loss of file and damage directly have influence on the normal operation of system, and unique way of dealing with problems is exactly formatted file system, reinstalls operating system.This brings a large amount of workloads will to virtually later stage system maintenance, has increased the maintenance cost of operator.
Under just current Linux, no matter the file system of frequent use, be EXT2, EXT3, and XFS, or REISERFS, no matter and first whether they support the write-in functions of daily record to disk, but all cannot avoid the write operation to disk.And as long as occur the physics of disk to write, so just there is the possibility of file corruption, the hidden danger that operating system also exists the instability brought because of File lose or damage can not move even completely.
Summary of the invention
Because log type file system can not meet the requirement to file system protection of information issuing system and set-top-box system, also can increase no small workload to later maintenance work simultaneously.Therefore, object of the present invention for these two problems, fundamentally provides a solution thoroughly just, guarantees that direct power-off can not cause above-mentioned impact to file system, from function and operation cost, meets user's demand, reaches the target reducing costs.
As shown in Figure 1, in general (SuSE) Linux OS, after system starts, after particularly Xwindow starts, whole root file system is read-write state.Meanwhile, when Xwindow normally moves, must assurances/etc ,/root ,/var with/this four systems file of tmp in read-write state, otherwise the normal start-up and operation of Xwindow.
In this case, should protect the root file system can be not damaged, make again Xwindow normally start, main thought of the present invention is: by foundation/etc in internal memory, / root, / var and/the read-write copy of this four systems file of tmp, so that the copy of those system files became read-write state for system call before Xwindow starts, meet the read-write requirement of system Start-up and operating performance to those system files, and carry out startup system by calling the read-write copy of described four systems file, the root file system of take on maintenance disk is a read states in start-up and operation process always.
Keep whole root file system in start-up and operation process, to keep a read states, from system, start to start just to avoid the write operation to disk, this is to allow the key point of the anti-power down of file system, is also core of the present invention; Allow/etc ,/root ,/var and/this four systems file of tmp became read-write state before Xwindow starts, guarantee Xwindow normally starts like this, the application program on operation.
Realize and state above-mentioned purpose, the present invention includes an initialization step, by the mode of carry file system again, four critical file catalogue/etc ,/root under root file system ,/var are carried out again to carry and become four read-write files under memory file system with/tmp; A file recovering step, recovers the content of above-mentioned four files.
The mode of the described file system of carry is again to utilize memory file system---tmpfs, by carry order mount, is memory file system by four whole carries of crucial catalogue described in this, makes these four files just become four empty read-write files.
Wherein, initialization step can be in general linux system, by this crucial script rc.sysinit file in change system starting process, the instruction of the carry again existing in described four critical files is commented out or deleted, thereby realize root file system, in startup and Xwindow operational process, all keep a reading mode.
Described file recovering step refer to by four critical file/etc ,/root under root file system ,/var and/file content of tmp is written in four read-write files of carry.
This system separately comprises a particular category, under root file system /etc ,/root and/tri-critical files of var folder uses tools of compression break into compressed package and deposit under this particular category, the concrete mode of said write comprises by decompression order, by described/etc ,/root and/compressed package of tri-critical files folders of var unzips to respectively in the read-write file that corresponding carry is memory file system.Such as, can increase the decompress(ion) part of compressed package by rc.sysinit file is changed, then by decompression order, by three system file compressed packages difference decompress(ion)s under particular category.
Now, system /etc, / root and/tri-files of var are all read-write, simultaneity factor file is also complete by the method full recovery decompressing, and/tmp file is also read-write, so, four critical files press from both sides read-write condition and so far all meet, and system comprises the execution that Xwindow now can order and moved.
The mode of the mode of above-mentioned writing in files except decompressing, can also adopt alternate manner to carry out, for example, utilize file system to copy in the read-write file that corresponding backup file is memory file system to corresponding carry.
Wherein, for the write operation of four read-write files of carry, need to avoid being written in disk, could fundamentally eliminate like this read-write operation and disk be caused to the hidden danger of damage.
The execution of initialization and file recovering step need to be carried out opportunity between initrd.img decompress(ion) operation and these two steps of startup system service.
In the present embodiment, under described particular category and particular category, deposit /etc ,/root and/compressed package of tri-critical files of var folder prepares when custom-built system.Core content of the present invention is by allowing operating system in normal operational process; keep root file system all the time in a read states; fundamentally avoid the write operation of operating system to disk completely, thereby reach the object of protected file system, realize perfect anti-power down scheme.
Principal feature of the present invention is embodied in:
(1) adopted the Starting mode of memory file system, and all files all rest in the middle of physical memory, when having guaranteed that file is read-write, also promoted the read or write speed for file;
(2) adopt the method for file compressed package decompress(ion), do not rely on any special file system and instrument, principle is simple, easy to use.
The explanation of nouns of the relevant technical terms the present invention relates to:
Carry: refer to an equipment (normally memory device) to be articulated in a catalogue having existed (this catalogue can be for not empty, but after carry the content before under this catalogue by unavailable).If want the file in accessing storage device, the subregion at the file place that must will access is mounted in a catalogue having existed, and then by accessing this catalogue, visits the file of memory device.
File system: be in charge of in operating system with the software mechanism of storage file information and be called file management system, be called for short file system.File system is comprised of three parts: the software relevant with file management, the file being managed and the required data structure of enforcement file management.From system perspective, file system is that file memory space is organized and distributed, and is responsible for the storage of file the system that the file depositing in is protected and retrieved.Specifically, it is responsible for user and sets up file, deposits in, reads, modification, dump file, and the work such as file are cancelled in the access of control documents when user does not re-use.
Memory file system: the file of carry in this document system is to be all stored under virtual memory, the virtual memory here comprises that (it is exactly the virtual memory subregion under LINUX that virtual memory subregion is again in exchange partition for physical memory and exchange partition, its effect is after physical memory uses, and disk space (namely SWAP subregion) is invented to internal memory and use.It should be noted that, although this SWAP subregion can be as the internal memory of " virtual ", but its speed is more slowly than physical memory, if therefore need speed faster, can not post great expectations in SWAP, best bet remains increasing physical memory, and SWAP subregion is interim solution).
X Window system: be often called X11 or X, it is a kind of software windows system showing in bitmap mode, the research of Massachusetts Institute of Technology (MIT) in 1984 at first, become afterwards the operating systems such as UNIX, class UNIX and openVMS the unanimously running agreement of applicable standardized software suite of tools and display framework, see through Software tool and framework and reach an agreement on to set up operating system graphic user interface used, after this expansion is adapted in other operating systems that each shape is of all kinds gradually, and nowadays nearly all modernity operating system can be supported and use X.
Because X is suite of tools and framework standard, itself there is no the entity of actual participation running, so must there be people to develop and write according to this standard, so just there is really available, executable entity, this can be described as realizes body.XFree86 is a realization of XWindow system, and from 1992 to 2004, it with the open source code mode development of freely providing always.2004, the exploitation of XFree86, because difference appears in software license, developed from XFree864.4RC2 version source code and derive another, is named as the XWindow system of X.Org server.
At present according to the standard framework of X, develop realizing in body of being formulated as, the most general and most popular with X.Org, and popular in the Unix style operating system of increasing income gradually.X.Org protocol revision X11 used issued in September, 1987, now up-to-date reference implementation (referential, exemplary implementation) version is that X11 Release 7.1 (is called for short: X11R7.1), and this special project is by the X.Org fund leader of club, and authorize and be free software under similar authorization at MIT.
Accompanying drawing explanation
Fig. 1 is that existing general linux system starts process flow diagram.
Fig. 2 is that the linux system of the anti-power down of the present invention starts process flow diagram.
Embodiment
For above-mentioned and other object of the present invention, feature and advantage can be become apparent, the preferred embodiments of the present invention cited below particularly, and coordinate accompanying drawing, be described in detail below:
The startup of linux system is roughly divided into six step: Grub guiding, Kernel starts, initrd.img decompress(ion) operation, the init application program of linux system is carried out rc.sysinit program, and system script rc starts system service and starts graphical interfaces Xwindow according to runlevel.The linux system that comprises anti-power down function starts process flow diagram as shown in Figure 2, and the concrete steps of realization comprise:
(1) linux system directly enters Grub boot (step 10) after starting, and Grub is by loading Grub.conf configuration file, the operating system of specified partition in boot configuration file.
(2) first step of guiding operating system is the kernel (system kernel) of loading system, and kernel starts (step 11), and after the kernel of system loaded, by system right of execution, gives kernel.Kernel, after obtaining right of execution, can survey current hardware and load corresponding driving, afterwards, initr.img is loaded in internal memory.
(3) first initrd.img can be decompressed in internal memory, initrd.img is a small files system, and after decompress(ion), kernel can be carried out the core script of this small files system, loads the drivings (step 12) such as USB, afterwards, right of execution is given to system initialization routine init.
(4) init program is carried out rc.sysinit program (step 13), first loads anti-power down process module, and this module need be carried out and comprise that initialization (step 131) and file recover (step 132) these two steps.The execution of initialization and file recovering step is extremely important opportunity, specifically need to and start between these two steps of system service (step 14) in initrd.img decompress(ion) operation (step 12) and carry out, otherwise system can cause normally starting because of disappearance system file.
Xwindows starts must use/etc, / root, / var and/these four special folder of tmp, if being placed in, the system file therefore needs being write is located at internal memory, can avoid disk file system to be destroyed the in the situation that of power-off suddenly, anti-power down process module in the present embodiment adopts file system decompression method, file system decompression method is specially for the problem of " these four special system files need to be set as read-write pattern " and the method adopting, the method can be divided into two steps, the one, initialization (step 131), being about to four file carries is read-write file, the 2nd, file recovers (step 132), the content in four files is recovered.
Initialization (step 131) need to four crucial catalogue/etc ,/root ,/var and/tmp carries out carry again, the fundamental purpose of carry is the read-write mode that changes file here.Here needing to use memory file system---tmpfs, by carry order mount, is memory file system by these four whole carries of catalogue, and these four files just become four empty read-write files like this.
File recovers (step 132) needs to do some preliminary works before carrying out: in the present embodiment by system/etc ,/root and/tri-critical files folders of var use tools of compression to break into compressed package, under particular category, set up a hidden folder, these three file compressed packages are copied into.These preliminary works just completed in advance before system starts.What need special instruction here is a bit, / tmp file does not need to break into compressed package, because under/tmp catalogue be all temporary file, in system starting process, need to from this file, not read any configuration information or use information, therefore/tmp catalogue is after carry is memory file system, be an empty folder, met the requirement that system starts.
It should be noted that, above-mentioned preliminary work, in the present embodiment before system starts, when customizing this system, just in advance in system all set/etc ,/root and/compressed package of tri-critical files folders of var, so that start at every turn, when can directly start for system, to start more fast.
After initialization (step 131) completes, carry out second step file and recover (step 132): rc.sysinit file is changed, increase the decompress(ion) part of compressed package, respectively by decompression order, three system file compressed packages under particular category are unziped to respectively under the catalogue that corresponding carry is memory file system, now, system /etc, / root and/tri-files of var are all read-write, simultaneity factor file is also complete by the method full recovery decompressing, and/tmp file is also read-write, so, four critical files press from both sides read-write condition and so far all meet, system comprise Xwindow now can order execution and moved.
It should be noted that above-mentioned file recovery step, except can be by being decompressed to the mode of memory file system, can also adopt directly by root file system on disk /etc ,/root and/read-write file that the backup content direct copying of the file of var is memory file system to the carry of correspondence in.
(5) when rc.sysinit execution is exited, actuator transfers to system script rc to start system service (step 14) according to runlevel.After starting system service (step 14), finally start graphical interfaces Xwindow (step 15), so far system starts complete.
The instrument of wanting required for the present invention, only comprise the memory file system that carries support in kernel---tmpfs and a compressed and decompressed instrument, do not need the support of alternative document system or upgrade kit, do not rely on special software or file system yet, implementation method is simply effective, and can within the shortest time, realize the target of moving Xwindow system on read-only file system, has met the requirement of anti-power down, reduce the operation maintenance cost of operator, met user's demand.
More than in the mode of carry file system again, make the system file that need to write be placed in physical memory, it is only explanation the preferred embodiment of the present invention, but not limit the scope of the invention, any those skilled in the art, without departing from the spirit and scope of the present invention, when doing a little change and retouching, be that all equalizations of doing according to the present invention change and modify, should be the scope of the claims of the present invention and contain.