CentOS6上新增硬盘并安装配置grub文件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS6上新增硬盘并安装配置grub文件相关的知识,希望对你有一定的参考价值。

实例:

为运行于虚拟机上的CentOS 6添加一块新硬件,提供两个主分区;

(1) 为硬盘新建两个主分区;并为其安装grub

(2) 为硬盘的第一个主分区提供内核和ramdisk文件; 为第二个分区提供rootfs

(3) rootfs提供bashlscat程序及所依赖的库文件;

(4) grub提供配置文件;

(5) 将新的硬盘设置为第一启动项并能够正常启动目标主机;

 新增硬盘并分区

[[email protected]~]# fdisk -l /dev/sdb

 

Disk /dev/sdb: 10.7 GB, 10737418240 bytes

255 heads, 63 sectors/track, 1305 cylinders

Units = cylinders of 16065 * 512 = 8225280bytes

Sector size (logical/physical): 512 bytes /512 bytes

I/O size (minimum/optimal): 512 bytes / 512bytes

Disk identifier: 0x6a3c778b

 

  Device Boot      Start         End      Blocks  Id  System

/dev/sdb1               1         132    1060258+  83  Linux

/dev/sdb2             133         264    1060290   83  Linux

         创建文件系统

[[email protected]~]# mke2fs -t ext4 /dev/sdb1

[[email protected]~]# mke2fs -t ext4 /dev/sdb2

         挂载

[[email protected]~]# mkdir /mnt/boot

[[email protected]~]# mount /dev/sdb1 /mnt/boot

         安装grub至分区1

[[email protected]~]# grub-install --root-directory=/mnt /dev/sdb

Probing devices to guess Bios drives. Thismay take a long time.

Installation finished. No error reported.

This is the contents of the device map/mnt/boot/grub/device.map.

Check if this is correct or not. If any ofthe lines is incorrect,

fix it and re-run the script`grub-install‘.

         复制内核文件和initrdfs文件

[[email protected]]# cp /boot/vmlinuz-2.6.32-431.el6.x86_64 /mnt/boot/vmlinuz

[[email protected]]# cp /boot/initramfs-2.6.32-431.el6.x86_64.img  /mnt/boot/initramfs

         创建grub配置文件

[[email protected]]# vim /mnt/boot/grub//grub.conf

default=0

timeout=5

title CentOS6(test)

root (hd0,0)

kernel /vmlinuz ro root=/dev/sdb2 selinux=0init=/bin/bash

initrd /initramfs

 

         卸载sdb1,挂载sdb2,并创建rootfs相关目录

[[email protected] /]# umount /dev/sdb1

[[email protected] /]# mount /dev/sdb2 /mnt

[[email protected] /]# mkdir -p/mnt/{bin,sbin,lib,lib64,etc,home,root,media,dev,mnt,tmp}

[[email protected] /]# mkdir -p/mnt/{usr/{bin,sbin,lib,lib64},var/{lib,lib64,log,local,cache

},proc,sys,selinux}

         rootfs提供bashlscat程序及所依赖的库文件;

cp /bin/{bash,ls,cat} /mnt/bin

ldd命令:                                   #需要ldd命令

- print shared library dependencies

ldd [OPTION]... FILE...

[[email protected]/]# cp `ldd /bin/{bash,ls,cat}|grep -Eo "/lib.*[[:space:]]"| sort -u`/mnt

/lib64

[[email protected] /]# sync                     #同步到磁盘

         重启后调整硬盘启动顺序测试

         调整虚拟机bios硬盘开机启动项

技术分享

启动后读取自定义的grub.conf

技术分享

正常启动

技术分享



本文出自 “11290766” 博客,请务必保留此出处http://rylan.blog.51cto.com/11290766/1922542

以上是关于CentOS6上新增硬盘并安装配置grub文件的主要内容,如果未能解决你的问题,请参考以下文章

Grub实践

centos6系统裁剪

如何从ubuntu14.04下硬盘安装ubuntu

8.操作系统实战——环境配置,用文件模拟硬盘(生成文件,格式化,安装GRUB,转换虚拟硬盘格式)

系统启动时遇到“设备忙”问题的解决

CentOS6.2修复Grub引导