ubuntu-18.04.2-desktop-amd64.sh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/usr/bin/env bash
  2. # Copied from https://github.com/cirosantilli/linux-cheat/commit/d3f524e59b2d3042de2daee46a0ae241e2a16766
  3. # Tested on: Ubuntu 18.10.
  4. # https://askubuntu.com/questions/884534/how-to-run-ubuntu-16-04-desktop-on-qemu/1046792#1046792
  5. set -eux
  6. id=ubuntu-18.04.2-desktop-amd64
  7. OPTIND=1
  8. while getopts i: OPT; do
  9. case "$OPT" in
  10. i)
  11. id="$OPTARG"
  12. ;;
  13. esac
  14. done
  15. shift "$(($OPTIND - 1))"
  16. disk_img="${id}.img.qcow2"
  17. disk_img_snapshot="${id}.snapshot.qcow2"
  18. iso="${id}.iso"
  19. # Get image.
  20. if [ ! -f "$iso" ]; then
  21. wget "http://releases.ubuntu.com/18.04/${iso}"
  22. fi
  23. # Go through installer manually.
  24. if [ ! -f "$disk_img" ]; then
  25. qemu-img create -f qcow2 "$disk_img" -o size=9G
  26. qemu-system-x86_64 \
  27. -cdrom "$iso" \
  28. -drive "file=${disk_img},format=qcow2" \
  29. -enable-kvm \
  30. -m 2G \
  31. -smp 2 \
  32. ;
  33. fi
  34. # Snapshot the installation.
  35. if [ ! -f "$disk_img_snapshot" ]; then
  36. qemu-img \
  37. create \
  38. -b "$disk_img" \
  39. -f qcow2 \
  40. "$disk_img_snapshot" \
  41. ;
  42. fi
  43. # Run the installed image.
  44. qemu-system-x86_64 \
  45. -drive "file=${disk_img_snapshot},format=qcow2" \
  46. -enable-kvm \
  47. -m 2G \
  48. -serial mon:stdio \
  49. -smp 2 \
  50. -soundhw hda \
  51. -vga virtio \
  52. "$@" \
  53. ;