Initrd: Difference between revisions

From OSDev Wiki
Jump to navigation Jump to search
Line 1: Line 1:
{{Filesystems}}
{{Filesystems}}
(削除) {{Stub}} (削除ここまで)


"Initrd" stands for "(削除) initial ramdisk (削除ここまで)".
(追記) The term (追記ここまで)"Initrd" stands for "(追記) Initial RamDisk (追記ここまで)"(追記) . Basically, it is simply a file loaded into memory which the OS uses as a filesystem containing stuff necessary for it to boot (追記ここまで).


(削除) A modular kernel (like a (削除ここまで)[[(削除) Microkernel (削除ここまで)]] (削除) or (削除ここまで)[[(削除) Modular Kernel (削除ここまで)]](削除) ) (削除ここまで)commonly (削除) faces (削除ここまで)a chicken-(削除) and (削除ここまで)-egg problem: (削除) In order to initialize (削除ここまで)the (削除) hardware, it (削除ここまで)needs to load (削除) driver (削除ここまで)modules(削除) ; in order to load anything (削除ここまで)from disk, (削除) it needs (削除ここまで)the (削除) necessary drivers (削除ここまで)((削除) e (削除ここまで).(削除) g (削除ここまで). (削除) IDE / SATA (削除ここまで), (削除) filesystem (削除ここまで)driver (削除) etc (削除ここまで).).
(追記) == Uses of an Initial Ramdisk == (追記ここまで)
(追記) Initial Ramdisks are usually used by (追記ここまで)[[(追記) Modular Kernel (追記ここまで)]](追記) s and (追記ここまで)[[(追記) Microkernel (追記ここまで)]](追記) s, which (追記ここまで)commonly (追記) face (追記ここまで)a chicken-(追記) or (追記ここまで)-egg problem (追記) at boot time (追記ここまで): the (追記) kernel (追記ここまで)needs to load (追記) its (追記ここまで)modules from disk, (追記) but these modules include the driver that normally allows (追記ここまで)the (追記) kernel to access that disk (追記ここまで)((追記) although this applies to any other media) (追記ここまで). (追記) An Initrd is an elegant solution to this problem: the boot disk driver is stored within the initrd, which is loaded along with the kernel (追記ここまで). (追記) Then (追記ここまで), (追記) when the kernel boots, it retrieves the initrd in memory, loads the boot disk driver from it, and uses the freshly-loaded (追記ここまで)driver (追記) to load the rest of its modules (追記ここまで). (追記) This is the solution used by Linux (not the early versions (追記ここまで))(追記) , as well as many hobby OS's (追記ここまで).


(削除) An initial ramdisk is one way to solve this problem. Elementary modules are packed into a single file, which is then loaded together with the kernel by the bootloader. The kernel can then use the in-memory Initrd to initialize elementary hardware (e.g. those required for mass storage access). (削除ここまで)


