diff --git a/iridium_installer/backend/disk.py b/iridium_installer/backend/disk.py index 6f5916f..d0f5f4c 100644 --- a/iridium_installer/backend/disk.py +++ b/iridium_installer/backend/disk.py @@ -120,10 +120,13 @@ def create_partition(disk_device, size_mb, type_code="8300", name="Linux filesys next_num += 1 # Use -g (mbrtogpt) to ensure we can work on the disk if it was MBR + # size_mb=0 means use all available space in the gap + size_spec = f"+{size_mb}M" if size_mb > 0 else "0" + run_command([ "sgdisk", "-g", - "-n", f"{next_num}:0:+{size_mb}M", + "-n", f"{next_num}:0:{size_spec}", "-t", f"{next_num}:{type_code}", "-c", f"{next_num}:{name}", disk_device diff --git a/iridium_installer/ui/pages/partitioning.py b/iridium_installer/ui/pages/partitioning.py index 02f9f01..1f16044 100644 --- a/iridium_installer/ui/pages/partitioning.py +++ b/iridium_installer/ui/pages/partitioning.py @@ -558,13 +558,27 @@ class PartitioningPage(Adw.Bin): error_label.set_text("Can't set partition name to Linux filesystem") return - size_mb = int(size_entry.get_text()) + size_text = size_entry.get_text() + try: + size_mb = int(size_text) + # If they are using the max proposed size, use 0 to avoid alignment issues + # with sgdisk +sizeM logic exceeding disk boundaries. + max_mb = int(data["bytes"] / (1024*1024)) + if size_mb >= max_mb: + size_mb = 0 + except ValueError: + error_label.set_text("Invalid size value") + return + type_code = types[selected_type] fstype = fs_options[fs_dropdown.get_selected()] - create_partition(self.current_disk_path, size_mb, type_code, name, fstype) - win.close() - self.load_partitions(self.current_disk_path) + try: + create_partition(self.current_disk_path, size_mb, type_code, name, fstype) + win.close() + self.load_partitions(self.current_disk_path) + except Exception as e: + error_label.set_text(f"Error: {str(e)}") btn = Gtk.Button(label="Create") btn.add_css_class("suggested-action")