Linux File System tailoring (Graduation Design II a few years ago)

Source: Internet
Author: User
Chapter 3 Linux File System tailoring 3.1linux File System tailoring Platform(1) Add a virtual hard disk (1.5 GB, SCSI interface) based on the kernel tailoring platform ). (2) install a redhat9.0 server version + Perl language environment on this hard disk (3) install vmware-tools to direct the VM's optical drive to Linux in the VMware Installation File. the ISO image file enters the file cropping platform of the virtual system.

# Mount/mnt/CDROM

# Cd/usr/src/

# Tar zxvf/Mn t/CDROM/vmware-linux-tools.tar.gz

# Cd vmwrae-tools-distrib

#./Vmware-install.pl and then press Enter. (4) upgrade module-init-Tools 3.2linux File System tailoring MethodMake some preparations before tailoring. First, analyze the requirements. Analyze the functions to be achieved by the embedded system and set the system tailoring objectives. Then, the Linux system directory and the functions of the main files under the directory should be analyzed to retain the files required by the embedded system during the cropping process. Finally, develop a tailoring plan. Because I tailor the image on a virtual machine, I divide the tailoring process into four stages based on the characteristics of the Virtual Machine: the first stage is the overall tailoring stage. In this phase, the directory and file in redhat9 are tailored to the directories and files that are completely independent of the embedded system. In the process of tailoring, we must first ensure the normal operation of the system's network functions and various security services; and again ensure the normal operation of the file sharing Function of the virtual machine, because the file sharing Function of virtual machines should be used to interact with files on the host, more importantly, the system should be backed up during the tailoring process. On the one hand, you can use the snapshot of a virtual machine to back up the system for a short period of time. That is, during the system tailoring process, you can regularly check whether the functions to be retained in the system are running properly. If the functions are running properly, you can use snapshot to create, if not, the system revert is taken to the next normal running breakpoint. On the other hand, the system uses the tar backup tool to back up the system for a long time. Backup:

# Tar cvzf/mnt/HGFS/Windows/redhatbackup/redhat0420-200m.tar.gz bin/boot/dev/etc/initrd/lib/lost + found/root/sbin/usr/var/

Upload the system to the redhatbackupfolder of the primary system. The name "redhat0420-200m.tar.gz" indicates that the backup was performed on April 9, 200 MB. The details of the backup system should be saved as a description file for system recovery. Used for System Recovery: # cd/

# Tar zxvf/mnt/HGFS/Windows/redhatbackup/redhat0420-200m.tar.gz

