Linux学习-grub配置

grub.conf配置说明
#设定默认启动的title编号,从0开始
default=0       
#等待用户选择的超时时间,单位:秒
timeout=5
#指定背景图片
splashimage=(hd0,0)/grub/splash.xpm.gz
#隐藏菜单
hiddenmenu
#编辑grub参数时需要输入密码
password --md5 $1$f5XgL1$hdFGd6LTtQEcVC/k46S8E/
# 引导内核的标题或操作系统标题,字符串,可自由修改
title CentOS 6 (2.6.32-754.el6.x86_64)
#内核文件所在的设备,grub识别硬件,对Grub而言,所有类型硬盘名称一律为hd:hd#,#表示第几个磁盘,后面的0表示对应磁盘的分区
	root (hd0,0)
	#指定kernel文件路径及传递给内核的参数
	kernel /vmlinuz-2.6.32-754.el6.x86_64 ro root=/dev/mapper/vg_lotus-lv_root rd_NO_LUKS rd_LVM_LV=vg_lotus/lv_root rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=vg_lotus/lv_swap  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM LANG=en_US.UTF-8 rhgb quiet
	#ramfs文件路径
	initrd /initramfs-2.6.32-754.el6.x86_64.img
	#启动内核时,需要输入密码
	password --md5 $1$f5XgL1$hdFGd6LTtQEcVC/k46S8E/
生成grub的md5密码
#生成grub的md5加密
[root@lotus ~]# grub-md5-crypt
Password: 
Retype password: 
$1$f5XgL1$hdFGd6LTtQEcVC/k46S8E/
破坏MBR,并修复
第一种修改grub
[root@lotus ~]# dd if=/dev/zero of=/dev/sda count=1 bs=400
1+0 records in
1+0 records out
400 bytes (400 B) copied, 0.00901449 s, 44.4 kB/s
[root@lotus ~]# sync
#修复grub,安装grub stage1
[root@lotus ~]# grub
Probing devices to guess BIOS drives. This may take a long time.

    GNU GRUB  version 0.97  (640K lower / 3072K upper memory)

 [ Minimal BASH-like line editing is supported.  For the first word, TAB
   lists possible command completions.  Anywhere else TAB lists the possible
   completions of a device/filename.]
grub> root (hd0,0)
root (hd0,0)
 Filesystem type is ext2fs, partition type 0x83
grub> setup (hd0,0)
setup (hd0,0)
 Checking if "/boot/grub/stage1" exists... no
 Checking if "/grub/stage1" exists... yes
 Checking if "/grub/stage2" exists... yes
 Checking if "/grub/e2fs_stage1_5" exists... yes
 Running "embed /grub/e2fs_stage1_5 (hd0,0)"... failed (this is not fatal)
 Running "embed /grub/e2fs_stage1_5 (hd0,0)"... failed (this is not fatal)
 Running "install /grub/stage1 (hd0,0) /grub/stage2 p /grub/grub.conf "... succeeded
Done.
grub> quit
第二种修改grub

grub-install --root-directory=/path/to/boot父目录 /path/to/设备目录

  • 在虚拟机中添加另一块硬盘,进行分区格式化,并挂载至/media/boot目录,
    在这里插入图片描述
  • 安装grub到新添加的磁盘中

[root@localhost ~]# grub-install --root-directory=/media dev/sdb
Probing devices to guess BIOS drives. This may take a long time.
Format of install_device not recognized.
Usage: grub-install [OPTION] install_device
Install GRUB on your drive.

  -h, --help              print this message and exit
  -v, --version           print the version information and exit
  --root-directory=DIR    install GRUB images under the directory DIR
                          instead of the root directory
  --grub-shell=FILE       use FILE as the grub shell
  --no-floppy             do not probe any floppy drive
  --force-lba             force GRUB to use LBA mode even for a buggy
                          BIOS
  --recheck               probe a device map even if it already exists
                          This flag is unreliable and its use is
                          strongly discouraged.

INSTALL_DEVICE can be a GRUB device name or a system device filename.

grub-install copies GRUB images into the DIR/boot directory specfied by
--root-directory, and uses the grub shell to install grub into the boot
sector.

Report bugs to <bug-grub@gnu.org>.
[root@localhost ~]# grub-install --root-directory=/media /dev/sdb
Installation finished. No error reported.
This is the contents of the device map /media/boot/grub/device.map.
Check if this is correct or not. If any of the lines is incorrect,
fix it and re-run the script `grub-install'.

(fd0)	/dev/fd0
(hd0)	/dev/sda
(hd1)	/dev/sdb
  • 在/media/boot/grub 目录下创建grub.conf
[root@localhost ~]# mount /dev/sdb1 /media/boot
[root@localhost ~]# cd /media/boot
[root@localhost boot]# cd grub
[root@localhost grub]# ls
device.map     fat_stage1_5  grub.conf         jfs_stage1_5    reiserfs_stage1_5  stage2         vstafs_stage1_5
e2fs_stage1_5  ffs_stage1_5  iso9660_stage1_5  minix_stage1_5  stage1             ufs2_stage1_5  xfs_stage1_5
[root@localhost grub]# cat grub.conf
default=0
timeout=1
title Fake Linux
	root (hd1,0)
	kernel /vmlinuz
	initrd /initrd.img

  • 配置完成后,将虚拟机关机,创建一个新的虚拟机,选择磁盘时,使用已存在磁盘,并选择刚创建了grub的磁盘
    在这里插入图片描述
    在这里插入图片描述
    D:\VirtualMachine\CentOS6\CentOS 6 64 位-0.vmdk

  • 配置完成后,启动虚拟机,会出现以下页面
    在这里插入图片描述

启动时在grub模式下启动系统
  • 启动时按c键进入grub模式,查找内核所有盘
    在这里插入图片描述
  • 根据找到的盘符
    • 使用root (hd0,0)
    • kernel /vmlinuz-内核版本
    • initrd /initrd-内核版本.img
    • boot

在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值