From c1a1399958501de2e3e4a2cf05fa8ab8f6df162c Mon Sep 17 00:00:00 2001 From: demmm Date: Sun, 12 Oct 2014 13:45:02 -0400 Subject: [PATCH] adding new bootloader job options are to use grub for BIOS, gummiboot for efi set extra mountpoint when efi is found --- src/modules/bootloader/bootloader.conf | 8 ++ src/modules/bootloader/main.py | 102 +++++++++++++++++++++++++ src/modules/bootloader/module.desc | 5 ++ src/modules/bootloader/test.yaml | 3 + src/modules/mount/main.py | 4 + src/modules/mount/mount.conf | 6 ++ 6 files changed, 128 insertions(+) create mode 100644 src/modules/bootloader/bootloader.conf create mode 100644 src/modules/bootloader/main.py create mode 100644 src/modules/bootloader/module.desc create mode 100644 src/modules/bootloader/test.yaml diff --git a/src/modules/bootloader/bootloader.conf b/src/modules/bootloader/bootloader.conf new file mode 100644 index 000000000..56e0746bb --- /dev/null +++ b/src/modules/bootloader/bootloader.conf @@ -0,0 +1,8 @@ +--- +# Gummiboot configuration files settings, set preffered distribution name and amount of time before +# default selection boots +distribution: KaOS + +timeout: 10 + + diff --git a/src/modules/bootloader/main.py b/src/modules/bootloader/main.py new file mode 100644 index 000000000..62d37e244 --- /dev/null +++ b/src/modules/bootloader/main.py @@ -0,0 +1,102 @@ +#!/usr/bin/env python3 +# encoding: utf-8 +# === This file is part of Calamares - === +# +# Copyright 2014, Aurélien Gâteau +# Copyright 2014, Anke Boersma +# Copyright 2014, Daniel Hillenbrand +# Copyright 2014, Benjamin Vaudour +# +# Calamares is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Calamares is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Calamares. If not, see . + +import libcalamares + +import os +import shutil +import subprocess + +from libcalamares.utils import check_chroot_call + +def detect_firmware_type(): + # Check for EFI variables support + if(os.path.exists("/sys/firmware/efi/efivars")): + fw_type = 'efi' + else: + fw_type = 'bios' + + libcalamares.globalstorage.insert("firmwareType", fw_type) + libcalamares.utils.debug("Firmware type: {!s}".format(fw_type)) + +def get_uuid(): + root_mount_point = libcalamares.globalstorage.value("rootMountPoint") + print(root_mount_point) + partitions = libcalamares.globalstorage.value("partitions") + print(partitions) + for partition in partitions: + if partition["mountPoint"] == "/": + print(partition["uuid"]) + return partition["uuid"] + return "" + +def create_conf(uuid, conf_path): + distribution = libcalamares.job.configuration["distribution"] + lines = [ + '## This is just an exmaple config file.\n', + '## Please edit the paths and kernel parameters according to your system.\n', + '\n', + 'title %s GNU/Linux, with Linux core repo kernel\n' % distribution, + 'linux /vmlinuz-linux\n', + 'initrd /initramfs-linux.img\n', + 'options root=UUID=%s quiet rw\n' % uuid, + ] + + with open(conf_path, 'w') as f: + for l in lines: + f.write(l) + f.close() + +def create_loader(loader_path): + distribution = libcalamares.job.configuration["distribution"] + timeout = libcalamares.job.configuration["timeout"] + lines = [ + 'timeout %s\n' % timeout, + 'default %s\n' % distribution, + ] + + with open(loader_path, 'w') as f: + for l in lines: + f.write(l) + f.close() + +def install_grub(boot_loader, fw_type): + if fw_type == 'efi': + install_path = libcalamares.globalstorage.value( "rootMountPoint" ) + uuid = get_uuid() + distribution = libcalamares.job.configuration["distribution"] + conf_path = os.path.join(install_path, "boot", "loader", "entries", "%s.conf" % distribution) + loader_path = os.path.join(install_path, "boot", "loader", "loader.conf") + subprocess.call(["gummiboot", "--path=%s/boot" % install_path, "install"]) + create_conf(uuid, conf_path) + create_loader(loader_path) + else: + install_path = boot_loader["installPath"] + check_chroot_call(["grub-install", install_path]) + check_chroot_call(["grub-mkconfig", "-o", "/boot/grub/grub.cfg"]) + +def run(): + detect_firmware_type() + boot_loader = libcalamares.globalstorage.value("bootLoader") + fw_type = libcalamares.globalstorage.value("firmwareType") + install_grub(boot_loader, fw_type) + return None diff --git a/src/modules/bootloader/module.desc b/src/modules/bootloader/module.desc new file mode 100644 index 000000000..94534cc98 --- /dev/null +++ b/src/modules/bootloader/module.desc @@ -0,0 +1,5 @@ +--- +type: "job" +name: "bootloader" +interface: "python" +script: "main.py" diff --git a/src/modules/bootloader/test.yaml b/src/modules/bootloader/test.yaml new file mode 100644 index 000000000..3b9852e63 --- /dev/null +++ b/src/modules/bootloader/test.yaml @@ -0,0 +1,3 @@ +rootMountPoint: /tmp/mount +bootLoader: + installPath: /dev/sdb diff --git a/src/modules/mount/main.py b/src/modules/mount/main.py index 67f34701b..4233001c2 100644 --- a/src/modules/mount/main.py +++ b/src/modules/mount/main.py @@ -48,12 +48,16 @@ def run(): root_mount_point = tempfile.mkdtemp(prefix="calamares-root-") partitions = libcalamares.globalstorage.value("partitions") extra_mounts = libcalamares.job.configuration["extraMounts"] + extra_mounts_efi = libcalamares.job.configuration["extraMountsEfi"] # Sort by mount points to ensure / is mounted before the rest partitions.sort(key=lambda x: x["mountPoint"]) mount_partitions(root_mount_point, partitions) mount_partitions(root_mount_point, extra_mounts) + + if(os.path.exists("/sys/firmware/efi/efivars")): + mount_partitions(root_mount_point, extra_mounts_efi) libcalamares.globalstorage.insert("rootMountPoint", root_mount_point) return None diff --git a/src/modules/mount/mount.conf b/src/modules/mount/mount.conf index 9e917ed84..c548d1939 100644 --- a/src/modules/mount/mount.conf +++ b/src/modules/mount/mount.conf @@ -9,3 +9,9 @@ extraMounts: - device: /dev mountPoint: /dev options: bind + +extraMountsEfi: + - device: /sys/firmware/efi + mountPoint: /sys/firmware/efi + options: bind +