QEMU Tips

The usage of QEMU is not always straightforward. The use case here is starting yet another Linux server on a ssh-ed Linux server.

Updated on 2019-11-18

https://graspingtech.com/ubuntu-desktop-18.04-virtual-machine-macos-qemu/

  1. Install

    $ qemu-system-x86_64 -m 2048 -cdrom ubuntu-19.10-desktop-amd64.iso \
      -drive file=ubuntu.qcow2 -accel hvf
    
  2. Run

    $ qemu-system-x86_64 -m 2048 -vga virtio -show-cursor \
      -drive file=./ubuntu.qcow2,if=virtio -accel hvf \
      -cdrom ubuntu-19.10-desktop-amd64.iso \
      -net user,hostfwd=tcp::2222-:22 -net nic
    

Summary of the tips is followed.

  1. By default, QEMU uses VGA display and expect X Windows.
  2. QEMU can work with ncurses and without X Windows. But it may fail.

The steps I have tried are listed below.

  1. ssh to the existing Linux server.

    $ ssh dev
    
  2. Install qemu

    $ sudo yum install qemu
    
  3. Download the minimal Ubuntu or Desktop.

    $ wget http://archive.ubuntu.com/ubuntu/dists/bionic/main/installer-amd64/current/images/netboot/mini.iso
    
    $ wget http://releases.ubuntu.com/19.10/ubuntu-19.10-desktop-amd64.iso
    
  4. Create the image, which is empty.

    $ qemu-img create -f qcow2 mini.qcow2 100G
    
  5. Try to start the empty image.

    $ qemu-system-x86_64 mini.qcow2 
    

    The qemu process exit with some errors, like.

    ** (qemu-system-x86_64:18015): WARNING **: Could not open X display
    

    Add -curses to let QEMU run without X Windows,

    $ qemu-system-x86_64 -curses mini.qcow2
    

    It try to boot the system and failed as expected.

    <snipped>
    Boot failed: not a bootable disk
        
    Booting from Floppy...
    Boot failed: could not read the boot disk
        
    Booting from DVD/CD...
    Boot failed: Could not read from CDROM (code 0003)
    Booting from ROM...
    iPXE (PCI 00:03.0) starting execution...ok
    iPXE initialising devices...ok
        
    iPXE 1.0.0+ (c4bce43) -- Open Source Network Boot Firmware -- http://ipxe.org
    Features: iSCSI HTTP DNS TFTP AoE bzImage ELF MBOOT PXE Menu PXEXT
        
    net0: 52:54:00:12:34:56 using 82540em on PCI00:03.0 (open)
    [Link:up, TX:0 TXE:0 RX:0 RXE:0]
    DHCP (net0 52:54:00:12:34:56)............... ok
    net0: 10.0.2.15/255.255.255.0 gw 10.0.2.2
    Nothing to boot: No such file or directory (http://ipxe.org/2d03e13b)
    No more network devices
        
    No bootable device.
    
  6. Try to boot the image with the iso, but it still failed.

    $ qemu-system-x86_64 -curses -hda mini.qcow2 -boot d -cdrom mini.iso
    

    Unfortunately, the screen print several lines of logs, then stop with “640 x 480 Graphic mode”, if input with some key stokes, it blinks and then changed to “800 x 600 Graphic mode”.

  7. But it can boot a existing DOS image.

    Download https://github.com/palmercluff/qemu-images/tree/master/ms-dos-7.10, and extract it with 7zip.

    $ qemu-system-i386 -curses -hda ms-dos-7.10.qcow2
    

    DOS

    Unfortunately, the latest QEMU installed on macOS can’t run the same command. And report an error.

    DOS

  8. Finally, I have to make X Windows ready.

    Then run the command without ncurses.

    $ qemu-system-x86_64 -hda mini.qcow2 -boot d -cdrom mini.iso
    

    Ubuntu

Note: The screenshots were taken on macOS.

[ VM , QEMU ]
Written on March 20, 2019