28
28
from provisioningserver.boot.install_bootloader import install_bootloader
29
from provisioningserver.utils import atomic_symlink
31
# Bootloader file names to install.
31
32
BOOTLOADERS = ['pxelinux.0', 'chain.c32', 'ifcpu64.c32']
33
BOOTLOADER_DIR = '/usr/lib/syslinux'
34
# Possible locations in which to find the bootloader files. Search these
35
# in this order for each file. (This exists because locations differ
36
# across Ubuntu releases.)
37
BOOTLOADER_DIRS = ['/usr/lib/syslinux', '/usr/lib/syslinux/modules/bios']
39
# List of possible directories where to find additioning bootloader files.
40
# The first existing directory will be symlinked to /syslinux/ inside
41
# the TFTP root directory.
43
# Location for syslinux version 6 (the version in Utopic).
44
'/usr/lib/syslinux/modules/bios',
45
# Location for syslinux version 4 (the version in Trusty).
107
121
namespace = self.compose_template_namespace(kernel_params)
108
122
return BytesReader(template.substitute(namespace).encode("utf-8"))
124
def locate_bootloader(self, bootloader):
125
"""Search BOOTLOADER_DIRS for bootloader.
127
:return: The full file path where the bootloader was found, or None.
129
for dir in BOOTLOADER_DIRS:
130
filename = os.path.join(dir, bootloader)
131
if os.path.exists(filename):
135
def locate_syslinux_dir(self):
136
"""Search for an existing directory among SYSLINUX_DIRS."""
137
for bootloader_dir in SYSLINUX_DIRS:
138
if os.path.exists(bootloader_dir):
139
return bootloader_dir
110
142
def install_bootloader(self, destination):
111
"""Installs the required files for PXE booting into the
143
"""Installs the required files and symlinks into the tftproot."""
114
144
for bootloader in BOOTLOADERS:
115
bootloader_src = os.path.join(BOOTLOADER_DIR, bootloader)
145
# locate_bootloader might return None but happy to let that
146
# traceback here is it should never happen unless there's a
147
# serious problem with packaging.
148
bootloader_src = self.locate_bootloader(bootloader)
116
149
bootloader_dst = os.path.join(destination, bootloader)
117
150
install_bootloader(bootloader_src, bootloader_dst)
152
# Create /syslinux/ symlink. PXE linux tries this subdirectory
153
# when trying to fetch files for PXE-booting.
154
bootloader_dir = self.locate_syslinux_dir()
155
if bootloader_dir is not None:
157
bootloader_dir, os.path.join(destination, 'syslinux'))