Back to Home Back to Notes

Lightweight VM running Linux on macOS

Using xhyve, instead of VirtualBox / VMWare / ...
7th March, 2020
# fetch installer kernel and init image.
curl https://d-i.debian.org/daily-images/amd64/daily/netboot/debian-installer/amd64/linux -o linux-installer
curl https://d-i.debian.org/daily-images/amd64/daily/netboot/debian-installer/amd64/initrd.gz -o initrd.gz-installer

# create disk
dd if=/dev/zero of=disk.img bs=1m count=8192

# generate a UUID that we'll use later to get a fixed IP address.
python -c 'import uuid; print uuid.uuid4()'

# start the installation (set hostname, users, etc.) .... BUT DON'T EXIT!
sudo xhyve -A -H -U 8b6f2ce7-0c59-4e44-91ce-4201cbcad2bd -m 1G -s 0,hostbridge -s 1,lpc -s 2,virtio-blk,disk.img -s 3,virtio-net -l com1,stdio -f "kexec,linux-installer,initrd.gz-installer,earlyprintk=serial console=ttyS0"

########### HOST #############
# retrieve kernel and init image from guest
nc -l 8000 > vmlinuz
nc -l 8000 > initrd.img
########### HOST #############

########### GUEST #############
# drop to root shell, switch to /target/boot
nc 192.168.64.1 8000 < vmlinuz*
nc 192.168.64.1 8000 < initrd.img*
########### GUEST #############

# boot into guest!
sudo xhyve -A -H -U 8b6f2ce7-0c59-4e44-91ce-4201cbcad2bd -m 1G -s 0,hostbridge -s 1,lpc -s 2,virtio-blk,disk.img -s 3,virtio-net -l com1,stdio -f "kexec,vmlinuz,initrd.img,earlyprintk=serial console=ttyS0 root=/dev/vda1"

# final setup in the guest
apt-get install sudo
usermod -aG sudo 
Back to Notes