|
| 1 | +--- |
| 2 | +title: "Set QEMU Networking up on macOS by socket_vmnet" |
| 3 | +date: 2024-05-26T23:14:10+08:00 |
| 4 | +draft: false |
| 5 | +summary: A guide to set QEMU networking up on macOS by socket_vmnet. |
| 6 | +tags: ["QEMU", "macOS", "socket_vmnet"] |
| 7 | +categories: ["English"] |
| 8 | +--- |
| 9 | + |
| 10 | +The previous post [Run Ubuntu in QEMU on macOS (Apple Silicon)](/post/qemu-macos-apple-silicon/) instructed us how to |
| 11 | +set QEMU networking up by [vde_vmnet](https://github.com/lima-vm/vde_vmnet). However, the |
| 12 | +[vde_vmnet](https://github.com/lima-vm/vde_vmnet) was deprecated. This post is a guide to set QEMU networking up by the |
| 13 | +successor [socket_vmnet](https://github.com/lima-vm/socket_vmnet). |
| 14 | + |
| 15 | +# Prerequisite |
| 16 | + |
| 17 | +1. ubuntu-24.04-live-server-arm64.iso |
| 18 | +2. QEMU >= 9.0 |
| 19 | +3. [socket_vmnet](https://github.com/lima-vm/socket_vmnet) >= 1.1.4 |
| 20 | +4. macOS >= Sonoma (Apple Silicon) |
| 21 | + |
| 22 | +## Preparation |
| 23 | + |
| 24 | +```shell |
| 25 | +# Download the Ubuntu live cd from the official website. |
| 26 | +# https://ubuntu.com/download/server/arm |
| 27 | + |
| 28 | +# Install QEMU by Homebrew. |
| 29 | +brew install qemu |
| 30 | + |
| 31 | +# Install socket_vmnet. |
| 32 | +brew install socket_vmnet |
| 33 | + |
| 34 | +# Install the launchd service |
| 35 | +brew tap homebrew/services |
| 36 | +# sudo is necessary for the next line |
| 37 | +sudo brew services start socket_vmnet |
| 38 | +``` |
| 39 | + |
| 40 | +## Test |
| 41 | + |
| 42 | +```shell |
| 43 | +ping 192.168.105.1 |
| 44 | +``` |
| 45 | + |
| 46 | +If the test is failed, try to restart the service by the following command. |
| 47 | + |
| 48 | +```shell |
| 49 | +sudo brew services restart socket_vmnet |
| 50 | +``` |
| 51 | + |
| 52 | +# Install Ubuntu |
| 53 | + |
| 54 | +1. Download QEMU EFI. |
| 55 | + |
| 56 | + ```shell |
| 57 | + curl -L https://releases.linaro.org/components/kernel/uefi-linaro/latest/release/qemu64/QEMU_EFI.fd -o QEMU_EFI.fd |
| 58 | + |
| 59 | + ``` |
| 60 | + |
| 61 | +2. Create an image. |
| 62 | + |
| 63 | + ```shell |
| 64 | + qemu-img create -f raw -o preallocation=full ubuntu.img 40G |
| 65 | + ``` |
| 66 | + |
| 67 | +3. Boot QEMU to install Ubuntu. |
| 68 | + |
| 69 | + ```shell |
| 70 | + socket_vmnet_client /opt/homebrew/var/run/socket_vmnet \ |
| 71 | + qemu-system-aarch64 \ |
| 72 | + -machine virt,accel=hvf \ |
| 73 | + -cpu host \ |
| 74 | + -smp 8 \ |
| 75 | + -m 8G \ |
| 76 | + -device virtio-net-pci,netdev=net0 -netdev socket,id=net0,fd=3 \ |
| 77 | + -drive if=virtio,format=raw,file=./ubuntu.img \ |
| 78 | + -cdrom <path/to/ubuntu iso> \ |
| 79 | + -nographic \ |
| 80 | + -bios QEMU_EFI.fd |
| 81 | + ``` |
| 82 | + |
| 83 | +# Boot Ubuntu in QEMU |
| 84 | + |
| 85 | +```shell |
| 86 | +socket_vmnet_client /opt/homebrew/var/run/socket_vmnet \ |
| 87 | + qemu-system-aarch64 \ |
| 88 | + -machine virt,accel=hvf \ |
| 89 | + -cpu host \ |
| 90 | + -smp 8 \ |
| 91 | + -m 8G \ |
| 92 | + -device virtio-net-pci,netdev=net0 -netdev socket,id=net0,fd=3 \ |
| 93 | + -drive if=virtio,format=raw,file=./ubuntu.img \ |
| 94 | + -nographic \ |
| 95 | + -bios QEMU_EFI.fd |
| 96 | +``` |
| 97 | + |
| 98 | +# Log into the server by SSH |
| 99 | + |
| 100 | +```shell |
| 101 | +ssh 192.168.105.2 |
| 102 | +``` |
0 commit comments