Proficient in building initramfs stepbystep (11)

Source: Internet
Author: User
Article Title: proficient in building initramfs stepbystep (11 ). Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

Install klibc

(1) download the klibcsource code from linux/libs/klibc/"> http://www.kernel.org/pub/linux/libs/klibc/. the latest version is 1.5.

(2) unlock the source code and create a symbolic link to linux in the top-level directory to point to the linux kernel source code. Note that the kernel source code must be configured through make menuconfig and other commands.

(3) Execution

Make command to compile klibc. After compilation, there are shell and some common commands in the usr/dash and usr/utils directories in the klibc source code directory tree. They are divided into two versions: static link and dynamic link, in the static and shared directories respectively. For simplicity, our init ramfs uses the statically compiled version. The dynamically linked program must use the dynamic library file of klibc, which is located in the usr/klibc/directory.

33. run-init command

Similar to busybox, klibc also has a command to switch to the real root file system, which is the run-init command. The run-init command is in the same format as the switch_root command in busybox. It has two parameters: the first is the directory where the real root file system is mounted; the second is the init program path name in the real root file system, which is usually/sbin/init. That is

Run-init/newroot/sbin/init

You can switch from init ramfs to the real root file system mounted in the/newroot directory, and execute the/sbin/init initialization program.

. Try it

Now that we have compiled klibc and learned the key run-init command, we can try to use klibc to build init ramfs. We use QEMU as the test environment, and assume that there is a linux system on/dev/hda8, and the root file system is ext3.

(1) copy the required command to the image build directory

Copy the mount and mknod commands in the usr/dash/sh and usr/utils/static directories in klibc to the image/bin directory. Copy the usr/kinit/run-init/static/run-init command to the image/sbin directory.

Klibc static build commands do not need library files, so they do not need to be copied.

(2) create a device file on the hard disk

For simplicity, instead of using udev to create a device file, we directly use the mknod command to create a device file on the hard disk. For the IDE Hard Drive/dev/hda, its main device number is 3 and its secondary device number is 0, which is a block device type, therefore, use the following command to create the corresponding device file in the image/dev directory.

Mknod dev/hda B 3 0

The primary device Number of the partition on/dev/hda is also 3, and the secondary device number is the same as the Partition Number. Therefore, you can create/dev/hda1 ~ /Dev/hda8 device file.

(3) create/init scripts

#! /Bin/sh

/Bin/mount-t sysfs/sys

/Bin/mount-t proc/proc

/Bin/mount-t ext3/dev/hda6/mnt

Exec/sbin/run-init/mnt/sbin/init

(4) use the cpio command to construct the init ramfs, and then perform the test in the QEMU environment. If nothing happens, the test system can correctly switch from init ramfs to the real linux system.

 

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.