Babylinux production process detailed (transfer)

xiaoxiao2021-03-06  42

First, what is Babylinux

Babylinux is not a complete release. He uses the original set of kernel of the Linux system and compile tools, using the powerful features built by busybox, a small Linux system on a floppy disk. He has the basic characteristics of a Linux system, supporting more than 100 orders for Linux systems, supporting multiple file systems, supporting networks, etc., you can use him as a Linux boot disk and repair disk, you also You can make a static router software, of course, you can also show him a Linux toy, showing off Linux to your friends, how small it is. I called him Babylinux because he is very small, small is very cute, Like a small Baby that has just been born.

Second, why do you want to make such a Linux

Let me talk about my thoughts. When I first touched Linux, I saw the book saying that Linux usually only needs a space of about 60m, but I found that the RedHat 6.0 installed on my hard drive is really good. Hundred M space. Why is my Linux so big? Later I found that so many things installed on my machine is that I usually use, 30% is very used, and another 40% is basically not. So, I have started complaining with most beginners. Why can't Linux are thin? So, I sprout myself to cut the system. Unfortunately I haven't heard it. After LFS and Debain. After I have accumulated enough Linux knowledge, I started to make such a small system.

What is the biggest meaning of making such a small system is that you can learn about the LINUX startup process by making a system, learn RamDisk's use, let you learn more Linux knowledge in a short time. Of course, you will get a lot of fun. This project is just a Linux system with basic features. If you want to be a full-feature Linux, please read the Linux from Scratch (LFS) document.

Third, what person is suitable for reading this document

If you are a Linux fan, and I want to know the basic structure of Linux's startup process and the system, and it is a person who likes to work to study the gadgets, then this document can meet your needs. If you just use Linux Some ordinary daily work, instead of your Linux work, then this document may not be suitable for you. In addition, if you are Linux enthusiasts, but is still a new Newbi just started, I suggest you put Linux command first. Learn well. But I think I will write this document as much as possible. If you have enough perseverance, maybe a newbi can also make a babylinux. Or, you encounter a very unexpected thing, such as you The wife came to a holiday, and your weekend will bubble, then read this document and do a Linux small toys to send your time.

Fourth, the knowledge you should have

Before doing Babylinux, you should already apply Linux's most commonly used commands. And at least once successfully compile and install the system's core experience, you will install the software by compiling the source code. If you have these conditions, then do such a The small system will be smooth. If you haven't mastered these knowledge, you may have some difficulties. But as long as you have perseverance, you can succeed. You don't need to have a programming knowledge, because my goal is: let's have a medium or more Linux Horizontal enthusiasts can easily complete this project through reading documents. There is also a very famous Linux called LoAP on a floppy disk (Linux ON A).

FLOPPY) But he is a multi-prior person to prepare a lot of programs, and there is no documentation on his production process.

V. Introduction to the Linux system boot process

First, the motherboard's BIOS will read the main boot record (MBR) of the hard disk. The MBR is stored in a small program. His function is to read the operating system core file from the hard disk and run, because this applet is too small. Therefore, usually this applet does not have the ability to direct the system kernel. He first guides another slightly larger applet, and then guides the system kernel by this big small program. Such a small program in Linux system LILO and GRUB. In this project, I decided to use LILO to do system boot programs. The process of launching the Linux system on the floppy disk is similar to the process of starting on the hard disk.

After the Linux system kernel is booted to load the kernel and run, the Linux core will detect various hardware in the system. And do a good job in the initialization of various hardware, so that they can work properly after the system is officially running. The last core did One job is running

The init program under SBIN, INIT is the abbreviation of the English word Initialization (initialization), the initial work is to read the instructions described in the / etc / inittab file, and make the initiation setting for the system's various hardware and software environments. final Waiting for the user to enter the username login system. All work is so simple, although there is a lot of content when Linux started, it looks very high, but it is the expansion of this process. I understand this truth, you can write some The script allows him to run the task at a specific time of the system started. In fact, the system kernel does not care about / sit is really init, as long as it is placed in / sbin's name to be the executable of init. You can do the following experiment: Write a very simple C program:

Main ()

{

Printf ("Hello, World!");

}

After saving, save him in INIT.C and compile with GCC.

#gcc --static -o init init.c

The --static parameter tells GCC to connect this program static, so this program can run without relying on any library. Copy the compiled init program to / sbin, back up the original one. Restart the system's last system The result is: Hello, World!

Then stop there. Before doing this experiment, you know how you know how to restore the system to the original state, there is a simple method, give him the init = parameter before the kernel starts, such as your original init by you. INIT.BAK can start the system with the original init program as long as you add init = / sbin / init.bak when starting.

After doing the above experiment, it understands the relationship between the kernel and the init program. In addition, the init program is not necessarily a binary executable, he can be a Bash script, a join point to another program, his location is also Do not have to be in / s, as long as you start the kernel, add the init parameter to the kernel, such as, add the init = / bin / bash parameter at the beginning, the kernel is directly running BASH directly in the last step. The prompt can enter the command without the login system. It features a single user mode startup system. / Sbin / init program is only the first program that is run by the kernel.

Six, compile a Linux system kernel

1. Planning and preparation before compiling

