亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Table of Contents
1. Root file system" >1. Root file system
2. Main root file system" >2. Main root file system
3.Ramdisk production" >3.Ramdisk production
4.Cramfs制作" >4.Cramfs制作
5.其他根文件系統(tǒng)的制作" >5.其他根文件系統(tǒng)的制作
6.BusyBox編譯制作" >6.BusyBox編譯制作
Home System Tutorial LINUX Secrets of the Linux root file system

Secrets of the Linux root file system

Feb 15, 2024 pm 01:42 PM
linux linux tutorial linux system Linux operating system linux command shell script embeddedlinux Getting started with linux linux learning

Linux is an open source, portable, customizable operating system that is widely used in various fields, such as servers, desktops, embedded devices, etc. The core of Linux is the kernel, which is responsible for managing hardware resources and providing basic services. However, the kernel is not an independent entity and requires a file system to store and access various data and programs. A file system is a method of organizing and managing files. It defines the file's name, location, attributes, permissions and other information. In Linux, there are many different types of file systems, such as ext4, xfs, btrfs, etc., each of which has its own characteristics and advantages. However, among all file systems, there is a special file system, which is the foundation and core of the Linux system, which is the root file system (rootfs). So, what is the root file system? What does it do? How is it created and managed? This article will answer the questions from the following aspects:

Secrets of the Linux root file system

1. Root file system

A file system is a directory structure included in a disk (including optical disks, floppy disks, flash disks and other storage devices) or partitions; an applicable disk device can contain one or more file systems; if you want to enter a file system, the first thing you have to do is to mount the file system; in order to mount the file system, you must specify a mount point.

Note: For our application development, when purchasing a development board, the manufacturer will provide a ready-made root file system and BootLoader. If necessary, we can change the commands without making a new root file from scratch. system. However, the production process here can give us a deeper understanding of the Linux file system.

2. Main root file system

* In Linux, rootfs is essential. PC mainly implements ramdisk and directly mounts the root file system on HD (Harddisk, hard disk); embedded systems generally do not boot from HD, but from Flash. The simplest method is to load rootfs to the RAMDisk of RAM. The slightly more complicated one is to read Cramfs directly from Flash, and the more complicated one is to partition on Flash and build a file system such as JFFS2.

* RAMDisk compresses the prepared rootfs and writes it to Flash. During startup, the Bootloader loads it into RAM, decompresses it, and then mounts it to /. This method is simple to operate, but the file system in RAM is not compressed, so it requires RAM, a scarce resource in many embedded systems.

ramdisk uses memory space to simulate hard disk partitions. Ramdisk usually uses disk file system compression and is stored in flash. During system initialization, it is decompressed to SDRAM and mounted to the root file system. In Linux systems, ramdisk has There are two types. One is that it can be formatted and loaded. It is already supported in Linux kernel 2.0/2.2. Its disadvantage is that the size is fixed; the other is only supported by the 2.4 kernel and is implemented through ramfs. It cannot be formatted. However, it is easy to use and its size increases or decreases according to the required space. It is a commonly used ramdisk technology in Linux at present.

* initrd is the format of RAMDisk. Before kernel 2.4, it was image-initrd. Kernel 2.5 introduced cpio-initrd, which greatly simplified the Linux startup process and conformed to the basic philosophy of Linux: Keep it simple, stupid (KISS) . However, cpio-initrd, as a new format, has not been extensively tested. Image-initrd is mainly used in embedded Linux.

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

* SquashFS is an enhancement to Cramfs. Breaking through some limitations of Cramfs, it also has advantages in terms of Flash and RAM usage. However, according to the developers, it may not be as good as Cramfs in terms of performance. This is also a new approach that will require more testing before adoption in embedded systems.

3.Ramdisk production

The method of making RAMDisk is as follows:
(1) In the Linux operating system environment of the PC, generate a file that can be virtualized into a block device. Assume that the file name is init.img.

$?dd?if=/dev/zero?of=init.img?bs=4096?count=1024

bs*count is the block device size (unit: bytes). After generating the init.img file, the file must be formatted.

$?mke2fs?–m0?–F?init.img

(2) Create a new folder ram and attach init.img to the ram directory.

$?mkdir?ram
$?mount?init.img?ram/?-o?loop

