Skip to content

Commit

Permalink
Merge pull request #182 from yfyf/improve-install-dev-selection
Browse files Browse the repository at this point in the history
Improve install device selection in installer
  • Loading branch information
knuton committed Sep 26, 2024
2 parents 36f21c1 + fc86dec commit 38e9fa9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
1 change: 1 addition & 0 deletions controller/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- kiosk: Open settings with a long press on the Menu key
- 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:")
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

0 comments on commit 38e9fa9

Please sign in to comment.