Before compiling the kernel, please determine your needs first, listen to a detailed form. Do you need to make the kernel to support what hardware, support how many partition types and file systems, which network cards are supported, etc. Wait. Please don't be too greedy as possible, but you should not be too greedy, because all the space you can use is only 1440K, if you compile a kernel greater than 1440K or close this number, your project cannot be completed. You have no space to put the Ramdisk image file unless you have the original floppy disk, do a small Linux system for two floppy disks. For the sound card driver, I advise you to give up, because a sound card driver Maybe only make your kernel more than ten K, but you have a sound card driver to have a player, otherwise the sound card driver is meaningless, but the size of a player is not a floppy disk can be installed. Under the Babylinux kernel I have made, there is more than 900 K, of which some of the file system stands most, because my goal is to make him a system repair disk. So I compiled 7 file systems in the kernel. Support, each reduction of a file system can reduce the kernel size of several tens of or even 200 K. The more complicated, the more secure file system, the larger the module, such as the FAT module under Linux, only 32K, vfat only 17K, but the module of EXT3 has 86K, JFS reaches 216K, the Reiserfs module is 224K, you can imagine, compile a kernel that supports 7 file systems, the file system part accounts for more than 600K room, so if a certain A file system is not available at all, then do not compile into the kernel, so at least 100 K room. For other drivers, such as NIC, usually only 8,9K, the biggest is more than 10 K Therefore, you can compile the commonly used NIC chips. In addition, if you want your babylinux to support the U disk, then the SCSI's drive module is not small, he usually approaches 150K, because the U disk is being used as a SCSI The device is driven. In addition, you also need to let your kernel support plug and play, these are unmoid space overhead, my suggestion is that you give up one or two file systems you don't have to use. In short, you finally compiled The kernel size is best not to exceed 900K, otherwise you can only compile very little commands in BusyBox.

In my compiled busybox, I compile to more than 120 commands, basically include the commands supported by Busybox into it. Plus the file system directory necessary for the small system, / dev file under / DEV, and / etc Required profile, the size of the RAMDisk compressed is more than 440 K, plus the kernel of 900K is just a 1440K floppy disk, please pay attention, you should leave at least 50K space, because we have to be in floppy Create an EXT2 file system, and the file system's life needs to occupy a 25K disk space. In addition, the size of the boot file boot.b is 5.7K, and the MAP file generated automatically after LILO is installed, more than 10 K The space, the specific size of the MAP file is determined by the actual size installed in the kernel, usually does not exceed 30K. In summary, please follow the formula below:

Nuclear size file system compressed impression 50K <= 1440K

In addition, it needs to be explained: The size of the file system module in the above listed listed is to look at the Redhat 9 I am using.

The module file under lib / modules is obtained, the actual compiled kernel size will be small, because we use make bzimage

The kernel generated under the internal nuclear source code directory tree is compressed.

If you don't know much about the above content, I will do a detailed description in the following.

2, must compile the contents of the kernel

First of all, this small system we make is based on a floppy disk. Therefore, your kernel must support the floppy disk. In addition, support for IDE hard drives and CDROM is also indispensable, otherwise the Babylinux that has been made does not have practical value, because he can't Accessing the content on the hard disk and the disc can do smaller, but manufacturing a completely useless thing is a waste time. Other FrameBuffer, etc. If you need to support high resolution in the character interface, Seeing more screen content, then you must support the FrameBuffer to compile into the kernel, and 8x8 fonts used under high resolution also need to be compiled. Otherwise, even if you pass the VGA = parameter, the kernel will be available because there is no available. The small font is automatically jumped into low-resolution mode. This is the thing that I can't think about it in a few days. Later, I learned that it was the style of the font. Here, I will take care of what I need to pay attention to. When the next section is compiled, I will continue to explain some of the details.

3, about the version of the kernel

I am a Babylinux small system built under Redhat 9 Linux system. Used is the 2.4.20 version of the 2.4.20 version of the Redhat 9.

Why don't I have the latest 2.6 kernel?

At first, I also tried to use the latest kernel, but I found out that I used the latest 2.6.9 kernel, I compiled an all-no (all content selected N, do not support any hardware, only one The most basic kernel) minimizes the kernel to 460K, if I add several file systems and the necessary drivers on this basis, then the size of the kernel cannot be installed 1440K

The floppy disk, and I use a 2.4.20 kernel to build a minimized kernel only need 217K. If you optimize the GCC parameter, he can also be some. So I will immediately save more than 200 K, in Usually, more than 200 K is insignificant, but in Babylinux, this number is 1/7 of the whole space, which is equivalent to the size of a Reiserfs file system module. Of course, I also tried 2.2 and older kernels, but they lack What I need, so I finally trade out the core of 2.4. If you use the 2.6 kernel's FC system, then it is best to download a 2.4 version of the kernel, www.kernel.org has every period of each period. The kernel can be downloaded.

4, the kernel configuration

If you are very familiar with the configuration and compilation of the Linux kernel, please skip this paragraph and look directly at Busybox compilation.

Log in to the system as root

Enter / usr / src / linux directory

[root @ gucuiwen root] # CD / usr / src / linux

If you download a 2.4 version of the kernel, in order to avoid trouble, please copy him under / usr / src, then pick up, and then make a link to his name Linux. Although this is not required, My past experience, if I put the Linux source code in other directories to unlock and compile, there will be some inexplicable small problems.

#CP Linux-2.4.20.bz2 / usr / src /

#CD / USR / SRC

#TAR XFVJ Linux-2.4.20.bz2

If it is Tar.gz format, you can unlock it. #TAR XFVZ Linux-2.4.20.tar.gz

For convenience, make a connection to the directory Linux-2.4.20:

#LN -s Linux-2.4.20 Linux

Enter Linux Source Catalog:

#CD Linux

Clean up source tree:

#make mrproperty

Run the configuration program:

#make xconfig

Code Maturity Level Options

First select N, when we configure regular things, add this option when adding FrameBuffer to support, because in 2.4.20, FrameBuffer support is still an experimental code. If you don't choose to be Y, FrameBuffer will not be configured.

Loadable Module Support

Select N, in order to simplify the production of the system, I don't choose to load the kernel module in this item.

Processor Type and Features

Select the CPU type you need in Processor Family. If you want old to 386, you can run BabayLinux if you want old to 386, please select 386CPU, otherwise, please select it according to your own actual situation.

Other options are selected n. These are unneed in Babylinux.

General setup

NetWorking Support Select Y

PCI Support Select Y Unless you don't have to use a PCI device, it's all needed, because most of the NIC is PCI.

System V IPC Select Y

SYSTRL Support Select Y

Keernel Support for Elf Select Y

The rest can choose n, if there is a special need, such as the network card is ISA, then select the corresponding content. But can't be greedy, always keep in mind, the space we can use is only 1440K, the size of the kernel can not exceed 900K Any unnecessary things should be removed from the kernel.

Memory Technology DEVICES (MTD)

Parallel Port Support

Plug and Play Configuration

All content in the above three big items choose n

Block Devices

Normal Floppy Disk Support

Loopback Device Support

Ram Disk Support

Initial Ram Disk (Initrd) Support

Per Partition Statics In / Proc / Partitions

Several choices Y, the rest of the rest of the N.

The option here is more important, I want to focus on it. For the support of the floppy disk, it is not necessary to say, it is necessary.

Loopback Device is a loop device, we usually use commands

#mount -o loop somecd.iso / mnt / cdrom

Holding the disc image file, or other file system image files use the loopback module in the kernel. If you do not compile this module, you will not be able to mount the disc image and file system images with the above command.

Individual thinks this feature is very important, so compiled into it.

Ram Disk Support is a memory disk (more appropriately is a virtual disk, that is, all of the memory is used as a disk). This is the core content of the Babylinux project, because a floppy disk is limited, Babylinux root file system is used Gzip compression is highly compressed. When running, copy the decompressed file to a RAM Disk, so when running, all the operations you on the root file system are actually done on memory. But in the form The same is to run on a real disk. Only all content placed on the RAM DISK will disappear after the system is turned off.

Not only when running Babylinux, we also use RamDisk when making compressed root file systems. Learning RamDisk is one of the important purposes of Babylinux. In Linux, another virtual disk is also supported. Cased SHM,

(Shared Memory), this virtual disk mechanism is more advanced than RAMDisk, the size of RAMDisk is fixed, and the default Ram Disk size is determined by compiling the core. The default is 4096K (4M), or it can be added to RAMDISK_SIZE = before the kernel loading The parameter determines his size, but once the system starts, the size of the RAMDisk cannot be changed, while the size of the SHM changes. By default, it is half the physical memory. When the system needs more memory, he will automatically Reduce. When the system memory is surplus, he automatically increases, so it can fully flexibly use memory space, SHM is usually used as a system's disk cache, and the temporary file in the system run. Reedaht Linux is available by default. SHM support, you can use Mount and DF to look at his flush points and size, as follows: [root @ gucuiwen linux] # mount

/ DEV / HDA1 ON / TYPE EXT3 (RW)

None ON / PROC TYPE PROC (RW)

USBDEVFS ON / PROC / Bus / USB Type USBDEVFS (RW)

None ON / DEV / PTS TYPE DEVPTS (RW, GID = 5, MODE = 620)

/ DEV / HDA6 ON / Home Type EXT3 (RW)

/ dev / hda5 on / oracle Type EXT3 (RW)

None ON / DEV / SHM TYPE TMPFS (RW)

/ dev / hda7 on / var type ext3 (rw)

[root @ gucuiwen linux] # DF -H

File system capacity has been used with available% mount points

/ DEV / HDA1 2.9G 2.7G 26M 100% /

/ DEV / HDA6 3.8G 1.8G 1.8G 50% / Home

/ DEV / HDA5 5.7G 677M 4.8G 13% / Oracle

None 125M 0 125M 0% / dev / shm

/ DEV / HDA7 711M 91M 584M 14% / var

Although SHM has so many advantages, I still chose RamDisk because ramdisk can easily load it when the system is started, but SHM is not so easy. Let's take a look at the RAMDISK image on the kernel. .

Initial Ram Disk (Initrd) Support

That is, the RamDisk support is initialized. This option allows the kernel capability to load ramdisk in the kernel loading phase, and run the content, otherwise we can only use ramdisk during the system run, we usually compile a new kernel, if you The root file system uses EXT3, and you didn't compile EXT3 into the kernel, but only as a module, then you need to use the mkinitrd command to make an init (Initialization Ramdisk), this Ramdisk puts EXT3 module, so the kernel The EXT3 file system can be correctly identified before loading the root file system. Otherwise, the last step of the kernel will have an error in Kernel Panic Cant Not Find Init ....

In the Babylinux project, this option is required, the role here is to load the decompressed root file system image into ramdisk.

Per Partition Statics In / Proc / Partitions

This option is not required, but I found that if I don't compile this function into the kernel, then when I am playing the file system, there will be some small problems when I am playing the file system. For example, I can't help the file system with a short-written command. I Uncertain, it is not the relationship between this option, but compiling this option into the kernel and only increases a little kernel space, so I compile him in order to avoid trouble.

Multi-Device Support (RAID AND LVM)

Cryptography Support (CryptoApi)

All of these two big items choose n, because in the PC, and less involve these two items, if you really have a RAID device or LVM, then you will find it.

