Send logs as file, create sudoer user, and improve bootloader reliability
This commit is contained in:
@@ -150,9 +150,9 @@ def install_minimal_os(mount_root, releasever="43"):
|
||||
log_os_install("INSTALL", "complete", f"Installed to {mount_root}")
|
||||
|
||||
|
||||
def configure_system(mount_root, partition_info):
|
||||
def configure_system(mount_root, partition_info, user_info=None):
|
||||
"""
|
||||
Basic configuration: fstab and systemd-boot.
|
||||
Basic configuration: fstab, systemd-boot, and user creation.
|
||||
"""
|
||||
logger.info("Configuring system...")
|
||||
log_os_install("CONFIGURE", "start", f"Configuring system in {mount_root}")
|
||||
@@ -179,7 +179,22 @@ UUID={efi_uuid} /boot vfat defaults 0 2
|
||||
with open(os.path.join(mount_root, "etc/fstab"), "w") as f:
|
||||
f.write(fstab_content)
|
||||
|
||||
# 2. Configure systemd-boot
|
||||
# 2. Configure User
|
||||
if user_info:
|
||||
logger.info(f"Creating user {user_info['username']}...")
|
||||
with mount_pseudo_fs(mount_root):
|
||||
# Create user and add to wheel group (sudoer)
|
||||
run_command(["chroot", mount_root, "useradd", "-m", "-G", "wheel", user_info["username"]])
|
||||
|
||||
# Set password
|
||||
p = subprocess.Popen(["chroot", mount_root, "chpasswd"], stdin=subprocess.PIPE, text=True)
|
||||
p.communicate(input=f"{user_info['username']}:{user_info['password']}")
|
||||
|
||||
# Set hostname
|
||||
with open(os.path.join(mount_root, "etc/hostname"), "w") as f:
|
||||
f.write(user_info["hostname"] + "\n")
|
||||
|
||||
# 3. Configure systemd-boot
|
||||
with mount_pseudo_fs(mount_root):
|
||||
# Ensure machine-id exists for kernel-install
|
||||
if not os.path.exists(os.path.join(mount_root, "etc/machine-id")):
|
||||
@@ -191,7 +206,8 @@ UUID={efi_uuid} /boot vfat defaults 0 2
|
||||
f.write(f"root=UUID={root_uuid} rw quiet\n")
|
||||
|
||||
# Install systemd-boot to the ESP (mounted at /boot)
|
||||
run_command(["chroot", mount_root, "bootctl", "install"])
|
||||
# Use --path=/boot to be explicit, though standard behavior usually finds it.
|
||||
run_command(["chroot", mount_root, "bootctl", "install", "--path=/boot"])
|
||||
|
||||
# Add kernel entries
|
||||
modules_dir = os.path.join(mount_root, "lib/modules")
|
||||
@@ -199,17 +215,24 @@ UUID={efi_uuid} /boot vfat defaults 0 2
|
||||
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}...")
|
||||
|
||||
# Ensure initramfs exists. If not, generate it.
|
||||
initrd_path_rel = f"boot/initramfs-{kver}.img"
|
||||
initrd_full_path = os.path.join(mount_root, initrd_path_rel)
|
||||
|
||||
if not os.path.exists(initrd_full_path):
|
||||
logger.info(f"Generating initramfs for {kver}...")
|
||||
run_command(["chroot", mount_root, "dracut", "--force", f"/boot/initramfs-{kver}.img", kver])
|
||||
|
||||
kernel_image = f"/lib/modules/{kver}/vmlinuz"
|
||||
initrd_arg = f"/boot/initramfs-{kver}.img"
|
||||
|
||||
# In Fedora, the initrd is usually created in /boot/initramfs-<version>.img
|
||||
# During installation, dnf should have triggered dracut.
|
||||
initrd_path = f"/boot/initramfs-{kver}.img"
|
||||
|
||||
# kernel-install add <version> <image> [initrd]
|
||||
cmd = ["chroot", mount_root, "kernel-install", "add", kver, kernel_image]
|
||||
if os.path.exists(os.path.join(mount_root, initrd_path.lstrip("/"))):
|
||||
cmd.append(initrd_path)
|
||||
if os.path.exists(os.path.join(mount_root, initrd_arg.lstrip("/"))):
|
||||
cmd.append(initrd_arg)
|
||||
|
||||
run_command(cmd)
|
||||
|
||||
logger.info("System configuration complete.")
|
||||
log_os_install("CONFIGURE", "complete", "systemd-boot configured successfully")
|
||||
log_os_install("CONFIGURE", "complete", "systemd-boot and user configured successfully")
|
||||
|
||||
Reference in New Issue
Block a user