先系统中有一块空闲磁盘,将其划分为两个分区/dev/sdb1和/dev/sdb2,/dev/sdb1做/boot分区,/dev/sdb2做/分区
1 . 新分区格式化文件系统
mkfs.ext4 /dev/sdb1
mkfs.ext4 /dev/sdb2
2 . mkdir /app/boot -p 创建/dev/sdb1分区的挂载点
3 . mount /dev/sdb1 /app/boot 将sdb1分区挂载到/app/boot上
4 . grub-install --root-directory=/app /dev/sdb 安装sdb磁盘的grub到/app/boot下,即为/sdb1磁盘分区上
5 . ls /app/boot grub文件已生成
6 . hexdump -c -n 512 /dev/sdb 查看/dev/sdb的512字节
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 拷贝本系统的vmlinuz内核文件和initramfs虚拟磁盘文件到sdb1分区的/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,且为新系统的/分区,系统启动不启动/sbin/init进程,而是启动/bin/bash为第一启动进程
initrd /initramfs-2.6.32-696.el6.x86_64.img
10 . mkdir /app/rootfs
11 . mount /dev/sdb2 /app/rootfs 挂载sdb磁盘的根分区/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
- 拷贝网卡驱动模块
16 . ethtool -i eth0 查看eth0网卡的设备信息
17 . locate e1000.ko 查看e1000.ko驱动模块的路径信息
18 . cp /lib/modules/2.6.32-696.el6.x86_64/kernel/drivers/net/e1000/e1000.ko /app/rootfs/lib 拷贝e1000.ko网卡模块到/app/rootfs/lib文件
19 . 关闭系统,拔出/dev/sdb磁盘,然后插入没有安装系统的新主机上启动即可
20 . 新主机挂载磁盘
21 . vim /sbin/init(开机自动运行)
#!/bin/bash
....
流程图如下
图1
图2
图3
图4
拷贝网卡设备驱动模块
图5
新主机挂载磁盘启动后界面
图6
网友评论