這時,讀寫ram目錄,等效于讀寫init.img文件。用戶可以將根文系統(tǒng)所需的文件寫入到ram目錄中。往ram目錄寫完文件以后,還需要使用umount ram命令卸載init.img,才能將已寫入的文件保存到init.img中。

(3)添加完畢,需要umount ram

4.Cramfs制作

CramFS(Compressed Rom File System)是Linux Torvalds在Transmeta任職時,所參與開發(fā)的文件系統(tǒng)。它是針對Linux內(nèi)核2.4之后的版本所設計的一種新型只讀文件系統(tǒng),采用了zlib 壓縮,壓縮比一般可以達到1:2,但仍可以作到高效的隨機讀取,Linux系統(tǒng)中,通常把不需要經(jīng)常修改的目錄壓縮存放,并在系統(tǒng)引導的時候再將壓縮文件 解開。因為Cramfs不會影響系統(tǒng)的讀取文件的速度,而且是一個高度壓縮的文件系統(tǒng)。因此非常廣泛應用于嵌入式系統(tǒng)中。

在嵌入式的 環(huán)境之下,內(nèi)存和外存資源都需要節(jié)約使用。如果使用RAMDISK方式來使用文件系統(tǒng),那么在系統(tǒng)運行之后,首先要把Flash上的映像文件解壓縮到內(nèi)存 中,構造起RAMDISK環(huán)境,才可以開始運行程序。但是它也有很致命的弱點。在正常情況下,同樣的代碼不僅在Flash中占據(jù)了空間(以壓縮后的形式存 在),而且還在內(nèi)存中占用了更大的空間(以解壓縮之后的形式存在),這違背了嵌入式環(huán)境下盡量節(jié)省資源的要求。

使用CramFS文件 系統(tǒng)就是一種解決這個問題的方式。CramFS是一個壓縮格式的文件系統(tǒng),它并不需要一次性地將文件系統(tǒng)中的所有內(nèi)容都解壓縮到內(nèi)存之中,而只是在系統(tǒng)需 要訪問某個位置的數(shù)據(jù)的時候,馬上計算出該數(shù)據(jù)在CramFS中的位置,將它實時地解壓縮到內(nèi)存之中,然后通過對內(nèi)存的訪問來獲取文件系統(tǒng)中需要讀取的數(shù) 據(jù)。CramFS中的解壓縮以及解壓縮之后的內(nèi)存中數(shù)據(jù)存放位置都是由CramFS文件系統(tǒng)本身進行維護的,用戶并不需要了解具體的實現(xiàn)過程,因此這種方 式增強了透明度,對開發(fā)人員來說,既方便,又節(jié)省了存儲空間。

但是Cramfs也有其缺點:延遲、小于16MB、不支持寫,只支持PAGE_CREATE_SIZE=4096的內(nèi)核。

制作的命令:(root文件夾中存放著文件系統(tǒng))

#mkcramfs?root?cramfs.img

5.其他根文件系統(tǒng)的制作

制作yaffs文件系統(tǒng):?mkyaffsimage?myroots?myroots.img
制作squashfs:?mksquashfs?$(FS_DIR)?$(FS_NAME)?-noappend?-be?-lzma?-no-fragments?–noI

6.BusyBox編譯制作

建立目標板空根目錄文件夾及根目錄下的文件夾:

[root@190?friendly-arm]#?mkdir?myroots
[root@190?friendly-arm]#pwd
/friendly-arm/myroots
[root@190?friendly-arm]#cd?myroots
[root@190?myroots]#?mkdir?bin?sbin?usr?lib?dev?mnt?opt?root?etc?home?proc?tmp?var
[root@190?myroots]#?mkdir?etc/init.d

進入etc/init.d目錄下,建立一個腳本文件,并命名為rcS,用gedit打開,添加如下內(nèi)容:

#!?/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:
runlevel=S
prevlevel=N
umask?022
export?PATH?runlevel?prevlevel
#
#?Trap?CTRL-C?&c?only?in?this?shell?so?we?can?interrupt?subprocesses.
#
trap?":"?INT?QUIT?TSTP

創(chuàng)建 dev 中的節(jié)點
如果使用“l(fā)inux 2.6.xx”的內(nèi)核,應該事先創(chuàng)建節(jié)點“console”、“null”。否則在系統(tǒng)啟動時內(nèi)容會提示以下錯誤:

