[root@station103 ~]# mount /dev/sdb1 /mnt/boot/
[root@station103 ~]# mount
/dev/sdb1 on /mnt/boot type ext4 (rw)
5、為新的磁盤分區sdb1裝入grub;
[root@station103 ~]# grub-install --root-directory=/mnt /dev/sdb
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
[root@station103 ~]# ls /mnt/boot/
grub lost+found
[root@station103 ~]#
6、複制主控端的核心至新磁盤分區上sdb1挂載的/boot目錄下;
[root@station103 ~]# cp /boot/vmlinuz-2.6.32-431.el6.x86_64 /mnt/boot/vmlinuz
[root@station103 ~]# cp /boot/initramfs-2.6.32-431.el6.x86_64.img /mnt/boot/initramfs.img
[root@station103 ~]# cd /mnt/boot/
[root@station103 boot]# ll
total 21074
drwxr-xr-x 2 root root 1024 Feb 22 23:32 grub
-rw------- 1 root root 17437215 Feb 22 23:36 initramfs.img
drwx------ 2 root root 12288 Feb 22 23:23 lost+found
-rwxr-xr-x 1 root root 4128368 Feb 22 23:36 vmlinuz
7、挂載sdb2至/mnt/sysroot下,并且建立目标所需的根檔案;
[root@station103 ~]# mount /dev/sdb2 /mnt/sysroot
[root@station103 ~]# mkdir -pv /mnt/sysroot/{etc/rc.d,usr,var,proc,sys,dev,lib,lib64,bin,sbin,boot,srv,mnt,media,home,root}
[root@station103 ~]# cd /mnt/sysroot/
[root@station103 sysroot]# ls
bin dev home lib64 media proc sbin sys var
boot etc lib lost+found mnt root srv usr
[root@station103 etc]# ./bashcp.sh
Enter a command: ls
Enter a command: ifconfig
Enter a command: ping
Enter a command: mv
Enter a command: cp
Enter a command: cat
Enter a command: mkdir
Enter a command: bash
Enter a command: useradd
Enter a command: chmod
Enter a command: chown
Enter a command: reboot
Enter a command: insmod
Enter a command: exit
Enter a command: quit
9、檢視下剛剛複制的指令,并且為/mnt/sysroot/bin建立連結檔案;
[root@station103 etc]# chroot /mnt/sysroot
bash-4.1# ls
bin dev home lib64 media proc sbin sys var
boot etc lib lost+found mnt root srv usr
bash-4.1# cd /bin
bash-4.1# ls
bash cat chmod chown cp ls mkdir mv ping
bash-4.1# cd /sbin
bash-4.1# ls
ifconfig insmod reboot
[root@station103 bin]# ln -sv hash sh 建立連結檔案
`sh' -> `hash'
10、為目标主機/mnt/boot/grub/下建立開機自檢grub.conf配置檔案;
default=0 指定預設啟動的核心或OS
timeout=5 等待使用者選擇要啟動的核心或OS的時間,預設機關為秒
title OuYang Linux System 标題名
root (hd0,0) 在grub中,都以hd開頭
kernel /vmlinuz ro root=/dev/sda2 selinux=0 init=/bin/bash
指定核心檔案及傳遞給核心的參數
initrd /initramfs.img