Skip to content

Instantly share code, notes, and snippets.

@eirikb
Last active May 18, 2018 07:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eirikb/4e23d0972098f3a4ffc2e2efc8e878ee to your computer and use it in GitHub Desktop.
Save eirikb/4e23d0972098f3a4ffc2e2efc8e878ee to your computer and use it in GitHub Desktop.
Host VDI / VMDK (VirtualBox images) directly over PXE (Network boot).

PXE Boot VDI/VMDK over network

This is an example script of how to host VDI / VMDK (VirtualBox images) directly over PXE (Network boot).  
Example relies on LTSP.  

Client

Can be any distro, but requires ltsp-client-core, example with Debian:

sudo apt-get -y install ltsp-client-core
sudo /usr/share/ltsp/update-kernel

If testing/building with VirtualBox remember to properly shutdown the machine (shutdown -h now).

If you want DHCP from a second interface, this should do the trick upon boot inside the PXE client:

 sudo ip route del default
 sudo ip link set up dev enp0s3
 sudo dhclient enp0s3

install.sh

Run the install.sh-file on a Debian (tested on 9) box, VirtualBox should work fine. enp0s8 is the second interface on my vbox test, you probably have to change this. Both server and client supports multiple interfaces.

#!/usr/bin/env bash
sudo apt-get -y install ltsp-server-standalone qemu-utils
sudo modprobe nbd
sudo qemu-nbd -c /dev/nbd0 -P 1 ~/client.vdi
sudo mkdir -p /opt/ltsp/images
sudo ln -s /dev/nbd0 /opt/ltsp/images/amd64.img
sudo chown nbd /opt/ltsp/images/amd64.img
# Force ltsp-update-kernels to recognize symbolic links
sudo sed -i 's/ -f / -e /g' /usr/sbin/ltsp-update-kernels
# Mount and un-mount for unknown reason (or else ltsp-update-kernel will throw "cannot mount: /dev/loop0 read-only)
sudo mount /dev/nbd0 /mnt
sudo umount /mnt
sudo ltsp-update-kernels amd64
sudo ltsp-config dnsmasq --no-proxy-dhcp
sudo tee -a /etc/nbd-server/config <<EOF
[/opt/ltsp/amd64]
exportname = /opt/ltsp/images/amd64.img
EOF
sudo ip link set up dev enp0s8
sudo ip addr add 192.168.67.1/24 dev enp0s8
sudo systemctl restart dnsmasq
sudo systemctl restart nbd-server
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment