本文以虚机中新加入一块硬盘,安装grub以及/bin/bash程序模拟裁剪系统
新加一块硬盘,提供单独运行的bash系统
新增一块20G硬盘
创建分区以及文件系统
fdisk /dev/sdb 后进入创建分区并写入
mkfs.ext4 /dev/sdb1
mkfs.ext4 /dev/sdb2
挂载文件系统并制作grub
[root@host70 ~]
[root@host70 ~]
[root@host70 boot]
lost+found
[root@host70 boot]
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@host70 boot]
Probing devices to guess BIOS drives. This may 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 of the lines is incorrect,
fix it and re-run the script `grub-install'.
(fd0) /dev/fd0
(hd0) /dev/sda
(hd1) /dev/sdb
default=0
timeout=5
title Red Hat Enterprise Linux (2.6.32-431.el6.x86_64)
root (hd1,0)
kernel /vmlinuz-2.6.32-431.el6.x86_64 ro root=/dev/sdb2 selinux=0 init=/bin/bash
initrd /initramfs-2.6.32-431.el6.x86_64.img
制作/bin/bash
[root@host70 boot]
[root@host70 boot]
grub initramfs-2.6.32-431.el6.x86_64.img lost+found vmlinuz-2.6.32-431.el6.x86_64
[root@host70 boot]
[root@host70 sysroot]
[root@host70 sysroot]
/bin/bash
[root@host70 sysroot]
[root@host70 sysroot]
linux-vdso.so.1 => (0x00007fffc2ce0000)
libtinfo.so.5 => /lib64/libtinfo.so.5 (0x00007f9eba33e000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f9eba13a000)
libc.so.6 => /lib64/libc.so.6 (0x00007f9eb9da5000)
/lib64/ld-linux-x86-64.so.2 (0x00007f9eba567000)
[root@host70 sysroot]
[root@host70 sysroot]
[root@host70 bin]
bash-4.1
在现有VM中以第二块硬盘加载/bin/bash系统
default=0
timeout=5
title Red Hat Enterprise Linux (2.6.32-431.el6.x86_64)
root (hd1,0)
kernel /vmlinuz-2.6.32-431.el6.x86_64 ro root=/dev/sdb2 selinux=0 init=/bin/bash
initrd /initramfs-2.6.32-431.el6.x86_64.img
正常进入
模拟硬盘拆下来后插到一个新的机器上
1)还原至正常系统,进入grub命令行界面,输入如下命令
root (hd0,0)
kernel /vmlinuz-2.6.32-431.el6.x86_64 ro root=/dev/mapper/vg_host70-lv_root selinx=0
initrd /initramfs-2.6.32-431.el6.x86_64.img
boot
2) 修改grub.conf 文件
3)新建一个VM,硬盘为上图中的disk 载入系统即可
|