RHCSA:引导过程

GRUB2(GRand Unified BootLoader version 2):统一引导加载程序2

BIOS/UEFI指向启动设备,如果启动设备是硬盘,则硬盘的MBR/GPT指向GRUB2

GRUB2选择一个启动选项,则加载对应的Linux的内核和RAM文件系统。内核启动systemd进程,systemd进程初始化系统,为initrd.target激活相关系统服务,将根文件系统挂载到/sysroot下,systemd在新的根下重新启动自己,再激活默认目标下的所有单元。

systemd是在引导时第一个启动的进程。它负责激活所有服务。

/var/log/dmesg文件或者dmesg命令可以查看引导内容。

传统硬盘用MBR分区,现代硬盘用GPT

在GRUB菜单中,E进入临时编辑模式,C进入grub命令行


引导到不同目标:

按E进入编辑模式,找到类似如下行:

linux /vmlinuz-3******.x86_64 root=/dev/mapper******* 。。。。。。rhgb quiet LANGE=。。。。。。。

删除:rhgb quiet ,改为systemd.unit=multi-user.target    或者:graphical.target rescue.target emergency.target

可以进入不同的启动目标,需要口令

如果直接在这行末尾加rd.break 或者 init=/sysroot/bin/sh,以只读方式挂载root文件系统,不需要口令。这是重置root密码的常用方法。

恢复root口令:

按E键-》添加rd.break-》ctrl+x

以读写方式重新挂载/sysroot,并将根目录改为/sysroot

mount -o remount,rw /sysroot

chroot /sysroot

修改口令:passwd root

此时SELinux没有启动,不会存入/etc/passwd,因此:

touch /.autorelabel   通知系统引导时重新赋予标签

exit 关闭chroot

exit 重新引导


修改引导程序:

配置文件:

BIOS管理的:/etc/grub2.cfg 指向/boot/grub2/grub.cfg

UEFI管理的:指向/boot/efi/EFI/redhat/grub.cfg

一般不直接修改这个配置文件,使用grub2-mkconfig命令,基于/etc/defalt/grub文件和/etc/grub.d目录生成新版本

grub2-mkconfig -o /boot/grub2/grub.cfg


GRUB命令行

grub>ls  列出所有硬盘分区,包括LVM

grub>ls (hd0,msdos1)/grub2/grub.cfg  找到grub配置文件位置

grub>cat  (hd0,msdos1)/grub2/grub.cfg  查看grub配置文件

也可以search.file /grub2/grub.cfg查找

加载LVM模块命令:

grub>insmod lvm

grub> cat (lvm/rhel-root)/etc/fstab 查看文件系统设备文件名


手动引导:都在grub>命令行下进行

insmod lvm

ls

cat (lvm/rhel-root)/etc/fstab

set root=(lvm/rhel-root)

linuxefi (boot所在分区)/vmlinuz。。。。。 root=/dev/mapper.........

initrd (boot所在分区)/initramfs..........img

boot


重装grub

rpm -qc grub-tools

rm -f /etc/default/grub

rm -f /etc/grub.d/*

yum reinstall grub2-tools

grub2-mkconfig -o /boot/grub2/grub.cfg


救援:启动U盘的rescue模式

进入continue选项

chroot /mnt/sysimage(把系统的顶层目录挂载到/)


目标、服务单元

systemctl list-units --type=service --all

systemctl list-units --type=target --all

查看runlevel运行级别:

ls -al /usr/lib/systemd/system/runlevel?.target

ls /lib/systemd/system/run*.target -al

RHCSA:引导过程_第1张图片

查看一个目标、单元的依赖:

systemctl list-dependencies graphical.target

不同目标之间的切换:

systemctl isolate graphical.target

其他:

systemctl poweroff

systemctl reboot


日志记录:

journalctl命令显示systemd日志

默认临时存储在RAM

持久存储:

mkdir /var/log/journal

chgrp systemd-journal /var/log/journal

chmod 2755   /var/log/journal

systemctl restart system-journald.service

有了持久日志,journalctl -b 0 指定特定的一次引导的日志

journalctl -p warning -p参数用来过滤


cgroups:

把进程分组到一起。

systemd使用cgroups可以杀死一组进程

systemd-cgls显示cgroups层次结构


systemd单元

systemd进程的配置文件在/etc/systemd/system(自定义) 和 /usr/lib/systemd/system(默认配置)

列出所有活动的systemd单元:systemctl list-units

列出单元启动时的状态:systemctl list-unit-files


时区配置:

timedatectl

timedatectl list-timezones

timedatectl set-timezone America/Los_Angles

使用chronyd同步时间:

配置文件/etc/chrony.conf

使用NTP时间同步

安装NTP

配置文件/etc/ntp.conf

systemctl start ntpd.service

systemctl enable ntpd.service

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(linux,linux)