Initramfs starting Linux

Source: Internet
Author: User

First, Rootfs production:

The root file system is the first file system used by Linux to boot, just like the file directory on a PC

1. Create the directory of the root file system (directory name Random)

mkdir Rootfs

CD Rootfs

mkdir Bin Dev etc lib home proc sbin sys usr MNT tmp var

mkdir usr/bin usr/lib Usr/sbin lib/modules

2. Create a Device file

CD dev/

Mknod-m 666 Console C 5 1

Mknod-m 666 NULL C 1 3

3. Configure BusyBox (Linux is a set of commands and tools used below)

Unzip the BusyBox and enter the BusyBox root directory

Make Menuconfig

Select the tools you want to use

Enter BusyBox Settings->build option->

Check "Build BusyBox as a static binary", Static link

Change cross Compiler prefix to (arm-linux-)

Third, compile and install BusyBox

Copy the relevant command/file to the file system you are creating

1. Under the BusyBox root directory

Modify Makefile

Arch=arm

cross_compile=arm-linux-

Make

650) this.width=650; "title=" 6631710980001993205.jpg "src=" https://s2.51cto.com/wyfs02/M01/06/97/ Wkiom1m6e8rqnhiqaada-z6adco586.jpg-wh_500x0-wm_3-wmp_4-s_1345791393.jpg "alt=" Wkiom1m6e8rqnhiqaada-z6adco586.jpg-wh_50 "/>

Make install

650) this.width=650; "title=" 6631822030676395001.jpg "src=" https://s4.51cto.com/wyfs02/M01/A5/47/ Wkiol1m6e8gtuscnaaaowrhzwq4081.jpg-wh_500x0-wm_3-wmp_4-s_4224716163.jpg "alt=" Wkiol1m6e8gtuscnaaaowrhzwq4081.jpg-wh_50 "/>

CP-RF _install/* Rootfs

Since/ROOT/ROOTFS/LINUXRC and/root/rootfs/sbin/init are the same program, you can remove LINUXRC to save space, Ln-s/sbin/init init

[[email protected] rootfs]# ls

Bin Dev etc home lib init mnt root proc sbin sys tmp usr var

2. Create a directory file under etc

CD etc

Cp-a/root/busybox-1.20.2/examples/bootfloppy/etc/*.

[[email protected] etc]# ls

Fstab INIT.D Inittab Profile

3. Modify these files

Modify Inittab

Original file:

:: Sysinit:/etc/init.d/rcs

:: respawn:-/bin/sh

Tty2::askfirst:/bin/sh

:: Ctrlaltdel:/bin/umount-a-R

After modification: power-on without landing directly open the shell (the front number represents the line number)

:: Sysinit:/etc/init.d/rcs

Console::askfirst:-/bin/sh

:: Ctrlaltdel:/bin/umount-a-R

After modification: The power-on need to log on (the front number represents the line number)

:: Sysinit:/etc/init.d/rcs

:: Respawn:-/bin/login

:: Ctrlaltdel:/bin/umount-a-R

Modify Fstab

PROC/PROC proc Defaults 0 0

None/dev/pts devpts mode=0622 0 0

TMPFS/DEV/SHM TMPFS Defaults 0 0

Modify Profile

#/etc/profile:system-wide. profile file for the Bourne shells

Path=/bin:/sbin:/usr/bin:/usr/sbin

Export Ld_library_path=/lib:/usr/lib

/bin/hostname Test

User= "' Id-un '"

Logname= $USER

Hostname= '/bin/hostname '

Ps1= ' [\[email protected]\h \w]# '

echo "All done!" echo

4. Modify/etc/init.d/rcs

echo "Starting RcS ..."

echo "+ + mounting filesystem ..."

MOUNT-T proc None/proc

Mount-t Sysfs None/sys

Mkdir-p/DEV/SHM

Mount-t Tmpfs none/tmp

echo "+ + Setting up Mdev ..."

Echo/sbin/mdev >/proc/sys/kernel/hotplug

Mkdir-p/dev/pts

Mkdir-p/DEV/I2C

Mount-t devpts devpts/dev/pts

/sbin/mdev-s

/bin/mount-a

echo "+ + starting telnet daemon ..."

Telnetd-l/bin/sh #telnetd-L/bin/mylogin (mylogin self-written program with password authentication)

echo "+ + Set Network ..."

/sbin/ifconfig Lo 127.0.0.1 netmask 255.0.0.0

/sbin/ifconfig Eth9 192.168.3.1

/sbin/ifconfig eth9 netmask 255.255.255.0

echo "RcS Complete"

5. Copy passwd, shadow, and group files from the native computer.

[Email protected] etc]# cp/etc/passwd.

[Email protected] etc]# Cp/etc/shadow.

[Email protected] etc]# Cp/etc/group.

[Email protected] etc]# cp/etc/localtime.

echo "Root::0:0:root:/root:/bin/sh" >/etc/passwd

echo "Root:x:0:root" >/etc/group

echo "Root:$1$3jz93mwq$oaeef6lwiuthavs8wd0wh1:0:0:99999:7:::" >/etc/shadow

The user name is root and the password is 123456.

6. Copy the Cross compiler ***/lib/***.so library (depending on your system needs) to the/lib directory

[email protected] lib]# CP ***/lib/***.so. -A

To this file system finished

Iv. Production of Initramfs

Delete. config

CP Linux-2.6.26/arch/mips/configs/xxxxx_config Linux-2.6.26/.config

Modify Makefile

Arch=mips

cross_compile=mipsel-linux-

Step 1.make Menuconfig Open the Configuration menu

General setup--> Select Initial RAM filesystem and RAM disk ...; [*] Compress RAMDisk by Lzma instead of gzip, the reason is simple, we're using Initramfs instead of RAMDisk, so don't configure RAMDisk driver support Item device drivers--> Block Devices-->ram block Device support item, the corresponding default configuration options, such as the following (4096) Defaults RAM disk size Kbytes, will no longer appear.

Another important difference between INITRAMFS technology and RAMDisk technology is that INITRAMFS does not emulate a disk in memory, so it does not require the EXT2 driver support required for RAMDisk. Therefore, the Ext2 file system support < > Second Extended FS supports option can be canceled under the Files Systems menu.

Another important difference in this step is the need for general Setup-->initial RAM filesystem and RAM disk ... The item's related item (/ROOT/ROOTFS) Initramfs source file (s) is populated with the root filesystem directory that you want to make into INITRAMFS format, where I want to do the root file system directory is/root/rootfs.

Step 2: Make Initramfs root file system

The steps to make a minimal system root file system are basically consistent with the previous steps to make the RAMDisk root file system, which only shows how the last step is different.

In addition, we are using the GENEXT2FS tool when we make the RAMDisk root file system image, we do not need additional steps when making the Initramfs root file system image, but it is generated automatically when you compile the Linux kernel. The automatically generated Initramfs root file system is mirrored in the USR directory of the Linux source tree. Name is initramfs_data.cpio.gz, it is a zip file in GZ format

So there is a problem, when compiling a kernel that can use INITRAMFS boot, its configuration options have a correlation, is to be in (/ROOT/ROOTFS) Initramfs source file (s) Fill in the root file system directory you want to make into INITRAMFS format. This requires us to compile the kernel, first of all the root file system to do a good job. It is important to note that the kernel image that we made in this way is actually a lot larger than the original, because when we do this, we actually merge the Initramfs root filesystem directly into the kernel image. In this way, a single image will no longer need to burn a separate root file system image, corresponding to the boot kernel parameters do not need to add initrd= ... To specify the location of the Initramfs.

Step 3: Compile the installation kernel

CD Linux 2.6.26

Make Modules_install install_mod_path=/***/rootfs//Generate rootfs/lib/modules/2.6.26

