Commit Graph

14 Commits (11a963c70930405cb94d222ec5a55b1e5000bcb4)

Author SHA1 Message Date
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 c09c064f28 postinstall: ignore legacy scripts non-zero return code
legacy scripts are not reliable, legacy scripts continue processing on errors,
warn on errors until they are converted to native code instead.
2024-08-30 11:56:41 +02:00
Alejandro Sirgo Rica 71b3211d3d postinstall: remove shell=True
Remove the use of shell=True.
2024-08-09 11:05:02 +02:00
OpenGnSys Support Team 89d711be2a postinstall: ignore output when invoking legacy scripts
output is never consumed.
2024-08-08 13:36:32 +02:00
OpenGnSys Support Team 9be639ae78 postinstall: add logging to report this stage
log that image restoration has entered OS configuration stage.
2024-08-08 12:21:05 +02:00
OpenGnSys Support Team 9ee5f4adaa live: move filesystem expansion out of OS configuration
just a clean up.
2024-08-06 18:39:37 +02:00
OpenGnSys Support Team 9a52df7711 postinstall: add logging to report postconfiguration script invocation 2024-08-06 18:16:23 +02:00
OpenGnSys Support Team 16251d42d3 postinstall: typo in maximum win hostname error
s/nor/not
2024-08-06 17:30:19 +02:00
OpenGnSys Support Team fd64b84bcc postinstall: linux does not allow more than 64 bytes long hostnames
As per:

  $ getconf HOST_NAME_MAX
  64

truncate it to the maximum.
2024-08-06 17:29:57 +02:00
OpenGnSys Support Team 9a553765b4 utils: postinstall: show hostname in logs
Display the hostname that is set in the logs.
2024-07-30 16:40:07 +02:00
Alejandro Sirgo Rica 210a70fc73 utils: add set_linux_hostname
Add set_linux_hostname function to redefine the hostname of a
Linux install by overwriting the contents of /etc/hostname
2024-07-29 15:07:22 +02:00
Alejandro Sirgo Rica adbf02d170 utils: add set_windows_hostname
Add function to redefine the hostname of a Windows install.
Windows hostnames can't be larger than 15 characters due to
legacy heritage.

Hostname modification is done by modifying 3 registry values in
the ControlSetXXX entry of the SYSTEM hive. ControlSet001 is
generally the entry to be edited but one must query the value
of the 'Current' key in the 'Select' entry of the SYSTEM hive
to retrieve the active ControlSet.

The hostname has to be introduced in the following entries:
path = 'ControlSetXX/Control/ComputerName/ComputerName'
key = 'ComputerName'

path = 'ControlSetXXX/Services/Tcpip/Parameters'
key = 'HostName'
key = 'NV Hostname'

The value to store in those keys is of tipe SZ and has to be
encoded in UCS-2 Little Endian (utf-16-le).
2024-07-29 15:07:22 +02:00
Alejandro Sirgo Rica 567fea276e utils: add postinstall.py
Replace ConfigureOs script by native calls to:

- update BCD via hivex using bcd.py and winreg.py infrastructure.
- restore efi bootloader restore_windows_efi_bootloader().

Call legacy scripts for remaining postinstall procedures to
replace them incrementally.

Define variable CONFIGUREOS_LEGACY_ENABLED as False by default.
Run legacy configureOs when CONFIGUREOS_LEGACY_ENABLED = True.
This serves as a auxiliar method to keep the restoration functional
in case of problems with the new configure_os logic.
2024-07-29 15:07:22 +02:00