fix(partitioning): avoid alignment errors by using fill-gap logic for full space
This commit is contained in:
@@ -120,10 +120,13 @@ def create_partition(disk_device, size_mb, type_code="8300", name="Linux filesys
|
|||||||
next_num += 1
|
next_num += 1
|
||||||
|
|
||||||
# Use -g (mbrtogpt) to ensure we can work on the disk if it was MBR
|
# 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([
|
run_command([
|
||||||
"sgdisk",
|
"sgdisk",
|
||||||
"-g",
|
"-g",
|
||||||
"-n", f"{next_num}:0:+{size_mb}M",
|
"-n", f"{next_num}:0:{size_spec}",
|
||||||
"-t", f"{next_num}:{type_code}",
|
"-t", f"{next_num}:{type_code}",
|
||||||
"-c", f"{next_num}:{name}",
|
"-c", f"{next_num}:{name}",
|
||||||
disk_device
|
disk_device
|
||||||
|
|||||||
@@ -558,13 +558,27 @@ class PartitioningPage(Adw.Bin):
|
|||||||
error_label.set_text("Can't set partition name to Linux filesystem")
|
error_label.set_text("Can't set partition name to Linux filesystem")
|
||||||
return
|
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]
|
type_code = types[selected_type]
|
||||||
fstype = fs_options[fs_dropdown.get_selected()]
|
fstype = fs_options[fs_dropdown.get_selected()]
|
||||||
|
|
||||||
|
try:
|
||||||
create_partition(self.current_disk_path, size_mb, type_code, name, fstype)
|
create_partition(self.current_disk_path, size_mb, type_code, name, fstype)
|
||||||
win.close()
|
win.close()
|
||||||
self.load_partitions(self.current_disk_path)
|
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 = Gtk.Button(label="Create")
|
||||||
btn.add_css_class("suggested-action")
|
btn.add_css_class("suggested-action")
|
||||||
|
|||||||
Reference in New Issue
Block a user