Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.

Commit 8aa705b

Browse files
committed
Added support for PXE booting HVM guests using the --pxe command line arg
1 parent 19e4cd3 commit 8aa705b

6 files changed

Lines changed: 80 additions & 8 deletions

File tree

man/en/virt-install.1

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
.\" ========================================================================
130130
.\"
131131
.IX Title "VIRT-INSTALL 1"
132-
.TH VIRT-INSTALL 1 "2007-07-15" "perl v5.8.8" "User Contributed Perl Documentation"
132+
.TH VIRT-INSTALL 1 "2007-09-11" "perl v5.8.8" "Virtual Machine Install Tools"
133133
.SH "NAME"
134134
virt\-install \- provision new virtual machines
135135
.SH "SYNOPSIS"
@@ -334,7 +334,13 @@ path to an \s-1ISO\s0 image, or to a \s-1CDROM\s0 device. It can also be a \s-1U
334334
to fetch/access a minimal boot \s-1ISO\s0 image. The URLs take the same format as
335335
described for the \f(CW\*(C`\-\-location\*(C'\fR argument. If this parameter is omitted then
336336
the \f(CW\*(C`\-\-location\*(C'\fR argument must be given to specify a location for the kernel
337-
and initrd.
337+
and initrd, or the \f(CW\*(C`\-\-pxe\*(C'\fR argument used to install from the network.
338+
.IP "\-\-pxe" 4
339+
.IX Item "--pxe"
340+
Use the \s-1PXE\s0 boot protocol to load the initial ramdisk and kernel for starting
341+
the guest installation process. If this parameter is omitted then either the
342+
\&\f(CW\*(C`\-\-location\*(C'\fR or \f(CW\*(C`\-\-cdrom\*(C'\fR arguments must be given to specify a location for
343+
the kernel and initrd.
338344
.IP "\-\-os\-type=OS_TYPE" 4
339345
.IX Item "--os-type=OS_TYPE"
340346
Optimize the guest configuration for a type of operating system. This will

man/en/virt-install.pod

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,14 @@ path to an ISO image, or to a CDROM device. It can also be a URL from which
240240
to fetch/access a minimal boot ISO image. The URLs take the same format as
241241
described for the C<--location> argument. If this parameter is omitted then
242242
the C<--location> argument must be given to specify a location for the kernel
243-
and initrd.
243+
and initrd, or the C<--pxe> argument used to install from the network.
244+
245+
=item --pxe
246+
247+
Use the PXE boot protocol to load the initial ramdisk and kernel for starting
248+
the guest installation process. If this parameter is omitted then either the
249+
C<--location> or C<--cdrom> arguments must be given to specify a location for
250+
the kernel and initrd.
244251

245252
=item --os-type=OS_TYPE
246253

virt-install

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ def parse_args():
248248
parser.add_option("-c", "--cdrom", type="string", dest="cdrom",
249249
action="callback", callback=cli.check_before_store,
250250
help=_("File to use a virtual CD-ROM device for fully virtualized guests"))
251+
parser.add_option("", "--pxe", action="store_true", dest="pxe",
252+
help=_("Boot an installer from the network using the PXE boot protocol"))
251253
parser.add_option("", "--os-type", type="string", dest="os_type",
252254
action="callback", callback=cli.check_before_store,
253255
help=_("The OS type for fully virtualized guests, e.g. 'linux', 'unix', 'windows'"))
@@ -367,15 +369,24 @@ def main():
367369
print >> sys.stderr, _("LiveCD installations are not supported for paravirt guests")
368370
sys.exit(1)
369371
installer = virtinst.LiveCDInstaller(type = type)
372+
elif options.pxe:
373+
installer = virtinst.PXEInstaller(type = type)
370374
else:
371375
installer = virtinst.DistroInstaller(type = type)
372376

377+
if (options.pxe and options.location) or (options.location and options.cdrom) or (options.cdrom and options.pxe):
378+
print >> sys.stderr, _("Only one of --pxe, --location and --cdrom can be used")
379+
sys.exit(1)
380+
373381
if hvm:
374382
# Xen only supports CDROM
375383
if type == "xen":
376384
installer.cdrom = True
377385
guest = virtinst.FullVirtGuest(connection=conn, installer=installer, arch=options.arch)
378386
else:
387+
if options.pxe:
388+
print >> sys.stderr, _("Network PXE boot is not support for paravirtualized guests")
389+
sys.exit(1)
379390
guest = virtinst.ParaVirtGuest(connection=conn, installer=installer)
380391

381392
# now let's get some of the common questions out of the way
@@ -400,7 +411,8 @@ def main():
400411
get_paravirt_extraargs(options.extra, guest)
401412
continue_inst = False
402413
else:
403-
get_fullvirt_cdrom(options.cdrom, options.location, guest)
414+
if not options.pxe:
415+
get_fullvirt_cdrom(options.cdrom, options.location, guest)
404416
if options.noacpi:
405417
guest.features["acpi"] = False
406418
if options.noapic:

virtinst/DistroManager.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,3 +720,49 @@ def post_install_check(self, guest):
720720
buf = os.read(fd, 512)
721721
os.close(fd)
722722
return len(buf) == 512 and struct.unpack("H", buf[0x1fe: 0x200]) == (0xaa55,)
723+
724+
725+
726+
class PXEInstaller(Guest.Installer):
727+
def __init__(self, type = "xen", location = None, boot = None, extraargs = None):
728+
Guest.Installer.__init__(self, type, location, boot, extraargs)
729+
730+
def prepare(self, guest, meter, distro = None):
731+
pass
732+
733+
def _get_osblob(self, install, hvm, arch = None, loader = None):
734+
osblob = ""
735+
if install or hvm:
736+
osblob = "<os>\n"
737+
738+
if hvm:
739+
type = "hvm"
740+
else:
741+
type = "linux"
742+
743+
if arch:
744+
osblob += " <type arch='%s'>%s</type>\n" % (arch, type)
745+
else:
746+
osblob += " <type>%s</type>\n" % type
747+
748+
if loader:
749+
osblob += " <loader>%s</loader>\n" % loader
750+
751+
if install:
752+
osblob += " <boot dev='network'/>\n"
753+
else:
754+
osblob += " <boot dev='hd'/>\n"
755+
756+
osblob += " </os>"
757+
else:
758+
osblob += "<bootloader>/usr/bin/pygrub</bootloader>"
759+
760+
return osblob
761+
762+
def post_install_check(self, guest):
763+
# Check for the 0xaa55 signature at the end of the MBR
764+
fd = os.open(guest.disks[0].path, os.O_RDONLY)
765+
buf = os.read(fd, 512)
766+
os.close(fd)
767+
return len(buf) == 512 and struct.unpack("H", buf[0x1fe: 0x200]) == (0xaa55,)
768+

virtinst/FullVirtGuest.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,10 @@ def validate_parms(self):
198198
Guest.Guest.validate_parms(self)
199199

200200
def _prepare_install(self, meter):
201-
self._installer.prepare(guest = self,
202-
meter = meter,
203-
distro = self.os_distro)
201+
if self.location or self.cdrom:
202+
self._installer.prepare(guest = self,
203+
meter = meter,
204+
distro = self.os_distro)
204205

205206
def get_continue_inst(self):
206207
if self.os_type is not None:

virtinst/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ def _virtinst(msg):
1212
from Guest import Guest, VirtualDisk, VirtualNetworkInterface, XenGuest, XenDisk, XenNetworkInterface
1313
from FullVirtGuest import FullVirtGuest
1414
from ParaVirtGuest import ParaVirtGuest
15-
from DistroManager import DistroInstaller
15+
from DistroManager import DistroInstaller, PXEInstaller
1616
from LiveCDInstaller import LiveCDInstaller
1717
from ImageManager import ImageInstaller

0 commit comments

Comments
 (0)