linux启动流程,grub和kickstart文件安装系统详解

简述linux操作系统启动流程

本示例流程以centos5和centos6版本的以MBR结构的linux启动流程为例,如下图:


linux启动流程,grub和kickstart文件安装系统详解_第1张图片
centos启动流程.png

加电自检:
自检主要检查硬件设备如:cup,内存,硬盘是否正常,外接的输入输出设备是否存在等等.

启动BIOS:
BIOS(基本的输入输出系统)装载在硬件芯片CMOS之上,自检时会启动这个程序,并根据CMOS上的配置信息去读取其他的硬件信息,检测正常之后进行硬件设备的初始化.

Boot Loader:
引导加载程序,在MBR(主引导记录)中,主要功能是识别,加载操作系统的核心文件,并提交到内存中运行来启动对应的系统,.windows的Boot Loader不具备控制权转交功能,因此windows的Boot Loader不能加载linux系统的Boot Loader,相反linux系统的Boot Loader可以加载windows的Boot Loader.

启动Kernel(ramdisk):
Kernel会自身初始化,探测可识别的硬件设备,因为Kernel是存在硬盘之中的,但是在内核启动时还没有加载硬盘,为了解决这个问题Kernel内核通过ramdisk(虚拟文件系统)来加载硬件程序,为了防止根文件系统加载时出现bug等问题无法挽回的情况,以只读方式来挂载根文件系统,来完成根文件系统的初始化.

rootfs:
启动真正的根文件系统,然后虚拟的根文件系统与真实的根文件系统进行交换

/sbin/init:
在内核,硬件及驱动信息加载完毕后,内核会运行用户空间的第一个应用程序:/sbin/init ,包括系统的主机名称,网络管理,文件系统格式等其他服务

centos5的文件格式
[root@localhost ~]# cat /etc/inittab 
#
# inittab       This file describes how the INIT process should set up
#               the system in a certain run-level.
#
# Author:       Miquel van Smoorenburg, 
#               Modified for RHS Linux by Marc Ewing and Donnie Barnes
#

# Default runlevel. The runlevels used by RHS are:
#   0 - halt (Do NOT set initdefault to this)
#   1 - Single user mode
#   2 - Multiuser, without NFS (The same as 3, if you do not have networking)
#   3 - Full multiuser mode
#   4 - unused
#   5 - X11
#   6 - reboot (Do NOT set initdefault to this)
# 
id:5:initdefault:

# System initialization.
si::sysinit:/etc/rc.d/rc.sysinit

l0:0:wait:/etc/rc.d/rc 0
l1:1:wait:/etc/rc.d/rc 1
l2:2:wait:/etc/rc.d/rc 2
l3:3:wait:/etc/rc.d/rc 3
l4:4:wait:/etc/rc.d/rc 4
l5:5:wait:/etc/rc.d/rc 5
l6:6:wait:/etc/rc.d/rc 6

# Trap CTRL-ALT-DELETE
ca::ctrlaltdel:/sbin/shutdown -t3 -r now

# When our UPS tells us power has failed, assume we have a few minutes
# of power left.  Schedule a shutdown for 2 minutes from now.
# This does, of course, assume you have powerd installed and your
# UPS connected and working correctly.  
pf::powerfail:/sbin/shutdown -f -h +2 "Power Failure; System Shutting Down"

# If power was restored before the shutdown kicked in, cancel it.
pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled"


# Run gettys in standard runlevels
1:2345:respawn:/sbin/mingetty tty1
2:2345:respawn:/sbin/mingetty tty2
3:2345:respawn:/sbin/mingetty tty3
4:2345:respawn:/sbin/mingetty tty4
5:2345:respawn:/sbin/mingetty tty5
6:2345:respawn:/sbin/mingetty tty6

