From 83e6dfc81e471f68e37b6e5aa4ca95d5f334c60b Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 7 Sep 2017 03:42:46 -0400 Subject: [PATCH] Swap + LUKS configuration. Based on patches from crazy@frugalware.org and V3n3RiX. (presumably) FIXES #730 --- src/modules/bootloader/main.py | 12 ++++++++++-- src/modules/grubcfg/main.py | 31 ++++++++++++++++++++++--------- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/modules/bootloader/main.py b/src/modules/bootloader/main.py index fd5990490..c2cdc1108 100644 --- a/src/modules/bootloader/main.py +++ b/src/modules/bootloader/main.py @@ -11,6 +11,8 @@ # Copyright 2015, Philip Mueller # Copyright 2016-2017, Teo Mrnjavac # Copyright 2017, Alf Gaida +# Copyright 2017, Adriaan de Groot +# Copyright 2017, Gabriel Craciunescu # # Calamares is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -104,16 +106,22 @@ def create_systemd_boot_conf(uuid, conf_path, kernel_line): cryptdevice_params = [] + # Take over swap settings: + # - unencrypted swap partition sets swap_uuid + # - encrypted root sets cryptdevice_params for partition in partitions: - if partition["fs"] == "linuxswap": + has_luks = "luksMapperName" in partition + if partition["fs"] == "linuxswap" and not has_luks: swap_uuid = partition["uuid"] - if partition["mountPoint"] == "/" and "luksMapperName" in partition: + if partition["mountPoint"] == "/" and has_luks: cryptdevice_params = ["cryptdevice=UUID=" + partition["luksUuid"] + ":" + partition["luksMapperName"], "root=/dev/mapper/" + + partition["luksMapperName"], + "resume=/dev/mapper/" + partition["luksMapperName"]] if cryptdevice_params: diff --git a/src/modules/grubcfg/main.py b/src/modules/grubcfg/main.py index 5b1028c58..3ef68e46e 100644 --- a/src/modules/grubcfg/main.py +++ b/src/modules/grubcfg/main.py @@ -6,6 +6,8 @@ # Copyright 2014-2015, Philip Müller # Copyright 2015-2017, Teo Mrnjavac # Copyright 2017, Alf Gaida +# Copyright 2017, Adriaan de Groot +# Copyright 2017, Gabriel Craciunescu # # Calamares is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -29,6 +31,8 @@ def modify_grub_default(partitions, root_mount_point, distributor): """ Configures '/etc/default/grub' for hibernation and plymouth. + @see bootloader/main.py, for similar handling of kernel parameters + :param partitions: :param root_mount_point: :param distributor: @@ -45,6 +49,7 @@ def modify_grub_default(partitions, root_mount_point, distributor): use_splash = "" swap_uuid = "" swap_outer_uuid = "" + swap_outer_mappername = None if libcalamares.globalstorage.contains("hasPlymouth"): if libcalamares.globalstorage.value("hasPlymouth"): @@ -54,30 +59,35 @@ def modify_grub_default(partitions, root_mount_point, distributor): if have_dracut: for partition in partitions: - if partition["fs"] == "linuxswap": + has_luks = "luksMapperName" in partition + if partition["fs"] == "linuxswap" and not has_luks: swap_uuid = partition["uuid"] - if (partition["fs"] == "linuxswap" - and "luksMapperName" in partition): + if (partition["fs"] == "linuxswap" and has_luks): swap_outer_uuid = partition["luksUuid"] + swap_outer_mappername = partition["luksMapperName"] - if (partition["mountPoint"] == "/" - and "luksMapperName" in partition): + if (partition["mountPoint"] == "/" and has_luks): cryptdevice_params = [ "rd.luks.uuid={!s}".format(partition["luksUuid"]) ] else: for partition in partitions: - if partition["fs"] == "linuxswap": + has_luks = "luksMapperName" in partition + if partition["fs"] == "linuxswap" and not has_luks: swap_uuid = partition["uuid"] - if (partition["mountPoint"] == "/" - and "luksMapperName" in partition): + if (partition["mountPoint"] == "/" and has_luks): cryptdevice_params = [ "cryptdevice=UUID={!s}:{!s}".format( partition["luksUuid"], partition["luksMapperName"] ), - "root=/dev/mapper/{!s}".format(partition["luksMapperName"]) + "root=/dev/mapper/{!s}".format( + partition["luksMapperName"] + ), + "resume=/dev/mapper/{!s}".format( + partition["luksMapperName"] + ) ] kernel_params = ["quiet"] @@ -93,6 +103,9 @@ def modify_grub_default(partitions, root_mount_point, distributor): if have_dracut and swap_outer_uuid: kernel_params.append("rd.luks.uuid={!s}".format(swap_outer_uuid)) + if have_dracut and swap_outer_mappername: + kernel_params.append("resume=/dev/mapper/{!s}".format( + swap_outer_mappername)) distributor_line = "GRUB_DISTRIBUTOR='{!s}'".format(distributor_replace)