From 9145738f109b9e7d8ad5dd032a6c54c544d67335 Mon Sep 17 00:00:00 2001 From: Felipe Sateler Date: Sat, 27 Aug 2016 16:20:18 -0300 Subject: [PATCH] Add bootable image support for debian --- mkosi | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/mkosi b/mkosi index 9a5f9ff38..37f330a6a 100755 --- a/mkosi +++ b/mkosi @@ -445,8 +445,32 @@ def install_debian_or_ubuntu(args, workspace, run_build_script, mirror): if run_build_script and not args.build_packages is None: cmdline[3] += "," + ",".join(args.build_packages) + if args.bootable and args.output_format == OutputFormat.raw_btrfs: + cmdline[3] += ",btrfs-tools" + subprocess.run(cmdline, check=True) + # Work around debian bug #835628 + os.makedirs(os.path.join(workspace, "root/etc/dracut.conf.d")) + with open(os.path.join(workspace, "root/etc/dracut.conf.d/99-generic.conf"), "w") as f: + f.write("hostonly=no") + + # We cannot install this directly in the debootstrap phase. + # linux-image prefers initramfs-tools over dracut, and debootstrap is not smart enough + # to realize the solution when installing linux-image-amd64 + dracut is to not install + # initramfs-tools... + if args.bootable: + subprocess.run(["systemd-nspawn", + "--directory=" + os.path.join(workspace, "root"), + "--as-pid2", + "--register=no", + "/usr/bin/apt-get", "--assume-yes", "--no-install-recommends", "install", + "linux-image-amd64", + "dracut", + "systemd-sysv", + ], + check=True) + def install_debian(args, workspace, run_build_script): print_step("Installing Debian...") @@ -552,6 +576,18 @@ def install_boot_loader_arch(args, workspace): "/usr/bin/kernel-install", "add", kernel_version, "/boot/vmlinuz-linux"], check=True) +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")))) + + subprocess.run(["systemd-nspawn", + "--directory=" + os.path.join(workspace, "root"), + "--as-pid2", + "--private-network", + "--register=no", + "/usr/bin/kernel-install", "add", kernel_version, "/boot/vmlinuz-" + kernel_version], + check=True) + + def install_boot_loader(args, workspace): if not args.bootable: return @@ -567,6 +603,9 @@ def install_boot_loader(args, workspace): if args.distribution == Distribution.arch: install_boot_loader_arch(args, workspace) + if args.distribution == Distribution.debian: + install_boot_loader_debian(args, workspace) + print_step("Installing boot loader completed.") def enumerate_and_copy(source, dest, suffix = ""): @@ -1205,8 +1244,8 @@ def load_args(): args.release = "yakkety" if args.bootable: - if args.distribution not in (Distribution.fedora, Distribution.arch): - sys.stderr.write("Bootable images are currently supported only on Fedora and ArchLinux.\n") + if args.distribution not in (Distribution.fedora, Distribution.arch, Distribution.debian): + sys.stderr.write("Bootable images are currently supported only on Debian, Fedora and ArchLinux.\n") sys.exit(1) if not args.output_format in (OutputFormat.raw_gpt, OutputFormat.raw_btrfs): -- 2.47.2