17.6centos7开机启动顺序

centos7
    1、grub1阶段和1.5阶段是存放在磁盘上,以二进制形式存放,1.5阶段的xfs驱动加
    载/boot所在分区的文件xfs文件系统,此时可以进入/boot文件系统
    2、加载/boot/grub/grub2阶段,/boot/grub/grub.conf文件的内容,找到/boot/    vmlinuz,initramfs
        vmlinuz及其后的root开始挂载硬盘的根/即本虚拟机的/dev/sda2
        initramfs放的是/文件系统的驱动,加载/根文件系统的驱动
    3、另外,/boot的文件系统可能和/的文件系统不一样,不过此虚拟机的/boot和/都是xfs文件系统
 
  [root@centos7:~ ]# df -T
    Filesystem     Type     1K-blocks    Used Available Use% Mounted on
    /dev/sda2      xfs      208563716 4645320 203918396   3% /
    /dev/sda1      xfs        1038336  158004    880332  16% /boot

    [root@centos7:~ ]# locate xfs.ko
    /usr/lib/modules/3.10.0-862.el7.x86_64/kernel/fs/xfs/xfs.ko.xz
    [root@centos7:~ ]# ll -h /usr/lib/modules/3.10.0-862.el7.x86_64/kernel/fs/xfs/xfs.ko.xz
    -rw-r--r--. 1 root root 327K Apr 21 01:39 /usr/lib/modules/3.10.0-862.el7.x86_64/kernel/fs/xfs/xfs.ko.xz
系统加载阶段
    [root@centos7:/boot/grub2 ]# cat grub.cfg
    #
    # DO NOT EDIT THIS FILE
    #
    # It is automatically generated by grub2-mkconfig using templates
    # from /etc/grub.d and settings from /etc/default/grub
    #
        linux16 /vmlinuz-3.10.0-862.el7.x86_64 root=UUID=fbe53d4c-ab79-4207-a4a7-e370854f796e ro rhgb quiet LANG=en_US.UTF-8
        initrd16 /initramfs-3.10.0-862.el7.x86_64.img
    *******省略********


    [root@centos7:~ ]# which init
    /usr/sbin/init
    [root@centos7:~ ]# rpm -qf /usr/sbin/init
    systemd-219-57.el7.x86_64
    [root@centos7:~ ]# rpm -qi systemd
    Name        : systemd
    Version     : 219
    Release     : 57.el7
    Architecture: x86_64
    Install Date: Tue 15 May 2018 06:53:51 PM CST
    Group       : Unspecified
    Size        : 24389374
    License     : LGPLv2+ and MIT and GPLv2+
    Signature   : RSA/SHA256, Wed 25 Apr 2018 07:48:21 PM CST, Key ID 24c6a8a7f4a80eb5
    Source RPM  : systemd-219-57.el7.src.rpm
    Build Date  : Wed 11 Apr 2018 03:37:32 PM CST
    Build Host  : x86-01.bsys.centos.org
    Relocations : (not relocatable)
    Packager    : CentOS BuildSystem <http://bugs.centos.org>
    Vendor      : CentOS
    URL         : http://www.freedesktop.org/wiki/Software/systemd
    Summary     : A System and Service Manager
    Description :
    systemd is a system and service manager for Linux, compatible with
    SysV and LSB init scripts. systemd provides aggressive parallelization
    capabilities, uses socket and D-Bus activation for starting services,
    offers on-demand starting of daemons, keeps track of processes using
    Linux cgroups, supports snapshotting and restoring of the system
    state, maintains mount and automount points and implements an
    elaborate transactional dependency-based service control logic. It can
    work as a drop-in replacement for sysvinit.

    [root@centos7:~ ]# ll /sbin/init
    lrwxrwxrwx. 1 root root 22 May 15 18:53 /sbin/init -> ../lib/systemd/systemd
