initramfs-kernel_deepin initramfs

initramfs-kernel_deepin initramfsOtherlanguages:一些基于Linux的计算机系统系统需要一个intramfs才能正常启动。在本指南中,将说明initramfs的概念,以及如何正确地创建和管理initramfs。Initramfs是什么介绍许多用户是没有必要关心initramfs系统的。他们的系统使用了简单的分区方案,而且没有奇奇怪怪的驱动程序或者设置(如加密的文件系统),因此Linux内核完全能够把…


Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

Other languages:

一些基于 Linux 的计算机系统系统需要一个intramfs才能正常启动。在本指南中,将说明 initramfs 的概念,以及如何正确地创建和管理 initramfs。

Initramfs 是什么

介绍

许多用户是没有必要关心initramfs系统的。他们的系统使用了简单的分区方案,而且没有奇奇怪怪的驱动程序或者设置(如加密的文件系统),因此 Linux 内核完全能够把控制权交给系统中的init可执行文件。但对于许多系统,initramfs 是强制性使用的。

了解 initramfs(或者需要)的关键概念是了解 Linux 引导过程的工作原理,即使是在高级方法中也是如此。

Linux 启动过程

一旦 Linux 内核控制了系统(内核在由启动加载引导程序加载后获得控制权),它就会准备好内存结构和驱动程序。然后它将控制交给应用程序(通常是 init),其任务是进一步准备系统并确保在引导过程结束时,所有必要的服务正在运行且用户能够登录。该 init 应用程序通过启动 udev 守护程序来执行此操作,该守护程序将根据检测到的设备进一步加载和准备系统。启动 udev 时,将挂载尚未挂载的所有剩余文件系统,并启动其余服务。

对于那些所有必需的文件和工具驻留在同一个文件系统中的系统, init 应用程序可以完全控制进一步的引导过程。但当有多个文件系统被定义(或拥有更多的外来设备)时,情况可能变得更棘手些︰

当 /usr 分区位于单独的文件系统上时,除非 /usr 可用,否则无法使用存储在 /usr 中的文件的工具和驱动程序。如果需要这些工具来使 /usr 可用,那么我们就无法启动系统。

如果根文件系统被加密,那么 Linux 内核将无法找到 init 程序,导致系统无法启动。

这个问题的解决方案长期以来一直使用 initrd(初始根设备)。

初始根磁盘

initrd 是一个内存中的磁盘结构(ramdisk),其中包含必要的工具和脚本,用于在将控制权交给根文件系统上的 init 应用程序之前挂载所需的文件系统。 Linux 内核在此根磁盘上触发安装脚本(通常称为 linuxrc,但该名称不是必需的),此脚本的工作是准备系统、切换到真正的根文件系统,然后调用 init。

虽然使用initrd是必要的,但是它有一些缺点:

这是一个完整的块设备,他需要整个文件系统的开销,它有一个固定的大小。选择一个initrd是太小了,所需要的脚本不适用。让它过大的话,就会浪费内存。

因为它是一个真实的、 静态的设备,它消耗 Linux 内核中的缓存内存和易于使用的文件(如分页),这使得 initrd 有更大的内存消耗。

initramfs 的诞生解决了这些的问题。

initial ram 文件系统

Initramfs 初始 ram 文件系统基于 ‘tmpfs ‘ (大小灵活、 内存中的轻量级文件系统),但是他并不是一个单独的块设备 (所以没有缓存和所有额外的开销)。就像 initrd,它包含的工具和脚本在被称为真正的根文件系统上的二进制文件 init启动之前被挂载 。这些工具可以解密抽象层 (用于加密的文件系统),逻辑卷管理器,软件 raid,蓝牙驱动程序基于文件系统的装载机等。

The content of the initramfs is made by creating a cpio archive. cpio is an old (but proven) file archiver solution (and its resulting archive files are called cpio files). cpio is definitely comparable to the tar archiver. The choice of cpio here was because it was easier to implement (code-wise) and supported device files which tar did not support at the time.

All files, tools, libraries, configuration settings (if applicable), etc. are put into the cpio archive. This archive is then compressed using the gzip utility and stored alongside the Linux kernel. The boot loader will then offer it to the Linux kernel at boot time so the kernel knows an initramfs is needed.

Once detected, the Linux kernel will create a tmpfs file system, extract the contents of the archive on it, and then launch the init script located in the root of the tmpfs file system. This script then mounts the real root file system (after making sure it can mount it, for instance by loading additional modules, preparing an encryption abstraction layer, etc.) as well as vital other file systems (such as /usr and /var ).

Once the root file system and the other vital file systems are mounted, the init script from the initramfs will switch the root towards the real root file system and finally call the /sbin/init binary on that system to continue the boot process.

创建一个initramfs

Introduction and bootloader configuration

To create an initramfs, it is important to know what additional drivers, scripts and tools will be needed to boot the system. For instance, if LVM is used, then LVM tools will be needed in the initramfs. Likewise, if software RAID is used, mdadm utilities will be needed, etc.

