Linux started successfully using initramfs

Source: Internet
Author: User
Original address: http://www.arm9home.net/simple/index.php? T5645.html started a Linux experiment from the ramdisk root file system the day before yesterday and wrote a post. With the help of Kasim, the general moderator, I learned that Linux-based releases usually use initramfs instead of initrd. The architecture is simpler and the applications are more flexible. Just this evening, I just started Linux using initramfs and wrote a post to summarize it.
This post does not detail every step, but only describes the difference between it and the steps required to start the system using ramdisk. In fact, I also changed it based on the steps of configuring and compiling the kernel to start the system using ramdisk the day before yesterday. Here, we will only summarize the main differences between using initramfs and using ramdisk to configure kernel options and some problems encountered.

Refer to my other post titled "LINUX started successfully from the ramdisk root file system. To sum up,"
Http://www.arm9home.net/read.php? Tid-5610.html

Development Environment: fedora 9
Tool chain for cross-Compilation: Arm-Linux-GCC 4.3.2 with Eabi
Embedded Linux kernel version: 2.6.29.4-friendlyarm. This article is based on the config_mini2440_t35 kernel of 2.6.29.4-friendlyarm. Other versions should be similar for reference only.
Development Board: mini2440-128M NAND Flash
Bootloader: u-boot-2009.11

Main differences:
Step 2. Modify Kernel configuration options
Go to the kernel source code directory linux-2.6.29 directory
# Cp config_mini2440_t35. config
# Make menuconfig arch = arm
Open the configuration menu and set two options when you use ramdisk to start the system,You only need to configure one configuration item here:
General setup --> select initial Ram filesystem and RAM disk...

The reason is very simple. We use initramfs instead of ramdisk, so we do not need to configure the ramdisk driver support item device drivers --> Block devices --> ram block device support item. Corresponding (4096) default RAM disk size Kbytes and other related default configuration options will not appear again.

Another important difference between initramfs and ramdisk is that initramfs does not model a disk in the memory, so it does not require the ext2 driver support required by ramdisk. Therefore, the <> second extended FS Support option can be canceled for the ext2 File System under the file systems menu.

In this stepAnother important difference is that you need to go to General setup --> initial Ram filesystem and RAM disk ...... in the/work/rootfs initramfs source file (s) field, enter the root file system directory in the initramfs format.Here, the root file system directory I want to do is/work/rootfs.

Step 6. Create the initramfs root file system
H) Create an initramfs root file system image

The steps for creating the minimum system root file system are basically the same as those for creating the ramdisk root file system. Here, we only show what is the difference in the last step.
Because the initramfs root file system is executed at startupFirstProgramIt's init, not linuxrcSo here, the root file system we create needsAdd an init fileThe corresponding linuxrc file is no longer needed.
Modify the root file system as follows
# Cd/work/rootfs
# Ln-s bin/busybox init
In this way, a soft link init is created for busybox, which is the init file to be created.

In addition, we used the genext2fs tool when making the ramdisk root file system image. Here, we do not need to take any additional steps to make the initramfs root file system image, instead, it is automatically generated when you compile the Linux kernel.The automatically generated initramfs root file system image is in the USR directory of the Linux source code tree. Name: initramfs_data.cpio.gzIt is a GZ compressed file.

In this way, there is a problem inWhen compiling a kernel that can be started using initramfs, There is a related item in its configuration options, that is, in (/work/rootfs) initramfs source file (s) enter the root file system directory that you want to make into initramfs format. This requires that the root file system be ready first when compiling the kernel. It is worth noting that the kernel image we have produced based on this method is actually much larger than the original one, because we are doing this step, in fact, the initramfs root file system is directly merged into the kernel image. In this way,If you combine the two images, you no longer need to separately burn the root file system image. Correspondingly, you do not need to add initrd = ...... To specify the initramfs location. Of course, if you do not want to merge initramfs into the kernel, you can directly use the kernel configured with ramdisk to start the system. However, you must use initrd = ...... To specify the initramfs location, and the size of the second initramfs root file system image must be specified as the actual size. Otherwise, an image verification error is prompted and the system cannot be started.

There is no difference between others.

-------------------------------------------------------------------
Uimageand initramfs_data.cpio.gz have been compiled.
Use U-boot to download the kernel image and the initramfs root file system image. When the system is started, the kernel crashes and the kernel panic fails to be started.
The following error is displayed on the last line of the Super Terminal:
Unpacking initramfs... <0> kernel panic-not syncing: Bad gzip magic numbers

Check related errors online. The solution is as follows:
"This problem has been solved;

It is because the initrd = bufptr, size that I pass to the kernel in U-boot;
In the size parameter, the size is larger than the actual initramfs;
As a result, when unpack_to_rootfs calls gunzip to decompress the initramfs package, gunzip cannot determine the end address of the initramfs package. This is caused by repeated decompressing. (gunzip is really not intelligent, haha)

Set the size to be the same as the size of the initramfs package ;"

The system is started successfully.

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.