From a4fadcd9be71fec09b5de17f5d12ec46dd25cd5e Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 6 Jul 2021 12:54:25 +0200 Subject: [PATCH] [partition] Introduce check for EFI partition type-and-size Re-use the existing message about partition type and size, since I don't want to introduce another message with all the specifics; give a works-always message instead. The check itself is also straightforward, avoiding all of the nuances and technically-this-might-work cases: FAT32, 300MiB+. FIXES #607 --- src/modules/partition/PartitionViewStep.cpp | 2 +- src/modules/partition/core/PartUtils.cpp | 28 +++++++++++++++++++++ src/modules/partition/core/PartUtils.h | 6 +++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/modules/partition/PartitionViewStep.cpp b/src/modules/partition/PartitionViewStep.cpp index 3f57050aa..015aab2ce 100644 --- a/src/modules/partition/PartitionViewStep.cpp +++ b/src/modules/partition/PartitionViewStep.cpp @@ -445,7 +445,7 @@ PartitionViewStep::onLeave() QString message; QString description; - if ( !esp ) + if ( !esp || ( esp && !PartUtils::isEfiFilesystemSuitable( esp ) ) ) { message = tr( "No EFI system partition configured" ); description = tr( "An EFI system partition is necessary to start %1." diff --git a/src/modules/partition/core/PartUtils.cpp b/src/modules/partition/core/PartUtils.cpp index 22e84a09c..5b8572189 100644 --- a/src/modules/partition/core/PartUtils.cpp +++ b/src/modules/partition/core/PartUtils.cpp @@ -446,6 +446,34 @@ isEfiSystem() return QDir( "/sys/firmware/efi/efivars" ).exists(); } +bool +isEfiFilesystemSuitable(const Partition* candidate) +{ + auto type = candidate->fileSystem().type(); + auto size = candidate->capacity(); // bytes + + using CalamaresUtils::Units::operator""_MiB; + + switch( type ) + { + case FileSystem::Type::Fat32: + if ( size >= 300_MiB ) + { + return true; + } + cWarning() << "FAT32 filesystem is too small (" << size << "bytes)"; + return false; + case FileSystem::Type::Fat12: + case FileSystem::Type::Fat16: + cWarning() << "FAT12 and FAT16 are probably not supported by EFI"; + return false; + default: + cWarning() << "EFI boot partition must be FAT32"; + return false; + } +} + + bool isEfiBootable( const Partition* candidate ) { diff --git a/src/modules/partition/core/PartUtils.h b/src/modules/partition/core/PartUtils.h index 5e84e379b..6bf223921 100644 --- a/src/modules/partition/core/PartUtils.h +++ b/src/modules/partition/core/PartUtils.h @@ -82,6 +82,12 @@ OsproberEntryList runOsprober( DeviceModel* dm ); */ bool isEfiSystem(); +/** + * @brief Is the @p partition suitable as an EFI boot partition? + * Checks for filesystem type (FAT32) and size (300MiB at least). + */ +bool isEfiFilesystemSuitable( const Partition* candidate ); + /** * @brief Is the given @p partition bootable in EFI? Depending on * the partition table layout, this may mean different flags.