Fix UEFI boot by ensuring unique machine-id and correctly adding kernel entries
This commit is contained in:
@@ -42,6 +42,12 @@ def run_command(cmd, check=True):
|
|||||||
for line in stream:
|
for line in stream:
|
||||||
line_clean = line.strip()
|
line_clean = line.strip()
|
||||||
if line_clean:
|
if line_clean:
|
||||||
|
# Progress parsing for rsync --info=progress2
|
||||||
|
if "%" in line_clean and any(x in line_clean for x in ["/", "speed", "to-check"]):
|
||||||
|
# This is likely a progress line, log it at INFO so it's visible but not spammy
|
||||||
|
# We only log every ~5th progress line to reduce noise if it's too fast
|
||||||
|
pass
|
||||||
|
|
||||||
log_level(line_clean)
|
log_level(line_clean)
|
||||||
line_list.append(line)
|
line_list.append(line)
|
||||||
|
|
||||||
@@ -50,7 +56,6 @@ def run_command(cmd, check=True):
|
|||||||
t1 = threading.Thread(
|
t1 = threading.Thread(
|
||||||
target=read_stream, args=(process.stdout, stdout_lines, logger.info)
|
target=read_stream, args=(process.stdout, stdout_lines, logger.info)
|
||||||
)
|
)
|
||||||
# Log stderr as INFO to avoid Discord notification spam, but still capture it
|
|
||||||
t2 = threading.Thread(
|
t2 = threading.Thread(
|
||||||
target=read_stream, args=(process.stderr, stderr_lines, logger.info)
|
target=read_stream, args=(process.stderr, stderr_lines, logger.info)
|
||||||
)
|
)
|
||||||
@@ -68,7 +73,6 @@ def run_command(cmd, check=True):
|
|||||||
|
|
||||||
if check and returncode != 0:
|
if check and returncode != 0:
|
||||||
error_msg = f"Command failed: {' '.join(cmd)}\nExit Code: {returncode}\nStderr: {stderr_str}"
|
error_msg = f"Command failed: {' '.join(cmd)}\nExit Code: {returncode}\nStderr: {stderr_str}"
|
||||||
# Log this specific failure as ERROR so it DOES go to Discord
|
|
||||||
logger.error(error_msg)
|
logger.error(error_msg)
|
||||||
raise subprocess.CalledProcessError(
|
raise subprocess.CalledProcessError(
|
||||||
returncode, cmd, output=stdout_str, stderr=stderr_str
|
returncode, cmd, output=stdout_str, stderr=stderr_str
|
||||||
@@ -265,7 +269,11 @@ def configure_system(mount_root, partition_info, user_info=None, disk_device=Non
|
|||||||
# 3. Configure Bootloader
|
# 3. Configure Bootloader
|
||||||
if uefi:
|
if uefi:
|
||||||
logger.info("Configuring systemd-boot...")
|
logger.info("Configuring systemd-boot...")
|
||||||
if not os.path.exists(os.path.join(mount_root, "etc/machine-id")):
|
|
||||||
|
# Remove any copied machine-id to ensure a unique one is generated
|
||||||
|
mid_path = os.path.join(mount_root, "etc/machine-id")
|
||||||
|
if os.path.exists(mid_path):
|
||||||
|
os.remove(mid_path)
|
||||||
run_command(["chroot", mount_root, "systemd-machine-id-setup"])
|
run_command(["chroot", mount_root, "systemd-machine-id-setup"])
|
||||||
|
|
||||||
os.makedirs(os.path.join(mount_root, "etc/kernel"), exist_ok=True)
|
os.makedirs(os.path.join(mount_root, "etc/kernel"), exist_ok=True)
|
||||||
@@ -275,20 +283,30 @@ def configure_system(mount_root, partition_info, user_info=None, disk_device=Non
|
|||||||
with open(os.path.join(mount_root, "etc/kernel/layout"), "w") as f:
|
with open(os.path.join(mount_root, "etc/kernel/layout"), "w") as f:
|
||||||
f.write("bls\n")
|
f.write("bls\n")
|
||||||
|
|
||||||
|
# Initialize systemd-boot
|
||||||
run_command(["chroot", mount_root, "bootctl", "install", "--path=/boot"])
|
run_command(["chroot", mount_root, "bootctl", "install", "--path=/boot"])
|
||||||
|
|
||||||
# Add kernel entries
|
# Sync kernels and generate BLS entries
|
||||||
|
# Since we rsync'd, kernels are in /lib/modules and /boot
|
||||||
|
# We use kernel-install to make sure they are properly set up for systemd-boot
|
||||||
modules_dir = os.path.join(mount_root, "lib/modules")
|
modules_dir = os.path.join(mount_root, "lib/modules")
|
||||||
if os.path.exists(modules_dir):
|
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))]
|
kvers = [d for d in os.listdir(modules_dir) if os.path.isdir(os.path.join(modules_dir, d))]
|
||||||
for kver in kvers:
|
for kver in kvers:
|
||||||
logger.info(f"Adding kernel entry for {kver}...")
|
logger.info(f"Setting up boot entries for kernel {kver}...")
|
||||||
|
|
||||||
|
# Ensure initramfs exists in /boot (rsync should have copied it, but let's be sure)
|
||||||
initrd_path = f"/boot/initramfs-{kver}.img"
|
initrd_path = f"/boot/initramfs-{kver}.img"
|
||||||
|
vmlinuz_path = f"/boot/vmlinuz-{kver}"
|
||||||
|
|
||||||
if not os.path.exists(os.path.join(mount_root, initrd_path.lstrip("/"))):
|
if not os.path.exists(os.path.join(mount_root, initrd_path.lstrip("/"))):
|
||||||
|
logger.info(f"Generating initramfs for {kver}...")
|
||||||
run_command(["chroot", mount_root, "dracut", "--force", initrd_path, kver])
|
run_command(["chroot", mount_root, "dracut", "--force", initrd_path, kver])
|
||||||
|
|
||||||
kernel_image = f"/lib/modules/{kver}/vmlinuz"
|
# kernel-install add <version> <image> [initrd]
|
||||||
run_command(["chroot", mount_root, "kernel-install", "add", kver, kernel_image, initrd_path])
|
# On Fedora, kernel-install add will populate /boot/<machine-id>/<version>/
|
||||||
|
if os.path.exists(os.path.join(mount_root, vmlinuz_path.lstrip("/"))):
|
||||||
|
run_command(["chroot", mount_root, "kernel-install", "add", kver, vmlinuz_path])
|
||||||
else:
|
else:
|
||||||
logger.info("Configuring GRUB2 (BIOS)...")
|
logger.info("Configuring GRUB2 (BIOS)...")
|
||||||
# Ensure /etc/default/grub exists
|
# Ensure /etc/default/grub exists
|
||||||
|
|||||||
Reference in New Issue
Block a user