Describes steps 14 of the BabyLinux Production Process

Source: Internet
Author: User
Article Title: describes the 14th step of the BabyLinux production process. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Directory
  
1. What is BabyLinux?
2. Why is such a linux
3. Who should read this document?
4. Knowledge
V. Introduction to linux boot process
6. Compile the kernel
7. Compile busybox
8. Create a root file system
9. Create a ramdisk Image File
10. Integration of kernel and busybox
11. Installation test and content Adjustment
12. Bugs in babylinux
13. What to do next
Iv. References
  
1. What is BabyLinux?
  
BabyLinux is not a complete release version. It uses the original kernel original code and compilation tools of a complete linux System and the powerful built-in functions of busybox, A small linux system made on a floppy disk. he has the basic features of a linux system, supports more than one hundred commands most commonly used in linux systems, supports multiple file systems, and supports networks, you can use it as a linux boot and Repair Disk, or you can use it as a static router software. Of course, you can also use it as a linux toy, show your friends how small linux can be. I call him BabyLinux because he is very small and cute, just like a baby.
  
2. Why is such a linux
  
First, let me talk about my first thoughts. When I first came into contact with linux, I found that linux usually only needs about 60 MB of space to be installed, however, I found that the Redhat 6.0 on my hard disk really occupies several hundred MB of space. why is my linux so big? Later, I found that less than 30% of the things installed on my machine are commonly used by me, and 30% are rarely used by me. The other 40% is basically not used. as a result, I started to complain like most beginners. Why can't linux be simplified? As a result, I developed my own idea of cutting the system. unfortunately, at that time I had not heard of LFS and Debain. after I accumulated enough linux knowledge, I began to create such a small system.
The biggest significance of making such a small system is that you can understand the linux Startup Process through the production system and learn how to use ramdisk, so that you can learn more about linux in a short time. of course, you will have a lot of fun. this project is just a linux system with basic features. If you want to create a linux system with complete functions, read the Linux From Scratch (LFS) documentation.
  
3. Who should read this document?
  
If you are a linux enthusiast and want to understand the linux Startup Process and basic structure of the system, and are a person who likes to study gadgets, this document can meet your needs. if you only use linux for some common daily work and don't care how your linux works, this document may not be suitable for you. in addition, if you are a linux enthusiast but still a newbi, I suggest you learn the linux Command first. but I think I will try my best to write this document in detail. If you have enough perseverance, maybe a newbi can also be used as a babylinux. or, if you encounter a very unfortunate thing, such as your wife's official holiday, you will be ruined this weekend, so reading this document and making a linux toy will take your time.
  
4. Knowledge
  
Before creating a babylinux, You should have applied the most common commands in linux. at least one successful compilation and installation of the system kernel will install the software by compiling the source code. if you have these conditions, it will be very smooth to make such a small system. If you have not mastered this knowledge, you may encounter some difficulties. but as long as you have perseverance, you can also succeed. you do not need to have programming knowledge, because my goal is to make it easy for anyone with a moderate or higher level of linux to complete this project by reading the documentation. linux On A floppy disk is also known as LOAP (linux On
Floppy) but he is a professional who needs to write a lot of programs, and there is no document about his production process.
  
V. Introduction to linux boot process
  
First, the BIOS of the motherboard reads the Master Boot Record (MBR) of the hard disk. The MBR stores a small program. Its function is to read and run the core file of the operating system from the hard disk, because this small program is too small, it usually does not have the ability to directly guide the system kernel. He will first guide another small program that is a little larger, then, the larger program will guide the system kernel. in linux, such small programs include LILO and GRUB. in this project, I decided to use LILO as the system boot program. the process of starting a linux system on a floppy disk is similar to that on a hard disk.
  
After the Linux kernel is loaded into and run by the boot program, the Linux kernel detects various hardware in the system. and initialize various hardware so that they can work normally after the system is officially run. then, the last job the kernel does is run.
The init program in/sbin. init is short for initialization (initialization). The init program is used to read the instructions described in the/etc/inittab file, initially set various software and hardware environments of the system. finally, run mingetty to wait for the user to enter the user name to log on to the system. all the work is so simple. Although there is a lot of content when linux is started, it looks very advanced, but it is just an extension of this process. with this understanding, you can write script programs to run and complete the task at the specific time the system starts. in fact, the system kernel does not care whether the init in/sbin is true init. As long as it is put in the executable program named init in/sbin, it can be executed. you can do the following experiments:
  
Compile a very simple C program:
  
Main ()
{
Printf ("hello, world! ");
}
  
