Create a linux root file system

Source: Internet
Author: User
Tags gz file

It took me a few hours yesterday and finally made the root file system ~

(1): first, the development environment required for the creation of the Linux root file system.

1: porting linux kernel version: linux-3.0.1 (as long as it can be used)

2: Cross-compilation tool: Arm-Linux-GCC 4.3.2 (optional)

3: file system production tools: Busybox-1.13.3 (optional)

4: etc.tar.gz

(2): Build a cross-compilation environment (this step is very simple because I have a detailed setup process in other articles on my blog ~)

(3): create a directory for the root file system

1: Create a folder named rootfs in the main directory.

[Root @ localhost fs] # ls
[Root @ localhost fs] # mkdir rootfs
[Root @ localhost fs] # cd rootfs/
[Root @ localhost rootfs] # mkdir bin Dev etc lib proc sbin sys usr mnt tmp VaR
[Root @ localhost rootfs] #
Mkdir usr/bin usr/lib usr/sbin lib/modules

Note:

The root file system is the first file system used when Linux is started. It cannot be started normally without it.

However, this root file system contains a series of directories. Next we will give a brief introduction to these directories. Actually, everyone knows this.

Bin
Stores basic commands that can be used by all users.
 
Sbin

It stores basic system commands for starting and repairing systems.

Sys

Some bus, devices, and drivers. And so on. It seems that they are all dynamically generated.

 
USR
It stores shared and read-only programs and data.
 
Proc
This is an empty directory, often used as a mount point for the proc file system.
 
Dev
This directory stores device files and other special files.
 
Etc
Stores system configuration files, including startup files.
 
Lib

Stores shared libraries and loaded blocks (drivers). Shared libraries are used to start the system and run executable programs in the root file system.

MNT
It is used to temporarily mount the mount point of a file system, usually an empty directory. You can also create an empty subdirectory in it.
Boot
Static files used by the bootstrap loader
 
Home
The user's main directory, including the main directory used by the Service account lock, such as ftp
 
OPT
Directory for additional software installation on the host.
 
Root
Root user's home directory
 
TMP
Stores temporary files, usually empty directories.
 
VaR

Store variable data.

2: create a device file

[Root @ localhost rootfs] # cd DEV/

[Root @ localhost Dev] #
Mknod-M 666 console C 5 1
[Root @ localhost Dev] #
Mknod-M 666 null C 1 3

Note: mknod-M 666 console C 5 1

The console is the name of the device file and can be retrieved as needed. C indicates that the device is a portable device (B, block device)

5. The master device number/dev/devices records the existing devices.

1 is the device number. When you want to give two identical devices a drive, the device number will be divided. Starting from 0, 1 is the second device. For character devices, the device number indicates different devices of the same type. 666 indicates the access permission


3: Configure/etc/

There are two methods

1: You can copy some important files under/etc/in the system.

2: You can also download an etc.tar.gz file on the Internet.

# Tar-zxvf etc.tar.gz

Copy all the items in the ETC file to the/rootfs/etc/directory under the newly created root directory.

ETC/inittab
Etc/profile
Etc/fstab
Etc/init. d/
Etc/init. d/RCS


4: Compile the kernel module

First, go to the kernel directory (the kernel directory and the root file system directory are not in the same directory)

# Cd linux-3.0.1

# Make modules arch = arm cross_compile = arm-Linux-

Note: Some Problems Occurred in this step and I found that the compilation was not successful. Later, I downloaded a kernel and compiled it through

5. Install the kernel module.

# Make modules_install arch = arm install_mod_path =/home/xiongyao/rootfs

(Put the compiled modules in the kernel under the root file system directory (in fact, the process of copying the modules to the directory)

6: Configure busybox

Note: busybox :( Baidu encyclopedia)

Busybox is a software integrated with more than one hundred Linux commands and tools. Busybox contains some simple tools, such as LS, cat
And Echo. It also contains some larger and more complex tools, such as grep, find, and mount.
And Telnet. Some people call busybox the Swiss army knife in Linux. In short, busybox is like a big toolbox, which is integrated with compression.
Many Linux tools and commands also contain the built-in shell of the Android system.

# Tar-xvzf busybox-1.13.3.tar.gz

# Cd busybox-1.13.3

# Make menuconfig

Note: This step requires you to configure the busybox GUI to make it take effect. Running this command may cause errors because you do not have

Install the image interface dependency library, enter apt-Get install libncurses5-dev in the terminal will be OK ~

Busybox settings -----> build options ----->

Select build busybox as a static binary (no shared libs)

Busybox settings -----> installationoptions ------------>

Select "Don't use/usr" to prevent busybox from being installed in the/usr directory of the host system and damaging the host system.

Busybox installation prefix (/home/fs/myrootfs) enter the absolute installation path of busybox

7. Compile and install busybox

# Make arch = arm cross_compile = arm-Linux-

# Make install

So far, the root file system has been fully completed. You can make this root file system into a ramdisk system.

8:Create the root file system as ramdisk

# Genext2fs-B 8192-D/home/fs/myrootfs/ramdisk

Note: This step encountered a problem. Later I found that the allocated space was too small, so I changed 8192 to 120400.

# Genext2fs-B/home/xiongyao/rootfs/ramdisk

# Gzip-9-F ramdisk

In this case, you can download ramdisk.gz to the Development Board.


During the production process, you may encounter various problems. If the problem is okay, I usually have hundreds of degrees directly. There are various solutions in it. If you have to understand it with your heart, I believe it will be successful!

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.