From 0a9da5af75df1f08446c76c527ad3a3a0e2b50f8 Mon Sep 17 00:00:00 2001 From: name Date: Mon, 15 Jun 2020 04:33:29 +0000 Subject: [PATCH] SSH! Set -e RAM, -e CORES, -e EXTRA QEMU commands. VNC version update to core. --- CREDITS.md | 28 +++++++ Dockerfile | 161 +++++++++++++++++++++++++++++++++-------- README.md | 35 ++++++--- vnc-version/Dockerfile | 14 ++-- 4 files changed, 191 insertions(+), 47 deletions(-) create mode 100644 CREDITS.md diff --git a/CREDITS.md b/CREDITS.md new file mode 100644 index 0000000..597e153 --- /dev/null +++ b/CREDITS.md @@ -0,0 +1,28 @@ +# Credits + +The upstream credits are available at @Kholia's repo https://github.com/kholia/OSX-KVM/blob/master/CREDITS.md + +These credits refer to the contributors to this repository: + +[@GreeFine](https://github.com/GreeFine) - Readme Typo #9 + +[@parasquid](https://github.com/parasquid) - Docker compose file + +[@matusnovak](https://github.com/matusnovak) - Kill badly terminated old vnc session before vnc starts and fix gtk initialization failed #31 + +[@m1k1o](https://github.com/m1k1o) - Kill badly terminated old vnc session before vnc starts and fix gtk initialization failed #31 + +[@qcasey](https://github.com/qcasey) - Removed unnecessary yay in Remove yay dependancy #40 + + + + + + + + + + + + +``` \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 1a05400..0ae04b2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,39 +5,65 @@ # / /_/ / /_/ / /__/ ,< / __/ / / /_/ /___/ / | # /_____/\____/\___/_/|_|\___/_/ \____//____/_/|_| # +# Repo: https://github.com/sickcodes/Docker-OSX/ # Title: Mac on Docker (Docker-OSX) -# Author: Sick.Codes https://sick.codes/ -# Version: 1.0 -# License: GPLv3 +# Author: Sick.Codes https://sick.codes/ +# Version: 2.0 +# License: GPLv3+ # -# All credits for OSX-KVM and the rest at Kholia's repo: https://github.com/kholia/osx-kvm +# All credits for OSX-KVM and the rest at @Kholia's repo: https://github.com/kholia/osx-kvm # OpenCore support go to https://github.com/Leoyzen/KVM-Opencore # and https://github.com/thenickdude/KVM-Opencore/ # # This Dockerfile automates the installation of Docker-OSX -# It will build a 32GB Mojave Disk, you can change the size using build arguments. -# This file builds on top of the work done by Dhiru Kholia and many others. +# It will build a 200GB container. You can change the size using build arguments. +# This Dockerfile builds on top of the work done by Dhiru Kholia, and many others. # # Build: # # docker build -t docker-osx . -# -# docker build -t docker-osx --build-arg VERSION=10.14.6 --build-arg SIZE=200G +# docker build -t docker-osx --build-arg VERSION=10.15.5 --build-arg SIZE=200G . +# +# Basic Run: # -# Run: +# docker run --privileged -e "DISPLAY=${DISPLAY:-:0.0}" -v /tmp/.X11-unix:/tmp/.X11-unix docker-osx +# +# +# Run with SSH: +# +# +# docker run -e RAM=6 --privileged -p 50922:10022 -e "DISPLAY=${DISPLAY:-:0.0}" -v /tmp/.X11-unix:/tmp/.X11-unix docker-osx:latest +# # ssh fullname@localhost -p 50922 +# +# Optargs: # -# docker run --privileged -v /tmp/.X11-unix:/tmp/.X11-unix docker-osx -# +# SIZE=200G +# VERSION=10.15.5 +# ENV RAM=5 +# ENV SMP=4 +# ENV CORES=4 +# ENV EXTRA= +# ENV INTERNAL_SSH_PORT=10022 +# +# Extra QEMU args: +# +# docker run ... -e EXTRA="-usb -device usb-host,hostbus=1,hostaddr=8" ... +# # you will also need to pass the device to the container +# +# +# Other permissions: +# +# docker run --privileged --net host -e "DISPLAY=${DISPLAY:-:0.0}" -e RAM=6 --cap-add=ALL -v /tmp/.X11-unix:/tmp/.X11-unix -v /dev:/dev -v /lib/modules:/lib/modules -v /var/run/libvirt/libvirt-sock:/var/run/libvirt/libvirt-sock docker-osx:latest FROM archlinux:latest MAINTAINER 'https://sick.codes' -# change disk size here or add during build, e.g. --build-arg VERSION=10.14.6 --build-arg SIZE=50G -ARG SIZE=32G -ARG VERSION=10.14.6 +# change disk size here or add during build, e.g. --build-arg VERSION=10.14.5 --build-arg SIZE=50G +ARG SIZE=200G +ARG VERSION=10.15.5 -# This fails on hub.docker.com +# This fails on hub.docker.com, useful for debugging in cloud # RUN [[ $(egrep -c '(svm|vmx)' /proc/cpuinfo) -gt 0 ]] || { echo KVM not possible on this host && exit 1; } WORKDIR /root @@ -46,11 +72,31 @@ RUN tee -a /etc/pacman.conf <<< 'Include = /etc/pacman.d/mirrorlist' RUN pacman -Syu --noconfirm RUN pacman -S sudo git make automake gcc python go autoconf cmake pkgconf alsa-utils fakeroot --noconfirm -RUN useradd arch -RUN echo 'arch ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers +RUN useradd arch -p arch +RUN tee -a /etc/sudoers <<< 'arch ALL=(ALL) NOPASSWD: ALL' RUN mkdir /home/arch RUN chown arch:arch /home/arch +# allow ssh to container +WORKDIR /root +RUN mkdir .ssh +RUN chmod 700 .ssh + +WORKDIR /root/.ssh +RUN touch authorized_keys +RUN chmod 644 authorized_keys + +WORKDIR /etc/ssh +RUN tee -a sshd_config <<< 'AllowTcpForwarding yes' +RUN tee -a sshd_config <<< 'PermitTunnel yes' +RUN tee -a sshd_config <<< 'X11Forwarding yes' +RUN tee -a sshd_config <<< 'PasswordAuthentication yes' +RUN tee -a sshd_config <<< 'PermitRootLogin yes' +RUN tee -a sshd_config <<< 'PubkeyAuthentication yes' +RUN tee -a sshd_config <<< 'HostKey /etc/ssh/ssh_host_rsa_key' +RUN tee -a sshd_config <<< 'HostKey /etc/ssh/ssh_host_ecdsa_key' +RUN tee -a sshd_config <<< 'HostKey /etc/ssh/ssh_host_ed25519_key' + USER arch WORKDIR /home/arch RUN git clone https://github.com/corpnewt/gibMacOS.git @@ -60,31 +106,88 @@ RUN perl -p -i -e 's/print("Succeeded:")/exit()/' ./gibMacOS.command # this command takes a while! RUN python gibMacOS.command -v "${VERSION}" -d || echo Done -RUN sudo pacman -S qemu libvirt dnsmasq virt-manager bridge-utils flex bison ebtables edk2-ovmf --noconfirm +RUN sudo pacman -Syu qemu libvirt dnsmasq virt-manager bridge-utils flex bison ebtables edk2-ovmf netctl libvirt-dbus libguestfs --noconfirm # RUN sudo systemctl enable libvirtd.service # RUN sudo systemctl enable virtlogd.service +# download OSX-KVM WORKDIR /home/arch RUN git clone https://github.com/kholia/OSX-KVM.git -RUN sudo pacman -Syu netctl libvirt-dbus libguestfs --noconfirm - -WORKDIR /home/arch/OSX-KVM -RUN sed -i -e 's/usb-mouse/usb-tablet/g' OpenCore-Boot.sh -RUN chmod +x OpenCore-Boot.sh - +# create disk WORKDIR /home/arch/OSX-KVM RUN qemu-img convert ${HOME}/gibMacOS/macOS\ Downloads/publicrelease/*/BaseSystem.dmg -O raw ${HOME}/OSX-KVM/BaseSystem.img RUN qemu-img create -f qcow2 mac_hdd_ng.img "${SIZE}" -RUN perl -p -i -e \ -'s/-netdev tap,id=net0,ifname=tap0,script=no,downscript=no -device vmxnet3,netdev=net0,id=net0,mac=52:54:00:c9:18:27/-netdev user,id=net0 -device vmxnet3,netdev=net0,id=net0,mac=52:54:00:09:49:17/' \ -./OpenCore-Boot.sh +# enable ssh +# docker exec .... ./enable-ssh.sh +USER arch +RUN touch enable-ssh.sh +RUN chmod +x ./enable-ssh.sh +RUN tee -a enable-ssh.sh <<< '[[ -f /etc/ssh/ssh_host_rsa_key ]] || \' +RUN tee -a enable-ssh.sh <<< '[[ -f /etc/ssh/ssh_host_ed25519_key ]] || \' +RUN tee -a enable-ssh.sh <<< '[[ -f /etc/ssh/ssh_host_ed25519_key ]] || \' +RUN tee -a enable-ssh.sh <<< 'sudo /usr/bin/ssh-keygen -A' +RUN tee -a enable-ssh.sh <<< 'nohup sudo /usr/bin/sshd -D &' + +# QEMU CONFIGURATOR +# set optional ram at runtime -e RAM=16 +# set optional cores at runtime -e SMP=4 -e CORES=2 +# add any additional commands in QEMU cli format -e EXTRA="-usb -device usb-host,hostbus=1,hostaddr=8" + +# default env vars, RUNTIME ONLY, not for editing in build time. + +# > Launch.sh +# > Docker-OSX.xml + +RUN touch Launch.sh +RUN chmod +x ./Launch.sh +RUN tee -a Launch.sh <<< 'qemu-system-x86_64 -enable-kvm -m ${RAM}000 \' +RUN tee -a Launch.sh <<< '-cpu Penryn,kvm=on,vendor=GenuineIntel,+invtsc,vmware-cpuid-freq=on,+pcid,+ssse3,+sse4.2,+popcnt,+avx,+aes,+xsave,+xsaveopt,check \' +RUN tee -a Launch.sh <<< '-machine q35 \' +RUN tee -a Launch.sh <<< '-smp ${SMP},cores=${CORES} \' +RUN tee -a Launch.sh <<< '-usb -device usb-kbd -device usb-tablet \' +RUN tee -a Launch.sh <<< '-device isa-applesmc,osk=ourhardworkbythesewordsguardedpleasedontsteal\(c\)AppleComputerInc \' +RUN tee -a Launch.sh <<< '-drive if=pflash,format=raw,readonly,file=/home/arch/OSX-KVM/OVMF_CODE.fd \' +RUN tee -a Launch.sh <<< '-drive if=pflash,format=raw,file=./OVMF_VARS-1024x768.fd \' +RUN tee -a Launch.sh <<< '-smbios type=2 \' +RUN tee -a Launch.sh <<< '-device ich9-intel-hda -device hda-duplex \' +RUN tee -a Launch.sh <<< '-device ich9-ahci,id=sata \' +RUN tee -a Launch.sh <<< '-drive id=OpenCoreBoot,if=none,snapshot=on,format=qcow2,file=/home/arch/OSX-KVM/OpenCore-Catalina/OpenCore.qcow2 \' +RUN tee -a Launch.sh <<< '-device ide-hd,bus=sata.2,drive=OpenCoreBoot \' +RUN tee -a Launch.sh <<< '-device ide-hd,bus=sata.3,drive=InstallMedia \' +RUN tee -a Launch.sh <<< '-drive id=InstallMedia,if=none,file=BaseSystem.img,format=raw \' +RUN tee -a Launch.sh <<< '-drive id=MacHDD,if=none,file=/home/arch/OSX-KVM/mac_hdd_ng.img,format=qcow2 \' +RUN tee -a Launch.sh <<< '-device ide-hd,bus=sata.4,drive=MacHDD \' +RUN tee -a Launch.sh <<< '-netdev user,id=net0,hostfwd=tcp::${INTERNAL_SSH_PORT}-:22, -device e1000-82545em,netdev=net0,id=net0,mac=52:54:00:09:49:17 \' +RUN tee -a Launch.sh <<< '-monitor stdio \' +RUN tee -a Launch.sh <<< '-vga vmware \' +RUN tee -a Launch.sh <<< '${EXTRA}' -ENV DISPLAY :0.0 ENV USER arch + +ENV RAM=5 +ENV SMP=4 +ENV CORES=4 +ENV EXTRA= +ENV INTERNAL_SSH_PORT=10022 + +# if you're in the shell, export these variables to use then in envsubst +# export RAM=5 +# export SMP=4 +# export CORES=4 +# export EXTRA= +# export INTERNAL_SSH_PORT=10022 + USER arch VOLUME ["/tmp/.X11-unix"] -CMD ./OpenCore-Boot.sh +CMD ./enable-ssh.sh && envsubst < ./Launch.sh | bash +# virt-manager mode: eta son +# CMD virsh define <(envsubst < Docker-OSX.xml) && virt-manager || virt-manager +# CMD virsh define <(envsubst < macOS-libvirt-Catalina.xml) && virt-manager || virt-manager + + +# all perms +# diff --git a/README.md b/README.md index 2d3de52..2dbb5a8 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,7 @@ Run Mac in a Docker container! Run near native OSX-KVM in Docker! X11 Forwarding! - - - -Author: Sick.Codes https://sick.codes/ +Author: Sick.Codes https://sick.codes/ & https://twitter.com/sickcodes Credits: OSX-KVM project among many others: https://github.com/kholia/OSX-KVM/blob/master/CREDITS.md @@ -25,13 +22,13 @@ docker run --privileged -e "DISPLAY=${DISPLAY:-:0.0}" -v /tmp/.X11-unix:/tmp/.X1 # scroll down to troubleshooting if you have problems -# need more RAM? -# try this, change the number 8000, e.g. 8GB: +# need more RAM and SSH on 0.0.0.0:50922? -# docker run --privileged -v /tmp/.X11-unix:/tmp/.X11-unix sickcodes/docker-osx /bin/bash -c "sed -e 's/3072/8000/g' ./OpenCore-Boot.sh | sh -" +docker run -e RAM=6 -p 50922:10022 --privileged-e "DISPLAY=${DISPLAY:-:0.0}" -v /tmp/.X11-unix:/tmp/.X11-unix docker-osx:latest ``` + # Requirements: KVM on the host Need to turn on hardware virtualization in your BIOS, very easy to do. @@ -111,18 +108,23 @@ docker run --privileged -e "DISPLAY=${DISPLAY:-:0.0}" -v /tmp/.X11-unix:/tmp/.X1 ``` Alternative run, thanks @roryrjb + ```docker run --privileged --net host --cap-add=ALL -v /tmp/.X11-unix:/tmp/.X11-unix -v /dev:/dev -v /lib/modules:/lib/modules sickcodes/docker-osx``` Check if your hardware virt is on + ```egrep -c '(svm|vmx)' /proc/cpuinfo``` Try adding yourself to the docker group + ```sudo usermod -aG docker $USER``` Turn on docker daemon + ```sudo nohup dockerd &``` Check /dev/kvm permissions + ```sudo chmod 666 /dev/kvm``` @@ -152,6 +154,7 @@ apt-get install docker-ce docker-ce-cli containerd.io -y sudo dockerd & sudo groupadd docker sudo usermod -aG docker $USER +sudo nohup dockerd & ``` @@ -161,17 +164,18 @@ your image will be stored in: /var/lib/docker/overlay2/...../arch/OSX-KVM/home/arch/OSX-KVM/mac_hdd_ng.img ``` -# find your container's root folder +# note the container id +docker ps +# find your container's root folder docker inspect $(docker ps -q --all --filter "ancestor=docker-osx") | grep UpperDir # In the folder from the above command, your image is inside ./home/arch/OSX-KVM/mac_hdd_ng.img -# then sudo cp it somewhere. Don't do it while the container is running tho, it bugs out. +# then sudo cut it somewhere. Don't do it while the container is running as you might lose data. ``` - # Wipe old images ``` @@ -187,7 +191,7 @@ docker image prune --all # Instant OSX-KVM in a BOX! This Dockerfile automates the installation of OSX-KVM inside a docker container. -It will build a 32GB Mojave Disk. +It will build a Catalina Disk with up to 200GB of space. You can change the size and version using build arguments (see below). @@ -201,7 +205,14 @@ docker build -t docker-osx:latest \ --build-arg VERSION=10.14.6 \ --build-arg SIZE=200G -docker run --privileged -v /tmp/.X11-unix:/tmp/.X11-unix docker-osx:latest +docker run \ +-e RAM=4 \ +-e SMP=4 \ +-e CORES=4 \ +-e EXTRA='-usb -device usb-host,hostbus=1,hostaddr=8' \ +-e INTERNAL_SSH_PORT=23 \ +--privileged -v /tmp/.X11-unix:/tmp/.X11-unix docker-osx:latest + ``` diff --git a/vnc-version/Dockerfile b/vnc-version/Dockerfile index e3e6103..211d6a3 100644 --- a/vnc-version/Dockerfile +++ b/vnc-version/Dockerfile @@ -26,7 +26,7 @@ # # Run: # -# docker run -p 8888:5999 -d --privileged docker-osx-vnc:latest +# docker run -p 8888:5999 -p 50922:10022 -d --privileged docker-osx-vnc:latest # # # Connect locally (safe): @@ -72,7 +72,7 @@ # VNC Version # Let's piggyback the other image: -FROM sickcodes/docker-osx:latest +FROM docker-osx:latest MAINTAINER 'https://sick.codes' @@ -90,11 +90,11 @@ RUN printf '%s\n' \ RUN printf '%s\n%s\n%s\n\n' \ 'export DISPLAY=:99' \ 'vncserver -kill :99 || true' \ -'vncserver -geometry 1920x1080 -depth ${DEPTH:=24} -xstartup ~/.vnc/xstartup :99' > vnc.sh +'vncserver -geometry 1920x1080 -depth ${DEPTH} -xstartup ~/.vnc/xstartup :99' > vnc.sh -RUN cat vnc.sh OpenCore-Boot.sh > OpenCore-Boot_custom.sh +RUN cat vnc.sh Launch.sh > Launch_custom.sh -RUN chmod +x OpenCore-Boot_custom.sh +RUN chmod +x Launch_custom.sh RUN tee vncpasswd_file <<< "${VNC_PASSWORD:=$(openssl rand -hex 4)}" RUN vncpasswd -f < vncpasswd_file > ${HOME}/.vnc/passwd @@ -102,7 +102,9 @@ RUN vncpasswd -f < vncpasswd_file > ${HOME}/.vnc/passwd RUN chmod 600 ~/.vnc/passwd RUN printf '\n\n\n\n%s\n%s\n\n\n\n' '===========VNC_PASSWORD========== ' "$(