Manually customize a BusyBox-based micro Linux system

Source: Internet
Author: User
Tags bz2 ide hard drive

Manually customize a BusyBox-based micro Linux system

Premise:

1. A Linux as host; the system version is Redhat Enterprise Linux 5.8;

2, BusyBox source; version is busybox-1.20.2. Busbox to pack a lot of commands together

3, add a piece of extra hard disk on the host as the storage disk of the new system, add a new hard disk using an IDE interface;

4. Download the Linux kernel source code and BusyBox source code via https://busybox.net/and https://www.kernel.org/respectively.

5. Create a new redhat5.8 host under vmware10.0 to experiment and add additional hard drives

First, for the new hard disk on the system to establish two partitions, size customization and format, the/DEV/HDA1 mounted to the/mnt/boot directory, the/DEV/HDA1 mounted to the/mnt/sysroot directory;

FDISK/DEV/HDA Create a new two primary partition Hda1,hda2

Partprobe/dev/hda the kernel to re-read the partition table and take effect

Mke2fs-j/dev/hda1

Mke2fs-j/dev/hda2

Mkdir/mnt/boot

Mkdir/mnt/sysroot

Mount/dev/hda1/mnt/boot

Mount/dev/hda2/mnt/sysroot

Second, get the kernel: Copy the host's existing kernel directly or compile the new kernel on demand

1. If you are compiling a new kernel kernel, proceed as follows:

Cd/usr/src

Tar jxvf linux-2.6.38.5.tar.bz2

LN-SV linux-2.6.38.5 Linux

CD Linux

Make Menuconfig save to the current directory as desired. config file

Make subdir=arch/only compile the platform core

CP Arch/x86/boot/bzimage/mnt/boot

Tip: It is best to compile the driver of the EXT3 and network card in the file system directly into the kernel, otherwise it is necessary to manually load the corresponding module;

2. In order to facilitate, do not recompile the kernel, directly use the host system existing kernel. Simple and clear

Cp/boot/vmlinuz-2.6.18-308.el5/mnt/boot/vmlinuz

Third, compiling BusyBox

Cd/usr/src

TAR-JXVF busybox-1.20.2.tar.bz2

CD 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 The static binaries of the shared library are not used, which avoids the dependency on the shared library of the host, but you can also choose not to do so, and then copy the shared library that it relies on to the corresponding Lib directory on the micro-system after compiling. It's a little bit trickier.

2, if you want to modify the installation location, the method is: Busybox Settings-Installation Options-and (./_install) Busybox installation prefix, where you can modify the installation path, This experiment remains unchanged by default

Make install

The installed files are located in the/usr/src/busybox-1.20.2/_install directory;

Mkdir-pv/tmp/initrd

Cp-r/usr/src/busybox-1.20.2/_install/*/TMP/INITRD

Iv. Production of INITRD

Cd/tmp/initrd

1, establish ROOTFS:

MKDIR-PV proc SYS etc/init.d TMP dev mnt/sysroot

2. Create two necessary equipment files:

Mknod dev/console C 5 1

Mknod dev/null C 1 3

3, for INITRD to make the INIT program, the main task of this program is to implement the root file system switch, so it can be completed by script:

RM LINUXRC

VIM Init

Add the following content:

#!/bin/sh

MOUNT-T proc Proc/proc

Mount-t Sysfs Sysfs/sys

Insmod/lib/modules/jbd.ko

Insmod/lib/modules/ext3.ko

Mdev-s

Mount-t Ext3/dev/hda2/mnt/sysroot

EXEC switch_root/mnt/sysroot/sbin/init

To execute permissions on this script:

chmod +x Init

Copy Ext3.ko and Jbd.ko to the corresponding directory

Modinfo ext3 Find System ext3 module path for easy copy

Modinfo JBD Find System JBD module path for easy copy

Cp/lib/modules/2.6.18-308.el5/kernel/fs/ext3/ext3.ko/lib/modules/ext3.ko

Cp/lib/modules/2.6.18-308.el5/kernel/fs/jbd/jbd.ko/lib/modules/jbd.ko

4. Making INITRD

Find. | Cpio--quiet-h Newc-o | Gzip-9-n >/mnt/boot/initrd.gz

5. Making the 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;

Grub Setup Configuration file:

Vim/mnt/boot/grub/grub.conf

Add the following content:

Default 0

Timeout 5

Title BusyBox Linux (2.6.18)

Root (hd0,0)

Kernel/vmlinuz ro root=/dev/hda2

Initrd/initrd.gz

The kernel Vmlinuz,initrd,grub and other files required to boot the system at this/mnt/boot/directory are all established OK

V. Building a real root file system

Cd/mnt/sysroot

Cp-r/usr/src/busybox-1.20.2/_install/*/mnt/sysroot/

1, establish ROOTFS:

MKDIR-PV proc SYS etc/rc.d/init.d tmp dev/pts boot Var/log usr/lib

2. Create two necessary equipment files:

Mknod/mnt/sysroot/dev/console C 5 1

Mknod/mnt/sysroot/dev/null C 1 3

3. Set up the system initialization script file

Vim/mnt/sysroot/etc/rc.d/rc.sysinit

Add the following content:

#!/bin/sh

Echo-e "\twelcome to \033[31mbusybox\033[0m Linux"

Echo-e "remounting The root filesystem ..."

MOUNT-T proc Proc/proc

Mount-t Sysfs Sysfs/sys

Mount-o REMOUNT,RW/

Echo-e "Creating The Files of device ..."

Mdev-s

ECHO-E "Mounting the filesystem ..."

Mount-a

ECHO-E "Starting the log daemon ..."

Syslogd

Klogd

Let this script have execute permissions:

chmod +x/mnt/sysroot/etc/init.d/rc.sysinit

4. Configuring Init and the required inittab files

Cd/mnt/sysroot

RM-RF LINUXRC

To provide a configuration file for the init process:

Vim Etc/inittab

Add the following content:

:: Sysinit:/etc/rc.d/rc.sysinit

#console:: respawn:-/bin/sh Let this line log off, or the system will go directly to SH

:: Respawn:/sbin/getty 9600 tty1 user Login 1th terminal

:: Respawn:/sbin/getty 9600 tty2 user Login 2nd terminal

:: Respawn:/sbin/getty 9600 tty3 User Login 3rd Terminal

:: Ctrlaltdel:/sbin/reboot

:: Shutdown:/bin/umount-a-R

5. Create a user login account for the target host, and copy root and Willow two accounts from the host.

Grep-e "^ (root|willow) \>"/etc/passwd >/mnt/sysroot/etc/

Grep-e "^ (root|willow) \>"/etc/group >/mnt/sysroot/etc/

Grep-e "^ (root|willow) \>"/etc/shadow >/mnt/sysroot/etc/

6. Prepare a File system table configuration file for the system/etc/fstab

Vim Etc/fstab

Add the following content:

Sysfs/sys Sysfs Defaults 0 0

PROC/PROC proc Defaults 0 0

/dev/hda1/boot ext3 defaults 0 0

/DEV/HDA2/EXT3 Defaults 1 1

7. Customized banner information for micro-systems

Cp/etc/issue/mnt/sysroot/etc/can change the inside display information if necessary

8. Provide host name for micro-system

8.1.vim/mnt/sysroot/etc/hostname

Add the following content:

Hostname=tiny.willow.com

8.2. Edit the system initialization script Rc.sysinit to set the host name during boot

Vim/mnt/sysroot/etc/rc.d/rc.sysinit

echo "Setting the hostname ..."

[-f/etc/hostname] &&. /etc/hostname

[-Z $HOSTNAME-o $HOSTNAME = = ' (none) '] && hostname=localhost

Hostname $HOSTNAME

9. Because the Rc.sysinit file generates a large number of logs, the log is sent to the/var/log/messages file;

Vim etc/syslog.conf

Add the following line:

*.info/var/log/messages

If you need to monitor the log, tail-f/var/log/messages

Okay, so this is a simple, memory-based mini Linux system that has been built ,

The following will host the machine, and then create a new virtual machine to mount the newly-customized IDE hard drive, boot test effect

Note: Tty1 terminal test input root user password can not log in, do not know what reason, hope the great God advice!

But alt+f2,alt+f3 switch to the second or third terminal, log in normal, the effect is as follows:


650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/7F/B4/wKioL1cpu_XCyIr_AACUqZ92PXQ818.jpg "title=" B22.jpg "alt=" Wkiol1cpu_xcyir_aacuqz92pxq818.jpg "/>










This article is from the "Xavier Willow" blog, please be sure to keep this source http://willow.blog.51cto.com/6574604/1770078

Manually customize a BusyBox-based micro 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.