feat(partitioning): support fat32 and add validation for system partition name
This commit is contained in:
@@ -100,10 +100,11 @@ def mount_partitions(partition_info, mount_root="/mnt"):
|
||||
|
||||
logger.info(f"Partitions mounted at {mount_root}")
|
||||
|
||||
def create_partition(disk_device, size_mb, type_code="8300", name="Linux filesystem"):
|
||||
def create_partition(disk_device, size_mb, type_code="8300", name="Linux filesystem", fstype=None):
|
||||
"""
|
||||
Creates a new partition on the disk.
|
||||
Creates a new partition on the disk and formats it.
|
||||
type_code: ef00 (EFI), 8200 (Swap), 8300 (Linux)
|
||||
fstype: ext4, fat32, swap
|
||||
"""
|
||||
# Find next available partition number
|
||||
res = run_command(["sgdisk", "-p", disk_device])
|
||||
@@ -126,6 +127,20 @@ def create_partition(disk_device, size_mb, type_code="8300", name="Linux filesys
|
||||
disk_device
|
||||
])
|
||||
run_command(["partprobe", disk_device])
|
||||
|
||||
# Wait for partition node
|
||||
import time
|
||||
time.sleep(1)
|
||||
|
||||
part_dev = get_partition_device(disk_device, next_num)
|
||||
|
||||
if fstype == "fat32":
|
||||
run_command(["mkfs.vfat", "-F32", part_dev])
|
||||
elif fstype == "ext4":
|
||||
run_command(["mkfs.ext4", "-F", part_dev])
|
||||
elif fstype == "swap":
|
||||
run_command(["mkswap", part_dev])
|
||||
|
||||
return next_num
|
||||
|
||||
def delete_partition(disk_device, part_num):
|
||||
|
||||
@@ -504,6 +504,11 @@ class PartitioningPage(Adw.Bin):
|
||||
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=12, margin_top=24, margin_bottom=24, margin_start=24, margin_end=24)
|
||||
win.set_content(box)
|
||||
|
||||
# Name entry
|
||||
name_entry = Gtk.Entry(text="Linux filesystem")
|
||||
box.append(Gtk.Label(label="Partition Name:"))
|
||||
box.append(name_entry)
|
||||
|
||||
# Size entry
|
||||
size_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=12)
|
||||
size_entry = Gtk.Entry(text=str(int(data["bytes"] / (1024*1024))))
|
||||
@@ -519,11 +524,45 @@ class PartitioningPage(Adw.Bin):
|
||||
box.append(Gtk.Label(label="Partition Type:"))
|
||||
box.append(type_dropdown)
|
||||
|
||||
# Filesystem dropdown
|
||||
fs_options = ["ext4", "fat32", "swap"]
|
||||
fs_dropdown = Gtk.DropDown.new_from_strings(fs_options)
|
||||
box.append(Gtk.Label(label="Filesystem:"))
|
||||
box.append(fs_dropdown)
|
||||
|
||||
# Auto-update FS and Name based on Type
|
||||
def on_type_changed(dropdown, pspec):
|
||||
selected_type = type_names[dropdown.get_selected()]
|
||||
if selected_type == "EFI System":
|
||||
fs_dropdown.set_selected(1) # fat32
|
||||
name_entry.set_text("EFI System")
|
||||
elif selected_type == "Swap":
|
||||
fs_dropdown.set_selected(2) # swap
|
||||
name_entry.set_text("Swap")
|
||||
else:
|
||||
fs_dropdown.set_selected(0) # ext4
|
||||
name_entry.set_text("Linux filesystem")
|
||||
|
||||
type_dropdown.connect("notify::selected", on_type_changed)
|
||||
|
||||
error_label = Gtk.Label(label="")
|
||||
error_label.add_css_class("error")
|
||||
box.append(error_label)
|
||||
|
||||
def on_create(b):
|
||||
from ...backend.disk import create_partition
|
||||
name = name_entry.get_text()
|
||||
selected_type = type_names[type_dropdown.get_selected()]
|
||||
|
||||
if selected_type == "EFI System" and name == "Linux filesystem":
|
||||
error_label.set_text("Can't set partition name to Linux filesystem")
|
||||
return
|
||||
|
||||
size_mb = int(size_entry.get_text())
|
||||
type_code = types[type_names[type_dropdown.get_selected()]]
|
||||
create_partition(self.current_disk_path, size_mb, type_code)
|
||||
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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user