1. Field of the Invention
The present invention relates to a method for restoring a booted system, and more particularly, to such a method for a device of an embedded Linux system to boot normally.
2. Description of Related Art
According to the definition of the Institute of Electrical Engineers (IEE), an “embedded System” is a control, monitoring, or accessory equipment, machine, or even a factory-operating device, and the embedded system is integrated with a computer software and hardware that can meet the “Custom-made” principle. In other words, it is a system developed according to a certain specific application. Since the embedded system can enhance the stability and portability of a product, lower the cost, and add specific functions, etc, therefore the embedded systems are extensively used. At present, the common embedded systems include VxWORK, QNX, Palm OS, Windows CE, and Linux, etc, and wherein the embedded Linux system has an advantage of free license, and thus the embedded Linux system is used by most users.
The development of the embedded Linux system requires the following three basic elements: a boot loader, a Linux kernel and a root file system, and the Linux kernel and the root file system are read-only files such as CRAMFS or ROMFS installed into a flash memory for users to boot a system. Since the root file system is a read-only file, users cannot write an application program into the root file system, and thus making some of the application programs unusable. Therefore, related R&D engineers load the root file system into a RAM disk, so that the application program can write in the root file system in the RAM disk. However, the root file system in the RAM disk will be totally erased when the system is turned off, and it is necessary to repeat the foregoing procedure for a use of next time, and such arrangement is very inconvenient.
To solve the foregoing problem, some manufacturers store the Linux kernel and the root file system in separate blocks of a flash memory. Referring to
However, such arrangement still has a serious issue. If a power failure occurs while the root file system is writing in a file, the root file system will be damaged and unrepairable. As a result, the system cannot be booted.
The present invention has been accomplished under the circumstance in view. It is therefore the main objective of the present invention to use a read-only block and a read/write block of a flash memory of a device to separately store a mini root file system and a user root file system, and install a detect program to the mini root file system, such that when the device is booted, the detect program will be executed first to detect whether or not the user root file system is damaged in order to determine using the mini root file system or the user root file system as the embedded Linux system. The present invention can prevent the device from being unusable due to the damage of the root file system.
Referring to
Refer to
(100) turning on the device;
(110) executing the boot loader in the embedded Linux system, and loading the Linux Kernel into the memory for the execution;
(120) executing the detect program in the mini root file system to detect whether or not the user root file system is damaged; if the detected user root file system is not damaged, then carry out step (130); and if the detected user root file system is damaged, then carry out step (140);
(130) using the user root file system to mount the system; and
(140) using the mini root file system to mount the system.
Even if the user root file system is damaged, the embedded Linux system still can use the mini root file system to mount the system. After the device is booted, the user root file system can be repaired so as to avoid the situation of unable to use the device as it does in the prior art.
Further, when the detect program detects whether or not the user root file system is damaged; the user root file system will be mounted to a subdirectory of the mini root file system, and confirms whether or not the mount is successful. If the mount is successful, the detect program will continuing to determine whether or not the user root file system mounted to the subdirectory of the mini root file system is damaged. If the user root file system is not damaged, then the detect program will continue to check whether or not the user root file system includes programs such as sbin/init, bin/bash, bin/sh, and etc/inittab. If the user root file system includes all the aforementioned programs, then the user root file system is not damaged. If any of the foregoing programs detected by the detect program is missing, then the user root file system is damaged.
The main characteristic of the method for restoring a booted system in accordance with the present invention resides on dividing a prior art root file system into a mini root file system and a user root file system, and storing the mini root file system and the user root file system in a read-only block and a read/write block respectively, and adding a detect program in the mini root file system, such that when the device is booted, the detect program will be executed first to detect whether or not the user root file system is damaged. If the user root file system is not damaged, the user root file system will be used as the embedded Linux system. If the user root file system is damaged, the mini root file system will be used as the embedded Linux system. Therefore, other application programs can be written in the user root file system. Even if the user root file system is damaged, the mini root file system can be used for booting, and thus avoiding the device from being unusable at all.