For faster navigation, this Iframe is preloading the Wikiwand page for initrd.

initrd

Initrd ramdisk或者initrd是指在启动阶段被Linux内核调用的临时文件系统,用于根目录挂载之前的准备工作。[1]

基本原理

[编辑]

同其他Unix系统,Linux首先要将内核載入到内存。initrd通常被壓縮成gzip類型,開機時由bootloader(如LILOGRUB)來告知核心initrd的位置,使其被核心存取,掛載成一個loop型態的檔案。在2.6版本内核之后出现了initramfs,它的功能類似initrd,但是它基于CPIO格式,无须挂载就可以展开成一个文件系统。

initramfs 與 initrd

[编辑]

initramfs是initrd的替代品。initrd是一个被加载的块设备,内部有ext2一类文件系统的存在,于是由于Linux内核的缓存机制,其中的内容还会被缓存到内存上,造成一定的内存空间浪费。而initramfs本身就是一个tmpfsRAM disk,拥有最小化的设计,绕过了缓存机制,也消除了多余的内存占用。[2]

initramfs的生成方式也远比initrd简单。对于initramfs,只需 geninitramfs() { cd "$1"; find . -depth| cpio -o -H newc | ${3-cat}> "$2"; } 就可以利用cpio生成这样一个文件,同时使用一些程序进行压缩(通过额外的管道实现,其中使用cat仅用于无压缩时转发输出,可省去)。对于initrd,则涉及生成一定大小的空文件,然后创建文件系统,挂载并添加文件等等诸多步驟。

实现

[编辑]

Linux內核 與 initrd/initramfs 必須儲存在 bootloader 可以存取的位置,通常是在:

  • root 檔案系統內
  • 一個小的ext4FAT檔案系統的分割區(通常掛載到 /boot)
  • TFTP server內

bootloader 會將內核與 initrd 載入到記憶體中並將 initrd 的位址傳給內核。initrd會被掛載當成 initial root file system。

現在的 Linux 發行版會建立客製化只包含必要元件的 initrd 映像檔,例如只包含 IDESCSISATASAS 以及檔案系統核心模組。

参考

[编辑]
  1. ^ Almesberger, Werner, Booting linux: the history and the future, Proceedings of the Ottawa Linux Symposium, 2000 [2012-12-26], (原始内容存档于2008-07-24) 
  2. ^ The difference between initrd and initramfs?. Stack Overflow. [2014-04-24]. (原始内容存档于2021-01-26). 

更多链接

[编辑]
{{bottomLinkPreText}} {{bottomLinkText}}
initrd
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?