Warning:?unable?to?open?an?initial?console.
Kernel?panic?-?not?syncing:?Attempted?to?kill?init!

創(chuàng)建節(jié)點的命令如下:

#?mknod?dev/console?c?5?1
#?mknod?dev/null?c?1?3?移植Busybox:

進入到壓縮文件存放的目錄下,并解壓。然后進入解壓后的busybox目錄文件夾,隨后配置busybox 。

[root@190?busybox-1.2.0]#?make?menuconfig

由于每個版本的配置選項組織有所不同。不管怎樣,我們注意以下選項就行了:

1)?Support?for?devfs
2)?Build?BusyBox?as?a?static?binary?(?no?shared?libs?)?//將busybox編譯成靜態(tài)鏈接
3)?Do?you?want?to?build?busybox?with?a?Cross?Compile?
(/usr/local/arm/3.3.2/bin/arm-linux-)?Cross?Compile?prefix?//指定交叉編譯器
4)?init
5)?Support?reading?an?inittab?file?//支持init讀取/etc/inittab?配置文件
6)?(X)?ash選中ash?//建立的rcS腳本才能執(zhí)行
7)ash
8)cp?cat?ls?mkdir?mv?//可執(zhí)行命令工具的選擇,自己看著辦吧,需要用到的就選上
9)?mount
10)?umount
11)?Support?loopback?mounts
12)?Support?for?the?old?/etc/mtab?file
13)?insmod
14)?Support?version?2.2.x?to?2.4.x?Linux?kernels
15)?Support?version?2.6.x?Linux?kernels
16)?vi
17)don’t?use?user

以上內(nèi)容必須選上,其他可按默認值;如果要支持其他功能,如網(wǎng)絡支持等,可按需選擇,英語不是很爛的話,這些都沒有問題。
配置好之后,保存退出。然后對其編譯和安裝到剛才建立的根文件系統(tǒng)目錄下:

[root@190?busybox-1.2.0]?make?TARGET_ARCH=arm?CROSS=arm-linux-?\?PREFIX=/friendly-arm/myroots/?all?install

安裝好之后,將相應的二進制文件拷貝到根文件系統(tǒng)相應的目錄下:
拷貝一些管理員控制程序到/sbin目錄下,最重要的就是要包含一個init命令;
拷貝應用程序運行時所需要的庫到/lib,庫文件可以從PC機上的交叉編譯工具安裝目錄下拷貝,如libc-2.2.2.so、libcryt-2.2.2.so、libm-2.2.2.so、libutil-2.2.2.so等,為部分相應庫建立快捷方式,提供一些應用程序按快 捷方式名稱調(diào)用。值得注意的是C庫要采用C庫的版本glibc, glibc位于/lib/libc.so.6

Through the above analysis, we can see that the root file system is an important part of the Linux system. It contains key files and directories required for the startup and operation of the Linux system. The root file system is usually mounted under the / (root) directory and can contain mount points for other file systems. Root file systems can use different types of file system formats and can be created and managed through a number of tools. For example, we can use the mkfs command to format a partition or device as a root file system, we can use the mount command to mount or unmount a root file system, and we can use the df command to view the usage of a root file system, etc. In short, the root file system is the secret of the Linux system, which provides a stable and flexible foundation for the Linux system.

The above is the detailed content of Secrets of the Linux root file system. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1488
72
How to install Linux alongside Windows (dual boot)? How to install Linux alongside Windows (dual boot)? Jun 18, 2025 am 12:19 AM

The key to installing dual systems in Linux and Windows is partitioning and boot settings. 1. Preparation includes backing up data and compressing existing partitions to make space; 2. Use Ventoy or Rufus to make Linux boot USB disk, recommend Ubuntu; 3. Select "Coexist with other systems" or manually partition during installation (/at least 20GB, /home remaining space, swap optional); 4. Check the installation of third-party drivers to avoid hardware problems; 5. If you do not enter the Grub boot menu after installation, you can use boot-repair to repair the boot or adjust the BIOS startup sequence. As long as the steps are clear and the operation is done properly, the whole process is not complicated.

What Are the Steps to Install Redis on a Linux System? What Are the Steps to Install Redis on a Linux System? Jun 11, 2025 am 12:11 AM

ToinstallRedisonaLinuxsystem,followthesesteps:1)DownloadandextractRedisfromtheofficialGitHubrepository,2)CompileRedisusingthe'make'command,3)InstallRediswith'sudomakeinstall',4)ConfigureRedisbycopyingandeditingtheconfigurationfile,and5)StartRedisusin

