CN102262543B - Power-failure resistant method for starting Linux system - Google Patents

Power-failure resistant method for starting Linux system Download PDF

Info

Publication number
CN102262543B
CN102262543B CN201010181899.3A CN201010181899A CN102262543B CN 102262543 B CN102262543 B CN 102262543B CN 201010181899 A CN201010181899 A CN 201010181899A CN 102262543 B CN102262543 B CN 102262543B
Authority
CN
China
Prior art keywords
file
read
write
root
files
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201010181899.3A
Other languages
Chinese (zh)
Other versions
CN102262543A (en
Inventor
兰雨晴
李文昌
董恩广
王钧
钟伟
黄世林
张木梁
夏颖
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
China Standard Software Co Ltd
Original Assignee
China Standard Software Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by China Standard Software Co Ltd filed Critical China Standard Software Co Ltd
Priority to CN201010181899.3A priority Critical patent/CN102262543B/en
Publication of CN102262543A publication Critical patent/CN102262543A/en
Application granted granted Critical
Publication of CN102262543B publication Critical patent/CN102262543B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Stored Programmes (AREA)

Abstract

The invention relates to a power-failure resistant method for starting a Linux system. The method comprises the following steps of: establishing read-write copies of four system folders, namely /etc, /root, /var and /tmp, in an internal memory; and starting a system by operating the read-write copies of the four system folders to keep a root file system, on a disk, read-only in the process of starting and operating and meet the requirements that the four system file folders, namely /etc, /root, /var and /tmp, are in a read-write state during the starting and operating of Xwindow. Therefore, even if power failure frequently occurs, the system can be normally started, and the hidden danger of instability or even inoperability brought by loss or damage of the file system caused by write-in operation of the disk is avoided.

Description

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.

Claims (6)

1. the linux system starting method of an anti-power down, 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 this system file 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, the root file system of take on maintenance disk is a read states in start-up and operation process always, it is characterized in that, the method comprises:
An initialization step, by the mode of carry file system again, utilizes four critical file catalogue/etc ,/root under root file system ,/var is carried out again to carry and become four read-write files under memory file system with/tmp;
A file recovering step, by four critical file/etc under root file system, / root, / var and/file content of tmp is written in four read-write files of carry, this system 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, the compressed package of described three critical files folder is unziped to respectively in the read-write file that corresponding carry is memory file system.
2. the linux system starting method of anti-power down as claimed in claim 1, it is characterized in that: the mode of the described file system of carry is again to utilize memory file system---tmpfs, by carry order mount, by described four whole carries of critical file catalogue, be memory file system, and make these four file copies be made as read-write state.
3. the linux system starting method of anti-power down as claimed in claim 2, it is characterized in that: described initialization step is also included 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 start-up and operation process, all keep a reading mode.
4. the linux system starting method of anti-power down as claimed in claim 1, is characterized in that: to the write operation of four read-write files of carry, need to avoid being written in disk, to eliminate read-write operation, disk be caused to the hidden danger of damage.
5. the linux system starting method of anti-power down as claimed in claim 1, is characterized in that: the execution of initialization and file recovering step need to and start between these two steps of system service in initrd.img decompress(ion) operation opportunity be carried out.
6. the linux system starting method of anti-power down as claimed in claim 1, is characterized in that: under described particular category and this particular category, deposit /etc ,/root and/compressed package of tri-critical files folders of var prepares when custom-built system.
CN201010181899.3A 2010-05-25 2010-05-25 Power-failure resistant method for starting Linux system Active CN102262543B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201010181899.3A CN102262543B (en) 2010-05-25 2010-05-25 Power-failure resistant method for starting Linux system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201010181899.3A CN102262543B (en) 2010-05-25 2010-05-25 Power-failure resistant method for starting Linux system

Publications (2)

Publication Number Publication Date
CN102262543A CN102262543A (en) 2011-11-30
CN102262543B true CN102262543B (en) 2014-01-15

Family

ID=45009181

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201010181899.3A Active CN102262543B (en) 2010-05-25 2010-05-25 Power-failure resistant method for starting Linux system

Country Status (1)

Country Link
CN (1) CN102262543B (en)

Families Citing this family (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2016045101A1 (en) * 2014-09-26 2016-03-31 宇龙计算机通信科技(深圳)有限公司 Method and apparatus for protecting operating system partition, and terminal
CN104392189B (en) * 2014-12-12 2017-10-10 北京元心科技有限公司 The method and apparatus for realizing file system safe operation
CN105808269B (en) * 2014-12-30 2019-11-12 Tcl集团股份有限公司 A kind of method and device that application is installed to virtual SD card
CN105912426A (en) * 2016-04-28 2016-08-31 浪潮(北京)电子信息产业有限公司 K-UX operating system reduction method and system
CN106649152A (en) * 2016-12-29 2017-05-10 郑州云海信息技术有限公司 System log storage method and device based on non-volatile memory
CN108920215A (en) * 2018-07-18 2018-11-30 郑州云海信息技术有限公司 A method of passing through initramfs collection system log
CN109634669B (en) * 2018-11-20 2021-08-17 锐捷网络股份有限公司 Starting method and device of embedded system
CN110413230B (en) * 2019-07-12 2023-01-06 湖南建工集团有限公司 Embedded system construction method and storage medium
CN111143267A (en) * 2019-12-31 2020-05-12 郑州信大捷安信息技术股份有限公司 Hot plug method and system based on Linux system disk

Non-Patent Citations (6)

* Cited by examiner, † Cited by third party
Title
[转载]把Linux塞在CF卡/U盘中;Lv (My sight are yours);《BBS大漠孤烟站(展开完整界面)/电脑技术/精华区文章阅读》;20051108;第1-2页 *
Lv (My sight are yours).[转载]把Linux塞在CF卡/U盘中.《BBS大漠孤烟站(展开完整界面)/电脑技术/精华区文章阅读》.2005,
mufa.让硬碟只在关机时才进行写入动作.《摩托学园讨论区-检视主题》.2009,
Unionfs:联合文件系统;yjmwolf;《Linux文档专区-ChinaUnix.net》;20070517;第2页 *
yjmwolf.Unionfs:联合文件系统.《Linux文档专区-ChinaUnix.net》.2007,
让硬碟只在关机时才进行写入动作;mufa;《摩托学园讨论区-检视主题》;20091227;第1-2页 *

Also Published As

Publication number Publication date
CN102262543A (en) 2011-11-30

Similar Documents

Publication Publication Date Title
CN102262543B (en) Power-failure resistant method for starting Linux system
CN102262568B (en) Power-down prevention Linux system startup method
EP1907935B1 (en) System and method for virtualizing backup images
US6618736B1 (en) Template-based creation and archival of file systems
CN102473089B (en) File system for dual operating systems
US8261035B1 (en) System and method for online data migration
KR101636870B1 (en) Method and apparatus for generating minimal boot image
US20170286234A1 (en) System and method for live virtual incremental restoring of data from cloud storage
CN103365696B (en) BIOS image file acquisition methods and device
CN105446826A (en) Virtual machine backup and recovery method and device
EP3769224B1 (en) Configurable recovery states
CN101506776A (en) In-line non volatile memory disk read cache and write buffer
CN102141923B (en) Memory file system loading method and device
US20060200500A1 (en) Method of efficiently recovering database
US6901481B2 (en) Method and apparatus for storing transactional information in persistent memory
CN115098299B (en) Backup method, disaster recovery method, device and equipment of virtual machine
CN104751062A (en) Method and device improving operation system reliability
US10564894B2 (en) Free space pass-through
CN110134545A (en) The method and system of the virtual NVRAM of offer based on credible performing environment
EP2490123A2 (en) An embedded appliance
CN112148532A (en) Batch recovery method and device for hard disk data, storage medium and electronic equipment
CN100547550C (en) Install and be written into the system and method for installation system supervisory routine behind the operating system of user
CN117033085B (en) kvm virtual machine backup method and device, computer equipment and storage medium
KR101460452B1 (en) Apparatus of generating snapshot image based on hibernation and method of the same
CN112685233A (en) Data backup and restoration method and device based on Linux operating system

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
ASS Succession or assignment of patent right

Owner name: CHINA STANDARD SOFTWARE CO., LTD.

Free format text: FORMER OWNER: SHANGHAI ZHONGBIAO SOFTWARE CO. LTD.

Effective date: 20120305

C41 Transfer of patent application or patent right or utility model
TA01 Transfer of patent application right

Effective date of registration: 20120305

Address after: 200030 room 1006-1010, Panyu Road, Shanghai, 1028

Applicant after: China Standard Software Co., Ltd.

Address before: 200030 Panyu Road, Shanghai, No. 10, building 1028, building

Applicant before: Shanghai Zhongbiao Software Co., Ltd.

C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant