Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve install device selection in installer #182

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions controller/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Added

- controller: Enable spatial navigation using the arrow keys
- os: Improve installation device selection

## Removed

Expand Down
34 changes: 26 additions & 8 deletions installer/install-playos/install-playos.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

PARTITION_SIZE_GB_SYSTEM = 10
PARTITION_SIZE_GB_DATA = 5
REQUIRED_INSTALL_DEVICE_SIZE_GB = PARTITION_SIZE_GB_DATA + 2*PARTITION_SIZE_GB_SYSTEM + 1

GRUB_CFG = "@grubCfg@"
GRUB_ENV = '/mnt/boot/grub/grubenv'
Expand All @@ -40,10 +41,20 @@ def find_device(device_path):
boot_device = get_blockdevice("/iso")
if boot_device is None:
print("Could not identify installer medium. Considering all disks as installation targets.")
available_devices = all_devices
else:
available_devices = [device for device in all_devices if not device.path.startswith(boot_device)]

def device_filter(dev):
is_boot_device = (boot_device is not None) and dev.path.startswith(boot_device)
is_read_only = dev.readOnly
is_big_enough = gb_size(dev) > REQUIRED_INSTALL_DEVICE_SIZE_GB

return (not is_boot_device) and (not is_read_only) and is_big_enough

available_devices = [device for device in all_devices if device_filter(device)]

print("Minimum required size for installation target: {req_gb} GB".format(
req_gb=REQUIRED_INSTALL_DEVICE_SIZE_GB
))

print(f"Found {len(available_devices)} possible installation targets:")
yfyf marked this conversation as resolved.
Show resolved Hide resolved
for device in available_devices:
print(f'\t{device_info(device)}')
Expand Down Expand Up @@ -76,15 +87,22 @@ def get_blockdevice(mount_path):
# Find the parent device of the partition with mountpoint
for device in lsblk_data['blockdevices']:
if 'children' in device:
for child in device['children']:
if 'mountpoints' in child and mount_path in child['mountpoints']:
return '/dev/' + device['name']
children = device['children']
# the mount could be e.g. a cdrom blockdevice, in which case there are
# no cildren
else:
children = [device]

for child in children:
if 'mountpoints' in child and mount_path in child['mountpoints']:
return '/dev/' + device['name']
return None

def gb_size(device):
return int((device.sectorSize * device.length) / (10**9))

def device_info(device):
gb_size = int((device.sectorSize * device.length) / (10**9))
return f'{device.path} ({device.model} - {gb_size} GB)'
return f'{device.path} ({device.model} - {gb_size(device)} GB)'


def commit(disk):
Expand Down
Loading