From b7f78be0c3e2b625e962359bad2f74c816d94ae9 Mon Sep 17 00:00:00 2001 From: Mitchel Humpherys Date: Wed, 19 Jun 2019 16:22:43 -0700 Subject: [PATCH 1/2] basic.sh: Get system disk image path from environment Currently users have to modify the basic.sh script by hand to add the path to the system disk image they created. Rather than having them modify the script, just grab it from the environment. --- README.md | 19 +++++++++++-------- basic.sh | 12 ++++++++++++ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 9048901..cda4073 100644 --- a/README.md +++ b/README.md @@ -27,14 +27,17 @@ Create an empty hard disk using `qemu-img`, changing the name and size to prefer qemu-img create -f qcow2 MyDisk.qcow2 64G ``` -and add it to the end of `basic.sh`: -``` - -drive id=SystemDisk,if=none,file=MyDisk.qcow2 \ - -device ide-hd,bus=sata.4,drive=SystemDisk \ -``` -> Note: If you're running on a headless system (such as on Cloud providers), you will need `-nographic` and `-vnc :0 -k en-us` for VNC support. +> 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. Remember to partition in Disk Utility first! +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: + +``` +SYSTEM_DISK=MyDisk.qcow2 ./basic.sh +``` + +Remember to partition in Disk Utility first! ## Step 2a (Virtual Machine Manager) If instead of QEMU, you'd like to import the setup into Virt-Manager for further configuration, just run `make.sh --add`. @@ -43,4 +46,4 @@ If instead of QEMU, you'd like to import the setup into Virt-Manager for further You're done! -To fine-tune the system and improve performance, look in the `docs` folder for more information on [adding memory](docs/guide-performance.md), seting up [bridged networking](docs/guide-networking.md), adding [passthrough hardware (for GPUs)](docs/guide-passthrough.md), and enabling sound features. \ No newline at end of file +To fine-tune the system and improve performance, look in the `docs` folder for more information on [adding memory](docs/guide-performance.md), seting up [bridged networking](docs/guide-networking.md), adding [passthrough hardware (for GPUs)](docs/guide-passthrough.md), and enabling sound features. diff --git a/basic.sh b/basic.sh index 5902877..12343b7 100755 --- a/basic.sh +++ b/basic.sh @@ -6,6 +6,16 @@ OVMF=$VMDIR/firmware #export QEMU_AUDIO_DRV=pa #QEMU_AUDIO_DRV=pa +[[ -z "$SYSTEM_DISK" ]] && { + echo "Please set the SYSTEM_DISK environment variable" + exit 1 +} + +[[ -r "$SYSTEM_DISK" ]] || { + echo "Can't read system disk image: $SYSTEM_DISK" + exit 1 +} + qemu-system-x86_64 \ -enable-kvm \ -m 2G \ @@ -26,3 +36,5 @@ qemu-system-x86_64 \ -device ide-hd,bus=sata.2,drive=ESP \ -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 From 98f1453fd147ad836b9b17fd6cdad4a1bd01bb81 Mon Sep 17 00:00:00 2001 From: Mitchel Humpherys Date: Wed, 19 Jun 2019 16:28:56 -0700 Subject: [PATCH 2/2] 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[@]}