Linux distro
download debian-12 for qemu. (this is a distro without gui)
you can download other image media you like, tutorial for iso is flooding with internet, so here I will only talk about the above image.
Boot
qemu-system-x86_64 -m 4G -smp 2 -accel tcg \
-hda /path/to/image/debian-12-nocloud-amd64.qcow2
-m
memory size-smp
set the number of initial CPUs
a window should show up , login use user “root”
Enable ssh
sudo apt-get update
sudo apt-get install openssh-server
sudo systemctl status sshd
quit current window, and run the following command to launch background qemu emulation.
qemu-system-x86_64 -m 4G -smp 2 -accel tcg \
-hda /path/to/image/debian-12-nocloud-amd64.qcow2 \
-net nic -net user,hostfwd=tcp::10022-:22 -daemonize -display none
-net user,hostfwd=tcp::<yout host port>-:22
forward your port to qemu debian’s 22 port
# e.g. ssh root@localhost -p10022
ssh <user>@localhost -p<your host port>
Out of device space
qemu-img resize /path/to/image/debian-12-nocloud-amd64.qcow2 +10G
then extend disk partition inside the guest system, just ask Dr.Google.
To poor kids in mainland China
The default network behavior of qemu is NAT, however, the gateway is qemu builtin, so adding route rules is not a good idea to bypass the GFW. Currently I work on OSX, where I found I cant create a network bridge that links to interface en0 (just on interface for me to choose).
So the left ways to visit west world is
- try other methods to bridge host with guest
- lanuch a proxy inside guest
- intercept and forward all traffic on host
I am as lazy as fuck, so I turned on TUN mode. And good luck for you.
Gnarly issues
- fail to do anything with any such terminal info.
update-initramfs: deferring update (trigger activated)
update-initramfs: Generating /boot/initrd.img-6.1.0-26-amd64
solution:
# some scary warning concerned with kernel will pop up, be brave
sudo apt remove initramfs-tools
sudo apt clean
sudo apt install initramfs-tools