sickcodes / Docker-OSX

Run macOS VM in a Docker! Run near native OSX-KVM in Docker! X11 Forwarding! CI/CD for OS X Security Research! Docker mac Containers.
https://hub.docker.com/r/sickcodes/docker-osx
GNU General Public License v3.0
45.36k stars 2.4k forks source link

[Question] Automated ci/cd pipeline with no display? #83

Closed GrabbenD closed 3 years ago

GrabbenD commented 3 years ago

Is there any way to build/perform a full installation of the container with no display to make it fully automated?

Thanks in advance for any help with this.

sickcodes commented 3 years ago

Yes, using the VNC version.

@jviotti knows how to setup the auto boot to correct disk, I'm not sure how.

You can write a an xdotool script to format the disk first too or can use hfsprogs to make the disks

jviotti commented 3 years ago

@sickcodes @xRiot The trick is to create a custom OpenCore image (https://github.com/kholia/OSX-KVM/blob/master/OpenCore-Catalina/OpenCore.qcow2) that boots in the way you want it to boot. Docker-OSX loads this image here: https://github.com/sickcodes/Docker-OSX/blob/master/Dockerfile#L156-L157

&& tee -a Launch.sh <<< '-drive id=OpenCoreBoot,if=none,snapshot=on,format=qcow2,file=/home/arch/OSX-KVM/OpenCore-Catalina/OpenCore.qcow2 \' \
&& tee -a Launch.sh <<< '-device ide-hd,bus=sata.2,drive=OpenCoreBoot \' \

You can tweak OpenCore's config.plist (https://github.com/kholia/OSX-KVM/blob/master/OpenCore-Catalina/config.plist) and re-build it using this script: https://github.com/kholia/OSX-KVM/blob/master/OpenCore-Catalina/opencore-image-ng.sh.

These are some of the settings you might be interested in: https://github.com/kholia/OSX-KVM/blob/master/OpenCore-Catalina/config.plist#L520-L529

<key>PickerMode</key>
<string>External</string>
<key>PollAppleHotKeys</key>
<true/>
<key>ShowPicker</key>
<true/>
<key>TakeoffDelay</key>
<integer>0</integer>
<key>Timeout</key>
<integer>0</integer>

You can find the docs here: https://github.com/acidanthera/OpenCorePkg/blob/master/Docs/Configuration.pdf

GrabbenD commented 3 years ago

Thanks a lot for the information @jviotti @sickcodes!

I can see that there's a display being exported in the VNC version. Would it be possible to entirely drop rendering of the desktop to save resources? I'm looking into only using SSH to access the container post installation.

sickcodes commented 3 years ago

Maybe try booting into the recovery disk, it has a terminal, I haven't tried automating it tho.

sickcodes commented 3 years ago

@jviotti Thanks for uploading that mate! I will add that second auto-booter next week unless someone wants to do a PR 😛

GrabbenD commented 3 years ago

Thanks for the insights @sickcodes!

At the moment the VNC container boots into boot disk selection menu, is there a way to automatically boot into the (predefined/right) disk?

sickcodes commented 3 years ago

Yes there is, @jviotti just explained above that you need to build a custom OpenCore qcow boot disk.

JB-CHAUVIN commented 3 years ago

Hello @sickcodes, have you released the auto-booter option yet? Thanks @jviotti for the tips !!

sickcodes commented 3 years ago

I think this is it:

https://github.com/kholia/OSX-KVM/blob/master/OpenCore-Catalina/OpenCore-nopicker.qcow2

Will have a look later this week

JB-CHAUVIN commented 3 years ago

I think this is it:

https://github.com/kholia/OSX-KVM/blob/master/OpenCore-Catalina/OpenCore-nopicker.qcow2

Will have a look later this week

This is working ! It would be great if you add an option to choose the OpenCore version :)

Thanks for the great work with this tool @sickcodes !

sickcodes commented 3 years ago

Sure, unless someone would like to submit a PR:

docker exec id sed -i -e opencore.qcow to the new version

sickcodes commented 3 years ago

