ramfs, rootfs & initramfs

Linux内核rootfs的初始化过程 由于在下水平相当有限,不当之处,还望大家批评指正^_^ 在Linux  shell中执行mount命令,通常可以看到某个做了文件系统的磁盘分区或flash分区或内存文件系统做为所谓的根文件系统被mount到了挂载点/处。 实际上内核中最初始的根文件系统,并不是来自内核外部,他是由内核自己构建出来的。 为了说明这个过程,我们先说说mount的过程。 系统调用sys_mount是在fs/n 阅读详情

From: http://android.git.kernel.org/?p=kernel/common.git;a=blob;f=Documentation/filesystems/ramfs-rootfs-initramfs.txt


What is ramfs?

 

Ramfs is a very simple filesystem that exports Linux's disk caching mechanisms (the page cache and dentry cache) as a dynamically resizable RAM-based filesystem.

 

Normally all files are cached in memory by Linux.  Pages of data read from backing store (usually the block device the filesystem is mounted on) are kept
around in case it's needed again, but marked as clean (freeable) in case the Virtual Memory system needs the memory for something else. Similarly, data
written to files is marked clean as soon as it has been written to backing store, but kept around for caching purposes until the VM reallocates the
memory. A similar mechanism (the dentry cache) greatly speeds up access to directories.

With ramfs, there is no backing store. Files written into ramfs allocate dentries and page cache as usual, but there's nowhere to write them to.
This means the pages are never marked clean, so they can't be freed by the VM when it's looking to recycle memory.

The amount of code required to implement ramfs is tiny, because all the work is done by the existing Linux caching infrastructure. Basically,
you're mounting the disk cache as a filesystem. Because of this, ramfs is not an optional component removable via menuconfig, since there would be negligible
space savings.

ramfs and ramdisk:

 

The older "ram disk" mechanism created a synthetic block device out of an area of RAM and used it as backing store for a filesystem.

 

This block device was of fixed size, so the filesystem mounted on it was of fixed size. Using a ram disk also required unnecessarily copying memory from the fake block device into the page cache (and copying changes back out), as well as creating and destroying dentries. Plus it needed a filesystem driver (such as ext2) to format and interpret this data.

