Score:0

how to get internet on qemu + cloudimg?

cn flag

trying to run a cloudimg in qemu, and i haven't found a way to get internet access, help? i've set up the cloudimg with

wget 'https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64-disk-kvm.img';
mkdir -p ./mnt;
sudo guestmount -a jammy-server-cloudimg-amd64-disk-kvm.img -i --rw ./mnt;
sudo chroot ./mnt /bin/passwd --delete root;
sudo umount mnt;

and i'm starting qemu with

sudo qemu-system-x86_64 \
-machine accel=kvm \
-cpu host \
-smp cores=4 \
-m size=1G \
-serial stdio \
-boot menu=on \
-drive media=disk,file=jammy-server-cloudimg-amd64-disk-kvm.img,if=virtio,cache=unsafe,format=qcow2,werror=report

and the system starts, and i can login as root, but it doesn't have internet access, ping saying

root@ubuntu:~# ping 8.8.8.8
ping: connect: Network is unreachable

i have tried granting network access a couple of ways, with

qemu-system-x86_64 -nic user,model=virtio-net-pci

and

qemu-system-x86_64 -nic tap

but it doesn't seem to make a difference, still getting ping: connect: Network is unreachable , and i'm stuck

Christian Ehrhardt avatar
sl flag
I recommend following https://powersj.io/posts/ubuntu-qemu-cli/ which has examples of networking as well.
Score:1
kr flag

This is mainly because the network configuration is missing in the guest OS, and not because of wrong configuration of the VM.

Based on instructions from 1 I had success with the following procedure.

Before starting the VM I stripped cloud-init from it, by running

virt-customize -a bionic-server-cloudimg-amd64.img --uninstall cloud-init

in the host.

Then started the bionic server cloudimg directly with qemu-system-x86_64, passing only this additional option for network

-nic user,hostfwd=tcp::8888-:22

Inside the VM, logged in as root, I had to configure the network with

cd /etc/netplan
nano 01-netcfg.yaml

and then adding this content to the created file

network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s2:
       dhcp4: true

saving and closing it, and then running

netplan --debug apply

After that, ifconfig reported an configured network, and the guest had connection.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.