From 98f1453fd147ad836b9b17fd6cdad4a1bd01bb81 Mon Sep 17 00:00:00 2001 From: Mitchel Humpherys Date: Wed, 19 Jun 2019 16:28:56 -0700 Subject: [PATCH] basic.sh: Add support for HEADLESS mode via environment Currently if a user wants to run in headless mode they have to edit the basic.sh script by hand. Rather than making them edit the script by hand, add support for a HEADLESS environment variable which can be set to 1 to add necessary command line arguments to qemu. --- README.md | 9 +++++++-- basic.sh | 9 ++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index cda4073..6263ae9 100644 --- a/README.md +++ b/README.md @@ -27,8 +27,6 @@ Create an empty hard disk using `qemu-img`, changing the name and size to prefer qemu-img create -f qcow2 MyDisk.qcow2 64G ``` -> Note: If you're running on a headless system (such as on Cloud providers), you will need to add `-nographic` and `-vnc :0 -k en-us` (for VNC support) to the end of `basic.sh`. - Then run `basic.sh` to start the machine and install macOS, setting the `SYSTEM_DISK` environment variable to the path to your freshly created system disk image: @@ -37,6 +35,13 @@ system disk image: SYSTEM_DISK=MyDisk.qcow2 ./basic.sh ``` +If you're running on a headless system (such as on Cloud providers), set +the `HEADLESS` environment variable to 1: + +``` +SYSTEM_DISK=MyDisk.qcow2 HEADLESS=1 ./basic.sh +``` + Remember to partition in Disk Utility first! ## Step 2a (Virtual Machine Manager) diff --git a/basic.sh b/basic.sh index 12343b7..0b8263a 100755 --- a/basic.sh +++ b/basic.sh @@ -16,6 +16,12 @@ OVMF=$VMDIR/firmware exit 1 } +MOREARGS=() + +[[ "$HEADLESS" = "1" ]] && { + MOREARGS+=(-nographic -vnc :0 -k en-us) +} + qemu-system-x86_64 \ -enable-kvm \ -m 2G \ @@ -37,4 +43,5 @@ qemu-system-x86_64 \ -drive id=InstallMedia,if=none,file=BaseSystem.img \ -device ide-hd,bus=sata.3,drive=InstallMedia \ -drive id=SystemDisk,if=none,file="${SYSTEM_DISK}" \ - -device ide-hd,bus=sata.4,drive=SystemDisk + -device ide-hd,bus=sata.4,drive=SystemDisk \ + ${MOREARGS[@]}