Skip to contentSkip to conversation

gPXE fw_cfg file interface support

RFC In review Stefan Hajnoczi 3 participants 4 messages Jan 27, 2010 – Feb 8, 2010

lore
Share & tools
lore
#0 lore raw

RFC 1/1 gPXE fw_cfg file interface support

This patch makes it possible for gPXE under QEMU/KVM to fetch files from the host using the fw_cfg file interface. This means gPXE in the guest can fetch an exposed file from the host without using networking.

I believe this feature will be useful to management software so that network boot
configuration can be managed alongside with the virtual machine configuration, not on a remote TFTP server.

Any interest in this feature? I imagine libvirt could use this to set up iSCSI or
other network boot settings.

Images are fetched from the hypervisor using the fw_cfg interface provided by QEMU/KVM. The URI syntax is as follows:

gPXE> imgfetch fw_cfg:genroms/static.gpxe

where 'fw_cfg' is the new URI scheme this patch adds and 'genroms/static.gpxe' is the filename exported from QEMU/KVM via the fw_cfg interface.

Note that the URI uses a single colon ':', not '://', since there is no hostname.

Current QEMU/KVM builds can be (ab)used to expose arbitrary files like this:

qemu -option-rom path/to/file [...]

The file will appear as 'genroms/file'. Use the 'fw_cfg:genroms/file' URI to reference it in gPXE.

The fw_cfg file interface is a recent addition to QEMU/KVM. You may need to build QEMU/KVM from source in order to get this feature.

Note that this patch only adds the fw_cfg file interface mechanism, it does not automatically probe for a special file when gPXE starts. You will need to manually
"chain fw_cfg:genroms/file".

Any comments?

Stefan

From 586b7502ebf3dcfe5ab315052446c6b10bb2637e Mon Sep 17 00:00:00 2001
From: Stefan Hajnoczi <[email protected]>
Date: Thu, 14 Jan 2010 08:55:38 +0000
Subject: [PATCH] [fw_cfg] Support fetching files from QEMU fw_cfg

This patch adds support for fetching files from the QEMU fw_cfg file interface, which exposes a set of files on the host into the guest. Virtual machine netboot configuration can be maintained by a management layer on the host. This feature makes virtual machine deployment via gPXE more flexible.

URIs are in the form "fw_cfg:<filename>", where <filename> is the name of the file exposed via fw_cfg. Note that there are no double slashes after the "fw_cfg:".

---
 src/arch/i386/Makefile               |    1 +
 src/arch/i386/firmware/qemu/fw_cfg.c |  300 ++++++++++++++++++++++++++++++++++
 src/arch/i386/include/bits/errfile.h |    1 +
 src/config/config.c                  |    3 +
 src/config/general.h                 |    1 +
 5 files changed, 306 insertions(+), 0 deletions(-)
 create mode 100644 src/arch/i386/firmware/qemu/fw_cfg.c
src/arch/i386/Makefile +1 -0
index dd8da80..6ddb86a 100644
@@ -75,6 +75,7 @@ ISOLINUX_BIN	= /usr/lib/syslinux/isolinux.bin
 #
 SRCDIRS		+= arch/i386/core arch/i386/transitions arch/i386/prefix
 SRCDIRS		+= arch/i386/firmware/pcbios
+SRCDIRS		+= arch/i386/firmware/qemu
 SRCDIRS		+= arch/i386/image
 SRCDIRS		+= arch/i386/drivers
 SRCDIRS		+= arch/i386/drivers/net
src/arch/i386/firmware/qemu/fw_cfg.c new file +300 -0

300 lines not on this page · raw message

src/arch/i386/include/bits/errfile.h +1 -0
index 32b8a08..849cdc0 100644
@@ -15,6 +15,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
 #define ERRFILE_biosint		( ERRFILE_ARCH | ERRFILE_CORE | 0x00040000 )
 #define ERRFILE_int13		( ERRFILE_ARCH | ERRFILE_CORE | 0x00050000 )
 #define ERRFILE_pxeparent	( ERRFILE_ARCH | ERRFILE_CORE | 0x00060000 )
