I'm working on an OpenStack-based project. Now we need a virtual machine to boot from PXE. I cannot find any document about that. Does nova support PXE boot? If yes, how do I create a KVM image that equivalent is equivalent to a naked machine that would boot from PXE?
You can install ipxe onto a disk and load it using syslinux (or some other bootloader); this will get you something that will behave exactly like a system booted via a PXE BIOS. The iPXE distribution includes tools for building a bootable ISO image, which you could use to boot systems in OpenStack, or you could build a hard disk image with a very similar setup.
Create a disk image:
$ dd if=/dev/zero of=/tmp/boot.img bs=1M count=4
Partition the image:
$ fdisk /tmp/boot.img
You will need to set the number of cylinders.
Create single partition with type
band make it bootable (
ato toggle the boot flag).
Connect the image to a loopback device.
# losetup -fP /tmp/boot.img
Create an msdos filesystem.
# mkdosfs -I /dev/loop0p1
Mount the filesystem.
# mount /dev/loop0p1 /mnt
# syslinux --install /dev/loop0p1
ipxe.krnonto the device (from somewhere...either you've built it yourself or you've copied it from the ipxe ISO).
Create an appropriate syslinux configuration, something like:
DEFAULT ipxe LABEL ipxe KERNEL ipxe.krn
Test it out by booting it on a local KVM instance. Upload it to openstack and boot with it. Note that in this example we've created a very small (4M) disk image, but you could also create a large disk image and then put a small partition on it. It all depends on what you're trying to accomplish.
The surrounding framework of the cloud needs to support passing those options. If you're using the instance-private networking feature, this will constrain you as the current setup doesn't permit passing extra options to the dnsmasq daemon which provides DHCP support. You'd have to modify the source code of the product to provide an interface for PXE options to be entered and appropriate mechanism of passing those options to the underlying dnsmasq process.
However, if you're using a "flat" network and providing your own DHCP service, then yes -- an appropriate boot image supporting PXE can be used and you'll have PXE booting.
The company I work for, Nimbula, uses KVM and DNSmasq the same way as NOVA. At least internally, we use gPXE to launch instances. The disk image has the gPXE loader at the start and the rest is sparse space for the desired size of the volume.
As for uniform support of booting PXE, I'll probably get this into our product for our next minor release cycle, and it's possible that will get ported to NOVA sometime after.
<boot dev=network> tag to XMLs in IceHouse v.2014.1.5, I had to add the line:
Before the code (out of for loop):
for boot_dev in self.os_boot_dev: os.append(etree.Element("boot", dev=boot_dev))
Around line 1195 n /usr/lib/python2.7/dist-packages/nova/virt/libvirt/config.py (I also had to delete config.pyc in the same dir and restart nova service)