Networking options

In this big item, you only need to compile the following items into the kernel:

Packet Socket: Mmapped IO

TCP / IP Networking For IP: Advanced Router, if you want to focus on making static routing software, then this compile, and for NetWork Packet Filtering (Replace Ipchains), there is no need to compile, Because Busybox does not provide iptables tools to set pack filtrans firewalls. Similarly, UNIX Domain sockets does not have to choose, only this will be selected if you run x.

Telephony Support Select N

ATA / IDE / MFM / RLL Support

Select Y, then the 'IDE, ATA and AtaPi Block Devices' is activated

Please select Y, the rest can be N.

Enhanced IDE / MFM / RLL Disk / CDROM / TAPE / FLOPPY Support

INCLUDE IDE / ATA-2 Disk Support

Auto-Geometry Resizing Support

Includort IDE / ATA CDROM Support

If your kernel is going to run on a very old Pentium or 486, compile CMD640 ChipFix / Support, because the motherboard's CMD640 IDE control chip has many inexplicable bugs, which will repair this compilation. Bug.

The following big items:

SCSI Support

Fusion MPT Device Support

IEEE 1394 (FireWire) Support

I2o Device Support

All Select N, here there may be a good thing you want, such as 1394 interface driver, but in Babylinux is not big, and our space is only 1440K.

A big item below:

Network Device Support

Choose Y, you can support the NIC, the rest of the options N. Then the Ethernet (10 or 100 mbit) button selects the network card driver you need, you can compile the most common Reltek8139, NE2000, 3Com and other network cards into the kernel Although the driver of the network card is usually very small, don't be too greedy, choose 2 ~ 3, it is enough, otherwise your kernel will take more dozens of K. In the Babylinux kernel I have compiled, I put Via. The -Rhine network card is compiled, because I created the Babylinux machine with only one piece of the chip's network card.

If you find that the network card you need is gray, you can't, then make sure that the option in his last level is already point, such as the NE2000 network card, you must first select ELSA, VLB, PCI and On Board Controllers. It is still not possible, then make sure that the PCI's support option has been selected, (in GeneAl Setup). Without PCI support, PCI's network card will not be selected.

Maybe you are a rich man, use Gigabit network card on your own PC, then choose in the Gigabit NIC.

Next, several big items:

Amateur Radio Support

Irda (Infrared) Support

ISDN SUBSYSTEM

Old CD-ROM Drivers (Not SCSI, Not IDE)

Input Core Support

All Select N.

The next Charcter Devices is an important one, and he is as important as BloAck Devices, I will focus on.

In addition to the Virtual Terminal and Support for Console on Terminal, other all-in-election N.

Virtual Terminal is a virtual terminal, which is a general Linux essential option. Otherwise, you will not see anything on the screen. It is also responsible for keyboard input information. Only in some embedded Linux applications will not This option is because these Linux usually do not operate.

Support for Console on Terminal

In the console on the virtual terminal. He supports the output of various information on the terminal, which is also necessary.

The next few big items:

MultiMedia Devices

Crypto Hardware Support

All Select N.

Then the part of the file, the file sytems, but the weight. This part doesn't have to be too arrogant, what you need to support what you need to support.

But there are three of you must choose:

/ Proc File System Support lacks him, many commands and software can't run.

The basic file system of SecondEded Fs Support Babylinux.

ISO 9660 CDROM FILESYTEM Support Unless you don't want to use a disc.

In addition, such as Quota Support, Reiserfs Debug Mode (Enable Reiserfs Debug Mode)

You don't have to compile it. These things are not significant, do not increase the kernel size. Please keep in mind that the compiled kernel size should not exceed 900K.

Tip: Is it very tired? I wrote more tired, don't worry, the kernel configuration section is better.

Last Console Drivers

This is a kernel module that supports Linux high resolution display in character mode. The front selection Y,

The frame-buffer support button is a gray, don't worry, go back to the first big option:

Code Maturity Level Options Select Y, you can activate this button.

The following options need to choose Y:

Support for FrameBuffer Devices

VESA VGA Graphics Console

You can also choose other graphics card drivers, such as NVIDIA, but VESA and VGA are best practical, as long as it is not a black and white video card decorate (I only have heard, I have never seen), it is compatible with VESA and VGA. Therefore, in order to make good Babylinux, please select this driver.

Support Only 8 Pixels Wide Fonts

This must be selected, whether you pass the VGA = 788 parameters to the kernel, let Linux displays high resolution under the character interface, the system will return to the low resolution mode because of the appropriate small fonts.

Ok! All the kernels are all completed here, and the remaining big items are all selected.

After saving, the configuration program will automatically generate a hidden profile .config

