gpt4 book ai didi

Mounting /dev/ and /sys/ filesystems(挂载/dev/和/sys/文件系统)

转载 作者:bug小助手 更新时间:2023-10-25 16:39:47 33 4
gpt4 key购买 nike



I have a question regarding /dev/ and /sys/ pseudo file systems creation in kernel. While kernel booting, rootfs mounts at the end and init process will be started after that. At kernel boot time, device drivers create device nodes(under /dev/) and sysfs entries(under /sys/) during device and driver binding. This device and driver binding can happen before rootfs mounts. How the /dev/ and /sys/ filesystems will be created under root(/) before rootfs mounts.

我有一个关于在内核中创建/dev/和/sys/伪文件系统的问题。在内核引导时,rootfs将在最后挂载,之后将启动init进程。在内核引导时,设备驱动程序在设备和驱动程序绑定期间创建设备节点(在/dev/下)和sysf条目(在/sys/下)。此设备和驱动程序绑定可以在挂载rootfs之前进行。在挂载rootfs之前,如何在根(/)下创建/dev/和/sys/文件系统。


更多回答

The /dev and /sys pseudo filesystems are primarily for userspace. The kernel always boots with an initramfs before there is ever a root filesystem on a block device. Note device drivers do not "create device nodes"; they merely have major & minor numbers.

Dev和/sys伪文件系统主要用于用户空间。在块设备上有根文件系统之前,内核总是使用initramfs引导。注意:设备驱动程序不“创建设备节点”;它们只有主编号和次要编号。

AFAIK when you use systemd in your initramfs aswell as in the real system, it has a special option to rescue over your /dev and remount it in the final rootfs. That is not needed for sys though, since sys is an in-kernel FS that can always be mounted whereever needed.

AFAIK当您在initramf中以及在实际系统中使用system d时,它有一个特殊的选项来拯救您的/dev并将其重新挂载到最终的rootfs中。不过,这对于sys来说并不是必需的,因为sys是一个内核内的文件系统,可以随时挂载到任何需要的地方。

I think, we can build kernel image without initramfs. Because I could see the options in usr/Kconfig can be enabled or disabled, which means we can disable initramfs for a kernel build(Ex: CONFIG_INITRAMFS_SOURCE default value is ""). I have checked character device source, it seems the details are stores in cdev_map and kobj_map. can you guide to understand how and who mounts /dev/ during the 2 scenarios(when initramfs enables and disables).

我认为,我们可以在没有initramf的情况下构建内核映像。因为我可以看到USR/KCONFIG中的选项可以启用或禁用,这意味着我们可以为内核构建禁用initramf(例如:CONFIG_INITRAMFS_SOURCE缺省值为“”)。我已经查看了字符设备源代码,细节似乎存储在CDEV_MAP和KOBJ_MAP中。在这两个场景中(initramfs启用和禁用时),您能指导理解如何以及谁挂载/dev/吗?

"I think, we can build kernel image without initramfs" -- No, you are conflating the initial rootfs with the option of providing a cpio archive file to populate that initramfs. Study Documentation/filesystems/ramfs-rootfs-initramfs.txt

“我认为,我们可以在没有initramf的情况下构建内核映像”--不,您是在将初始rootf与提供cpio归档文件来填充该initramf的选项混为一谈。研究Documentation/filesystems/ramfs-rootfs-initramfs.txt

优秀答案推荐

During the early stages of the Linux boot process, before the root filesystem (rootfs) is mounted, several filesystems can be mounted. The exact number and types of filesystems mounted may vary depending on the distribution, configuration, and specific boot process of the Linux system. However, there are typically three key filesystems mounted in the early boot stages:

在Linux引导过程的早期阶段,在挂载根文件系统(Rootfs)之前,可以挂载几个文件系统。根据Linux系统的分发、配置和特定引导过程,挂载的文件系统的确切数量和类型可能会有所不同。但是,在早期引导阶段通常会安装三个关键文件系统:


1. Initramfs (Initial RAM Filesystem): The initramfs is an initial filesystem that is loaded into memory during the early stages of the Linux boot process. It contains essential utilities, device drivers, and configuration files necessary for booting the system. While technically not mounted like other filesystems, it serves as a temporary working filesystem during the initial boot process. The initramfs is responsible for setting up device nodes in /dev/, mounting the /sys/ filesystem, and performing other tasks needed to initialize the system before transitioning to the root filesystem.

1.Initramfs(初始RAM文件系统):initramfs是在Linux引导过程的早期阶段加载到内存中的初始文件系统。它包含引导系统所需的基本实用程序、设备驱动程序和配置文件。虽然在技术上不像其他文件系统那样挂载,但它在初始引导过程中充当临时工作文件系统。Initramfs负责在/dev/中设置设备节点、挂载/sys/文件系统,以及在转换到根文件系统之前执行初始化系统所需的其他任务。


2. /dev/ (Device Filesystem): The /dev/ directory is a special filesystem that contains device nodes representing various hardware devices. These device nodes are used for device file operations, such as reading and writing to hardware devices. During the early boot stages, the /dev/ directory is typically created and populated with device nodes for detected hardware devices. This is often managed by the udev or mdev utility within the initramfs.

2./dev/(设备文件系统):/dev/目录是一个特殊的文件系统,它包含代表各种硬件设备的设备节点。这些设备节点用于设备文件操作,例如读写硬件设备。在早期引导阶段,通常会创建/dev/目录,并使用检测到的硬件设备的设备节点进行填充。这通常由initramf中的udev或mdev实用程序管理。


3. /sys/ (Sysfs Filesystem): The /sys/ filesystem is an in-memory filesystem (tmpfs) mounted by the Linux kernel early in the boot process. It provides a structured way to interact with and configure kernel features and exposes information about kernel objects, devices, and parameters. Sysfs is essential for kernel configuration and hardware management.

3./sys/(系统文件系统):/sys/文件系统是在引导过程早期由Linux内核挂载的内存文件系统(Tmpf)。它提供了一种与内核功能交互和配置内核功能的结构化方法,并公开了有关内核对象、设备和参数的信息。系统文件系统对于内核配置和硬件管理是必不可少的。


These filesystems are mounted to set up critical components, initialize devices, and provide the necessary infrastructure for the kernel and early boot processes to function correctly before transitioning to the root filesystem. The specific sequence and handling of these filesystems may vary between different Linux distributions and boot configurations.

挂载这些文件系统是为了设置关键组件、初始化设备,并为内核和早期引导进程在转换到根文件系统之前正常运行提供必要的基础设施。这些文件系统的特定顺序和处理在不同的Linux发行版和引导配置中可能有所不同。


更多回答

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com