Booting Linux II from the RAMDisk root file system

Source: Internet
Author: User

Today did a test, let Linux2.6.29.4 from the RAMDisk root file system to start a successful, summed up.
It involves more content, a lot of things no longer detailed, for further study please consult the relevant information (Baidu or Google a lot).


Development environment: Fedora 9
Cross-compilation toolchain: ARM-LINUX-GCC 4.3.2 with EABI
Embedded Linux kernel version: 2.6.29.4-friendlyarm. When I wrote the Post yesterday, I did not know the details, today to start the Development Board with Uname-r Check, is called 2.6.29.4-friendlyarm, the posts have been changed. This article is based on the 2.6.29.4-friendlyarm version of the friendly arm of the kernel. Other versions should also be similar, for informational purposes only.
Development Board: mini2440-128m Nand Flash
bootloader:u-boot-2009.11


The steps are as follows:
1. Unzip the kernel source tree
Extracting the linux-2.6.29-mini2440-20090708.tgz into your working directory will generate a friendly arm of the kernel source directory linux-2.6.29 that has been modified and has several mini2440 default profiles. Specific steps refer to the friendly arm mini2440 Development Board User manual, specifically not detailed.

2. Modify Kernel configuration options
Enter the kernel source directory linux-2.6.29 directory
#cp config_mini2440_t35. config
#make Menuconfig Arch=arm
Open the Configuration menu and modify the two configuration items, respectively:
A): General setup--> Select Initial RAM filesystem and RAM disk ... Item
b): Device drivers-->block devices--> Select RAM Block Device Support Item

And check if optimize for size is selected, if not selected, this key optimizes the kernel size and configures as needed.
Modify (8192) the Default RAM disk size Kbytes option for(4096) Default RAM disk size Kbytes, the reason for this modification is that the RAMDisk I made later is 4096KB in size. Of course, if you want to make 8192KB size RAMDisk, here is the corresponding 8192, and so on. But the smallest system, is not so big ramdisk. The default configuration for this item is (4096), which I had previously changed, so it was (8192). If this size does not match the ramdisk you do, the kernel panic kernel panic will still appear on startup, prompting the RAMDisk format is not correct and the RAMDisk is not mounted.
It is then important to note that RAMDisk is a memory virtual disk technology that is not essentially a file system that uses the file system when ext2 the file system. So be sure to go to the file Systems menu when make Menuconfig arch=arm, and select <*> Second extended FS support. To provide kernel support for the ext2 file system. I have previously added the ext2 file system, so there is no explanation at the beginning, here in order to explain why some people follow my method, but still kernel panic, especially this step is added.
Then save the configuration to exit.
This adds the RAMDisk startup function and RAMDisk driver support to the kernel.

3. Modify Kernel boot parameters
There are two methods:
A): Modify the No. 310 line of the. config and modify the definition of config_cmdline= ""
Modified to Config_cmdline= "initrd=0x31000000,0x200000 root=/dev/ram rw init=/linuxrc console=ttysac0 Mem=64M"
Save.
Starting from RAMDisk, RAMDisk compresses the file start address at the memory address 0x31000000, and the file size is 0x200000.
This parameter can also be entered in the Boot Options menu when make Menuconfig arch=arm, and then modified in the default kernel command string. The effect is the same.
b): Or do not modify the No. 310 line of the. config cmdline definition, but instead use the U-boot bootargs environment variable to pass the startup parameters.
Also modify the environment variable to bootargs=initrd=0x31000000,0x200000 root=/dev/ram rw init=/linuxrc console=ttysac0 Mem=64M
and saveenv save u-boot environment variable
Above a), B) The effect is the same.

4. Compiling the kernel
#make zimage Arch=arm cross_compile=arm-linux-
Then there was a wait of about 20 minutes.
The Zimage kernel image appears in the current directory when the compilation is complete.
As if the friendly arm of the kernel source directory in the Uimage target to comment, previously seen in the forum has been said that the direct make uimage as if prompted not uimage goal. So I first make zimage, and then use the U-boot mkimage tool to convert to Uimage. In fact Uimage is in the beginning of Zimage added a 64-byte kernel image description.

