Create the smallest root file system for linux

Source: Internet
Author: User
Create the smallest root file system for linux-general Linux technology-Linux programming and kernel information. The following is a detailed description. Source: cornsea-http://www.cnblogs.com/cornsea/archive/2009/02/23/1396177.html

During kernel compilation, you can specify a folder as the root file system when the kernel is started. In linux, the file system is called initramfs.

The procedure is as follows (take i386 as an example)

1. Download The Kernel File

Wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.26.tar.bz2

2. decompress the kernel

Bzip2-d linux-2.6.26.tar.bz2 to generate a linux-2.6.26.tar file, and then

Tar xvf linux-2.6.26.tar

After decompression, there will be a linux-2.6.26 folder

3. Prepare a folder for the iniramfs file system.

Create a folder myinitramfs under the linux-2.6.26 folder

Write a hello world for testing and name it hello. c, as follows:

# Include
# Include
Int main (int argc, char * argv [])
{
Int I = 0;
While (1 ){
Printf ("hello world (% d) \ n", I );
}
Return 0;
}

Compile gcc-static-o init hello. c

Copy init to the myinitramfs folder.

Cp init myinitramfs/

To display text, you also need to prepare the console device file in the folder.

Mkdir myinitramfs/dev

Cp-a/dev/console myinitramfs/

4. Compile the kernel

Under the linux-2.6.26 file, execute make help.

You will see a lot of help information, one of which is i386_defconfig

Run make i386_defconfig to generate a. config file.

To add the prepared folder to the Kernel configuration file, you must reconfigure the config file.

Make config

In General Setup --->

Initial RAM filesystem and RAM disk (initramfs/initrd) support (BLK_DEV_INITRD) [Y/n/?]

Initramfs source file (s) (INITRAMFS_SOURCE) [myinitramfs]

Enter the prepared folder.

After the configuration is completed, the. config file contains the following definition:

CONFIG_INITRAMFS_SOURCE = "myinitramfs"

Save. config

Make

5. Use qemu to test the kernel and initramfs

Qemu-kernel linux-2.6.26/arch/i386/boot/bzImage-initrd linux-2.6.26/usr/initramfs_data.cpio.gz/dev/zero

The initramfs_data.cpio.gz file is automatically generated by the internal kernel, with different domain names. However, the suffix is .cpio.gz.

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.