Creating Initramfs/ramdisk for Linux Systems

Source: Internet
Author: User
Tags gz file

Overview

You need to use INITRAMFS in your recent work. Initramfs is a RAM FS that enables Linux systems to be started in stages. There are two main ways to use Initramfs: one is to compile the minimum file system directly into the kernel image, the other is to make the RAMDisk, then load the RAMDisk into memory and assign it to the kernel. Either way, the kernel-driven support is required, so using INITRAMFS requires that support for Initramfs be turned on when the kernel is compiled.

The configuration menu is as follows:

The size of the INITRAMFS is limited, and the configuration of the RAM block driver is required to make the required size, configured as follows:

The figure uses 16MB, which can be configured to size as needed.

First, the file system is compiled into the kernel

The simplest way is to compile the minimal root file system into the kernel image. That would only require the location of the minimum root filesystem when the kernel was configured prior to compilation, and the configuration of the Initramfs source file would be as follows:

You can modify the path of the Initramfs source file according to your situation, just select Initramfs source file(s) the item carriage return and enter the root file system path:

After the configuration is finished compiling, the kernel image file compiled will be larger, because the bread contains the smallest file system.

Booting a kernel image with Initramfs is the same as starting a normal kernel, but the file system is in memory.

Second, the use of RAMDisk

Using RAMDisk as a Initramfs more flexible, do not need to compile the kernel every time, use some commands to make RAMDisk. RAMDisk also needs the support of the kernel, which has been said before. In order to reduce the memory space occupied by RAMDisk, sometimes it is necessary to compress the RAMDisk, the kernel needs to decompress when using compressed RAMDisk, we can configure the kernel so that the kernel supports some compression formats:

As can be seen, we configure the kernel to support the RAMDisk of gzip compression, in addition to the kernel also supports BZIP2,LZMA,XZ and LZO compression formats such as RAMDisk.

Here are the steps to make RAMDisk:

1, create a 16M empty file, our kernel configuration of RAM block device size of 16MB:

#dd if=/dev/zero of=ramdisk bs=1M count=16

2. Format this file

#mke2fs -F -m0 ramdisk

3. Mount this file (via loop device)

#mount -t ext2 -o loop ramdisk /mnt

4. Copy the minimum file system to RAMDisk

#cp ~/minirootfs/* /mnt -rf

5, Umount this RAMDisk

#umount /mnt

6, Compression RAMDisk

#gzip -9 ramdisk

The 6th step will result in a ramdisk.gz file, which is a well-crafted compressed RAMDisk file.
The above step to the 5th step, RAMDisk should already be ready to use, compression is to reduce the space they occupy.

With RAMDisk as INITRAMFS, you need to modify the Bootargs of the kernel to add some args options.

    • initrd=[address | path]

      Initrd=0xxxxxx is commonly used in arm platforms where the address specified by the INITRD parameter is the address RAMDisk loaded into memory.

    • Noinitrd
      This option allows the kernel not to convert INITRD to RAM disk, and the system can access the data in the INITRD via/DEV/INITRD after booting. In this way initrd can be any data, not necessarily a file system image.

    • Root=/dev/ram0
      INITRD is mounted as root. Start from the INITRD.

Detailed steps for RAMDisk production can be consulted in the kernel documentation kernel/documentation/initrd.txt

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Creating Initramfs/ramdisk for Linux Systems

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.