From dae254028af0dafa225964a365e6414f33ad67c8 Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Fri, 16 Nov 2018 16:24:18 -0800 Subject: [PATCH] Add bios support to Archlinux In order to add support to boot on bios mode for Archlinux, the following changes were made: - kernel packages are now installed as a second step: this allows us to patch the initrd config file so to disable the autodetection hook - patching the initrd config is now part of the distro install rather than bootloader install uefi-only is the default and we can generate uefi-only, bios-only and hybrid images. In the latter case grub is used for bios and systemd-boot for UEFI. --- mkosi | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/mkosi b/mkosi index 3ad628aed..c319f915b 100755 --- a/mkosi +++ b/mkosi @@ -1600,8 +1600,8 @@ SigLevel = Required DatabaseOptional "linux-hardened", "linux-zen", } + kernel_packages = official_kernel_packages.intersection(args.packages) - packages |= kernel_packages if len(kernel_packages) > 1: warn('More than one kernel will be installed: {}', ' '.join(kernel_packages)) @@ -1617,13 +1617,27 @@ SigLevel = Required DatabaseOptional packages.add("device-mapper") if not kernel_packages: # No user-specified kernel - packages.add("linux") + kernel_packages.add("linux") + if args.bios_partno: + packages.add("grub") + + packages.add("mkinitcpio") # Set up system with packages from the base group run_pacstrap(packages) - # Install the user-specified packages + # Patch mkinitcpio configuration so: 1) we remove autodetect and + # 2) we add the modules needed for encrypt. + patch_file(os.path.join(workspace, "root", "etc/mkinitcpio.conf"), + lambda line: "HOOKS=\"systemd modconf block sd-encrypt filesystems keyboard fsck\"\n" if line.startswith("HOOKS=") and args.encrypt == "all" else + "HOOKS=\"systemd modconf block filesystems fsck\"\n" if line.startswith("HOOKS=") else + line) + + # Install the user-specified packages and kernel packages = set(args.packages) + if args.bootable: + packages |= kernel_packages + if run_build_script: packages.update(args.build_packages) # Remove already installed packages @@ -1891,15 +1905,15 @@ def install_grub(args, workspace, loopdev, grub): def install_boot_loader_fedora(args, workspace, loopdev): install_grub(args, workspace, loopdev, "grub2") -def install_boot_loader_arch(args, workspace): - patch_file(os.path.join(workspace, "root", "etc/mkinitcpio.conf"), - lambda line: "HOOKS=\"systemd modconf block sd-encrypt filesystems keyboard fsck\"\n" if line.startswith("HOOKS=") and args.encrypt == "all" else - "HOOKS=\"systemd modconf block filesystems fsck\"\n" if line.startswith("HOOKS=") else - line) +def install_boot_loader_arch(args, workspace, loopdev): + if "uefi" in args.boot_protocols: + # add loader entries and copy kernel/initrd under that entry + workspace_root = os.path.join(workspace, "root") + kernel_version = next(filter(lambda x: x[0].isdigit(), os.listdir(os.path.join(workspace_root, "lib/modules")))) + run_workspace_command(args, workspace, "/usr/bin/kernel-install", "add", kernel_version, find_kernel_file(workspace_root, "/boot/vmlinuz-*")) - workspace_root = os.path.join(workspace, "root") - kernel_version = next(filter(lambda x: x[0].isdigit(), os.listdir(os.path.join(workspace_root, "lib/modules")))) - run_workspace_command(args, workspace, "/usr/bin/kernel-install", "add", kernel_version, find_kernel_file(workspace_root, "/boot/vmlinuz-*")) + if "bios" in args.boot_protocols: + install_grub(args, workspace, loopdev, "grub") def install_boot_loader_debian(args, workspace): kernel_version = next(filter(lambda x: x[0].isdigit(), os.listdir(os.path.join(workspace, "root", "lib/modules")))) @@ -1947,7 +1961,7 @@ def install_boot_loader(args, workspace, loopdev, cached): install_boot_loader_fedora(args, workspace, loopdev) if args.distribution == Distribution.arch: - install_boot_loader_arch(args, workspace) + install_boot_loader_arch(args, workspace, loopdev) if args.distribution == Distribution.debian: install_boot_loader_debian(args, workspace) @@ -3315,7 +3329,7 @@ def load_args() -> CommandLineArguments: args.boot_protocols = ["uefi"] if not {"uefi", "bios"}.issuperset(args.boot_protocols): die("Not a valid boot protocol") - if "bios" in args.boot_protocols and args.distribution not in (Distribution.fedora,): + if "bios" in args.boot_protocols and args.distribution not in (Distribution.fedora,Distribution.arch): die(f"bios boot not implemented yet for {args.distribution}") if args.encrypt is not None: -- 2.47.2