Implement basic partitioning backend and CLI interface

This commit is contained in:
2026-02-03 16:20:59 +01:00
parent aae235e81f
commit 3c4870b104
3 changed files with 118 additions and 24 deletions

View File

View File

@@ -0,0 +1,76 @@
import subprocess
import logging
logger = logging.getLogger(__name__)
def run_command(cmd, check=True):
logger.info(f"Running command: {' '.join(cmd)}")
try:
result = subprocess.run(cmd, check=check, capture_output=True, text=True)
return result
except subprocess.CalledProcessError as e:
logger.error(f"Command failed: {e.stderr}")
raise
def get_partition_device(disk_device, partition_number):
"""
Returns the partition device path.
Handles NVMe style (p1) vs sd style (1).
"""
if disk_device[-1].isdigit():
return f"{disk_device}p{partition_number}"
return f"{disk_device}{partition_number}"
def auto_partition_disk(disk_device):
"""
Automatically partitions the disk with a standard layout:
1. EFI System Partition (1GB)
2. Swap (4GB) - simpler fixed size for now
3. Root (Remaining)
"""
logger.info(f"Starting auto-partitioning on {disk_device}")
# 1. Zap the disk (destroy all data)
run_command(["sgdisk", "-Z", disk_device])
# 2. Create new GPT table
run_command(["sgdisk", "-o", disk_device])
# 3. Create EFI Partition (Part 1, 1GB, Type EF00)
# -n <partnum>:<start>:<end>
run_command(["sgdisk", "-n", "1:0:+1024M", "-t", "1:ef00", "-c", "1:EFI System", disk_device])
# 4. Create Swap Partition (Part 2, 4GB, Type 8200)
run_command(["sgdisk", "-n", "2:0:+4096M", "-t", "2:8200", "-c", "2:Swap", disk_device])
# 5. Create Root Partition (Part 3, Rest, Type 8300)
run_command(["sgdisk", "-n", "3:0:0", "-t", "3:8300", "-c", "3:Root", disk_device])
# Inform kernel of changes
run_command(["partprobe", disk_device])
# Wait a bit for nodes to appear? Usually partprobe handles it but sometimes there's a race.
import time
time.sleep(1)
# 6. Format Partitions
efi_part = get_partition_device(disk_device, 1)
swap_part = get_partition_device(disk_device, 2)
root_part = get_partition_device(disk_device, 3)
logger.info("Formatting EFI partition...")
run_command(["mkfs.vfat", "-F32", efi_part])
logger.info("Formatting Swap partition...")
run_command(["mkswap", swap_part])
logger.info("Formatting Root partition...")
run_command(["mkfs.ext4", "-F", root_part])
logger.info("Partitioning and formatting complete.")
return {
"efi": efi_part,
"swap": swap_part,
"root": root_part
}

View File

@@ -1,16 +1,44 @@
import argparse
import sys
import logging
# Configure logging
logging.basicConfig(level=logging.INFO)
def main():
parser = argparse.ArgumentParser(description="Iridium OS Installer")
parser.add_argument(
"--mock",
action="store_true",
help="Run in mock mode (no actual changes to disk)",
)
parser.add_argument(
"--partition-disk",
help="Automatically partition the specified disk (WARNING: DESTROYS DATA)",
)
args = parser.parse_args()
if args.partition_disk:
from .backend.disk import auto_partition_disk
try:
print(f"Starting partitioning on {args.partition_disk}...")
result = auto_partition_disk(args.partition_disk)
print("Partitioning successful!")
print(f"EFI: {result['efi']}")
print(f"Swap: {result['swap']}")
print(f"Root: {result['root']}")
return 0
except Exception as e:
print(f"Partitioning failed: {e}", file=sys.stderr)
return 1
import gi
gi.require_version("Gtk", "4.0")
gi.require_version("Adw", "1")
from gi.repository import Adw, Gio, Gtk
from gi.repository import Adw, Gio
from .ui.window import InstallerWindow
class IridiumInstallerApp(Adw.Application):
def __init__(self, mock_mode=False):
super().__init__(
@@ -25,16 +53,6 @@ class IridiumInstallerApp(Adw.Application):
win = InstallerWindow(application=self, mock_mode=self.mock_mode)
win.present()
def main():
parser = argparse.ArgumentParser(description="Iridium OS Installer")
parser.add_argument(
"--mock",
action="store_true",
help="Run in mock mode (no actual changes to disk)",
)
args = parser.parse_args()
app = IridiumInstallerApp(mock_mode=args.mock)
return app.run(sys.argv)