The four busybox of the Linux system clipping notes

Source: Internet
Author: User

The four busybox of the Linux system clipping notes

1. What is cut?

The main purpose of this article is to give the author and readers a deeper understanding of how the Linux system works, the general content is to take Linux apart from the components to assemble, and then complete a micro Linux system. Let's do it now. Please advise me where the writing is not good.

2. Principle

As we all know, the operating system start-up process is (mainly Linux):P Ost->bios->mbr-kernel-->initrd-->sbin/init,

Post,bios is not our tube, so here we start from the MBR, Linux system boot is mainly used grub this software, Grub boot system, and then start the kernel, the kernel calls INITRD to achieve the most basic operating system,

3. Experiments (all operations are implemented on the virtual machine and the IDE is selected when the hard drive is defined)


Kernel + INITRD (busybox production, providing ext3 file system module) + ROOTFS (busybox production)

Hardware driver: INITRD

INITRD: Only need to provide kernel access to the drive required by the device where the real root file system resides

Storage devices and file system-related modules

System initialization Rc.sysinit: The driver of the initial other hardware;

Rootfs:busybox,init does not support run level

/etc/inittab: formats are different Ash,hush bash


Compile BusyBox: (: https://busybox.net/)

Ide:

/dev/hda1:ext3/boot

/DEV/HDA2:EXT3/


[Email protected] tmp]# tar -xf linux-2.6.38.5.tar.bz2
[Email protected] mtd]# cd/tmp/busybox-1.20.2/

[Email protected] include]# cp/tmp/linux-2.6.38.5/include/mtd/ubi-user.h./mtd/

[Email protected] include]# cp/tmp/linux-2.6.38.5/include/mtd/mtd-abi.h./mtd/


[[email protected] busybox-1.20.2]# make Install #

[email protected] busybox-1.20.2]# ll _install
Total 28
Drwxr-xr-x 2 root root 4096 2016-11-29 13:50 bin
lrwxrwxrwx 1 root root one 2016-11-29 13:50 linuxrc bin/busybox
Drwxr-xr-x 2 root root 4096 2016-11-29 13:51 sbin
Drwxr-xr-x 4 root root 4096 2016-11-29 13:51 usr
[Email protected] busybox-1.20.2]# du -sh _install

3.0M _install #initrd, Fsfiles

[Email protected] busybox-1.20.2]# CP _install/tmp/busybox-a

[Email protected] busybox-1.20.2]# CP _install/tmp/busybox2-a

[Email protected] busybox-1.20.2]# Cd/tmp/busybox
[email protected] busybox]# LL
Total 28
Drwxr-xr-x 2 root root 4096 2016-11-29 13:50 bin
lrwxrwxrwx 1 root root one 2016-11-29 13:58 linuxrc bin/busybox
Drwxr-xr-x 2 root root 4096 2016-11-29 13:51 sbin
Drwxr-xr-x 4 root root 4096 2016-11-29 13:51 usr
[Email protected] busybox]# RM LINUXRC
Rm:remove Symbolic link ' linuxrc '? Y

[Email protected] busybox]# mkdir proc sys etc Dev tmp mnt/sysroot LIB/MODULES-PV

[Email protected] busybox]# Modinfo ext3
FileName:/lib/modules/2.6.23.1-42.fc8/kernel/fs/ext3/Ext3.ko
...
Depends:jbd

[Email protected] busybox]# Modinfo JBD
FileName:/lib/modules/2.6.23.1-42.fc8/kernel/fs/jbd/Jbd.ko

[Email protected] busybox]# Cp/lib/modules/2.6.23.1-42.fc8/kernel/fs/ext3/ext3.ko lib/modules/

[Email protected] busybox]# Cp/lib/modules/2.6.23.1-42.fc8/kernel/fs/jbd/jbd.ko lib/modules/

[[email protected] busybox]# vim Init
#!/bin/sh
#
MOUNT-T proc Proc/proc
Mount-t Sysfs Sysfs/sys
Insmod/lib/modules/jbd.ko
Insmod/lib/modules/ext3.ko

Mount-t Ext3/dev/hda2/mnt/sysroot
EXEC switch_root/mnt/sysroot/sbin/init

[Email protected] busybox]# chmod +x Init

[[email protected] busybox]# mknod dev/console C 5 1
[[email protected] busybox]# mknod dev/null C 1 3
[[email protected] busybox]# ls
Bin Dev etc init lib mnt proc sbin sysroot usr
[Email protected] busybox]# Tree Dev
Dev
|--Console
'--nullmdev-s


