This article is just to demonstrate the necessary elements of the Linux system boot process, not a fully functional Linux system.
My environment is VMware virtual machine, centos-6.7-x86_64 operating system.
First to add a disk for the virtual machine, I use the default 20G here, in fact, it does not need so large, but the virtual machine, you do not choose to allocate immediately, it will not really occupy so much space.
First partition it, using the MBR partition table. Plan three partitions, one boot partition 200M, one swap partition 2G, and the remaining space to the root partition.
[[email protected] ~]# parted -s /dev/sdb mklabel msdos[[email Protected] ~]# parted -s /dev/sdb mkpart primary 2048s 200m[[email protected] ~]# parted -s /dev/sdb mkpart primary 200m 2200m[[ email protected] ~]# parted -s /dev/sdb mkpart primary 2200m 100% [[email protected] ~]# partx -a /dev/sdb[[email protected] ~]# Mkfs.ext4 /dev/sdb1[[email protected] ~]# mkswap /dev/sdb2[[email protected] ~]# mkfs.ext4 /dev/sdb3[[email protected] ~]# parted -s /dev/sdb printModel: VMware, VMware Virtual S (SCSI) disk /dev/sdb: 21.5gbsector size (logical/physical): 512b/512bpartition table: msdosnumber start end size type file system Flags 1 1049kB 200MB 199MB primary ext4 2 200mb 2200mb 2000mb primary linux-swap (v1) 3 2200mb 21.5gb 19.3gb primary ext4
Create a directory under the/mnt directory as the root of the most streamlined system, and mount the plan as the root partition/dev/sdb3 to that directory.
[Email protected] mnt]# mkdir sysroot[[email protected] mnt]# mount/dev/sdb3/mnt/sysroot/
Build FHS directory structure under the/mnt/sysroot directory
[[Email protected] ~]# cd /mnt/sysroot/[[email protected] sysroot]# for d in $ (ls /); do mkdir -v $d; donemkdir: created directory ' bin ' mkdir: created directory ' boot ' mkdir: created directory ' dev ' mkdir: created directory ' etc ' mkdir: created directory ' home ' mkdir: created directory ' lib ' mkdir: created directory ' lib64 ' mkdir: cannot create directory ' Lost+found ': file existsmkdir: created directory ' media ' mkdir: created directory ' misc ' mkdir: created directory ' mnt ' mkdir: created directory ' net ' mkdir: created directory ' opt ' mkdir: created directory ' proc ' mkdir: created directory ' root ' mkdir: created directory ' sbin ' mkdir: created directory ' SELinux ' mkdir: created directory ' srv ' mkdir: created directory ' sys ' mkdir: created directory ' tmp ' mkdir: created directory ' usr ' mkdir: created directory ' var '
Mount the boot partition/dev/sdb1 to/mnt/sysroot/boot
[[email protected] sysroot]# mount /dev/sdb1 /mnt/sysroot/boot[[email protected] sysroot]# df -hFilesystem size used avail use% mounted on/dev/mapper/vg0-root 20g 301M 19G 2% /tmpfs 491M 0 491M 0% /dev/shm/dev/sda1 190m 36m 145m 20% /boot/dev/mapper/vg0-usr 9.8G 2.0G 7.4G 21% /usr/dev/mapper/vg0-var 20G 136M 19G 1% /var/dev/sdb3 18g 45m 17g 1% /mnt/sysroot/dev/sdb1 180m 1.6m 169m 1% /mnt/sysroot/boot
Grub is installed on the SDB and you can see that grub installs the Grub directory into the/mnt/sysroot/boot directory. In fact, some of the code is directly written to the physical sector of the disk, such as Stage1 is directly written to the first 446 bytes of the MBR, and according to the boot partition of the file type, the corresponding stage1_5 code will be written to the physical sector of the disk in front of the location, it should be written e2fs_ Stage1_5.
[[email protected] sysroot]# grub-install --root-directory=/mnt/sysroot/ /dev/ sdbprobing devices to guess bios drives. this may take a Long time. Installation finished. no error reported. this is the contents of the device map /mnt/sysroot//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/sdb[[email protected] ~]# ls /mnt/sysroot/boot/grub/ device.map ffs_stage1_5 minix_stage1_5 stage2 xfs_stage1_ 5e2fs_stage1_5 iso9660_stage1_5 reiserfs_stage1_5&Nbsp; ufs2_stage1_5fat_stage1_5 jfs_stage1_5 stage1 vstafs_stage1_5
Directly using the CentOS-6 kernel and pseudo-root file system, not so complicated, the version number is not.
[Email protected] boot]# cd/mnt/sysroot/boot[[email protected] boot]# cp/boot/vmlinuz-2.6.32-573.el6.x86_64. Vmlinuz[[email protected] boot]# cp/boot/initramfs-2.6.32-573.el6.x86_64.img./initramfs[[email protected] boot]# Lsgrub Initramfs Lost+found Vmlinuz
After the kernel boot is complete, it also needs to start the system initialization program, but it really completes the whole system initialization process, it requires many other programs to collaborate, too complex. In fact, you can specify a different program, here we to simplify, directly launched a bash, so we need to put bash to the past.
[email protected] ~]# which bash/bin/bash[[email protected] ~]# cp/bin/bash/mnt/sysroot/bin/
This is not enough, bash is not working, it also relies on some library files, so these library files also need to be ported.
[Email protected] ~]# Ldd/bin/bash linux-vdso.so.1 = (0x00007ffe8fbba000) libtinfo.so.5 =/lib64/libtinfo.so.5 (0x0000003e81000000) libdl.so.2 =/lib64/libdl.so.2 (0x0000003e76c00000) libc.so.6 =/lib64/libc.so.6 ( 0x0000003e77000000)/lib64/ld-linux-x86-64.so.2 (0x0000003e76800000) [[email protected] ~]# cp/lib64/libtinfo.so.5/ Mnt/sysroot/lib64/[[email protected] ~]# cp/lib64/libdl.so.2/mnt/sysroot/lib64/[[email protected] ~]# cp/lib64/ Libc.so.6/mnt/sysroot/lib64/[[email protected] ~]# cp/lib64/ld-linux-x86-64.so.2/mnt/sysroot/lib64/
Now there is a grub configuration file, you can do it yourself. Because we are going to take this hard drive down and hang it on another new virtual machine, so the new virtual machine only has this disk, (hd0,0) and/dev/sda3. In addition, when CentOS starts, the SELinux is loaded by default, and this simplified system has nothing to do, so it will affect the boot and turn it off.
[[email protected] ~]# cat/mnt/sysroot/boot/grub/grub.conf default 0timeout 5title minilinuxroot (hd0,0) kernel/vmlinuz Root=/dev/sda3 selinux=0 Init=/bin/bashinitrd/initramfs
After all this is done, the N-pass Sync command is executed, notifying the kernel that changes are immediately written to the disk and then shut down or suspended.
Create a new virtual machine, use the disk that you have just modified using select disk, and then start.
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/7E/1A/wKioL1b3sVqDRPqnAAAnkiSiK7E787.png "title=" 2016-03-27_180237.png "width=" "height=" 526 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" WIDTH:700PX;HEIGHT:526PX; " alt= "Wkiol1b3svqdrpqnaaankisik7e787.png"/>
You can see that grub boots up normally.
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/7E/1D/wKiom1b3sQKisBKYAABK3AvlW2s368.png "title=" 2016-03-27_180505.png "width=" "height=" 526 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" WIDTH:700PX;HEIGHT:526PX; " alt= "Wkiom1b3sqkisbkyaabk3avlw2s368.png"/>
Bash also starts up normally.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/7E/1D/wKiom1b3sVXjxSUhAAA5Z_fXv1w515.png "title=" 2016-03-27_180624.png "width=" "height=" 526 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" WIDTH:700PX;HEIGHT:526PX; " alt= "Wkiom1b3svxjxsuhaaa5z_fxv1w515.png"/>
As you can see, other commands cannot be executed except Bash's built-in commands, so this is just one of the most streamlined Linux systems to demonstrate the system's startup process, far from a fully functional Linux system.
This article is from the "knfprex3a29" blog, make sure to keep this source http://knfprex3a29.blog.51cto.com/9761463/1757273
Making the most streamlined Linux system