5. Making Uimage kernel image
Since I am using the bootloader is U-boot, so to convert Zimage to Uimage, the method is as follows:
#mkimage-A arm-o linux-t kernel-c none-a 0x30008000-e 0x30008000-n "Linux kernel Image"-D zimage Uimage-ramdisk
Description: The Mkimage tool is a u-boot format uimage kernel image authoring tool. If U-boot is compiled successfully, it will be under the Tools directory under the U-boot source tree. It is recommended that you copy it to the host's/sbin/directory for ease of use. Mkimage use of the specific parameters are no longer detailed, not clear please check their own.

6. Making RAMDisk root file system
This process is the core step of making the RAMDisk root file system, the method is as follows:
A) Create the root file system directory:
#cd转入到你的工作目录.
#mkdir Rootfs
#cd Rootfs
#mkdir bin Dev etc lib proc sbin sys usr MNT tmp var
#mkdir usr/bin usr/lib Usr/sbin lib/modules

b) Create the most basic device files:
#cd Dev
#mknod-M 666 console C 5 1
#mknod-M 666 null C 1 3
#cd:

c) Install/etc configuration file:
Here can directly the friendly arm of the Root_qtopia in a few basic configuration files, copy only the necessary, and the contents of the deletion, because I do not include the RAMDisk Qtopia, all copies come and no use.
I was looking for the smallest system from the Internet etc profile extracted directly into the root file system I made, and do reference to the friendly arm of the Root_qtopia added some content, see the final description.
The operation is as follows:
#tar etc.tar.gz-c/xxx/rootfs
XXX Indicates the directory where you want to make the rootfs.

d) Compile the kernel module:
The method is as follows:
Enter the Linux kernel source directory (linux-2.6.29)
#make Modules Arch=arm cross_compile=arm-linux-

e) Install the kernel module:
#make Modules_install Arch=arm Install_mod_path=/xxx/rootfs
XXX Indicates the directory where you want to make the rootfs.

f) Configuration BusyBox
Go to BusyBox directory to execute #make menuconfig
Enter "Build BusyBox as a static binary" in BusyBox Settings, build Options, which is a static link, eliminating the copying of a large number of library files.
Installation options, "Don t use/usr", to prevent BusyBox accidentally installed in the host system in the appropriate directory, destroy the host system.
Busybox installation Prefix (/XXX/ROOTFS), modify this option to indicate that the compiled Busybox will be installed to that location.

g) Compile and install BusyBox
#make Arch=arm cross_compile=arm-linux-
A few minutes after the compilation is complete
#make Install
Installed in the BusyBox installation Prefix (/XXX/ROOTFS) settings directory. Currently the root file system directory (/XXX/ROOTFS) that I want to make.

h) Make RAMDisk root file system image
Here's how:
Onhttp://genext2fs.sourceforge.net/Download can be simple and convenient to make RAMDisk file System tool GENEXT2FS, so that you do not like most of the internet as the cumbersome production RAMDisk image, the latest version is genext2fs-1.4.1.tar.gz.
Compile and build the tool genext2fs and put it into the/sbin/directory of the host for easy use.
Jump to the top-level directory of the rootfs you want to make
#genext2fs-B 4096-d rootfs RAMDisk
-B refers to the RAMDisk size of 4096K bytes made
-D refers to the root file system directory to be made into RAMDisk
The last RAMDisk is the name of the RAMDisk, and of course it can be renamed.
#gzip-9-F RAMDisk
The RAMDisk is optimally compressed to ramdisk.gz

