附加一块磁盘并进行分区,至少分区2个,一个用于/boot 一个用于根目录/
在将创建的分区进行格式化并挂载在/mnt/boot 和 /mnt/root下分别代表为根目录和boot目录
对磁盘464个字节进行grub安装,安装完成后会有grub文件夹,相应的grub stage将出现
grub-install --root-directory=/mnt/ /dev/sdb
将内核文件和initramfs文件拷贝至/mnt/boot下
root@LGW-Linux-6 boot]# cp /boot/vmlinuz-2.6.32-642.el6.x86_64 /mnt/boot/vmlinuz
[root@LGW-Linux-6 boot]# cp /boot/initramfs-2.6.32-642.el6.x86_64.img /mnt/boot/initramfs.img
建立grub.conf文件
vim /mnt/boot/grub/grub.conf
default=0
timeout=5
title linux made by lgw
root (hd0,0)
kernel /vmlinuz root=/dev/sda2 selinux=0 init=/bin/bash
initrd /initramfs.img
准备相应的进程程序(脚本如下)
#/bin/bash
. /etc/init.d/functions
DIR=/mnt/root
while true;do
read -p "please input command:" CMD
CMD_PATH=`which $CMD`
if [ $CMD = "quit" ];then
echo 退出
break
elif [ $CMD_PATH ];then
[ -d $DIR`dirname $CMD_PATH` ] && cp $CMD_PATH $DIR`dirname $CMD_PATH` || mkdir $DIR`dirname $CMD_PATH` && cp $CMD_PATH $DIR`dirname $CMD_PATH`
for path in `ldd $CMD_PATH |sed -nr 's/.*(\/lib64.*)\(.*/\1/gp'`;do
mkdir $DIR`dirname $path` &>/dev/null
cp $path $DIR$path
done
else
echo "$CMD is not command"
fi
done
建立根目录下的文件夹 proc lib sys etc等
准备网卡驱动
[root@LGW-Linux-6 root]# ethtool -i eth1
driver: vmxnet3
version: 1.4.2.0-k-NAPI
firmware-version:
bus-info: 0000:0b:00.0
supports-statistics: yes
supports-test: no
supports-eeprom-access: no
supports-register-dump: yes
supports-priv-flags: no
[root@LGW-Linux-6 root]# modinfo -n vmxnet3
/lib/modules/2.6.32-642.el6.x86_64/kernel/drivers/net/vmxnet3/vmxnet3.ko
[root@LGW-Linux-6 root]# cp /lib/modules/2.6.32-642.el6.x86_64/kernel/drivers/net/vmxnet3/vmxnet3.ko /mnt/root/lib/
测试切入
挂载其他虚拟机上,测试启动
标签:grub,系统,自制,CMD,boot,mnt,linux,PATH,root From: https://blog.51cto.com/gavenlee/5945624