]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Add bios support to Archlinux 261/head
authorLucas De Marchi <lucas.demarchi@intel.com>
Sat, 17 Nov 2018 00:24:18 +0000 (16:24 -0800)
committerLucas De Marchi <lucas.demarchi@intel.com>
Wed, 21 Nov 2018 02:07:28 +0000 (18:07 -0800)
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

diff --git a/mkosi b/mkosi
index 3ad628aed935bb8385d69260b5f7c098d20ea3cc..c319f915b472c328efbb70f978ada67099532f1a 100755 (executable)
--- 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: