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:
- #include <stdio.h>
- #include <unistd.h>
- 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-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.
- Describes how to install a wireless NIC Driver in Linux.
- Wine successfully runs Bitcomet in the Linux operating system
- Analysis of Open-source Cisco router virtual machines in Linux
- Basic Linux operating system knowledge
- Learning Manual: poll and select in Linux