A new method for implementing the embedded Linux System

Source: Internet
Author: User
A new method for implementing the embedded Linux system-general Linux technology-Linux programming and kernel information. For more information, see the following. Summary

In Linux, the system cannot be started properly due to file system damage and manual repair is required. This article uses the Linux memory disk initialization (INITRD) technology, and uses a part of the memory as the Linux root directory. Each time the system is started, the complete file system is extracted here, this prevents the system from starting from a corrupted file system. This not only enables the system to start normally, but also improves the system performance.

Introduction

In Linux, there is a special feature-initializing the memory Disk INITRD (INITial Ram Disk) technology, and the kernel supports compressed file system images. With these two functions, we can enable the Linux system to initialize the memory disk from an early stage and mount part of the system memory as the root file system, in addition, you do not need to use swap partitions (if you do not run X Windows, this is all possible). That is, you can completely embed the Linux system into the memory without relying on any other hard disks. At present, the PC memory is at least 128 MB, while the root file system only uses 30 MB. Therefore, not only will the performance of the entire machine be reduced, but it will be greatly improved.

Because the system does not work on the hard disk, the system eliminates the problem caused by the mechanical drive. Because the system runs in the memory, the root file system and operations are completely in the CPU/RAM environment, the system performance is very good in terms of speed and reliability; it will not damage the file system due to illegal shutdown, each time we start, we extract the compressed file system to the memory disk and mount it as the root file system.

1. Hardware requirements

For such a system, hardware does not need to be specially designed, but is only implemented through components on a common PC. It is worth mentioning that the system memory size should be at least 64 MB. Because 30 M is used as Ramdisk and more than 30 mb is used as the system, the normal operation of the system can be ensured. The current computer memory is generally 128 M, and this condition can be met. The only special one is a flash disk, which is equivalent to a hard disk with an IDE interface and is 20 mb in size. It is mainly used to start LILO and store the compressed package of the root file system.

2 Ramdisk usage

Ramdisk allocates a portion of the memory as a partition and uses it as a hard disk. For programs that are constantly used during system operation, placing them on Ramdisk will speed up computer operations, such as network servers with large data volumes and diskless workstations. In order to be able to use Ramdisk, We must select Ramdisk support in block device during kernel compilation. There are two options below. One is to set the Ramdisk size. The default value is 4096 k; the other is initrd support. It can be directly compiled into the kernel, compiled into modules, and loaded as needed. Since we use it at startup, We must compile it directly into the kernel.

If Ramdisk support has been compiled into the kernel, we can use it. First, create the directory ram under the/mnt directory, run mkdir/mnt/ram, then create a file system for/dev/ram0, and run mke2fs/dev/ram; finally, mount/dev/ram and run mount/dev/ram/mnt/ram to operate it like a general hard disk. It is worth noting that, when creating a file system, 1024 inodes and 4096 blocks are output on the screen, that is, the ramdisk size is 4 MB = 4096 blocks. However, after mounting, run df? When k/dev/ram is viewed, it is displayed that the ramdisk size is only 3963 K, because the file system occupies some space.

We can change the ramdisk location size as needed. If we want to increase the default 4 M to 10 M, when ramdisk is directly compiled into the kernel, We can configure the LILO file in lilo. add a line to the conf file: append = "ramdis_size = 10000". After LILO is run, after the computer is restarted, The ramdisk size changes to 10 MB, or ramdis_size = 10000, which is the parameter of the startup line; when ramdisk is compiled as a loadable module, You need to load the configuration file/etc/modules in the module. add a line in the conf file: options rd rd_size = 10000, or add a description after loading the rd module, that is, insmod rd rd_size = 10000.

3. Implementation Process

3.1 create a compressed file system

Our implementation process depends on the existing Linux system. First, start a general Linux system. In this system, create a suitable File System Based on your needs. For example, to implement an Apache network server, you only need to leave the commands, scripts, configuration files, and library functions required for system startup and basic maintenance, and add the ones required for implementing the Apache server. The specific process is as follows:

Create a directory/minlinux in Linux, where we create a file system. All static link libraries, man pages, info pages, header files, and kernel source code of the system are useless for system operation, so they are not needed. Some basic tools for system maintenance in the directory bin, such as ls, mv, grep, chown, chmod, chgrp, ln, rm, etc; in sbin, it is a common command for the system startup process, such as bash, e2fsck, mke2fs, fdisk, insmod, rmmod, depmod, modprobe, lsmod, shutdown, reboot, login, init, getty, mount, umount, etc; put Apache Application http and some other special tools in usr/bin. Then, the content in the lib directory is determined based on the dynamic link library required by these executable files. Of course, the configuration files under the etc directory and the device files under dev must all be available. They all correspond to executable files, because when many executable files are executed, generally, you can open the device and run it according to the configuration file. There is a special directory where proc should be set. In the kernel compilation option file system selection, we choose to support the file system proc, so after the system runs, it has a lot of content, these contents are generated by tracking the status of the system kernel and running processes in real time, but they do not occupy any disk space, but reside in the memory. In some cases, you can use it for system settings. Many tools obtain information from it, such as dmesg, ps, and top. The file system has been created. The size should be around 20 mb.

Next, copy the file system to ramdisk to prepare for generating the ramdisk image file. We changed the system's ramdisk to 30 M. After restarting the computer, we performed the following operations:
QUOTE:
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.