Save it as init. c and compile it with gcc.
# Gcc? -Static-o init. c
Here the -- static parameter tells gcc to statically connect the program, so that the program can run without relying on any library. copy the compiled init program to/sbin and back up the original one. the output result of restarting the system is: hello, world!
Then stop there. before doing this experiment, make sure that you know how to restore the system to its original state. There is a simple method to add the init = parameter to the kernel before it starts, for example, you changed your original init to init. bak only needs to add init =/sbin/init to the kernel at startup. bak can use the original init program to start the system.
After completing the above experiment, we will understand the relationship between the kernel and the init program. in addition, the init program is not necessarily a binary executable program. It can be a bash script and a link pointing to another program. Its location is not necessarily under/sbin, the init parameter can be added to the kernel when the kernel is started. For example, the init =/bin/bash parameter is added to the kernel at the beginning, the kernel runs bash directly in the last step and provides a prompt. You can enter the command without logging on to the system. the function is similar to starting the system in single-user mode. the/sbin/init program is the first program that runs by default in the kernel.
  
6. Compile a linux Kernel
  
1. planning and preparation before Compilation
  
Before compiling the kernel, determine your requirements and list your requirements in a detailed table. what hardware does the Kernel support, how many partition types and file systems are supported, what network adapters are supported, and what network protocols are supported. and so on. please list the content in detail as much as possible, but you should not be greedy, because all the space you can use is only 1440 K, if you compile a kernel larger than 1440K or very close to this number, your project will not be completed. You have no space to store the ramdisk image file, unless you want to create another floppy disk and create a linux system with two floppy disks. for sound card drivers, I suggest you give up, because a sound card driver may only increase your kernel by more than 10 K, but you must have a player if you have a sound card driver, otherwise, the sound card driver is meaningless, but the size of a player is not the size of a floppy disk. the babylinux kernel I created earlier has more than 900 KB. Among them, the file system department has a majority of sub-stations, because my goal is to make him a system Repair Disk. therefore, I compile the support for 7 types of file systems in the kernel. Every time a file system is reduced, the kernel size can be reduced by dozens or even more than 200 kb. the more complex the file system is, the more secure the file system is. For example, in linux, the FAT module only has 32 K, and the VFAT module only has 17 K, but the ext3 module has 86 K, JFS reaches 216 kb, And the reiserfs module is 224 KB. As you can imagine, compiling a 900-kb kernel that supports 7 file systems takes up more than KB of space, therefore, if you do not need a file system, you should not compile it into the kernel, which can save at least 100 kb of space. for other drivers, such as NICs, the size is usually only 8 K, but the maximum size is more than 10 K. Therefore, you can compile the drivers of commonly used Nic chips. in addition, if you want your babylinux to support the USB flash drive, the scsi driver module should not be underestimated. Generally, it should be close to 150 kb, because the USB flash drive is used as a scsi device. in addition, you also need to make your kernel support plug-and-play, which is not a small amount of space overhead. I suggest you discard one or two file systems you don't need. in short, the size of the last compiled kernel should not exceed 900 KB. Otherwise, you can only compile a few commands in busybox.
  
In my compiled busybox, I compiled more than 120 commands, basically including the commands supported by busybox. add the file system directory required by a small system, the device files under/dev, and several required configuration files under/etc. The size after ramdisk compression is more than 440 kb, a k or so kernel can be added to a 1440K floppy disk. Please note that you should leave at least 50 K space, because we need to create an ext2 File System on the floppy disk, the file system must occupy about 25 KB of disk space. in addition, the lilo boot file. the size of B is 5.7 kb, and the size of the map file automatically generated after lilo is installed is more than 10 KB. The size of the map file is determined by the actual size of the kernel installation, usually no more than 30 K.
To sum up, follow the following formula:
  
Kernel size + file system compression impression file + 50 K <= 1440 K
  
Another point to note is that the file system module size listed above is to check my current Redhat 9
The actual size of the module File under/lib/modules compiled into the kernel will be a little smaller, because we use make bzImage
The kernel generated under the kernel source code directory is compressed.
  
If you do not understand the above content, I will provide a detailed description in the following content.
  
2. Content that must be compiled into the kernel
  
First, the small system we created is based on a floppy disk. Therefore, your kernel must support floppy disks. in addition, the support for IDE hard disks and cdrom is also indispensable. Otherwise, babylinux has no practical value, it is a waste of time to create a useless thing because he cannot access linux such as hard disk and disk content. others include framebuffer. If you need to support high-resolution display on the Character interface to see more screen content, you must compile the framebuffer support into the kernel, in addition, the 8x8 fonts used in high resolution must be compiled. otherwise, even if you pass the vga = parameter to the kernel, the kernel will automatically jump to the low resolution mode because there is no available small font. This is
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.