2017-12-20 14:39:09 +01:00
|
|
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
2015-09-18 15:39:49 +02:00
|
|
|
*
|
2016-02-12 17:19:30 +01:00
|
|
|
* Copyright 2015-2016, Teo Mrnjavac <teo@kde.org>
|
2018-05-19 15:08:11 +02:00
|
|
|
* Copyright 2018, Adriaan de Groot <groot@kde.org>
|
2019-02-28 13:18:02 +01:00
|
|
|
* Copyright 2019, Collabora Ltd <arnaud.ferraris@collabora.com>
|
2015-09-18 15:39:49 +02:00
|
|
|
*
|
|
|
|
* Calamares is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Calamares is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "PartUtils.h"
|
|
|
|
|
|
|
|
#include "PartitionCoreModule.h"
|
|
|
|
|
|
|
|
#include "core/DeviceModel.h"
|
|
|
|
#include "core/KPMHelpers.h"
|
2018-05-16 13:28:30 +02:00
|
|
|
#include "core/PartitionInfo.h"
|
2017-07-11 12:07:15 +02:00
|
|
|
#include "core/PartitionIterator.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>
|
|
|
|
|
2018-11-12 17:07:18 +01:00
|
|
|
#include <utils/CalamaresUtilsSystem.h>
|
2015-09-18 15:39:49 +02:00
|
|
|
#include <utils/Logger.h>
|
|
|
|
#include <JobQueue.h>
|
|
|
|
#include <GlobalStorage.h>
|
|
|
|
|
|
|
|
#include <QProcess>
|
2016-07-08 17:02:23 +02:00
|
|
|
#include <QTemporaryDir>
|
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() )
|
|
|
|
return candidate->mountPoint();
|
|
|
|
if ( !candidate->partitionPath().isEmpty() )
|
|
|
|
return candidate->partitionPath();
|
|
|
|
if ( !candidate->devicePath().isEmpty() )
|
|
|
|
return candidate->devicePath();
|
|
|
|
if ( !candidate->deviceNode().isEmpty() )
|
|
|
|
return candidate->devicePath();
|
|
|
|
|
|
|
|
QString p;
|
|
|
|
QTextStream s( &p );
|
|
|
|
s << (void *)candidate;
|
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2016-02-12 15:02:17 +01:00
|
|
|
bool
|
|
|
|
canBeReplaced( Partition* candidate )
|
|
|
|
{
|
2016-07-28 12:48:40 +02:00
|
|
|
if ( !candidate )
|
|
|
|
return false;
|
|
|
|
|
2017-09-07 10:55:26 +02:00
|
|
|
if ( candidate->isMounted() )
|
|
|
|
return false;
|
|
|
|
|
2016-02-12 15:02:17 +01:00
|
|
|
bool ok = false;
|
|
|
|
double requiredStorageGB = Calamares::JobQueue::instance()
|
|
|
|
->globalStorage()
|
|
|
|
->value( "requiredStorageGB" )
|
|
|
|
.toDouble( &ok );
|
|
|
|
|
|
|
|
qint64 availableStorageB = candidate->capacity();
|
|
|
|
qint64 requiredStorageB = ( requiredStorageGB + 0.5 ) * 1024 * 1024 * 1024;
|
|
|
|
cDebug() << "Required storage B:" << requiredStorageB
|
|
|
|
<< QString( "(%1GB)" ).arg( requiredStorageB / 1024 / 1024 / 1024 );
|
2016-12-23 14:03:31 +01:00
|
|
|
cDebug() << "Storage capacity B:" << availableStorageB
|
|
|
|
<< QString( "(%1GB)" ).arg( availableStorageB / 1024 / 1024 / 1024 )
|
2019-02-25 22:39:19 +01:00
|
|
|
<< "for" << convenienceName( candidate ) << " length:" << candidate->length();
|
2016-02-12 15:02:17 +01:00
|
|
|
|
|
|
|
if ( ok &&
|
|
|
|
availableStorageB > requiredStorageB )
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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.";
|
2016-02-11 16:52:21 +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()
|
2018-12-03 16:42:40 +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
|
|
|
|
2016-03-10 12:54:16 +01:00
|
|
|
if ( KPMHelpers::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
|
|
|
{
|
2019-04-15 14:15:17 +02:00
|
|
|
cDebug() << Logger::SubEntry << "NO, partition table already has"
|
2018-12-03 16:42:40 +01:00
|
|
|
<< 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;
|
|
|
|
double requiredStorageGB = Calamares::JobQueue::instance()
|
|
|
|
->globalStorage()
|
|
|
|
->value( "requiredStorageGB" )
|
|
|
|
.toDouble( &ok );
|
2019-04-04 17:58:03 +02:00
|
|
|
// We require a little more for partitioning overhead and swap file
|
2017-04-20 01:37:52 +02:00
|
|
|
double advisedStorageGB = requiredStorageGB + 0.5 + 2.0;
|
2016-02-11 16:52:21 +01:00
|
|
|
qint64 availableStorageB = candidate->available();
|
|
|
|
|
2019-04-04 17:58:03 +02:00
|
|
|
qint64 advisedStorageB = CalamaresUtils::GiBtoBytes( advisedStorageGB );
|
2016-02-11 16:52:21 +01:00
|
|
|
|
|
|
|
if ( ok &&
|
2017-04-20 01:37:52 +02:00
|
|
|
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-04-04 17:58:03 +02:00
|
|
|
else if ( ok )
|
|
|
|
{
|
|
|
|
auto deb = cDebug();
|
2019-04-15 14:15:17 +02:00
|
|
|
deb << Logger::SubEntry << "NO, insufficient storage";
|
|
|
|
deb << Logger::Continuation << "Required storage B:" << advisedStorageB
|
2019-04-04 17:58:03 +02:00
|
|
|
<< QString( "(%1GB)" ).arg( advisedStorageGB );
|
2019-04-15 14:15:17 +02:00
|
|
|
deb << Logger::Continuation << "Available storage B:" << availableStorageB
|
2019-04-04 17:58:03 +02:00
|
|
|
<< QString( "(%1GB)" ).arg( availableStorageB / 1024 / 1024 / 1024 )
|
|
|
|
<< "for" << convenienceName( candidate ) << " length:" << candidate->length()
|
|
|
|
<< " sectorsUsed:" << candidate->sectorsUsed() << " fsType:" << candidate->fileSystem().name();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-04-15 14:15:17 +02:00
|
|
|
cDebug() << Logger::SubEntry << "NO, requiredStorageGB is not set correctly.";
|
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
|
|
|
|
canBeResized( PartitionCoreModule* core, const QString& partitionPath )
|
|
|
|
{
|
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/" ) )
|
|
|
|
{
|
|
|
|
DeviceModel* dm = core->deviceModel();
|
|
|
|
for ( int i = 0; i < dm->rowCount(); ++i )
|
|
|
|
{
|
|
|
|
Device* dev = dm->deviceForIndex( dm->index( i ) );
|
|
|
|
Partition* candidate = KPMHelpers::findPartitionByPath( { dev }, partitionWithOs );
|
|
|
|
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 )
|
|
|
|
{
|
2018-11-12 17:07:18 +01:00
|
|
|
QStringList mountOptions{ "ro" };
|
|
|
|
|
|
|
|
auto r = CalamaresUtils::System::runCommand(
|
|
|
|
CalamaresUtils::System::RunLocation::RunInHost,
|
|
|
|
{ "blkid", "-s", "TYPE", "-o", "value", partitionPath }
|
|
|
|
);
|
|
|
|
if ( r.getExitCode() )
|
|
|
|
cWarning() << "blkid on" << partitionPath << "failed.";
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QString fstype = r.getOutput().trimmed();
|
|
|
|
if ( ( fstype == "ext3" ) || ( fstype == "ext4" ) )
|
|
|
|
mountOptions.append( "noload" );
|
|
|
|
}
|
|
|
|
|
2019-02-28 13:18:02 +01:00
|
|
|
cDebug() << "Checking device" << partitionPath
|
2018-12-03 16:28:40 +01:00
|
|
|
<< "for fstab (fs=" << r.getOutput() << ')';
|
|
|
|
|
2016-07-08 17:02:23 +02:00
|
|
|
FstabEntryList fstabEntries;
|
|
|
|
QTemporaryDir mountsDir;
|
2018-11-02 16:58:49 +01:00
|
|
|
mountsDir.setAutoRemove( false );
|
2016-07-08 17:02:23 +02:00
|
|
|
|
2018-11-12 17:07:18 +01:00
|
|
|
int exit = QProcess::execute( "mount", { "-o", mountOptions.join(','), partitionPath, mountsDir.path() } );
|
2016-07-08 17:02:23 +02:00
|
|
|
if ( !exit ) // if all is well
|
|
|
|
{
|
|
|
|
QFile fstabFile( mountsDir.path() + "/etc/fstab" );
|
2019-02-28 13:18:02 +01:00
|
|
|
|
2018-12-03 16:28:40 +01:00
|
|
|
cDebug() << " .. 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 ) )
|
|
|
|
{
|
2016-09-01 14:21:05 +02:00
|
|
|
const QStringList fstabLines = QString::fromLocal8Bit( fstabFile.readAll() )
|
2016-07-08 17:02:23 +02:00
|
|
|
.split( '\n' );
|
|
|
|
|
2016-09-01 14:21:05 +02:00
|
|
|
for ( const QString& rawLine : fstabLines )
|
2018-11-02 17:13:29 +01:00
|
|
|
fstabEntries.append( FstabEntry::fromEtcFstab( rawLine ) );
|
2016-07-08 17:02:23 +02:00
|
|
|
fstabFile.close();
|
2018-12-03 16:28:40 +01:00
|
|
|
cDebug() << " .. got" << fstabEntries.count() << "lines.";
|
2018-11-02 17:13:29 +01:00
|
|
|
std::remove_if( fstabEntries.begin(), fstabEntries.end(), [](const FstabEntry& x) { return !x.isValid(); } );
|
2018-12-03 16:28:40 +01:00
|
|
|
cDebug() << " .. got" << fstabEntries.count() << "fstab entries.";
|
2016-07-08 17:02:23 +02:00
|
|
|
}
|
2018-12-03 16:28:40 +01:00
|
|
|
else
|
|
|
|
cWarning() << "Could not read fstab from mounted fs";
|
2016-07-08 17:02:23 +02:00
|
|
|
|
2018-11-02 17:04:09 +01:00
|
|
|
if ( QProcess::execute( "umount", { "-R", mountsDir.path() } ) )
|
|
|
|
cWarning() << "Could not unmount" << mountsDir.path();
|
2016-07-08 17:02:23 +02:00
|
|
|
}
|
2018-12-03 16:28:40 +01:00
|
|
|
else
|
|
|
|
cWarning() << "Could not mount existing fs";
|
2016-07-08 17:02:23 +02:00
|
|
|
|
|
|
|
return fstabEntries;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-28 11:36:21 +02:00
|
|
|
static QString
|
2016-07-13 17:30:29 +02:00
|
|
|
findPartitionPathForMountPoint( const FstabEntryList& fstab,
|
|
|
|
const QString& mountPoint )
|
|
|
|
{
|
|
|
|
if ( fstab.isEmpty() )
|
|
|
|
return QString();
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
if ( entry.partitionNode.startsWith( "/dev" ) ) // plain dev node
|
|
|
|
{
|
|
|
|
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/...
|
|
|
|
|
|
|
|
if ( partPath.startsWith( "/dev/disk/by-" ) ) // we got a fancy node
|
|
|
|
{
|
|
|
|
readlink.start( "readlink", { "-en", partPath });
|
|
|
|
if ( !readlink.waitForStarted( 1000 ) )
|
|
|
|
return QString();
|
|
|
|
if ( !readlink.waitForFinished( 1000 ) )
|
|
|
|
return QString();
|
|
|
|
if ( readlink.exitCode() != 0 || readlink.exitStatus() != QProcess::NormalExit )
|
|
|
|
return QString();
|
|
|
|
partPath = QString::fromLocal8Bit(
|
|
|
|
readlink.readAllStandardOutput() ).trimmed();
|
|
|
|
}
|
|
|
|
|
|
|
|
return partPath;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-18 15:39:49 +02:00
|
|
|
OsproberEntryList
|
|
|
|
runOsprober( PartitionCoreModule* core )
|
|
|
|
{
|
|
|
|
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
|
|
|
|
{
|
|
|
|
osproberOutput.append(
|
|
|
|
QString::fromLocal8Bit(
|
|
|
|
osprober.readAllStandardOutput() ).trimmed() );
|
|
|
|
}
|
|
|
|
|
|
|
|
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() )
|
|
|
|
prettyName = lineColumns.value( 1 ).simplified();
|
|
|
|
else if ( !lineColumns.value( 2 ).simplified().isEmpty() )
|
|
|
|
prettyName = lineColumns.value( 2 ).simplified();
|
|
|
|
|
|
|
|
QString path = lineColumns.value( 0 ).simplified();
|
|
|
|
if ( !path.startsWith( "/dev/" ) ) //basic sanity check
|
|
|
|
continue;
|
|
|
|
|
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
|
|
|
|
2015-09-18 15:39:49 +02:00
|
|
|
osproberEntries.append( { prettyName,
|
|
|
|
path,
|
2016-07-28 17:41:44 +02:00
|
|
|
QString(),
|
2015-09-18 15:39:49 +02:00
|
|
|
canBeResized( core, path ),
|
2016-07-08 17:02:23 +02:00
|
|
|
lineColumns,
|
2016-07-13 17:30:29 +02:00
|
|
|
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 )
|
|
|
|
cDebug() << "os-prober lines after cleanup:" << Logger::DebugList( osproberCleanLines );
|
|
|
|
else
|
|
|
|
cDebug() << "os-prober gave no output.";
|
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();
|
2018-02-19 16:25:00 +01:00
|
|
|
cDebug() << " .. flags" << candidate->activeFlags();
|
|
|
|
|
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 ) )
|
2018-01-09 16:53:33 +01:00
|
|
|
return true;
|
|
|
|
|
|
|
|
/* 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();
|
2018-02-19 16:25:00 +01:00
|
|
|
cDebug() << " .. moved towards root" << (void *)root;
|
|
|
|
}
|
2018-01-09 16:53:33 +01:00
|
|
|
|
|
|
|
// Strange case: no root found, no partition table node?
|
|
|
|
if ( !root )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const PartitionTable* table = dynamic_cast<const PartitionTable*>( root );
|
2018-02-19 16:25:00 +01:00
|
|
|
cDebug() << " .. partition table" << (void *)table << "type" << ( table ? table->type() : PartitionTable::TableType::unknownTableType );
|
2018-01-09 16:53:33 +01:00
|
|
|
return table && ( table->type() == PartitionTable::TableType::gpt ) &&
|
2019-03-20 16:32:13 +01:00
|
|
|
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 )
|
|
|
|
{
|
|
|
|
QStringList fsLanguage { QLatin1Literal( "C" ) }; // Required language list to turn off localization
|
|
|
|
if ( fsName.isEmpty() )
|
|
|
|
fsName = QStringLiteral( "ext4" );
|
|
|
|
|
|
|
|
FileSystem::Type tmpType = FileSystem::typeForName( fsName, fsLanguage );
|
|
|
|
if ( tmpType != FileSystem::Unknown )
|
|
|
|
{
|
|
|
|
cDebug() << "Found filesystem" << fsName;
|
|
|
|
if ( fsType )
|
|
|
|
*fsType = tmpType;
|
|
|
|
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 )
|
|
|
|
*fsType = t;
|
|
|
|
return fsRealName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cDebug() << "Filesystem" << fsName << "not found, using ext4";
|
|
|
|
fsName = QStringLiteral( "ext4" );
|
|
|
|
// fsType can be used to check whether fsName was a valid filesystem.
|
|
|
|
if (fsType)
|
|
|
|
*fsType = FileSystem::Unknown;
|
|
|
|
#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 )
|
|
|
|
d << TR( static_cast<int>( t ), FileSystem::nameForType( t, fsLanguage ) );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return fsName;
|
|
|
|
}
|
|
|
|
|
2019-02-28 13:36:29 +01:00
|
|
|
static qint64
|
|
|
|
sizeToBytes( double size, SizeUnit unit, qint64 totalSize )
|
|
|
|
{
|
|
|
|
qint64 bytes;
|
|
|
|
|
|
|
|
switch ( unit )
|
|
|
|
{
|
|
|
|
case SizeUnit::Percent:
|
|
|
|
bytes = qint64( static_cast<double>( totalSize ) * size / 100.0L );
|
|
|
|
break;
|
|
|
|
case SizeUnit::KiB:
|
|
|
|
bytes = CalamaresUtils::KiBtoBytes(size);
|
|
|
|
break;
|
|
|
|
case SizeUnit::MiB:
|
|
|
|
bytes = CalamaresUtils::MiBtoBytes(size);
|
|
|
|
break;
|
|
|
|
case SizeUnit::GiB:
|
|
|
|
bytes = CalamaresUtils::GiBtoBytes(size);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
bytes = size;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bytes;
|
|
|
|
}
|
|
|
|
|
2019-02-28 13:18:02 +01:00
|
|
|
double
|
|
|
|
parseSizeString( const QString& sizeString, SizeUnit* unit )
|
|
|
|
{
|
|
|
|
double value;
|
|
|
|
bool ok;
|
|
|
|
QString valueString;
|
|
|
|
QString unitString;
|
|
|
|
|
|
|
|
QRegExp rx( "[KkMmGg%]" );
|
|
|
|
int pos = rx.indexIn( sizeString );
|
|
|
|
if (pos > 0)
|
|
|
|
{
|
|
|
|
valueString = sizeString.mid( 0, pos );
|
|
|
|
unitString = sizeString.mid( pos );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
valueString = sizeString;
|
|
|
|
|
|
|
|
value = valueString.toDouble( &ok );
|
|
|
|
if ( !ok )
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* In case the conversion fails, a size of 100% allows a few cases to pass
|
|
|
|
* anyway (e.g. when it is the last partition of the layout)
|
|
|
|
*/
|
|
|
|
*unit = SizeUnit::Percent;
|
|
|
|
return 100.0L;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( unitString.length() > 0 )
|
|
|
|
{
|
|
|
|
if ( unitString.at(0) == '%' )
|
|
|
|
*unit = SizeUnit::Percent;
|
|
|
|
else if ( unitString.at(0).toUpper() == 'K' )
|
|
|
|
*unit = SizeUnit::KiB;
|
|
|
|
else if ( unitString.at(0).toUpper() == 'M' )
|
|
|
|
*unit = SizeUnit::MiB;
|
|
|
|
else if ( unitString.at(0).toUpper() == 'G' )
|
|
|
|
*unit = SizeUnit::GiB;
|
|
|
|
else
|
|
|
|
*unit = SizeUnit::Byte;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*unit = SizeUnit::Byte;
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2019-02-28 13:46:25 +01:00
|
|
|
qint64
|
|
|
|
parseSizeString( const QString& sizeString, qint64 totalSize )
|
|
|
|
{
|
|
|
|
SizeUnit unit;
|
|
|
|
double value = parseSizeString( sizeString, &unit );
|
|
|
|
|
|
|
|
return sizeToBytes( value, unit, totalSize );
|
|
|
|
}
|
|
|
|
|
2019-02-28 13:36:29 +01:00
|
|
|
qint64
|
|
|
|
sizeToSectors( double size, SizeUnit unit, qint64 totalSectors, qint64 logicalSize )
|
|
|
|
{
|
|
|
|
qint64 bytes = sizeToBytes( size, unit, totalSectors * logicalSize );
|
|
|
|
return bytesToSectors( static_cast<unsigned long long>( bytes ), logicalSize );
|
|
|
|
}
|
|
|
|
|
2017-07-11 12:07:15 +02:00
|
|
|
} // nmamespace 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( '#' ) )
|
|
|
|
return FstabEntry{ QString(), QString(), QString(), QString(), 0, 0 };
|
|
|
|
|
|
|
|
QStringList splitLine = line.split( ' ' );
|
|
|
|
if ( splitLine.length() != 6 )
|
|
|
|
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
|
|
|
|
};
|
|
|
|
}
|