Here is the content I configured .config file. If you are lazy you go to configure it, you can use this .config to copy it to your source code. (I have already dropped # 开 的 注行)

Config_x86 = y

CONFIG_UID16 = Y

Config_experimental = y

CONFIG_M586 = Y Y

Config_x86_wp_works_ok = Y

CONFIG_X86_INVLPG = Y

Config_x86_cmpxchg = y

CONFIG_X86_XADD = Y

Config_x86_bswap = y

CONFIG_X86_POPAD_OK = Y

Config_rwsem_xchgadd_algorithm = y

CONFIG_X86_L1_CACHE_SHIFT = 5

CONFIG_X86_USE_STRING_486 = Y

Config_x86_alignment_16 = y

CONFIG_X86_PPRO_FENCE = Y

Config_nohighmem = y

CONFIG_NET = Y

Config_pci = y

CONFIG_PCI_GODIRECT = Y

Config_pci_direct = y

Config_sysvipc = y

Config_sysctl = y

Config_kcore_elf = Y

Config_binfmt_elf = y

Config_blk_dev_fd = Y

Config_blk_dev_loop = Y

CONFIG_BLK_DEV_RAM = Y

Config_blk_dev_ram_size = 4096

Config_blk_dev_initrd = y

Config_packet = y

Config_inet = yconfig_ip_multicast = y

CONFIG_IDE = Y

Config_blk_dev_ide = y

Config_blk_dev_idedisk = y

Config_idedisk_multi_mode = y

Config_blk_dev_idecd = Y

Config_blk_dev_ide_modes = Y

Config_netDevices = Y Y

Config_net_ethernet = Y

Config_input_mousedev_screen_x = 1024

CONFIG_INPUT_MOUSEDEV_SCREEN_Y = 768

CONFIG_VT = Y

Config_vt_console = Y

Config_reiserfs_fs = y

Config_ext3_fs = y

Config_jbd = Y

Config_fat_fs = y

CONFIG_VFAT_FS = Y

Config_ramfs = y

Config_iso9660_fs = y

CONFIG_JFS_FS = Y

CONFIG_NTFS_FS = Y

Config_proc_fs = y

Config_ext2_fs = y

Config_msdos_partition = y

CONFIG_NLS = Y

CONFIG_NLS_DEFAULT = "ISO8859-1"

Config_vga_console = y

Config_video_select = y

Config_video_ignore_bad_mode = y

CONFIG_FB = Y

Config_dummy_console = y

CONFIG_FB_VESA = Y

Config_video_select = y

Config_fbcon_cfb8 = y

CONFIG_FBCON_CFB16 = Y

CONFIG_FBCON_CFB24 = Y

CONFIG_FBCON_CFB32 = Y

CONFIG_FBCON_FONTWIDTH8_ONLY = Y

Config_font_8x8 = y

Config_font_8x16 = y

5, compile the kernel

#make dep

#make bzimage

Below is the last compilation result:

Boot sector 512 bytes.

Setup is 4733 bytes.

System IS 845 KB

Make [1]: Leaving Directory `/usr/src/linux-2.4.20-8/Arch/i386/boot '

I used the above configuration to get a 845K kernel.

Compiled good kernels in /usr/src/linux-2.4.20-8/Arch/i386/boot. Copy him in a safe place.

Create a directory for the Babylinux material

#mkdir / babylinux

Create a directory for making Babylinux root file systems

#mkdir / babylinux / rootfs

Backup kernel

#CP /usR/src/linux-2.4.20-8/Arch/i386/boot/bzimage / babylinux /

Seven, compile busybox

1, BUSYBOX

BusyBox is a software integrated with more than 100 common Linux commands and tools. He even integrates an HTTP server and a Telnet server, and all this features are only about 1M of the zone. We usually use those Linux The command is like a scivable electronic component, and busybox is like an integrated circuit, integrating common tools and commands in an executable file, the function is basically unchanged, and the size is small, in the embedded type In Linux applications, busybox has a wide range of applications, in addition, most Linux distributions have busybox's figure, when installing Linux, Ctrl Alt F2 can get a console, and this console All commands point to busybox links. BusyBox's small body features, bringing and convenient to linux that makes a floppy disk.

2, busybox usage

Can use busybox

#busybox ls

His function is quite running ls command

The most common usage is to establish a link to BusyBox, different link names complete different features.

#LN-S Busybox LS

#LN-S Busybox RM

#LN -s busybox mkdir

Then run these three links separately:

#. / ls

#. / rm

#. / mkdir

The functionality of the LS RM and MKDIR commands can be completed separately. Although they all point to the same executable BUSYBOX

But as long as the link name is different, the completed function is different, and BusyBox is such a magical.

Many Linux websites offer the source code download of BusyBox. The current version is a formal version of BusyBox 1.0.

3, configure busybox

Busybox's configuration programs and Linux kernel menus are simply exactly the same. Friends who are familiar with Make MenuConfig are easy to get started.

#cp busybox-1.00.tar.gz / babylinux

#CD / BABYLINUX

#TAR XVFZ busybox-1.00.tar.gz

#CD busybox-1.00

#make menuconfig

Below is a feature option that needs to be compiled into BusyBox, and other can be selected as needed, but it is also not too greedy.

General Configuration should choose the option

Show Verbose Applet Usage Messages

Runtime Suid / SgID Configuration Via /etc/busybox.conf

Build Options

Build BusyBox as a static binary (no shared libs)

This option is necessary to select, so you can compile Busybox into a static link executable, run independently of other function libraries. Otherwise, other library files must be running, and a single Linux kernel cannot make him normal work.

Installation Options

Don't use / usr

This option must also be selected. Otherwise, Make Install will be installed in the original system / usr, which will overwrite the original command. After selecting this option, make install will generate a call _Install in the busybox directory. Directory, there is busybox and link to his link.

Other options are some Linux basic command options, which commands you need to compile, usually use the default.

After configuring, exit and save it.

4, compile and install busybox

#make

#make install

After compiling, generate subdirectory _INSTALL in the busybox directory, inside:

DRWXR-XR-x 2 root root 4096 November 24 15:28 bin

LRWXRWXRWX 1 root root 11 November 24 15:28 Linuxrc -> Bin / BusyBox

DRWXR-XR-X 2 root root 4096 November 24 15:28 sbin

The executable BUSYBOX is in the bin directory, and the other points to his symbolic link.

My compiled busybox executable is 935K, plus symbolic links, the whole _install directory is 952K. Plus 845K kernel is not more than 1440K? Don't worry, we will significantly compress the entire root file system 8. Produce root file system

1, basic directory structure

#CD / BABYLINUX / ROOTFS

#mkdir etc usr var TMP Proc Home Root Dev

Where ETC, Proc and DEV must be built, BIN and SBIN are not built, because it is already in Busybox.

Other can be built in symbolic.

Copy busybox

#cp -r /babylinux/busybox-1.00/_install/* / babylinux / rootfs /

2. Establish a device file name

#CD / BABYLINUX / ROOTFS / DEV

You can use MKNOD to create, or copy it directly from the original system / dev directory.

Hand-established method:

#ls -l / dev / console

CRW ------- 1 root root 5, 1 November 30 09:02 / dev / console

This checks that the main device number of the console device is 5, the auxiliary standby number is 1, which is a character device tagged C.

Thus, we can build a same device file with mknod:

#mknod Console C 5 1

However, the manual method has been too much trouble, usually copy the required device files directly from / dev.

These device files are special files, and they must be added to the -R parameter when copying.

#cp -r / dev / console ./

#cp -r / dev / null ./

#cp -r / dev / zero ./

...

Here are the names I think needed:

CDROM FD0 HDA14 HDA4 HDB11 HDB19 HDC HDC16 HDC6 HDD13 HDD3 LOOP2 RAM2

Console FD0H1440 HDA15 HDA5 HDB12 HDB2 HDC1 HDC17 HDC7 HDD14 HDD4 LOOP3 TTY0

FB HDA HDA16 HDA6 HDB13 HDB3 HDC10 HDC18 HDC8 HDD15 HDD5 LOOP4 TTY1

FB0 HDA1 HDA17 HDA7 HDB14 HDB4 HDC11 HDC19 HDD HDD16 HDD6 LOOP5 TTY2

FB1 HDA10 HDA18 HDA8 HDB15 HDB5 HDC12 HDC2 HDD1 HDD17 HDD7 NULL TTY3

FB2 HDA11 HDA19 HDB HDB16 HDB6 HDC13 HDC3 HDD10 HDD18 HDD8 RAM TTY4

FB3 HDA12 HDA2 HDB1 HDB17 HDB7 HDC14 HDC4 HDD11 HDD19 Initctl Ram0 TTY5

FB4 HDA13 HDA3 HDB10 HDB18 HDB8 HDC15 HDC5 HDD12 HDD2 LOOP1 RAM1 ZERO

Among them, FD0, HDA, RAM, RAM1, TTY1, NULL, ZERO, LOOP1, FB0, FB, etc. are essential.

Other HDA, HDA1, HDB, etc. can be decided according to actual needs. But the choice in the table is relatively reasonable, which can meet most of the needs, there is no equipment waste space. Note, don't put / dev The equipment is copied, which will generate approximately 420K / dev directory, which is too big for Babylinux.

3. Establish a profile in the ETC directory

Busybox.conf group inittab motord passwd resolv.conf shadow-

Fstab Init.d Issue MTAB Profile Shadow

Where INIT.D is a directory that is copied from the busybox-1.00 source code directory.

#cp -r /babylinux/busybox-1.00/examples/bootflopyp/etc/init.d / babylinux / rootfs / etc /

BusyBox.conf is an empty file.

The contents of other files are as follows:

FSTAB

/ DEV / FD0 / EXT2 Defaults 0 0

None / Proc Proc Defaults 0 0

/ dev / cdrom / mnt / cdrom udf, ISO9660 NOAUTO, OWNER, KUDZU, RO 0 0

/ dev / fd0 / mnt / floppy auto noauto, Owner, Kudzu 0 0

group

Root: x: 0: root

inittab

:: Sysinit: /etc/init.d/rcs

:: askfirst: / bin / sh

TTY2 :: Respawn: / bin / getty 38400 TTY2

TTY3 :: Respawn: / bin / getty 38400 TTY3

Tty4 :: Respawn: / bin / getty 38400 TTY4

# Stuff to do when restarting the init process

:: Restart: / Bin / Init

# Stuff to do before rebooting

:: Ctrlaltdel: / Bin / Reboot

:: Shutdown: / bin / umount -a -r

:: Shutdown: / Bin / Swapoff -a

Issue

Baby Linux Release 0.1

MOTD

MTAB

Passwd

Root :: 0: 0: root: / root: / bin / ash

Profile

# / etc / profile: system-wide .profile file for the bourne shells

echo

echo

Export ps1 = "[u @ h w] $"

Echo "DONE"

Alias ​​ll = 'ls -l'

Alias ​​du = 'du -h'

Alias ​​DF = 'DF -H'

Alias ​​rm = 'rm -i'

echo

Resolv.conf

Nameserver 202.96.209.5

Nameserver 202.96.209.6

Shadow

ROOT: $ 1 $$ Adltab9SR / MSKQYLIVSJT /: 12705: 0: 99999: 7 :::

Shadow-

ROOT: $ 1 $ dwu.tenp $ b7anixogoizmwjr6ih8810: 12705: 0: 99999: 7 :::

There are many copies from the original system / etc. If you are a Linux enthusiast with medium level, then you should understand, of course, you can modify these files according to your needs. The most important of these is the syntax of the initTab file for the initTab, BusyBox built-in init, and generally different, can't copy the original system / etc initTab file. You can use the example in the busybox-1.00 directory. Document copy comes to modify. Please see the busybox document. Busybox's initTab. But there is a very strange bug in the Babylinux process. All / sbin Busybox links are made into a compressed root file system After the decompression, you can't run normally. You can't find this command. Only when I do these links under / bin, you can run. The specific reason is not too clear, so you need to do the following work:

#CD / BABYLINUX / ROOTFS / SBIN

#LS

Chroot Getty ifconfig Losetup Pivot_Root Reboot Swapoff Sysctl

FDISK HALT INIT MKSWAP PowerOff Route Swapon Telnetd

View the above links under Sbin

Go to BIN

#CD / BABYLINUX / ROOTFS / BIN

Re-do these links:

#ln -s busybox chroot

#LN -s busybox getty

#LN -S BusyBox ifconfig ...

Then remove the link under the sbin to save space

#RM-RF / Babylinux / rootfs / sbin / *

Change all the SBIN in the original initTab to bin

Under the file under InIT.D:

RCS

Make sure this file is executable, otherwise it is changed to executable:

#CHMOD U X RCS

RCS content:

#! / bin / sh

Mount -o Remount, RW /

/ bin / mount -a

> / etc / mtab

echo

echo

echo

echo

echo -en "Welcom to 33 [0; 32Mbabylinux33 [0; 39M"

echo -en "33 [0; 36M"

echo

echo -en " "

echo -en " This is a tiny linux system based on a floppy.It contains"

echo -en " more than 100 basic Linux commands and tools.The kernel of"

echo -en " this tiny system support all kinds of normal filesystems."

Echo -en " Linux EXT2, EXT3, JFS, Reiserfs and Windows Fat, Vfat, NTFS [Readonly]

echo -en " is supported! So it is a powerful small system you can use it"

echo -en " as a linux and windows rescue disk.Beside this, the kernel also"

echo -en " contains the drivers of Reltek8139, NE2000, via-rhine ethernet"

echo -en " adpater. you can configure the IPaddress and netmask with tools"

echo -en " 'ifconfig' and config the default Gateway with command 'Route'."

echo -en " Is there anything else? Haha, this is a telnet server build-in"

echo -en " you can type 'telnetd' to startd it and thus your friends can"

Echo -en " logon to your system to help you solve the problem." echo -en " 33 [0; 32mall the Great Features Are Powered by Busybox 1.033 [0; 36M"

Echo -en " this is a free system tool development by gucuiwen."

Echo -en " Run Your Own Risk of use it! if you have anyproblem please"

echo -en " mailto: win2linux@163.com enjoy !!"

Echo -en " "

echo -en "33 [0; 39m"

Hostname Babylinux

You can make your own modifications.

The above is all the contents of the Babylinux root file system, and his total size should be around 1m.

[root @ gucuiwen baby] # du -hs

1.1m.

Nine, make a ramdisk image file

Babylinux root file system All things are placed under / babylinux / rootfs, we will use ramdisk to make these contents into the RAMDisk image file and compress him.

The following is mainly RamDisk's usage, after reading the following, you should learn Ramdisk's use.

[root @ gucuiwen babylinux] # DD if = / dev / zero of = / dev / ram1

DD: Writing '/ dev / ram1': There is no space on the device

Read 8193 0 blocks

Output 8192 0 blocks

ZERO is a special device that represents all 0 characters. The above command means that the first RAMDisk of the system is filled with all 0 data, because the default size is 4m, so when it is over 8192 After block (512 bytes per piece), there is no space on the 'device'. This is normal, / dev / ram1 has been filled.

If the size of the block is specified:

[root @ Gucuiwen Babylinux] # DD if = / dev / zero of = / dev / ram1 bs = 1M count = 4

Read 4 0 blocks

Output 4 0 blocks

There is no error message, here demonstrates the general usage of DD, and then uses the DD command frequently.

There are many RamDisk devices, RAM1, RAM2, RAM3 ....

Generally, you can use the first one.

After filling, RAM1 can be spaced, you can create a file system on this space:

[root @ gucuiwen babylinux] # mkfs.ext2 -m0 / dev / ram1

MKE2FS 1.32 (09-NOV-2002)

FileSystem label =

OS Type: Linux

Block size = 1024 (log = 0)

Fragment size = 1024 (log = 0) 1024 inodes, 4096 blocks

0 blocks (0.00%) reserved for the super user

First Data Block = 1

1 block group

8192 Blocks Per Group, 8192 Fragments Per Group

1024 inodes per group

Writing Inode Tables: DONE

Writing Superblocks and FileSystem Accounting Information: DONE

This FileSystem Will Be Automatically Checked Event 37 Mounts OR

180 Days, Whichever Comes First. Use tune2fs -c or --i to override.

Plock RAM1 to the file system:

Build a flush point first:

#mkdir / mnt / ram

Hanging RAM1:

#mount / dev / ram1 / mnt / ram

Copy the previous Babylinux root file system to RAM1.

#cp -r / babylinux / rootfs / * / mnt / ram

After doing the above steps, you should have the meaning of the Ramdisk device, he is with HDA1, HDB1, the same block device, and you can visit it with mount, you can put things, but all things are Memory. Shutdown will lose everything.

Copy a good Babylinux root file system to uninstall RAM1:

#umount / dev / ram1

At this time, although the content in RAM1 cannot be accessed by the flushing point of / MNT / RAM, he is cut in memory.

Use DD to take this RAM1 in an image mode:

[root @ gucuiwen babylinux] # DD if = / dev / ram1 of = / babylinux / ramdisk.img

Read 8192 0 blocks

Output 8192 0 blocks

Verify the content taken out:

[root @ Gucuiwen Babylinux] # file ramdisk.img

Ramdisk.img: Linux Rev 1.0 EXT2 FILESYSTEM DATA

He is an EXT2 file system, similar to an ISO disc image file.

Because of the times, we can use loop devices to reinite him into the file system:

[root @ Gucuiwen Babylinux] # mount -o loop ramdisk.img / mnt / ram /

For the convenience, I still hang him under / mnt / ram, so, I have to take / dev / ram1 umount before.

View / MNT / RAM, he should be the same as the / babylinux / rootfs, otherwise it is wrong:

[root @ gucuiwen babylinux] # lrs / mnt / ram

Bin Dev ETC Home Lost Found MNT Proc Root Sbin TMP USR VAR

In this way, we get a RAMDisk root file system image: ramdisk.img

Take him umount:

#umount / mnt / ram

If it is the first time you come into contact with ramdisk, you may be confused about the above content, if so, please read and understand the above content, you can understand how you do a few more tests.

Compressed ramdisk.img Impression Document:

[root @ gucuiwen babylinux] # gzip -v9 ramdisk.img

Ramdisk.Img: 87.9% - Replaced with ramdisk.img.gz

Check the size of the compressed:

[root @ Gucuiwen Babylinux] # ls -lh ramdisk.img.gz

-rw-r - r - r - 1 Root root 495k November 30 11:32 Ramdisk.img.gz I get the compressed ramdisk image file is 495K. Plus the kernel 845K, it is 1340K

Compliance with the formula:

Nuclear size file system compressed impression 50K <= 1440K

If you make kernel and ramdisk.img.gz too big, please re-produce kernel or ramdisk.img.gz, do some hits, if your kernel and ramdisk.img.gz are too small, then you can Add some content to the inside to make your babylinux function more.

Ten, the integration of kernel and busybox

Prepare a good white floppy disk

Create a file system that is slightly larger than the kernel:

For example, the kernel size is 845K, then I have created a 920K file system:

# MKFS.EXT2 -M0 / DEV / FD0 920

If space allows, you can also be more, but it is necessary to guarantee

1440K- File System Size> = Ramdisk.img.gz size.

Hang up floppy disk

#mount / dev / fd0

Copy the kernel to floppy disk:

#CP / Babylinux / BZIMAGE / MNT / FLOPPY /

Put the LILO boot file to copy to the floppy disk

#CP /BOOT / MNT / FLOPPY

Newly built a lilo.conf configuration file:

Prompt

TIMEOUT = 60

Default = linux

Boot = / dev / fd0

MAP = / mnt / floppy / map

INSTALL = / mnt / floppy / boot.b

Linear

Image = / mNT / Floppy / Bzimage

Label = Linux

Read-only

VGA = 788

root = / dev / fd0

append = "LOAD_RAMDISK = 1 ramdisk_start = 940"

VGA = 788 means that the high-resolution display of the kernel supports the character interface, you can change to VGA = ASK, which selects the resolution when starting.

The red row is the key, and load_ramdisk = 1 tells the kernel to reprint the compressed RamDisk impression file when starting.

RamDisk_start = 940 tells the kernel to find and load the compressed RamDisk impression file from the place where the floppy disk is located.

For the usage and more parameters of RamDisk, please check the Linux0 core document /usr/src/linux/documents/ramdisk.txt

Next, use the DD command to put the ramdisk.img.gz on the floppy disk.

#dd if = / babylinux / ramdisk.img.gz of = / dev / fd0 bs = 1k seek = 940

Seek = 940 here indicates where the ramdisk.img.gz is installed on the 940K of the floppy disk.

For details, please see the DD online document Man DD

Why start from 940K?

Because I just made a 920K file system. I put him behind the file system 20K.

Of course, if your space is very nervous, even these 20K is not willing to waste, then you can:

#dd if = / babylinux / ramdisk.img.gz of = / dev / fd0 bs = 1k seek = 921

Of course, don't forget to modify the lilo.conf file. RamDisk_start = 921

Next, the LILO boot process is very successful.

#LILO -C LILO.CONF

If there is still a little free space on your disk, you can copy lilo.conf to use in the future.

#CP lilo.conf / mnt / floppy

#umount / dev / fd0

The entire project has been completed, you can restart the machine and set the computer from the floppy disk. See if there is any success.

XI, installation test and content adjustment

If the disk space is not enough during the integration of the kernel and the RamDisk image, recompile the kernel and busybox can adjust the kernel and busybox according to actual needs. For example, you have to support a lot of things, but only one support 50 commands. Busybox, then you can do your own adjustments.

Twelve, BUG in Babylinux

The output of some commands will have a deviation, such as the use of disk usage with busybox, and actually different.

Thirteen, the next thing to do

Do a Linux small system based on a 64M U disk.

Plan supports the following characteristics:

a. Flock Babylinux all features

b. Support for graphical interface.

c. A lightweight window manager (Window Maker)

d. Network support,

e. At least one graphical web browser, you can go online.

f. A music player and a video player.

g. Support Chinese display and input.

h. You can modify the configuration and save the data

I also plan to do a Live CD, but there are already many Live CDs, and they do very well.

But I will do myself as a means of learning Linux. If there is time, I may write a U disk Linux and Live CD.

The tutorial. However, I don't think of the same detail as this document, my time is limited. It may probably talk about the principles and steps. Experience Linux enthusiasts should be able to do production by reading documents.

转载请注明原文地址:https://www.9cbs.com/read-73061.html

New Post(0)