File System loading during Linux Startup

Source: Internet
Author: User
File System loading during Linux Startup-general Linux technology-Linux programming and kernel information. The following is a detailed description. I think my articles are relatively simple. Some beginners can see that this is why I am not posting on the embedded version. For the experts, if you don't have time, I hope you can help me with the mistakes. This is why I am here to communicate with you.

After completing the module driver, you need to mount the file system. I always thought:

The kernel I compiled uses the initrd mode. The device is loaded by the/linuxrc script program in the RAM DISK file system, which wastes a lot of time. However, I have a deep understanding of initrd. Let's wait.

In fact, the first file system mounted to the kernel is root. cramfs in nand flash. The mounting code mount_root () is in the file/fs/super. c. Then mount the devcie File System to the/dev directory and run the code mount_devfs_fs (). Since the noninitrd mode is used, the mount of the file system is complete, and the init process continues until running:

If (execute_command)
Execve (execute_command, argv_init, envp_init );

Here, init is switched to another thread and the running program is defined in execute_command. Execute_command is the command line passed in by vivi. During the startup process, you can see:

Kernel command line: noinitrd root =/dev/bon/2 init =/linuxrc console = ttyS0

Therefore, execute_command corresponds to/linuxrc. Therefore, the script linuxrc under the root directory of the program running corresponds:

#! /Bin/sh
Echo "mount/etc as ramfs"
/Bin/mount-n-t ramfs/etc
/Bin/cp-a/mnt/etc/*/etc
Echo "re-create the/etc/mtab entries"
/Bin/mount-f-t cramfs-o remount, ro/dev/mtdblock/3/
/Bin/mount-f-t ramfs/etc
Exec/sbin/init

This will not be explained (bash is finally started). You can mount root. cramfs to/mnt in linux to see the content:

Mount? T cramfs? O loop root. cramfs/mnt/cramfs

I 'd like to tell you how to automatically load some running programs at startup. Now I should understand it. It's okay to write a script. (In fact, I have been having this problem with yy)

Finally, let's talk about initrd (initail ram disk)

I will not talk about the principle. It's a cliché, and there are a lot of online things. In my understanding, initrd includes some module drivers and shares the kernel size to a certain extent, this is because the two must be loaded to memory at the same time at startup. More importantly, it can ensure the portability of the kernel. For different hardware platforms, as long as different initrd file systems are provided, the kernel can remain unchanged. Therefore, initrd is mainly used to load complex platform-related hardware, such as SCSI hard drive and nic drive (such as diskless workstation and nfs.

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.