utils: move all boot from OS functionality into boot.py

This change is a preparative for reimplementing the BIOS boot
in order to deprecate the legacy script. All the codepaths to
boot systems located at a partition are now called from the
boot_os_at function enabling an easier structure for the incoming
code.
master
Alejandro Sirgo Rica 2024-03-07 10:09:56 +01:00 committed by lupoDharkael
parent 7f18485eff
commit 4d4171e459
2 changed files with 51 additions and 25 deletions

View File

@ -19,7 +19,6 @@ from subprocess import Popen, PIPE
import fdisk
from src.ogClient import ogClient
from src.ogRest import ThreadState
from src.live.partcodes import GUID_MAP
from src.live.parttypes import get_parttype
@ -37,6 +36,8 @@ from src.utils.boot import *
from src.utils.sw_inventory import get_package_set
from src.utils.hw_inventory import get_hardware_inventory, legacy_list_hardware_inventory
from src.ogClient import ogClient
from src.utils.probe import OSFamily, get_os_family
OG_SHELL = '/bin/bash'
@ -262,27 +263,32 @@ class OgLiveOperations:
disk = request.getDisk()
partition = request.getPartition()
if is_uefi_supported(disk):
logging.info('UEFI support detected')
logging.info(f'Booting disk={disk} partition={partition}')
boot_os_at(int(disk), int(partition))
self.reboot()
return
device = get_partition_device(int(disk), int(partition))
mountpoint = device.replace('dev', 'mnt')
cmd = f'{ogClient.OG_PATH}interfaceAdm/IniciarSesion {disk} {partition}'
if not mount_mkdir(device, mountpoint):
raise RuntimeError(f'Cannot probe OS family. Unable to mount {device} at {esp_mountpoint}.')
is_legacy = not is_uefi_supported(disk) and get_os_family(mountpoint) == OSFamily.WINDOWS
umount(mountpoint)
try:
ogRest.proc = subprocess.Popen([cmd],
stdout=subprocess.PIPE,
shell=True,
executable=OG_SHELL)
(output, error) = ogRest.proc.communicate()
except:
logging.exception('Exception when running session subprocess')
raise ValueError('Error: Incorrect command value')
if is_legacy:
cmd = f'{ogClient.OG_PATH}interfaceAdm/IniciarSesion {disk} {partition}'
logging.info('Starting OS at disk %s partition %s', disk, partition)
return output.decode('utf-8')
try:
ogRest.proc = subprocess.Popen([cmd],
stdout=subprocess.PIPE,
shell=True,
executable=OG_SHELL)
(output, error) = ogRest.proc.communicate()
except:
logging.exception('Exception when running session subprocess')
raise ValueError('Error: Incorrect command value')
logging.info('Starting OS at disk %s partition %s', disk, partition)
return output.decode('utf-8')
boot_os_at(int(disk), int(partition))
self.reboot()
def software(self, request, ogRest):
disk = request.getDisk()

View File

@ -18,6 +18,17 @@ from src.utils.uefi import *
from src.utils.fs import *
def _boot_bios_legacy(disk, part, mountpoint):
raise NotImplementedError
def _boot_bios_linux(disk, part, mountpoint):
logging.info(f'Booting Linux system')
_boot_bios_legacy(disk, part, mountpoint)
def _boot_bios_windows(disk, part, mountpoint):
logging.info(f'Booting Windows system')
_boot_bios_legacy(disk, part, mountpoint)
def _boot_uefi_windows(disk, part, mountpoint):
logging.info(f'Booting windows system')
bootlabel = f'Part-{disk:02d}-{part:02d}'
@ -69,21 +80,30 @@ def _boot_uefi_linux(disk, part, mountpoint):
umount(esp_mountpoint)
def boot_os_at(disk, part):
if not is_uefi_supported(disk):
raise NotImplementedError('BIOS booting is not implemented yet')
logging.info(f'Booting disk={disk} partition={part}')
device = get_partition_device(disk, part)
mountpoint = device.replace('dev', 'mnt')
if not mount_mkdir(device, mountpoint):
raise RuntimeError(f'Cannot probe OS family. Unable to mount {device} at {esp_mountpoint}.')
logging.info(f'Booting system at {device}. Probing OS family...')
is_uefi = is_uefi_supported(disk)
if is_uefi:
logging.info('UEFI support detected')
else:
logging.info('UEFI support not detected')
os_family = get_os_family(mountpoint)
logging.info(f'{os_family} detected at {device}.')
try:
if os_family == OSFamily.WINDOWS:
if is_uefi and os_family == OSFamily.WINDOWS:
_boot_uefi_windows(disk, part, mountpoint)
elif os_family == OSFamily.LINUX:
elif is_uefi and os_family == OSFamily.LINUX:
_boot_uefi_linux(disk, part, mountpoint)
elif not is_uefi and os_family == OSFamily.WINDOWS:
_boot_bios_windows(disk, part, mountpoint)
elif not is_uefi and os_family == OSFamily.LINUX:
_boot_bios_linux(disk, part, mountpoint)
else:
raise RuntimeError('Unknown OS family')
finally: