QEMU来创建一个,[教程在这]。

2023-05-16

RASPBERRY PI ON QEMU

Let’s start setting up a Lab VM. We will use Ubuntu and emulate our desired ARM versions inside of it.

First, get the latest Ubuntu version and run it in a VM:

  • https://www.ubuntu.com/download/desktop

For the QEMU emulation you will need the following:

  1. A Raspbian Image: http://downloads.raspberrypi.org/raspbian/images/raspbian-2017-04-10/ (other versions might work, but Jessie is recommended)
  2. Latest qemu kernel: https://github.com/dhruvvyas90/qemu-rpi-kernel

Inside your Ubuntu VM, create a new folder:


$ mkdir ~/qemu_vms/  

Download and place the Raspbian Jessie image to ~/qemu_vms/.

Download and place the qemu-kernel to ~/qemu_vms/.


$ sudo apt-get install qemu-system
$ unzip <image-file>.zip
$ fdisk -l <image-file>  

You should see something like this:


Disk 2017-03-02-raspbian-jessie.img: 4.1 GiB, 4393533440 bytes, 8581120 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x432b3940

Device                          Boot  Start     End Sectors Size Id Type
2017-03-02-raspbian-jessie.img1        8192  137215  129024  63M  c W95 FAT32 (LBA)
2017-03-02-raspbian-jessie.img2      137216 8581119 8443904   4G 83 Linux  

You see that the filesystem (.img2) starts at sector 137216. Now take that value and multiply it by 512, in this case it’s 512 * 137216 = 70254592 bytes. Use this value as an offset in the following command:


$ sudo mkdir /mnt/raspbian
$ sudo mount -v -o offset=70254592 -t ext4 ~/qemu_vms/<your-img-file.img> /mnt/raspbian
$ sudo nano /mnt/raspbian/etc/ld.so.preload  

Comment out every entry in that file with ‘#’, save and exit with Ctrl-x » Y.


$ sudo nano /mnt/raspbian/etc/fstab  

IF you see anything with mmcblk0 in fstab, then:

  1. Replace the first entry containing /dev/mmcblk0p1 with /dev/sda1
  2. Replace the second entry containing /dev/mmcblk0p2 with /dev/sda2, save and exit.

$ cd ~
$ sudo umount /mnt/raspbian  

Now you can emulate it on Qemu by using the following command:


$ qemu-system-arm -kernel ~/qemu_vms/<your-kernel-qemu> -cpu arm1176 -m 256 -M versatilepb -serial stdio -append "root=/dev/sda2 rootfstype=ext4 rw" -hda ~/qemu_vms/<your-jessie-image.img> -redir tcp:5022::22 -no-reboot  

If you see GUI of the Raspbian OS, you need to get into the terminal. Use Win key to get the menu, then navigate with arrow keys until you find Terminal application as shown below.

From the terminal, you need to start the SSH service so that you can access it from your host system (the one from which you launched the qemu).

Now you can SSH into it from your host system with (default password – raspberry):


$ ssh pi@127.0.0.1 -p 5022  

For a more advanced network setup see the “Advanced Networking” paragraph below.

Troubleshooting

If SSH doesn’t start in your emulator at startup by default, you can change that inside your Pi terminal with:


$ sudo update-rc.d ssh enable  

If your emulated Pi starts the GUI and you want to make it start in console mode at startup, use the following command inside your Pi terminal:


$ sudo raspi-config
>Select 3 – Boot Options
>Select B1 – Desktop / CLI
>Select B2 – Console Autologin  

If your mouse doesn’t move in the emulated Pi, click <Windows>, arrow down to Accessories, arrow right, arrow down to Terminal, enter.

Resizing the Raspbian image

Once you are done with the setup, you are left with a total of 3,9GB on your image, which is full. To enlarge your Raspbian image, follow these steps on your Ubuntu machine:

Create a copy of your existing image:


$ cp <your-raspbian-jessie>.img rasbian.img  

Run this command to resize your copy:


$ qemu-img resize raspbian.img +6G  

Now start the original raspbian with enlarged image as second hard drive:


$ sudo qemu-system-arm -kernel ~/qemu_vms/<kernel-qemu> -cpu arm1176 -m 256 -M versatilepb -serial stdio -append "root=/dev/sda2 rootfstype=ext4 rw" -hda ~/qemu_vms/<your-original-raspbian-jessie>.img -redir tcp:5022::22 -no-reboot -hdb raspbian.img  

Login and run:


$ sudo cfdisk /dev/sdb  

Delete the second partition (sdb2) and create a New partition with all available space. Once new partition is creates, use Write to commit the changes. Then Quit the cfdisk.

Resize and check the old partition and shutdown.


$ sudo resize2fs /dev/sdb2
$ sudo fsck -f /dev/sdb2
$ sudo halt  

Now you can start QEMU with your enlarged image:


$ sudo qemu-system-arm -kernel ~/qemu_vms/<kernel-qemu> -cpu arm1176 -m 256 -M versatilepb -serial stdio -append "root=/dev/sda2 rootfstype=ext4 rw" -hda ~/qemu_vms/raspbian.img -redir tcp:5022::22  

Advanced Networking

In some cases you might want to access all the ports of the VM you are running in QEMU. For example, you run some binary which opens some network port(s) that you want to access/fuzz from your host (Ubuntu) system. For this purpose, we can create a shared network interface (tap0) which allows us to access all open ports (if those ports are not bound to 127.0.0.1). Thanks to @0xMitsurugi for suggesting this to include in this tutorial.

This can be done with the following commands on your HOST (Ubuntu) system:


azeria@labs:~ $ sudo apt-get install uml-utilities
azeria@labs:~ $ sudo tunctl -t tap0 -u azeria
azeria@labs:~ $ sudo ifconfig tap0 172.16.0.1/24  

After these commands you should see the tap0 interface in the ifconfig output.


azeria@labs:~ $ ifconfig tap0
tap0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.16.0.1 netmask 255.255.255.0 broadcast 172.16.0.255
ether 22:a8:a9:d3:95:f1 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0  

You can now start your QEMU VM with this command:


azeria@labs:~ $ sudo qemu-system-arm -kernel ~/qemu_vms/<kernel-qemu> -cpu arm1176 -m 256 -M versatilepb -serial stdio -append "root=/dev/sda2 rootfstype=ext4 rw" -hda ~/qemu_vms/rasbian.img -net nic -net tap,ifname=tap0,script=no,downscript=no -no-reboot  

When the QEMU VM starts, you need to assign an IP to it’s eth0 interface with the following command:


pi@labs:~ $ sudo ifconfig eth0 172.16.0.2/24  

If everything went well, you should be able to reach open ports on the GUEST (Raspbian) from your HOST (Ubuntu) system. You can test this with a netcat (nc) tool (see an example below).



转自:https://www.anquanke.com/post/id/86383

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

QEMU来创建一个,[教程在这]。 的相关文章

  • win11 使用 QEMU 配置龙芯 3A5000 虚拟环境

    01 下载资源 本实验使用资源 开源模拟器qemu 下载地址 qemu w64 setup 20230822 exe loongarch 固件下载 QEMU EFI 8 0 fd loongarch 基本镜像下载 archlinux loo
  • 从零开始制作Linux

    提到制作Linux 大家都能想到如雷贯耳 大名鼎鼎的Linux from scratch 但Linux from scratch的复杂性不是普通人能轻易掌握的 对于初学者来说 任何步骤出现不一致 会让初学者遇到挫拆 攻破LFS的信心越来越低
  • ovirt-node和ovirt-engine相连遇到的问题解决办法

    1 Host 192 168 70 7 does not comply with the cluster Default emulated machines The Hosts emulated machines are
  • qemu模拟器搭建arm运行环境搭建笔记

    qemu system arm M vexpress a9 m 512M kernel home lyk Downloads qemu linux 3 16 arch arm boot zImage nographic append roo
  • 梳理Vue常考面试题型

    完整版在线阅读 http interview poetries top 1 对于MVVM的理解 MVVM是Model View ViewModel缩写 也就是把MVC中的Controller演变成ViewModel Model层代表数据模型
  • QEMU-在内核中增加驱动(6)

    上面是我的微信和QQ群 欢迎新朋友的加入 进入linux源码目录 增加驱动 hello c include
  • qemu-linux-user ELF vs XCOFF 2

    最后更新2021 12 16 qemu 4 x linux user mmap c 里target mmap如果offset不是aligned有问题 前面检测后直接退出了 后面做了pread 但走不到这个地方 修改一下 看看效果如何 如前所
  • Rustc/LLVM 为 aarch64 生成错误代码,opt-level=0

    我有两个文件被组装 编译 链接到简约内核中 start s set CPACR EL1 FPEN 0b11 lt lt 20 set BOOT STACK SIZE 8 1024 global boot stack global start
  • Android Studio 模拟器卡在 Google 徽标上

    我正在尝试在 Android Studio 模拟器中运行我的应用程序 模拟器已打开但卡在 Google 徽标加载中 我能做些什么 我的电脑是低端的 如何才能快速运行模拟器 我还在模拟器设置中减小了 RAM 的大小 但这并不能解决我的问题 请
  • 如何在 QEMU x86 上模拟 i2c 设备?

    我正在研究 QEMU 1 5 1 6 但还没有看到任何在 i2c 总线上添加设备的文档 有人可以帮忙吗 Thanks 好吧 没人对这个问题感兴趣 我发布我自己的解决方案 由于 QEMU 不支持 I2C 总线级数据传输 因此在将多点触摸数据从
  • 在linux下构建edk2

    我开始用 edk2 编写一个小而简单的应用程序 因此 要编写一个简单的 edk2 UEFI 应用程序 我是这样开始的 git克隆https github com tianocore edk2 git edksetup sh BaseTool
  • 实现自定义 u-boot 命令

    我想添加自定义命令命令u boot可以是一个简单的 hello world 命令 搜索后我发现了这个链接Yocto u boot 自定义命令它说看的地方timer命令输入cmd misc c作为起点 我怎么带这个timer命令到我的 u b
  • 在 SR-IOV 虚拟功能 (VF) NIC 之间转发数据包

    我有一个支持 Intel SR IOV 的 Intel 82599ES 10G NIC 我已成功创建了 8 个虚拟功能 VF 并将其分配给 2 个 qemu kvm VM 每个 VM 2 个 VF 两台虚拟机都使用分配的 VF 运行 DPD
  • 如何使用 QEMU 的简单跟踪后端?

    这是后续this https stackoverflow com questions 37522552 qemu simple backend tracing dosent print anything comment65639854 37
  • 如何编写 Sparc 程序集并在 Qemu 或 Simics 中运行其二进制文件?

    我正在尝试开始编写一些 Sparc 程序集 但我不知道如何汇编和运行代码 我已经用 arcTools 编写了 arc 但这就是我对汇编的了解 我已经下载了 simics 和 qemu 但我不知道从这里去哪里 有人能指出我正确的方向吗 谢谢
  • 如何统计QEMU从运行开始到结束执行的客户指令数量?

    我想对 QEMU 每秒的客户指令进行基准测试 以将其与其他模拟器进行比较 如何获取访客指令数 我对用户模式和完整系统模式都感兴趣 我现在唯一的解决方案是使用简单的跟踪记录所有指令exec tb or d in asm 如何使用 QEMU 的
  • 使用 QEMU 模拟 Big Endian ARM 系统

    是否可以编译一些 Linux 内核并通过 QEMU 运行它 模拟一些 Big Endian ARM 处理器 如果 QEMU 无法做到这一点 我很想知道其他可以做到这一点的系统模拟器 我的基本目标是在尽可能多的本机环境中运行和调试专用的 Bi
  • 用于 RHEL 的 gdb-multiarch

    我正在尝试寻找方法来运行gdb 多架构RHEL 中的命令 我已经安装了用于 ARM 处理的 QEMU 模拟器 我想安装GDB进行调试 我能够安装GDB 多体系结构在 Ubuntu 中运行命令成功 sudo apt get GDB multi
  • qemu kvm:如何获取性能监控中断?

    我在操作系统内核中编写了一些函数 以便在指令计数器溢出时发出性能监控中断 PMI 它在我的机器 Intel core i5 上运行良好 但是当我使用 qemu 在 qemu 上运行它时 qemu system x86 64 enable k
  • 如何使用 ioread64() 和 iowrite64() 访问 IO 内存?

    背景 我目前正在编写一个设备驱动程序教育设备 https github com qemu qemu blob master hw misc edu c在 qemu RISC V 中 由此question https stackoverflo

随机推荐

  • FreeRTOS代码阅读笔记:heap_4.c

    FreeRTOS中对于内存的管理当前一共有5种实现方式 xff08 作者当前的版本是10 1 1 xff09 xff0c 均在 Source portable MemMang 下面 xff0c 这里笔记下 heap 4 c和第二种方式比较相
  • (1)touchgfx 添加时钟控件

    第一步 xff1a 新建空白模版 添加图片 xff1a 放入 链接 xff1a https pan baidu com s 1NI6LUYrTUs64Z2jZE6AAQQ 提取码 xff1a 2odw 添加控件 xff1a 位置部件属性1T
  • 【基于51】红外寻迹智能小车 - 代码篇

    文章目录 前言一 准备工作二 使用步骤1 模块化编程2 电机模块3 小车动作模块4 PWM 和定时器 中断系统5 寻迹逻辑 总结 前言 关于硬件部分可以看我上次写的帖子https blog csdn net ZER00000001 arti
  • C++关键字override

    一 什么是override override的翻译是覆盖 实际上它在C 43 43 中可以检测哪些虚函数没有被重写并报错 注 xff1a 在派生类的成员函数中使用override时 xff0c 如果基类中无此函数 xff0c 或基类中的函数
  • 邻接矩阵和邻接表

    图的概述和存储结构 xff08 一 xff09 文章目录 前言一 图的概述1 xff09 图的分类2 xff09 图的要素 二 图的存储结构三 邻接矩阵四 邻接表 前言 有一种说法是程序是由数据结构和算法组成的 xff0c 这很能体现出数据
  • 图解迪杰斯特拉(Dijkstra)最短路径算法

    往期文章目录 干货满满 xff01 最小生成树 Prim算法 最小生成树 Kruskal算法 目录 前言 一 最短路径的概念及应用 二 Dijkstra迪杰斯特拉 1 什么是Dijkstra 2 逻辑实现 总结 前言 无论是什么程序都要和数
  • Vscode配置Git+快速入门,一篇学会80%的Git操作

    前言 团队开发中经常会用到Git xff0c 能极大简化开发的流程 xff0c 而个人开发也可以利用Git管理自己的代码 同样作为一个初学者 xff0c 我在学完Git之后写下这篇文章总结个人走过的坑 xff0c 大家一起进步 Git下载和
  • 【C++11】三大神器之——智能指针

    文章目录 前言 一 智能指针的原理1 RAII机制2 简单的实现 二 智能指针的用法1 智能指针的分类2 unique ptr基本语法 3 shared ptr基本语法 4 删除器5 weak ptr 前言 一 智能指针的原理 1 RAII
  • 【C++11】三大神器之——右值、移动语义、完美转发

    前言 如果你还不知道C 43 43 11引入的右值 移动语义 完美转发是什么 xff0c 可以阅读这篇文章 xff1b 如果你已经对这些知识了如指掌 xff0c 也可以看看有什么可以补充 x1f60f 一 右值 值类别vs变量类型 在正式认
  • 【C++11】三大神器之——包装器和绑定器

    前言 如果你还不知道 C 43 43 11 引入的包装器和绑定器是什么 xff0c 可以读读这篇文章 xff0c 看看有什么 启发 xff1b 如果你已经对包装器和绑定器了如指掌 xff0c 也可以读读这篇文章 xff0c 看看有什么 补充
  • 【神经网络和深度学习-开发案例】第四章 神经网络如何对数字进行分类

    神经网络和深度学习 第四章 神经网络如何对数字进行分类 案例 xff1a 使用神经网络识别手写数字 好了 xff0c 让我们来写一个程序 xff0c 学习如何识别手写的数字 xff0c 使用随机梯度下降和MNIST的训练数据 我们将用一个简
  • Win7下安装Ubuntu(双硬盘)的简要步骤

    0 硬件准备 一个至少4G大小的U盘 xff0c 用于刻录Ubuntu系统并安装 1 下载Ubuntu镜像及刻录 Ubuntu镜像 Ubuntu镜像可从官网下载 xff08 外网 xff0c 速度太慢 xff09 xff0c 或使用国内镜像
  • C++ Primer Plus拾遗

    本博文整理了C 43 43 Primer Plus前六章中的部分知识点 xff0c 一般为不常用的小技巧或基础概念性的内容 C与C 43 43 的语言特性 C语言特性 结构化编程 xff08 Structured Programming x
  • 时隔一年,对全国大学生智能车竞赛做段总结(五)

    早期粗糙的赛道元素处理 说这个没有别的意思 xff0c 就是觉得 xff0c 遇到实际应用上的问题 xff0c 虽然脑海里的知识技巧并不能让我们有多高明的手法去解决这个问题 xff0c 但也要努力去尝试 元素判断 这里的元素判断也是粗糙的
  • Windows7 VMware USB Arbitration Service启动失败解决

    转自 http huxiaodan666 blog 163 com blog static 162090542201091014749373 前几日安装了Windows7 xff0c 不过vmware虚拟机安装之后却无法使用usb 软件是官
  • Windows下以太坊公钥加密功能python实现

    文章目录 一 什么是公钥 私钥 地址二 实现过程1 从keystore文件中解出私钥以及私钥 gt 公钥 gt 地址2 利用公钥进行消息加密 解密 一 什么是公钥 私钥 地址 私钥 xff1a 32字节 xff08 256位 xff09 x
  • fatal error: mav_msgs/Actuators.h: 没有那个文件或目录

    编译ros gz包的时候 xff0c ros ign bridge一直报错 xff0c 最开始都已经放弃了 xff0c 但是今天发现不得不跑 xff0c 唉 xff0c 一直报 xff1a fatal error mav msgs Actu
  • stalled和Initial connection偶尔请求时间长

    Queueing 请求排队的时间 关于这个 xff0c 需要知道一个背景 xff0c 就是浏览器与同一个域名建立的TCP连接数是有限制的 xff0c chrome设置的6个 xff0c 如果说同一时间 xff0c 发起的同一域名的请求超过了
  • 自制stm32F103c6t6出现No target connected或者Internal command error的原因猜测和解决方法

    刚刚焊好的最小系统板 xff0c 在使用ST LINK下载程序的时候 xff0c 发现没有啥问题 xff0c 之后再下载的时候便出现了这样的问题 xff0c 怀疑是单片机供电出现了问题 xff0c 但是每个脚都供好了电 xff0c 网上说可
  • QEMU来创建一个,[教程在这]。

    RASPBERRY PI ON QEMU Let s start setting up a Lab VM We will use Ubuntu and emulate our desired ARM versions inside of i