Proficient in initramfs build stepbystep (5)

Source: Internet
Author: User
Article Title: proficient in building initramfs stepbystep (5 ). Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

17. Configure Kernel support for initrd

So far, our init ramfs is generated by the kernel compilation system and linked to the kernel. In fact, we can also use the cpio command to generate a separate init ramfs, Which is decoupled from kernel compilation and loaded to the kernel in the form of initrd during kernel running to increase flexibility.

First, configure the kernel to use a separate initrd: In the Device Driver/Block device/configuration directory, select the RAM filesystem and RAMdisk (init ramfs/initrd) support configuration item; go to the General Setup configuration directory and clear the original content of the init ramfs source file (s) configuration item. Copy the init ramfs file initramfs_data.cpio.gz that has been compiled by the kernel in the usr directory of the kernel source code tree ~ In the/initramfs-test directory, we first use this file to test the initrd init ramfs effect. Finally, run the make command to re-compile the kernel. In the QEMU test environment, write the content in the initrd Configuration box (below the linux Configuration box) ~ /Init ramfs-test/init ramfs_data.cpio.gz, specify the file path of initrd.

Let's test the init ramfs of the new initrd method. The effect is exactly the same as that of the previous one.

18. Use cpio command to generate init ramfs

Cpio commands have three operation modes: copy-out, copy-in, and copy-pass. The init ramfs is generated in the copy-out mode, that is, the file packaging operation mode. Use the-o command line option to specify the copy-out operation mode of cpio. By default, cpio reads the input data from the standard input and writes the output data to the standard output. The-I option can be used to specify the file name instead of the standard input, and the-O option can be used to specify the file name instead of the standard output, the file name specified by the-F option can replace the standard input or standard output according to the cpio operation mode.

Change ~ Package the files in the/init ramfs-test/image Directory into init ramfs and run the following command:

Find. | cpio-o-H newc | gzip> ../image.cpio.gz

After the command is executed ~ The init ramfs file named imgae.cpio.gz is generated under the/init ramfs-testdirectory.

The-H option of the cpio command above specifies the specific format of the package file. to generate the init ramfs, only the newc format can be used. If other formats are used, the kernel will output the following error message: unpacking init ramfs... <0> kernel panic-not syncing: no cpio magic

In the QEMU test environment, test the init ramfs of the new initrd method. The effect is exactly the same as that of the previous one.

Other usage of cpio commands

If we want to uncompress a package file in cpio format, we need to use the copy-in operation mode of the cpio command. Use the-I command line option to specify the copy-out operation mode of cpio. For example, we want to expand the init ramfs_data.cpio.gz copied from the usr directory of the kernel source code tree ~ Run the following command in the/init ramfs-test/init ramfs_data directory:

Mkdir ~ /Init ramfs-test/init ramfs_data

Cd ~ /Init ramfs-test/init ramfs_data

Cpio-I-F ../init ramfs_data.cpio.gz -- no-absolute-filename

After the command is executed, multiple directories and files appear under the init ramfs_data directory. Use the diff command to compare the init ramfs_data and image directories, which are identical.

The -- no-absolute-filename option of the above cpio command is used to remove "/" at the beginning of the file path when expanding the file and change the absolute path name to the relative path name. The init ramfs generated during kernel compilation uses the absolute path name, so this option must be used. Otherwise, the files in init ramfs are expanded to the "/" directory, if you are a root user or have the write permission for the "/" directory, the expanded file may overwrite the file with the same name (the file is new to the original file at the file modification time ), that's terrible!

[1] [2] Next page

Related Article

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.