Linux customization method summary

Source: Internet
Author: User

A summary of Linux customization methods since I learned that Linux can be customized in college, I have always wanted to make a version of my own Linux system. Recently, I was idle and finally had a hard time learning. Currently, there are two methods for customizing Linux: 1. Taking busybox as the core and building the fs + kernel made by initrd + busybox, build Linux 2. Use a more underlying approach. Based on the source code level, build your own toolchain + compilation and build your own lfs + kernel, the most typical one is the LFS system I just completed. The advantages and disadvantages of the two methods may be incorrect because I am not familiar with them. Method 1 is much faster than method 2, and is more suitable for small embedded Linux. Method 2 adopts a more underlying and direct method, and is suitable for learning the Linux architecture. It also has good scalability and freedom, and is more flexible in customization, after laying the foundation, you can continue BLFS. No matter how much it is, I just want to take a note to avoid having finished it. After two months, I forgot how to do it =! Method 1: Prepare a tool: one host, one hard disk (Virtual Disk of virtual machine can be used for learning), one pure kernel, busybox Source Code 1. Split the hard disk into two zones, one for boot and the other for the root file system, then they are mounted to the/mnt/boot AND/mnt/sysroot directories of the host machine. Install grub to the boot directory: grub-install -- root-directory =/mnt/dev/sda 2. Compile busybox. The menuconfig is similar to the kernel, select the following in the box, 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. Create initrd. Initrd stands for init ram disk. In my understanding, it is a temporary root file system running in ram before linux is started. It is used to mount the root file system on the actual hard disk. For some scenarios that require hot shutdown, initrd can be used directly as the final file system. Create an initrd folder under the host machine/tmp directory, and copy all the content in the _ install Folder after busybox is installed to the initrd folder, at this time, some common commands are included. Next, create a common system folder: mkdir-pv proc sys etc tmp dev mnt/sysroot to create two necessary device files: mknod dev/console c 5 1 mknod dev/null c 1 3 create init script, implement rootfs switching after initrd is started [root @ localhost initrd] # vim init [root @ localhost initrd] # cat init #! /Bin/shmount-t proc/procmount-t sysfs/sysmdev-smount-t ext3/dev/hda2/mnt/sysrootexec switch_root/mnt/sysroot/sbin/init # this script execution permission: chmod + x init Note: For various possible reasons, rootfs cannot be mounted when the init script is started, especially in the mdev-s step. There is a debugging method here, start the shell directly in initrd. Code above/sbin/getty-n-l/bin/sh 38400 tty1exec/bin/sh can load a location in the init script as appropriate. Okay. Now the initrd is ready and packaged for use. Find. | cpio -- quiet-H newc-o | gzip-9>/mnt/boot/initrd.gz 5. Next, create a true rootfs. In fact, the working principle is similar to making initrd. The following is a brainless record: # copy all files in busybox to/mnt/sysrootcp-a busybox-1.20.2/_ install/*/mnt/sysroot # create the directory mkdir-pv/mnt/{boot/grub required by minilinux, 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} # create two necessary device files: mknod dev/console c 5 1 mknod dev/null c 1 3 # configure the inittab configuration file cd/mnt/sysrootrm-f linuxrc [root @ localhost sysroot] # vim etc/ inittab [root @ l Ocalhost 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 # configure the system initialization script etc/rc. d/rc. sysinit [root @ localhost sysroot] # vim etc/rc. d/rc. sysinit [root @ localhost sysroot] # cat etc/rc. d/rc. sysinit #! /Bin/shecho-e "\ tWelcome to \ 033 [31mMageEdu \ 033 [0 m Linux" echo-e "Remounting the root filesystem... "mount-t proc/procmount-t sysfs/sysmount-o remount, rw/echo-e" Creating the files of device... "mdev-secho-e" Mounting the filesystem... "mount-aswapon-aecho-e" Starting the log daemon... "syslogdklogdecho-e" logging ing loopback interface... "ifconfig lo 127.0.0.1/24 ifconfig Eth0 172.16.100.100/16 # grant this script execution permission: chmod + x etc/rc. d/rc. sysinit # Prepare a "file system table" configuration file for the system etc/fstab [root @ localhost sysroot] # vim etc/fstab [root @ localhost sysroot] # cat etc/fstabsysfs/sys sysfs defaults 0 0 proc/proc defaults 0 0/dev/hda1/boot ext3 defaults 0 0 0/dev/hda2/ext3 defaults 1 1 -------------------- reprint ends ---------------------- note that, the fstab file is very important and must be configured to meet actual usage requirements. 4. Compile the pure kernel first. Some options can be simplified .. Make mrproper in advance. After compilation, copy the compiled bzImage file to the boot partition. 5. Now you have both the kernel and initrd. You need to configure grub. conf and pay attention to the actual usage. 6. Remember to sync and create a new virtual machine. You can boot it with a prepared hard disk. For the busybox method, there are a lot of tutorials on the Internet, which are very detailed and have similar ideas. Let's talk about it here. Method 2: Prepare a tool: one host and one hard disk (Virtual Disks of virtual machines can be used when learning). Download the tool from LFS-packeages, I am using stable7.3. In fact, the best thing about this method is to read the official tutorial. It is very well written, very detailed, and has many knowledge points. I will record a train of thought here. Let me explain my understanding. The most important thing for us to do is to ensure her purity. That is, the system is an independent system, which has nothing to do with the host machine, therefore, because LFS is code-based and all programs need to be compiled, this means that the compiler and glibc library that are dependent on during compilation are a key point, that is, the tool chain mentioned repeatedly, as follows. Host tool chain-compile the LFS system tool chain-for self-compilation, build rootfs the entire LFS process is as follows: 1. Partition the hard disk; 2. Create a user, enter the directory, and compile Binutils and Gcc together with the host, then compile Glibc, and then re-compile Binutils and Gcc Based on the compiled Glib. In fact, the layout of the tool chain is just like this, and the relationship with the host machine is eliminated. Of course, these three are the most basic tools. In addition, a large number of tools are required to deploy the tool chain. These tools are based on these three tools. 3. Run the chroot command below to enter the pure LFS system, starting from scratch. Install the required commands one by one through the tool chain completed above. 4. Compile the kernel, configure fstab, and configure grub, but there is no initrd. After checking the cause on the Internet, the meaning of initrd can also reduce the kernel size of the real system, because some of them need to start the media driver and root file system driver during system startup, so there are general releases. However, LFS is generally used only on a single machine, so this step is not required. You can also add it if you want to add it. The above is a beginner's note (which may be full of loopholes and incorrect links.

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.