with open("/etc/os-release") as f:
return util.config_read(f)
+ def open(self, path, *args, **kwargs):
+ """
+ Opens a file inside the environment
+ """
+ # Make the path relative
+ while path.startswith("/"):
+ path = path[1:]
+
+ # Make the path relative to the root directory
+ path = os.path.join(self.root, path)
+
+ # Open the file and return the handle
+ return open(path, *args, **kwargs)
+
def command(self, command, error_ok=False, interactive=False, chroot=False, bind=None):
"""
Runs a command in a shell environment
# Setup logging
log = logging.getLogger("bricklayer.bootloaders")
+GRUB_TIMEOUT = 5
+
class Bootloader(object):
"""
A generic class for bootloaders
requires_bootldr_partition = True
def install(self):
+ # Write the configuration file
+ self.write_configuration()
+
# Install GRUB2 on all disks that have been selected
for disk in self.bricklayer.disks.selected:
self.install_on_disk(disk)
*self.grub_args, disk.path,
], chroot=True, bind=["/dev", "/proc", "/sys"])
+ def write_configuration(self):
+ """
+ This method writes /etc/default/grub
+ """
+ log.debug("Writing GRUB Configuration:")
+
+ conf = {
+ # Tell GRUB who we are
+ "GRUB_DISTRIBUTOR" : "\"$(sed 's, release .*$,,g' /etc/system-release)\"",
+
+ # Give the user a moment to select an option
+ "GRUB_TIMEOUT" : GRUB_TIMEOUT,
+
+ # Remember the selected option
+ "GRUB_DEFAULT" : "saved",
+
+ # Do not show a submenu
+ "GRUB_DISABLE_SUBMENU" : "true",
+
+ # Disable the recovery option
+ "GRUB_DISABLE_RECOVERY" : "true",
+ }
+
+ # XXX Handle serial console
+ conf["GRUB_TERMINAL_OUTPUT"] = "\"console\""
+
+ # Write everything to file
+ with self.bricklayer.open("/etc/default/grub", "w") as f:
+ for key, val in conf.items():
+ # Log the line
+ log.debug(" %s = %s" % (key, val))
+
+ # Write the line to file
+ f.write("%s=%s\n" % (key, val))
+
def install_configuration(self):
"""
Generates a GRUB configuration file