2020-08-25 16:05:56 +02:00
|
|
|
/* === This file is part of Calamares - <https://calamares.io> ===
|
2015-09-18 15:39:49 +02:00
|
|
|
*
|
2020-08-22 01:19:58 +02:00
|
|
|
* SPDX-FileCopyrightText: 2015-2016 Teo Mrnjavac <teo@kde.org>
|
2019-04-01 13:55:14 +02:00
|
|
|
* Copyright 2018-2019 Adriaan de Groot <groot@kde.org>
|
2020-08-22 01:19:58 +02:00
|
|
|
* SPDX-FileCopyrightText: 2019 Collabora Ltd <arnaud.ferraris@collabora.com>
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
2015-09-18 15:39:49 +02:00
|
|
|
*
|
2020-08-25 16:05:56 +02:00
|
|
|
* Calamares is Free Software: see the License-Identifier above.
|
2015-09-18 15:39:49 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "PartUtils.h"
|
|
|
|
|
|
|
|
#include "core/DeviceModel.h"
|
|
|
|
#include "core/KPMHelpers.h"
|
2018-05-16 13:28:30 +02:00
|
|
|
#include "core/PartitionInfo.h"
|
2019-06-13 12:27:39 +02:00
|
|
|
|
|
|
|
#include "GlobalStorage.h"
|
|
|
|
#include "JobQueue.h"
|
2019-06-20 14:49:44 +02:00
|
|
|
#include "partition/Mount.h"
|
2019-06-13 12:27:39 +02:00
|
|
|
#include "partition/PartitionIterator.h"
|
2019-06-13 14:41:33 +02:00
|
|
|
#include "partition/PartitionQuery.h"
|
2019-06-13 12:27:39 +02:00
|
|
|
#include "utils/CalamaresUtilsSystem.h"
|
|
|
|
#include "utils/Logger.h"
|
2015-09-18 15:39:49 +02:00
|
|
|
|
2017-07-11 12:07:15 +02:00
|
|
|
#include <kpmcore/backend/corebackend.h>
|
|
|
|
#include <kpmcore/backend/corebackendmanager.h>
|
|
|
|
#include <kpmcore/core/device.h>
|
2015-09-18 15:39:49 +02:00
|
|
|
#include <kpmcore/core/partition.h>
|
|
|
|
|
|
|
|
#include <QProcess>
|
2016-07-08 17:02:23 +02:00
|
|
|
#include <QTemporaryDir>
|
2015-09-18 15:39:49 +02:00
|
|
|
|
2019-06-13 14:41:33 +02:00
|
|
|
using CalamaresUtils::Partition::isPartitionFreeSpace;
|
|
|
|
using CalamaresUtils::Partition::isPartitionNew;
|
|
|
|
|
2015-09-18 15:39:49 +02:00
|
|
|
namespace PartUtils
|
|
|
|
{
|
|
|
|
|
2019-03-17 23:10:41 +01:00
|
|
|
QString
|
2019-02-25 22:39:19 +01:00
|
|
|
convenienceName( const Partition* const candidate )
|
|
|
|
{
|
|
|
|
if ( !candidate->mountPoint().isEmpty() )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2019-02-25 22:39:19 +01:00
|
|
|
return candidate->mountPoint();
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2019-02-25 22:39:19 +01:00
|
|
|
if ( !candidate->partitionPath().isEmpty() )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2019-02-25 22:39:19 +01:00
|
|
|
return candidate->partitionPath();
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2019-02-25 22:39:19 +01:00
|
|
|
if ( !candidate->devicePath().isEmpty() )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2019-02-25 22:39:19 +01:00
|
|
|
return candidate->devicePath();
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2019-02-25 22:39:19 +01:00
|
|
|
if ( !candidate->deviceNode().isEmpty() )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2019-02-25 22:39:19 +01:00
|
|
|
return candidate->devicePath();
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2019-02-25 22:39:19 +01:00
|
|
|
|
|
|
|
QString p;
|
|
|
|
QTextStream s( &p );
|
2020-02-14 11:15:57 +01:00
|
|
|
s << (void*)candidate;
|
2019-02-25 22:39:19 +01:00
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2019-06-07 22:55:50 +02:00
|
|
|
/** @brief Get the globalStorage setting for required space. */
|
|
|
|
static double
|
|
|
|
getRequiredStorageGiB( bool& ok )
|
|
|
|
{
|
|
|
|
return Calamares::JobQueue::instance()->globalStorage()->value( "requiredStorageGiB" ).toDouble( &ok );
|
|
|
|
}
|
|
|
|
|
2016-02-12 15:02:17 +01:00
|
|
|
bool
|
|
|
|
canBeReplaced( Partition* candidate )
|
|
|
|
{
|
2016-07-28 12:48:40 +02:00
|
|
|
if ( !candidate )
|
2019-06-07 23:19:24 +02:00
|
|
|
{
|
|
|
|
cDebug() << "Partition* is NULL";
|
2016-07-28 12:48:40 +02:00
|
|
|
return false;
|
2019-06-07 23:19:24 +02:00
|
|
|
}
|
2016-07-28 12:48:40 +02:00
|
|
|
|
2019-06-07 23:19:24 +02:00
|
|
|
cDebug() << "Checking if" << convenienceName( candidate ) << "can be replaced.";
|
2017-09-07 10:55:26 +02:00
|
|
|
if ( candidate->isMounted() )
|
2019-06-07 23:19:24 +02:00
|
|
|
{
|
|
|
|
cDebug() << Logger::SubEntry << "NO, it is mounted.";
|
2017-09-07 10:55:26 +02:00
|
|
|
return false;
|
2019-06-07 23:19:24 +02:00
|
|
|
}
|
2017-09-07 10:55:26 +02:00
|
|
|
|
2016-02-12 15:02:17 +01:00
|
|
|
bool ok = false;
|
2019-06-07 23:19:24 +02:00
|
|
|
double requiredStorageGiB = getRequiredStorageGiB( ok );
|
|
|
|
if ( !ok )
|
|
|
|
{
|
|
|
|
cDebug() << Logger::SubEntry << "NO, requiredStorageGiB is not set correctly.";
|
|
|
|
return false;
|
|
|
|
}
|
2016-02-12 15:02:17 +01:00
|
|
|
|
|
|
|
qint64 availableStorageB = candidate->capacity();
|
2019-06-07 23:19:24 +02:00
|
|
|
qint64 requiredStorageB = CalamaresUtils::GiBtoBytes( requiredStorageGiB + 0.5 );
|
|
|
|
|
|
|
|
if ( availableStorageB > requiredStorageB )
|
2016-02-12 15:02:17 +01:00
|
|
|
{
|
2019-02-25 22:39:19 +01:00
|
|
|
cDebug() << "Partition" << convenienceName( candidate ) << "authorized for replace install.";
|
2016-02-12 15:02:17 +01:00
|
|
|
return true;
|
|
|
|
}
|
2019-06-07 23:19:24 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
Logger::CDebug deb;
|
|
|
|
deb << Logger::SubEntry << "NO, insufficient storage";
|
|
|
|
deb << Logger::Continuation << "Required storage B:" << requiredStorageB
|
2020-02-14 11:15:57 +01:00
|
|
|
<< QString( "(%1GiB)" ).arg( requiredStorageGiB );
|
2019-06-07 23:19:24 +02:00
|
|
|
deb << Logger::Continuation << "Available storage B:" << availableStorageB
|
2020-02-14 11:15:57 +01:00
|
|
|
<< QString( "(%1GiB)" ).arg( CalamaresUtils::BytesToGiB( availableStorageB ) );
|
2019-06-07 23:19:24 +02:00
|
|
|
return false;
|
|
|
|
}
|
2016-02-12 15:02:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-02-11 16:52:21 +01:00
|
|
|
bool
|
|
|
|
canBeResized( Partition* candidate )
|
|
|
|
{
|
2016-07-28 12:48:40 +02:00
|
|
|
if ( !candidate )
|
2018-12-03 16:42:40 +01:00
|
|
|
{
|
|
|
|
cDebug() << "Partition* is NULL";
|
2016-07-28 12:48:40 +02:00
|
|
|
return false;
|
2018-12-03 16:42:40 +01:00
|
|
|
}
|
2016-07-28 12:48:40 +02:00
|
|
|
|
2019-02-25 22:39:19 +01:00
|
|
|
cDebug() << "Checking if" << convenienceName( candidate ) << "can be resized.";
|
2020-02-14 11:15:57 +01:00
|
|
|
if ( !candidate->fileSystem().supportGrow() || !candidate->fileSystem().supportShrink() )
|
2018-12-03 16:42:40 +01:00
|
|
|
{
|
2019-04-15 14:15:17 +02:00
|
|
|
cDebug() << Logger::SubEntry << "NO, filesystem" << candidate->fileSystem().name()
|
2020-02-14 11:15:57 +01:00
|
|
|
<< "does not support resize.";
|
2016-02-11 16:52:21 +01:00
|
|
|
return false;
|
2018-12-03 16:42:40 +01:00
|
|
|
}
|
2016-02-11 16:52:21 +01:00
|
|
|
|
2019-06-13 14:41:33 +02:00
|
|
|
if ( isPartitionFreeSpace( candidate ) )
|
2018-12-03 16:42:40 +01:00
|
|
|
{
|
2019-04-15 14:15:17 +02:00
|
|
|
cDebug() << Logger::SubEntry << "NO, partition is free space";
|
2016-03-10 12:54:16 +01:00
|
|
|
return false;
|
2018-12-03 16:42:40 +01:00
|
|
|
}
|
2016-03-10 12:54:16 +01:00
|
|
|
|
2017-09-07 10:55:26 +02:00
|
|
|
if ( candidate->isMounted() )
|
2018-12-03 16:42:40 +01:00
|
|
|
{
|
2019-04-15 14:15:17 +02:00
|
|
|
cDebug() << Logger::SubEntry << "NO, partition is mounted";
|
2017-09-07 10:55:26 +02:00
|
|
|
return false;
|
2018-12-03 16:42:40 +01:00
|
|
|
}
|
2017-09-07 10:55:26 +02:00
|
|
|
|
2016-02-12 16:36:50 +01:00
|
|
|
if ( candidate->roles().has( PartitionRole::Primary ) )
|
|
|
|
{
|
|
|
|
PartitionTable* table = dynamic_cast< PartitionTable* >( candidate->parent() );
|
|
|
|
if ( !table )
|
2018-12-03 16:42:40 +01:00
|
|
|
{
|
2019-04-15 14:15:17 +02:00
|
|
|
cDebug() << Logger::SubEntry << "NO, no partition table found";
|
2016-02-12 16:36:50 +01:00
|
|
|
return false;
|
2018-12-03 16:42:40 +01:00
|
|
|
}
|
2016-02-12 16:36:50 +01:00
|
|
|
|
|
|
|
if ( table->numPrimaries() >= table->maxPrimaries() )
|
2018-12-03 16:42:40 +01:00
|
|
|
{
|
2020-02-14 11:15:57 +01:00
|
|
|
cDebug() << Logger::SubEntry << "NO, partition table already has" << table->maxPrimaries()
|
|
|
|
<< "primary partitions.";
|
2016-02-12 16:36:50 +01:00
|
|
|
return false;
|
2018-12-03 16:42:40 +01:00
|
|
|
}
|
2016-02-12 16:36:50 +01:00
|
|
|
}
|
|
|
|
|
2016-02-11 16:52:21 +01:00
|
|
|
bool ok = false;
|
2019-06-07 23:04:24 +02:00
|
|
|
double requiredStorageGiB = getRequiredStorageGiB( ok );
|
2019-06-07 22:51:33 +02:00
|
|
|
if ( !ok )
|
|
|
|
{
|
|
|
|
cDebug() << Logger::SubEntry << "NO, requiredStorageGiB is not set correctly.";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-04-04 17:58:03 +02:00
|
|
|
// We require a little more for partitioning overhead and swap file
|
2019-06-07 23:04:24 +02:00
|
|
|
double advisedStorageGiB = requiredStorageGiB + 0.5 + 2.0;
|
2016-02-11 16:52:21 +01:00
|
|
|
qint64 availableStorageB = candidate->available();
|
2019-06-07 23:04:24 +02:00
|
|
|
qint64 advisedStorageB = CalamaresUtils::GiBtoBytes( advisedStorageGiB );
|
2016-02-11 16:52:21 +01:00
|
|
|
|
2019-06-07 22:51:33 +02:00
|
|
|
if ( availableStorageB > advisedStorageB )
|
2016-02-11 16:52:21 +01:00
|
|
|
{
|
2019-02-25 22:39:19 +01:00
|
|
|
cDebug() << "Partition" << convenienceName( candidate ) << "authorized for resize + autopartition install.";
|
2016-02-11 16:52:21 +01:00
|
|
|
return true;
|
|
|
|
}
|
2019-06-07 22:51:33 +02:00
|
|
|
else
|
2019-04-04 17:58:03 +02:00
|
|
|
{
|
2019-04-15 16:05:29 +02:00
|
|
|
Logger::CDebug deb;
|
2019-04-15 14:15:17 +02:00
|
|
|
deb << Logger::SubEntry << "NO, insufficient storage";
|
|
|
|
deb << Logger::Continuation << "Required storage B:" << advisedStorageB
|
2020-02-14 11:15:57 +01:00
|
|
|
<< QString( "(%1GiB)" ).arg( advisedStorageGiB );
|
2019-04-15 14:15:17 +02:00
|
|
|
deb << Logger::Continuation << "Available storage B:" << availableStorageB
|
2020-02-14 11:15:57 +01:00
|
|
|
<< QString( "(%1GiB)" ).arg( CalamaresUtils::BytesToGiB( availableStorageB ) ) << "for"
|
|
|
|
<< convenienceName( candidate ) << "length:" << candidate->length()
|
|
|
|
<< "sectorsUsed:" << candidate->sectorsUsed() << "fsType:" << candidate->fileSystem().name();
|
2019-04-04 17:58:03 +02:00
|
|
|
return false;
|
|
|
|
}
|
2016-02-11 16:52:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-18 15:39:49 +02:00
|
|
|
bool
|
2020-10-05 11:39:04 +02:00
|
|
|
canBeResized( DeviceModel* dm, const QString& partitionPath )
|
2015-09-18 15:39:49 +02:00
|
|
|
{
|
2018-12-03 16:42:40 +01:00
|
|
|
cDebug() << "Checking if" << partitionPath << "can be resized.";
|
2015-09-18 15:39:49 +02:00
|
|
|
QString partitionWithOs = partitionPath;
|
|
|
|
if ( partitionWithOs.startsWith( "/dev/" ) )
|
|
|
|
{
|
|
|
|
for ( int i = 0; i < dm->rowCount(); ++i )
|
|
|
|
{
|
|
|
|
Device* dev = dm->deviceForIndex( dm->index( i ) );
|
2019-06-13 14:41:33 +02:00
|
|
|
Partition* candidate = CalamaresUtils::Partition::findPartitionByPath( { dev }, partitionWithOs );
|
2015-09-18 15:39:49 +02:00
|
|
|
if ( candidate )
|
|
|
|
{
|
2016-02-11 16:52:21 +01:00
|
|
|
return canBeResized( candidate );
|
2015-09-18 15:39:49 +02:00
|
|
|
}
|
|
|
|
}
|
2019-04-15 14:15:17 +02:00
|
|
|
cDebug() << Logger::SubEntry << "no Partition* found for" << partitionWithOs;
|
2015-09-18 15:39:49 +02:00
|
|
|
}
|
|
|
|
|
2019-04-15 14:15:17 +02:00
|
|
|
cDebug() << Logger::SubEntry << "Partition" << partitionWithOs << "CANNOT BE RESIZED FOR AUTOINSTALL.";
|
2015-09-18 15:39:49 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-28 11:36:21 +02:00
|
|
|
static FstabEntryList
|
2016-07-08 17:02:23 +02:00
|
|
|
lookForFstabEntries( const QString& partitionPath )
|
|
|
|
{
|
2020-02-14 11:15:57 +01:00
|
|
|
QStringList mountOptions { "ro" };
|
2018-11-12 17:07:18 +01:00
|
|
|
|
2020-02-14 11:15:57 +01:00
|
|
|
auto r = CalamaresUtils::System::runCommand( CalamaresUtils::System::RunLocation::RunInHost,
|
|
|
|
{ "blkid", "-s", "TYPE", "-o", "value", partitionPath } );
|
2018-11-12 17:07:18 +01:00
|
|
|
if ( r.getExitCode() )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2018-11-12 17:07:18 +01:00
|
|
|
cWarning() << "blkid on" << partitionPath << "failed.";
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2018-11-12 17:07:18 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
QString fstype = r.getOutput().trimmed();
|
|
|
|
if ( ( fstype == "ext3" ) || ( fstype == "ext4" ) )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2018-11-12 17:07:18 +01:00
|
|
|
mountOptions.append( "noload" );
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2018-11-12 17:07:18 +01:00
|
|
|
}
|
|
|
|
|
2020-02-14 11:15:57 +01:00
|
|
|
cDebug() << "Checking device" << partitionPath << "for fstab (fs=" << r.getOutput() << ')';
|
2018-12-03 16:28:40 +01:00
|
|
|
|
2016-07-08 17:02:23 +02:00
|
|
|
FstabEntryList fstabEntries;
|
|
|
|
|
2020-02-14 11:15:57 +01:00
|
|
|
CalamaresUtils::Partition::TemporaryMount mount( partitionPath, QString(), mountOptions.join( ',' ) );
|
2019-06-20 14:49:44 +02:00
|
|
|
if ( mount.isValid() )
|
2016-07-08 17:02:23 +02:00
|
|
|
{
|
2019-06-21 16:30:09 +02:00
|
|
|
QFile fstabFile( mount.path() + "/etc/fstab" );
|
2019-02-28 13:18:02 +01:00
|
|
|
|
2019-04-15 14:59:12 +02:00
|
|
|
cDebug() << Logger::SubEntry << "reading" << fstabFile.fileName();
|
2019-02-28 13:18:02 +01:00
|
|
|
|
2016-07-08 17:02:23 +02:00
|
|
|
if ( fstabFile.open( QIODevice::ReadOnly | QIODevice::Text ) )
|
|
|
|
{
|
2020-02-14 11:15:57 +01:00
|
|
|
const QStringList fstabLines = QString::fromLocal8Bit( fstabFile.readAll() ).split( '\n' );
|
2016-07-08 17:02:23 +02:00
|
|
|
|
2016-09-01 14:21:05 +02:00
|
|
|
for ( const QString& rawLine : fstabLines )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2018-11-02 17:13:29 +01:00
|
|
|
fstabEntries.append( FstabEntry::fromEtcFstab( rawLine ) );
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2016-07-08 17:02:23 +02:00
|
|
|
fstabFile.close();
|
2019-04-15 14:59:12 +02:00
|
|
|
cDebug() << Logger::SubEntry << "got" << fstabEntries.count() << "lines.";
|
2020-02-14 11:15:57 +01:00
|
|
|
std::remove_if(
|
|
|
|
fstabEntries.begin(), fstabEntries.end(), []( const FstabEntry& x ) { return !x.isValid(); } );
|
2019-04-15 14:59:12 +02:00
|
|
|
cDebug() << Logger::SubEntry << "got" << fstabEntries.count() << "fstab entries.";
|
2016-07-08 17:02:23 +02:00
|
|
|
}
|
2018-12-03 16:28:40 +01:00
|
|
|
else
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2018-12-03 16:28:40 +01:00
|
|
|
cWarning() << "Could not read fstab from mounted fs";
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2016-07-08 17:02:23 +02:00
|
|
|
}
|
2018-12-03 16:28:40 +01:00
|
|
|
else
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2018-12-03 16:28:40 +01:00
|
|
|
cWarning() << "Could not mount existing fs";
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2016-07-08 17:02:23 +02:00
|
|
|
|
|
|
|
return fstabEntries;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-28 11:36:21 +02:00
|
|
|
static QString
|
2020-02-14 11:15:57 +01:00
|
|
|
findPartitionPathForMountPoint( const FstabEntryList& fstab, const QString& mountPoint )
|
2016-07-13 17:30:29 +02:00
|
|
|
{
|
|
|
|
if ( fstab.isEmpty() )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2016-07-13 17:30:29 +02:00
|
|
|
return QString();
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2016-07-13 17:30:29 +02:00
|
|
|
|
2016-09-01 14:21:05 +02:00
|
|
|
for ( const FstabEntry& entry : fstab )
|
2016-07-13 17:30:29 +02:00
|
|
|
{
|
|
|
|
if ( entry.mountPoint == mountPoint )
|
|
|
|
{
|
|
|
|
QProcess readlink;
|
|
|
|
QString partPath;
|
|
|
|
|
2020-02-14 11:15:57 +01:00
|
|
|
if ( entry.partitionNode.startsWith( "/dev" ) ) // plain dev node
|
2016-07-13 17:30:29 +02:00
|
|
|
{
|
|
|
|
partPath = entry.partitionNode;
|
|
|
|
}
|
|
|
|
else if ( entry.partitionNode.startsWith( "LABEL=" ) )
|
|
|
|
{
|
|
|
|
partPath = entry.partitionNode.mid( 6 );
|
|
|
|
partPath.remove( "\"" );
|
|
|
|
partPath.replace( "\\040", "\\ " );
|
|
|
|
partPath.prepend( "/dev/disk/by-label/" );
|
|
|
|
}
|
|
|
|
else if ( entry.partitionNode.startsWith( "UUID=" ) )
|
|
|
|
{
|
|
|
|
partPath = entry.partitionNode.mid( 5 );
|
|
|
|
partPath.remove( "\"" );
|
|
|
|
partPath = partPath.toLower();
|
|
|
|
partPath.prepend( "/dev/disk/by-uuid/" );
|
|
|
|
}
|
|
|
|
else if ( entry.partitionNode.startsWith( "PARTLABEL=" ) )
|
|
|
|
{
|
|
|
|
partPath = entry.partitionNode.mid( 10 );
|
|
|
|
partPath.remove( "\"" );
|
|
|
|
partPath.replace( "\\040", "\\ " );
|
|
|
|
partPath.prepend( "/dev/disk/by-partlabel/" );
|
|
|
|
}
|
|
|
|
else if ( entry.partitionNode.startsWith( "PARTUUID=" ) )
|
|
|
|
{
|
|
|
|
partPath = entry.partitionNode.mid( 9 );
|
|
|
|
partPath.remove( "\"" );
|
|
|
|
partPath = partPath.toLower();
|
|
|
|
partPath.prepend( "/dev/disk/by-partuuid/" );
|
|
|
|
}
|
|
|
|
|
|
|
|
// At this point we either have /dev/sda1, or /dev/disk/by-something/...
|
|
|
|
|
2020-02-14 11:15:57 +01:00
|
|
|
if ( partPath.startsWith( "/dev/disk/by-" ) ) // we got a fancy node
|
2016-07-13 17:30:29 +02:00
|
|
|
{
|
2020-02-14 11:15:57 +01:00
|
|
|
readlink.start( "readlink", { "-en", partPath } );
|
2016-07-13 17:30:29 +02:00
|
|
|
if ( !readlink.waitForStarted( 1000 ) )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2016-07-13 17:30:29 +02:00
|
|
|
return QString();
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2016-07-13 17:30:29 +02:00
|
|
|
if ( !readlink.waitForFinished( 1000 ) )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2016-07-13 17:30:29 +02:00
|
|
|
return QString();
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2016-07-13 17:30:29 +02:00
|
|
|
if ( readlink.exitCode() != 0 || readlink.exitStatus() != QProcess::NormalExit )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2016-07-13 17:30:29 +02:00
|
|
|
return QString();
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
|
|
|
partPath = QString::fromLocal8Bit( readlink.readAllStandardOutput() ).trimmed();
|
2016-07-13 17:30:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return partPath;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-18 15:39:49 +02:00
|
|
|
OsproberEntryList
|
2020-10-05 11:39:04 +02:00
|
|
|
runOsprober( DeviceModel* dm )
|
2015-09-18 15:39:49 +02:00
|
|
|
{
|
|
|
|
QString osproberOutput;
|
|
|
|
QProcess osprober;
|
|
|
|
osprober.setProgram( "os-prober" );
|
|
|
|
osprober.setProcessChannelMode( QProcess::SeparateChannels );
|
|
|
|
osprober.start();
|
|
|
|
if ( !osprober.waitForStarted() )
|
|
|
|
{
|
2018-02-13 11:14:45 +01:00
|
|
|
cError() << "os-prober cannot start.";
|
2015-09-18 15:39:49 +02:00
|
|
|
}
|
|
|
|
else if ( !osprober.waitForFinished( 60000 ) )
|
|
|
|
{
|
2018-02-13 11:14:45 +01:00
|
|
|
cError() << "os-prober timed out.";
|
2015-09-18 15:39:49 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-02-14 11:15:57 +01:00
|
|
|
osproberOutput.append( QString::fromLocal8Bit( osprober.readAllStandardOutput() ).trimmed() );
|
2015-09-18 15:39:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QStringList osproberCleanLines;
|
|
|
|
OsproberEntryList osproberEntries;
|
2016-09-01 14:21:05 +02:00
|
|
|
const auto lines = osproberOutput.split( '\n' );
|
|
|
|
for ( const QString& line : lines )
|
2015-09-18 15:39:49 +02:00
|
|
|
{
|
|
|
|
if ( !line.simplified().isEmpty() )
|
|
|
|
{
|
|
|
|
QStringList lineColumns = line.split( ':' );
|
|
|
|
QString prettyName;
|
|
|
|
if ( !lineColumns.value( 1 ).simplified().isEmpty() )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2015-09-18 15:39:49 +02:00
|
|
|
prettyName = lineColumns.value( 1 ).simplified();
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2015-09-18 15:39:49 +02:00
|
|
|
else if ( !lineColumns.value( 2 ).simplified().isEmpty() )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2015-09-18 15:39:49 +02:00
|
|
|
prettyName = lineColumns.value( 2 ).simplified();
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2015-09-18 15:39:49 +02:00
|
|
|
|
2020-05-15 23:03:51 +02:00
|
|
|
QString file, path = lineColumns.value( 0 ).simplified();
|
2020-02-14 11:15:57 +01:00
|
|
|
if ( !path.startsWith( "/dev/" ) ) //basic sanity check
|
|
|
|
{
|
2015-09-18 15:39:49 +02:00
|
|
|
continue;
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2015-09-18 15:39:49 +02:00
|
|
|
|
2020-05-15 23:03:51 +02:00
|
|
|
// strip extra file after device: /dev/name@/path/to/file
|
|
|
|
int index = path.indexOf( '@' );
|
|
|
|
if ( index != -1 )
|
|
|
|
{
|
|
|
|
file = path.right( path.length() - index - 1 );
|
|
|
|
path = path.left( index );
|
|
|
|
}
|
|
|
|
|
2016-07-08 17:02:23 +02:00
|
|
|
FstabEntryList fstabEntries = lookForFstabEntries( path );
|
2016-07-13 17:30:29 +02:00
|
|
|
QString homePath = findPartitionPathForMountPoint( fstabEntries, "/home" );
|
2016-07-08 17:02:23 +02:00
|
|
|
|
2020-02-14 11:15:57 +01:00
|
|
|
osproberEntries.append(
|
2020-05-15 23:03:51 +02:00
|
|
|
{ prettyName, path, file, QString(), canBeResized( dm, path ), lineColumns, fstabEntries, homePath } );
|
2015-09-18 15:39:49 +02:00
|
|
|
osproberCleanLines.append( line );
|
|
|
|
}
|
|
|
|
}
|
2018-11-12 16:31:30 +01:00
|
|
|
|
|
|
|
if ( osproberCleanLines.count() > 0 )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2018-11-12 16:31:30 +01:00
|
|
|
cDebug() << "os-prober lines after cleanup:" << Logger::DebugList( osproberCleanLines );
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2018-11-12 16:31:30 +01:00
|
|
|
else
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2018-11-12 16:31:30 +01:00
|
|
|
cDebug() << "os-prober gave no output.";
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2015-09-18 15:39:49 +02:00
|
|
|
|
|
|
|
Calamares::JobQueue::instance()->globalStorage()->insert( "osproberLines", osproberCleanLines );
|
|
|
|
|
|
|
|
return osproberEntries;
|
|
|
|
}
|
|
|
|
|
2017-08-28 11:36:21 +02:00
|
|
|
bool
|
|
|
|
isEfiSystem()
|
|
|
|
{
|
|
|
|
return QDir( "/sys/firmware/efi/efivars" ).exists();
|
|
|
|
}
|
|
|
|
|
2018-01-09 16:53:33 +01:00
|
|
|
bool
|
|
|
|
isEfiBootable( const Partition* candidate )
|
|
|
|
{
|
2019-02-25 22:39:19 +01:00
|
|
|
cDebug() << "Check EFI bootable" << convenienceName( candidate ) << candidate->devicePath();
|
2019-04-15 14:59:12 +02:00
|
|
|
cDebug() << Logger::SubEntry << "flags" << candidate->activeFlags();
|
2018-02-19 16:25:00 +01:00
|
|
|
|
2018-05-16 13:28:30 +02:00
|
|
|
auto flags = PartitionInfo::flags( candidate );
|
|
|
|
|
2018-01-09 16:53:33 +01:00
|
|
|
/* If bit 17 is set, old-style Esp flag, it's OK */
|
2019-03-20 16:37:50 +01:00
|
|
|
if ( flags.testFlag( KPM_PARTITION_FLAG_ESP ) )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2018-01-09 16:53:33 +01:00
|
|
|
return true;
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2018-01-09 16:53:33 +01:00
|
|
|
|
|
|
|
/* Otherwise, if it's a GPT table, Boot (bit 0) is the same as Esp */
|
|
|
|
const PartitionNode* root = candidate;
|
|
|
|
while ( root && !root->isRoot() )
|
2018-02-19 16:25:00 +01:00
|
|
|
{
|
2018-01-09 16:53:33 +01:00
|
|
|
root = root->parent();
|
2020-08-22 01:19:58 +02:00
|
|
|
cDebug() << Logger::SubEntry << "moved towards root" << Logger::Pointer( root );
|
2018-02-19 16:25:00 +01:00
|
|
|
}
|
2018-01-09 16:53:33 +01:00
|
|
|
|
|
|
|
// Strange case: no root found, no partition table node?
|
|
|
|
if ( !root )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2018-01-09 16:53:33 +01:00
|
|
|
return false;
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2018-01-09 16:53:33 +01:00
|
|
|
|
2020-02-14 11:15:57 +01:00
|
|
|
const PartitionTable* table = dynamic_cast< const PartitionTable* >( root );
|
2020-08-22 01:19:58 +02:00
|
|
|
cDebug() << Logger::SubEntry << "partition table" << Logger::Pointer( table ) << "type"
|
2020-02-14 11:15:57 +01:00
|
|
|
<< ( table ? table->type() : PartitionTable::TableType::unknownTableType );
|
|
|
|
return table && ( table->type() == PartitionTable::TableType::gpt ) && flags.testFlag( KPM_PARTITION_FLAG( Boot ) );
|
2018-01-09 16:53:33 +01:00
|
|
|
}
|
|
|
|
|
2019-02-22 18:42:16 +01:00
|
|
|
QString
|
|
|
|
findFS( QString fsName, FileSystem::Type* fsType )
|
|
|
|
{
|
2019-09-08 22:20:13 +02:00
|
|
|
QStringList fsLanguage { QLatin1String( "C" ) }; // Required language list to turn off localization
|
2019-02-22 18:42:16 +01:00
|
|
|
if ( fsName.isEmpty() )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2019-02-22 18:42:16 +01:00
|
|
|
fsName = QStringLiteral( "ext4" );
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2019-02-22 18:42:16 +01:00
|
|
|
|
|
|
|
FileSystem::Type tmpType = FileSystem::typeForName( fsName, fsLanguage );
|
|
|
|
if ( tmpType != FileSystem::Unknown )
|
|
|
|
{
|
|
|
|
cDebug() << "Found filesystem" << fsName;
|
|
|
|
if ( fsType )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2019-02-22 18:42:16 +01:00
|
|
|
*fsType = tmpType;
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2019-02-22 18:42:16 +01:00
|
|
|
return fsName;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Second pass: try case-insensitive
|
|
|
|
const auto fstypes = FileSystem::types();
|
|
|
|
for ( FileSystem::Type t : fstypes )
|
|
|
|
{
|
|
|
|
if ( 0 == QString::compare( fsName, FileSystem::nameForType( t, fsLanguage ), Qt::CaseInsensitive ) )
|
|
|
|
{
|
|
|
|
QString fsRealName = FileSystem::nameForType( t, fsLanguage );
|
|
|
|
cDebug() << "Filesystem name" << fsName << "translated to" << fsRealName;
|
|
|
|
if ( fsType )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
2019-02-22 18:42:16 +01:00
|
|
|
*fsType = t;
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2019-02-22 18:42:16 +01:00
|
|
|
return fsRealName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cDebug() << "Filesystem" << fsName << "not found, using ext4";
|
|
|
|
fsName = QStringLiteral( "ext4" );
|
|
|
|
// fsType can be used to check whether fsName was a valid filesystem.
|
2020-02-14 11:15:57 +01:00
|
|
|
if ( fsType )
|
|
|
|
{
|
2019-02-22 18:42:16 +01:00
|
|
|
*fsType = FileSystem::Unknown;
|
2020-02-14 11:15:57 +01:00
|
|
|
}
|
2019-02-22 18:42:16 +01:00
|
|
|
#ifdef DEBUG_FILESYSTEMS
|
|
|
|
// This bit is for distro's debugging their settings, and shows
|
|
|
|
// all the strings that KPMCore is matching against for FS type.
|
|
|
|
{
|
|
|
|
Logger::CDebug d;
|
|
|
|
using TR = Logger::DebugRow< int, QString >;
|
|
|
|
const auto fstypes = FileSystem::types();
|
|
|
|
d << "Available types (" << fstypes.count() << ')';
|
|
|
|
for ( FileSystem::Type t : fstypes )
|
2020-02-14 11:15:57 +01:00
|
|
|
{
|
|
|
|
d << TR( static_cast< int >( t ), FileSystem::nameForType( t, fsLanguage ) );
|
|
|
|
}
|
2019-02-22 18:42:16 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return fsName;
|
|
|
|
}
|
|
|
|
|
2020-02-14 11:15:57 +01:00
|
|
|
} // namespace PartUtils
|
2018-11-02 16:57:49 +01:00
|
|
|
|
|
|
|
/* Implementation of methods for FstabEntry, from OsproberEntry.h */
|
|
|
|
|
|
|
|
bool
|
|
|
|
FstabEntry::isValid() const
|
|
|
|
{
|
|
|
|
return !partitionNode.isEmpty() && !mountPoint.isEmpty() && !fsType.isEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
FstabEntry
|
|
|
|
FstabEntry::fromEtcFstab( const QString& rawLine )
|
|
|
|
{
|
|
|
|
QString line = rawLine.simplified();
|
|
|
|
if ( line.startsWith( '#' ) )
|
2020-02-14 11:15:57 +01:00
|
|
|
return FstabEntry { QString(), QString(), QString(), QString(), 0, 0 };
|
2018-11-02 16:57:49 +01:00
|
|
|
|
|
|
|
QStringList splitLine = line.split( ' ' );
|
|
|
|
if ( splitLine.length() != 6 )
|
2020-02-14 11:15:57 +01:00
|
|
|
return FstabEntry { QString(), QString(), QString(), QString(), 0, 0 };
|
|
|
|
|
|
|
|
return FstabEntry {
|
|
|
|
splitLine.at( 0 ), // path, or UUID, or LABEL, etc.
|
|
|
|
splitLine.at( 1 ), // mount point
|
|
|
|
splitLine.at( 2 ), // fs type
|
|
|
|
splitLine.at( 3 ), // options
|
|
|
|
splitLine.at( 4 ).toInt(), //dump
|
|
|
|
splitLine.at( 5 ).toInt() //pass
|
|
|
|
};
|
|
|
|
}
|