Done! https://github.com/sickcodes/Docker-OSX/commit/81682df5febf936cbadd889b8ec46c73b8d1466e

sickcodes commented 3 years ago

Will work in both VNC and regular containers btw

AdamMomen commented 3 years ago

Thanks for your amazing efforts @sickcodes, I am running this on a VM on the cloud and wanted to make it boot autmatically, so I tried these two commands but did not work yet!

docker exec 260b77373875 mv ./Launch-nopicker.sh ./Launch.sh

# This one didn't work as well
docker exec 260b77373875 bash -c "grep -v InstallMedia ./Launch.sh > ./Launch-nopicker.sh
chmod +x ./Launch-nopicker.sh
sed -i -e s/OpenCore\.qcow2/OpenCore\-nopicker\.qcow2/ ./Launch-nopicker.sh
"

Launch.sh file Content

sudo chown    $(id -u):$(id -g) /dev/kvm 2>/dev/null || true 
sudo chown -R $(id -u):$(id -g) /dev/snd 2>/dev/null || true 
exec qemu-system-x86_64 -m ${RAM:-8}000 \
-cpu Penryn,vendor=GenuineIntel,+invtsc,vmware-cpuid-freq=on,+pcid,+ssse3,+sse4.2,+popcnt,+avx,+aes,+xsave,+xsaveopt,check \
-machine q35,accel=kvm:tcg \
-smp ${SMP:-4},cores=${CORES:-4} \
-usb -device usb-kbd -device usb-tablet \
-device isa-applesmc,osk=ourhardworkbythesewordsguardedpleasedontsteal\(c\)AppleComputerInc \
-drive if=pflash,format=raw,readonly,file=/home/arch/OSX-KVM/OVMF_CODE.fd \
-drive if=pflash,format=raw,file=/home/arch/OSX-KVM/OVMF_VARS-1024x768.fd \
-smbios type=2 \
-audiodev ${AUDIO_DRIVER:-alsa},id=hda -device ich9-intel-hda -device hda-duplex,audiodev=hda \
-device ich9-ahci,id=sata \
#============>This seems okay! <===========
-drive id=OpenCoreBoot,if=none,snapshot=on,format=qcow2,file=/home/arch/OSX-KVM/OpenCore-Catalina/OpenCore-nopicker.qcow2 \
-device ide-hd,bus=sata.2,drive=OpenCoreBoot \
-drive id=MacHDD,if=none,file=/home/arch/OSX-KVM/mac_hdd_ng.img,format=qcow2 \
-device ide-hd,bus=sata.4,drive=MacHDD \
-netdev user,id=net0,hostfwd=tcp::${INTERNAL_SSH_PORT:-10022}-:22,hostfwd=tcp::${SCREEN_SHARE_PORT:-5900}-:5900, -device e1000-82545em,netdev=net0,id=net0,mac=52:54:00:09:49:17 \
-monitor stdio \
-vga vmware \

I am not sure putting container run logs would help here.

@jviotti could you please elaborate more on how to do your approach, I couldn't understand the "create a custom OpenCore image" part. Thanks

2020-11-06-09-38-29 (1)

Edit Running process monitor htop shows that docker or maybe arch-linux didn't update the image yet, I am still trying to figure out how to update it. image

Edit 2 I found the issue, I am using vnc-version docker which uses Launch_custom.sh file instead of Launch.sh

Solution:

docker exec 260b77373875 bash -c "grep -v InstallMedia ./Launch-nopicker.sh > ./Launch_custom.sh
chmod +x ./Launch_custom.sh
sed -i -e s/OpenCore\.qcow2/OpenCore\-nopicker\.qcow2/ ./Launch_custom.sh
"

@sickcodes maybe adding this to the readme so others won't fall into the same mistake I did, thanks.

sickcodes commented 3 years ago

Added in https://github.com/sickcodes/Docker-OSX/commit/a09c565e36d45f6663567b7c4f1402279e725519

See https://github.com/sickcodes/Docker-OSX#quick-start-175gb-pre-made-image