fix(partitioning): avoid alignment errors by using fill-gap logic for full space

This commit is contained in:
2026-02-03 20:19:25 +01:00
parent 7371da2451
commit 7a8e8ccbed
2 changed files with 22 additions and 5 deletions

View File

@@ -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

View File

@@ -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")