QEMU搭建虚拟化开发环境

QEMU搭建虚拟化开发环境

环境:ubuntu 20.04

1. qemu安装

1.1 命令行安装

sudo apt-get install qemu qemu-system qemu-user

1.2 源码安装

待补充

2. qemu运行arm32/arm64程序

2.1 arm32/64交叉编译器安装

# arm32
sudo apt-get install gcc-arm-linux-gnueabihf
# arm64
sudo apt-get install gcc-aarch64-linux-gnu

2.2 qemu运行arm32/64程序

测试程序hello.c

#include <stdio.h>
int main()
{
    printf("hello world!\n");
    return 0;
}

使用arm32交叉编译器编译程序:

arm-linux-gnueabihf-gcc hello.c -o hello

使用qemu运行hello:

qemu-arm -L /usr/arm-linux-gnueabihf hello

运行结果:
在这里插入图片描述

使用arm64交叉编译器编译程序:

aarch64-linux-gnu-gcc hello.c -o hello_aarch64

使用qemu运行hello_aarch64:

qemu-aarch64 -L /usr/aarch64-linux-gnu hello_aarch64

运行结果:
在这里插入图片描述

在qemu运行ARM 32/64程序添加了-L <PATH>指定了程序运行的链接路径:

-L path QEMU_LD_PREFIX set the elf interpreter prefix to 'path'

也可以选择在编译时添加-static进行静态编译,便不需要在qemu运行时添加-L参数


版权声明:本文为weixin_43217824原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。