如何用QEMU模拟Raspberry Pi Raspbian? [英] How to emulate Raspberry Pi Raspbian with QEMU?

查看:616
本文介绍了如何用QEMU模拟Raspberry Pi Raspbian?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用QEMU在Raspian OS上模拟Raspberry Pi.我尝试了互联网上描述的几种方法,但都没有成功.

I'm trying to emulate a Raspberry Pi with the Raspian OS using QEMU. I've tried several approaches described on the internet but without any success.

我发现我需要修补一个适合所需OS的Linux内核.就我而言,我选择了带有内核4.4的Rasbian Lite:

I figured out that I need to patch a Linux Kernel fitting the desired OS. In my case I chose Rasbian Lite with Kernel 4.4:

wget https://downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2016-05-31/2016-05-27-raspbian-jessie-lite.zip
unzip 2016-05-27-raspbian-jessie-lite.zip
rm 2016-05-27-raspbian-jessie-lite.zip

接下来,我从 https://www.kernel.org/加载内核:

Next I load a Kernel from https://www.kernel.org/:

wget https://www.kernel.org/pub/linux/kernel/v4.x/linux-4.4.16.tar.gz
tar -xzf linux-4.4.16.tar.gz
rm linux-4.4.16.tar.gz

现在交叉编译内核:

export ARCH=arm
export CROSS_COMPILE=arm-linux-gnueabi-
cd linux-4.4.16
make vexpress_defconfig
make all
cd ..

现在,我可以将启动映像(即在RAM中自动提取的压缩内核映像)复制到我的工作区:

Now I can copy the boot image, that is a compressed kernel image that auto-extracts in RAM, to my workspace:

cp linux-4.4.16/arch/arm/boot/zImage zImage

并运行QEMU

qemu-system-arm -kernel zImage -M vexpress-a9 -m 1024 -cpu cortex-a9 -no-reboot -serial stdio -hda 016-05-27-raspbian-jessie-lite.img -append "root=/dev/sda2 rootfstype=ext4"

但是我所看到的只是一个黑色的QEMU窗口. :(

But all I see is a black filled QEMU-window. :(

我认为问题在于获取正确的内核.从Internet复制某些内核永远不会成功,因为它们不适合该操作系统.

I think that the problem is to get the right Kernel. Copying some of the Kernels from the Internet never led to success because they are not fit for the OS.

如何构建/修补适合操作系统的内核(无需下载现有的内核)以及如何正确运行QEMU?

How can I build/patch a Kernel fitting the OS (without downloading an existing one) and how to run QEMU properly?

预先感谢
亚历克斯

Thanks in advance
Alex

我从此处 https://www加载kernel-qemu. dropbox.com/s/g8u93xblz1v1ly0/kernel-qemu?dl=0 并运行 QEMU :

I load a kernel-qemu from here https://www.dropbox.com/s/g8u93xblz1v1ly0/kernel-qemu?dl=0 and run QEMU with it:

qemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append "root=/dev/sda2" -hda 2016-05-27-raspbian-jessie-lite.img

这给我带来以下输出: 这对我来说很有意义,因为该内核的版本早于Raspbian Jessie的3.10.25版本,而其内核为4.4.16.

This brings me the following output: And it makes sense to me because the Kernel is 3.10.25 and older than Raspbian Jessie with Kernel 4.4.16.

使用来自的qemu-kernel https://github.com/dhruvvyas90/qemu-rpi-kernel/blob/master/kernel-qemu-4.4.12-jessie

qemu-system-arm -kernel kernel-qemu-4.4.12-jessie -cpu arm1176 -m 256 -M versatilepb -serial stdio -append "root=/dev/sda2 rootfstype=ext4 rw" -hda 2016-05-27-raspbian-jessie-lite.img

我得到了类似的结果:

I got this similar result:

尝试使用新的内核qemu 4.4.16:

A new try with a new kernel-qemu 4.4.16:

  1. https://复制build-kernel-qemu github.com/dhruvvyas90/qemu-rpi-kernel/tree/master/tools 并添加以下行以检出内核4.4.16的版本:

  1. Copy build-kernel-qemu from https://github.com/dhruvvyas90/qemu-rpi-kernel/tree/master/tools and add the following line to checkout the version for Kernel 4.4.16:

git checkout b05965f284db3e086022f4e318e46cb5bffb1376

  • 运行build-kernel-qemu来构建内核

  • Run build-kernel-qemu to build the kernel

    sh build-kernel-qemu
    

  • 运行 QEMU

    qemu-system-arm -kernel kernel-qemu -m 256 -M versatilepb -serial stdio -append "root=/dev/sda2 rootfstype=ext4 rw" -hda 2016-05-27-raspbian-jessie-lite.img
    

    结果:

    推荐答案

    您应该在开始之前展开Raspbian Image文件

    使用 kpartx 挂载Raspbian图像文件(可能必须安装kpartx)

    Mount the Raspbian Image file with kpartx (might have to install kpartx)

    $ sudo kpartx -av your-image.img
    add map loop0p1 (252:5): 0 117187 linear /dev/loop0 1
    add map loop0p2 (252:6): 0 3493888 linear /dev/loop0 118784
    
    $ sudo mount /dev/mapper/loop0p2 /mnt/img1
    $ cd /mnt/img1
    

    修改/etc/fstab 并注释掉MMCBLK挂载

    Modify the /etc/fstab and comment out the MMCBLK mounts

    $ sudo nano etc/fstab
    
    proc            /proc           proc    defaults          0       0
    #/dev/mmcblk0p1  /boot           vfat    defaults          0       2
    #/dev/mmcblk0p2  /               ext4    defaults,noatime  0       1
    # a swapfile is not a swap partition, no line here
    #   use  dphys-swapfile swap[on|off]  for that
    

    修改/etc/ld.so.preload 并注释掉行...

    Modify /etc/ld.so.preload and comment out lines ...

    $ sudo nano etc/ld.so.preload
    
    #/usr/lib/arm-linux-gnueabihf/libarmmem.so
    

    卸载并销毁来自kpartx的循环

    Unmount and destroy loops from kpartx

    $ sudo umount /mnt/img1
    $ sudo kpartx -d your-image.img
    

    在此处获取与Raspbian图像匹配的 Qemu内核 ...

    Get the Qemu kernel matching the Raspbian image here...

    https://github.com/dhruvvyas90/qemu-rpi-kernel

    我使用此命令成功模拟了Raspbian Jessie

    I used this command to successfully emulate Raspbian Jessie

    qemu-system-arm -kernel kernel-qemu-4.4.12-jessie -cpu arm1176 -m 256 -M versatilepb \
    -no-reboot -serial stdio -append "root=/dev/sda2 panic=1 rootfstype=ext4 rw" \
    -redir tcp:5022::22 \
    -hda 2016-05-27-raspbian-jessie-lite.img
    

    这篇关于如何用QEMU模拟Raspberry Pi Raspbian?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