5

I've installed Ubuntu 16.04 Desktop on QEMU, but now when I start it with:

qemu-system-i386 -m 1024M -enable-kvm -drive file=./ubuntu-desktop.img,index=0,media=disk,format=raw

I see this picture: enter image description here

Whats going on? How can I fix this?

  • 1
    try -hda rather than -drive and remove all the extra options with drive. Just pass the hard disk file. – user595510 Feb 17 '17 at 23:20
  • Is it possible to use libvirt? – Kong Chun Ho Jun 15 '18 at 8:06
7

Working Ubuntu 18.04 setup

Tested in an Ubuntu 18.10 host.

enter image description here

ubuntu-18.04.1-desktop-amd64.sh

#!/usr/bin/env bash

set -eux

# Parameters.
id=ubuntu-18.04.1-desktop-amd64
disk_img="${id}.img.qcow2"
disk_img_snapshot="${id}.snapshot.qcow2"
iso="${id}.iso"

# Get image.
if [ ! -f "$iso" ]; then
  wget "http://releases.ubuntu.com/18.04/${iso}"
fi

# Go through installer manually.
if [ ! -f "$disk_img" ]; then
  qemu-img create -f qcow2 "$disk_img" 1T
  qemu-system-x86_64 \
    -cdrom "$iso" \
    -drive "file=${disk_img},format=qcow2" \
    -enable-kvm \
    -m 2G \
    -smp 2 \
  ;
fi

# Snapshot the installation.
if [ ! -f "$disk_img_snapshot" ]; then
  qemu-img \
    create \
    -b "$disk_img" \
    -f qcow2 \
    "$disk_img_snapshot" \
  ;
fi

# Run the installed image.
qemu-system-x86_64 \
  -drive "file=${disk_img_snapshot},format=qcow2" \
  -enable-kvm \
  -m 2G \
  -smp 2 \
  -soundhw hda \
  -vga virtio \
  "$@" \
;

GitHub upstream.

This script will do two QEMU runs:

  • first an installation run. Gets kipped if already done.
  • then a regular boot

The fist time QEMU comes up

  • Install Ubuntu
  • continue, continue, continue...
  • wait a few minutes
  • at the end "Restart now"
  • now you can close the QEMU window

The installer looks like this:

enter image description here

After the install is complete, the script automatically takes a snapshot, and starts a regular boot.

Anytime you want to go back to the pristine install, just remove the snapshot and re-run the script:

rm ubuntu-18.04-desktop-amd64.snapshot.qcow2
./ubuntu-18.04.1-desktop-amd64.sh

and the snapshot will be re-generated starting from the clean install.

The snapshot only stores the diffs between the original image, and so it does not take a lot of disk space.

This setup has by default a funky system that automatically resizes the guest resolution to best fit the QEMU window size, just either:

  • drag the window with the mouse
  • toggle fullscreen with Ctrl + Alt + F or or start QEMU with -full-screen

Notes:

Related: https://unix.stackexchange.com/questions/108122/installing-ubuntu-13-0-desktop-in-qemu

Tested on an Ubuntu 18.04 host, QEMU 1:2.11+dfsg-1ubuntu7.3, nvidia-384 version 390.48-0ubuntu3, Lenovo ThinkPad P51, NVIDIA Corporation GM107GLM [Quadro M1200 Mobile] GPU.

Prebuilt bootable images

If you want an image that boots without the need for any interaction on the installer, see: Is there any prebuilt QEMU Ubuntu image(32bit) online?

Server

The exact same procedure as mentioned for desktop also worked for the server image.

I just wasn't able to do the initial install with -nogrphic to get rid of the GUI entirely: How to boot and install the Ubuntu server image on QEMU -nographic without the GUI?

But after the initial boot, after editing GRUB configs I achieve that: How to get to the GRUB menu at boot-time using serial console?

However, for the most part, you will likely just want to use the cloud image instead of the server image with emulation, as it does not have the interactive installer, and is usable from the CLI by default.

0

Installation steps described (by Ciro )worked for me. The cmd line used in script worked fine, But I had to use other options which were causing boot issues after that (booting stops showing storage blocks info)

-vga cirrus helped finally (max 1280 x 1024 resolution). I have nvidia GPU on host with dual monitor setup. Not sure what was causing issue. Also -vga std and -vga virtio didn't work.

Host OS = 16.4 LTS & Guest OS = 18.4.2 LTS

sudo ./x86_64-softmmu/qemu-system-x86_64 -m 8196 -M q35,accel=kvm,kernel-irqchip=split -cpu host -smp 8 -drive file=~/qemu/ubuntu-18.04.2-desktop-amd64.img.qcow2,format=qcow2 -vnc :5 -net nic -net user,hostfwd=tcp::2222-:22 -device intel-iommu,intremap=on **-vga cirrus**

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.