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?

Shane Madden
  • 112,982
  • 12
  • 174
  • 248
TieDad
  • 264
  • 5
  • 13
  • Note, cross-posted at http://stackoverflow.com/q/14349812/90322 – Jeff Ferland Jan 16 '13 at 01:07
  • KVM has been able to PXE-boot for a very long time now. – Michael Hampton Jan 16 '13 at 01: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. – Jeff Ferland Jan 16 '13 at 01:14
  • Hi @JeffFerland, do you mean that current nova doesn't support PXE boot? Could you give me some hint how to implement that? Thanks. – TieDad Jan 16 '13 at 01:23
  • 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. – Jeff Ferland Jan 16 '13 at 01:28
  • @JeffFerland dnsmasq serves as a DHCP server. In my project, the DHCP server is out side of the openstack. I just want my VM to initiate PXE boot. When we run "nova boot", we have to give "--image" option, so I think I must create a kvm image that is equivalent to a naked machine that has a PXE rom. In my case, do I still need to modify code as you mentioned? Could openstack support that already? – TieDad Jan 16 '13 at 03:54
  • 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. – Jeff Ferland Jan 16 '13 at 03:57
  • @JeffFerland Thanks again for your answer. Now my problem is how to the create the "appropriate boot image supporting PXE". I don't know how to create such a KVM image. Do you have any suggestion? Do you feel IPXE would work for me? – TieDad Jan 16 '13 at 04:20

4 Answers4

5

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.

larsks
  • 41,276
  • 13
  • 117
  • 170
  • Doesn't the PXE process need appropriate DHCP options? Unless OpenStack's system allows setting those parameters, I'm not sure this will help. – Jeff Ferland Jan 16 '13 at 01: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 '13 at 01:13
  • @larsks, Thanks for your answer. I'll try it. If it works for me, I'll accept it. – TieDad Jan 16 '13 at 01: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 '13 at 02: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 the`isolinux.cfg` file on the iPXE ISO image. – larsks Jan 16 '13 at 02:51
  • Something like [this](http://dl.dropbox.com/u/1405733/boot.img). – larsks Jan 16 '13 at 03:19
  • After more investigation, I found that things is not so difficult. We just need to modify nova code to add one line "" in the vm configure xml file. Because nova uses libvirt, and libvirt supports PXE boot already. Anyway, thanks for everybody's help. – TieDad Jan 17 '13 at 01:35
  • @EvanLi Please post your answer as an answer, since that's what it is. – Michael Hampton Jan 17 '13 at 22:51
  • @larsks, The links are dead. And this answer is the only non intrusive way i have seen for doing pxe in nova. Can you somehow fix it like add the content in the links in the answer itself instead of links. – The_Lost_Avatar Jun 29 '18 at 23:24
  • This makes it boot as a BIOS machine, is there any way to make it for UEFI? – djuarez Oct 22 '19 at 15:37
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.

TieDad
  • 264
  • 5
  • 13
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.

Jeff Ferland
  • 20,239
  • 2
  • 61
  • 85
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)