(削除) The format (削除ここまで)of (削除) the image is (削除ここまで)totally (削除) depending (削除ここまで)on the (削除) kernel (削除ここまで)and its version(削除) . It could be a (削除ここまで)compressed (削除) archive (削除ここまで)of a (削除) "real" ramdisk with (削除ここまで)filesystem (削除) semantics (削除ここまで), (削除) which (削除ここまで)is (削除) uncompressed (削除ここまで)in (削除) memory (削除ここまで), or (削除) it could (削除ここまで)be a (削除) flat image (削除ここまで).
(追記) == Setting up an Initial Ramdisk == (追記ここまで)
(追記) An initrd is simply a file containing some sort (追記ここまで)of (追記) minimalistic filesystem (if it can be called so). That filesystem (追記ここまで)totally (追記) depends (追記ここまで)on the (追記) Operating system (追記ここまで)and its version(追記) , but it is usually some archive format ( (追記ここまで)compressed (追記) or not) such as [[tar]], which has the advantage (追記ここまで)of (追記) being very simple to generate using the ''tar'' command, (追記ここまで)a (追記) simplistic (追記ここまで)filesystem (追記) such as [[SFS]] (追記ここまで), (追記) or just a custom format. The good news (追記ここまで)is (追記) that this custom filesystem can be very simple: (追記ここまで)in (追記) fact (追記ここまで), (追記) it doesn't need the complications of usual filesystems, such as addition, modification (追記ここまで)or (追記) deletion of files, and the parsing logic has to (追記ここまで)be (追記) very simple: you don't want your kernel to spend 5 minutes reading the initrd on each boot, do you ? [http://www.jamesmolloy.co.uk/tutorial_html/8.-The%20VFS%20and%20the%20initrd.html JamesM's tutorials] describe the development of (追記ここまで)a (追記) VFS and of an initrd (追記ここまで).


(削除) Popular bootloaders like (削除ここまで)[[GRUB]] (削除) support loading initial ramdisks (削除ここまで). GRUB (削除) also supports (削除ここまで)loading (削除) additional (削除ここまで)kernel modules directly.
(追記) === Setup in a Multiboot-compliant kernel === (追記ここまで)
(追記) If you are using a [[Multiboot]]-compliant kernel, then most of the job is already performed by your bootloader (e.g. (追記ここまで)[[GRUB]](追記) ). All you have to do is tell GRUB to load it along with you kernel, as a [[Multiboot]] module (for GRUB, the setting is found in ''menu (追記ここまで).(追記) lst'' for (追記ここまで)GRUB (追記) Legacy, or ''grub.cfg'' for GRUB2), and use the [[Multiboot]] structure to find where it has been loaded. (追記ここまで)
(追記) === Setup in custom-booted kernels === (追記ここまで)
(追記) If you are using a custom bootloader, then you will have to load the initrd yourself. You can either load it at a fixed address and hardcode it into the kernel, or determine that address dynamically, and pass it to the kernel. (追記ここまで)
(追記) As an alternative, you can use the ''cat'' command to concatenate your kernel image and initrd image, and modify the linker script to setup a constant as the ending address of your kernel, which will match the (追記ここまで)loading (追記) address of your initrd, or just write a simple program to convert your initrd image into a C header containing a byte array containing its bytes, and include that into your (追記ここまで)kernel(追記) . (追記ここまで)
(追記) == Alternatives == (追記ここまで)
(追記) If you can't (or just don't want to) use an initrd, you can also use a reserved boot partition (which is much the same thing, except you'll need the disk driver before), or just build certain (追記ここまで)modules directly (追記) into the kernel, which might be a bad idea because changing filesystem or disk will require the kernel to be recompiled with different modules, unless you prefer to hard-build several disk drivers into the kernel, which will increase boot time. (追記ここまで)
(追記) The article on [[Modular Kernel]]s shortly describes some other alternative solutions (追記ここまで).


== See Also ==
== See Also ==

Revision as of 18:37, 22 September 2013

Filesystems
Virtual Filesystems

VFS

Disk Filesystems
CD/DVD Filesystems
Network Filesystems
Flash Filesystems

The term "Initrd" stands for "Initial RamDisk". Basically, it is simply a file loaded into memory which the OS uses as a filesystem containing stuff necessary for it to boot.

Uses of an Initial Ramdisk

Initial Ramdisks are usually used by Modular Kernels and Microkernels, which commonly face a chicken-or-egg problem at boot time: the kernel needs to load its modules from disk, but these modules include the driver that normally allows the kernel to access that disk (although this applies to any other media). An Initrd is an elegant solution to this problem: the boot disk driver is stored within the initrd, which is loaded along with the kernel. Then, when the kernel boots, it retrieves the initrd in memory, loads the boot disk driver from it, and uses the freshly-loaded driver to load the rest of its modules. This is the solution used by Linux (not the early versions), as well as many hobby OS's.


Setting up an Initial Ramdisk

An initrd is simply a file containing some sort of minimalistic filesystem (if it can be called so). That filesystem totally depends on the Operating system and its version, but it is usually some archive format (compressed or not) such as tar, which has the advantage of being very simple to generate using the tar command, a simplistic filesystem such as SFS, or just a custom format. The good news is that this custom filesystem can be very simple: in fact, it doesn't need the complications of usual filesystems, such as addition, modification or deletion of files, and the parsing logic has to be very simple: you don't want your kernel to spend 5 minutes reading the initrd on each boot, do you ? JamesM's tutorials describe the development of a VFS and of an initrd.

Setup in a Multiboot-compliant kernel

If you are using a Multiboot-compliant kernel, then most of the job is already performed by your bootloader (e.g. GRUB). All you have to do is tell GRUB to load it along with you kernel, as a Multiboot module (for GRUB, the setting is found in menu.lst for GRUB Legacy, or grub.cfg for GRUB2), and use the Multiboot structure to find where it has been loaded.

Setup in custom-booted kernels

If you are using a custom bootloader, then you will have to load the initrd yourself. You can either load it at a fixed address and hardcode it into the kernel, or determine that address dynamically, and pass it to the kernel.

As an alternative, you can use the cat command to concatenate your kernel image and initrd image, and modify the linker script to setup a constant as the ending address of your kernel, which will match the loading address of your initrd, or just write a simple program to convert your initrd image into a C header containing a byte array containing its bytes, and include that into your kernel.

Alternatives

If you can't (or just don't want to) use an initrd, you can also use a reserved boot partition (which is much the same thing, except you'll need the disk driver before), or just build certain modules directly into the kernel, which might be a bad idea because changing filesystem or disk will require the kernel to be recompiled with different modules, unless you prefer to hard-build several disk drivers into the kernel, which will increase boot time.

The article on Modular Kernels shortly describes some other alternative solutions.

See Also

  • tar archive format
  • SFS simple filesystem implementation

External Links

  • cpio archive format
  • SquashFS filesystem designed for small disks
  • CramFS filesystem designed for compressed ram disks
Retrieved from "https://wiki.osdev.org/index.php?title=Initrd&oldid=15202"