Skip to content

Instantly share code, notes, and snippets.

@ynwd
Created May 26, 2023 03:46
Show Gist options
  • Save ynwd/13a95bb5dd657ab720997a1ffa0504ed to your computer and use it in GitHub Desktop.
Save ynwd/13a95bb5dd657ab720997a1ffa0504ed to your computer and use it in GitHub Desktop.
Macos, Qemu and Debian

Install homebrew

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Install QEMU and other required packages:

brew install qemu

Download iso

wget https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-11.7.0-amd64-netinst.iso

Create a disk image for the debian server

qemu-img create -f qcow2 debian-11.7.0-amd64-netinst.qcow2 20G

Install server

qemu-system-x86_64 -hda debian-11.7.0-amd64-netinst.qcow2 -boot d -cdrom debian-11.7.0-amd64-netinst.iso -m 2048

Run server

qemu-system-x86_64 -hda debian-11.7.0-amd64-netinst.qcow2 -m 2048
@ynwd
Copy link
Author

ynwd commented May 26, 2023

To access SSH, you must run qemu with port forwarding args

qemu-system-x86_64 -hda debian-11.7.0-amd64-netinst.qcow2 -m 2048 -net nic -net user,hostfwd=tcp::2222-:22

Now you can SSH from macos:

ssh -p 2222 dev@localhost

@ynwd
Copy link
Author

ynwd commented May 26, 2023

When -nographic is specified, no graphical window is created

qemu-system-x86_64 -hda debian-11.7.0-amd64-netinst.qcow2 -m 2048 -net nic -net user,hostfwd=tcp::2222-:22 -nographic

@ynwd
Copy link
Author

ynwd commented May 27, 2023

if you want to access SSH without port forwarding, try this

sudo qemu-system-x86_64 -hda debian-11.7.0-amd64-netinst.qcow2 -m 2048 -nic vmnet-bridged,ifname=en0

@ynwd
Copy link
Author

ynwd commented May 27, 2023

you can make debian load faster with additional args

sudo qemu-system-x86_64 -hda debian-11.7.0-amd64-netinst.qcow2 -nic vmnet-bridged,ifname=en0 -M accel=hvf -cpu host -smp cpus=8 -m 2048

-M accel=hvf specifies the use of the Hypervisor.framework framework, which is only valid on macos platforms

-smp cpus=8 specifies that the guest machine should have 8 virtual CPUs

@ynwd
Copy link
Author

ynwd commented May 27, 2023

Screenshot 2023-05-27 at 20 20 17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment