背景:最近在做一个虚拟机安全的项目,使用KVM来支撑虚拟化,涉及到KVM和QEMU的代码修改。由于KVM可以以模块的方式加载到内核中,可以单独编译KVM模块,而不必每次重新编译内核(鉴于编译内核所耗的时间,如果每次改动KVM都要重新编译一次内核,估计等项目做完,头发也等白了)
参考:http://blog.chinaunix.net/uid-23390992-id-3300514.html
我的改进:
1.清理
make clean CONFIG_KVM=m CONFIG_INTEL_KVM=m -C /home/kvm/linux-3.14.5 M=/home/kvm/linux-3.14.5/arch/x86/kvm
2.编译make CONFIG_KVM=m CONFIG_INTEL_KVM=m -C /home/kvm/linux-3.14.5 M=/home/kvm/linux-3.14.5/arch/x86/kvm3.将arch/x86/kvm目录下生成kvm.ko和kvm-intel.ko生成的两个模块文件,拷贝到/lib/modules/$(uname -r)/kernel/arch/x86/kvm目录下
4.运行depmod -a重新配置模块依赖关系5.modprobe kvm;modprobe kvm_intel加载两个模块说明:/home/kvm/linux-3.14.5是linux源码的路径
应用场景:KVM开发
附以上命令的shell脚本,欢迎参考批评改进(github:):
(将path修改为你的linux源码目录)
#!/bin/bashpath="/home/kvm/src/linux-3.14.10"echo "1.rmmod kvm_intel kvm\n"rmmod kvm-intelrmmod kvmecho "success!\n"echo "2.rm kvm-intel.ko kvm.ko\n"rm /lib/modules/$(uname -r)/kernel/arch/x86/kvm/kvm.korm /lib/modules/$(uname -r)/kernel/arch/x86/kvm/kvm-intel.koecho "success!\n"echo "3.make clean kvm module\n"make clean CONFIG_KVM=m CONFIG_INTEL_KVM=m -C ${path} M=${path}/arch/x86/kvmecho "success!\n"echo "4.make kvm module"make CONFIG_KVM=m CONFIG_INTEL_KVM=m -C ${path} M=${path}/arch/x86/kvmecho "success!\n"echo "5.insmod kvm-intel.ko kvm.ko\n"cp ${path}/arch/x86/kvm/kvm-intel.ko /lib/modules/$(uname -r)/kernel/arch/x86/kvm/cp ${path}/arch/x86/kvm/kvm.ko /lib/modules/$(uname -r)/kernel/arch/x86/kvm/echo "success!\n"echo "6.modprobe kvm_intel kvm"modprobe kvm_intelmodprobe kvmlsmod|grep kvmls -l /dev/kvmecho "recompile and insmod kvm success!\n"
posted on 2014-07-04 16:22 阅读( ...) 评论( ...)