Compared to ramfs, this wastes memory (and memory bus bandwidth), creates unnecessary work for the CPU, and pollutes the CPU caches.  (There are tricks
to avoid this copying by playing with the page tables, but they're unpleasantly complicated and turn out to be about as expensive as the copying anyway.)
More to the point, all the work ramfs is doing has to happen _anyway_, since all file access goes through the page and dentry caches. The RAM
disk is simply unnecessary; ramfs is internally much simpler.

Another reason ramdisks are semi-obsolete is that the introduction of loopback devices offered a more flexible and convenient way to create
synthetic block devices, now from files instead of from chunks of memory.
See losetup (8) for details.

 

ramfs and tmpfs:

One downside of ramfs is you can keep writing data into it until you fill up all memory, and the VM can't free it because the VM thinks that files
should get written to backing store (rather than swap space), but ramfs hasn't got any backing store. Because of this, only root (or a trusted user) should
be allowed write access to a ramfs mount.

A ramfs derivative called tmpfs was created to add size limits, and the ability to write the data to swap space. Normal users can be allowed write access to
tmpfs mounts. See Documentation/filesystems/tmpfs.txt for more information.

What is rootfs?

Rootfs is a special instance of ramfs (or tmpfs, if that's enabled), which is always present in 2.6 systems.  You can't unmount rootfs for approximately the
same reason you can't kill the init process; rather than having special code to check for and handle an empty list, it's smaller and simpler for the kernel
to just make sure certain lists can't become empty.

Most systems just mount another filesystem over rootfs and ignore it. The amount of space an empty instance of ramfs takes up is tiny.

What is initramfs?

All 2.6 Linux kernels contain a gzipped "cpio" format archive, which is extracted into rootfs when the kernel boots up.  After extracting, the kernel
checks to see if rootfs contains a file "init", and if so it executes it as PID 1. If found, this init process is responsible for bringing the system the
rest of the way up, including locating and mounting the real root device (if any). If rootfs does not contain an init program after the embedded cpio
archive is extracted into it, the kernel will fall through to the older code to locate and mount a root partition, then exec some variant of /sbin/init
out of that.

.....

Populating initramfs:

External initramfs images:
Contents of initramfs:
Why cpio rather than tar?
Future directions:

Linux内核启动流程揭秘:从vmlinux到用户空间,Ramdisk解压与rootfs构建全解析 本文深入解析Linux内核启动流程中的Ramdisk解压与rootfs构建全过程,详细介绍了从vmlinux到用户空间的完整启动机制。重点剖析了Ramdisk在内核启动中的关键作用、压缩格式识别与解压技术,以及rootfs的特殊性与挂载过程,为开发者理解Linux系统启动原理提供全面指导。 阅读详情

相关推荐

嵌入式Linux启动提速:手把手教你用Buildroot配置Ramdisk(含内核参数详解)

本文详细介绍了如何在嵌入式Linux系统中使用Buildroot配置Ramdisk以显著提升启动速度。通过内存级访问和并行加载技术,Ramdisk可将启动时间缩短至传统存储方案的1/3到1/5。文章包含从基础配置到内核参数调优、文件系统裁剪及高级性能优化的全流程指南,特别解析了rootfs解压和内存管理技巧,帮助开发者实现快速启动的嵌入式系统。

weixin_30847063的博客 229

rk3188--4.android用initrd文件系统启动流程

 在init/intramfs.c中 static int __init populate_rootfs(void) {     unpack_to_rootfs(__initramfs_start, __initramfs_size);  //1. initramfs的解压     if (initrd_start) {         unpack

嵌入精灵 2233

基于国产Flash的ZYNQ7045启动优化:XSCT命令与PetaLinux实战指南

本文详细介绍了基于国产Flash的ZYNQ7045启动优化方法,重点解析了XSCT命令与PetaLinux的实战应用。通过优化BOOT.BIN加载机制、调整Flash初始化参数及自动化脚本编写,有效解决了国产Flash兼容性问题,提升启动速度和稳定性。

weixin_30664051的博客 225

Android的init过程详解(一)

Android的init过程(二):初始化语言(init.rc)解析 本文使用的软件版本 Android:4.2.2 Linux内核:3.1.10      本文及后续几篇文章将对Android的初始化(init)过程进行详细地、剥丝抽茧式地分析,并且在其中穿插了大量的知识,希望对读者了解Android的启动过程又所帮助。本章主要介绍了与硬件相关初始化文件名的确定以及属性服务的原理和实现。...

weixin_34295316的博客 408

10、内核启动与 initramfs 详解

本文详细解析了Linux内核启动过程中initramfs的作用与实现机制。首先介绍了内核解压、设置栈和页面大小、中断处理、initramfs提取等关键步骤,接着分析了initramfs的基础设施,包括ramfs、tmpfs和rootfs的区别。文章还探讨了initramfs在系统启动中的核心作用,如帮助挂载实际根文件系统,并介绍了如何查看、提取和定制initramfs。最后总结了initramfs的优势,并展望了其未来发展方向。

milk5的博客 77

深入解析AndroidManifest.xml与device_admin.xml:打造完美DeviceOwner应用配置

本文深入解析了Android企业级开发中DeviceOwner应用的核心配置文件AndroidManifest.xml与device_admin.xml。详细阐述了如何精准声明DeviceAdminReceiver、定义管理策略,并提供了通过ADB命令进行设置与验证的实战指南,帮助开发者构建权限完整、配置正确的设备所有者应用。

ice55的博客 688

ramdisk.img在android中的使用

ramdisk.img在android中的使用  ramdisk中包含一些对于启动android的很重要的文件,比如内核启动完后加载的第一个进程init,一些重要的配置文件等,总之它控制着整个android的启动.  ramdisk的使用有两种方法:1,编译进内核;2,将ramdisk单独烧写 1,编译进内核 将ramdisk解压,可以看到它里面有很多文件和目录,如:data,dev,pr

ot735i的专栏 742

基于大模型的恶性胸腔积液全周期预测与诊疗方案研究

本研究基于大模型技术构建了恶性胸腔积液全流程预测与诊疗体系,涵盖术前风险评估、术中方案优化、术后恢复预测及并发症预防。通过整合多源医疗数据,实现了手术风险概率预测(准确率80%)、并发症预警(AUC值0.85)及个性化康复方案制定,显著提升诊疗精准度。研究创新性地将Transformer架构与多模态数据融合,在100例临床验证中显示良好性能,但存在数据样本局限、模型可解释性不足等问题。未来将扩大多中心临床验证,优化算法可解释性,探索与基因检测等技术的结合应用,推动恶性胸腔积液的精准诊疗发展。

嵌入式毕设/课设资料清单(速查手册·文档模板·题库,持续更新)→ 见最新文章 1907

sysfs与ramfs、tmpfs、devtmpfs的一点区别

ramfs在挂载以后,其内部以dentry和inode为核心层次维护。sysfs在挂载后,一般只会把挂载点的dentry和inode进行创建,并初始化该sys目录的inode->i_op为sysfs_dir_inode_operations.这之后所有的sys下文件的读写访问操作,都需要经过look_up先找到文件路径,并逐一给每个目录建立inode与dentry,是个动态的过程,只有这个时候才会

天才之嵌入式 1万+

V.PhyloMaker实战:从物种列表到维管束植物系统发育树的完整流程

本文详细介绍了使用V.PhyloMaker工具包,从物种列表快速构建维管束植物系统发育树的完整实战流程。内容涵盖R包安装、物种名标准化、核心函数phylo.maker的三种构建方案选择、结果树的可视化与导出,以及与picante包的联动分析,为生态学和生物地理学研究提供了高效解决方案。

weixin_29057237的博客 387

SpringBoot与锐浪报表服务器深度整合实战指南

本文详细介绍了SpringBoot与锐浪报表服务器的深度整合实战指南,包括环境准备、Windows/Linux系统配置、核心功能实现代码解析及常见问题解决方案。通过具体案例和代码示例,帮助开发者高效完成报表系统的集成与部署,提升企业级应用的报表处理能力。

weixin_29238147的博客 375

linux 启动中对 initrd ramdisk的处理

linux 启动中对 initrd ramdisk的处理 Kernel command line: root=/dev/ram initrd=0x31000000,0x00A00000console=ttySAC0 console=ttyS0 mem=64M init=/linuxrc  在早期的Linux系统中,一般就只有软盘或者硬盘被用来作为Linux的根文件系统,

sdssly的专栏 2688

C#教程

C# 教程 C# 是一个简单的、现代的、通用的、面向对象的编程语言,它是由微软(Microsoft)开发的。 本教程将告诉您基础的 C# 编程,同时将向您讲解 C# 编程语言相关的各种先进理念。 现在开始学习 C#! C# 在线工具 谁适合阅读本教程? 本教程有助于初学者理解基础的 C# 编程。在学习完本教程后,您将到达一个中级的 C# 编程水平。

zm1_1zm 1万+

imx6q initramfs rootfs.cpio.gz.u-boot 的生成详解

fsl-image-mfgtool-initramfs-xxxx.rootfs.cpio.gz.u-boot 的生成流程如下, 该流程来自于yocto2.1 的BB 文件: (cd ${IMAGE_ROOTFS} && find . | cpio -o -H newc >${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}...

Qing的专栏 4655

LOFIC / 全局快门在移动端的可行性:曝光容限、读出噪声与算力预算

手机端引入 LOFIC 与全局快门的核心权衡在于:在有限像素面积与功耗下,如何换取更高的动态范围与运动场景鲁棒性。LOFIC 通过侧向溢流到积分电容扩大满井并保持较高转换增益,全局快门在帧内一次性采样消除行时序伪影,但需付出像素填充率、读出噪声与片上存储功耗的代价。本文以工程可实操为目标,给出像素与读出链的简化模型、曝光损益测算、数据率与带宽估算、端到端算力与热预算方法,配套寄存器配置流程、帧内/帧间切换策略与验证清单,帮助在真实移动 SoC 与 ISP 约束下完成可行性评估与原型落地。

努力分享一些人工智能、计算机视觉、影像等相关的知识干货! 1149

scratch绘制四个三角形 2024年6月中国电子学会 图形化编程 scratch编程等级考试二级真题和答案解析

​ scratch绘制四个三角形 一、题目要求 2024年6月电子学会图形化编程Scratch等级考试二级真题 1、准备工作 1.保留默认角色小猫; 2.添加背景Stars。 2、功能实现 1 .隐藏角色小猫,设置画笔裙始位置为(0,0),画笔颜色为黄色,画笔的粗细为5; 2. 点击绿旗,绘制如下图所示图形,三角形的边长为50。 二、案例分析 1、角色分析 角色:小猫 2、背景分析 背景:Stars背景 3、前期准备 1. 保留默认的小猫不变 ​

青少年编程学习指导 1730

ramfs, rootfs, tmpfs, initramfs and initrd

2019独角兽企业重金招聘Python工程师标准>>> ...

weixin_33827590的博客 169

HFSS实战项目——微带带通滤波器设计

本文详细介绍并设计了一款微带带通滤波器,通过HFSS三位电磁仿真软件对其进行仿真设计及优化,仿真结果表明,本文设计的滤波器表现出优良的滤波性能,符合设计要求。

2401_87464239的博客 5408

Linux rootfs挂载过程

Linux rootfs挂载过程

zzZhangYiLong的博客 3501

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

深入Linux内核:ramdisk解压到rootfs的全过程拆解(附GDB调试技巧)

本文深入解析Linux内核中ramdisk解压到rootfs的全过程,从CPIO格式处理到文件系统构建的完整链路。详细拆解了populate_rootfs()和unpack_to_rootfs()等核心函数,并提供了实用的GDB调试技巧,帮助开发者优化启动流程和解决常见问题。

weixin_29230773的博客 184

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

Linux kvmtool Kernel Virtual Machine Tool and ramfs Loading

ramfs加载完成后,内核解压initramfs时通过arch/x86/kernel/setup.c中的populate_initrd_image访问这些地址。每个mem_bank对应一个KVM memory slot,kvmtool通过KVM_SET_USER_MEMORY_REGION将host_addr线性映射到guest_phys_addr供Guest内核直接访问。/* 使用KVM_SET_USER_MEMORY_REGION映射 *//* 打开/dev/kvm获取KVM文件描述符 */

raoxiaoz0425的博客 95

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

linux 根文件系统的挂载分析(一)

在介绍根文件系统挂载之前先介绍一些基础知识 initramfs 当linux内核启动后,会找到并执行第一个用户程序,一般是init。这个程序存在于文件系统当中,文件系统存在于设备上,但不知道init存在哪个设备上,于是有了内核命令列选项root=,用来指定root文件系统存在于哪个设备上。 然后由于后来的设备类型越来越来多,比如可能在scsi,sata,flash这些设备,还有的存在于网络设

z41013774的专栏 1198

图文详解Linux根文件系统(1)

图文详解Linux根文件系统(1)

phmatthaus的专栏 133

深入Linux内核:图解Ramdisk从压缩包到根文件系统的完整解压与挂载流程

本文深入解析Linux内核中Ramdisk从压缩包到根文件系统的完整解压与挂载流程。通过图解和源码分析,详细介绍了Ramdisk的初始化、解压过程、文件系统挂载及用户空间启动等关键步骤,帮助开发者理解Linux启动机制并解决常见问题。

weixin_32121331的博客 329

EXT4 之 Android 文件系统剖析

文件系统的结构剖析。 inode和dentry之间的关系 superblock数据结构解析

caopeng的专栏 9769

arm系统启动后进入busybox 根文件系统(initramfs)

---------------------------------------- arm系统启动后进入busybox 根文件系统(initramfs) ---------------------------------------- 甲:交叉编译busybox, 注意书写ARCH=arm, 选择交叉编译前缀arm-none-linux-gnueabi-    用静态编译方式, 会省掉cop

hjjdebug的专栏 2224
上一篇: HOWTO: Unpack, Edit, and Re-Pack Boot Images
下一篇: Advanced Socket Topics
CodeJoker
博客等级 码龄18年 50粉丝 37原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址