QEMU

Differences between revisions 1 and 19 (spanning 18 versions)
Revision 1 as of 2015-03-13 02:31:26
Size: 931
Editor: dannf
Comment:
Revision 19 as of 2024-04-18 09:13:56
Size: 2839
Editor: sally-makin
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
#refresh 0 https://ubuntu.com/server/docs/boot-arm64-virtual-machines-on-qemu
Line 5: Line 7:
'''Note: this requires Ubuntu 15.04 or greater''' '''Note: this requires Ubuntu 20.04 or greater'''
Line 7: Line 9:
 1. Install QEMU  1. Install QEMU and the EFI image for QEMU:
Line 9: Line 11:
 $ sudo apt-get install qemu-system-aarch64  $ sudo apt-get install qemu-system-arm qemu-efi
Line 11: Line 13:
 1. Get a tianocore UEFI image. Eventually Ubuntu should provide this in a package called qemu-efi (there's one currently in Debian's NEW queue), but for now you can download [[http://releases.linaro.org/15.01/components/kernel/uefi-linaro/release/qemu-intelbds/QEMU_EFI.fd|one from Linaro]].
 1. Now you'll need to create plflash
 
 1.Create a VM-specific flash volume for storing NVRAM variables:
 {{{
 $ cp /usr/share/AAVMF/AAVMF_CODE.fd flash1.img
 }}}
 1. Now you should be able to boot/ into a ''-arm64.img'' type [[http://cloud-images.ubuntu.com|cloud image]].
  a. For accelerated VMs (arm64 host w/ KVM support)
  {{{
  $ sudo qemu-system-aarch64 -enable-kvm -m 1024 -cpu host -M virt -nographic -pflash /usr/share/AAVMF/AAVMF_CODE.fd -pflash flash1.img -drive if=none,file=jammy-server-cloudimg-arm64.img,id=hd0 -device virtio-blk-device,drive=hd0 -netdev type=tap,id=net0 -device virtio-net-device,netdev=net0,mac=$randmac
  }}}
  '''Note: For GICv3 systems, such as Cavium ThunderX, you must use QEMU from Ubuntu 16.04 or newer, and pass "-M virt,gic-version=3". Additionally, you must use a 15.10 (wily) or newer cloud image for guests.'''

  a. For emulated VMs (e.g. x86 host)
  {{{
  $ sudo qemu-system-aarch64 -m 1024 -cpu cortex-a57 -M virt -nographic -pflash /usr/share/AAVMF/AAVMF_CODE.fd -pflash flash1.img -drive if=none,file=jammy-server-cloudimg-arm64.img,id=hd0 -device virtio-blk-device,drive=hd0 -netdev type=tap,id=net0 -device virtio-net-device,netdev=net0,mac=$randmac
  }}}

= Troubleshooting =
== Generate MAC Address ==
In the above command, we use ''randmac'' as a variable of mac address. You may generate it by the following command:

  {{{
  #!/usr/bin/python3

  import random

  def randomMAC():
      return [ 0x00, 0x16, 0x3e,
               random.randint(0x00, 0x7f),
               random.randint(0x00, 0xff),
               random.randint(0x00, 0xff) ]

  def MACprettyprint(mac):
      return ':'.join(map(lambda x: "%02x" % x, mac))

  if __name__ == '__main__':
      print(MACprettyprint(randomMAC()))
  }}}

== No Output and No Response ==
If such thing happens to you, align your host and guest release version may help. For example, if you generated ''flash0.img'' on Focal but want to emulate Jammy with the cloud image of Jammy, the firmware is not fully compatible. Generating ''flash0.img'' on Jammy when emulating Jammy with the cloud image of Jammy may help.
Line 16: Line 55:
https://wiki.linaro.org/LEG/UEFIforQEMU
http://blog.eciton.net/uefi
 * https://wiki.linaro.org/LEG/UEFIforQEMU
 * http://blog.eciton.net/uefi

Ubuntu/arm64 can run inside the QEMU emulator. You can either do this fully emulated (e.g. on an x86 host) or, accelerated w/ KVM if you have an arm64 host. This page describes how to do both.

I've chosen to describe a UEFI-based system here so I can make use of the kernel on the guest's disk image. It is possible to boot directly into Linux instead.

Note: this requires Ubuntu 20.04 or greater

Getting the bits

  1. Install QEMU and the EFI image for QEMU:
     $ sudo apt-get install qemu-system-arm qemu-efi
    1.Create a VM-specific flash volume for storing NVRAM variables:
     $ cp /usr/share/AAVMF/AAVMF_CODE.fd flash1.img
  2. Now you should be able to boot/ into a -arm64.img type cloud image.

    1. For accelerated VMs (arm64 host w/ KVM support)
        $ sudo qemu-system-aarch64 -enable-kvm -m 1024 -cpu host -M virt -nographic -pflash /usr/share/AAVMF/AAVMF_CODE.fd -pflash flash1.img -drive if=none,file=jammy-server-cloudimg-arm64.img,id=hd0 -device virtio-blk-device,drive=hd0 -netdev type=tap,id=net0 -device virtio-net-device,netdev=net0,mac=$randmac

      Note: For GICv3 systems, such as Cavium ThunderX, you must use QEMU from Ubuntu 16.04 or newer, and pass "-M virt,gic-version=3". Additionally, you must use a 15.10 (wily) or newer cloud image for guests.

    2. For emulated VMs (e.g. x86 host)
        $ sudo qemu-system-aarch64 -m 1024 -cpu cortex-a57 -M virt -nographic -pflash /usr/share/AAVMF/AAVMF_CODE.fd -pflash flash1.img -drive if=none,file=jammy-server-cloudimg-arm64.img,id=hd0 -device virtio-blk-device,drive=hd0 -netdev type=tap,id=net0 -device virtio-net-device,netdev=net0,mac=$randmac

Troubleshooting

Generate MAC Address

In the above command, we use randmac as a variable of mac address. You may generate it by the following command:

  •   #!/usr/bin/python3
    
      import random
    
      def randomMAC():
          return [ 0x00, 0x16, 0x3e,
                   random.randint(0x00, 0x7f),
                   random.randint(0x00, 0xff),
                   random.randint(0x00, 0xff) ]
    
      def MACprettyprint(mac):
          return ':'.join(map(lambda x: "%02x" % x, mac))
    
      if __name__ == '__main__':
          print(MACprettyprint(randomMAC()))

No Output and No Response

If such thing happens to you, align your host and guest release version may help. For example, if you generated flash0.img on Focal but want to emulate Jammy with the cloud image of Jammy, the firmware is not fully compatible. Generating flash0.img on Jammy when emulating Jammy with the cloud image of Jammy may help.

References

ARM64/QEMU (last edited 2024-04-18 09:13:56 by sally-makin)