Commit Graph

16 Commits (64f1f5403e014a944e70187e6eda9a02c08eac3e)

Author SHA1 Message Date
Alejandro Sirgo Rica 64f1f5403e disk: use different log message in get_disk_data and get_partition_data
Use a more specific message to differentiate the source of the error.

Add the target device to the log message.
2024-10-25 09:47:49 +02:00
Alejandro Sirgo Rica 2fcdf89606 disk: use cxt.label.name to dtect disk type in get_efi_partition
Use cxt.label.name instead of cxt.label to identify if the disk is
GPT or MBR. This way is more used in other parts of the codebase.
2024-10-21 16:56:05 +02:00
Alejandro Sirgo Rica e8ddbbd075 src: isolate libfdisk operations to enable mount operations
python-libfdisk does not close file descriptor until the cxt
object goes out of scope.

Define get_partition_data and get_disk_data functions to isolate
the python-libfdisk logic and return the data as an object.

Improve error handling of libfdisk operaions in refresh.
2024-10-08 10:07:45 +02:00
Alejandro Sirgo Rica 11a963c709 utils: Add windows_register_c_drive implementation
Add python implementation of the legacy ogWindowsRegisterPartition
function.

This function configures the system partition to be considered the
new C drive after a Windows image restore.

The drive letter configuration is stored in the SYSTEM hive of
the windows registry. The node MountedDevices contains all the
configuration as key-value pairs.
The C drive key \DosDevices\C: contains a different value based on
the partitioning type.

GPT
the value is DMIO:ID: followed by the 16 byte GUID of the
partition.
Example: DMIO:ID:\xc9\xfc\x1c\x86\x13\x11O\t\xa2\x9c{/\xf1\xdf\xe4)

MBR
The value is a little endian byte sequence with 2 parts.
The first 4 bytes correspond to the disk id. The second part is
the byte offset start of the partition in that disk.
Example: \xe1\\\x9cP\x00\x00\x10j\x18\x00\x00\x00

If we format the MBR value in a more readable way we get
e1 5c 9c 50 00 00 10 6a 18 00 00 00
In this case the disk ID is 509c5ce1.
The partition offset is 186a100000.

This patch adds the following helper functions to:

- get_disk_id_bytes(): to obtain the disk identifier.

- get_part_id_bytes(): to obtain a partition identifier as UUID
  for MBR or DMIO:ID format for GPT.

- get_sector_size(): to query the sector size of a specific disk.
  Read /sys/class/block/{device_name}/queue/hw_sector_size to obtain the value.
  This is MBR specific.

- get_partition_start_offset(): to query the start sector of a specific
  partition and disk. Use sfdisk with the -J argument to get fdisk data in
  json format. This is MBR specific.
2024-09-12 10:43:09 +02:00
Alejandro Sirgo Rica f7b37ba010 utils: replace the legacy function ogConfigureFstab
Implement configure_fstab() as a replacement of ogConfigureFstab.

Create src/utils/fstab.py to implement the main fstab
configuration functions. Define two fstab helper classes,
FstabBuilder and FstabEntry.

FstabEntry
Represents each line in the fstab file.
Has the values: device, mountpoint, fstype, options, dump_code
and pass_code.

FstabBuilder
Contains a list of FstabEntry. Handles loading of a
preexisting fstab file and the serialization of multiple
FstabEntry into a file.

The fstab configuration has 3 main steps:

Root partition:
- Update the device field with the device where
the new system is installed.

Swap partition:
- Preserve all the swapfile entries in every case.
- If the filesystem has a swap partition: update the device field
  in the first fstab swap entry and remove the rest swap entries
  pointing to a swap partition. Only one swap partition is supported.
  Create a new fstab entry if no preexisting swap entry exists.
- If the system has no swap partition remove every swap partition
  entry.

EFI partition:
- Update the device field of the EFI fstab entry if it exists.
  Create a new fstab entry if no preexisting EFI entry exists.

Add get_filesystem_id to disk.py to obtain the UUID.
Define every device field as a UUID. That method is more robust
than a plain device path as it works after disks being added or
removed.
2024-08-30 12:19:48 +02:00
OpenGnSys Support Team 9b317cf3e0 utils: disk: revisit logging to find EFI partition
instead of

	Checking partition "Microsoft Basic Data"...
	Checking partition "EFI System"...

