一种验证Linux kernel是否可用的Sanity Check方法

xiaoxiao2021-02-28  15

本例子介绍对linux kernel进行sanity check的一种方式。由于kernel在启动时,将首先执行initrd,因此可构造一个程序作为initrd,在kernel启动时检查initrd程序是否被执行。 ## 构造用户程序作为initrd 1. 构造test.c ```c #include <stdio.h> void main() {   printf("Greeting.\n");   while(1); } ``` 2. 编译 ```shell $ arm-linux-gnueabi-gcc -static test.c -o test ``` 3. 构造initrd ```shell $ echo test | cpio -o --format=newc > rootfs ``` ## sanity check for kernel ```shell # zImage : kernel already built # rootfs : initrd $ ./qemu-system-arm -M versatilepb -kernel zImage -initrd rootfs -append "root=/dev/ram rdinit=/test console=ttyAMA0" -nographic ``` 观察终端输出,最末出现"Greeting"意味着initrd被执行。 ## reference [compile linux kernel for qemu arm]: https://balau82.wordpress.com/2010/03/22/compiling-linux-kernel-for-qemu-arm-emulator/
转载请注明原文地址: https://www.6miu.com/read-1750113.html

最新回复(0)