3

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?

8
  • Note, cross-posted at stackoverflow.com/q/14349812/90322 Jan 16, 2013 at 1:07
  • KVM has been able to PXE-boot for a very long time now. Jan 16, 2013 at 1:11
  • 1
    @MichaelHampton The surrounding framework of the cloud needs to support passing those options, though. I'm working on implementing that in a related product that uses KVM, actually. Jan 16, 2013 at 1:14
  • 1
    @EvanLi 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. Jan 16, 2013 at 1:28
  • 1
    @EvanLi 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. Jan 16, 2013 at 3:57

4 Answers 4

6

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.

  1. Create a disk image:

    $ dd if=/dev/zero of=/tmp/boot.img bs=1M count=4
    
  2. Partition the image:

    $ fdisk /tmp/boot.img
    
  3. You will need to set the number of cylinders.

  4. Create single partition with type b and make it bootable (n to create, a to toggle the boot flag).

  5. Connect the image to a loopback device.

    # losetup -fP /tmp/boot.img
    
  6. Create an msdos filesystem.

    # mkdosfs -I /dev/loop0p1
    
  7. Mount the filesystem.

    # mount /dev/loop0p1 /mnt
    
  8. Install syslinux.

    # syslinux --install /dev/loop0p1
    
  9. Copy ipxe.krn onto the device (from somewhere...either you've built it yourself or you've copied it from the ipxe ISO).

  10. 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.

10
  • Doesn't the PXE process need appropriate DHCP options? Unless OpenStack's system allows setting those parameters, I'm not sure this will help. Jan 16, 2013 at 1:11
  • You can override any DHCP options with an ipxe script, if necessary (which can be passed in by the bootloader, or embedded in the ipxe binary). Whether or not this is appropriate really depends on what the OP is trying to do.
    – larsks
    Jan 16, 2013 at 1:13
  • @larsks, Thanks for your answer. I'll try it. If it works for me, I'll accept it.
    – TieDad
    Jan 16, 2013 at 1:26
  • @larsks, I just took look at ipxe web site. It gives a procedure of booting machine from ipxe iso, then boot from pxe using ipxe command line. What I want is to create a kvm image which will be used to boot vm from pxe in openstack. Could you give me a more detailed guide how to do that?
    – TieDad
    Jan 16, 2013 at 2:27
  • Sure. Grab the iPXE ISO, which uses isolinux. Create a KVM disk image and format it with a FAT filesystem, install syslinux, and create a configuration that is largely identical to theisolinux.cfg file on the iPXE ISO image.
    – larsks
    Jan 16, 2013 at 2:51
2

After more investigation, I found that things is not so difficult. We just need to modify nova code to add one line

<boot dev=network>

in the vm configure xml file. Because nova uses libvirt, and libvirt supports PXE boot already. Anyway, thanks for everybody's help.

5
  • What's the line you added? Jan 18, 2013 at 2:12
  • No more added. Just there was a comment asking me to move my final comment to answer.
    – TieDad
    Jan 18, 2013 at 3:12
  • What I'm saying is that this doesn't tell anybody else who looks at your question how they might solve the problem for themselves. Jan 18, 2013 at 3:43
  • ahh... sorry, I didn't notice that copy-paste caused the line I added didn't show in the answer. I have edited my answer.
    – TieDad
    Jan 18, 2013 at 4:23
  • The question wasn't "How to change the source code of nova to use libvirt's netboot support?" Jul 28, 2014 at 21:12
1

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.

0

To add <boot dev=network> tag to XMLs in IceHouse v.2014.1.5, I had to add the line:

    os.append(etree.Element("boot", dev='network'))

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)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .