initrd: Using a RAM Disk

Modern Linux distributions use a modular kernel, which allows modules to be added without requiring that the kernel be rebuilt. If your root filesystem is on a device whose driver is a module, as is frequently true of SCSI disks, you can use the initrd facility, which provides a two-stage boot process, to first set up a temporary root filesystem in a RAM disk containing the modules you need to add (e.g., the SCSI driver) and then load the modules and mount the real root filesystem. The RAM disk containing the temporary filesystem is the special device file /dev/initrd.

Before you can use initrd, both RAM disk support (CONFIG_BLK_DEV_RAM=y) and initial RAM disk support (CONFIG_BLK_DEV_INITRD=y) must be compiled into the Linux kernel. Then you need to prepare the normal root filesystem and create the RAM disk image. Your Linux distribution may have utilities to do some of the setup for you; for example, the Red Hat distribution comes with the mkinitrd command, which builds the initrd image. For detailed information, see the initrd manpage and the file initrd.txt (the path may vary but is usually something like /usr/src/linux/Documentation/initrd.txt).

Once your Linux system has been set up for initrd, you can do one of the following, depending on which boot loader you are using:

  • If LILO is your boot loader, add the initrd option to the appropriate image section:

    image = /vmlinuz
      initrd = /boot/initrd  # The file to load as the contents of /dev/initrd
      ...

    Run the /sbin/lilo command, and you can reboot with initrd.

  • If you are using Loadlin, add the initrd option to the command line:

    loadlin c:\linux\vmlinuz initrd=c:\linux\initrd

Get Linux in a Nutshell, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.