show

	Searching EFI partition...
	EFI partition found at /dev/sda1

and refer to EFI partition consistently in logs.
2024-07-30 16:50:17 +02:00
Alejandro Sirgo Rica 4f31bde549 utils: add functions to obtain disk and partition UUIDs
Add get_partition_id and get_disk_id to obtain the UUID of a disk
or partition as a string. These values are obtained invoking the
program blkid as a subprocess.

This commit is preparatory work for the new native postinstall code.
2024-07-29 15:07:22 +02:00
Alejandro Sirgo Rica dfde363aa6 src: log backtrace in unhandled error cases
Log an error message in known error cases and log a backtrace
otherwise.

Define a new error type OgError to be used in all the 'raise'
blocks to define the error message to log. The exception
propagates until it reaches send_internal_server_error() where
the exception type is checked. If the type is OgError we log
the exception message. Logs the backtrace for other types.

The initial error implementation printed a backtrace everytime
an error ocurred. The next iteration changed it to only print
a backtrace in a very particular case but ended up omiting too
much information such as syntax errors or unknown error context.
The actual implementation only logs the cases we already cover in
the codebase and logs a bracktrace in the others, enabling a
better debugging experience.
2024-04-03 13:31:10 +02:00
OpenGnSys Support Team 4712941828 utils: refine log when booting windows UEFI from DOS partition
Refine 97647c32aa utils: add enforce_gpt argument to get_efi_partition()
to provide more explicit error when trying to boot Windows UEFI from DOS
partition.
2024-04-01 14:28:14 +02:00
Alejandro Sirgo Rica 97647c32aa utils: add enforce_gpt argument to get_efi_partition()
The Windows bootloader only supports a UEFI boot from a GPT
partition. Set enforce_gpt to True in every codepath related to
Windows. When enforce_gpt is set to True get_efi_partition()
raises an exception when an MBR partition scheme is detected.
2024-03-26 13:23:04 +01:00
Alejandro Sirgo Rica ddf08779ae utils: add disk index checks in get_partition_device
Control the possibility of a bad disk index. Handle the checks in
a similar fashion to the get_efi_partition function.
2024-03-21 10:29:13 +01:00
Alejandro Sirgo Rica aa34704b4d utils: improve logging in the get_efi_partition function
Log each partition that gets checked and make the exception messages
more informative.
2024-03-08 12:43:01 +01:00
Jose M. Guisado bb3264d8f4 disk: add get_efi_partition function
Add utility function inside disk.py to find, if any, the first ESP
partition of a given disk.

The disk is provided as an integer (starting at 1 following OpenGnsys
scripts usual values), meaning the (n-1)th disk from the disk array
returned from get_disks(). In the future a better mechanism should be
put in place to fetch probed disks from a running client.

This change is part of the upcoming drop of "IniciarSesion" script in
favor of a Python native approach. Specifically regarding UEFI systems.
2024-03-04 11:33:10 +01:00
Alejandro Sirgo Rica 478c4447be src: improve error check in image_create and image_restore
cover more error cases where exceptions need to be raised.
check return code in the invoked subprocess.

restoreImageCustom has been intentionally left behind, it
is unclear what this custom script returns on success and
error.
2024-02-14 12:28:28 +01:00
Jose M. Guisado 52838e2ce6 utils: add get_partition_device
Maps a disk and partition number to the corresponding device path
('/dev/sdXY', '/dev/nvmeXnYpZ', ...)
2022-09-14 17:12:14 +02:00
Jose M. Guisado 902e019505 Add utils modules
* disk.py

	Disk discovery

* fs.py

	Uses psutil to fetch fs usage information

* menu.py

	ogBrowser menu generation

* net.py: gets nic status information

	IP address, MAC address and ethernet speed.

* probe.py: probes mountpoints for operating systems

	Uses hivexget command to try fetching Windows installation
	information.
	Looks for /etc/os-release for probing linux systems.
2022-04-21 09:47:04 +02:00