[partition] fix PartitionActions
This commit is contained in:
parent
961b603f78
commit
a33cd43d09
@ -28,7 +28,6 @@
|
|||||||
#include "utils/Units.h"
|
#include "utils/Units.h"
|
||||||
#include "JobQueue.h"
|
#include "JobQueue.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
#include "GlobalStorage.h"
|
|
||||||
|
|
||||||
#include <kpmcore/core/device.h>
|
#include <kpmcore/core/device.h>
|
||||||
#include <kpmcore/core/partition.h>
|
#include <kpmcore/core/partition.h>
|
||||||
@ -43,58 +42,38 @@ using CalamaresUtils::operator""_GiB;
|
|||||||
using CalamaresUtils::operator""_MiB;
|
using CalamaresUtils::operator""_MiB;
|
||||||
|
|
||||||
qint64
|
qint64
|
||||||
swapSuggestion( const qint64 availableSpaceB )
|
swapSuggestion( const qint64 availableSpaceB, Choices::SwapChoice swap )
|
||||||
{
|
{
|
||||||
/* If suspend-to-disk is demanded, then we always need enough
|
if ( ( swap != Choices::SmallSwap ) && ( swap != Choices::FullSwap ) )
|
||||||
* swap to write the whole memory to disk -- between 2GB and 8GB
|
return 0;
|
||||||
* RAM give proportionally more swap, and from 8GB RAM keep
|
|
||||||
* swap = RAM.
|
// See partition.conf for explanation
|
||||||
*
|
|
||||||
* If suspend-to-disk is not demanded, then ramp up more slowly,
|
|
||||||
* to 8GB swap at 16GB memory, and then drop to 4GB for "large
|
|
||||||
* memory" machines, on the assumption that those don't need swap
|
|
||||||
* because they have tons of memory (or whatever they are doing,
|
|
||||||
* had better not run into swap).
|
|
||||||
*/
|
|
||||||
qint64 suggestedSwapSizeB = 0;
|
qint64 suggestedSwapSizeB = 0;
|
||||||
auto memory = CalamaresUtils::System::instance()->getTotalMemoryB();
|
auto memory = CalamaresUtils::System::instance()->getTotalMemoryB();
|
||||||
qint64 availableRamB = memory.first;
|
qint64 availableRamB = memory.first;
|
||||||
qreal overestimationFactor = memory.second;
|
qreal overestimationFactor = memory.second;
|
||||||
|
|
||||||
bool ensureSuspendToDisk =
|
bool ensureSuspendToDisk = swap == Choices::FullSwap;
|
||||||
Calamares::JobQueue::instance()->globalStorage()->
|
|
||||||
value( "ensureSuspendToDisk" ).toBool();
|
|
||||||
|
|
||||||
if ( ensureSuspendToDisk )
|
// Ramp up quickly to 8GiB, then follow memory size
|
||||||
{
|
if ( availableRamB <= 4_GiB )
|
||||||
if ( availableRamB < 4_GiB )
|
suggestedSwapSizeB = availableRamB * 2;
|
||||||
suggestedSwapSizeB = qMax( 2_GiB, availableRamB * 2 );
|
else if ( availableRamB <= 8_GiB )
|
||||||
else if ( availableRamB >= 4_GiB && availableRamB < 8_GiB )
|
suggestedSwapSizeB = 8_GiB;
|
||||||
suggestedSwapSizeB = 8_GiB;
|
else
|
||||||
else
|
suggestedSwapSizeB = availableRamB;
|
||||||
suggestedSwapSizeB = availableRamB;
|
|
||||||
|
|
||||||
suggestedSwapSizeB *= overestimationFactor;
|
// .. top out at 8GiB if we don't care about suspend
|
||||||
}
|
if ( !ensureSuspendToDisk )
|
||||||
else //if we don't care about suspend to disk
|
suggestedSwapSizeB = qMin( 8_GiB, suggestedSwapSizeB );
|
||||||
{
|
|
||||||
if ( availableRamB < 2_GiB )
|
|
||||||
suggestedSwapSizeB = qMax( 2_GiB, availableRamB * 2 );
|
|
||||||
else if ( availableRamB >= 2_GiB && availableRamB < 8_GiB )
|
|
||||||
suggestedSwapSizeB = availableRamB;
|
|
||||||
else if ( availableRamB >= 8_GiB && availableRamB < 16_GiB )
|
|
||||||
suggestedSwapSizeB = 8_GiB;
|
|
||||||
else
|
|
||||||
suggestedSwapSizeB = 4_GiB;
|
|
||||||
|
|
||||||
suggestedSwapSizeB *= overestimationFactor;
|
|
||||||
|
|
||||||
// don't use more than 10% of available space
|
// Allow for a fudge factor
|
||||||
qreal maxSwapDiskRatio = 0.10;
|
suggestedSwapSizeB *= overestimationFactor;
|
||||||
qint64 maxSwapSizeB = availableSpaceB * maxSwapDiskRatio;
|
|
||||||
if ( suggestedSwapSizeB > maxSwapSizeB )
|
// don't use more than 10% of available space
|
||||||
suggestedSwapSizeB = maxSwapSizeB;
|
if ( !ensureSuspendToDisk )
|
||||||
}
|
suggestedSwapSizeB = qMin( suggestedSwapSizeB, qint64( 0.10 * availableSpaceB ) );
|
||||||
|
|
||||||
cDebug() << "Suggested swap size:" << suggestedSwapSizeB / 1024. / 1024. / 1024. << "GiB";
|
cDebug() << "Suggested swap size:" << suggestedSwapSizeB / 1024. / 1024. / 1024. << "GiB";
|
||||||
|
|
||||||
@ -118,16 +97,14 @@ bytesToSectors( qint64 bytes, qint64 blocksize )
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
doAutopartition( PartitionCoreModule* core, Device* dev, const QString& luksPassphrase )
|
doAutopartition( PartitionCoreModule* core, Device* dev, Choices::AutoPartitionOptions o )
|
||||||
{
|
{
|
||||||
Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage();
|
QString defaultFsType = o.defaultFsType;
|
||||||
|
|
||||||
bool isEfi = PartUtils::isEfiSystem();
|
|
||||||
|
|
||||||
QString defaultFsType = gs->value( "defaultFileSystemType" ).toString();
|
|
||||||
if ( FileSystem::typeForName( defaultFsType ) == FileSystem::Unknown )
|
if ( FileSystem::typeForName( defaultFsType ) == FileSystem::Unknown )
|
||||||
defaultFsType = "ext4";
|
defaultFsType = "ext4";
|
||||||
|
|
||||||
|
bool isEfi = PartUtils::isEfiSystem();
|
||||||
|
|
||||||
// Partition sizes are expressed in MiB, should be multiples of
|
// Partition sizes are expressed in MiB, should be multiples of
|
||||||
// the logical sector size (usually 512B). EFI starts with 2MiB
|
// the logical sector size (usually 512B). EFI starts with 2MiB
|
||||||
// empty and a 300MiB EFI boot partition, while BIOS starts at
|
// empty and a 300MiB EFI boot partition, while BIOS starts at
|
||||||
@ -160,8 +137,7 @@ doAutopartition( PartitionCoreModule* core, Device* dev, const QString& luksPass
|
|||||||
PartitionTable::FlagNone
|
PartitionTable::FlagNone
|
||||||
);
|
);
|
||||||
PartitionInfo::setFormat( efiPartition, true );
|
PartitionInfo::setFormat( efiPartition, true );
|
||||||
PartitionInfo::setMountPoint( efiPartition, gs->value( "efiSystemPartition" )
|
PartitionInfo::setMountPoint( efiPartition, o.efiPartitionMountPoint );
|
||||||
.toString() );
|
|
||||||
core->createPartition( dev, efiPartition, PartitionTable::FlagEsp );
|
core->createPartition( dev, efiPartition, PartitionTable::FlagEsp );
|
||||||
firstFreeSector = lastSector + 1;
|
firstFreeSector = lastSector + 1;
|
||||||
}
|
}
|
||||||
@ -170,20 +146,18 @@ doAutopartition( PartitionCoreModule* core, Device* dev, const QString& luksPass
|
|||||||
core->createPartitionTable( dev, PartitionTable::msdos );
|
core->createPartitionTable( dev, PartitionTable::msdos );
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool mayCreateSwap = !gs->value( "neverCreateSwap" ).toBool();
|
const bool mayCreateSwap = ( o.swap == Choices::SmallSwap ) || ( o.swap == Choices::FullSwap );
|
||||||
bool shouldCreateSwap = false;
|
bool shouldCreateSwap = false;
|
||||||
qint64 suggestedSwapSizeB = 0;
|
qint64 suggestedSwapSizeB = 0;
|
||||||
|
|
||||||
if ( mayCreateSwap )
|
if ( mayCreateSwap )
|
||||||
{
|
{
|
||||||
qint64 availableSpaceB = ( dev->totalLogical() - firstFreeSector ) * dev->logicalSize();
|
qint64 availableSpaceB = ( dev->totalLogical() - firstFreeSector ) * dev->logicalSize();
|
||||||
suggestedSwapSizeB = swapSuggestion( availableSpaceB );
|
suggestedSwapSizeB = swapSuggestion( availableSpaceB, o.swap );
|
||||||
// Space required by this installation is what the distro claims is needed
|
// Space required by this installation is what the distro claims is needed
|
||||||
// (via global configuration) plus the swap size plus a fudge factor of
|
// (via global configuration) plus the swap size plus a fudge factor of
|
||||||
// 0.6GiB (this was 2.1GiB up to Calamares 3.2.2).
|
// 0.6GiB (this was 2.1GiB up to Calamares 3.2.2).
|
||||||
qint64 requiredSpaceB =
|
qint64 requiredSpaceB = o.requiredSpaceB + 600_MiB + suggestedSwapSizeB;
|
||||||
GiBtoBytes( gs->value( "requiredStorageGB" ).toDouble() + 0.6 ) +
|
|
||||||
suggestedSwapSizeB;
|
|
||||||
|
|
||||||
// If there is enough room for ESP + root + swap, create swap, otherwise don't.
|
// If there is enough room for ESP + root + swap, create swap, otherwise don't.
|
||||||
shouldCreateSwap = availableSpaceB > requiredSpaceB;
|
shouldCreateSwap = availableSpaceB > requiredSpaceB;
|
||||||
@ -196,7 +170,7 @@ doAutopartition( PartitionCoreModule* core, Device* dev, const QString& luksPass
|
|||||||
}
|
}
|
||||||
|
|
||||||
Partition* rootPartition = nullptr;
|
Partition* rootPartition = nullptr;
|
||||||
if ( luksPassphrase.isEmpty() )
|
if ( o.luksPassphrase.isEmpty() )
|
||||||
{
|
{
|
||||||
rootPartition = KPMHelpers::createNewPartition(
|
rootPartition = KPMHelpers::createNewPartition(
|
||||||
dev->partitionTable(),
|
dev->partitionTable(),
|
||||||
@ -217,7 +191,7 @@ doAutopartition( PartitionCoreModule* core, Device* dev, const QString& luksPass
|
|||||||
FileSystem::typeForName( defaultFsType ),
|
FileSystem::typeForName( defaultFsType ),
|
||||||
firstFreeSector,
|
firstFreeSector,
|
||||||
lastSectorForRoot,
|
lastSectorForRoot,
|
||||||
luksPassphrase,
|
o.luksPassphrase,
|
||||||
PartitionTable::FlagNone
|
PartitionTable::FlagNone
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -232,7 +206,7 @@ doAutopartition( PartitionCoreModule* core, Device* dev, const QString& luksPass
|
|||||||
if ( shouldCreateSwap )
|
if ( shouldCreateSwap )
|
||||||
{
|
{
|
||||||
Partition* swapPartition = nullptr;
|
Partition* swapPartition = nullptr;
|
||||||
if ( luksPassphrase.isEmpty() )
|
if ( o.luksPassphrase.isEmpty() )
|
||||||
{
|
{
|
||||||
swapPartition = KPMHelpers::createNewPartition(
|
swapPartition = KPMHelpers::createNewPartition(
|
||||||
dev->partitionTable(),
|
dev->partitionTable(),
|
||||||
@ -253,7 +227,7 @@ doAutopartition( PartitionCoreModule* core, Device* dev, const QString& luksPass
|
|||||||
FileSystem::LinuxSwap,
|
FileSystem::LinuxSwap,
|
||||||
lastSectorForRoot + 1,
|
lastSectorForRoot + 1,
|
||||||
dev->totalLogical() - 1,
|
dev->totalLogical() - 1,
|
||||||
luksPassphrase,
|
o.luksPassphrase,
|
||||||
PartitionTable::FlagNone
|
PartitionTable::FlagNone
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -269,13 +243,11 @@ void
|
|||||||
doReplacePartition( PartitionCoreModule* core,
|
doReplacePartition( PartitionCoreModule* core,
|
||||||
Device* dev,
|
Device* dev,
|
||||||
Partition* partition,
|
Partition* partition,
|
||||||
const QString& luksPassphrase )
|
Choices::ReplacePartitionOptions o )
|
||||||
{
|
{
|
||||||
cDebug() << "doReplacePartition for device" << partition->partitionPath();
|
cDebug() << "doReplacePartition for device" << partition->partitionPath();
|
||||||
|
|
||||||
QString defaultFsType = Calamares::JobQueue::instance()->
|
QString defaultFsType = o.defaultFsType;
|
||||||
globalStorage()->
|
|
||||||
value( "defaultFileSystemType" ).toString();
|
|
||||||
if ( FileSystem::typeForName( defaultFsType ) == FileSystem::Unknown )
|
if ( FileSystem::typeForName( defaultFsType ) == FileSystem::Unknown )
|
||||||
defaultFsType = "ext4";
|
defaultFsType = "ext4";
|
||||||
|
|
||||||
@ -296,7 +268,7 @@ doReplacePartition( PartitionCoreModule* core,
|
|||||||
}
|
}
|
||||||
|
|
||||||
Partition* newPartition = nullptr;
|
Partition* newPartition = nullptr;
|
||||||
if ( luksPassphrase.isEmpty() )
|
if ( o.luksPassphrase.isEmpty() )
|
||||||
{
|
{
|
||||||
newPartition = KPMHelpers::createNewPartition(
|
newPartition = KPMHelpers::createNewPartition(
|
||||||
partition->parent(),
|
partition->parent(),
|
||||||
@ -317,7 +289,7 @@ doReplacePartition( PartitionCoreModule* core,
|
|||||||
FileSystem::typeForName( defaultFsType ),
|
FileSystem::typeForName( defaultFsType ),
|
||||||
partition->firstSector(),
|
partition->firstSector(),
|
||||||
partition->lastSector(),
|
partition->lastSector(),
|
||||||
luksPassphrase,
|
o.luksPassphrase,
|
||||||
PartitionTable::FlagNone
|
PartitionTable::FlagNone
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user