|
|
|
|
@@ -145,14 +145,12 @@ def install_minimal_os(mount_root, releasever="43"):
|
|
|
|
|
"passwd",
|
|
|
|
|
"rootfiles",
|
|
|
|
|
"vim-minimal",
|
|
|
|
|
"grub2-tools",
|
|
|
|
|
"grubby",
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
if uefi:
|
|
|
|
|
packages += ["grub2-efi-x64", "grub2-efi-x64-modules", "shim-x64", "efibootmgr"]
|
|
|
|
|
packages += ["systemd-boot-unsigned", "efibootmgr"]
|
|
|
|
|
else:
|
|
|
|
|
packages += ["grub2-pc"]
|
|
|
|
|
packages += ["grub2-pc", "grub2-tools", "grubby"]
|
|
|
|
|
|
|
|
|
|
# Offline installation logic
|
|
|
|
|
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):
|
|
|
|
|
"""
|
|
|
|
|
Basic configuration: fstab, grub2, and user creation.
|
|
|
|
|
Basic configuration: fstab, bootloader, and user creation.
|
|
|
|
|
"""
|
|
|
|
|
logger.info("Configuring system...")
|
|
|
|
|
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"):
|
|
|
|
|
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"):
|
|
|
|
|
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:
|
|
|
|
|
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"):
|
|
|
|
|
efi_target = os.path.join(mount_root, "boot/efi")
|
|
|
|
|
efi_target = os.path.join(mount_root, "boot")
|
|
|
|
|
os.makedirs(efi_target, exist_ok=True)
|
|
|
|
|
# Check if already mounted
|
|
|
|
|
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:
|
|
|
|
|
logger.error(f"Failed to set passwords: {e}")
|
|
|
|
|
|
|
|
|
|
# 3. Configure GRUB2
|
|
|
|
|
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')
|
|
|
|
|
|
|
|
|
|
# 3. Configure Bootloader
|
|
|
|
|
if uefi:
|
|
|
|
|
efi_dir = "/boot/efi"
|
|
|
|
|
# Re-verify mount inside chroot if possible, but we already mounted it outside
|
|
|
|
|
logger.info("Configuring systemd-boot...")
|
|
|
|
|
if not os.path.exists(os.path.join(mount_root, "etc/machine-id")):
|
|
|
|
|
run_command(["chroot", mount_root, "systemd-machine-id-setup"])
|
|
|
|
|
|
|
|
|
|
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")
|
|
|
|
|
|
|
|
|
|
logger.info("Installing GRUB2 for UEFI...")
|
|
|
|
|
# Using --removable can help on some systems that don't like efibootmgr entries
|
|
|
|
|
# but for now let's stick to standard and add --recheck
|
|
|
|
|
run_command(["chroot", mount_root, "grub2-install", "--target=x86_64-efi", f"--efi-directory={efi_dir}", "--bootloader-id=iridium", "--recheck"])
|
|
|
|
|
|
|
|
|
|
config_path = "/boot/efi/EFI/iridium/grub.cfg"
|
|
|
|
|
run_command(["chroot", mount_root, "grub2-mkconfig", "-o", config_path])
|
|
|
|
|
|
|
|
|
|
# Fedora compatibility link
|
|
|
|
|
fedora_dir = os.path.join(mount_root, "boot/efi/EFI/fedora")
|
|
|
|
|
os.makedirs(fedora_dir, exist_ok=True)
|
|
|
|
|
with open(os.path.join(fedora_dir, "grub.cfg"), "w") as f:
|
|
|
|
|
f.write(f"configfile /EFI/iridium/grub.cfg\n")
|
|
|
|
|
with open(os.path.join(mount_root, "etc/kernel/layout"), "w") as f:
|
|
|
|
|
f.write("bls\n")
|
|
|
|
|
|
|
|
|
|
run_command(["chroot", mount_root, "bootctl", "install", "--path=/boot"])
|
|
|
|
|
|
|
|
|
|
# Add kernel entries
|
|
|
|
|
modules_dir = os.path.join(mount_root, "lib/modules")
|
|
|
|
|
if os.path.exists(modules_dir):
|
|
|
|
|
kvers = [d for d in os.listdir(modules_dir) if os.path.isdir(os.path.join(modules_dir, d))]
|
|
|
|
|
for kver in kvers:
|
|
|
|
|
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:
|
|
|
|
|
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:
|
|
|
|
|
# Try to guess disk device from root partition
|
|
|
|
|
disk_device = partition_info["root"].rstrip("0123456789")
|
|
|
|
|
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"])
|
|
|
|
|
|
|
|
|
|
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")
|
|
|
|
|
|