Step 4: Modify the Makefile compilation

Objcopy Tool Parameter Introduction

#使用-o binary (or--out-target=binary) output is the original binary file

#使用-R. Note (or--remove-section) output file do not. Note This section, reducing file size

#使用-S (or--strip-all) output files do not reposition information and symbol information, reducing file size

Due to the use of u-boot boot, so the kernel to make Uimage,uimage is a u-boot dedicated image file, it is before the zimage with a length of 0x40 "header", indicating the type of the image file, loading location, generation time, size and other information, Vmlinux is the most primitive non-compressed kernel file.

Comp=lzma (compression mode) Image:mkimage

$ (cross_compile) Objcopy-o binary-r. Note-r. Comment-s $ (RootDir)/$ (Linuxdir)/vmlinux $ (Kernelz)

CD $ (IMAGEDIR); Rm-f $ (Kernelz). *; $ (comp) -9-f-S. $ (Comp) $ (Kernelz)

CD $ (IMAGEDIR); $ (cur_dir)/mkimage-a mips-o linux-t kernel-c $ (COMP)-a 80000000-e $ (Shell readelf-h $ (RootDir)/$ (linuxdir)/vmlinux | grep "Entry" | awk ' {print $$4} ')-n "Linux Kernel Image"-D $ (Kernelz). $ (COMP) $ (Image)

The uimage generated after make is the Initramfs boot file system.

Five, embedded Linux supported file system:

Jffs2,yaffs,cramfs,ramdisk,ramfs

JFFS2: For Norflash, can read and write, support data compression

YAFFS2: For Nandflash, data compression not supported, can read and write

Cramfs: Can be used on norflash, and can be used on Nandflash, read-only, support data compression

RAMDisk: Use a portion of fixed-size memory as a partition, not an actual file system, to facilitate kernel boot

NFS: File system on PC, shared over network
650) this.width=650; "title=" 6632050729095279025.jpg "src=" https://s5.51cto.com/wyfs02/M02/06/97/ Wkiom1m6fddaahntaabt3yuo-d4471.jpg-wh_500x0-wm_3-wmp_4-s_3043568825.jpg "alt=" Wkiom1m6fddaahntaabt3yuo-d4471.jpg-wh_50 "/>

This article is from the "Linux_woniu" blog, make sure to keep this source http://llu1314.blog.51cto.com/5925801/1965284

Initramfs starting 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.