# cat /etc/passwd | egrep -v 'shutdown$|halt$|nologin$|false$|sync$'
[步骤] 在不能进系统的情况下 GRUB 开机菜单的显示 (进入安全模式或者恢复模式) (Ubuntu 版)
正文:
步骤一:取消 GRUB 开机菜单的显示
1.1 修改 /etc/default/grub 配置文件
# vim /etc/default/grub
添加以下内容:
......
GRUB_TIMEOUT_STYLE=hidden
......
添加后的案例:
......
GRUB_DEFAULT=0
GRUB_TIMEOUT_STYLE=hidden
GRUB_TIMEOUT=0
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT=""
GRUB_CMDLINE_LINUX=" "
......
1.2 让刚刚设置的参数生效
# update-grub
步骤二:在不能进系统的情况下显示 GRUB 开机菜单
2.1 进入 GRUB 命令行
重启系统后按下 “E” 键不放
2.2 进入 GRUB 命令行以后以正常模式启动系统
grub> normal
2.3 启动后 GRUB 开机菜单就会显示了
(步骤略)
(注意:有时候要重复步骤 2.1 和 2.2 才能显示 GRUB 开机菜单)
2.4 在拯救模式下进入 root 模式
此时选择以下选项并按下 “回车” 键,就可以通过拯救模式进入 root 模式了
root Drop to root shell prompt
参考文献:
https://askubuntu.com/questions/381613/how-to-return-from-grub-prompt-to-the-grub-menu
https://blog.csdn.net/geekqian/article/details/82912518
Several situations of Linux automatically reboot without reboot logs in the /var/log/messages
Situation One
This Linux server is a virtual server. If we reboot it though its virtual software, there is no relevant logs in the /var/log/messages.
Situation Two
This Linux server is a member of a pacemaker cluster. If the pacemaker cluster software fences this server for protecting the whole cluster, there is no relate logs in the /var/log/messages.
Situation Three
This Linux server has critical problems in its system or hardware. Core panic of Linux and hardware problem both can reboot the system automatically without any reboot logs in the /var/log/messages.
[步骤] Linux 关机前执行脚本
步骤一:创建要被管理的脚本
# vim /root/12456.sh
创建以下内容:
#!/bin/bash
for i in {1..5}
do
echo $i
done
(补充:这里以创建 /etc/root/for.sh 脚本为例)
步骤二:创建 systemctl 的管理文件
# vim /etc/systemd/system/12456.service
创建以下内容:
[Unit]
Description=12345
After=getty@tty1.service display-manager.service plymouth-start.service
Before=systemd-poweroff.service systemd-halt.service
DefaultDependencies=no
[Service]
ExecStart=/root/12456.sh
Type=forking
[Install]
WantedBy=poweroff.target
WantedBy=reboot.target
WantedBy=halt.target
(补充:这里以创建 /etc/systemd/system/12456.service 来管理 ExecStart=/root/12456.sh 为例)
步骤三:加载刚刚创建的 systemctl 管理文件
# systemctl daemon-reload
步骤四:给 systemctl 的管理文件添加执行权限
# chmod u+x /etc/systemd/system/12456.service
步骤五:设置关机前执行脚本
5.1 设置关闭系统前执行此脚本
# ln -s /usr/lib/systemd/system/12456.service /usr/lib/systemd/system/halt.target.wants/
5.2 设置关闭电源前执行此脚本
# ln -s /usr/lib/systemd/system/12456.service /usr/lib/systemd/system/poweroff.target.wants/
5.3 设置重启先执行此脚本
# ln -s /usr/lib/systemd/system/12456.service /usr/lib/systemd/system/reboot.target.wants/
[内容] Linux 查看 auditd 日志的案例
案例一:查看文件创建记录
# /usr/sbin/ausearch --start $(date +\%m/\%d/\%Y -d "-1 month") -i --input-logs | egrep "/test/test.txt.*nametype=CREATE" | awk '{print $2,$3,$6}'
(补充:这里以查看 /test/test.txt 文件有没有被创建为例)
案例二:查看文件删除记录
# /usr/sbin/ausearch --start $(date +\%m/\%d/\%Y -d "-1 month") -i --input-logs | egrep "/test/test.txt.*nametype=DELETE" | awk '{print $2,$3,$6}'
(补充:这里以查看 /test/test.txt 文件有没有被删除为例)
案例三:查看文件有没有存在过
# /usr/sbin/ausearch --start $(date +\%m/\%d/\%Y -d "-1 month") -i --input-logs | egrep "/test/test.txt.*nametype=" | awk '{print $2,$3,$6}' | uniq
(补充:这里以查看 /test/test.txt 文件有没有存在过为例)