How to create an embedded Linux File System

Source: Internet
Author: User

How to create an embedded Linux File System

Speaking of the Linux file system, it is still a little unfamiliar for beginners who have just been familiar with Linux. In fact, it is not difficult to understand his definition and master his usage methods. In the following sections, you will learn in detail what a Linux File System is and how to create an embedded Linux File System.

1. What is a file system)

A file system is a directory structure that includes a disk (including a CD, floppy disk, flash disk, and other storage devices) or a partition. An applicable disk device can contain one or more file systems; to access a file system, you must first mount the file system. To mount the file system, you must specify a mount point.

Ii. Mainly embedded file systems

In Linux, rootfs is essential. Ramdisk and direct mounting of the root file system on HD (hard disk) are mainly implemented on the PC. in embedded systems, it is generally started from Flash instead of HD, the simplest method is to load rootfs to RAM's RAMDisk. The more complex method is to directly read Cramfs from Flash, and more complicated is to partition on Flash and build file systems such as JFFS2.

RAMDisk compresses the created rootfs and writes it to Flash. during startup, the Bootloader loads it to RAM, decompress it, And then mounts it /. This method is simple, but the file system in RAM is not compressed, so it needs to occupy a lot of rare resources in embedded systems RAM.

Ramdisk uses memory space to simulate hard disk partitions. ramdisk usually uses the compression of the disk file system and stores it in flash. during system initialization, It is decompressed to SDRAM and mounted to the root file system, in linux, there are two types of ramdisk. One is to format and load ramdisk, which is supported in linux kernel 2.0/2.2. The disadvantage is that the size is fixed; the other is supported by the 2.4 kernel. It is implemented through ramfs and cannot be formatted, but it is easy to use. Its size increases or decreases as needed, ramdisk is a common ramdisk Technology in linux.

Initrd is the RAMDisk format. Before kernel 2.4 was image-initrd, Kernel 2.5 introduced cpio-initrd, which greatly simplified the Linux Startup Process and included the basic Linux philosophy: Keep it simple, stupid (KISS ). however, cpio-initrd is not widely tested as a new format, and image-initrd is mainly used in embedded Linux.

Cramfs is a simple file system written by Linus. It has good compression green and can be run directly from Flash without being loaded into RAM, thus saving RAM. However, Cramfs is read-only and inconvenient for directories (such as/etc,/var,/tmp) that need to be modified during runtime. Therefore, these directories are generally made into writable fs such as ramfs.

SquashFS is an enhancement to Cramfs. It breaks through some Cramfs restrictions and also has advantages in Flash and RAM usage. However, according to developers, the performance may be inferior to that of Cramfs. This is also a new method. More tests are required before embedded systems are used.

3. Create a directory containing all files

1. Create a directory rootfs to install the File System

2. Mkdir bin dev etc lib proc sbin tmp usr var

3. ln-fs bin/busybox linuxrc (using busybox)

4. to the system/dev, pack all the devices and copy them to dev (the most convenient way). Or, to use mknod to build the desired device, I use the following:

Crw-rw-1 root 5, 1 2006-02-24 13:12 console
Crw-rw-1 root 5, 64 cua0
Crw-rw-1 root 63, 0 2006-02-24 13:12 dk0
Crw-rw-1 root 63, 1 2006-02-24 13:12 dk1
Drwxr-xr-x 2 root 4096 flash
Brw-rw-1 root 3, 0 2006-02-24 13:12 hda
Crw-rw-1 root 36, 10 2006-02-24 13:12 ipsec
Crw-rw-1 root 241, 0 2006-02-24 13:12 ixNpe
Crw-rw-1 root 1, 2 2006-02-24 13:12 kmem
Crw-rw-1 root 126, 0 2006-02-24 13:12 ledman
Lrwxrwxrwx 1 root 16 log->/tmp/var/log
Crw-rw-1 root 1, 1 2006-02-24 13:12 mem
Crw-rw-1 root 90, 0 2006-02-24 13:12 mtd0
Brw-rw-1 root 31, 0 2006-02-24 13:12 mtdblock0
Brw-rw-1 root 31, 1 2006-02-24 13:12 mtdblock1
Brw-rw-1 root 31, 2 mtdblock2
Brw-rw-1 root 31, 3 2006-02-24 13:12 mtdblock3
Brw-rw-1 root 31, 4 mtdblock4
Brw-rw-1 root 31, 5 mtdblock5
Brw-rw-1 root 31, 6 mtdblock6
Crw-rw-1 root 90, 1 2006-02-24 13:12 mtdr0
Crw-rw-1 root 1, 3 2006-02-24 13:12 null
Crw-rw-1 root 108, 0 2006-02-24 13:12 ppp
Crw-r -- 1 root 5, 2 ptmx
Drwxr-xr-x 2 root 4096 pts
Crw-rw-1 root 2, 0 2006-02-24 13:12 ptyp0
Brw-rw-1 root 1, 0 2006-02-24 13:12 ram0
Crw-rw-1 root 1, 8 random
Crw-rw-1 root 5, 0 2006-02-24 13:12 tty
Crw-rw-1 root 4, 0 2006-02-24 13:12 tty0
Crw-rw-1 root 3, 0 2006-02-24 13:12 ttyp0
Crw-rw-1 root 4, 64 2006-02-24 13:12 ttyS0
Crw-rw-1 root 1, 9 urandom
Crw-rw-1 root 1, 5 zero

Example: mknod console c 5 1 crw-rw-1 root 5, 1 console

5. Copy the compiled busybox to/bin. All other commands except busybox are their links.

Ash chgrp clear dd echo fgrep gzip ip ls modprobe mv ping pwd sed stty tar true zcat busybox chmod cp egrep grep hostname kill mkdir more netstat ping2file rm sh sync tftp umount cat chown date dmesg false gunzip ifconfig ln mknod mount pidof ps rmdir sleep sysinfo touch uname

You can use make menuconfig to increase or decrease all commands in busybox.

6. Similarly, the link of busybox is under/sbin.

Halt ifconfig init insmod klogd losetup lsmod mkswap modprobe reboot rmmod route swapoff swapon

  • 1
  • 2
  • Next Page
[Content navigation]
Page 1: Embedded Linux File System definition and preparation Page 2nd: script generated by the embedded Linux File System

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.