先系統(tǒng)中有一塊空閑磁盤,將其劃分為兩個(gè)分區(qū)/dev/sdb1和/dev/sdb2垦细,/dev/sdb1做/boot分區(qū),/dev/sdb2做/分區(qū)
1 . 新分區(qū)格式化文件系統(tǒng)
mkfs.ext4 /dev/sdb1
mkfs.ext4 /dev/sdb2
2 . mkdir /app/boot -p 創(chuàng)建/dev/sdb1分區(qū)的掛載點(diǎn)
3 . mount /dev/sdb1 /app/boot 將sdb1分區(qū)掛載到/app/boot上
4 . grub-install --root-directory=/app /dev/sdb 安裝sdb磁盤的grub到/app/boot下,即為/sdb1磁盤分區(qū)上
5 . ls /app/boot grub文件已生成
6 . hexdump -c -n 512 /dev/sdb 查看/dev/sdb的512字節(jié)
7 . cd /app/boot
8 . cp /boot/vmlinuz-2.6.32-696.el6.x86_64 /boot/initramfs-2.6.32-696.el6.x86_64.img /app/boot 拷貝本系統(tǒng)的vmlinuz內(nèi)核文件和initramfs虛擬磁盤文件到sdb1分區(qū)的/app/boot文件中
9 . vim /app/boot/grub/grub.conf
default=0
timeout=5
title danran
root (hd0,0)
kernel /vmlinuz-2.6.32-696.el6.x86_64 root=UUID=57dcc7f1-6df9-4748-b5c7-9c75a4d45f32 selinux=0 init=/bin/bash \\/dev/sdb2的UUID,且為新系統(tǒng)的/分區(qū),系統(tǒng)啟動(dòng)不啟動(dòng)/sbin/init進(jìn)程悠就,而是啟動(dòng)/bin/bash為第一啟動(dòng)進(jìn)程
initrd /initramfs-2.6.32-696.el6.x86_64.img
10 . mkdir /app/rootfs
11 . mount /dev/sdb2 /app/rootfs 掛載sdb磁盤的根分區(qū)/dev/sdb2到/app/rootfs
12 . cd /app/rootfs
13 . mkdir (root,bin,sbin,lib,lib64,var,usr,dev,etc,proc,sys,home) -pv
14 . vim /app/cmdcp.sh 編輯命令拷貝腳本
vim cmdcp.sh
#!bin/bash
#ch_root="/app/sysroot"
[ ! -d $ch_root ] && mkdir $ch_root
bincopy() {
if which $1 &> /dev/null;then
local cmd_path=`which --skip-alias $1`
local bin_dir=`dirname $cmd_path`
[ -d ${ch_root}${bin_dir} ] || mkdir -p ${ch_root}${bin_dir}
[ -f ${ch_root}${cmd_path} ] || \cp -f $cmd_path ${ch_root}${bin_dir}
return 0
else
echo "Command not found"
fi
}
libcopy() {
local lib_list=$(ldd `which --skip-alias $1` | grep -Eo '/[^[:space:]]+')
for loop in $lib_list;do
local lib_dir=`dirname $loop`
[ -d ${cn_root}${lib_dir} ] || mkdir -p ${ch_root}${lib_dir}
[ -f ${ch_root}${loop} ] || cp $loop ${ch_root}${lib_dir}
done
}
read -p "Please input copy path: " path
ch_root=$path
read -p "Please input a command or quit: " command
while [ "$command" != "quit" ];do
if bincopy $command;then
libcopy $command
fi
read -p "Please input a command or quit: " command
done
15 . bash /app/cmdcp.sh 拷貝以下命令到/app/rootfs/bin
Please input copy path: /app/rootfs/bin
Please input a command or quit: ls
Please input a command or quit: ifconfig
Please input a command or quit: cpp
Please input a command or quit: cp
Please input a command or quit: mv
Please input a command or quit: cat
Please input a command or quit: vi
Please input a command or quit: tree
Please input a command or quit: reboot
Please input a command or quit: bash
Please input a command or quit: ping
Please input a command or quit: lsblk
Please input a command or quit: ip
Please input a command or quit: insmod
Please input a command or quit: lsmod
Please input a command or quit: rmmod
Please input a command or quit: quit
- 拷貝網(wǎng)卡驅(qū)動(dòng)模塊
16 . ethtool -i eth0 查看eth0網(wǎng)卡的設(shè)備信息
17 . locate e1000.ko 查看e1000.ko驅(qū)動(dòng)模塊的路徑信息
18 . cp /lib/modules/2.6.32-696.el6.x86_64/kernel/drivers/net/e1000/e1000.ko /app/rootfs/lib 拷貝e1000.ko網(wǎng)卡模塊到/app/rootfs/lib文件
19 . 關(guān)閉系統(tǒng),拔出/dev/sdb磁盤充易,然后插入沒有安裝系統(tǒng)的新主機(jī)上啟動(dòng)即可
20 . 新主機(jī)掛載磁盤
21 . vim /sbin/init(開機(jī)自動(dòng)運(yùn)行)
#!/bin/bash
....
流程圖如下
圖1
圖2
圖3
圖4
拷貝網(wǎng)卡設(shè)備驅(qū)動(dòng)模塊
圖5
新主機(jī)掛載磁盤啟動(dòng)后界面
圖6