|
|
|
@ -22,8 +22,8 @@
|
|
|
|
|
|
|
|
|
|
#include "core/PartitionInfo.h"
|
|
|
|
|
|
|
|
|
|
#include "partition/Sync.h"
|
|
|
|
|
#include "partition/PartitionIterator.h"
|
|
|
|
|
#include "partition/Sync.h"
|
|
|
|
|
#include "utils/Logger.h"
|
|
|
|
|
|
|
|
|
|
// KPMcore
|
|
|
|
@ -47,16 +47,14 @@ ClearMountsJob::ClearMountsJob( Device* device )
|
|
|
|
|
QString
|
|
|
|
|
ClearMountsJob::prettyName() const
|
|
|
|
|
{
|
|
|
|
|
return tr( "Clear mounts for partitioning operations on %1" )
|
|
|
|
|
.arg( m_device->deviceNode() );
|
|
|
|
|
return tr( "Clear mounts for partitioning operations on %1" ).arg( m_device->deviceNode() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QString
|
|
|
|
|
ClearMountsJob::prettyStatusMessage() const
|
|
|
|
|
{
|
|
|
|
|
return tr( "Clearing mounts for partitioning operations on %1." )
|
|
|
|
|
.arg( m_device->deviceNode() );
|
|
|
|
|
return tr( "Clearing mounts for partitioning operations on %1." ).arg( m_device->deviceNode() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -70,15 +68,16 @@ getPartitionsForDevice( const QString& deviceName )
|
|
|
|
|
{
|
|
|
|
|
cDebug() << "Reading from" << dev_partitions.fileName();
|
|
|
|
|
QTextStream in( &dev_partitions );
|
|
|
|
|
(void) in.readLine(); // That's the header line, skip it
|
|
|
|
|
(void)in.readLine(); // That's the header line, skip it
|
|
|
|
|
while ( !in.atEnd() )
|
|
|
|
|
{
|
|
|
|
|
// The fourth column (index from 0, so index 3) is the name of the device;
|
|
|
|
|
// keep it if it is followed by something.
|
|
|
|
|
QStringList columns = in.readLine().split( ' ', QString::SkipEmptyParts );
|
|
|
|
|
if ( ( columns.count() >= 4 ) && ( columns[3].startsWith( deviceName ) ) && ( columns[3] != deviceName ) )
|
|
|
|
|
if ( ( columns.count() >= 4 ) && ( columns[ 3 ].startsWith( deviceName ) )
|
|
|
|
|
&& ( columns[ 3 ] != deviceName ) )
|
|
|
|
|
{
|
|
|
|
|
partitions.append( columns[3] );
|
|
|
|
|
partitions.append( columns[ 3 ] );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -118,50 +117,54 @@ ClearMountsJob::exec()
|
|
|
|
|
// /dev/sda1 : start= 63, size= 29329345, type=83, bootable
|
|
|
|
|
// /dev/sda2 : start= 29331456, size= 2125824, type=82
|
|
|
|
|
|
|
|
|
|
swapPartitions = QString::fromLocal8Bit( process.readAllStandardOutput() )
|
|
|
|
|
.split( '\n' );
|
|
|
|
|
swapPartitions = QString::fromLocal8Bit( process.readAllStandardOutput() ).split( '\n' );
|
|
|
|
|
swapPartitions = swapPartitions.filter( "type=82" );
|
|
|
|
|
for ( QStringList::iterator it = swapPartitions.begin();
|
|
|
|
|
it != swapPartitions.end(); ++it )
|
|
|
|
|
for ( QStringList::iterator it = swapPartitions.begin(); it != swapPartitions.end(); ++it )
|
|
|
|
|
{
|
|
|
|
|
*it = (*it).simplified().split( ' ' ).first();
|
|
|
|
|
*it = ( *it ).simplified().split( ' ' ).first();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QStringList cryptoDevices = getCryptoDevices();
|
|
|
|
|
for ( const QString &mapperPath : cryptoDevices )
|
|
|
|
|
for ( const QString& mapperPath : cryptoDevices )
|
|
|
|
|
{
|
|
|
|
|
tryUmount( mapperPath );
|
|
|
|
|
QString news = tryCryptoClose( mapperPath );
|
|
|
|
|
if ( !news.isEmpty() )
|
|
|
|
|
{
|
|
|
|
|
goodNews.append( news );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// First we umount all LVM logical volumes we can find
|
|
|
|
|
process.start( "lvscan", { "-a" } );
|
|
|
|
|
process.waitForFinished();
|
|
|
|
|
if ( process.exitCode() == 0 ) //means LVM2 tools are installed
|
|
|
|
|
if ( process.exitCode() == 0 ) //means LVM2 tools are installed
|
|
|
|
|
{
|
|
|
|
|
const QStringList lvscanLines = QString::fromLocal8Bit( process.readAllStandardOutput() ).split( '\n' );
|
|
|
|
|
for ( const QString& lvscanLine : lvscanLines )
|
|
|
|
|
{
|
|
|
|
|
QString lvPath = lvscanLine.simplified().split( ' ' ).value( 1 ); //second column
|
|
|
|
|
QString lvPath = lvscanLine.simplified().split( ' ' ).value( 1 ); //second column
|
|
|
|
|
lvPath = lvPath.replace( '\'', "" );
|
|
|
|
|
|
|
|
|
|
QString news = tryUmount( lvPath );
|
|
|
|
|
if ( !news.isEmpty() )
|
|
|
|
|
{
|
|
|
|
|
goodNews.append( news );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
cWarning() << "this system does not seem to have LVM2 tools.";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Then we go looking for volume groups that use this device for physical volumes
|
|
|
|
|
process.start( "pvdisplay", { "-C", "--noheadings" } );
|
|
|
|
|
process.waitForFinished();
|
|
|
|
|
if ( process.exitCode() == 0 ) //means LVM2 tools are installed
|
|
|
|
|
if ( process.exitCode() == 0 ) //means LVM2 tools are installed
|
|
|
|
|
{
|
|
|
|
|
QString pvdisplayOutput = process.readAllStandardOutput();
|
|
|
|
|
if ( !pvdisplayOutput.simplified().isEmpty() ) //means there is at least one LVM PV
|
|
|
|
|
if ( !pvdisplayOutput.simplified().isEmpty() ) //means there is at least one LVM PV
|
|
|
|
|
{
|
|
|
|
|
QSet< QString > vgSet;
|
|
|
|
|
|
|
|
|
@ -171,7 +174,9 @@ ClearMountsJob::exec()
|
|
|
|
|
QString pvPath = pvdisplayLine.simplified().split( ' ' ).value( 0 );
|
|
|
|
|
QString vgName = pvdisplayLine.simplified().split( ' ' ).value( 1 );
|
|
|
|
|
if ( !pvPath.contains( deviceName ) )
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vgSet.insert( vgName );
|
|
|
|
|
}
|
|
|
|
@ -181,41 +186,50 @@ ClearMountsJob::exec()
|
|
|
|
|
process.start( "vgchange", { "-an", vgName } );
|
|
|
|
|
process.waitForFinished();
|
|
|
|
|
if ( process.exitCode() == 0 )
|
|
|
|
|
{
|
|
|
|
|
goodNews.append( QString( "Successfully disabled volume group %1." ).arg( vgName ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
cWarning() << "this system does not seem to have LVM2 tools.";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QStringList cryptoDevices2 = getCryptoDevices();
|
|
|
|
|
for ( const QString &mapperPath : cryptoDevices2 )
|
|
|
|
|
for ( const QString& mapperPath : cryptoDevices2 )
|
|
|
|
|
{
|
|
|
|
|
tryUmount( mapperPath );
|
|
|
|
|
QString news = tryCryptoClose( mapperPath );
|
|
|
|
|
if ( !news.isEmpty() )
|
|
|
|
|
{
|
|
|
|
|
goodNews.append( news );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for ( const QString &p : partitionsList )
|
|
|
|
|
for ( const QString& p : partitionsList )
|
|
|
|
|
{
|
|
|
|
|
QString partPath = QString( "/dev/%1" ).arg( p );
|
|
|
|
|
|
|
|
|
|
QString news = tryUmount( partPath );
|
|
|
|
|
if ( !news.isEmpty() )
|
|
|
|
|
{
|
|
|
|
|
goodNews.append( news );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ( QString p, swapPartitions )
|
|
|
|
|
{
|
|
|
|
|
QString news = tryClearSwap( p );
|
|
|
|
|
if ( !news.isEmpty() )
|
|
|
|
|
{
|
|
|
|
|
goodNews.append( news );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Calamares::JobResult ok = Calamares::JobResult::ok();
|
|
|
|
|
ok.setMessage( tr( "Cleared all mounts for %1" )
|
|
|
|
|
.arg( m_device->deviceNode() ) );
|
|
|
|
|
ok.setMessage( tr( "Cleared all mounts for %1" ).arg( m_device->deviceNode() ) );
|
|
|
|
|
ok.setDetails( goodNews.join( "\n" ) );
|
|
|
|
|
|
|
|
|
|
cDebug() << "ClearMountsJob finished. Here's what was done:\n" << goodNews.join( "\n" );
|
|
|
|
@ -231,12 +245,16 @@ ClearMountsJob::tryUmount( const QString& partPath )
|
|
|
|
|
process.start( "umount", { partPath } );
|
|
|
|
|
process.waitForFinished();
|
|
|
|
|
if ( process.exitCode() == 0 )
|
|
|
|
|
{
|
|
|
|
|
return QString( "Successfully unmounted %1." ).arg( partPath );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
process.start( "swapoff", { partPath } );
|
|
|
|
|
process.waitForFinished();
|
|
|
|
|
if ( process.exitCode() == 0 )
|
|
|
|
|
{
|
|
|
|
|
return QString( "Successfully disabled swap %1." ).arg( partPath );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
@ -249,14 +267,17 @@ ClearMountsJob::tryClearSwap( const QString& partPath )
|
|
|
|
|
process.start( "blkid", { "-s", "UUID", "-o", "value", partPath } );
|
|
|
|
|
process.waitForFinished();
|
|
|
|
|
QString swapPartUuid = QString::fromLocal8Bit( process.readAllStandardOutput() ).simplified();
|
|
|
|
|
if ( process.exitCode() != 0 ||
|
|
|
|
|
swapPartUuid.isEmpty() )
|
|
|
|
|
if ( process.exitCode() != 0 || swapPartUuid.isEmpty() )
|
|
|
|
|
{
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
process.start( "mkswap", { "-U", swapPartUuid, partPath } );
|
|
|
|
|
process.waitForFinished();
|
|
|
|
|
if ( process.exitCode() != 0 )
|
|
|
|
|
{
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return QString( "Successfully cleared swap %1." ).arg( partPath );
|
|
|
|
|
}
|
|
|
|
@ -269,7 +290,9 @@ ClearMountsJob::tryCryptoClose( const QString& mapperPath )
|
|
|
|
|
process.start( "cryptsetup", { "close", mapperPath } );
|
|
|
|
|
process.waitForFinished();
|
|
|
|
|
if ( process.exitCode() == 0 )
|
|
|
|
|
{
|
|
|
|
|
return QString( "Successfully closed mapper device %1." ).arg( mapperPath );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
@ -282,14 +305,16 @@ ClearMountsJob::getCryptoDevices() const
|
|
|
|
|
const QFileInfoList fiList = mapperDir.entryInfoList( QDir::Files );
|
|
|
|
|
QStringList list;
|
|
|
|
|
QProcess process;
|
|
|
|
|
for ( const QFileInfo &fi : fiList )
|
|
|
|
|
for ( const QFileInfo& fi : fiList )
|
|
|
|
|
{
|
|
|
|
|
QString baseName = fi.baseName();
|
|
|
|
|
// Fedora live images use /dev/mapper/live-* internally. We must not
|
|
|
|
|
// unmount those devices, because they are used by the live image and
|
|
|
|
|
// because we need /dev/mapper/live-base in the unpackfs module.
|
|
|
|
|
if ( baseName == "control" || baseName.startsWith( "live-" ) )
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
list.append( fi.absoluteFilePath() );
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|