diff --git a/src/modules/partition/core/Config.cpp b/src/modules/partition/core/Config.cpp index 9f251229e..268399dbd 100644 --- a/src/modules/partition/core/Config.cpp +++ b/src/modules/partition/core/Config.cpp @@ -239,6 +239,20 @@ Config::setConfigurationMap( const QVariantMap& configurationMap ) Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage(); gs->insert( "allowManualPartitioning", CalamaresUtils::getBool( configurationMap, "allowManualPartitioning", true ) ); + + if ( configurationMap.contains( "requiredPartitionTableType" ) && + configurationMap.value( "requiredPartitionTableType" ).type() == QVariant::List ) + { + m_requiredPartitionTableType.clear(); + m_requiredPartitionTableType.append( configurationMap.value( "requiredPartitionTableType" ).toStringList() ); + } + else if ( configurationMap.contains( "requiredPartitionTableType" ) && + configurationMap.value( "requiredPartitionTableType" ).type() == QVariant::String ) + { + m_requiredPartitionTableType.clear(); + m_requiredPartitionTableType.append( configurationMap.value( "requiredPartitionTableType" ).toString() ); + } + gs->insert( "requiredPartitionTableType", m_requiredPartitionTableType); } void diff --git a/src/modules/partition/core/Config.h b/src/modules/partition/core/Config.h index 23ebdedf8..1629ccc22 100644 --- a/src/modules/partition/core/Config.h +++ b/src/modules/partition/core/Config.h @@ -114,6 +114,7 @@ private: InstallChoice m_initialInstallChoice = NoChoice; InstallChoice m_installChoice = NoChoice; qreal m_requiredStorageGiB = 0.0; // May duplicate setting in the welcome module + QStringList m_requiredPartitionTableType; }; /** @brief Given a set of swap choices, return a sensible value from it. diff --git a/src/modules/partition/gui/ChoicePage.cpp b/src/modules/partition/gui/ChoicePage.cpp index c81248c82..c3ac14735 100644 --- a/src/modules/partition/gui/ChoicePage.cpp +++ b/src/modules/partition/gui/ChoicePage.cpp @@ -89,6 +89,7 @@ ChoicePage::ChoicePage( Config* config, QWidget* parent ) auto gs = Calamares::JobQueue::instance()->globalStorage(); + m_requiredPartitionTableType = gs->value( "requiredPartitionTableType" ).toStringList(); m_defaultFsType = gs->value( "defaultFileSystemType" ).toString(); m_enableEncryptionWidget = gs->value( "enableLuksAutomatedPartitioning" ).toBool(); @@ -1252,6 +1253,7 @@ ChoicePage::setupActions() bool atLeastOneCanBeReplaced = false; bool atLeastOneIsMounted = false; // Suppress 'erase' if so bool isInactiveRAID = false; + bool matchTableType = false; #ifdef WITH_KPMCORE4API if ( currentDevice->type() == Device::Type::SoftwareRAID_Device @@ -1262,6 +1264,14 @@ ChoicePage::setupActions() } #endif + PartitionTable::TableType tableType = PartitionTable::unknownTableType; + if ( currentDevice->partitionTable() ) + { + tableType = currentDevice->partitionTable()->type(); + matchTableType = m_requiredPartitionTableType.size() == 0 || + m_requiredPartitionTableType.contains( PartitionTable::tableTypeToName( tableType ) ); + } + for ( auto it = PartitionIterator::begin( currentDevice ); it != PartitionIterator::end( currentDevice ); ++it ) { if ( PartUtils::canBeResized( *it ) ) @@ -1434,6 +1444,27 @@ ChoicePage::setupActions() m_replaceButton->hide(); } + if ( tableType != PartitionTable::unknownTableType && !matchTableType ) + { + m_messageLabel->setText( tr( "This storage device already may has an operating system on it, " + "but its partition table %1 mismatch the" + "requirement %2.
" ) + .arg( PartitionTable::tableTypeToName( tableType ) ) + .arg( m_requiredPartitionTableType.join( " or " ) ) ); + m_messageLabel->show(); + + cWarning() << "Partition table" << PartitionTable::tableTypeToName( tableType ) + << "does not match the requirement " << m_requiredPartitionTableType.join( " or " ) << ", " + "ENABLING erease feature and "; + "DISABLING alongside, replace and manual features."; + m_eraseButton->show(); + m_alongsideButton->hide(); + m_replaceButton->hide(); + m_somethingElseButton->hide(); + cDebug() << "Replace button suppressed because partition table type mismatch."; + force_uncheck( m_grp, m_replaceButton ); + } + if ( m_somethingElseButton->isHidden() && m_alongsideButton->isHidden() && m_replaceButton->isHidden() diff --git a/src/modules/partition/gui/ChoicePage.h b/src/modules/partition/gui/ChoicePage.h index cce91e9cc..118f23a46 100644 --- a/src/modules/partition/gui/ChoicePage.h +++ b/src/modules/partition/gui/ChoicePage.h @@ -154,6 +154,7 @@ private: int m_lastSelectedDeviceIndex = -1; int m_lastSelectedActionIndex = -1; + QStringList m_requiredPartitionTableType; QString m_defaultFsType; bool m_enableEncryptionWidget; diff --git a/src/modules/partition/partition.conf b/src/modules/partition/partition.conf index 451566f41..bfedddfca 100644 --- a/src/modules/partition/partition.conf +++ b/src/modules/partition/partition.conf @@ -102,6 +102,21 @@ initialSwapChoice: none # Names are case-sensitive and defined by KPMCore. # defaultPartitionTableType: msdos +# Requirement for partition table type +# +# Restrict the installation on disks that match the type of partition +# tables that are specified. +# +# Suggested values: msdos, gpt +# If nothing is specified, Calamares defaults to both "msdos" and "mbr". +# +# Names are case-sensitive and defined by KPMCore. +# requiredPartitionTableType: gpt +# or, +# requiredPartitionTableType: +# - msdos +# - gpt + # Default filesystem type, used when a "new" partition is made. # # When replacing a partition, the existing filesystem inside the