void CreatePartitionDialog::initMbrPartitionTypeUi() { QString fixedPartitionString; bool parentIsPartitionTable = m_parent->isRoot(); if ( !parentIsPartitionTable ) { m_role = PartitionRole( PartitionRole::Logical ); fixedPartitionString = tr( "Logical" ); } else if ( m_device->partitionTable()->hasExtended() ) { m_role = PartitionRole( PartitionRole::Primary ); fixedPartitionString = tr( "Primary" ); } if ( fixedPartitionString.isEmpty() ) m_ui->fixedPartitionLabel->hide(); else { m_ui->fixedPartitionLabel->setText( fixedPartitionString ); m_ui->primaryRadioButton->hide(); m_ui->extendedRadioButton->hide(); } }
void CreatePartitionDialog::initGptPartitionTypeUi() { m_role = PartitionRole( PartitionRole::Primary ); m_ui->fixedPartitionLabel->setText( tr( "GPT" ) ); m_ui->primaryRadioButton->hide(); m_ui->extendedRadioButton->hide(); }
Partition* CreatePartitionDialog::createPartition() { if ( m_role.roles() == PartitionRole::None ) { m_role = PartitionRole( m_ui->extendedRadioButton->isChecked() ? PartitionRole::Extended : PartitionRole::Primary ); } qint64 first = m_partitionSizeController->firstSector(); qint64 last = m_partitionSizeController->lastSector(); FileSystem::Type fsType = m_role.has( PartitionRole::Extended ) ? FileSystem::Extended : FileSystem::typeForName( m_ui->fsComboBox->currentText() ); Partition* partition = nullptr; QString luksPassphrase = m_ui->encryptWidget->passphrase(); if ( m_ui->encryptWidget->state() == EncryptWidget::EncryptionConfirmed && !luksPassphrase.isEmpty() ) { partition = KPMHelpers::createNewEncryptedPartition( m_parent, *m_device, m_role, fsType, first, last, luksPassphrase, newFlags() ); } else { partition = KPMHelpers::createNewPartition( m_parent, *m_device, m_role, fsType, first, last, newFlags() ); } if (m_device->type() == Device::Type::LVM_Device) { partition->setPartitionPath(m_device->deviceNode() + QStringLiteral("/") + m_ui->lvNameLineEdit->text().trimmed()); } PartitionInfo::setMountPoint( partition, selectedMountPoint( m_ui->mountPointComboBox ) ); PartitionInfo::setFormat( partition, true ); return partition; }
/** Creates a new unallocated Partition on the given Device. @param device the Device to create the new Partition on @param parent the parent PartitionNode for the new Partition @param start the new Partition's start sector @param end the new Partition's end sector @return pointer to the newly created Partition object or nullptr if the Partition could not be created */ Partition* createUnallocated(const Device& device, PartitionNode& parent, qint64 start, qint64 end) { PartitionRole::Roles r = PartitionRole::Unallocated; if (!parent.isRoot()) r |= PartitionRole::Logical; // Mark unallocated space in LVM VG as LVM LV so that pasting can be easily disabled (it does not work yet) if (device.type() == Device::LVM_Device) r |= PartitionRole::Lvm_Lv; if (!PartitionTable::getUnallocatedRange(device, parent, start, end)) return nullptr; return new Partition(&parent, device, PartitionRole(r), FileSystemFactory::create(FileSystem::Unknown, start, end), start, end, QString()); }
/** Creates a new Partition to restore to. @param device the Device to create the Partition on @param parent the parent PartitionNode @param start start sector of the Partition @param filename name of the image file to restore from */ Partition* RestoreOperation::createRestorePartition(const Device& device, PartitionNode& parent, qint64 start, const QString& filename) { PartitionRole::Roles r = PartitionRole::Primary; if (!parent.isRoot()) r = PartitionRole::Logical; QFileInfo fileInfo(filename); if (!fileInfo.exists()) return NULL; const qint64 end = start + fileInfo.size() / device.logicalSectorSize() - 1; Partition* p = new Partition(&parent, device, PartitionRole(r), FileSystemFactory::create(FileSystem::Unknown, start, end), start, end, QString()); p->setState(Partition::StateRestore); return p; }
void doAutopartition( PartitionCoreModule* core, Device* dev, const QString& luksPassphrase ) { bool isEfi = false; if ( QDir( "/sys/firmware/efi/efivars" ).exists() ) isEfi = true; QString defaultFsType = Calamares::JobQueue::instance()-> globalStorage()-> value( "defaultFileSystemType" ).toString(); if ( FileSystem::typeForName( defaultFsType ) == FileSystem::Unknown ) defaultFsType = "ext4"; #define MiB * static_cast< qint64 >( 1024 ) * 1024 #define GiB * static_cast< qint64 >( 1024 ) * 1024 * 1024 // Partition sizes are expressed in MiB, should be multiples of // the logical sector size (usually 512B). int uefisys_part_size = 0; int empty_space_size = 0; if ( isEfi ) { uefisys_part_size = 300; empty_space_size = 2; } else { // we start with a 1MiB offset before the first partition empty_space_size = 1; } qint64 firstFreeSector = empty_space_size MiB / dev->logicalSectorSize() + 1; if ( isEfi ) { qint64 lastSector = firstFreeSector + ( uefisys_part_size MiB / dev->logicalSectorSize() ); core->createPartitionTable( dev, PartitionTable::gpt ); Partition* efiPartition = KPMHelpers::createNewPartition( dev->partitionTable(), *dev, PartitionRole( PartitionRole::Primary ), FileSystem::Fat32, firstFreeSector, lastSector ); PartitionInfo::setFormat( efiPartition, true ); PartitionInfo::setMountPoint( efiPartition, Calamares::JobQueue::instance() ->globalStorage() ->value( "efiSystemPartition" ) .toString() ); core->createPartition( dev, efiPartition ); firstFreeSector = lastSector + 1; } else { core->createPartitionTable( dev, PartitionTable::msdos ); } bool shouldCreateSwap = false; qint64 availableSpaceB = ( dev->totalSectors() - firstFreeSector ) * dev->logicalSectorSize(); qint64 suggestedSwapSizeB = swapSuggestion( availableSpaceB ); qint64 requiredSpaceB = ( Calamares::JobQueue::instance()-> globalStorage()-> value( "requiredStorageGB" ).toDouble() + 0.1 + 2.0 ) GiB + suggestedSwapSizeB; // If there is enough room for ESP + root + swap, create swap, otherwise don't. shouldCreateSwap = availableSpaceB > requiredSpaceB; qint64 lastSectorForRoot = dev->totalSectors() - 1; //last sector of the device if ( shouldCreateSwap ) { lastSectorForRoot -= suggestedSwapSizeB / dev->logicalSectorSize() + 1; } Partition* rootPartition = nullptr; if ( luksPassphrase.isEmpty() ) { rootPartition = KPMHelpers::createNewPartition( dev->partitionTable(), *dev, PartitionRole( PartitionRole::Primary ), FileSystem::typeForName( defaultFsType ), firstFreeSector, lastSectorForRoot ); } else { rootPartition = KPMHelpers::createNewEncryptedPartition( dev->partitionTable(), *dev, PartitionRole( PartitionRole::Primary ), FileSystem::typeForName( defaultFsType ), firstFreeSector, lastSectorForRoot, luksPassphrase ); } PartitionInfo::setFormat( rootPartition, true ); PartitionInfo::setMountPoint( rootPartition, "/" ); core->createPartition( dev, rootPartition ); if ( shouldCreateSwap ) { Partition* swapPartition = nullptr; if ( luksPassphrase.isEmpty() ) { swapPartition = KPMHelpers::createNewPartition( dev->partitionTable(), *dev, PartitionRole( PartitionRole::Primary ), FileSystem::LinuxSwap, lastSectorForRoot + 1, dev->totalSectors() - 1 ); } else { swapPartition = KPMHelpers::createNewEncryptedPartition( dev->partitionTable(), *dev, PartitionRole( PartitionRole::Primary ), FileSystem::LinuxSwap, lastSectorForRoot + 1, dev->totalSectors() - 1, luksPassphrase ); } PartitionInfo::setFormat( swapPartition, true ); core->createPartition( dev, swapPartition ); } core->dumpQueue(); }
void doReplacePartition( PartitionCoreModule* core, Device* dev, Partition* partition, const QString& luksPassphrase ) { cDebug() << "doReplacePartition for device" << partition->partitionPath(); QString defaultFsType = Calamares::JobQueue::instance()-> globalStorage()-> value( "defaultFileSystemType" ).toString(); if ( FileSystem::typeForName( defaultFsType ) == FileSystem::Unknown ) defaultFsType = "ext4"; PartitionRole newRoles( partition->roles() ); if ( partition->roles().has( PartitionRole::Extended ) ) newRoles = PartitionRole( PartitionRole::Primary ); if ( partition->roles().has( PartitionRole::Unallocated ) ) { newRoles = PartitionRole( PartitionRole::Primary ); cDebug() << "WARNING: selected partition is free space"; if ( partition->parent() ) { Partition* parent = dynamic_cast< Partition* >( partition->parent() ); if ( parent && parent->roles().has( PartitionRole::Extended ) ) newRoles = PartitionRole( PartitionRole::Logical ); } } Partition* newPartition = nullptr; if ( luksPassphrase.isEmpty() ) { newPartition = KPMHelpers::createNewPartition( partition->parent(), *dev, newRoles, FileSystem::typeForName( defaultFsType ), partition->firstSector(), partition->lastSector() ); } else { newPartition = KPMHelpers::createNewEncryptedPartition( partition->parent(), *dev, newRoles, FileSystem::typeForName( defaultFsType ), partition->firstSector(), partition->lastSector(), luksPassphrase ); } PartitionInfo::setMountPoint( newPartition, "/" ); PartitionInfo::setFormat( newPartition, true ); if ( !partition->roles().has( PartitionRole::Unallocated ) ) core->deletePartition( dev, partition ); core->createPartition( dev, newPartition ); core->dumpQueue(); }
/** Creates a new RestoreOperation. @param d the Device to restore the Partition to @param p pointer to the Partition that will be restored. May not be NULL. @param filename name of the image file to restore from */ RestoreOperation::RestoreOperation(Device& d, Partition* p, const QString& filename) : Operation(), m_TargetDevice(d), m_RestorePartition(p), m_FileName(filename), m_OverwrittenPartition(NULL), m_MustDeleteOverwritten(false), m_ImageLength(QFileInfo(filename).size() / 512), // 512 being the "sector size" of an image file. m_CreatePartitionJob(NULL), m_RestoreJob(NULL), m_CheckTargetJob(NULL), m_MaximizeJob(NULL) { restorePartition().setState(Partition::StateRestore); Q_ASSERT(targetDevice().partitionTable()); Partition* dest = targetDevice().partitionTable()->findPartitionBySector(restorePartition().firstSector(), PartitionRole(PartitionRole::Primary | PartitionRole::Logical | PartitionRole::Unallocated)); Q_ASSERT(dest); if (dest == NULL) qWarning() << "destination partition not found at sector " << restorePartition().firstSector(); if (dest && !dest->roles().has(PartitionRole::Unallocated)) { restorePartition().setLastSector(dest->lastSector()); setOverwrittenPartition(dest); removePreviewPartition(targetDevice(), *dest); } if (!overwrittenPartition()) addJob(m_CreatePartitionJob = new CreatePartitionJob(targetDevice(), restorePartition())); addJob(m_RestoreJob = new RestoreFileSystemJob(targetDevice(), restorePartition(), fileName())); addJob(m_CheckTargetJob = new CheckFileSystemJob(restorePartition())); addJob(m_MaximizeJob = new ResizeFileSystemJob(targetDevice(), restorePartition())); }