Implement manual partition management (create/delete/mountpoints)
This commit is contained in:
@@ -99,3 +99,42 @@ def mount_partitions(partition_info, mount_root="/mnt"):
|
||||
run_command(["swapon", partition_info["swap"]])
|
||||
|
||||
logger.info(f"Partitions mounted at {mount_root}")
|
||||
|
||||
def create_partition(disk_device, size_mb, type_code="8300", name="Linux filesystem"):
|
||||
"""
|
||||
Creates a new partition on the disk.
|
||||
type_code: ef00 (EFI), 8200 (Swap), 8300 (Linux)
|
||||
"""
|
||||
# Find next available partition number
|
||||
res = run_command(["sgdisk", "-p", disk_device])
|
||||
# Very basic parsing to find the next number
|
||||
existing_nums = []
|
||||
for line in res.stdout.splitlines():
|
||||
parts = line.split()
|
||||
if parts and parts[0].isdigit():
|
||||
existing_nums.append(int(parts[0]))
|
||||
|
||||
next_num = 1
|
||||
while next_num in existing_nums:
|
||||
next_num += 1
|
||||
|
||||
run_command([
|
||||
"sgdisk",
|
||||
"-n", f"{next_num}:0:+{size_mb}M",
|
||||
"-t", f"{next_num}:{type_code}",
|
||||
"-c", f"{next_num}:{name}",
|
||||
disk_device
|
||||
])
|
||||
run_command(["partprobe", disk_device])
|
||||
return next_num
|
||||
|
||||
def delete_partition(disk_device, part_num):
|
||||
"""Deletes a partition by number."""
|
||||
run_command(["sgdisk", "-d", str(part_num), disk_device])
|
||||
run_command(["partprobe", disk_device])
|
||||
|
||||
def wipe_disk(disk_device):
|
||||
"""Zaps the disk and creates a new GPT table."""
|
||||
run_command(["sgdisk", "-Z", disk_device])
|
||||
run_command(["sgdisk", "-o", disk_device])
|
||||
run_command(["partprobe", disk_device])
|
||||
|
||||
Reference in New Issue
Block a user