From c987235bb8f9a8f4de1172d3182784bccaada053 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Sat, 20 Jun 2015 20:38:40 +0200 Subject: [PATCH] Scan for type 82 partitions and clear them regardless of swapon status. --- src/modules/partition/jobs/ClearMountsJob.cpp | 53 ++++++++++++++++--- src/modules/partition/jobs/ClearMountsJob.h | 1 + 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/src/modules/partition/jobs/ClearMountsJob.cpp b/src/modules/partition/jobs/ClearMountsJob.cpp index c3e187dd3..e793abbf6 100644 --- a/src/modules/partition/jobs/ClearMountsJob.cpp +++ b/src/modules/partition/jobs/ClearMountsJob.cpp @@ -72,6 +72,31 @@ ClearMountsJob::exec() QString partitions = process.readAllStandardOutput(); QStringList partitionsList = partitions.simplified().split( ' ' ); + // Build a list of partitions of type 82 (Linux swap / Solaris). + // We then need to clear them just in case they contain something resumable from a + // previous suspend-to-disk. + QStringList swapPartitions; + process.start( "sfdisk", { "-d", m_device->deviceNode() } ); + process.waitForFinished(); + // Sample output: + // % sudo sfdisk -d /dev/sda + // label: dos + // label-id: 0x000ced89 + // device: /dev/sda + // unit: sectors + + // /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 = swapPartitions.filter( "type=82" ); + for ( QStringList::iterator it = swapPartitions.begin(); + it != swapPartitions.end(); ++it ) + { + *it = (*it).simplified().split( ' ' ).first(); + } + // First we umount all LVM logical volumes we can find process.start( "lvscan", { "-a" } ); process.waitForFinished(); @@ -133,6 +158,13 @@ ClearMountsJob::exec() 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() ) ); @@ -156,13 +188,20 @@ ClearMountsJob::tryUmount( const QString& partPath ) process.start( "swapoff", { partPath } ); process.waitForFinished(); if ( process.exitCode() == 0 ) - { - process.start( "mkswap", { partPath } ); - process.waitForFinished(); - if ( process.exitCode() == 0 ) - return QString( "Successfully disabled and cleared swap %1." ).arg( partPath ); - return QString( "Successfully disabled but not cleared swap %1." ).arg( partPath ); - } + return QString( "Successfully disabled swap %1." ).arg( partPath ); + + return QString(); +} + + +QString +ClearMountsJob::tryClearSwap( const QString& partPath ) +{ + QProcess process; + process.start( "mkswap", { partPath } ); + process.waitForFinished(); + if ( process.exitCode() == 0 ) + return QString( "Successfully cleared swap %1." ).arg( partPath ); return QString(); } diff --git a/src/modules/partition/jobs/ClearMountsJob.h b/src/modules/partition/jobs/ClearMountsJob.h index 8503d8d97..464793f27 100644 --- a/src/modules/partition/jobs/ClearMountsJob.h +++ b/src/modules/partition/jobs/ClearMountsJob.h @@ -37,6 +37,7 @@ public: Calamares::JobResult exec() override; private: QString tryUmount( const QString& partPath ); + QString tryClearSwap( const QString& partPath ); Device* m_device; };