2020-08-25 16:05:56 +02:00
|
|
|
/* === This file is part of Calamares - <https://calamares.io> ===
|
2014-07-22 17:32:26 +02:00
|
|
|
*
|
2020-08-22 01:19:58 +02:00
|
|
|
* SPDX-FileCopyrightText: 2014 Aurélien Gâteau <agateau@kde.org>
|
|
|
|
* SPDX-FileCopyrightText: 2015-2016 Teo Mrnjavac <teo@kde.org>
|
|
|
|
* SPDX-FileCopyrightText: 2017 2019-2020, Adriaan de Groot <groot@kde.org>
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
2014-07-22 17:32:26 +02:00
|
|
|
*
|
2020-08-25 16:05:56 +02:00
|
|
|
* Calamares is Free Software: see the License-Identifier above.
|
2014-07-22 17:32:26 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-02-13 13:41:53 +01:00
|
|
|
#include "FillGlobalStorageJob.h"
|
2014-07-22 17:32:26 +02:00
|
|
|
|
2020-02-13 11:12:22 +01:00
|
|
|
#include "core/KPMHelpers.h"
|
2015-07-02 13:49:21 +02:00
|
|
|
#include "core/PartitionInfo.h"
|
2020-02-13 11:06:53 +01:00
|
|
|
|
2020-02-13 11:12:22 +01:00
|
|
|
#include "Branding.h"
|
2020-02-13 11:06:53 +01:00
|
|
|
#include "GlobalStorage.h"
|
|
|
|
#include "JobQueue.h"
|
2020-02-13 13:48:12 +01:00
|
|
|
#include "partition/FileSystem.h"
|
2019-06-13 12:27:39 +02:00
|
|
|
#include "partition/PartitionIterator.h"
|
2015-06-04 18:57:50 +02:00
|
|
|
#include "utils/Logger.h"
|
2014-07-22 17:32:26 +02:00
|
|
|
|
2019-06-14 23:20:26 +02:00
|
|
|
#include <kpmcore/core/device.h>
|
|
|
|
#include <kpmcore/core/partition.h>
|
|
|
|
#include <kpmcore/fs/filesystem.h>
|
|
|
|
#include <kpmcore/fs/luks.h>
|
2014-07-22 17:32:26 +02:00
|
|
|
|
2014-07-23 18:16:55 +02:00
|
|
|
#include <QDebug>
|
2014-07-28 14:58:06 +02:00
|
|
|
#include <QDir>
|
|
|
|
#include <QFileInfo>
|
2016-05-05 13:29:08 +02:00
|
|
|
#include <QProcess>
|
2014-07-28 14:58:06 +02:00
|
|
|
|
2020-02-27 14:29:54 +01:00
|
|
|
using CalamaresUtils::Partition::PartitionIterator;
|
2020-02-13 13:48:12 +01:00
|
|
|
using CalamaresUtils::Partition::untranslatedFS;
|
|
|
|
using CalamaresUtils::Partition::userVisibleFS;
|
2020-02-13 11:06:53 +01:00
|
|
|
|
2020-02-13 11:12:22 +01:00
|
|
|
typedef QHash< QString, QString > UuidForPartitionHash;
|
2014-07-28 14:58:06 +02:00
|
|
|
|
|
|
|
static UuidForPartitionHash
|
2020-02-13 11:12:22 +01:00
|
|
|
findPartitionUuids( QList< Device* > devices )
|
2014-07-28 14:58:06 +02:00
|
|
|
{
|
|
|
|
UuidForPartitionHash hash;
|
2015-06-04 19:34:30 +02:00
|
|
|
foreach ( Device* device, devices )
|
2014-07-28 14:58:06 +02:00
|
|
|
{
|
2020-02-13 11:12:22 +01:00
|
|
|
for ( auto it = PartitionIterator::begin( device ); it != PartitionIterator::end( device ); ++it )
|
2015-06-04 19:34:30 +02:00
|
|
|
{
|
|
|
|
Partition* p = *it;
|
|
|
|
QString path = p->partitionPath();
|
|
|
|
QString uuid = p->fileSystem().readUUID( p->partitionPath() );
|
|
|
|
hash.insert( path, uuid );
|
|
|
|
}
|
2014-07-28 14:58:06 +02:00
|
|
|
}
|
2018-10-05 13:59:44 +02:00
|
|
|
|
|
|
|
if ( hash.isEmpty() )
|
2020-02-13 11:12:22 +01:00
|
|
|
{
|
2019-03-17 21:08:31 +01:00
|
|
|
cDebug() << "No UUIDs found for existing partitions.";
|
2020-02-13 11:12:22 +01:00
|
|
|
}
|
2014-07-28 14:58:06 +02:00
|
|
|
return hash;
|
|
|
|
}
|
2014-07-23 18:16:55 +02:00
|
|
|
|
2016-05-05 13:29:08 +02:00
|
|
|
|
|
|
|
static QString
|
|
|
|
getLuksUuid( const QString& path )
|
|
|
|
{
|
|
|
|
QProcess process;
|
|
|
|
process.setProgram( "cryptsetup" );
|
|
|
|
process.setArguments( { "luksUUID", path } );
|
|
|
|
process.start();
|
|
|
|
process.waitForFinished();
|
|
|
|
if ( process.exitStatus() != QProcess::NormalExit || process.exitCode() )
|
2020-02-13 11:12:22 +01:00
|
|
|
{
|
2016-05-05 13:29:08 +02:00
|
|
|
return QString();
|
2020-02-13 11:12:22 +01:00
|
|
|
}
|
2016-05-05 13:29:08 +02:00
|
|
|
QString uuid = QString::fromLocal8Bit( process.readAllStandardOutput() ).trimmed();
|
|
|
|
return uuid;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-23 18:16:55 +02:00
|
|
|
static QVariant
|
2014-07-28 14:58:06 +02:00
|
|
|
mapForPartition( Partition* partition, const QString& uuid )
|
2014-07-23 18:16:55 +02:00
|
|
|
{
|
|
|
|
QVariantMap map;
|
|
|
|
map[ "device" ] = partition->partitionPath();
|
2020-03-12 20:27:35 +01:00
|
|
|
map[ "partlabel" ] = partition->label();
|
|
|
|
map[ "partuuid" ] = partition->uuid();
|
2020-07-03 22:33:00 +02:00
|
|
|
#ifdef WITH_KPMCORE42API
|
2020-06-16 19:20:37 +02:00
|
|
|
map[ "parttype" ] = partition->type();
|
|
|
|
map[ "partattrs" ] = partition->attributes();
|
2020-07-03 22:33:00 +02:00
|
|
|
#endif
|
2014-07-23 18:16:55 +02:00
|
|
|
map[ "mountPoint" ] = PartitionInfo::mountPoint( partition );
|
2020-02-13 11:22:09 +01:00
|
|
|
map[ "fsName" ] = userVisibleFS( partition->fileSystem() );
|
2020-02-13 11:06:53 +01:00
|
|
|
map[ "fs" ] = untranslatedFS( partition->fileSystem() );
|
2020-02-13 11:12:22 +01:00
|
|
|
if ( partition->fileSystem().type() == FileSystem::Luks
|
|
|
|
&& dynamic_cast< FS::luks& >( partition->fileSystem() ).innerFS() )
|
|
|
|
{
|
2020-02-13 11:06:53 +01:00
|
|
|
map[ "fs" ] = untranslatedFS( dynamic_cast< FS::luks& >( partition->fileSystem() ).innerFS() );
|
2020-02-13 11:12:22 +01:00
|
|
|
}
|
2014-07-28 14:58:06 +02:00
|
|
|
map[ "uuid" ] = uuid;
|
2020-02-20 12:07:18 +01:00
|
|
|
map[ "claimed" ] = PartitionInfo::format( partition ); // If we formatted it, it's ours
|
2018-10-05 13:59:44 +02:00
|
|
|
|
|
|
|
// Debugging for inside the loop in createPartitionList(),
|
|
|
|
// so indent a bit
|
2019-02-11 15:18:21 +01:00
|
|
|
Logger::CDebug deb;
|
2020-02-13 11:12:22 +01:00
|
|
|
using TR = Logger::DebugRow< const char* const, const QString& >;
|
2019-04-15 14:59:12 +02:00
|
|
|
deb << Logger::SubEntry << "mapping for" << partition->partitionPath() << partition->deviceNode()
|
2020-03-12 20:27:35 +01:00
|
|
|
<< TR( "partlabel", map[ "partlabel" ].toString() ) << TR( "partuuid", map[ "partuuid" ].toString() )
|
2020-06-16 19:20:37 +02:00
|
|
|
<< TR( "parttype", map[ "partype" ].toString() ) << TR( "partattrs", map[ "partattrs" ].toString() )
|
2020-03-17 14:31:17 +01:00
|
|
|
<< TR( "mountPoint:", PartitionInfo::mountPoint( partition ) ) << TR( "fs:", map[ "fs" ].toString() )
|
2020-02-27 14:29:54 +01:00
|
|
|
<< TR( "fsName", map[ "fsName" ].toString() ) << TR( "uuid", uuid )
|
2020-02-20 12:07:18 +01:00
|
|
|
<< TR( "claimed", map[ "claimed" ].toString() );
|
2016-04-22 16:50:46 +02:00
|
|
|
|
|
|
|
if ( partition->roles().has( PartitionRole::Luks ) )
|
|
|
|
{
|
|
|
|
const FileSystem& fsRef = partition->fileSystem();
|
|
|
|
const FS::luks* luksFs = dynamic_cast< const FS::luks* >( &fsRef );
|
|
|
|
if ( luksFs )
|
|
|
|
{
|
2016-09-05 08:20:02 +02:00
|
|
|
map[ "luksMapperName" ] = luksFs->mapperName().split( "/" ).last();
|
2016-05-05 13:29:08 +02:00
|
|
|
map[ "luksUuid" ] = getLuksUuid( partition->partitionPath() );
|
2016-05-06 16:59:11 +02:00
|
|
|
map[ "luksPassphrase" ] = luksFs->passphrase();
|
2018-10-05 13:59:44 +02:00
|
|
|
deb << TR( "luksMapperName:", map[ "luksMapperName" ].toString() );
|
2016-04-22 16:50:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-23 18:16:55 +02:00
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
|
|
|
FillGlobalStorageJob::FillGlobalStorageJob( QList< Device* > devices, const QString& bootLoaderPath )
|
2014-07-22 17:32:26 +02:00
|
|
|
: m_devices( devices )
|
2014-07-23 18:16:55 +02:00
|
|
|
, m_bootLoaderPath( bootLoaderPath )
|
2014-07-22 17:32:26 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QString
|
|
|
|
FillGlobalStorageJob::prettyName() const
|
|
|
|
{
|
|
|
|
return tr( "Set partition information" );
|
|
|
|
}
|
|
|
|
|
2015-04-10 17:46:42 +02:00
|
|
|
|
|
|
|
QString
|
|
|
|
FillGlobalStorageJob::prettyDescription() const
|
|
|
|
{
|
|
|
|
QStringList lines;
|
|
|
|
|
2020-02-27 13:49:02 +01:00
|
|
|
const auto partitionList = createPartitionList();
|
2020-02-13 11:12:22 +01:00
|
|
|
for ( const QVariant& partitionItem : partitionList )
|
2015-04-10 17:46:42 +02:00
|
|
|
{
|
|
|
|
if ( partitionItem.type() == QVariant::Map )
|
|
|
|
{
|
|
|
|
QVariantMap partitionMap = partitionItem.toMap();
|
|
|
|
QString path = partitionMap.value( "device" ).toString();
|
|
|
|
QString mountPoint = partitionMap.value( "mountPoint" ).toString();
|
|
|
|
QString fsType = partitionMap.value( "fs" ).toString();
|
|
|
|
if ( mountPoint.isEmpty() || fsType.isEmpty() )
|
2020-02-13 11:12:22 +01:00
|
|
|
{
|
2015-04-10 17:46:42 +02:00
|
|
|
continue;
|
2020-02-13 11:12:22 +01:00
|
|
|
}
|
2015-04-10 17:46:42 +02:00
|
|
|
if ( path.isEmpty() )
|
|
|
|
{
|
|
|
|
if ( mountPoint == "/" )
|
2020-02-13 11:12:22 +01:00
|
|
|
{
|
2015-04-10 17:46:42 +02:00
|
|
|
lines.append( tr( "Install %1 on <strong>new</strong> %2 system partition." )
|
2020-05-04 12:48:11 +02:00
|
|
|
.arg( Calamares::Branding::instance()->shortProductName() )
|
2020-02-13 11:12:22 +01:00
|
|
|
.arg( fsType ) );
|
|
|
|
}
|
2015-04-10 17:46:42 +02:00
|
|
|
else
|
2020-02-13 11:12:22 +01:00
|
|
|
{
|
2015-04-10 17:46:42 +02:00
|
|
|
lines.append( tr( "Set up <strong>new</strong> %2 partition with mount point "
|
|
|
|
"<strong>%1</strong>." )
|
2020-02-13 11:12:22 +01:00
|
|
|
.arg( mountPoint )
|
|
|
|
.arg( fsType ) );
|
|
|
|
}
|
2015-04-10 17:46:42 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( mountPoint == "/" )
|
2020-02-13 11:12:22 +01:00
|
|
|
{
|
2015-04-10 17:46:42 +02:00
|
|
|
lines.append( tr( "Install %2 on %3 system partition <strong>%1</strong>." )
|
2020-02-13 11:12:22 +01:00
|
|
|
.arg( path )
|
2020-05-04 12:48:11 +02:00
|
|
|
.arg( Calamares::Branding::instance()->shortProductName() )
|
2020-02-13 11:12:22 +01:00
|
|
|
.arg( fsType ) );
|
|
|
|
}
|
2015-04-10 17:46:42 +02:00
|
|
|
else
|
2020-02-13 11:12:22 +01:00
|
|
|
{
|
2015-04-10 17:46:42 +02:00
|
|
|
lines.append( tr( "Set up %3 partition <strong>%1</strong> with mount point "
|
|
|
|
"<strong>%2</strong>." )
|
2020-02-13 11:12:22 +01:00
|
|
|
.arg( path )
|
|
|
|
.arg( mountPoint )
|
|
|
|
.arg( fsType ) );
|
|
|
|
}
|
2015-04-10 17:46:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant bootloaderMap = createBootLoaderMap();
|
|
|
|
if ( !m_bootLoaderPath.isEmpty() )
|
|
|
|
{
|
2020-02-13 11:12:22 +01:00
|
|
|
lines.append( tr( "Install boot loader on <strong>%1</strong>." ).arg( m_bootLoaderPath ) );
|
2015-04-10 17:46:42 +02:00
|
|
|
}
|
|
|
|
return lines.join( "<br/>" );
|
|
|
|
}
|
|
|
|
|
2015-06-13 02:26:38 +02:00
|
|
|
|
|
|
|
QString
|
|
|
|
FillGlobalStorageJob::prettyStatusMessage() const
|
|
|
|
{
|
|
|
|
return tr( "Setting up mount points." );
|
|
|
|
}
|
|
|
|
|
2020-02-27 14:29:54 +01:00
|
|
|
|
|
|
|
/** @brief note which FS'ses are in use in GS
|
|
|
|
*
|
|
|
|
* .. mark as "1" if it's on the system, somewhere
|
|
|
|
* .. mark as "2" if it's one of the claimed / in-use FSses
|
|
|
|
*
|
|
|
|
* Stores a GS key called "filesystems_use" with this mapping.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
storeFSUse( Calamares::GlobalStorage* storage, const QVariantList& partitions )
|
|
|
|
{
|
|
|
|
QMap< QString, int > fsUses;
|
|
|
|
for ( const auto& p : partitions )
|
|
|
|
{
|
|
|
|
const auto pmap = p.toMap();
|
|
|
|
|
|
|
|
QString fs = pmap.value( "fs" ).toString();
|
|
|
|
int thisUse = pmap.value( "claimed" ).toBool() ? 2 : 1;
|
|
|
|
|
|
|
|
if ( fs.isEmpty() )
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
int newUse = qMax( fsUses.value( fs ), thisUse ); // value() is 0 if not present
|
|
|
|
fsUses.insert( fs, newUse );
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariantMap fsUsesVariant;
|
|
|
|
for ( auto it = fsUses.cbegin(); it != fsUses.cend(); ++it )
|
|
|
|
{
|
|
|
|
fsUsesVariant.insert( it.key(), it.value() );
|
|
|
|
}
|
|
|
|
|
|
|
|
storage->insert( "filesystems_use", fsUsesVariant );
|
|
|
|
}
|
|
|
|
|
2014-07-22 17:32:26 +02:00
|
|
|
Calamares::JobResult
|
|
|
|
FillGlobalStorageJob::exec()
|
2014-07-23 18:16:55 +02:00
|
|
|
{
|
|
|
|
Calamares::GlobalStorage* storage = Calamares::JobQueue::instance()->globalStorage();
|
2020-02-27 14:29:54 +01:00
|
|
|
const auto partitions = createPartitionList();
|
2020-02-20 11:59:48 +01:00
|
|
|
cDebug() << "Saving partition information map to GlobalStorage[\"partitions\"]";
|
2020-02-27 14:29:54 +01:00
|
|
|
storage->insert( "partitions", partitions );
|
|
|
|
storeFSUse( storage, partitions );
|
2020-02-27 13:49:02 +01:00
|
|
|
|
2015-07-07 19:16:22 +02:00
|
|
|
if ( !m_bootLoaderPath.isEmpty() )
|
|
|
|
{
|
|
|
|
QVariant var = createBootLoaderMap();
|
|
|
|
if ( !var.isValid() )
|
2020-02-13 11:12:22 +01:00
|
|
|
{
|
2015-07-07 19:16:22 +02:00
|
|
|
cDebug() << "Failed to find path for boot loader";
|
2020-02-13 11:12:22 +01:00
|
|
|
}
|
2016-12-02 18:36:02 +01:00
|
|
|
cDebug() << "FillGlobalStorageJob writing bootLoader path:" << var;
|
2015-07-07 19:16:22 +02:00
|
|
|
storage->insert( "bootLoader", var );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-12-02 18:36:02 +01:00
|
|
|
cDebug() << "FillGlobalStorageJob writing empty bootLoader value";
|
2015-07-07 19:16:22 +02:00
|
|
|
storage->insert( "bootLoader", QVariant() );
|
|
|
|
}
|
2014-07-23 18:16:55 +02:00
|
|
|
return Calamares::JobResult::ok();
|
|
|
|
}
|
|
|
|
|
2020-02-27 13:49:02 +01:00
|
|
|
QVariantList
|
2015-04-10 17:46:42 +02:00
|
|
|
FillGlobalStorageJob::createPartitionList() const
|
2014-07-22 17:32:26 +02:00
|
|
|
{
|
2015-06-04 19:34:30 +02:00
|
|
|
UuidForPartitionHash hash = findPartitionUuids( m_devices );
|
2014-07-22 17:32:26 +02:00
|
|
|
QVariantList lst;
|
2020-02-20 11:59:48 +01:00
|
|
|
cDebug() << "Building partition information map";
|
2014-07-28 14:58:06 +02:00
|
|
|
for ( auto device : m_devices )
|
2015-06-04 18:57:50 +02:00
|
|
|
{
|
2019-04-15 14:59:12 +02:00
|
|
|
cDebug() << Logger::SubEntry << "partitions on" << device->deviceNode();
|
2020-02-13 11:12:22 +01:00
|
|
|
for ( auto it = PartitionIterator::begin( device ); it != PartitionIterator::end( device ); ++it )
|
2015-06-04 18:57:50 +02:00
|
|
|
{
|
2018-10-05 13:59:44 +02:00
|
|
|
// Debug-logging is done when creating the map
|
2014-07-28 14:58:06 +02:00
|
|
|
lst << mapForPartition( *it, hash.value( ( *it )->partitionPath() ) );
|
2015-06-04 18:57:50 +02:00
|
|
|
}
|
|
|
|
}
|
2014-07-23 18:16:55 +02:00
|
|
|
return lst;
|
2014-07-22 17:32:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QVariant
|
2015-04-10 17:46:42 +02:00
|
|
|
FillGlobalStorageJob::createBootLoaderMap() const
|
2014-07-22 17:32:26 +02:00
|
|
|
{
|
|
|
|
QVariantMap map;
|
2014-07-23 18:16:55 +02:00
|
|
|
QString path = m_bootLoaderPath;
|
|
|
|
if ( !path.startsWith( "/dev/" ) )
|
|
|
|
{
|
2015-09-18 15:41:07 +02:00
|
|
|
Partition* partition = KPMHelpers::findPartitionByMountPoint( m_devices, path );
|
2014-07-23 18:16:55 +02:00
|
|
|
if ( !partition )
|
2020-02-13 11:12:22 +01:00
|
|
|
{
|
2014-07-23 18:16:55 +02:00
|
|
|
return QVariant();
|
2020-02-13 11:12:22 +01:00
|
|
|
}
|
2014-07-23 18:16:55 +02:00
|
|
|
path = partition->partitionPath();
|
|
|
|
}
|
|
|
|
map[ "installPath" ] = path;
|
2014-07-22 17:32:26 +02:00
|
|
|
return map;
|
|
|
|
}
|