How to enable the EPEL (Extra Packages for Enterprise Linux) repository? How to enable the EPEL (Extra Packages for Enterprise Linux) repository? Jun 17, 2025 am 09:15 AM

The key to enabling EPEL repository is to select the correct installation method according to the system version. First, confirm the system type and version, and use the command cat/etc/os-release to obtain information; second, enable EPEL through dnfinstallepel-release on CentOS/RockyLinux, and the 8 and 9 version commands are the same; third, you need to manually download the corresponding version of the .repo file and install it on RHEL; fourth, you can re-import the GPG key when encountering problems. Note that the old version may not be supported, and you can also consider enabling epel-next to obtain the test package. After completing the above steps, use dnfrepolist to verify that the EPEL repository is successfully added.

How to choose a Linux distro for a beginner? How to choose a Linux distro for a beginner? Jun 19, 2025 am 12:09 AM

Newbie users should first clarify their usage requirements when choosing a Linux distribution. 1. Choose Ubuntu or LinuxMint for daily use; programming and development are suitable for Manjaro or Fedora; use Lubuntu and other lightweight systems for old devices; recommend CentOSStream or Debian to learn the underlying principles. 2. Stability is preferred for UbuntuLTS or Debian; you can choose Arch or Manjaro to pursue new features. 3. In terms of community support, Ubuntu and LinuxMint are rich in resources, and Arch documents are technically oriented. 4. In terms of installation difficulty, Ubuntu and LinuxMint are relatively simple, and Arch is suitable for those with basic needs. It is recommended to try it first and then decide.

How to add a new disk to Linux How to add a new disk to Linux Jun 27, 2025 am 12:15 AM

The steps to add a new hard disk to the Linux system are as follows: 1. Confirm that the hard disk is recognized and use lsblk or fdisk-l to check; 2. Use fdisk or parted partitions, such as fdisk/dev/sdb and create and save; 3. Format the partition to a file system, such as mkfs.ext4/dev/sdb1; 4. Use the mount command for temporary mounts, such as mount/dev/sdb1/mnt/data; 5. Modify /etc/fstab to achieve automatic mount on the computer, and test the mount first to ensure correctness. Be sure to confirm data security before operation to avoid hardware connection problems.

Where are system logs located in Linux? Where are system logs located in Linux? Jun 24, 2025 am 12:15 AM

Logs in Linux systems are usually stored in the /var/log directory, which contains a variety of key log files, such as syslog or messages (record system logs), auth.log (record authentication events), kern.log (record kernel messages), dpkg.log or yum.log (record package operations), boot.log (record startup information); log content can be viewed through cat, tail-f or journalctl commands; application logs are often located in subdirectories under /var/log, such as Apache's apache2 or httpd directory, MySQL log files, etc.; at the same time, it is necessary to note that log permissions usually require s

Fixed the failure to upload files in Windows Google Chrome Fixed the failure to upload files in Windows Google Chrome Jul 08, 2025 pm 02:33 PM

Have problems uploading files in Google Chrome? This may be annoying, right? Whether you are attaching documents to emails, sharing images on social media, or submitting important files for work or school, a smooth file upload process is crucial. So, it can be frustrating if your file uploads continue to fail in Chrome on Windows PC. If you're not ready to give up your favorite browser, here are some tips for fixes that can't upload files on Windows Google Chrome 1. Start with Universal Repair Before we learn about any advanced troubleshooting tips, it's best to try some of the basic solutions mentioned below. Troubleshooting Internet connection issues: Internet connection

What is the sudo command and when should I use it? What is the sudo command and when should I use it? Jul 02, 2025 am 12:20 AM

sudo stands for "substituteuserdo" or "superuserdo", allowing users to run commands with permissions of other users (usually root). Its core uses include: 1. Perform system-level operations such as installing software or editing system files; 2. Accessing protected directories or logs; 3. Manage services such as restarting nginx; 4. Modify global settings such as /etc/hosts. When using it, the system will check the /etc/sudoers configuration and verify the user password, provide temporary permissions instead of continuously logging in as root, ensuring security. Best practices include: only when necessary, avoid blindly executing network commands, editing sudoers files with visudo, and considering continuous operations.

See all articles