6、复制内核文件和initrd文件
init是系统中用来产生其它所有进程的程序。它以守护进程的方式存在,其进程号为1,init是所有进程的父进程,老祖宗,所以不移植是不行的。它通过调用/etc/inittab这个配置文件,然后再去执行/etc/rc.d/rc.sysinit的系统初始化脚本。
将内核文件和initrd文件复制到/dev/sdb下的boot目录中。
[root@localhost grub]# cp /boot/vmlinuz-2.6.32-642.el6.x86_64 /mnt/boot/vmlinuz-soft
[root@localhost grub]# cp /boot/initramfs-2.6.32-642.el6.x86_64.img /mnt/boot/initramfs-soft.img
7、创建目标主机根文件系统
使用命令行展开创建文件系统
[root@localhost grub]# mkdir -pv /mnt/sysroot/{etc/rc.d,usr,var,proc,sys,dev,lib,lib64,bin,sbin,boot,srv,mnt,media,home,root}
mkdir: created directory `/mnt/sysroot'
mkdir: created directory `/mnt/sysroot/etc'
mkdir: created directory `/mnt/sysroot/etc/rc.d'
mkdir: created directory `/mnt/sysroot/usr'
mkdir: created directory `/mnt/sysroot/var'
mkdir: created directory `/mnt/sysroot/proc'
mkdir: created directory `/mnt/sysroot/sys'
mkdir: created directory `/mnt/sysroot/dev'
mkdir: created directory `/mnt/sysroot/lib'
mkdir: created directory `/mnt/sysroot/lib64'
mkdir: created directory `/mnt/sysroot/bin'
mkdir: created directory `/mnt/sysroot/sbin'
mkdir: created directory `/mnt/sysroot/boot'
mkdir: created directory `/mnt/sysroot/srv'
mkdir: created directory `/mnt/sysroot/mnt'
mkdir: created directory `/mnt/sysroot/media'
mkdir: created directory `/mnt/sysroot/home'
mkdir: created directory `/mnt/sysroot/root'
[root@localhost mnt]# ls root/
bin boot dev etc home lib lib64 lost+found media mnt proc root sbin srv sys usr var
8、移植bash命令和其库文件到根文件系统
[root@localhost scripts]# bash cporder.sh
Enter a command: bash
Enter a command: shutdown
Enter a command: vim
Enter a command: reboot
Enter a command: touch
Enter a command: mkdir
Enter a command: ls
Enter a command: rm
Enter a command: cat
Enter a command: less
Enter a command: tree
Enter a command: ifconfig
Enter a command: ip
Enter a command: route
Enter a command: ping
Enter a command: quit
quit
附:命令移植脚本
#!/bin/bash
#
target=/mnt/root
clearCmd() {
if which $cmd &> /dev/null; then
cmdPath=`which --skip-alias $cmd`
else
echo "No such command"
return 5
fi
}
cmdCopy() {
cmdDir=`dirname $1`
[ -d ${target}${cmdDir} ] || mkdir -p ${target}${cmdDir}
[ -f ${target}${1} ] || cp $1 ${target}${cmdDir}
}
libCopy() {
for lib in `ldd $1 | grep -o "/[^[:space:]]\{1,\}"`; do
libDir=`dirname $lib`
[ -d ${target}${libDir} ] || mkdir -p ${target}${libDir}
[ -f ${target}${lib} ] || cp $lib ${target}${libDir}
done
}
while true; do
read -p "Enter a command: " cmd
if [ "$cmd" == 'quit' ] ;then
echo "quit"
exit 0
fi
clearCmd $cmd
[ $? -eq 5 ] && continue
cmdCopy $cmdPath
libCopy $cmdPath
done
9、装载模块,实现网络功能
Linux是一个模块化的操作系统,好多功能组件都是通过模块化的工具来实现的,而且支持动态装载和卸载,我们要是想实现某种功能,只需加载相应的模块即可,就可以实现我们的Linux操作系统大瘦身了。
1、查看宿主机的网卡模块信息
[root@localhost ~]# lsmod | grep e1000
e1000 134863 0
2、查看网卡的详细信息
[root@localhost ~]# modinfo e1000
filename: /lib/modules/2.6.32-642.el6.x86_64/kernel/drivers/net/e1000/e1000.ko
version: 7.3.21-k8-NAPI
license: GPL
description: Intel(R) PRO/1000 Network Driver
author: Intel Corporation, <linux.nics@intel.com>
srcversion: A911791C4EFC2A93BCFCF6A
alias: pci:v00008086d00002E6Esv*sd*bc*sc*i*
alias: pci:v00008086d000010B5sv*sd*bc*sc*i*
alias: pci:v00008086d00001099sv*sd*bc*sc*i*
alias: pci:v00008086d0000108Asv*sd*bc*sc*i*
//这里查询到了网卡模块的路径,把它复制到/dev/sdb的库文件下:
[root@localhost ~]# mkdir /mnt/root/lib64/modules
[root@localhost ~]# cp /lib/modules/2.6.32-642.el6.x86_64/kernel/drivers/net/e1000/e1000.ko /mnt/root/lib64/modules/e1000.ko