Creating PXE bootable Virtualbox VMs

February 24, 2021 – Samuli Seppänen

We use Vagrant and Virtualbox heavily when developing Puppet code. We also do provisioning of baremetal servers with Foreman. While Vagrant is a really powerful tool, it is not designed for creating VMs that boot from the network (PXE boot). Fortunately Virtualbox itself provides a rich command-line with which you can create and configure virtual machines and configure them to boot from the network. It is assumed below that there is a PXE boot server (e.g. Foreman) created into a hostonly network with Vagrant. Here's an example script that create a VM with vboxmanage and adds it the same hostonly network interface (vboxnet15) as the PXE boot server:

#!/bin/sh
vboxmanage createvm --name "pxetest" --ostype RedHat_64 --register
vboxmanage modifyvm pxetest --description "PXEboot test (CentOS 7)" --memory 2048 --cpus 1 --boot1 net --nic1 hostonly --hostonlyadapter1 vboxnet15 --macaddress1 080027fbad17
vboxmanage createmedium disk --filename pxeboot-disk.vdi --size 8192
vboxmanage storagectl pxetest --name "SATA" --add sata --bootable on
vboxmanage storageattach pxetest --storagectl "SATA" --port 1 --type hdd --medium pxeboot-disk.vdi
vboxmanage startvm pxetest

Using the same hostonly network allows the two machine, PXE boot server and PXE boot client, to talk to each other.

To tear down the PXE boot client VM:

#!/bin/sh
vboxmanage controlvm pxetest poweroff
sleep 2
vboxmanage unregistervm pxetest --delete
sleep 2
vboxmanage closemedium pxeboot-disk.vdi --delete

The "sleep" command seem necessary because the vboxmanage commands exit before they have finished.

Want to talk to an expert?

If you want to reach us, just send us a message or book a free call!
Categories

Tags

#aad #Access #acl #alertmanager #ansible #ansible module development #Apache #API #augeas #authentication #authorization #automation #automatization #aws #azure #backup #bash #bitbucket #buildbot #cache #centos #cloud #cloud-init #cloudflare #cloudfront #cluster #connectionsJpa #control repo #custom fact #database #debian #devops #digital sovereignty #DNS #docker #domain mode #duplo #ejabberd #email #encryption #erb #europe #eyaml #fabric #facter #facts #fargate #fedora #file #finnish #foreman #freeipa #git #github #gitlab #gnome #google #grafana #hammer #hiera #IAM #import #infinispan #Infrastructure as Code #ipmi #irc #jboss #jdk #jenkins #JMESPath #kanban #keycloak #librarian-puppet #librenms #linkedin #Linux #Location #loop #marketing #mautic #Mellon #mfa #monitoring #mysql #nagios #network-manager #oauth #oauth2 #office365 #open source #openvpn #oxygen #packer #paranormal #pdk #people #php #pkcs7 #pomodoro #Powershell #preseed #presentation #profiles #prometheus #provisioning #puppet #puppet-bolt #puppet-litmus #puppetboard #puppetdb #Puppetfile #puppetserver #puppet types and providers #pxeboot #qemu #quality #r10k #recruitment #redirect #Restrict #Reverse Proxy #roles #rspec #ruby #SAML #sem #shell #showsql #snmp #snmpd #software developement #spam #ssh #sso #standardization #systemd #systemd-resolved #teams #terraform #ubuntu #user-data #vagrant #vanity awards #variable #vim #virtualbox #visualstudio #webdevelopment #wildfly #Windows #wireguard #wordpress #workflow #x11 #xmpp #zimbra
We are
 Puppeteers
menucross-circle