Linux system customization based on BusyBox and LFS

Source: Internet
Author: User

Since the university knew that Linux this thing can be customized, and always want to make a version of their own Linux system. Recently work relatively busy, finally collapsed heart to study well.   At present, there are two main ways I approach the customization of Linux:  1, busybox as the core, build linux 2 by building the three chunks of the fs+ kernel made by Initrd+busybox, and adopt a lower-level approach, Build Linux based on the source code level by compiling & building your own Toolchain + compiling & building your own lfs+ kernel, the most typical of which is the LFS system I just completed.   about the pros and cons of the two methods, because I contact is relatively superficial, so I know there may be some mistakes. The   Method 1 is much faster than 2 in speed and is more suitable for small embedded Linux. and Method 2 due to the use of a more direct approach to the lower level, suitable for learning the architecture of Linux, there is also good extensibility and freedom, the customization is more flexible, the foundation can continue to follow the Blfs.   First, no matter how much, I just want to make a note, so as not to finish, after two months, how to do all forget clean = =!   Method:  need to prepare tools:  host one, hard disk (you can use virtual machine when learning the virtual disk), a pure kernel, BusyBox source code a  1, the hard disk divided into two areas, a boot with, a root file system with , and then mount the/mnt/boot and/mnt/sysroot directories to the host respectively.      Installing grub to the boot directory: Grub-install--root-directory=/mnt/dev/sda 2, compiling BusyBox, This thing does menuconfig like the kernel, in which the following is selected, that is, the compiled Busybox does not share the library file with the host, and then make install:    busybox Settings Build Options-- build BusyBox as a static binary (no shared libs)  3, production initrd. The INITRD full name is the init RAM disk, which I understand is the temporary root filesystem that runs in RAM before Linux starts to mount the root filesystem on the actual hard disk. For some occasions where thermal shutdown is required, INITRD can actually be used as the final file system directly.     Production method is this, in the host/tmp directory to build a initrd folder, just BusyBox installation completed _install folder under the contents of the full copy to the Initrd folder, At this point, some of the system's common commands are already included.      Next build system common folder: MKDIR-PV  proc  sys  etc tmp  dev  mnt/sysroot   & nbsp; Create two necessary device files:       mknod  dev/console  c  5  1        Mknod  dev/null  c  1  3     set up init scripts for INITRD switching after Rootfs startup  [[email  Protected] initrd]# vim  init [[email protected] initrd]# cat init #!/bin/shmount-t proc proc/ Procmount-t Sysfs sysfs/sysmdev-smount-t ext3/dev/hda2  /mnt/sysrootexec  switch_root  /mnt/sysroot &n bsp;/sbin/init# to execute permissions for this script: chmod  +x  init here, for various possible reasons, Init script startup cannot mount Rootfs, especially in mdev-s this step, here is a debugging method, Start the shell directly in the INITRD. /sbin/getty-n-l/bin/sh 38400 tty1exec/bin/sh The code above can load a location in the Init script as appropriate.   Good, to here initrd is finished, pack it up, stay with it.  find  .  | Cpio  --quiet  -h NEWC  -O  | Gzip  -9 >/mnt/boot/initrd.gz 5, then make real rootfs, in fact, the method principle and production initrd almost. The following is no brain reproduced:   #拷贝busybox中所有文件到/mnt/sysrootcp-a busybox-1.20.2/_install/*/mnt/sysroot# The directory required to create the Minilinux mkdir-pv/mnt/{boot/grub,sysroot/{boot,proc,sys,bin,sbin,lib/modules,usr/{bin,sbin,lib},var/{ RUN,LOG,LOCK},ETC/{INIT.D,RC.D},DEV/PTS,HOME,ROOT,TMP}} #创建两个必要的设备文件: Mknod  dev/console  c  5   1mknod  dev/null  c  1  3# configuration init required Inittab profile CD  /MNT/SYSROOTRM  -f  linuxrc[[ Email protected] sysroot]# vim etc/inittab [[email protected] sysroot]# cat etc/inittab :: Sysinit:/etc/rc.d/rc.sysinit::respawn:/sbin/getty 9600 Tty1::respawn:/sbin/getty 9600 Tty2::respawn:/sbin/getty 9600 tty3::shutdown:/bin/umount-a-r::ctrlaltdel:/sbin/reboot# Configuring the system initialization script etc/rc.d/rc.sysinit[[email protected ] sysroot]# vim  etc/rc.d/rc.sysinit[[email protected] sysroot]# cat etc/rc.d/rc.sysinit#!/bin/shecho-e "\ Twelcome to  \033[31mmageedu\033[0m Linux "Echo-e" remounting the root filesystem ... "mount-t proc proc/procmount-t Sysfs Sysfs/sysmount -O  remount,rw  /echo-e "Creating The Files of device ..." MDEV-SECHO-E "mounting the filesystem ..." Mount-as WAPON-AECHO-E "Starting the log daemon ..." SYSLOGDKLOGDECHO-E "Configuring Loopback interface ..." Ifconfig  lo &nb Sp;127.0.0.1/24ifconfig eth0 172.16.100.100/16# and then let the script have Execute permissions: chmod +x  etc/rc.d/rc.sysinit# Prepare a "File system table" for the system Configuration file etc/fstab[[email protected] sysroot]# vim  etc/fstab[[email protected] sysroot]# cat etc/ Fstabsysfs                  /sys             & nbsp      SYSFS   defaults        0 0proc             &NB Sp      /proc                   proc    defaults        0 0/dev/hda1             /boot                   EXT3    defaults        0 0/dev/hda2              /    & nbsp                 ext3    defaults        1 1 ————————— ——————————— reprint ends ———————————————————————— Note that it is important to fstab this file to be configured to fit into the actual usage situation. 4, the pure kernel to compile first, you can streamline some of the options. It is best to be fully prepared for the first time, remember to make mrproper in advance. Once the compilation is complete, copy the compiled bzimage file to the boot partition. 5, now has both the kernel, and INITRD, the configuration grub.conf, the same attention to the actual use of the situation. 6, must remember sync, then create a new virtual machine, with a good hard drive should be able to boot up. About BusyBox This method, there are a lot of tutorials online, very detailed, the idea is similar, said here. Method two:  need to prepare tools:  host one, hard drive piece (can learn to use virtual machine virtual disk), lfs-packeages, official download, I use stable7.3  actually about this method, The best is to read the official tutorials, written very good, very detailed, but also with a lot of knowledge points, I will record a train of thought.   Let me explain what I understand. We want to make a system, the most important thing is to ensure her purity, that is, the finished system is a separate system, and the host has no connection, then because LFS is based on code-level, all programs need to compile, which means that the compiler depends on the compiler, GLIBC library, etc., is a focus, That is, the chain of tools repeatedly mentioned, as follows. Host Toolchain-"compiled LFS system Toolchain-" to self-compile, form a standalone-"build Rootfs the entire LFS process is 1, or the hard disk partition 2, create a new user, enter the directory, the host hosts separately compile binutils and GCC, then compile glibc, and then recompile binutils and GCC based on the newly compiled glib. In fact, the layout of the tool chain is such a meaning, out of the relationship with the host. Of course, these three are the most basic, in addition to the layout of the tool chain also requires a lot of tools, and these tools are based on these three. 3, the following chroot, into the pure LFS system, starting from zero. Through the tool chain completed above, one installs the required commands. 4, compile kernel, configure Fstab, configure grub, but no initrd. Check on the Internet for a reason, the original initrd the meaning of the existence of the real system can also reduce the kernel size, because some of the system boot time required to boot media driver, root file system driver, so the general distribution has. But LFS generally only for single use, so there is no such step, of course, I would like to add.   Above is a beginner's (probably a flawed, wrong) note.

Customization of Linux systems based on BusyBox and LFS

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.