Build a Linux system based on busybox

Source: Internet
Author: User
We sometimes need to create Linux based on busybox, but we do not know how to do it, the following describes how to create a linux mini system based on busybox. Prepare the environment: 1. a full Redhat system virtual machine. this time, we create a Linux small system based on busybox.

We sometimes need to create linux on the basis of busybox, but we do not know how to do it. here we will give a detailed description of how to create a linux small system based on busybox. Prepare the environment:
1. a full Redhat system virtual machine. This instance uses Redhat Enterprise Linux 5.8
2. add a hard disk on the primary virtual machine as the storage disk of the small system. here the IDE hard disk is added,
3, prepare the Linux kernel source code and busybox source code, here using linux-2.6.38.5 and busybox-1.20.2 version
4. copy the kernel configuration on the current system (/usr/src/kernel/2.6.18-308. el5-i686 /. if the current system kernel version is different from the linux kernel version, you can prepare a matching kernel blueprint. I have prepared a newer kernel blueprint (kernel-2.6.38.1-i686.cfg) for modification and compilation because the kernel version of the main system is relatively old.

Specific process:
I. Compile the kernel
1. extract the kernel source code under/root to the linux-2.6.38.5 under/usr/src, and create a connection for it, named linux
2. Compile the kernel based on/root/kernel-2.6.38.1-i686.cfg in the Linux Kernel link file
(1) copy the kernel blueprint to the/usr/src/linux directory and name it. config.
(2) compile the current kernel and select various functions as needed. In this example, the ext3 file system and the vmwarevm NIC driver of pcnet32 are directly loaded into the kernel. other options are as needed. After compilation, the compilation function can be automatically saved to the. config file. Finally, execute make SUBDIR =/arch for compilation.
[Go to the manual Kernel Compilation Interface, provided that the "Development Tools" "Development Libraries" group has been installed in grouplist. if not, configure the yum source and install the two Package groups]

[Go to Device Drivers --> Network device support --> Ethernet (10 or 100 Mbit) --> Find the AMD PCnet32 PCI support and change it to * to directly compile it into the kernel]
[Load Ext3 into the kernel in File systems -->]
Save and exit]
[Execute make SUBDIR =/arch for Compilation. note: the above steps must be performed in/usr/src/linux]


The compilation process may take some time. you can wait for the compilation to complete or take the next step in advance.
2. compile busybox
1. partition on the new hard disk. a m primary partition is required as the boot partition of the small system. a m primary partition is the root partition of the small system. After formatting the two partitions, mount them to the/mnt/boot and/mnt/sysroot directories respectively.

(W save and quit)
# Synchronize disks
2. install grub


3. compile busybox

[The default configuration here provides a lot of programs we need, so we don't need to make too many modifications. we just need to modify the compilation option and compile it into a static binary file that does not use the shared library, this avoids dependency on the shared libraries of the Master System. However, you can skip this option, after compilation, copy the dependent shared library to the/lib Directory of the target system. The previous method is used here.]
Busybox Settings --> Build Options --> Build BusyBox as a static binary (no shared libs)
Save and exit]
[Then make install compilation Note: Is in the busybox-1.20.2 Directory]

3. create initrd
(1) create a directory dedicated to implementing busybox-based initrd

(2) create initrd under/tmp/initrd
[Basic directory]

[Create an init script]
# Vim/tmp/init

# Chmod + x init plus execution permission
[Create initrd; archive and compress all files in the current directory to/mnt/boot/initrd.gz]
4. after the kernel is compiled successfully, load the kernel

5. provide grub configuration files
# Vim/mnt/boot/grub. conf


6. build a true root file system
Copy the busybox-1.20.2/_ install/* to/mnt/sysroot/rootfs to be created in busybox as the root file system for small linux]

[Create the required Directory, that is, create rootfs]

[Create two necessary device files]

[Configure init and the required inittab file to provide the configuration file for the init process]
# Vim/mnt/sysroot/etc/inittab

[Create a system initialization script]
# Vim/mnt/sysroot/etc/rc. d/rc. sysinit

[Provides the configuration file etc/fstab that is automatically mounted upon startup]
# Vim/mnt/sysroot/etc/fstab
[To adapt to the bash we are used to, copy bash and change the sh in the previous script to bash]

Change the sh set in etc/inittab to bash.
# Vim/mnt/sysroot/etc/inittab

[Synchronize]
# Sync
# Sync
# Sync
# Sync
# Sync
VII. test
Start the target host with a small system hard disk to check whether the commands are successfully executed.
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.