Chapter 2 Creating a Root File System
2.1 Preliminary knowledge of the root file system
In embedded Linux, a root file system needs to be built. The rules for building a root file system are in the FHS (Filesystem Hierarchy Standard) document. The following is the top-level directory of the root file system.
Table of contents
content
bin
Stores basic commands that can be used by all users.
sbin
It stores basic system commands, which are used to start the system, repair the system, etc.
usr
It contains shared, read-only programs and data.
proc
This is an empty directory, often used as the mount point of 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 loadable blocks (i.e. drivers). Shared libraries are used to start the system and run executable programs in the root file system.
boot
Static files used by the bootloader
home
User home directories, including home directories used by service accounts, such as FTP
mnt
A mount point used to temporarily mount a file system, usually an empty directory. You can also create empty subdirectories in it.
opt
The directory where additional software installed on the host is placed.
root
Home directory for the root user
tmp
A directory for storing temporary files, usually an empty directory.
was
Stores mutable data.
2.2. Build the root file according to the system
2.2.1. Create the root file system directory
Enter the /opt/studyarm directory, create a new script file create_rootfs_bash to create the root file system directory, use the command chmod +x create_rootfs_bash to change the executable permission of the file, and run the script ./create_rootfs_bash to complete the creation of the root file system directory.
#!/bin/sh
echo "------Create rootfs directons start...--------"
mkdir rootfs
cd rootfs
echo "--------Create root,dev....----------"
mkdir root dev etc boot tmp var sys proc lib mnt home
mkdir etc/init.d etc/rc.d etc/sysconfig
mkdir usr/sbin usr/bin usr/lib usr/modules
echo "make node in dev/console dev/null"
mknod -m 600 dev/console c 5 1
mknod -m 600 dev/null c 1 3
mkdir mnt/etc mnt/jffs2 mnt/yaffs mnt/data mnt/temp
mkdir var/lib var/lock var/run var/tmp
chmod 1777 tmp
chmod 1777 var/tmp
echo "-------make direction done---------"
Changed the usage rights of the tmp directory to enable the sticky bit. Enabling this bit for the usage rights of the tmp directory ensures that only the user who created it has the right to delete the files created under the tmp directory. Although most embedded systems are single-user, some embedded applications do not necessarily need to be executed with root permissions, so they need to be designed in accordance with the basic regulations of the root file system permission bits.
2.2.2. Create a dynamic link library. To
use the dynamic link library directly with Friendly Arm, first unzip the root file package of Friendly Arm and copy the contents of lib to the newly created root file directory lib.
cd /mnt/hgfs/share
tar –zxvf root_qtopia.tgz –C /opt/studyarm
cp –rfd /opt/studyarm/root_qtopia/lib/* /opt/studyarm/rootfs/lib/*
2.2.3 Cross-compile Bosybox
Bosybox is an open source project that complies with the GPL v2 protocol. It always optimizes the file size during the writing process and takes into account the limited system resources (such as memory, etc.). Using Busybox, you can automatically generate the bin, sbin, usr directories and linuxrc files required for the root file system.
1. Unzip busybox
cd /mnt/hgfs/share
tar –zxvf busybox-1.13.3.tar.tgz –C /opt/studyarm
2. Enter the source code and modify the Makefile file:
cd /opt/studyarm/busybox-1.13.3
Revise:
CROSS_COMPILE ?=arm-linux- //Line 164
ARCH ?=arm //Line 189
3. Configure busybox
Enter make menuconfig to configure
(1)、Busybox Settings--->
General Configuration--->
[*] Show verbose applet usage messages
[*] Store applet usage messages in compressed form
[*] Support –install [-s] to install applet links at runtime
[*] Enable locale support(system needs locale for this to work)
[*] Support for –long-options
[*] Use the devpts filesystem for unix98 PTYs
[*] Support writing pidfiles
[*] Runtime SUID/SGID configuration via /etc/busybox.config
[*] Suppress warning message if /etc/busybox.conf is not readable
Build Options--->
[*] Build BusyBox as a static binary(no shared libs)
[*] Build with Large File Support(for accessing files>2GB)
Installation Options->
[]Don’t use /usr
Applets links (as soft-links) --->
(./_install) BusyBox installation prefix
Busybox Library Tuning --->
(6)Minimum password legth
(2)MD5:Trade Bytes for Speed
[*]Fsater /proc scanning code(+100bytes)
[*]Command line editing
(1024)Maximum length of input
[*] vi-style line editing commands
(15) History size
[*] History saving
[*] Tab completion
[*]Fancy shell prompts
(4) Copy buffer size ,in kilobytes
[*]Use ioctl names rather than hex values in error messages
[*]Support infiniband HW
(2)、Linux Module Utilities--->
(/lib/modules)Default directory containing modules
(modules.dep)Default name of modules.dep
[*] insmod
[*] rmmod
[*] lsmod
[*] modprobe
-----options common to multiple modutils
[ ] support version 2.2/2.4 Linux kernels
[*]Support tainted module checking with new kernels
[*]Support for module .aliases file
[*] support for modules.symbols file
(3) Configure support for device types under dev in busybox
There are three ways to create dev:
Manual creation: When making the root file system, create the device files to be used in the dev directory. After the system mounts the root file system, you can use the device files in the dev directory.
Use devfs file system: This method is outdated, has uncertain device mapping, not enough major/minor device numbers, and devfs consumes a lot of memory.
udev: It is a user program that can dynamically update device files according to the status of hardware devices in the system, including the creation and deletion of device files. Its operation is relatively complex, but it is very flexible.
mdev is a simplified version of udev that comes with busybox, suitable for embedded applications. It is easy to use. Its function is to automatically generate the node files required by the driver when the system starts and hot-plugs or dynamically loads the driver. It is the best choice when building an embedded Linux root file system based on busybox. The following options will add support for mdev.
Linux System Utilities --->
[*]Support /etc/mdev.conf
[*]Support command execution at device addition/removal
4. Compile busybox
Compile busybox to the specified directory:
cd /opt/studyarm/busybox-1.13.3
make CONFIG_PREFIX=/opt/studyarm/rootfs install
The contents of the directories bin, sbin, usr and the file linuxrc will be generated under the rootfs directory.
2.2.4 Create the configuration file in the etc directory
1. etc/mdev.conf file, the content is empty.
2. Copy the passwd, group, and shadow files in the host etc directory to the rootfs/etc directory.
3. Create a new file HOSTNAME in the etc/sysconfig directory with the content "MrFeng".
4. etc/inittab file:
#etc/inittab
::sysinit:/etc/init.d/rcS
::askfirst:-/bin/sh
::ctrlaltdel:/sbin/reboot
::shutdown:/bin/umount -a –r
5. etc/init.d/rcS file:
#!/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
runlevel=S
prevleve=N
umask 022
export PATH runlevel prevlevel
echo "----------munt all----------------"
mount -a
echo /sbin/mdev>/proc/sys/kernel/hotplug
mdev -s
echo "***********************************************"
echo "****************Studying ARM*********************"
echo "Kernel version:linux-2.6.29.1"
echo "Student:Feng dong rui"
echo "Date:2009.07.15"
echo "***********************************************"
/bin/hostname -F /etc/sysconfig/HOSTNAME
Use the following command to change the execution permission of rcS:
Chmod +x rcS
6. etc/fstab file:
#device mount-point type option dump fsck order
proc /proc proc defaults 0 0
none /tmp ramfs defaults 0 0
sysfs /sys sysfs defaults 0 0
mdev /dev ramfs defaults 0 0
7. etc/profile file:
#Ash profile
#vim:syntax=sh
#No core file by defaults
#ulimit -S -c 0>/dev/null 2>&1
USER="id -un"
LOGNAME=$USER
PS1='[\u@\h=W]#'
PATH=$PATH
HOSTNAME='/bin/hostname'
export USER LOGNAME PS1 PATH
2.2.5 Make the root file system image file
Use the following command to install the yaffs file system creation tool:
cd /mnt/hgfs/share
tar –zxvf mkyaffs2image.tgz –C /
In the /opt/studyarm directory, run the command mkyaffs2image rootfs rootfs.img to generate the root file system image file.
Previous article:Linux kernel transplantation based on S3C2440 and yaffs2 file system production--starting system
Next article:Linux kernel transplantation based on S3C2440 and yaffs2 file system production--compile kernel
Recommended ReadingLatest update time:2024-11-16 13:01
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- [STM32WB55 Review] Play with the built-in Demo
- Reading Notes on the Good Book "Electronic Engineer Self-Study Handbook" 03 Program
- Base station interference source positioning system based on drone
- This is an article about 5G 2.4G antenna. You will earn money if you see it. You will learn the truth if you learn it.
- [Share] Easy-to-understand introductory textbook on FPGA. Standardize design and avoid detours
- Learn about the MSP430F5529 Power Management Module
- How to choose a DC-DC module power supply What is the importance of DC_DC module power supply
- Performance management for electronics and hardware engineers
- [Brick Drinking Water Recorder] 2022 Digi-Key Innovation Design Competition Material Unboxing
- 【Qinheng Trial】IV. UART0