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
36.13k stars 1.78k forks source link

Automate virtual machine creation #10

Closed awakecoding closed 4 years ago

awakecoding commented 4 years ago

This is more of a feature request: is there a way to automate the initial creation of the virtual machine, without having to manually go through the disk utility and the GUI installation? I'd like to be able to boot the virtual machine once to perform the macOS installation with preconfigured parameters, without the GUI, after which all management could be performed using the built-in macOS SSH and Apple Remote Desktop access.

One more thing: once the VM is created, the boot screen still requires me to select what to boot, is there a way to configure a default such that the VM can fully boot without user intervention? Bonus points if there is a way to configure an auto-login for a macOS user.

sickcodes commented 4 years ago

You can docker launch old versions of the machine using the docker start command in the readme.

You can copy an existing container in its existing state.

You can also docker commit, which solidifies the current container in its current state.

The whole OS is stored in one .img file, info in the readme.

So if you want to launch at the state it was again and again or copies of itself at that state try those.

Regarding the disk partitioning, you can edit the dockerfile to part the disk with parted or something.

Or get a custom img and then replace the qemu 2 img line with a simple wget of the image of your dreams in the state you want it :).

Regarding auto boot, there would certainly be a way. It’s OpenBoot core, so you’d have to look into that, it’s probably as easy as editing an ini file in the boot sector.

awakecoding commented 4 years ago

Alright, I think we can aim for something else then that might be easier: let's create the initial virtual machine manually, bring it up with a default user, auto-login + SSH enabled, and extract the resulting .img as a new base image.

What would be your thoughts on making a new "second-level" Dockerfile that always takes a preinstalled .img file with SSH enabled, auto-login enabled and the built-in username + password known ahead of time? If we can assume that those are already enabled with known values in the image, there might be a way to make a new Dockerfile that executes commands inside this golden image, and apply additional configuration automatically this way. We wouldn't solve the problem of automating the initial virtual machine, but we'd be able to automate the reusing of a golden image.

Dockerfile commands are executed inside the container itself, but there might be a way to preconfigure an authorized SSH key and run commands inside the virtual machine as part of the Dockerfile build steps. If it turns out to be a bit difficult to implement using regular SSH, I'm thinking that PowerShell remoting (runs over SSH, supports macOS) could also be used as part of the process.

Last but not least, do you know how the Dockerfile could be modified not to launch the qemu GUI, and make it 100% headless, making it possible to port map the SSH and ARD ports on the host for direct access this way? I would rather use it 100% "remote" once the initial configuration has been done.

sickcodes commented 4 years ago

Yeah, if you run it using virtual-manager via OSX-KVM

sickcodes commented 4 years ago

I can set up the automated SSH tunnel, VNC, CI/CD method.

I’ll be adding the VNC and/or xrdp methods soon, you can also request me to do work https://sick.codes/contact/ as I do freelance work.