You can perform tar backup several times during the cropping process. If an error occurs during the cropping process, choose to recover from the appropriate backup. In the first phase, the system will be cut to about 30 mb. The second stage is the detailed tailoring stage. During this phase, the upgraded and cropped kernel will be moved to the system, so that the cropped system can work normally under the linux2.6 kernel. In this phase, the file sharing Function of the virtual machine will no longer be retained. The system backup will be backed up in the first hard disk of the virtual system, the kernel clipping System in the first hard disk copies the backup file to the Windows main system for backup. At this stage, we need to analyze the functions of the remaining files in detail. On the other hand, we need to continuously "crop-test-Backup" during the cropping process, and sometimes even crop individual files. Errors Found and the roles of individual files should be recorded in the cropping. In the second stage, the system will be cut to around 13 MB. The third phase will use busybox and tinylogin to further compress the system size. Busybox is a powerful tool for embedded systems. Busybox is a collection of tools and programs that provide most common commands. Many commands can be directly connected to the past. It is designed for embedded system debugging. Busybox combines minor versions of many common UNIX utilities into a single executable to provide a completely POSIX environment for embedded systems. It can implement most common commands in Linux, but only occupies-K space (depending on the number of commands you compiled ). Replacing some commands with busybox can reduce space. Compiling busybox is similar to compiling the kernel. I use busybox-1.00-pre7.tar.gz # tar zxvf busybox-1.00-pre7.tar.gz # cd busybox-1.00-pre7 # Make menuconfig configure busybox option # Make Dep # Make prefix =/mnt/sdc1/install to install busybox directly to the U disk, you can perform drills on the system test platform several times. Note: commands such as init, login, ismod, unmod, halt, shutdown, poweroff, reboot, IFUP, ifdown, ls, hwclock, umount, and bash cannot be replaced by busybox. These command functions in busybox are weak, and the functions required for normal startup of the system cannot be completed. Tinylogin is a sister project of busybox and a collection of tool programs. It provides user identity management programs in a multi-user environment ,. Tinylogin implements login, user authentication, account management, and other functions. Like its name, tinylogin is very small and is a good supplement to busybox. In the system, tinylogin-1.4.tar.gz is used to replace login, passwd, Su, sulogin and other commands, and/lib/security/*,/etc/PAM are deleted. d/*,/lib/libpam *,/lib/libnsl * and other files. Saves a lot of space. The adduser, deluser, addgroup, delgroup, Getty, and Vlock options are removed from the configuration file config. h of tinylogin. Login, passwd, Su, sulogin, and other options are retained. Because tinylogin is used, remove Su, sulogin, and pidof from the configuration of busybox, and replace pidof in busybox with the original pidof of the system. The pidof function in busybox is weak and does not support MITI-call in tinylogin. An error occurs when the system disables the anacron service. To save space, the GNU libc's NSS library is not used during compilation. That is, the system in makefile "use_system_pwd_grp = false" will be cut to about 6 MB in the third stage. The fourth stage compresses the file system to further reduce the system size. In this phase, the system will adopt the "kernel + initrd" format. The file system will be compressed and loaded into the memory in the form of initrd at system startup, working in ramdisk mode (simulating the memory as a hard disk. This method has two advantages: on the one hand, the compression of the root file system reduces the size by 50%, and the USB Module is no longer needed in the kernel to reduce the size of the kernel, this greatly reduces the system volume (which can be reduced to less than 3 m). On the other hand, because the system runs in the kernel, its operation speed is greatly improved, and it also reduces the system's repeated read/write operations on the USB flash disk, improves the service life of the USB flash drive. Of course, this method also has some shortcomings: loading the entire root file system at startup will slow down the startup speed, and changes made to the system at runtime will not be saved, this will make some log files unable to be saved. Based on your needs, check whether the fourth step is tailored. Because the root file system exceeds 4 m and the default ramdisk size is 4 m, you need to modify the ram option of the kernel of the running system: <*> RAM disk supprot

(5120) default RAM disk size

Recompile the kernel. Then, create the initrd directory under the appropriate directory (the directory where the document is saved by yourself), create the local and ramdisk directories under the initrd directory, and set the system obtained in step 3 (except the boot/directory) and create the script file mkinitrd in the initrd directory. sh, whose content is :#! /Bin/sh dd If =/dev/Zero of =/dev/ram0 BS = 1 k count = 5120 mke2fs/dev/ram0 Mount-T ext2/dev/ram0 ramdisk/CP -APDR local/* ramdisk/umount ramdisk dd If =/dev/ram0 BS = 1 k count = 5120 | gzip-V9> initrd.gz: # chmod A + x mkinitrd. sh #. /mkinitrd.shshould be executed and cannot generate the corresponding initrd.gz file. You need to manually modify it # gunzip initrd.gz // decompress the block File

# Mke2fs-M 0 initrd // reformat the block File

# Mount-o loop initrd/mnt/initrd // mount the block File

# Cp-APDR local/*/mnt/initrd // copy the root file system

# Umount/mnt/initrd // unmount the block File

# Gzip-9 initrd // re-compress the block File

Note that the kernel module in the root file system must correspond to the kernel. 3.3 Linux File System Directory and reserved file description (see Appendix 2) Summary of this ChapterThis chapter describes the Linux File System tailoring process in four phases. It describes the important roles and usage of virtual machines in the tailoring process, at last, we will explain in detail the relevant information about the files retained after the cropping and the commands replaced by busybux.

 

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.