Several tools exist that help users create initramfs (compressed cpio archives) for their system. Those who want total control can easily create personal, custom initramfs images as well.

Once created, the bootloader configuration will need adjusted to inform it an initramfs is to be used. For instance, if the initramfs file is stored as /boot/initramfs-3.2.2-gentoo-r5, then the configuration in /boot/grub/grub.conf could look like the following:

FILE grub.confExample entry in grub.conf for booting with an initramfstitle Gentoo Linux 3.2.2-r5

root (hd0,0)

kernel /boot/kernel-3.2.2-gentoo-r5

initrd /boot/initramfs-3.2.2-gentoo-r5

使用 genkernel

Gentoo’s kernel building utility, genkernel, can be used to generate an initramfs, even if genkernel was not used to configure and build the kernel.

To use genkernel for generating an initramfs, it is recommended all necessary drivers and code that is needed to mount the / and /usr file systems be included in the kernel (not as modules). Then, call genkernel as follows:

root #genkernel –install –no-ramdisk-modules initramfs

Depending on the system, one or more of the following options may be needed:

Option

Description

–disklabel

Add support for LABEL= settings in /etc/fstab

–dmraid

Add support for fake hardware RAID.

–firmware

Add in firmware code found on the system.

–gpg

Add in GnuPG support.

–iscsi

Add support for iSCSI.

–luks

Add support for LUKS encryption containers.

–lvm

Add support for LVM.

–mdadm

Add support for software RAID.

–multipath

Add support for multiple I/O access towards a SAN.

–zfs

Add support for ZFS.

When finished, the resulting initramfs file will be stored in /boot.

使用 dracut

The dracut utility is created for the sole purpose of managing initramfs files. It uses a highly modular approach on what support is to be included and what is not to be included.

To install the Dracut utility, run:

root #emerge –ask sys-kernel/dracut

The next step is to configure dracut by editing /etc/dracut.conf. In the configuration file, which is well commented, in order to add support for needed modules.

Once configured, create an initramfs by calling dracut as follows:

root #dracut

由此产生的图像支持基于配置的通用系统启动在/etc/dracut.conf。另外,也可以产生专门为你的系统中的initramfs(其中dracut从现有的系统尝试检测所需要的工具,如驱动器等)。如果模块和驱动内置于内核(而不是作为单独的模块或固件),你可以在 –no-kernel 添加选项:

root #dracut –host-only –no-kernel

获取更多信息,请查看dracut和dracut.cmdline手册:

user $man dracut

user $man dracut.cmdline

参考

Initramfs 官方 Gentoo Wiki.

Custom Initramfs — the successor of initrd. It provides early userspace which can do things the kernel can’t easily do by itself during the boot process.

Early Userspace Mounting — how to build a custom minimal initramfs that checks the /usr filesystem and pre-mounts /usr. 另一个值得阅读的关于自定义 initramfs 的文章

外部资源

The ramfs-rootfs-initramfs.txt file within the Linux kernel documentation.

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/169671.html原文链接:https://javaforall.net

赞 (0)
全栈程序员-站长的头像全栈程序员-站长

相关推荐

  • 重新理解oauth2.0协议进行联合登录

    重新理解oauth2.0协议进行联合登录

    2021年7月10日
  • Docker镜像相关命令

    Docker镜像相关命令1、查看docker版本 docker version 2、列出本地主机上的镜像: docker images REPOSITORY:表示镜像的仓库源 TAG:镜像的标签 IMAGE ID:镜像ID CREATED:镜像创建时间 SIZE:镜像大小3、查询镜像 docker search 镜像名称…

    2022年6月13日
  • 理清那么多个OO(面向对象)

    OOA-Object-OrientedAnalysis(面向对象分析)OOT-Object-OrientedTesting(面向对象测试)OOP-Object-Oriented

    2021年12月24日
  • MySQL 使用方法简单教程

    MySQL 使用方法简单教程MySQL使用方法简单教程

    2022年6月26日
  • APP开发流程,移动应用开发流程

    APP开发流程,移动应用开发流程每天都有数以千计的移动应用程序发布到GooglePlay和AppleAppStore。其中一些移动应用程序是游戏,其他是社交网络,许多是电子商务应用程序。所有这些应用程序,如果专业构建,应遵循类似的移动应用程序开发过程。在BHW,我们已经构建了350多个网络和移动应用程序,在本文中,我将概述我们遵循的战略,设计和开发流程。每个应用程序都不同,我们的方法也在不断发展,但在开发移动应用程序时…

    2022年6月11日
  • UIP协议栈移植到u-boot详解「建议收藏」

    UIP协议栈移植到u-boot详解「建议收藏」UIP协议栈移植到u-boot详解        Author:杨正 date:2014.11.5 Email:y2012ww@gmail.com QQ:12097587561、uip简介      Uip网络是一个简单好用的嵌入式协议栈,易于移植且消耗的内存空间较少,应用于很多嵌入式产品。uIP协议栈去掉了完整的TCP/IP系统中不常用的功能,简化了通讯流程,只保留

    2022年10月20日

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号