centos7开机启动顺序
            UEFi或BIOS初始化,运行POST开机自检
            选择启动设备
            引导装载程序, centos7是grub2
            加载装载程序的配置文件:/etc/grub.d/ /etc/default/grub  /boot/grub2/grub.cfg
            加载initramfs驱动模块
            加载内核选项
            内核初始化,centos7使用systemd代替init
            执行initrd.target所有单元,包括挂载/etc/fstab
            从initramfs根文件系统切换到磁盘根目录
            systemd执行默认target配置,配置文件/etc/systemd/system/default.target

            systemd执行sysinit.target初始化系统及basic.target准备操作系统
            systemd启动multi-user.target下的本机与服务器服务
            systemd执行multi-user.target下的/etc/rc.d/rc.local
            Systemd执行multi-user.target下的getty.target及登录服务
            systemd执行graphical需要的服务
 
设置内核参数
            设置内核参数,只影响当次启动
            启动时,在linux16行后添加systemd.unit=desired.target
            systemd.unit=emergency.target
            systemd.unit=rescue.target
            rescue.target 比emergency 支持更多的功能,例如日志等
            systemctl default 进入默认target

启动排错
            文件系统损坏
                先尝试自动修复,失败则进入emergency shell ,提示用户修复
            在/etc/fstab不存在对应的设备和UUID  
                等一段时间,如不可用,进入emergency shell
            在/etc/fstab不存在对应挂载点
                systemd 尝试创建挂载点,否则提示进入emergency shell.
            在/etc/fstab不正确的挂载选项
                提示进入emergency shell

破解CentOS7的root口令方法一
            启动时任意键暂停启动
            按e键进入编辑模式
            将光标移动linux16开始的行,添加内核参数rd.break
            按ctrl-x启动
            mount –o remount,rw /sysroot
            chroot /sysroot
            passwd root
            touch /.autorelabel    #selinux标签
            exit
            reboot

破解CentOS7的root口令方法二
            启动时任意键暂停启动
            按e键进入编辑模式
            将光标移动linux16开始的行,改为rw init=/sysroot/bin/sh
            按ctrl-x启动
            chroot /sysroot
            passwd root
            touch /.autorelabel
            exit
            reboot

grub2-setpassword  生成/boot/grub2/user.cfg ,开机不显示菜单项

    修复GRUB2
            GRUB“the Grand Unified Bootloader”  
    引导提示时可以使用命令行界面  
    可从文件系统引导
            主要配置文件 /boot/grub2/grub.cfg
            修复配置文件
                grub2-mkconfig > /boot/grub2/grub.cfg
                grub2-mkconfig -o /boot/grub2/grub.cfg

            修复grub
                grub2-install /dev/sda BIOS环境   生成MBR446字节
                grub2-install UEFI环境
            调整默认启动内核
                vim /etc/default/grub
                GRUB_DEFAULT=0
                            grub2-mkconfig -o /boot/grub2/grub.cfg 生成文件,覆盖原来的文件

——————————————————————————————
删除/boot/*下的文件(centos7)
    chroot /sysroot/
    进入救援模式,挂载光盘,rpm -ivh /media/Packages/kernel-****.rpm
    grub2-install /dev/sda   #生成grub相关文件
    grub2 mkconfig -o grub.cfg        #生成grub.cfg配置文件
-------------
    centos7开机进入多用户,在linux16行后面加上
            systemd.unit=multi-user.target
--------------        
    grub2-setpassword  生成/boot/grub2/user.cfg ,开机不显示菜单项
---------------        
    grub> insmod xfs
    grub>    set root=(hd0,1)
    grub>    linux16 /vmlinuz-3.10***  root=/dev/sda2/ selinux=0
    grub>    initrd16 /initramfs-****tab键补齐
    重启,然后生成/boot/grub2/grub.cfg
        grub2-mkconfig -o /boot/grub2/grub.cfg
        其中网卡里面的配置项参考vim /etc/default/grub

猜你喜欢

转载自blog.csdn.net/csdn_immortal/article/details/80932594