qemu网络

主要参考 https://wiki.qemu.org/Documentation/Networking

qemu网络分为后端和前端。

backends是在qemu里设置,如下面的-netdev user, 指定了user类型的backends, 并且讲本地的5555端口和guest上22绑定,如此可以使用ssh root@localhost -p 5555来登录guest.
另外尝试过自编译的qemu-system-aarch64启动,报错qemu-system-aarch64: -netdev user,id=net0,hostfwd=tcp::5555-:22: network backend 'user' is not compiled into this binary,也就是后端支持需要qemu里源码修改。

sudo qemu-system-aarch64 -m 1024 -cpu cortex-a57 -M virt -nographic -smp 4 -kernel ~/software/linux/arch/arm64/boot/Image -append "noinintrd sched_debug root=/dev/vda rootfstype=ext4 rw crashkernel=256M loglevel=8" -drive if=none,file=linux_rootfs.ext4,id=hd0 -device virtio-blk-device,drive=hd0 -device e1000,netdev=net0 -netdev user,id=net0,hostfwd=tcp::5555-:22

User Networking is implemented using "slirp", which provides a full TCP/IP stack within QEMU and uses that stack to implement a virtual NAT'd network.
user网络类型是通过slirp实现,它在qemu内部提供了完整的TCP/IP栈来实现一个虚拟的网络设备


Note that from inside the guest, connecting to a port on the "gateway" IP address will connect to that port on the host; so for instance "ssh 10.0.2.2" will ssh from the guest to the host.
用户网络默认配置情况如上图,通过对gateway的IP访问,可以访问host机器。

User networking默认配置后,可以访问网页,apt-get都可以工作,但ping不行(即使有ping工具也不行)。因为只仿真了TCP/IP, 没有仿真ICMP.

qemu中的文件系统映射到真实的linux_rootfs.exe4这个磁盘文件,在qemu里面修改文件退出qemu,文件的内容可以固化到磁盘的linux_rootfs.exe4中,这点和docker启动后的tmpfs不一样。

qemu执行安装程序

qemu -cdrom类似在系统中插入了一个安装磁盘,其中的mini.iso可以,-vnc在qemu中启动一个vnc server,client连接之后可以完成系统安装。

2024-06-30$ qemu-system-x86_64 -netdev user,id=net0,hostfwd=tcp::5900-:5900 -device e1000,netdev=net0  -m 1024 -smp 4 -hda ubuntu.img -cdrom mini.iso  -serial mon:stdio -vnc 0.0.0.0:0

安装完之后再启动就直接从硬盘读取boot,而不用再指定kernel+rootfs的形式。ubuntu.img中除了我们开机后看到的文件系统,还有kernel的内容。

qemu-system-x86_64 -m 1024 -smp 4 -hda ubuntu.img  -serial mon:stdio -vnc 0.0.0.0:0

qemu 9pfs 共享文件

使用9pfs进行mount, 其中linux构建内核默认9p选项已经开启。

#host上
sudo virtfs-proxy-helper -p $PWD/test2 -s /tmp/vhostqemu -u zwl -g zwl

sudo qemu-system-aarch64 -m 1024 -cpu cortex-a57 -M virt -nographic -smp 4 \
-kernel ~/software/linux/arch/arm64/boot/Image -append "noinintrd sched_debug root=/dev/vda rootfstype=ext4 rw crashkernel=256M loglevel=8" -drive if=none,file=linux_rootfs.ext4,id=hd0 -device virtio-blk-device,drive=hd0 \
-virtfs local,path=/home/zwl/work/daily/2024-07-02,mount_tag=myfs,security_model=mapped-xattr

# 启动的guest上
sudo mount -t 9p -o trans=virtio myfs daily/

qemu 运行android virtwifi设置

https://blog.csdn.net/ldwyr2004/article/details/124490630

posted @ 2024-06-28 08:20  zwlwf  阅读(9)  评论(0编辑  收藏  举报