# Run xdm in runlevel 5
x:5:respawn:/etc/X11/prefdm -nodaemon
-----------------------分-----割-----线-----------------------
centos6的文件格式
[root@localhost ~]# cat /etc/inittab 
# inittab is only used by upstart for the default runlevel.
#
# ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
#
# System initialization is started by /etc/init/rcS.conf
#
# Individual runlevels are started by /etc/init/rc.conf
#
# Ctrl-Alt-Delete is handled by /etc/init/control-alt-delete.conf
#
# Terminal gettys are handled by /etc/init/tty.conf and /etc/init/serial.conf,
# with configuration in /etc/sysconfig/init.
#
# For information on how to write upstart event handlers, or how
# upstart works, see init(5), init(8), and initctl(8).
#
# Default runlevel. The runlevels used are:
#   0 - halt (Do NOT set initdefault to this)
#   1 - Single user mode
#   2 - Multiuser, without NFS (The same as 3, if you do not have networking)
#   3 - Full multiuser mode
#   4 - unused
#   5 - X11
#   6 - reboot (Do NOT set initdefault to this)
# 
id:5:initdefault:

/etc/inittab和/etc/init/*.conf:
centos5的配置文件都在/etc/inittab目录下,centos6的配置文件在/etc/init/目录下所有以.conf结尾的文件中.关闭或启动对应的服务.

每行定义一种action以及与之对应的process
     id:runlevels:action:process 
           id:一个任务的标识符
           runlevels:在哪些级别启动此任务;#,###,也可以为空,表示所有级别
           action:在什么条件下启动此任务
           process:任务
                        
       action:
         wait:等待切换至此任务所在的级别时执行一次
         respawn:一旦此任务终止,就自动重新启动之
         initdefault:设定默认运行级别;此时,process省略
         sysinit:设定系统初始化方式,此处一般为指定/etc/rc.d/rc.sysinit脚本
[root@localhost ~]# cat /etc/inittab 
#
# inittab       This file describes how the INIT process should set up
#               the system in a certain run-level.
#
# Author:       Miquel van Smoorenburg, 
#               Modified for RHS Linux by Marc Ewing and Donnie Barnes
#

# Default runlevel. The runlevels used by RHS are:
#   0 - halt (Do NOT set initdefault to this)
#   1 - Single user mode
#   2 - Multiuser, without NFS (The same as 3, if you do not have networking)
#   3 - Full multiuser mode
#   4 - unused
#   5 - X11
#   6 - reboot (Do NOT set initdefault to this)
# 
id:5:initdefault:

# System initialization.
si::sysinit:/etc/rc.d/rc.sysinit

l0:0:wait:/etc/rc.d/rc 0
l1:1:wait:/etc/rc.d/rc 1
l2:2:wait:/etc/rc.d/rc 2
l3:3:wait:/etc/rc.d/rc 3
l4:4:wait:/etc/rc.d/rc 4
l5:5:wait:/etc/rc.d/rc 5
l6:6:wait:/etc/rc.d/rc 6

# Trap CTRL-ALT-DELETE
ca::ctrlaltdel:/sbin/shutdown -t3 -r now

# When our UPS tells us power has failed, assume we have a few minutes
# of power left.  Schedule a shutdown for 2 minutes from now.
# This does, of course, assume you have powerd installed and your
# UPS connected and working correctly.  
pf::powerfail:/sbin/shutdown -f -h +2 "Power Failure; System Shutting Down"

# If power was restored before the shutdown kicked in, cancel it.
pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled"


# Run gettys in standard runlevels
1:2345:respawn:/sbin/mingetty tty1
2:2345:respawn:/sbin/mingetty tty2
3:2345:respawn:/sbin/mingetty tty3
4:2345:respawn:/sbin/mingetty tty4
5:2345:respawn:/sbin/mingetty tty5
6:2345:respawn:/sbin/mingetty tty6

# Run xdm in runlevel 5
x:5:respawn:/etc/X11/prefdm -nodaemon
-----------------------分-----割-----线-----------------------
[root@localhost init]# cat tty.conf 
# tty - getty
#
# This service maintains a getty on the specified device.
#
# Do not edit this file directly. If you want to change the behaviour,
# please create a file tty.override and put your changes there.

stop on runlevel [S016]

respawn
instance $TTY
exec /sbin/mingetty $TTY
usage 'tty TTY=/dev/ttyX  - where X is console id'

默认运行级别:
根据系统的设定来启动系统要进入的运行级别,默认的运行级别有7种,可以用runlevel 命令查看当前的运行级别,init #命令可以切换当前的运行级别,默认运行级别不能设置成0和6级别中的任何一个级别,这7种运行级别分别代表如下:

1. 0:关闭所有服务,关机操作
2. 1:维护模式,单用户模式,仅root用户可以登录且不用认证
3. 2:维护模式,多用户模式,需要认证,会开启网络但是没有NFS
4. 3:正常的文本界面多用户模式
5. 4:预留模式
6. 5:正常的图形界面多用户模式
7. 6:关闭所有服务,重启系统
[root@localhost ~]# runlevel 
N 5    # N:表示系统启动时就进入5级别   5:目前系统的运行级别
[root@localhost ~]# init 3
[root@localhost ~]# runlevel 
5 3   #由5级别切换到3级别运行

系统初始化:
系统初始化运行的脚本在/etc/rc.d/rc.sysinit配置文件中,主要进行如下的操作:
(1) 设置主机名
(2) 设置欢迎信息
(3) 激活udev和selinux
(4) 挂载/etc/fstab文件中定义的所有文件系统;
(5) 检测根文件系统,并以读写方式重新挂载根文件系统
(6) 设置系统时钟;
(7) 根据/etc/sysctl.conf文件来设置内核参数
(8) 激活lvm及软raid设备
(9) 激活swap设备
(10) 加载额外设备的驱动程序
(11) 清理操作

[root@localhost init]# less /etc/rc.d/rc.sysinit
#!/bin/bash
#
# /etc/rc.d/rc.sysinit - run once at boot time
#
# Taken in part from Miquel van Smoorenburg's bcheckrc.
#

HOSTNAME=$(/bin/hostname)

set -m

if [ -f /etc/sysconfig/network ]; then
    . /etc/sysconfig/network
fi
if [ -z "$HOSTNAME" -o "$HOSTNAME" = "(none)" ]; then
    HOSTNAME=localhost
fi

if [ ! -e /proc/mounts ]; then
        mount -n -t proc /proc /proc
        mount -n -t sysfs /sys /sys >/dev/null 2>&1
fi
if [ ! -d /proc/bus/usb ]; then
......
/etc/rc.d/rc.sysinit 

重启对应级别下的服务:
重启服务意味着去启动或关闭/etc/rc.d/rc#.d/目录下的服务脚本所控制的服务;
K:要停止的服务;K##,优先级,数字越小,越是优先关闭;依赖其他服务的服务先关闭,而后关闭被依赖的;
S:要启动的服务;S##,优先级,数字越小,越是优先启动;被其他服务依赖的服务先启动,而依赖的服务后启动;
同一个服务的K脚本数值小时,S的脚本数值就应该比K的数值大,相反的,如果S数值小,则K的数值要比S的数值要大.

chkconfig命令:管控/etc/init.d/每个服务脚本在各级别下的启动或关闭状态

chkconfig  --list   [name] :查看该服务在各级别下的开启或关闭状态
                                    
chkconfig  --add  name: 添加该服务在各级别下的开启或关闭状态
                                    
      能被添加的服务的脚本定义格式之一:
                  #!/bin/bash
                  #
                  # chkconfig: LLL  NN NN
                  # description:  

chkconfig  --del  name: 删除指定服务在各级别下的开启或关闭状态

注意:不便或不需写为服务脚本的程序期望能开机自动运行时直接放置/etc/rc.d/rc.local (/etc/rc.local)脚本文件中.最后启动的一个服务S99local会链接至了/etc/rc.d/rc.local (/etc/rc.local)脚本并启动.

在3级别下的服务有;
[root@localhost init]# ls /etc/rc.d/rc3.d/
K01smartd            K50snmptrapd         K99rngd              S15mdmonitor         S28autofs
K02oddjobd           K60nfs               S01sysstat           S20kdump             S50bluetooth
K05wdaemon           K69rpcsvcgssd        S02lvm2-monitor      S22messagebus        S55sshd
K10psacct            K73winbind           S08ip6tables         S23NetworkManager    S58ntpd
K10saslauthd         K75ntpdate           S08iptables          S24nfslock           S80postfix
K15htcacheclean      K75quota_nld         S10network           S24rpcgssd           S82abrt-ccpp
K15httpd             K76ypbind            S11auditd            S25blk-availability  S82abrtd
K15svnserve          K84wpa_supplicant    S11portreserve       S25cups              S90crond
K30spice-vdagentd    K87restorecond       S12rsyslog           S25netfs             S95atd
K50dnsmasq           K88sssd              S13cpuspeed          S26acpid             S99certmonger
K50netconsole        K89rdisc             S13irqbalance        S26haldaemon         S99local
K50snmpd             K95firstboot         S13rpcbind           S26udev-post   

启动终端:
最后mingetty会调用login程序

1:2345:respawn:/sbin/mingetty tty1
2:2345:respawn:/sbin/mingetty tty2
3:2345:respawn:/sbin/mingetty tty3
4:2345:respawn:/sbin/mingetty tty4
5:2345:respawn:/sbin/mingetty tty5
6:2345:respawn:/sbin/mingetty tty6                

简述grub启动引导程序配置及命令行接口详解

grub是目前使用最广泛linux启动管理程序,其配置文件为:/boot/grub/grub.conf

[root@localhost ~]# cat /boot/grub/grub.conf 
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,0)
#          kernel /vmlinuz-version ro root=/dev/mapper/VolGroup-lv_root
#          initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.32-431.el6.x86_64)
    root (hd0,0)  #代表第一块磁盘的第一块分区
    kernel /vmlinuz-2.6.32-431.el6.x86_64 ro root=/dev/mapper/VolGroup-lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD rd_LVM_LV=VolGroup/lv_swap SYSFONT=latarcyrheb-sun16 crashkernel=128M rd_LVM_LV=VolGroup/lv_root  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
    initrd /initramfs-2.6.32-431.el6.x86_64.img

各个选项的意义:
default=#: 设定默认启动的菜单项;落单项(title)编号从0开始
timeout=#:指定菜单项等待选项选择的时长
splashimage=(hd#,#)/PATH/TO/XPM_PIC_FILE:指明菜单背景图片文件路径
hiddenmenu:隐藏菜单
title TITLE:定义菜单项“标题”, 可定义多个
root (hd#,#):grub查找stage2及kernel文件所在设备分区;为grub的“根目录”;
kernel /PATH/TO/VMLINUZ_FILE [PARAMETERS]:启动的内核的路径
initrd /PATH/TO/INITRAMFS_FILE: 内核匹配的ramfs虚拟文件系统
password [--md5] STRING: 启动选定的内核或操作系统时进行认

GRUB的界面支持命令行接口,在界面中输入e,b,c等命令可以进入对应的命令编辑,在对应的"title"中输入c进入命令行模式


linux启动流程,grub和kickstart文件安装系统详解_第2张图片
GRUB界面.png

linux启动流程,grub和kickstart文件安装系统详解_第3张图片
GRUB的命令行模式.png

linux启动流程,grub和kickstart文件安装系统详解_第4张图片
GRUB的帮助信息.png

为了防止他人随意进入GRUB对系统造成破坏(修改root密码...)可以在GRUB的配置文件中加入密码来防止他人随意进入,

  1. 使用grub-md5-crypt命令来生成加密的密码
[root@localhost ~]# grub-md5-crypt 
Password: 
Retype password: 
$1$1Ot7n/$LJq4/Fgtfte.qmaPN45qW/
[root@localhost ~]# 

  1. 在配置文件中一个或某一个title上添加password --md5 *****格式的密码保护编辑模式
[root@localhost ~]# vim /boot/grub/grub.conf 

# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,0)
#          kernel /vmlinuz-version ro root=/dev/mapper/VolGroup-lv_root
#          initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
password --md5 $1$1Ot7n/$LJq4/Fgtfte.qmaPN45qW/     #这里加入了之前加密过的密码!!!!
title CentOS (2.6.32-431.el6.x86_64)
        root (hd0,0)
        kernel /vmlinuz-2.6.32-431.el6.x86_64 ro root=/dev/mapper/VolGroup-lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD rd_LVM_LV=VolGroup/lv_swap SYSFONT=latarcyrheb-sun16 crashkernel=128M rd_LVM_LV=VolGroup/lv_root  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
        initrd /initramfs-2.6.32-431.el6.x86_64.img

linux启动流程,grub和kickstart文件安装系统详解_第5张图片
输入密码进入编辑模式.png

输入密码后按c可以进入编辑模式,在编辑模式下可以进行find来查看GRUB第一和第二阶段所有的硬盘位置,具体的命令可以通过help来获取帮助:


linux启动流程,grub和kickstart文件安装系统详解_第6张图片
GRUB编辑模式的命令.png

实现kickstart文件制作与光盘镜像制作

定制kickstart文件:

kickstart默认在GUI模式下运行,要先安装kickstart才能使用.

        # yum install  system-config-kickstart
        # system-config-kickstart
linux启动流程,grub和kickstart文件安装系统详解_第7张图片
kickstart配置.png

kickstart文件的格式:

kickstart配置文件由命令段,程序包段,脚本段等一个分段内容组成

命令段:指定各种安装前配置选项,如键盘类型等,分为必备命令可选命令

必备命令:

        authconfig:为系统认证方式配置,格式如下:
                authconfig  --enableshadow  --passalgo=sha512 
        bootloader:定义bootloader的安装位置及相关配置,格式如下:
                bootloader  --location=mbr  --driveorder=sda  --append="crashkernel=auto rhgb quiet"
        keyboard:设置键盘类型
                keyboard us  定义美式键盘
        lang:语言类型
               lang  zh_CN.UTF-8   #utf-8的中文编码格式
        part:分区布局
               part  /boot  --fstype=ext4  --size=500  #给/boot目录分区大小500MB,类型为ext4
               part  pv.008002  --size=51200   #pv.后面的数字是pv的id号
        clearpart:清除分区
              clearpart  --none  --drives=sda:清空磁盘分区;
        volgroup:创建卷组
              volgroup  myvg  --pesize=4096  pv.008002 #创建一个大小4G,名为myvg的逻辑卷组
        logvol:创建逻辑卷
              logvol  /home  --fstype=ext4  --name=lv_home  --vgname=myvg  --size=5120
        rootpw:管理员密码,后面的密码字符串是经过加密处理的.
              rootpw   --iscrypted  $6$4Yh15kMGDWOPtbbW$SGax4DsZwDAz4201.O97WvaqVJfHcISsSQEokZH054juNnoBmO/rmmA7H8ZsD08.fM.Z3Br/67Uffod1ZbE0s.

           openssl  passwd  -1  -salt \`openssl rand -hex 4\` 这个命令去加密密码,方法如下
[root@localhost ~]# openssl passwd -1 -salt `openssl rand -hex 4`
Password:            #输入想要加密的密码
$1$92a7684b$fGvel6cJRHtD81P29G5gn0
       timezone:时区
             timezone  Asia/Shanghai  亚洲上海的时区   

可选命令:

    install  OR  upgrade:  定义安装或升级
    text:  安装界面类型,text为tui,默认为GUI
    network: 配置网络接口
         network  --onboot yes  --device eth0  --bootproto dhcp  --noipv6  #网络配置的格式和参数
    firewall:  防火墙是否开启
    selinux: SELinux的开启状态
    halt、poweroff或reboot: 定义安装完成之后的行为
    repo: 指明安装时使用的repository
    url:  以url格式指明安装时使用的repository          

程序包段:指明要安装程序包,以及包组,也包括不安装(用'#'注释掉)的程序包

 %packages    包安装开始标识符
 @group_name  包要安装的包组
 package      要安装的单个包
 -package     不需要安装的包
 %end         包安装结束标识符

脚本段:指明要运行的脚本,分为linux安装前的脚本和安装后脚本

 %pre:安装前脚本,运行在安装介质上的微型Linux系统环境之中
 %post:安装linux完成后重启之前运行的脚本,运行在安装完成的系统上

ks:指明kickstart文件的位置,主要有以下几种格式,其中http,ftp和https三种形式引导kickstart时要保证系统能连接网络

  ks=
    DVD drive: ks=cdrom:/PATH/TO/KICKSTART_FILE
    Hard Drive: ks=hd:/DEVICE/PATH/TO/KICKSTART_FILE
    HTTP Server: ks=http://HOST[:PORT]/PATH/TO/KICKSTART_FILE  #端口可以省略
    FTP Server:  ks=ftp://HOST[:PORT]/PATH/TO/KICKSTART_FILE
    HTTPS Server:   ks=https://HOST[:PORT]/PATH/TO/KICKSTART_FILE

如下是系统安装完成之后在/root目录下根据用户选择生成的kickstart的配置文件信息.

[root@localhost ~]# cat anaconda-ks.cfg 
# Kickstart file automatically generated by anaconda.

#version=DEVEL
install
cdrom
lang en_US.UTF-8
keyboard us
network --onboot no --device eth0 --bootproto dhcp --noipv6
rootpw  --iscrypted $6$wQ/sbWZ/qkI7G2Sc$OjPFBPRsijsikiTdTJKIhVGyO7J2gx5iliQdPFc.xtXSzdLmeIs2xbdHovDDOXDpJxcCq2/RzRC8yzFFKoWak1
firewall --service=ssh
authconfig --enableshadow --passalgo=sha512
selinux --enforcing
timezone --utc Asia/Hong_Kong
bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"
# The following is the partition information you requested
# Note that any partitions you deleted are not expressed
# here so unless you clear all partitions first, this is
# not guaranteed to work
#clearpart --none --drives=sda
#volgroup VolGroup --pesize=4096 pv.008002
#logvol / --fstype=ext4 --name=lv_root --vgname=VolGroup --grow --size=1024 --maxsize=51200
#logvol swap --name=lv_swap --vgname=VolGroup --grow --size=2048 --maxsize=2048

#part /boot --fstype=ext4 --size=500
#part pv.008002 --grow --size=1


repo --name="CentOS"  --baseurl=cdrom:sr0 --cost=100

%packages
@base
@core
@debugging
@basic-desktop
@desktop-debugging
@desktop-platform
@directory-client
@fonts
@general-desktop
@graphical-admin-tools
@input-methods
@internet-applications
@internet-browser
@java-platform
@legacy-x
@network-file-system-client
@office-suite
@print-client
@remote-desktop-clients
@server-platform
@server-policy
@workstation-policy
@x11
mtools
pax
oddjob
wodim
sgpio
genisoimage
device-mapper-persistent-data
abrt-gui
samba-winbind
certmonger
pam_krb5
krb5-workstation
libXmu

对于修改的kickstart配置文件如果有语法错误可以使用检查语法错误命令: ksvalidator

[root@localhost ~]# ksvalidator anaconda-ks.cfg  #没有提示错误证明语法正确

引导光盘镜像制作及kickstart文件安装系统

1. 创建目录并复制isolinux目录:
引导光盘仅需要isolinux就够了,并把配置好的kickstart文件复制创建目录中.

[root@localhost ~]# cp -r /media/yum.repo/isolinux /tmp/myiso/    #将整个isolinux目录复制过来
[root@localhost ~]# tree /tmp/myiso/
/tmp/myiso/
└── isolinux
    ├── boot.cat
    ├── boot.msg
    ├── grub.conf
    ├── initrd.img
    ├── isolinux.bin
    ├── isolinux.cfg
    ├── memtest
    ├── splash.jpg
    ├── TRANS.TBL
    ├── vesamenu.c32
    └── vmlinuz
---------------------------分割线---------------------------
[root@localhost isolinux]# ls
boot.cat  grub.conf   isolinux.bin  ks.cfg   splash.jpg  vesamenu.c32
boot.msg  initrd.img  isolinux.cfg  memtest  TRANS.TBL   vmlinuz

2. 创建iso文件系统
使用mkisofs命令来创建,格式如下:
mkisofs -R -J -T -v --no-emul-boot --boot-load-size 4 --boot-info-table -V "CentOS 6 x86_64 boot" -c isolinux/boot.cat -b isolinux/isolinux.bin -o /root/boot.iso myiso/

[root@localhost tmp]# mkisofs -R -J -T -v --no-emul-boot --boot-load-size 4 --boot-info-table -V "CentOS 6 x86_64 boot" -c isolinux/boot.cat -b isolinux/isolinux.bin -o  /root/boot.iso   myiso/
I: -input-charset not specified, using utf-8 (detected in locale settings)
genisoimage 1.1.9 (Linux)
Scanning myiso/
Scanning myiso/isolinux
Excluded: myiso/isolinux/TRANS.TBL
Excluded by match: myiso/isolinux/boot.cat
Writing:   Initial Padblock                        Start Block 0
Done with: Initial Padblock                        Block(s)    16
Writing:   Primary Volume Descriptor               Start Block 16
Done with: Primary Volume Descriptor               Block(s)    1
Writing:   Eltorito Volume Descriptor              Start Block 17
Size of boot image is 4 sectors -> No emulation
Done with: Eltorito Volume Descriptor              Block(s)    1
Writing:   Joliet Volume Descriptor                Start Block 18
Done with: Joliet Volume Descriptor                Block(s)    1
Writing:   End Volume Descriptor                   Start Block 19
Done with: End Volume Descriptor                   Block(s)    1
Writing:   Version block                           Start Block 20
Done with: Version block                           Block(s)    1
Writing:   Path table                              Start Block 21
Done with: Path table                              Block(s)    4
Writing:   Joliet path table                       Start Block 25
Done with: Joliet path table                       Block(s)    4
Writing:   Directory tree                          Start Block 29
Done with: Directory tree                          Block(s)    2
Writing:   Joliet directory tree                   Start Block 31
Done with: Joliet directory tree                   Block(s)    2
Writing:   Directory tree cleanup                  Start Block 33
Done with: Directory tree cleanup                  Block(s)    0
Writing:   Extension record                        Start Block 33
Done with: Extension record                        Block(s)    1
Writing:   The File(s)                             Start Block 34
 26.70% done, estimate finish Fri Mar 30 20:28:21 2018
 53.31% done, estimate finish Fri Mar 30 20:28:21 2018
 80.01% done, estimate finish Fri Mar 30 20:28:22 2018
Total translation table size: 4701
Total rockridge attributes bytes: 1438
Total directory bytes: 2534
Path table size(bytes): 26
Done with: The File(s)                             Block(s)    18577
Writing:   Ending Padblock                         Start Block 18611
Done with: Ending Padblock                         Block(s)    150
Max brk space used 0
18761 extents written (36 MB)

---------------------------分割线---------------------------

[root@localhost tmp]# ls /root/
anaconda-ks.cfg  Desktop    Downloads    install.log.syslog  Pictures  Templates
boot.iso         Documents  install.log  Music               Public    Videos

3. 使用ftp工具将boot.iso传到真实机上

linux启动流程,grub和kickstart文件安装系统详解_第8张图片
ftp发送到真实机.png

4. 虚拟机配置并启动
光盘路径要选择boot.iso这个包所在的位置.

linux启动流程,grub和kickstart文件安装系统详解_第9张图片
kickstart虚拟机启动配置.png

5. 开机启动并配置kickstart文件

linux启动流程,grub和kickstart文件安装系统详解_第10张图片
启动界面.png

在这个界面下安esc键进入boot
linux启动流程,grub和kickstart文件安装系统详解_第11张图片
输入ks.cfg存放的路径.png

敲入命令即可进入自动引导安装了.

注意:如果是纯本地kickstart自动安装,就要把整个镜像复制过去而不只是isolinux目录,然后复制ks.cfg到同一目录中重新制作一个新的iso镜像,如果只是制作本地自动引导的iso,则在ks.cfg的程序安装包选择路径中要选择好网络yum源.或ftp服务器上的镜像,本文只是提供思路,本地的iso没有完全复制过来,ks.cfg配置文件里也没有制定安装系统的网络镜像包.

你可能感兴趣的:(linux启动流程,grub和kickstart文件安装系统详解)