+#define ERRFILE_fw_cfg		( ERRFILE_ARCH | ERRFILE_CORE | 0x00070000 )
 
 #define ERRFILE_bootsector     ( ERRFILE_ARCH | ERRFILE_IMAGE | 0x00000000 )
 #define ERRFILE_bzimage	       ( ERRFILE_ARCH | ERRFILE_IMAGE | 0x00010000 )
src/config/config.c +3 -0
index 8252402..8023e41 100644
@@ -127,6 +127,9 @@ REQUIRE_OBJECT ( tftm );
 #ifdef DOWNLOAD_PROTO_SLAM
 REQUIRE_OBJECT ( slam );
 #endif
+#ifdef DOWNLOAD_PROTO_FW_CFG
+REQUIRE_OBJECT ( fw_cfg );
+#endif
 
 /*
  * Drag in all requested SAN boot protocols
src/config/general.h +1 -0
index f721f61..3fff9ef 100644
@@ -61,6 +61,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
 #undef	DOWNLOAD_PROTO_TFTM	/* Multicast Trivial File Transfer Protocol */
 #undef	DOWNLOAD_PROTO_SLAM	/* Scalable Local Area Multicast */
 #undef	DOWNLOAD_PROTO_FSP	/* FSP? */
+#undef	DOWNLOAD_PROTO_FW_CFG	/* QEMU fw_cfg file interface */
 
 /*
  * SAN boot protocols
Signature · 1 line
1.6.5
#1 lore raw
Quoted 1 line

gPXE> imgfetch fw_cfg:genroms/static.gpxe

Neat idea. On the qemu side we better shouldn't abuse the -option-rom switch though as seabios will try to load these files as option roms.

Quoted 4 lines

Note that this patch only adds the fw_cfg file interface mechanism, it does not automatically probe for a special file when gPXE starts. You will need to manually
"chain fw_cfg:genroms/file".

That should be changed too IMHO. qemu needs some kind of new switch, so you can place the firmware file into some other virtual directory where gpxe could look by default, i.e. something like "fw_cfg:gpxe/default". Then you can easily have qemu guests netboot from somewhere without any local pxe/tftp setup, like this:

qemu -fw-file gpxe/default=bko.gpxe

with bko.gpxe being:

#!gpxe
dhcp net0
set 209:string pxelinux.cfg/default
set 210:string http://boot.kernel.org/bko/
chain http://boot.kernel.org/bko/pxelinux.0

cheers,
Gerd

#2 lore raw
Quoted 14 lines · Gerd Hoffmann
Quoted 5 lines

Note that this patch only adds the fw_cfg file interface mechanism, it does not
automatically probe for a special file when gPXE starts.  You will need to manually
"chain fw_cfg:genroms/file".

That should be changed too IMHO.  qemu needs some kind of new switch, so you can place the firmware file into some other virtual directory where gpxe could look by default, i.e. something like "fw_cfg:gpxe/default". Then you can easily have qemu guests netboot from somewhere without any local pxe/tftp setup, like this:

 qemu -fw-file gpxe/default=bko.gpxe

Quoted 7 lines

with bko.gpxe being:

 #!gpxe
 dhcp net0
 set 209:string pxelinux.cfg/default
 set 210:string http://boot.kernel.org/bko/
 chain http://boot.kernel.org/bko/pxelinux.0

That sounds good. I will send out a new patch which fetches fw_cfg:gpxe/default on startup.

Stefan

#3 lore raw
In reply to Gerd Hoffmann
Quoted 6 lines · Gerd Hoffmann

...Then you can easily have qemu guests netboot from somewhere without any local pxe/tftp setup, like this:

qemu -fw-file gpxe/default=bko.gpxe

That looks a bit like:

# qemu -kernel gpxe.lkrn -initrd bko.gpxe -hda /dev/null

which might be useful iff the *.lkrn build target feature for using an initrd as a gPXE startup script is incorporated into gPXE mainline. Of course, it's different because an .lkrn is not a ROM.

- Shao Miller