Linux system Setup (ii)--busybox build small Linux

Source: Internet
Author: User

Premise:

1, a host of Linux (Redhat Enterprise linux 5.9);

2, the host provides a piece of additional hard disk as the new system storage disk (IDE interface);

3, the Linux kernel source code (linux-2.6.18) and BusyBox source code (busybox-1.20.2).

4. VMware Platform: VMware Workstation Pro

One, hard disk partition and Mount 1, hard disk partition situation 650) this.width=650; "Src=" http://s4.51cto.com/wyfs02/M00/7F/60/wKioL1cciregxQ3XAAA172C_ Hii471.jpg "title=" 36020160424154847922.jpg "alt=" Wkiol1cciregxq3xaaa172c_hii471.jpg "/>2, Mount of hard drive on host
# mount/dev/hda1/mnt/boot# Mount/dev/hda2/mnt/sysroot
TwocompilingBusyBox
# cd/usr/src# TAR-JXVF busybox-1.20.2.tar.bz2# CD busybox-1.20.2

before you execute make menuconfig, copy include/mtd/ubi-user.h from linux-2.6.38.5 to BusyBox source include/mtd/( missing This header file in busybox-1.20.2)

# mkdir INCLUDE/MTD # cp/usr/src/linux/include/mtd/ubi-user.h include/mtd/# make Menuconfig

Description

1. Here you need to choose Busybox Settings---build options--build Busybox as a static binary (no shared libs), so you can Compile busybox into a static binary file that does not use a shared library, thus avoiding dependency on the shared library of the host, but you can also do this without selecting it, and then copy the shared library it relies on to the/lib directory on the target system after the compilation is complete. (The previous method is used here)

2, the modification installation position is/mnt/sysroot; method: Busybox Settings---Installation Options---/_install Busybox On prefix, modify its value to/mnt/sysroot. (This modification is not made in this article)

# make Install

after compiling, the _instal is generated under the BusyBox folder and copied to/TMP for production INITRD

# mkdir-pv/tmp/busybox# Cp-a/mnt/sysroot/*/tmp/busybox
Third, the production of INITRD
# cd/tmp/busybox# RM LINUXRC
1, establish Rootfs
# MKDIR-PV proc sys etc/init.d Lib/modules Dev mnt/sysroot
2. Create two necessary equipment files:
# Mknod Dev/console C 5 # Mknod dev/null C 1 3
3. This version of the Rhel kernel is not recognized by defaultext3 file system format, so that you want to add ext3 dependent library files.
# Cp/lib/modules/2.6.18-348.el5/kernel/fs/ext3/ext3.ko lib/modules/# cp/lib/modules/2.6.18-348.el5/kernel/fs/jbd/ Jbd.ko lib/modules/
4, for INITRD to make the INIT program, the main task of this program is to implement the ROOTFS switch, so you can script the way to achieve
# VIM Init

Add the following content:

#!/bin/shmount-t proc proc/procmount-t sysfs sysfs/sys# Insert Modulesinsmod/lib/modules/jbd.koinsmod/lib/modules/ex t3.ko# Mdev-s is to being run during boot to Scan/sys and populate/devmdev-smount-t ext3/dev/hda2/mnt/sysroot# switch Root Filesystemexec Switch_root/mnt/sysroot/sbin/init


To execute permissions on this script:

chmod +x Init
5. Making INITRD
# Find. | Cpio-h NEWC--quiet-o | gzip-9 >/mnt/boot/initrd.gz

Description

The kernel is not compiled here, and the host Vmlinuz is copied directly

#cp/boot/vmlinuz-2.6.18-348.el5/mnt/boot/vmlinuz
Iv. building a real root filesystem
# Cd/mnt/sysroot
1, establish Rootfs
# MKDIR-PV proc SYS lib/modules MNT media etc/rc.d/init.d tmp dev/pts boot root Var/{log,run,lock/subsys} usr/lib
2. Create two necessary equipment files:
# Mknod Dev/console C 5 # Mknod dev/null C 1 3
3. Set up the system initialization script file
# Vim Etc/rc.d/rc.sysinit

Add the following content :

#!/bin/shecho-e "\twelcome to \e[31mlite\e[0m Linux" Echo-e "remounting the root filesystem ..." mount-t proc Proc/proc Mount-t sysfs sysfs/sysmount-o remount,rw/echo-e "Creating The Files of device ..." mdev-s echo-e "mounting the F Ilesystem ... "mount-aswapon-a

Let this script have execute permissions:

# chmod +x Etc/init.d/rc.sysinit
4. Configure init and the required Inittab file (iNIT Process configuration file):
# Vim Etc/inittab

Add the following content:

:: Sysinit:/etc/rc.d/rc.sysinitconsole::respawn:-/bin/sh::ctrlaltdel:/sbin/reboot::shutdown:/bin/umount-a-R
5. Prepare a File system table configuration file for the system/etc/fstab
# Vim Etc/fstab

Add the following content:

sysfs                    /sys                     sysfs   defaults        0  0proc                     /proc                    proc    defaults         0 0/dev/hda1                /boot                    ext3    defaults        0  0/dev/hda2               /                         Ext3    defaults        1 1

Now that a simple memory-based small system has been built, we will then create the required bootstrapper for this system.

V. GRUB BOOT Program
# Grub-install--root-directory=/mnt/dev/hda

Note: The/dev/hda here is the new disk on which the target system resides;

Next, create a configuration file for grub:

# vim/mnt/boot/grub/grub.conf

Add something like the following:

Default=0timeout=3color light-green/black light-magenta/blacktitle Lite Linux (2.6.18) root (hd0,0) kernel/ Vmlinuz ro root=/dev/hda2 Quiet initrd/initrd.gz

Finally, test on the virtual machine.

Most of this article refers to Marco's information and online content.


This article is from the "Hiyang" blog, make sure to keep this source http://hiyang.blog.51cto.com/10728919/1767266

Linux system Setup (ii)--busybox build small 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.