Switch to systemd-boot for UEFI while keeping GRUB2 for BIOS/MBR
This commit is contained in:
@@ -236,7 +236,8 @@ def mount_partitions(partition_info, mount_root="/mnt"):
|
|||||||
|
|
||||||
# 2. Mount EFI (if exists)
|
# 2. Mount EFI (if exists)
|
||||||
if partition_info.get("efi"):
|
if partition_info.get("efi"):
|
||||||
efi_mount = os.path.join(mount_root, "boot/efi")
|
# For systemd-boot, we prefer mounting ESP to /boot
|
||||||
|
efi_mount = os.path.join(mount_root, "boot")
|
||||||
os.makedirs(efi_mount, exist_ok=True)
|
os.makedirs(efi_mount, exist_ok=True)
|
||||||
run_command(["mount", partition_info["efi"], efi_mount])
|
run_command(["mount", partition_info["efi"], efi_mount])
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -145,14 +145,12 @@ def install_minimal_os(mount_root, releasever="43"):
|
|||||||
"passwd",
|
"passwd",
|
||||||
"rootfiles",
|
"rootfiles",
|
||||||
"vim-minimal",
|
"vim-minimal",
|
||||||
"grub2-tools",
|
|
||||||
"grubby",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
if uefi:
|
if uefi:
|
||||||
packages += ["grub2-efi-x64", "grub2-efi-x64-modules", "shim-x64", "efibootmgr"]
|
packages += ["systemd-boot-unsigned", "efibootmgr"]
|
||||||
else:
|
else:
|
||||||
packages += ["grub2-pc"]
|
packages += ["grub2-pc", "grub2-tools", "grubby"]
|
||||||
|
|
||||||
# Offline installation logic
|
# Offline installation logic
|
||||||
possible_repos = [
|
possible_repos = [
|
||||||
@@ -223,7 +221,7 @@ def install_minimal_os(mount_root, releasever="43"):
|
|||||||
|
|
||||||
def configure_system(mount_root, partition_info, user_info=None, disk_device=None):
|
def configure_system(mount_root, partition_info, user_info=None, disk_device=None):
|
||||||
"""
|
"""
|
||||||
Basic configuration: fstab, grub2, and user creation.
|
Basic configuration: fstab, bootloader, and user creation.
|
||||||
"""
|
"""
|
||||||
logger.info("Configuring system...")
|
logger.info("Configuring system...")
|
||||||
log_os_install("CONFIGURE", "start", f"Configuring system in {mount_root}")
|
log_os_install("CONFIGURE", "start", f"Configuring system in {mount_root}")
|
||||||
@@ -241,7 +239,8 @@ def configure_system(mount_root, partition_info, user_info=None, disk_device=Non
|
|||||||
|
|
||||||
if uefi and partition_info.get("efi"):
|
if uefi and partition_info.get("efi"):
|
||||||
efi_uuid = get_uuid(partition_info["efi"])
|
efi_uuid = get_uuid(partition_info["efi"])
|
||||||
fstab_lines.append(f"UUID={efi_uuid} /boot/efi vfat defaults 0 2")
|
# For systemd-boot, we mount ESP to /boot
|
||||||
|
fstab_lines.append(f"UUID={efi_uuid} /boot vfat defaults 0 2")
|
||||||
|
|
||||||
if partition_info.get("swap"):
|
if partition_info.get("swap"):
|
||||||
swap_uuid = get_uuid(partition_info["swap"])
|
swap_uuid = get_uuid(partition_info["swap"])
|
||||||
@@ -251,9 +250,9 @@ def configure_system(mount_root, partition_info, user_info=None, disk_device=Non
|
|||||||
with open(os.path.join(mount_root, "etc/fstab"), "w") as f:
|
with open(os.path.join(mount_root, "etc/fstab"), "w") as f:
|
||||||
f.write("\n".join(fstab_lines) + "\n")
|
f.write("\n".join(fstab_lines) + "\n")
|
||||||
|
|
||||||
# Ensure EFI is mounted for GRUB installation
|
# Ensure EFI is mounted for bootloader installation if UEFI
|
||||||
if uefi and partition_info.get("efi"):
|
if uefi and partition_info.get("efi"):
|
||||||
efi_target = os.path.join(mount_root, "boot/efi")
|
efi_target = os.path.join(mount_root, "boot")
|
||||||
os.makedirs(efi_target, exist_ok=True)
|
os.makedirs(efi_target, exist_ok=True)
|
||||||
# Check if already mounted
|
# Check if already mounted
|
||||||
res = subprocess.run(["mount"], capture_output=True, text=True)
|
res = subprocess.run(["mount"], capture_output=True, text=True)
|
||||||
@@ -284,35 +283,42 @@ def configure_system(mount_root, partition_info, user_info=None, disk_device=Non
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Failed to set passwords: {e}")
|
logger.error(f"Failed to set passwords: {e}")
|
||||||
|
|
||||||
# 3. Configure GRUB2
|
# 3. Configure Bootloader
|
||||||
logger.info("Configuring GRUB2...")
|
|
||||||
|
|
||||||
# Ensure /etc/default/grub exists
|
|
||||||
grub_default = os.path.join(mount_root, "etc/default/grub")
|
|
||||||
if not os.path.exists(grub_default):
|
|
||||||
with open(grub_default, "w") as f:
|
|
||||||
f.write('GRUB_TIMEOUT=5\nGRUB_DISTRIBUTOR="$(sed \'s, release .*$,,g\' /etc/system-release)"\nGRUB_DEFAULT=saved\nGRUB_DISABLE_SUBMENU=true\nGRUB_TERMINAL_OUTPUT="console"\nGRUB_CMDLINE_LINUX="rhgb quiet"\nGRUB_DISABLE_RECOVERY="true"\nGRUB_ENABLE_BLSCFG=true\n')
|
|
||||||
|
|
||||||
if uefi:
|
if uefi:
|
||||||
efi_dir = "/boot/efi"
|
logger.info("Configuring systemd-boot...")
|
||||||
logger.info("Installing GRUB2 for UEFI...")
|
if not os.path.exists(os.path.join(mount_root, "etc/machine-id")):
|
||||||
# Fedora's grub2-install requires --force for EFI to acknowledge it won't be Secure Boot signed
|
run_command(["chroot", mount_root, "systemd-machine-id-setup"])
|
||||||
run_command(["chroot", mount_root, "grub2-install", "--target=x86_64-efi", f"--efi-directory={efi_dir}", "--bootloader-id=iridium", "--recheck", "--force"])
|
|
||||||
|
os.makedirs(os.path.join(mount_root, "etc/kernel"), exist_ok=True)
|
||||||
|
with open(os.path.join(mount_root, "etc/kernel/cmdline"), "w") as f:
|
||||||
|
f.write(f"root=UUID={root_uuid} rw quiet\n")
|
||||||
|
|
||||||
config_dir = os.path.join(mount_root, "boot/efi/EFI/iridium")
|
with open(os.path.join(mount_root, "etc/kernel/layout"), "w") as f:
|
||||||
os.makedirs(config_dir, exist_ok=True)
|
f.write("bls\n")
|
||||||
|
|
||||||
config_path = "/boot/efi/EFI/iridium/grub.cfg"
|
run_command(["chroot", mount_root, "bootctl", "install", "--path=/boot"])
|
||||||
run_command(["chroot", mount_root, "grub2-mkconfig", "-o", config_path])
|
|
||||||
|
# Add kernel entries
|
||||||
# Fedora compatibility link
|
modules_dir = os.path.join(mount_root, "lib/modules")
|
||||||
fedora_dir = os.path.join(mount_root, "boot/efi/EFI/fedora")
|
if os.path.exists(modules_dir):
|
||||||
os.makedirs(fedora_dir, exist_ok=True)
|
kvers = [d for d in os.listdir(modules_dir) if os.path.isdir(os.path.join(modules_dir, d))]
|
||||||
with open(os.path.join(fedora_dir, "grub.cfg"), "w") as f:
|
for kver in kvers:
|
||||||
f.write(f"configfile /EFI/iridium/grub.cfg\n")
|
logger.info(f"Adding kernel entry for {kver}...")
|
||||||
|
initrd_path = f"/boot/initramfs-{kver}.img"
|
||||||
|
if not os.path.exists(os.path.join(mount_root, initrd_path.lstrip("/"))):
|
||||||
|
run_command(["chroot", mount_root, "dracut", "--force", initrd_path, kver])
|
||||||
|
|
||||||
|
kernel_image = f"/lib/modules/{kver}/vmlinuz"
|
||||||
|
run_command(["chroot", mount_root, "kernel-install", "add", kver, kernel_image, initrd_path])
|
||||||
else:
|
else:
|
||||||
|
logger.info("Configuring GRUB2 (BIOS)...")
|
||||||
|
# Ensure /etc/default/grub exists
|
||||||
|
grub_default = os.path.join(mount_root, "etc/default/grub")
|
||||||
|
if not os.path.exists(grub_default):
|
||||||
|
with open(grub_default, "w") as f:
|
||||||
|
f.write('GRUB_TIMEOUT=5\nGRUB_DISTRIBUTOR="$(sed \'s, release .*$,,g\' /etc/system-release)"\nGRUB_DEFAULT=saved\nGRUB_DISABLE_SUBMENU=true\nGRUB_TERMINAL_OUTPUT="console"\nGRUB_CMDLINE_LINUX="rhgb quiet"\nGRUB_DISABLE_RECOVERY="true"\nGRUB_ENABLE_BLSCFG=true\n')
|
||||||
|
|
||||||
if not disk_device:
|
if not disk_device:
|
||||||
# Try to guess disk device from root partition
|
|
||||||
disk_device = partition_info["root"].rstrip("0123456789")
|
disk_device = partition_info["root"].rstrip("0123456789")
|
||||||
if disk_device.endswith("p"): disk_device = disk_device[:-1]
|
if disk_device.endswith("p"): disk_device = disk_device[:-1]
|
||||||
|
|
||||||
@@ -323,4 +329,4 @@ def configure_system(mount_root, partition_info, user_info=None, disk_device=Non
|
|||||||
run_command(["sync"])
|
run_command(["sync"])
|
||||||
|
|
||||||
logger.info("System configuration complete.")
|
logger.info("System configuration complete.")
|
||||||
log_os_install("CONFIGURE", "complete", "GRUB2 and user configured successfully")
|
log_os_install("CONFIGURE", "complete", "Bootloader and user configured successfully")
|
||||||
|
|||||||
Reference in New Issue
Block a user