Skip to content

Instantly share code, notes, and snippets.

@josuesasilva
Forked from aserhat/0 - setup
Created November 9, 2020 19:02
Show Gist options
  • Save josuesasilva/a331f951463178621a38f95cd80eb37c to your computer and use it in GitHub Desktop.
Save josuesasilva/a331f951463178621a38f95cd80eb37c to your computer and use it in GitHub Desktop.
QEMU and HVF
# Summary
A few notes I took to see if I could use MacOS as Hypevirsor in a similar fashion to Linux
I wanted to see how few addons were needed instead of using Parallels, Virtual Box, VM Fsion etc.
The idea is to use QEMU, Hypervisor Framework (https://developer.apple.com/documentation/hypervisor) and some custom host networking.
# Installations
brew install qemu (For controlling Hypervisor Framework)
brew install cdrtools (For making cloud init iso's)
http://tuntaposx.sourceforge.net/download.xhtml (For customer tap based networking)
# Helpful Links (Mostly for the networking stuff)
https://davidhamann.de/2017/04/19/sharing-vpn-on-macos/
https://github.com/ckujau/scripts/blob/master/qemu-tap.sh
https://superuser.com/questions/596095/how-do-i-bridge-a-connection-from-wi-fi-to-tap-on-mac-os-x-for-the-emulator-qe
https://blog.san-ss.com.ar/2016/04/setup-nat-network-for-qemu-macosx
https://linuxconfig.org/how-to-configure-static-ip-address-on-ubuntu-18-04-bionic-beaver-linux
https://www.techrepublic.com/article/how-to-configure-a-static-ip-address-in-ubuntu-server-18-04/
http://osxdaily.com/2015/06/24/load-unload-kernel-extensions-mac-os-x/
#Static Builds
## Creata disk
qemu-img create -f qcow2 server1.img 10G
## Install the OS onto the disk
qemu-system-x86_64 -M accel=hvf --cpu host -hda server1.img -cdrom ubuntu-18.04.2-live-server-amd64.iso -boot d -m 2048
## Boot the server
qemu-system-x86_64 -M accel=hvf --cpu host server1.img -m 2048
## Boot the server with some custom networking
## This requires some additional configuration on the host to make work.
sudo qemu-system-x86_64 -M accel=hvf --cpu host server1.img -m 2048 -netdev tap,id=tap0,script=no,downscript=no -device e1000,netdev=tap0
## This requires some scripts at /etc/qemu-ifup and /etc/qemu-ifdown
sudo qemu-system-x86_64 -M accel=hvf --cpu host server1.img -m 2048 -net nic,model=virtio -net tap,br=/dev/bridge1,id=tap0
# Cloud Based Images
## Create the meta-data and user-data files (samples are the other files in this gist)
## Create the init iso
mkisofs -output init.iso -volid cidata -joliet -rock {user-data,meta-data}
## Boot the cloud image
qemu-system-x86_64 -M accel=hvf --cpu host -hda ubuntu-18.04-server-cloudimg-amd64.img --cdrom init.iso -boot d -m 2048
## Working on making this work with custom networking this was a pain to do without having ssh access to login to the server and test stuff out.
## Once the network is all settled I can work on headless most and some automation to bring up and down the VM's via Ansible.
# sample cloud init meta-data file, everything below this line.
instance-id: k8sm1
local-hostname: k8sm1
# sample cloud init user-data file, everything below this line.
#cloud-config
#obviously for demo purposes only, would want to inject ssh keys here.
#sets the ubuntu user password, root user password and allows password ssh vs key based ssh.
hostname: k8sm1
fqdn: k8sm1
ssh_pwauth: True
password: password
chpasswd:
list: |
root:password
expire: False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment