首先看一下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
|
十二、重啓系統,恢復正常算法