Phogat Ashish
Phogat Ashish

Reputation: 173

Initrd, Ramdisk, Initramfs, uclinux

I am working on uclinux porting on coldfire board M5272C3. Right now I have kernel running from RAM with romfs as my rootfile system. I am not clear about few terms what they mean and when to use them....

Please explain me in a simplest possible manner:

Q1: What is initrd? Why we need that?

Q2: What is ramdisk? Why and where we need this?

Q3: what is initramfs? Why and where we use this?

Q4: What is ramfs? Why and where we use this?

Also please refer document/reference book for in depth knowledge of these terms....

Thanks Phogat

Upvotes: 3

Views: 5233

Answers (1)

Tuxdude
Tuxdude

Reputation: 49473

A ramdisk merely refers to an in-memory disk image. It is implemented using the ramfs VFS driver in the kernel. The contents of the ramdisk would be wiped on the next reboot or power-cycle.

I'll give you details about initrd and initramfs next.

In simple terms, both initrd and initramfs refers to an early stage userspace root filesystem (aka rootfs) that will let you run a very minimal filesystem in memory.

The documentation present at Documentation/filesystems/ramfs-rootfs-initramfs.txt part of the linux kernel source tree, which would also give you a length description of what these are.

What is initrd ?

One common case where there is the need for such an early-stage filesystem is to load driver modules for hard disk controllers. If the drivers were present on the hard drive, it becomes a chicken-and-egg problem. Having these drivers as part of this early-stage rootfs helps the kernel load the drivers for any detected hard disk controllers, before it can mount the actual root filesystem from the hard drive. Another solution to this problem would be to have all the driver modules built into the kernel, but you're going to increase the size of the kernel binary this way. This kind of filesystem image is commonly referred to as initrd. It is implemented using either ramfs or tmpfs. It is emulated using a loopback block device.

The bootloader loads the kernel image into a memory address, the initrd image into another memory address, and tells the kernel where to find the initrd, passes the boot arguments to the kernel, and passes control to the kernel to let it continue the boot process.

So how is it different from initramfs then ?

initramfs is an even earlier stage filesystem compared to initrd which is built into the kernel (controlled by the kernel config of course).

As far as I know, both initrd and initramfs are controlled by this single kernel config, but it could have been changed in the recent kernels.

config BLK_DEV_INITRD

I'm not going deep into how to build your own initramfs, but I can tell you it just uses cpio format to store the files and can be configured using usr/Kconfig while building the kernel. Even if you do not specify your own initramfs image, but have turned on support for initramfs, kernel automatically embeds a very simple initramfs containing /dev/console, /root and some other files/directories.

In addition there is also a newer tmpfs filesystem which is commonly used to implement in-memory filesystems. In fact newer kernels implement initrd using tmpfs instead of ramfs.

UPDATE:

Just happened to stumble upon a similar question

This might also be useful

Upvotes: 8

Related Questions