From 1f9f506a16e26d6e41bad65fadb2cfdca47d5a8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20PORTAY?= Date: Wed, 17 Jun 2020 14:16:20 -0400 Subject: [PATCH 1/6] [partition] Make mountPoint optional Some devices cannot be mounted (as DM_verity_hash), therefore, it is nosense to set a mountPoint for them. --- src/modules/partition/core/PartitionLayout.cpp | 3 +-- src/modules/partition/partition.conf | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/modules/partition/core/PartitionLayout.cpp b/src/modules/partition/core/PartitionLayout.cpp index 15b18da93..0b0c7bedf 100644 --- a/src/modules/partition/core/PartitionLayout.cpp +++ b/src/modules/partition/core/PartitionLayout.cpp @@ -134,8 +134,7 @@ PartitionLayout::init( const QVariantList& config ) { QVariantMap pentry = r.toMap(); - if ( !pentry.contains( "name" ) || !pentry.contains( "mountPoint" ) || !pentry.contains( "filesystem" ) - || !pentry.contains( "size" ) ) + if ( !pentry.contains( "name" ) || !pentry.contains( "filesystem" ) || !pentry.contains( "size" ) ) { cError() << "Partition layout entry #" << config.indexOf( r ) << "lacks mandatory attributes, switching to default layout."; diff --git a/src/modules/partition/partition.conf b/src/modules/partition/partition.conf index 41652fe7d..ed2719ca7 100644 --- a/src/modules/partition/partition.conf +++ b/src/modules/partition/partition.conf @@ -208,7 +208,7 @@ defaultFileSystemType: "ext4" # - type: partition type (optional parameter; gpt only; requires KPMCore >= 4.2.0) # - attributes: partition attributes (optional parameter; gpt only; requires KPMCore >= 4.2.0) # - filesystem: filesystem type -# - mountPoint: partition mount point +# - mountPoint: partition mount point (optional parameter; not mounted if unset) # - size: partition size in bytes (append 'K', 'M' or 'G' for KiB, MiB or GiB) # or # % of the available drive space if a '%' is appended to the value From 54fd1f4b260fce83921116d93dd0c83848983e8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20PORTAY?= Date: Sat, 31 Oct 2020 04:44:49 -0400 Subject: [PATCH 2/6] [mount] Print a warning if mount failure The return of the call to libcalamares.utils.mount is never tested and it may fail silently; this causes some mounpoints to be missing. This adds a warning if mountpoint cannot be mounted. chcon: failed to get security context of '/tmp/verity': Operation not supported 06:44:23 [6]: static CalamaresUtils::ProcessResult CalamaresUtils::System::runCommand(CalamaresUtils::System::RunLocation, const QStringList&, const QString&, const QString&, std::chrono::seconds) Running "env" ("mount", "-t", "unformatted", "/dev/sdb2", "/tmp/calamares-root-kv8dqgb5/tmp/verity") .. Finished. Exit code: 32 .. Target cmd: ("mount", "-t", "unformatted", "/dev/sdb7", "/tmp/calamares-root-kv8dqgb5/tmp/verity") output: mount: /tmp/calamares-root-kv8dqgb5/tmp/verity: unknown filesystem type 'unformatted'. --- src/modules/mount/main.py | 71 ++++++++++++++------------------------- 1 file changed, 26 insertions(+), 45 deletions(-) diff --git a/src/modules/mount/main.py b/src/modules/mount/main.py index 01c0650bf..5ef7a2734 100644 --- a/src/modules/mount/main.py +++ b/src/modules/mount/main.py @@ -7,6 +7,7 @@ # SPDX-FileCopyrightText: 2017 Alf Gaida # SPDX-FileCopyrightText: 2019 Adriaan de Groot # SPDX-FileCopyrightText: 2019 Kevin Kofler +# SPDX-FileCopyrightText: 2019-2020 Collabora Ltd # SPDX-License-Identifier: GPL-3.0-or-later # # Calamares is Free Software: see the License-Identifier above. @@ -56,22 +57,16 @@ def mount_partition(root_mount_point, partition, partitions): if fstype == "fat16" or fstype == "fat32": fstype = "vfat" - if "luksMapperName" in partition: - libcalamares.utils.debug( - "about to mount {!s}".format(partition["luksMapperName"])) - libcalamares.utils.mount( - "/dev/mapper/{!s}".format(partition["luksMapperName"]), - mount_point, - fstype, - partition.get("options", ""), - ) + device = partition["device"] - else: - libcalamares.utils.mount(partition["device"], - mount_point, - fstype, - partition.get("options", ""), - ) + if "luksMapperName" in partition: + device = os.path.join("/dev/mapper", partition["luksMapperName"]) + + if libcalamares.utils.mount(device, + mount_point, + fstype, + partition.get("options", "")) != 0: + libcalamares.utils.warning("Cannot mount {}".format(device)) # If the root partition is btrfs, we create a subvolume "@" # for the root mount point. @@ -96,37 +91,23 @@ def mount_partition(root_mount_point, partition, partitions): subprocess.check_call(["umount", "-v", root_mount_point]) + device = partition["device"] + if "luksMapperName" in partition: - libcalamares.utils.mount( - "/dev/mapper/{!s}".format(partition["luksMapperName"]), - mount_point, - fstype, - ",".join( - ["subvol=@", partition.get("options", "")]), - ) - if not has_home_mount_point: - libcalamares.utils.mount( - "/dev/mapper/{!s}".format(partition["luksMapperName"]), - root_mount_point + "/home", - fstype, - ",".join( - ["subvol=@home", partition.get("options", "")]), - ) - else: - libcalamares.utils.mount( - partition["device"], - mount_point, - fstype, - ",".join(["subvol=@", partition.get("options", "")]), - ) - if not has_home_mount_point: - libcalamares.utils.mount( - partition["device"], - root_mount_point + "/home", - fstype, - ",".join( - ["subvol=@home", partition.get("options", "")]), - ) + device = os.path.join("/dev/mapper", partition["luksMapperName"]) + + if libcalamares.utils.mount(device, + mount_point, + fstype, + ",".join(["subvol=@", partition.get("options", "")])) != 0: + libcalamares.utils.warning("Cannot mount {}".format(device)) + + if not has_home_mount_point: + if libcalamares.utils.mount(device, + root_mount_point + "/home", + fstype, + ",".join(["subvol=@home", partition.get("options", "")])) != 0: + libcalamares.utils.warning("Cannot mount {}".format(device)) def run(): From c6feedf9230730ce62d80677fe89ff898495f977 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20PORTAY?= Date: Sat, 31 Oct 2020 07:18:30 -0400 Subject: [PATCH 3/6] [mount] Ignore empty mountpoints --- src/modules/mount/main.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/modules/mount/main.py b/src/modules/mount/main.py index 5ef7a2734..2e4de44fa 100644 --- a/src/modules/mount/main.py +++ b/src/modules/mount/main.py @@ -39,6 +39,9 @@ def mount_partition(root_mount_point, partition, partitions): # Create mount point with `+` rather than `os.path.join()` because # `partition["mountPoint"]` starts with a '/'. raw_mount_point = partition["mountPoint"] + if not raw_mount_point: + return + mount_point = root_mount_point + raw_mount_point # Ensure that the created directory has the correct SELinux context on From 163351a803dc4b86d0ac21e0f74d2877fb885b4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20PORTAY?= Date: Sat, 31 Oct 2020 07:19:53 -0400 Subject: [PATCH 4/6] [mount] Ignore empty or unformatted filesystems --- src/modules/mount/main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/modules/mount/main.py b/src/modules/mount/main.py index 2e4de44fa..71599a6de 100644 --- a/src/modules/mount/main.py +++ b/src/modules/mount/main.py @@ -56,6 +56,8 @@ def mount_partition(root_mount_point, partition, partitions): raise fstype = partition.get("fs", "").lower() + if not fstype or fstype == "unformatted": + return if fstype == "fat16" or fstype == "fat32": fstype = "vfat" From db08d2db8ba31f183d5a538fd838e8b318b18842 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20PORTAY?= Date: Sat, 31 Oct 2020 08:09:13 -0400 Subject: [PATCH 5/6] [partition] Make filesystem optional and default to unformatted --- src/modules/partition/core/PartitionLayout.cpp | 4 ++-- src/modules/partition/partition.conf | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/partition/core/PartitionLayout.cpp b/src/modules/partition/core/PartitionLayout.cpp index 0b0c7bedf..4650449bf 100644 --- a/src/modules/partition/core/PartitionLayout.cpp +++ b/src/modules/partition/core/PartitionLayout.cpp @@ -134,7 +134,7 @@ PartitionLayout::init( const QVariantList& config ) { QVariantMap pentry = r.toMap(); - if ( !pentry.contains( "name" ) || !pentry.contains( "filesystem" ) || !pentry.contains( "size" ) ) + if ( !pentry.contains( "name" ) || !pentry.contains( "size" ) ) { cError() << "Partition layout entry #" << config.indexOf( r ) << "lacks mandatory attributes, switching to default layout."; @@ -147,7 +147,7 @@ PartitionLayout::init( const QVariantList& config ) CalamaresUtils::getString( pentry, "type" ), CalamaresUtils::getUnsignedInteger( pentry, "attributes", 0 ), CalamaresUtils::getString( pentry, "mountPoint" ), - CalamaresUtils::getString( pentry, "filesystem" ), + CalamaresUtils::getString( pentry, "filesystem", "unformatted" ), CalamaresUtils::getSubMap( pentry, "features", ok ), CalamaresUtils::getString( pentry, "size", QStringLiteral( "0" ) ), CalamaresUtils::getString( pentry, "minSize", QStringLiteral( "0" ) ), diff --git a/src/modules/partition/partition.conf b/src/modules/partition/partition.conf index ed2719ca7..e5de69659 100644 --- a/src/modules/partition/partition.conf +++ b/src/modules/partition/partition.conf @@ -207,7 +207,7 @@ defaultFileSystemType: "ext4" # - uuid: partition uuid (optional parameter; gpt only; requires KPMCore >= 4.2.0) # - type: partition type (optional parameter; gpt only; requires KPMCore >= 4.2.0) # - attributes: partition attributes (optional parameter; gpt only; requires KPMCore >= 4.2.0) -# - filesystem: filesystem type +# - filesystem: filesystem type (optional parameter; fs not created if "unformatted" or unset) # - mountPoint: partition mount point (optional parameter; not mounted if unset) # - size: partition size in bytes (append 'K', 'M' or 'G' for KiB, MiB or GiB) # or From 6013ed52f8f9efb04365ea8b595d14a0fd2761c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20PORTAY?= Date: Mon, 2 Nov 2020 08:57:58 -0500 Subject: [PATCH 6/6] [partition] Ignore unformatted filesystem --- src/modules/partition/jobs/FillGlobalStorageJob.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/partition/jobs/FillGlobalStorageJob.cpp b/src/modules/partition/jobs/FillGlobalStorageJob.cpp index 8e7958e83..c9040877d 100644 --- a/src/modules/partition/jobs/FillGlobalStorageJob.cpp +++ b/src/modules/partition/jobs/FillGlobalStorageJob.cpp @@ -153,7 +153,7 @@ FillGlobalStorageJob::prettyDescription() const QString path = partitionMap.value( "device" ).toString(); QString mountPoint = partitionMap.value( "mountPoint" ).toString(); QString fsType = partitionMap.value( "fs" ).toString(); - if ( mountPoint.isEmpty() || fsType.isEmpty() ) + if ( mountPoint.isEmpty() || fsType.isEmpty() || fsType == QString( "unformatted" ) ) { continue; }