引导加载程序grub的使用详解
-
为运行于虚拟机上的CentOS 6添加一个新硬件,提供两个主分区
- 为硬盘建两个主分区;并为其安装grub
- 为硬盘的第一个主分区提供内核和ramdisk文件;为第二个分区提供rootfs
- 为rootfs提供bash、ls、cat程序以及所依赖的库文件
- 为grub提供配置文件
-
将新的硬盘设置为第一启动项并能够正常启动目标主机
-
1.新建分区
[root@slave1 ~]# fdisk /dev/sdb Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0xf614f379. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help): n Command action e extended p primary partition (1-4) 1 Invalid partition number for type `1' Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-2610, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +5G Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 2 First cylinder (655-2610, default 655): Using default value 655 Last cylinder, +cylinders or +size{K,M,G} (655-2610, default 2610): +5G Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@slave1 ~]# fdisk -l Disk /dev/sda: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00026a25 Device Boot Start End Blocks Id System /dev/sda1 * 1 64 512000 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 64 2611 20458496 8e Linux LVM Disk /dev/sdb: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xf614f379 Device Boot Start End Blocks Id System /dev/sdb1 1 654 5253223+ 83 Linux /dev/sdb2 655 1308 5253255 83 Linux Disk /dev/mapper/vg_slave1-lv_root: 18.9 GB, 18865979392 bytes 255 heads, 63 sectors/track, 2293 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 Disk /dev/mapper/vg_slave1-lv_swap: 2080 MB, 2080374784 bytes 255 heads, 63 sectors/track, 252 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000
-
2.挂载boot和根文件系统
[root@slave1 ~]# mke2fs -t ext4 /dev/sdb1 [root@slave1 ~]# mke2fs -t ext4 /dev/sdb2 [root@slave1 ~]# mkdir /myroot [root@slave1 ~]# mkdir /myroot/boot [root@slave1 ~]# mount /dev/sdb2 /myroot/boot [root@slave1 ~]# mkdir /myroot/sysroot [root@slave1 ~]# mount /dev/sdb1 /myroot/sysroot [root@slave1 myroot]# vi /etc/fstab /dev/sdb1 /myroot/sysroot ext4 defaults 1 1 /dev/sdb2 /myroot/boot ext4 defaults 1 2
-
3.安装配置grub
[root@slave1 /]# grub-install --root-directory=/myroot /dev/sdb [root@slave1 boot]# cp /boot/vmlinuz-2.6.32-431.el6.x86_64 /myroot/boot/ [root@slave1 boot]# cp /boot/initramfs-2.6.32-431.el6.x86_64.img /myroot/boot/ [root@slave1 grub]# vim /myroot/boot/grub/grub.conf default=0 timeout=5 title centos6.5 simple root (hd1,1) kernel /vmlinuz-2.6.32-431.el6.x86_64 ro root=/dev/sdb1 selinux=0 init=/bin/bash initrd /initramfs-2.6.32-431.el6.x86_64.img
-
4.创建根文件系统
[root@slave1 myroot]# mkdir etc bin sbin lib lib64 usr home root sys proc var mnt media [root@slave1 myroot]# cp /bin/{bash,ls,cat} /myroot/bin/ [root@slave1 bin]# ldd bash linux-vdso.so.1 => (0x00007fffc5f45000) libtinfo.so.5 => /lib64/libtinfo.so.5 (0x00007f0fbe3f8000) libdl.so.2 => /lib64/libdl.so.2 (0x00007f0fbe1f4000) libc.so.6 => /lib64/libc.so.6 (0x00007f0fbde5f000) /lib64/ld-linux-x86-64.so.2 (0x00007f0fbe622000) [root@slave1 bin]# cp /lib64/{libtinfo.so.5,libdl.so.2,libc.so.6,ld-linux-x86-64.so.2} /myroot/lib64/ [root@slave1 bin]# ldd ls linux-vdso.so.1 => (0x00007fff6adfe000) libselinux.so.1 => /lib64/libselinux.so.1 (0x00007fd0f7832000) librt.so.1 => /lib64/librt.so.1 (0x00007fd0f762a000) libcap.so.2 => /lib64/libcap.so.2 (0x00007fd0f7425000) libacl.so.1 => /lib64/libacl.so.1 (0x00007fd0f721d000) libc.so.6 => /lib64/libc.so.6 (0x00007fd0f6e89000) libdl.so.2 => /lib64/libdl.so.2 (0x00007fd0f6c84000) /lib64/ld-linux-x86-64.so.2 (0x00007fd0f7a5a000) libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fd0f6a67000) libattr.so.1 => /lib64/libattr.so.1 (0x00007fd0f6862000) [root@slave1 bin]# cp /lib64/ {libselinux.so.1,librt.so.1,libcap.so.2,libacl.so.1,libc.so.6,libdl.so.2,ld-linux-x86-64.so.2,libpthread.so.0,libattr.so.1} /myroot/lib64/ cp: overwrite `/myroot/lib64/libc.so.6'? no cp: overwrite `/myroot/lib64/libdl.so.2'? no cp: overwrite `/myroot/lib64/ld-linux-x86-64.so.2'? no [root@slave1 bin]# ldd cat linux-vdso.so.1 => (0x00007fff749e7000) libc.so.6 => /lib64/libc.so.6 (0x00007f6bdc516000) /lib64/ld-linux-x86-64.so.2 (0x00007f6bdc8b3000) [root@slave1 bin]# cp /lib64/{libc.so.6,ld-linux-x86-64.so.2} /myroot/lib64/ cp: overwrite `/myroot/lib64/libc.so.6'? no cp: overwrite `/myroot/lib64/ld-linux-x86-64.so.2'? no
-
5.更改启动项
- 点击菜单栏的虚拟机选项,下拉菜单里点击电源,电源选项里选择打开电源时进入固件,进入BIOS设置界面,选择boot菜单里的VMware Virtual SCSI Hard Drive(0:1)将新的硬盘设置为第一启动项,保存
-
原创文章,作者:N27_xiaoni,如若转载,请注明出处:http://www.178linux.com/85827
评论列表(1条)
看完的眼都花了,完成的很不错,讲解的也比较清楚。注意给代码着色,增加可读性。