首先看一下linux内核重要文件grub.conflinux
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# 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/sda2
# initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=0
#若是有多个菜单,默认选择的菜单为0
timeout=5
#菜单选项栏等待5s
splashimage=(hd0,0)
/grub/splash
.xpm.gz
#/dev/sda1即/boot下开机启动图片
hiddenmenu
#影藏菜单
title CentOS 6 (2.6.32-696.el6.x86_64)
#标题为CentOS 6 (2.6.32-696.el6.x86_64),此标题不能没有
root (hd0,0)
#第一块磁盘,第1个分区,指的是/boot
kernel
/vmlinuz-2
.6.32-696.el6.x86_64 ro root=UUID=9ca5bdac-ce61-410e-a9fb-19a7877163cc rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSF ONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
# kernel相对于/boot的路径,此处根值/boot,kenrl后面跟有系统启动相关参数 rhgb 图形化工具(转圈圈),删除rhgb直接到正常启动界面 quiet默认隐藏内核的启动过程
initrd
/initramfs-2
.6.32-696.el6.x86_64.img
title CentOS 6 (2.6.32-696.el6.x86_64)
#标题为CentOS 6 (2.6.32-696.el6.x86_64),此标题不能没有
kernel (hd0,0)
/vmlinuz-2
.6.32-696.el6.x86_64 ro root=UUID=9ca5bdac-ce61-410e-a9fb-19a7877163cc rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSF ONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
# 没有定义根,后面不能调用只能在前面添加(hd0,0)
initrd (hd0,0)
/initramfs-2
.6.32-696.el6.x86_64.img
|
1
|
[root@Centos6 ~]
# dd if=/dev/zero of=/dev/sda bs=1 count=4426
|
此时会发现菜单都看不到
1
|
sh-4.1
# grub
|
1
|
grub>root (hd0,0)
#表示boot在第一块磁盘第1个分区
|
1
2
3
|
title CentOS 6 (2.6.32-696.el6.x86_64)
#标题为CentOS 6 (2.6.32-696.el6.x86_64),此标题不能没有
kernel vmlinuz-2.6.32-696.el6.x86_64 ro root=UUID=9ca5bdac-ce61-410e-a9fb-19a7877163cc rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSF ONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
# 没有定义根,后面不能调用只能在前面添加(hd0,0)
initrd initramfs-2.6.32-696.el6.x86_64.img
|
1
2
3
4
|
#此时只能进入救援模式切根修改文件
title CentOS 6 (2.6.32-696.el6.x86_64)
#标题为CentOS 6 (2.6.32-696.el6.x86_64),此标题不能没有
kernel
/vmlinuz-2
.6.32-696.el6.x86_64 ro root=UUID=9ca5bdac-ce61-410e-a9fb-19a7877163cc rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSF ONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
# 没有定义根,后面不能调用只能在前面添加(hd0,0)
initrd
/initramfs-2
.6.32-696.el6.x86_64.img
|
1
2
3
|
title CentOS 6 (2.6.32-696.el6.x86_64)
kernel
/vmlinuz-2
.6.32-696.el6.x86_64 ro root=UUID=9ca5bdac-ce61-410e-a9fb-19a7877163cc rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSF ONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
initrd
/initramfs-2
.6.32-696.el6.x86_64.img
|
1
2
3
|
title CentOS 6 (2.6.32-696.el6.x86_64)
initrd
/initramfs-2
.6.32-696.el6.x86_64.img
kernel
/vmlinuz-2
.6.32-696.el6.x86_64 ro root=UUID=9ca5bdac-ce61-410e-a9fb-19a7877163cc rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSF ONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
|
1
|
password zangfans
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# 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/sda2
# initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)
/grub/splash
.xpm.gz
password centos6
#编辑菜单项输入密码
hiddenmenu
title CentOS 6 (2.6.32-696.el6.x86_64)
root (hd0,0)
kernel
/vmlinuz-2
.6.32-696.el6.x86_64 ro root=UUID=9ca5bdac-ce61-410e-a9fb-19a7877163cc rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSF ONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
initrd
/initramfs-2
.6.32-696.el6.x86_64.img
title CentOS 6 (2.6.32-696.el6.x86_64)
kernel (hd0,0)
/vmlinuz-2
.6.32-696.el6.x86_64 ro root=UUID=9ca5bdac-ce61-410e-a9fb-19a7877163cc rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSF ONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
#
initrd (hd0,0)
/initramfs-2
.6.32-696.el6.x86_64.img
password centos6
#启动输入密码
|
1
2
3
4
|
[root@Centos6 ~]
# grub-md5-crypt
Password:
Retype password:
$1$Z.gAn/$Xd647hXfPj
/sJ
.i8A0By8.
|
1
|
password --md5 $1$V1hAn/$hSLRXWfIZWwVtYz4th5rg1
|
1
2
3
4
|
[root@Centos6 ~]
# grub-crypt
Password:
Retype password:
$6$jkKAT.eUrv3d4bfM$f41lkKlqQk3fAPqNwgy93J6Wi6bVF.zB5b.24V1QPwAGXkVVmwk2MGdi1UxzStHBaPWarW20AppaOvwheNRRj.
|
1
|
password --encrypted $6$ndPVD
/LnVhjBwHaG
$XlSiTmJfRJrWufrmH0tLzle
/zlmCB
.Zyi
/WClkcL8G43NDpXlKuQPvsw4AiIJqT1fJrb2Kh8DgZLY68pIAKFI0
|
1
2
3
4
5
6
7
8
|
[root@Centos6 ~]
# which convert
/usr/bin/convert
[root@Centos6 ~]
# rpm -qf `which convert`
ImageMagick-6.7.2.7-6.el6.x86_64
[root@Centos6 ~]
# convert -resize 640x480 -colors 14 zf.jpg zf.xpm #此命令必须在zf.jpg位置使用,使用less zf.xpm能够在头部看到相关信息
[root@Centos6 ~]
# cp zf.xpm /boot/grub
[root@Centos6 grub]
# vim grub.conf
splashimage=(hd0,0)
/grub/zf
.xpm
|
1
2
|
[root@Centos6 ~]
# cat /proc/cmdline
ro root=UUID=9ca5bdac-ce61-410e-a9fb-19a7877163cc rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
|
1
|
[root@Centos6 ~]
# rm -rf /boot/grub
|
1
2
3
4
5
6
|
#必须写三项分别是title kernel initrd
default 0
timeout 3
title Centos6
kernel
/vmlinuz-2
.6.32-696.el6.x86_64 ro root=
/dev/sda2
#方便的小技巧,防止手敲出错
initrd
/initramfs-2
.6.32-696.el6.x86_64.img
|
1
2
3
4
5
6
7
8
|
[root@Centos6 ~]
# ls /boot
config-2.6.32-696.el6.x86_64 initramfs-2.6.32-696.el6.x86_64.img System.map-2.6.32-696.el6.x86_64
efi lost+found vmlinuz-2.6.32-696.el6.x86_64
grub symvers-2.6.32-696.el6.x86_64.gz
[root@Centos6 ~]
# rm -rf /boot
rm
: cannot remove `
/boot
': Device or resource busy
[root@Centos6 ~]
# ls /boot
[root@Centos6 ~]
#
|
1
|
[root@Centos6 ~]
# mv /sbin/init ~/
|
1
2
|
bash
-4.1
# rpm -qf /sbin/init
#upstart包提供
|
1
|
bash
-4.1
# mount -o remount,rw /
|
1
2
3
|
#默认光盘已经挂载在/mnt
bash
-4.1
# cd /mnt
bash
-4.1
# rpm -ivh /Packages/upstart-xxxxxx --force
|
1
|
bash
-4.1
# sync
|
1
2
|
[root@Centos6-LVM ~]
# mv /etc/fstab /root
[root@Centos6-LVM ~]
# rm -rf /boot/*
|
1
2
3
4
5
6
|
#必须写三项分别是title kernel initrd
default 0
timeout 3
title Centos6_lvm
kernel
/vmlinuz-2
.6.32-696.el6.x86_64 ro root=
/dev/vg_centos6lvm/LogVo100
selinux=0
initrd
/initramfs-2
.6.32-696.el6.x86_64.img
|
1
2
|
[root@Centos6 ~]
# rm -rf /etc/fstab
[root@Centos6 ~]
# rm -rf /boot
|
1
2
3
4
|
bash
-4.1
# mkdir /mnt/tmp #建立
bash
-4.1
# mount /sda1 /mnt/tmp #挂载到临时文件
bash
-4.1
# ls /mnt/tmp #查看里面的内容,此处能够看到没有任何文件能够判断为/boot
经过以上方法就能够知道每一个分区究竟是什么
|
1
2
3
4
5
6
|
#必须写三项分别是title kernel initrd
default 0
timeout 3
title Centos6
kernel
/vmlinuz-2
.6.32-696.el6.x86_64 ro root=
/dev/sda2
initrd
/initramfs-2
.6.32-696.el6.x86_64.img
|
十二、重启系统,恢复正常算法