From 0f23b8ad5c2f8ec13fb2e026c4a409db9b6e5f90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20G=C3=A2teau?= Date: Thu, 24 Jul 2014 17:17:40 +0200 Subject: [PATCH] Add basic grub module. Not enabled for now because it requires a rootfs to work Fixes #26 --- src/modules/grub/main.py | 80 ++++++++++++++++++++++++++++++++++++ src/modules/grub/module.conf | 16 ++++++++ 2 files changed, 96 insertions(+) create mode 100644 src/modules/grub/main.py create mode 100644 src/modules/grub/module.conf diff --git a/src/modules/grub/main.py b/src/modules/grub/main.py new file mode 100644 index 000000000..b365821a5 --- /dev/null +++ b/src/modules/grub/main.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python3 +# encoding: utf-8 +# === This file is part of Calamares - === +# +# Copyright 2014, Aurélien Gâteau +# +# 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 os +import subprocess +import sys + +import libcalamares + + +# FIXME: Duplicated between mount and grub +def mount( devicePath, mountPoint, fs = None, options = None ): + assert devicePath + assert mountPoint + if not os.path.exists( mountPoint ): + os.makedirs( mountPoint ) + cmd = [ "mount", devicePath, mountPoint ] + if fs: + cmd += ( "-t", fs ) + if options: + cmd += ( "-o", options ) + subprocess.check_call( cmd ) + + +def mountPartitions( rootMountPoint, partitions ): + for partition in partitions: + if not partition[ "mountPoint" ]: + continue + # Create mount point with `+` rather than `os.path.join()` because + # `partition["mountPoint"]` starts with a '/'. + mountPoint = rootMountPoint + partition[ "mountPoint" ] + mount( partition[ "device" ], mountPoint, + fs = partition.get( "fs" ), + options = partition.get( "options" ) + ) + + +def umountPartitions( rootMountPoint, partitions ): + for partition in partitions: + if not partition[ "mountPoint" ]: + continue + subprocess.call( [ "umount", rootMountPoint + partition[ "mountPoint" ] ] ) + + +def chroot_call( rootMountPoint, cmd ): + subprocess.check_call( [ "chroot", rootMountPoint ] + cmd ) + + +def installGrub( rootMountPoint, bootLoader ): + installPath = bootLoader[ "installPath" ] + chroot_call( rootMountPoint, [ "grub-install", installPath ] ) + chroot_call( rootMountPoint, [ "grub-mkconfig", "-o", "/boot/grub/grub.cfg" ] ) + + +def calamares_main(): + rootMountPoint = libcalamares.global_storage.value( "rootMountPoint" ) + bootLoader = libcalamares.global_storage.value( "bootLoader" ) + extraMounts = libcalamares.job.configuration[ "extraMounts" ] + mountPartitions( rootMountPoint, extraMounts ) + try: + installGrub( rootMountPoint, bootLoader ) + finally: + umountPartitions( rootMountPoint, extraMounts ) + return "All done" diff --git a/src/modules/grub/module.conf b/src/modules/grub/module.conf new file mode 100644 index 000000000..fc7432462 --- /dev/null +++ b/src/modules/grub/module.conf @@ -0,0 +1,16 @@ +type: "job" +name: "grub" +interface: "python" +requires: [] +script: "main.py" +configuration: + extraMounts: + - device: proc + fs: proc + mountPoint: /proc + - device: sys + fs: sysfs + mountPoint: /sys + - device: /dev + mountPoint: /dev + options: bind