AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题 / 764791
Accepted
wangt13
wangt13
Asked: 2023-12-14 07:55:30 +0800 CST2023-12-14 07:55:30 +0800 CST 2023-12-14 07:55:30 +0800 CST

如何验证内核映像中内置的 initramfs?

  • 772

我正在开发嵌入式 Linux 系统(kernel-5.10.24),并且我正在尝试在我的系统中启用 initramfs。

我按如下方式配置内核,

CONFIG_BLK_DEV_INITRD=y
CONFIG_INITRAMFS_SOURCE="/home/t/target_rootfs"
CONFIG_INITRAMFS_ROOT_UID=0
CONFIG_INITRAMFS_ROOT_GID=0
CONFIG_RD_GZIP=y
CONFIG_RD_BZIP2=y
....
# CONFIG_BLK_DEV_RAM is not set

并且target_rootfs有以下内容,

drwxr-xr-x 2 t t 4096 Dec 13 17:47 bin
drwxr-xr-x 4 t t 4096 Jun 28 06:23 dev
drwxr-xr-x 6 t t 4096 Dec 13 20:24 etc
drwxr-xr-x 3 t t 4096 Dec 13 17:47 lib
lrwxrwxrwx 1 t t    3 Oct 23 14:59 lib32 -> lib
lrwxrwxrwx 1 t t   11 Oct 23 15:01 linuxrc -> bin/busybox
drwxr-xr-x 2 t t 4096 Jun 28 06:23 mnt
drwxr-xr-x 2 t t 4096 Jun 28 06:23 opt
drwxr-xr-x 2 t t 4096 Jun 28 06:23 proc
drwxr-xr-x 2 t t 4096 Jun 28 06:23 root
drwxr-xr-x 2 t t 4096 Jun 28 06:23 run
drwxr-xr-x 2 t t 4096 Sep 19 18:58 sbin
drwxr-xr-x 2 t t 4096 Jun 28 06:23 sys
drwxr-xr-x 2 t t 4096 Jun 28 06:23 tmp
drwxr-xr-x 5 t t 4096 Dec 13 17:47 usr
drwxr-xr-x 3 t t 4096 Jun 28 06:23 var

内核命令行是

console=ttyS0,115200 init=/linuxrc ubi.mtd=5 root=ubi0:rootfs rootfstype=ubifs rw flashtype=nand

通过以上设置,系统就可以启动到shellnand rootfs中了!
现在为了验证initramfs内置内核是否正在工作(或正在使用),我做了以下操作。

  1. 我尝试擦除FLASH中MTD5中的rootfs分区

希望停止系统启动initramfs,但我得到了内核恐慌,如下所示,

[    0.715989] Kernel panic - not syncing: write error
[    0.720880] Rebooting in 10 seconds..
  1. 然后在target_rootfs我创建init并ln -sf bin/busybox init重建内核(保持 rootfs 未部署)中,我得到了以下内容,
[    5.266031] VFS: Cannot open root device "ubi0:rootfs" or unknown-block(0,0): error -19
[    5.274324] Please append a correct "root=" boot option; here are the available partitions:
[    5.282987] 1f00            1024 mtdblock0
[    5.282992]  (driver?)
[    5.289753] 1f01           65536 mtdblock1
[    5.289759]  (driver?)
[    5.296540] 1f02          195584 mtdblock2
[    5.296545]  (driver?)
[    5.303320] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
[    5.311876] Rebooting in 10 seconds..

那么,如何验证initramfs内置内核呢?

linux
  • 1 1 个回答
  • 19 Views

1 个回答

  • Voted
  1. Best Answer
    wangt13
    2023-12-14T09:44:31+08:002023-12-14T09:44:31+08:00

    我想我可以通过阅读ramfs rootfs initramfs 的内核文档来回答部分问题

    它说,

    什么是 initramfs?

    所有 2.6 Linux 内核都包含一个 gzip 压缩的“cpio”格式存档,该存档在内核启动时被提取到 rootfs 中。解压后,内核检查 rootfs 是否包含文件“init”,如果包含,则将其作为 PID 1 执行。如果找到,则该 init 进程负责完成系统的其余部分,包括定位和挂载真正的根设备(如果有)。如果在将嵌入式 cpio 存档解压到 rootfs 后,rootfs 不包含 init 程序,则内核将使用旧代码来定位并挂载根分区,然后从中执行 /sbin/init 的某些变体。

    因此,在我的第一次测试中,内核没有init在 initramfs 中找到该文件,因此它遵循旧路径。在我的第二次测试中,内核找到initinitramfs 中的文件,并启动它运行并进行初始化。

    这是我在部署 rootfs 后从第二次测试中获得的日志。

    [    5.352428] Warning: unable to open an initial console.
    [    5.357833] ====== kernel_init_freeable, 1541, 80a7fe00 (/init)
    [    5.364712] ====== kernel_init_freeable, 1544
    [    5.370661] UBIFS (ubi0:0): Mounting in unauthenticated mode
    [    5.376636] UBIFS (ubi0:0): background thread "ubifs_bgt0_0" started, PID 913
    [    5.403187] UBIFS (ubi0:0): start fixing up free space
    [    9.912861] UBIFS (ubi0:0): free space fixup complete
    [    9.934491] UBIFS (ubi0:0): UBIFS: mounted UBI device 0, volume 0, name "rootfs"
    [    9.942191] UBIFS (ubi0:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
    [    9.952459] UBIFS (ubi0:0): FS size: 189702144 bytes (180 MiB, 1494 LEBs), journal size 9023488 bytes (8 MiB, 72 LEBs)
    [    9.963525] UBIFS (ubi0:0): reserved for root: 0 bytes (0 KiB)
    [    9.969555] UBIFS (ubi0:0): media format: w4/r0 (latest is w5/r0), UUID B61B21A3-D917-436E-986D-091B195DF275, small LPT model
    [    9.981938] UBIFS (ubi0:0): full atime support is enabled.
    [    9.987664] VFS: Mounted root (ubifs filesystem) on device 0:14.
    [    9.994297] devtmpfs: mounted
    [    9.997393] ====== kernel_init_freeable, 1550
    [   10.009306] Freeing unused kernel memory: 17812K
    [   10.014107] This architecture does not have kernel memory protection.
    [   10.020789] ====== kernel_init, 1434, 00000000 (none)
    [   10.026726] ====== kernel_init, 1450, 80007c67 (/linuxrc)
    [   10.033039] Run /linuxrc as init process
    .....
    

    我添加printk了init/main.c,看起来内核首先/init从 initramfs 运行,然后/linuxrc按照内核命令行中的指定运行。

    所以现在的问题是谁安装了第二个 rootfs 并启动了/linuxrc?我的假设是/init,但内核日志显示它是kernel这样做的……

    以及如何停止系统initramfs?

    • 0

相关问题

  • 有没有办法让 ls 只显示某些目录的隐藏文件?

  • 使用键盘快捷键启动/停止 systemd 服务 [关闭]

  • 需要一些系统调用

  • astyle 不会更改源文件格式

  • 通过标签将根文件系统传递给linux内核

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve