使用brew安装qemu
#安装brew# /bin/bash -c "$(curl -fsSL /Homebrew/install/HEAD/install.sh)"#安装qemubrew install qemu
制作镜像
制作镜像就是制作一个硬盘,相当于其他虚拟机中的分配磁盘空间,这里分配30G。
qemu-img create -f qcow2 ubuntu20.qcow2 30G
安装虚拟机
安装x86系统
下载ubuntu2204:
wget /ubuntu-releases/20.04.3/ubuntu-20.04.3-live-server-amd64.iso
安装虚拟机:
#启动安装qemu-system-x86_64 \-machine type=q35,accel=hvf \-smp 6 \-cpu host \-hda ubuntu20.qcow2 \-m 16G \-vga virtio \-usb \-device usb-tablet \-display default,show-cursor=on \-cdrom ./ubuntu-20.04.3-live-server-amd64.iso
-accel=hvf,hvf就是qemu支持mac os原生hypervisor的选项;
-smp指定guest系统可用的核数;
-hda 是磁盘位置;
-m指定内存大小;
-cdrom是镜像位置;
这时候qemu会弹出安装界面,按照正常流程安装系统即可,这时候可以明显感觉到mac电脑跑虚拟机的安静。
启动虚拟机
qemu-system-x86_64 \-machine type=q35,accel=hvf \-smp 6 \-cpu host \-hda ubuntu20.qcow2 \-m 16G \-vga virtio \-usb \-device usb-tablet \-display default,show-cursor=on -net user,hostfwd=tcp::2222-:22 -net nic
启动时,我们做一下端口转发,我们这里把host的127.0.0.1:2222端口转发到guest的22端口,我们可以使用ssh来连接guest系统。
ssh <username>@127.0.0.1 -p 2222
arm
下载ubuntu-port镜像:
/ubuntu-releases/20.04.4/ubuntu-20.04.4-desktop-amd64.iso
#如果要确保可以下载,提高速度,如果有代-理,可以类似这样操作,#export http_proxy="http://127.0.0.1:8001"; export HTTP_PROXY="http://127.0.0.1:8001"; #export https_proxy="http://127.0.0.1:8001"; export HTTPS_PROXY="http://127.0.0.1:8001"echo "在MacOS上使用QEMU模拟Raspbian(Buster)"echo "安装QEMU:"echo "brew install qemu"echo "下载 qemu-rpi-kernel:"wget /dhruvvyas90/qemu-rpi-kernel/master/kernel-qemu-4.19.50-busterecho "下载 versatile-pb.dtb:"wget /dhruvvyas90/qemu-rpi-kernel/master/versatile-pb.dtbecho "下载树莓派操作系统:"wget /raspbian_lite/images/raspbian_lite--02-14/-02-13-raspbian-buster-lite.zipunzip -02-13-raspbian-buster-lite.zipecho "运行QEMU模拟器"qemu-system-arm -cpu arm1176 -m 256 \-kernel kernel-qemu-4.19.50-buster \-M versatilepb \-dtb versatile-pb.dtb \-no-reboot \-nographic \-append "dwc_otg.lpm_enable=0 root=/dev/sda2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait" \-drive "file=-02-13-raspbian-buster-lite.img,index=0,media=disk,format=raw" \-net user,hostfwd=tcp::22223-:22 -net nicecho "等待ssh登录屏幕出现…"
参考链接:
使用qemu虚拟机运行树莓派(linux kernel 4.9)
QEMU搭建arm32的ubuntu20.04虚拟机
如果觉得《使用Qemu在Mac上安装虚拟机》对你有帮助,请点赞、收藏,并留下你的观点哦!