The minimum root file is successfully created in Linux.

Source: Internet
Author: User

This article explains some problems that may occur when learning the Linux operating system, such as how to create a minimum root file system for Linux, I hope you will learn how to build a minimum root file system in Linux. 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.

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.bz2generate 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:

 
 
  1. #include <stdio.h> 
  2. #include <unistd.h> 
  3. int main(int argc,char *argv[])  
  4. {  
  5. int i = 0;  
  6. while (1) {  
  7. printf("hello world (%d)\n",i);  
  8. }  
  9.  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.

 
 
  1. Make config
  2. In General Setup ---> 
  3. Initial RAM filesystem and RAM disk (initramfs/initrd) support (BLK_DEV_INITRD) [Y/n/?]
  4. 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-kernelLinux-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.

The Linux root file system is successfully created.

  1. Describes how to install a wireless NIC Driver in Linux.
  2. Wine successfully runs Bitcomet in the Linux operating system
  3. Analysis of Open-source Cisco router virtual machines in Linux
  4. Basic Linux operating system knowledge
  5. Learning Manual: poll and select in Linux

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.