Commit 88dc85dc authored by Nigel Kukard's avatar Nigel Kukard
Browse files

Fixed parsing of disk sizes and added serial support to grub

parent fd0ae5ee
......@@ -125,7 +125,7 @@ def parse_size(size_str: str) -> int:
# Grab the size
size = int(components['num'])
size = float(components['num'])
# Check the multiplier we're going to use...
if components['multiplier'] == 'M':
......@@ -138,5 +138,5 @@ def parse_size(size_str: str) -> int:
raise ValueError('Failed to parse the "multiplier" portion of \
the block device size: %s' % components['multiplier'])
# Set the size
return size
# Return the size
return int(size)
......@@ -28,6 +28,7 @@ class SysGrub:
def __init__(self):
"""Initialize our class."""
# pylama:ignore=C901,R0914
def configure(self, system_path: str, output_callback: Optional[OutputCallback] = None, **kwargs):
"""Configure grub."""
......@@ -40,6 +41,22 @@ class SysGrub:
if not output_callback:
output_callback = self._default_output_callback
# If we are a serial console, we need to make sure grub is configured for serial
is_serial = {}
# Open the /proc/cmdline file to see what options we got
with open('/proc/cmdline', 'r') as cmdline_file:
# Loop with lines
for line in cmdline_file:
# Split options into a list
options = line.split()
# For now we only support *n8 speed on the first serial port...
for option in options:
matches = re.match(r'^console=ttyS(?P<unit>[0-9]),(?P<speed>[0-9]+)n8', option)
if matches:
is_serial['unit'] ='unit')
is_serial['speed'] ='speed')
# Open the config files and process
with open(sys_default_grub, 'r') as conf_file, open(sys_default_grub_new, 'w') as conf_file_new:
# Loop with lines
......@@ -58,9 +75,29 @@ class SysGrub:
# Rebuild the line
line = 'GRUB_PRELOAD_MODULES="' + ' '.join(modules) + '"\n'
# Check if this is the GRUB_CMDLINE_LINUX line
matches = re.match(r'^\s*GRUB_CMDLINE_LINUX="(?P<cmdline>.*)"', line)
if matches:
# If we can split it into a list
options ='cmdline').split()
# If we're dealing with a serial console add options
if is_serial:
options.append('console=ttyS%s,%sn8' % (is_serial['unit'], is_serial['speed']))
# Rebuild the line
line = 'GRUB_CMDLINE_LINUX="' + ' '.join(options) + '"\n'
# Write out line
# If this is a serial port add additional options
if is_serial:
conf_file_new.write('# START - Serial Console\n')
conf_file_new.write('GRUB_SERIAL_COMMAND="serial --unit=%s --speed=%s --word=8 --parity=no --stop=1"\n' %
(is_serial['unit'], is_serial['speed']))
conf_file_new.write('# END - Serial Console\n')
# Close files
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment