如何用QEMU运行x86 kernel
最近在提交cpufreq patch,稍微有点逻辑改动的Rafael都要你test, test。有个改动涉及setpolicy driver,要验证,第一印象就是用qemu。
让我们来看下如何搭环境(initrd=ramdisk):
my linux server(xeon) for building can not access internet,also vb under win is not. install qemu deb offline has too many dependens, forget it, let admin apt-get qemu(qemu-system-x86_64), it’s done.
I have already download the linux-pm git repo, below operations r based on this code.
kernel编译
1.generate .config
make O=out_x86_64/ x86_64_defconfig |
btw: gcc is default for x86_64 in xeon.
tj@bsvr:/sys/devices/system/cpu/cpu0/cpufreq$ file /usr/bin/gcc |
2.make
make O=out_x86_64/ bzImage -j8 |
遇到了错误:
You are building kernel with non-retpoline compiler. |
直接disable RETPOLINE:
arch/x86/Kconfig: |
继续又错:
error: Cannot generate ORC metadata for CONFIG_UNWINDER_ORC=y, please install libelf-dev, libelf-devel or elfutils-libelf-devel |
我们用menuconfig
make O=out_x86_64/ menuconfig |
改选Frame pointer…
Kernel hacking > Choose kernel unwinder -> select Frame pointer unwinder |
设置ramdisk size为65536 (64MB)
Device Drivers > Block dev > <*> RAM block device support > ()Default RAM disk size |
then building is ok.
Kernel: arch/x86/boot/bzImage is ready (#1) |
building busybox
1.generate config
make defconfig |
2.静态编译
make menuconfig |
Busybox setting > --- Build Options > [*] Build Busybox as a static |
3.building
make -j4 |
没有幺蛾子,it’s ok
LINK busybox_unstripped |
btw: my bb version: busybox-1.27.1
4.install
安装到指定目录for later usage:
make CONFIG_PREFIX=~/work/kernel/qemu/x86_64/busybox_install/ install |
进去看下:
tj@bsvr:~/work/kernel/qemu/x86_64/busybox_install$ ls -l |
有个linuxrc文件,link到了2.5M的bin/busybox,其他都是link。。。
tj@bsvr:/work/tj/kernel/qemu/x86_64/busybox_install/bin$ ls -lh |
制作ramdisk
这里参考别人了,hurry up,不过需要有root权限,只能cp到vb ubuntu下,得压缩后再cp,不然link全部变了real file了,几百M。
另外不要在vb下share的挂载点操作,cp到外面,比如Downloads:
tj@tj-u1404:~/Downloads/mk_ramdisk$ ls |
ok,run mk_ramdisk.h, then show below if successful:
Allocating group tables: done |
运行qemu x86_64
cp到一个目录:
tj@bsvr:~/work/kernel/qemu/x86_64$ ls |
run.sh:
tj@bsvr:~/work/kernel/qemu/x86_64$ cat run.sh |
see below, haha:)
[ 4.472432] ifconfig (1082) used greatest stack depth: 13824 bytes left |
but no cpufreq:
[root@x86 cpu1]# ls |
退出ctl-A + x
check for intel_pstate
intel_pstate用的就是setpolicy driver。
[root@x86 cpu1]# dmesg | grep "intel" |
nd, 不支持,看下代码需要硬件feature支持:
static int __init intel_pstate_init(void) |
|
X86_FEATURE_HWP
or X86_FEATURE_APERFMPERF
,QEMU(x86_64)本身就不支持,即使host支持也不行,歇菜,还有个x86模拟器叫Bochs以后看了,先用real pc…
refer doc
版权声明:本站所有文章均采用 CC BY-NC-SA 4.0 CN 许可协议。转载请注明原文链接!