Current location - Health Preservation Learning Network - Slimming men and women - How to make Linux root file system
How to make Linux root file system
Root file system has always been an important part of all Unix-like operating systems, and it can also be considered as an important feature that distinguishes embedded Linux systems from other traditional embedded operating systems. It brings many powerful and flexible functions to Linux, but it also brings some complexity. We need to clearly understand the basic structure of the root file system, carefully select the required system libraries, kernel modules and applications, configure various initialization script files, and select the appropriate file system type and put it in the appropriate location of the actual storage device.

The root file system of Linux is organized in a tree structure, including all kinds of files and programs needed for kernel and system management. Generally speaking, the top-level directories under the root directory "/"have some fixed names and uses.

The following lists the common directory structures in the Linux root file system:

/bin The directory where binary executable commands are stored.

This directory contains basic commands available to all users. These commands can be used before mounting other file systems, so the /bin directory must be in the same partition as the root file system.

Commands commonly used in /bin directory are: cat, chgrp, chmod, CP, ls, sh, kill, mount, umount, mkdir, mknod, [,test and other "["commands are actually test commands. When we use Busybox to make the root file system, we can see some executable files, that is, some available commands, in the generated bin directory.

The /dev directory where the device files are stored.

Device files are stored in this directory, which is a unique file type in Linux. Under the Linux system, all kinds of devices are accessed in the form of files, that is, a specific hardware is operated by reading and writing a device file. For example, serial port 0 can be operated by "dev/ttySAC0" file, and the second partition of MTD equipment can be accessed by "/dev/mtdblock 1".

Directory of /etc storage system management and configuration files.

Various configuration files are stored in this directory. For Linux system on PC, there are many files and directories in the /etc directory. These directory files are optional and depend on the applications in the system and whether they need configuration files. In embedded systems, these contents can be greatly reduced.

/home user's home directory, for example, the user's home directory is /home/user, which can be represented by ~user.

User directory, which is optional. For every ordinary user, there is a subdirectory named after the user name under the /home directory to store the user-related configuration files.

/lib is a directory that dynamically links * * * shared libraries.

This directory stores * * * shared libraries and loadable (drivers), and * * * shared libraries are used to start the system. Run executable programs in the root file system, such as those in the /bin /sbin directory.

/sbin is the directory of the hypervisor used by the storage system administrator.

This directory stores system commands, that is, commands that can only be used by administrators. System commands can also be stored in the /usr/sbin, /usr/local/sbin directories. The /sbin directory stores basic system commands, which are used to start and repair the system. Similar to the /bin directory, /sbin can be used before mounting other file systems, so the /sbin directory must be in the same location as the root file system.

Common commands in the /sbin directory are: shutdown reboot fdisk fsck, etc. System commands installed by local users are placed in the /usr/local/sbin directory.

/tmp general temporary file storage point

Used to store temporary files, usually an empty directory, located in the /tmp directory used by some programs that need to generate temporary files, so the /tmp directory must exist and be accessible.

/root system administrator's home directory

The directory of root user, corresponding to the directory of ordinary user, is a subdirectory under /home.

/mnt system provides this directory for users to temporarily mount other file systems.

The mount point used to mount the file system temporarily is usually an empty directory, or an empty subdirectory can be created in it, such as /mnt/cdram /mnt/hda 1. Used for temporary installation of CDs and hard disks.

/proc virtual file system, which can be directly accessed to obtain system information.

This is an empty directory and is usually used as a mount point for the proc file system. The proc file system is a virtual file system, which has no actual storage device. The directories and files inside are temporarily generated by the kernel to indicate the running state of the system and also to operate the file control system.

/usr is the largest directory, and almost all the applications and files to be used are in this directory.

The contents of the /usr directory can be stored in another partition and then linked to the /usr directory in the root file system after the system is started. The stored programs and data are * * * shared and read-only, indicating that the contents in the /usr directory can be shared among multiple hosts, which is mainly in line with FHS standards. Files in /usr should be read-only, and variable files related to other hosts should be saved in other directories, such as /var. The /usr directory can be refined in embedded systems.

/var overflow area of some large files.

In contrast to the /usr directory, the /var directory stores variable data, such as spool directories (e-mail, news), log files and temporary files.

-

First, the transplant environment:

1, Ubuntu 10. 10 allocation

2. Uber.bin

3. Target machine: FS_S5PC 100 platform.

4. Cross compiler ARM-Cortex _ A8-Linux-GNUEABI-GCC

-

Second, the transplant steps

1, source code download

The version we chose is busybox-1.17.3.tar.bz2. The download path is:

/download/

2. Decompress source code

$ tar xvf busybox- 1. 17.3 . tar . bz2

3. Enter the source directory

$ cd busybox- 1. 17.3

4. Configure the source code

$ make menuconfig

Busybox settings->

Build options->

[*] Build BusyBox as a static binary file (no shared library)

[] forced NOMMU construction

[] supports large file construction (for accessing file & gt2 GB).

(arm-cortex_a8-linux-gnueabi-) cross compiler prefix

() additional CFLAGS

5. Preparation

$ make

6. Device

The default installation path of busybox is _install in the source directory.

$ for installation

7. Enter the installation directory.

$ cd _install

$ ls

bin linuxrc sbin usr

8. Create other required directories.

Management process variables such as $ mkdir dev tmp system root

9. Add a library

Create a lib folder in the _install directory and copy the libraries in the tool chain to the lib directory.

$ mkdir library

$ CP/home/Linux/x-tools/arm-cortex _ A8-Linux-gnueabi/arm-cortex _ A8-Linux-gnueabi/lib/*。 /lib/

Delete all directories. O files and. Lib and slim down libraries under a file to reduce the size of the file system.

$ rm *。 o *。 a

$ arm-cortex _ A8-Linux-gnueabi-strip lib/*

10, add system startup file.

Add the file inittab under etc.

$ vim /etc/inittab

The contents of this document are as follows:

# In addition to starting in single-user mode, it runs first.

* sysinit:/etc/init . d/rcS

# /bin/sh call on the selected tty

# Start an ask first”shell (whatever it is) on the console.

* ask first:-/bin/sh

# What to do when restarting the initialization process

* restart:/sbin/init

# Things to do before restarting

* ctrl altdel:/sbin/reboot

Add file fstab under etc.

$ vim /etc/fstab

The contents of this document are as follows:

# device mount point type option dumps fsck order

Process/Process Default Value 0 0

Tmpfs /tmp tmpfs default value 0 0

Sysfs /sys sysfs default value 0 0

Tmpfs /dev tmpfs default value 0 0

There are three file systems: proc, sysfs and tmpfs. In the kernel, both proc and sysfs are supported by default, but tmpfs is not. We need to add tmpfs support.

Modify the kernel configuration:

$ make menuconfigFile system->

Pseudo file system->;

[*] Virtual memory file system support (formerly shm fs)

[*] Tmpfs POSIX access control list

Recompile kernel

$ make zImage

Create init.d directory under etc and rcS file under init.d.

$ mkdir /etc/init.d -p

$ vim /etc/init.d/rcS

The contents of the rcS file are:

#! /bin/sh

# This is the first script called by the init process.

/bin/mount -a

Add executable permissions for rcS:

$ chmod +x init.d/rcS

Add a configuration file under etc.

$ vim /etc/profile

The file content is:

#! /bin/sh

Export hostname = hyperopia

Export user =root

Export Home Page = Root

# export PS 1 = " \[\ u @ \ h \ W \]\ $ "

export PS 1 = "[$ USER @ $ HOSTNAME \ W]\ # "

PATH =/bin:/sbin:/usr/bin:/usr/sbin

LD _ LIBRARY _ PATH =/lib:/usr/lib:$ LD _ LIBRARY _ PATH

Export path LD_LIBRARY_PATH

1 1, device file creation

There must be a device node in the root file system. Create a console node under dev.

$ mknod development/console c 5 1

Important: If the size of the newly created file system exceeds 8M, please delete unnecessary library files.