7. Download the kernel image and RAMDisk image
Start U-boot, pause u-boot Auto-start, and on the u-boot command line, type the following command to download the kernel and RAMDisk image:
[[Email protected]]# tftp 0x32000000 Uimage-ramdisk
dm9000 I/o: 0x20000300, Id:0x90000a46
Dm9000:running in + bit mode
Mac:08:08:11:18:12:27
Operating at 100M full duplex mode
Using dm9000 Device
TFTP from server 192.168.31.117; Our IP address is 192.168.31.230
Filename ' Uimage-ramdisk '.
Load address:0x32000000
Loading:t T #################################################################
#################################################################
#
Done
Bytes transferred = 1917752 (1d4338 hex)
[[Email protected]]# tftp 0x31000000 ramdisk.gz
dm9000 I/o: 0x20000300, Id:0x90000a46
Dm9000:running in + bit mode
Mac:08:08:11:18:12:27
Operating at 100M full duplex mode
Using dm9000 Device
TFTP from server 192.168.31.117; Our IP address is 192.168.31.230
Filename ' ramdisk.gz '.
Load address:0x31000000
Loading:t T #################################################################
####
Done
Bytes transferred = 1002594 (f4c62 hex)

8) Boot the kernel using the RAMDisk root file system
Start the system by typing the following command at the u-boot command line:
Bootm 0x32000000
# # booting kernel from Legacy Image at 32000000 ...
Image Name:linux-2.6.29.4-friendlyarm
created:2010-04-09 15:13:52 UTC
Image Type:arm Linux Kernel image (uncompressed)
Data size:1917688 Bytes = 1.8 MB
Load address:30008000
Entry point:30008000
Verifying Checksum ... Ok
Loading Kernel Image ... Ok
Ok

Starting kernel ...

Uncompressing Linux ... ..... ... ..... ... ..... ..... ..... ..... ..... ..... ..... ..... ....... .........
...... .... done, booting T, ... done, .... Done, ... done, and .... done, and .... done, and .... Done.-----No, no, no, ..... done.
He kernel.
Linux version 2.6.29.4-friendlyarm ([email protected]Ldomain) (gcc version 4.3
.2 (Sourcery g++ Lite 2008q3-72)) #3 Fri Apr 9 23:13:36 CST 2010
cpu:arm920t [41129200] revision 0 (ARMV4T), cr=c0007177
CPU:VIVT data cache, VIVT instruction cache
Machine:friendlyarm Mini2440 Development Board
Memory POLICY:ECC Disabled, Data cache writeback
...... The content of the middle too long is omitted here ...
Ramdisk:compressed image found at block 0
vfs:mounted Root (ext2 filesystem) on device 1:0.
Freeing Init memory:136k
Eth0:link down

Processing/etc/profile ... Done

# Eth0:link up, 100Mbps, Full-duplex, LPA 0x45e1

The system started successfully.

----------------------------------------------------------------------------------
PostScript:Because of the friendly arm mini2440 the default configuration file is to compile the driver into the kernel directly, and does not use kernel modules. So the 6th step in making the root file system D) compilation and e) installation of kernel modules can be done without the steps. I did not compile the kernel module. Because the Root_qtopia root file system, referring to the friendly arm, found that/lib/modules/' uname-r ' had nothing at all. and used to use the friendly arm of the CONFIG_MINI2440_T35 default configuration when compiling kernel modules. Discover friendliness only made a hello_modules sample of kernel modules. We do not need to use this hello_modules here, so these two steps are slightly past.

Description:Because the ETC profile in the smallest system does not write the script to automatically start the NIC, I do not start the RAMDisk automatically start the network card. Later, the script can be started automatically by referring to the script in the Root_qtopia root file system of the friendly arm to make the following changes.
Modify the following:
Modify the/etc/init.d/rcs file under Rootfs of the RAMDisk root file system to be made
Add the following two lines of command at the bottom to automatically start the network card:
/sbin/ifconfig Lo 127.0.0.1
/sbin/ifconfig eth0 192.168.31.230 netmask 255.255.255.0 up

This method is discovered by analyzing the startup process of the Root_qtopia root file system of the friendly arm.
We can also find more content by analyzing the Root_qtopia root filesystem of the friendly arm. Not in detail here.
Exercise your ability to analyze and solve problems. Oh.

Booting Linux II from the RAMDisk root file system

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.