Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
    
Note, cross-posted at stackoverflow.com/q/14349812/90322 –  Jeff Ferland Jan 16 '13 at 1:07
    
KVM has been able to PXE-boot for a very long time now. –  Michael Hampton Jan 16 '13 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. –  Jeff Ferland Jan 16 '13 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. –  Jeff Ferland Jan 16 '13 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. –  Jeff Ferland Jan 16 '13 at 3:57
show 3 more comments

3 Answers 3

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.

share|improve this answer
    
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 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 '13 at 1:13
    
@larsks, Thanks for your answer. I'll try it. If it works for me, I'll accept it. –  Evan Li Jan 16 '13 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? –  Evan Li Jan 16 '13 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 the`isolinux.cfg` file on the iPXE ISO image. –  larsks Jan 16 '13 at 2:51
show 3 more comments

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.

share|improve this answer
add comment
up vote 1 down vote accepted

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.

share|improve this answer
    
What's the line you added? –  Jeff Ferland Jan 18 '13 at 2:12
    
No more added. Just there was a comment asking me to move my final comment to answer. –  Evan Li Jan 18 '13 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. –  Jeff Ferland Jan 18 '13 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. –  Evan Li Jan 18 '13 at 4:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.