Self-made Linux system

Source: Internet
Author: User
Tags uuid

This experiment takes CENTOS6 as an example


System Startup Process Description

--load the BIOS, load CMOS information through the BIOS program, and obtain hardware information via CMOS

-Power On self-test post

--Read MBR information

-->grub Boot system Boot

--Open the system first process init

-User Login

There are a few things we need to understand:

1, MBR is the first sector of the disk, 512 bytes, where the first 446 bytes is the boot loader boot loader, after 64 bytes is the partition table, the last 2 bytes is the end bit of MBR 55AA

System to boot, it is necessary to load the kernel, a variety of drivers, the Linux kernel is stored in/boot, the drive file is stored under/lib/modules, so the first step in the START process to enter/boot to load the kernel file,

The/boot is a separate partition and uses the Ext4 file system. That is, to enter/boot load the kernel must have a file system driver, and to install the file system driver to load the kernel first. So into a dead loop.

But we know that the reality is that Linux can start normally, what is the reason?

Because there are mbr,mbr in the first 446 bytes of boot loader, we call the Grub Stage1, and then into the stage1.5 phase, the information that is loaded in this phase is 27 sectors after the MBR512 bytes.

stage1.5 after the end of the stage2 phase, the Stage2 phase will execute the configuration file grub.conf, the document reads as follows:

default=0  //the default loaded kernel, INITRD file, 0 indicates that the first titletimeout=5  //the menu options that appear during boot time splashimage= (hd0,0)/ grub/splash.xpm.gz  //the background picture of the boot menu option hiddenmenu  //The background execution process of the hidden menu title centos 6  ( 2.6.32-696.el6.x86_64)   //name         root  (hd0,0)   //the 1th disk of the 1th partition as the root, it is plain that boot is the root, where the root for the system to start use, and after the start of the root/two different          kernel /vmlinuz-2.6.32-696.el6.x86_64 ro root=uuid=f1d8d9f5-4d1a-42e8-8a7f-600f668ce44f  rd_no_luks rd_no_lvm lang=en_us. utf-8 rd_no_md sysfont=latarcyrheb-sun16 crashkernel=auto  keyboardtype=pc  keytable=us rd_no_dm rhgb quiet        //kernel  Load the kernel as read-only, where the UUID is the root/uuid        initrd /at the end of startup initramfs-2.6.32-696.el6.x86_64.img        //initrd  contains file system drivers, whichTo load the kernel files. 

2, start the system the first process/sbin/init, its role is to deploy a good software environment, that is, host name, network configuration, file system format, etc.

And the implementation of these functions, mainly by/etc/inittab and/etc/init.d/*.conf these files completed (CENTOS6 version). These features of the CENTOS5 version are all on the/etcinittab file.

Its general meaning is as follows:

--Default RunLevel, user Login system default Level

    • 0: Turn off the machine

    • 1: Single-user mode

    • 2: Multi-user mode, some network functions do not support

    • 3: Full multi-user mode, character interface

    • 4: Reserved

    • 5: Graphical interface (default RunLevel)

    • 6: Restart

--script that executes the system software running environment/etc/rc.d/rc.sysinit

The function is to prepare the operating environment of the system, such as Mount file system, swap, clock, load peripheral driver, activate sysctl.conf file set kernel parameters

-->7 a different runlevel to start a path that is not a startup service script

--power outage and recovery power handling

--Terminal TTY settings

-Interface Run Settings

These steps are completed, the user can login to use the system;


Let's do an experiment and deepen our understanding.

Self-made Linux system

Preparation: A new disk, a machine with a system installed, and a machine without a system. You can finish the cost experiment on the virtual machine

Step 1, the new disk in the local partition, file system

Create 2 necessary partitions/dev/sdb1 corresponding BOOT,/DEV/SDB2 corresponding/

Fdisk/dev/sdb

Create file system, take EXT4 as an example

Mkfs.ext4/dev/sdb1mkfs.ext4/dev/sdb2

Blkid command to check file system Information

Step 2, Mount Boot

The Mkdir/mnt/boot mount directory must be boot, because Grub's stage2 will specifically find the boot directory mount/dev/sdb1/mnt/boot/

Step 3, install Grub

Grub-install--root-directory=/mnt/dev/sdbstage1 installed on/dev/sdb disk, Stage2 installed in/mnt/boot directory

In this case, there will be a stage2 stage directory for Grub/mnt/boot

Step 4, copy the kernel, Initramfs

cp/boot/vmlinuz-2.6.32-696.el6.x86_64/mnt/boot/cp/boot/initramfs-2.6.32-696.el6.x86_64.img/mnt/boot/

Step 5, Edit grub.conf

650) this.width=650; "Width=" "height=" "title=" Clipboard.png "style=" width:900px;height:100px; "alt=" Wkiom1mrt1igrzjcaadb7ju3goy086.png "src=" https://s4.51cto.com/wyfs02/M01/05/C0/ Wkiom1mrt1igrzjcaadb7ju3goy086.png "border=" 0 "vspace=" 0 "hspace=" 0 "/>

The contents of the diagram above have been described in basic, this experiment root=/dev/sda2, because this disk is to be another machine's boot disk is naturally Sdba2

Selinux=0, because selinux may affect the effect of this experiment, so start it off

Init=/bin/bash, we use bash as the first boot process

Step 6, Mount Root/, and initialize

Create a directory and mount the root

Mkdir/mnt/rootmount/dev/sdb2/mnt/root/mkdir/mnt/root/{etc,lib,sbin,tmp,var,sys,proc,dev,}//create the corresponding directory under root

Run the following script to copy the command file and the library file to the root directory (/mnt/root), provided that we enter common commands

The command we've entered is the command supported by the homemade Linux system.

#! /bin/bashtitle  ()  {        export CMD         read -t 30 -p  "Input an exec cmd  or press  ' quit ':  '  cmd        if [   "$CMD"  =  "Quit"  ];then                 exit        else                 is_exec         fi        title} #判断输入的是可执行文件is_exec   ()  {         if  ' which  $CMD  &> /dev/null '  ; Then                copy_ Cmdfile                copy_libfile                 echo  "--->done"          else                 echo  "Not a command"                  exit        fi}# Copy command file copy_cmdfile  ()  {        exec_cmd= ' which  $CMD '         if [ ! -e /mnt/root$exec_cmd ];then                 cp   --parents  $EXEC _cmd /mnt/root        fiunset exec_cmd}# Copy the library file corresponding to the command file copy_libfile&nbsp, ()  {        ldd  ' which  $CMD '  | grep  -o   "/.*[0-9] "  | while read line ;d o                 if [ ! -e /mnt/ root$line  ];then                         cp  --parents  $line    /mnt/root/                 fi        doneunset line}title

This is the end of the experiment, then shutdown, remove the disk, installed on another host without a system, start

The interface after startup is as follows:

650) this.width=650; "title=" Qq20170903162715.png "alt=" Wkiol1mrvspr2px8aabqcdcv_zk773.png "src=" https:// S1.51cto.com/wyfs02/m02/a4/72/wkiol1mrvspr2px8aabqcdcv_zk773.png "/>


This article is from the "Gao Pan" blog, make sure to keep this source http://panpangao.blog.51cto.com/10624093/1962313

Self-made Linux system

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.