# Show your mercy... If you step on me, please tell me the reason. (2) You just sent it up for 10 times in the morning...
# Build your own dedicated Linux (2) link http://blog.csdn.net/deansrk/article/details/6664558
It's almost a month since I followed Marco's study of Linux. A small Linux was created a few days ago, and the size was less than 10 MB. I came up with the idea that I would like to write a series of articles about DIY and Linux, by using the host machine, you can create a small Linux instance step by step and gradually add its functional modules: Network, service, ssh, graphic interface, etc ~ If you are interested, let's study together!
If you are not familiar with the Linux Startup Process, read my article:
Linux Startup Process Analysis http://blog.csdn.net/deansrk/article/details/6659421
My Linux version: RedHat 5.4
Virtual Machine Client: VMware Workstation 6.5
We implement this small Linux
Step 1: Add a new hard disk to Linux on the VM, with a size of 20 GB (customizable)
Step 2: 1) Open the terminal and use fdisk to format the New Hard Disk/dev/SDB that has just been attached to the partition. A 50 m primary partition and a m primary partition are divided.
[root@server69 ~]# fdisk /dev/sdbThe number of cylinders for this disk is set to 2610.There is nothing wrong with that, but this is larger than 1024,and could in certain setups cause problems with:1) software that runs at boot time (e.g., old versions of LILO)2) booting and partitioning software from other OSs (e.g., DOS FDISK, OS/2 FDISK)Command (m for help): pDisk /dev/sdb: 21.4 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System/dev/sdb1 1 7 56196 83 Linux/dev/sdb2 8 70 506047+ 83 Linux/dev/sdb3 71 102 257040 82 Linux swap / SolarisCommand (m for help): nCommand action e extended p primary partition (1-4)pSelected partition 4First cylinder (103-2610, default 103): Using default value 103Last cylinder or +size or +sizeM or +sizeK (103-2610, default 2610): +50M Command (m for help): w
2) reread the Partition Table
[root@server69 ~]# partprobe /dev/sdb
Format the created partition as an ext3 File System
[root@server69 ~]# mke2fs -j /dev/sdb1[root@server69 ~]# mke2fs -j /dev/sdb2
Step 3: mount the newly formatted partition/dev/sdb1 to/mnt/boot/dev/sdb2 to/mnt/sysroot. If you do not have these two folders, create them manually, if you have mounted other devices, you can change to another path.
[root@server69 LX]# mount /dev/sdb1 /mnt/boot[root@server69 LX]# mount /dev/sdb2 /mnt/sysroot
Step 4: 1) install grub to/dev/SDB
[Root @ server69 MNT] # grub-install -- root-directory =/mnt // DEV/sdbinstallation finished. no error reported. this is the contents of the device map/mnt // boot/GRUB/device. map. check if this is correct or not. if any of the lines is incorrect, fix it and re-run the script 'grub-install '. (fd0)/dev/fd0 (hd0)/dev/SDA (hd1)/dev/sdb2) Modify/mnt/boot/GRUB/device. map [root @ server69 MNT] # Vim/mnt/boot/GRUB/device. map (fd0)/dev/fd0 // remove this line FD refers to the floppy disk (hd0)/dev/SDA (hd1)/dev/SDB // remove this line
Step 5: Copy kernel and initrd to small Linux. If you have no idea about kernel and initrd, please refer to my article, which provides detailed instructions.
Introduction: Linux Startup Process Analysis
1) copy the Kernel File and rename it to make it easier to remember.
[root@server69 LX]# cp /boot/vmlinuz-2.6.18-164.el5 /mnt/boot/vmlinuz
2) copy the initrd file and rename it to make it easier to remember.
[root@server69 LX]# cp /boot/initrd-2.6.18-164.el5.img /mnt/boot/initrd
Step 6: Decompress initrd, edit the init file, and re-compress the package.
[Root @ server69 MNT] # mv initrd initrd.gz // just renamed, otherwise, Gzip does not recognize [root @ server69 MNT] # gzip-D initrd.gz // decompress [root @ server69 MNT] # cpio-id <initrd.gz // Release Archive 14731 blocks [root @ server69 MNT] # lsbin boot Dev etc init lib proc sbin sys sysroot // have you seen it? Initrd has almost all Linux file directories. It is simply a small Linux [root @ server69 MNT] # Vim init 99 mkrootdev-T ext3-O defaults, RO/dev/vol0/root // change to mkrootdev-T ext3-O defaults, RO/dev/sda2 [root @ server69 MNT] # Find. | cpio-h newc-O quiet | gzip-9 // archive and compress
Step 7: create a small Linux File directory structure
[root@server69 mnt]# cd /mnt/sysroot/[root@server69 sysroot]# mkdir -pv root bin sbin usr/{bin,sbin} lib dev tmp proc sys home mnt media boot
Step 8: copy the command to a small Linux
1) how to copy commands?
[Root @ server69 sysroot] # Which bash // use the which command to view the command path/bin/bash [root @ server69 sysroot] # LDD/bin/bash/LDD + command path the library file linux-gate.so.1 on which this command depends can be displayed => (0x008e6000) // This file does not need to be copied to libtermcap. so.2 =>/lib/libtermcap. so.2 (0x0041e000) libdl. so.2 =>/lib/libdl. so.2 (0x003ef000) libc. so.6 =>/lib/libc. so.6 (0x002a7000)/lib/ld-linux.so.2 (0x00284000) [root @ server69 sysroot] # cp/lib/cmdkl. so.2/mnt/sysroot/lib // copy the above library files to the corresponding directory of small Linux
2) copy the commands init, Bash, mount, and ls to Linux. Note that init and Bash must be copied.
Step 9: Create the/mnt/etc/fstab file and the/mnt/etc/inittab file. (the description of this file can be found in my startup process Article)
[root@server69 ~]# vim /mnt/sysroot/etc/fstab/dev/sda2 / ext3 defaults 0 0/dev/sda1 /boot ext3 defaults 0 0sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0[root@server69 ~]# vim /mnt/sysroot/etc/inittabid:3:initdefault:si::sysinit:/etc/rc.d/rc.sysinit
Step 10: Create/mnt/boot/GRUB/grub. conf and/etc/rc. d/rc. sysinit, and grant the execution permission to RC and sysyinit.
[Root @ server69 ~] # Vim/mnt/boot/GRUB/grub. conf default = 0 timeout = 10 Title little Linux // the title of grub. You can write kernel/vmlinuz Ro root =/dev/sda2 quiet // to load the kernel, mount the root file system initrd/initrd.gz in read-only mode // load the memory file system [root @ server69 ~] # Vim/mnt/sysroot/etc/rc. d/rc. sysinit #! /Bin/bashecho-e "\ t \ twelcome to \ 033 [31mlittle \ 033 [0 m Linux" // enter the welcome page you want to write here ^ Mount-n- O remount. RW /// restart the Mount root file system in read/write mode Mount-n-A // mount all devices without recording/bin/bash // load BASH Shell
[Root @ server69 ~] # Chmod + x/etc/rc. d/rc. sysinit // grant the execution permission to RC. sysinit
All right, I'm done. Create a new virtual machine and select linux2.6xx. Mount this hard disk to check the effect ~
This is my grub interface very simple ~ You can change the background by yourself.
The effect of startup is very simple. Pay attention to little
# Update: grant the execution permission to RC. sysinit at the end of Step 10. Otherwise, the system may not be able to execute the command during loading!
In the next article, we will announce that the automatic script will automatically create a Linux instance and port commands to keep your Linux instance running ~