[[email protected] busybox]# ls
Bin Dev etc init lib mnt proc sbin sys tmp usr
[[email protected] busybox]# find. | Cpio-h newc--quiet-o |gzip-9 >/mnt/boot/initrd.gz
[Email protected] busybox]# ls-lh/mnt/boot/initrd.gz
-rw-r--r--1 root root 937K 2016-11-29 14:33/mnt/boot/initrd.gz

[[email protected] boot]# CP /boot/vmlinuz-2.6.18-164.el5pae./vmlinuz # Copy kernel

[[email protected] boot]# ll
Total 2773
-rw-r--r--1 root root  959088 Nov 14:33 initrd.gz
drwx- -----2 root root   12288 Nov 10:42 lost+found
-rw-r--r--1 root root 1852596 Nov 14:35 vmlinuz
[[em Ail protected] Boot]# Grub-install --root-directory=/mnt/dev/hda
probing devices to guess BIOS drives. This could take a long time.
Installation finished. No Error reported.
This is the contents of the device Map/mnt/boot/grub/device.map.
Check If this is correct or not. If any of the lines is incorrect,
fix it and re-run the script ' Grub-install '.

(fd0)     /dev/fd0
(hd0)     /dev/hda
(HD1)     /dev/hdb
(HD2)     /DEV/SDA
[[email protected] boot]# LS
grub  initrd.gz  lost+found  vmlinuz

[Email protected] boot]# VI grub/grub.conf
Default=0
Timeout=3
Title Jack Linux (2.6.18)
Root (hd0,0)
Kernel/vmlinuz ro root=/dev/hda2
Initrd/initrd.gz


[Email protected] busybox-1.20.2]# CD /tmp/busybox2

[[email protected] busybox2]# ls
Bin Linuxrc sbin usr

[Email protected] busybox2]# rm-f LINUXRC

[[email protected] busybox2]# MKDIR-PV proc SYS dev tmp var/{log,lock,run} lib/modules etc/rc.d/init.d root boot mnt Medi A

[Email protected] busybox2]# vim Etc/inittab

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

Console::respawn:-/bin/sh

:: Ctrlaltdel:/sbin/reboot

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

[Email protected] busybox2]# vim Etc/fstab

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


[[email protected] busybox2]# ls bin #BusyBox already has 97 commands

AddGroup chown dmesg getopt iplink lsattr MT PS Setarch

AddUser conspy dnsdomainname grep iproute lzop mv pwd setseri

Ash CP dumpkmap gunzip iprule makemime netstat reformime sh

Base64 Cpio echo gzip iptunnel mkdir Nice rev Sleep

BusyBox cttyhack ed hostname kill Mknod Pidof RM stat

Cat Date egrep Hush linux32 mktemp ping rmdir stty

CATV dd false Iostat linux64 more ping6 rpm su

chattr delgroup fdflush IP ln mount pipe_progress run-parts Sync

CHGRP deluser fgrep ipaddr login mountpoint powertop scriptreplay tar

chmod df fsync ipcalc ls mpstat printenv sed touch


[[email protected] busybox2]# ls sbin/ #BusyBox has 61 commands

Acpid devmem Getty Ifup lsmod Mkfs.minix Poweroff Slattach sy

Adjtimex Fbsplash halt init makedevs mkfs.vfat raidautorun Start-stop-daemon tu

ARP fdisk hdparm insmod man mkswap reboot Sulogin VC

Blkid Findfs hwclock klogd mdev modinfo rmmod swapoff wa

Blockdev freeramdisk ifconfig loadkmap mkdosfs modprobe Route swapon ZC

BOOTCHARTD fsck ifdown logread mke2fs nameif runlevel switch_root

Depmod Fsck.minix ifenslave losetup mkfs.ext2 pivot_root setconsole sysctl

[[email protected] busybox2]# Mknod dev/console C 5 1
[[email protected] busybox2]# Mknod dev/null C 1 3

[email protected] busybox2]# ll dev/
Total 0
crw-r--r--1 root root 5, 1 Nov 15:42 console
crw-r--r--1 root root 1, 3 Nov 15:42 null


[Email protected] busybox2]# vim Etc/rc.d/rc.sysinit
[email protected] busybox2]# cat Etc/rc.d/rc.sysinit
#!/bin/sh
Echo-e "\twelcome to \033[31mjack XXX xxx\033[0m Linux"

Echo-e "remounting the root filesystem ... [\033[31mok033[0m] "
MOUNT-T proc Proc/proc
Mount-t Sysfs Sysfs/sys
Mount-o REMOUNT,RW/

Echo-e "Creating The files of device ... [\033[31mok033[0m] "
Mdev-s

ECHO-E "Mounting the filesystem ... [\033[31mok033[0m] "
Mount-a
Swapon-a
[Email protected] busybox2]# chmod +x etc/rc.d/rc.sysinit



---end---

Linux system crop note four BusyBox

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.