mirror of https://github.com/cutefishos/calamares
[fsresize] Add new module fsresizer
- Non-functional as yet, WIP - Intended for use on SBC images and similar, which need to resize the root partition to the size of the SD card they're on. FIXES #921main
parent
82c51dec37
commit
4d5eb90a04
@ -0,0 +1,27 @@
|
||||
find_package(ECM ${ECM_VERSION} REQUIRED NO_MODULE)
|
||||
|
||||
find_package( KPMcore 3.3 )
|
||||
find_package( Qt5 REQUIRED DBus ) # Needed for KPMCore
|
||||
find_package( KF5 REQUIRED I18n WidgetsAddons ) # Needed for KPMCore
|
||||
|
||||
if ( KPMcore_FOUND )
|
||||
if ( KPMcore_VERSION VERSION_GREATER "3.3.0")
|
||||
add_definitions(-DWITH_KPMCOREGT33) # kpmcore greater than 3.3
|
||||
endif()
|
||||
|
||||
include_directories( ${KPMCORE_INCLUDE_DIR} )
|
||||
include_directories( ${PROJECT_BINARY_DIR}/src/libcalamares )
|
||||
|
||||
calamares_add_plugin( fsresizer
|
||||
TYPE job
|
||||
EXPORT_MACRO PLUGINDLLEXPORT_PRO
|
||||
SOURCES
|
||||
ResizeFSJob.cpp
|
||||
LINK_PRIVATE_LIBRARIES
|
||||
kpmcore
|
||||
calamares
|
||||
SHARED_LIB
|
||||
)
|
||||
else()
|
||||
calamares_skip_module( "fsresizer (missing suitable KPMcore)" )
|
||||
endif()
|
@ -0,0 +1,104 @@
|
||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||
*
|
||||
* Copyright 2018, Adriaan de Groot <groot@kde.org>
|
||||
*
|
||||
* 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 "ResizeFSJob.h"
|
||||
|
||||
#include <QProcess>
|
||||
#include <QDateTime>
|
||||
#include <QThread>
|
||||
|
||||
#include "CalamaresVersion.h"
|
||||
#include "JobQueue.h"
|
||||
#include "GlobalStorage.h"
|
||||
|
||||
#include "utils/Logger.h"
|
||||
|
||||
ResizeFSJob::RelativeSize::RelativeSize()
|
||||
: m_unit( None )
|
||||
, m_value( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ResizeFSJob::RelativeSize::RelativeSize( const QString& s)
|
||||
: m_unit( None )
|
||||
, m_value( 0 )
|
||||
{
|
||||
QString valuePart;
|
||||
|
||||
if ( s.endsWith( '%' ) )
|
||||
{
|
||||
valuePart = s.left( s.length() - 1 );
|
||||
m_unit = Percent;
|
||||
}
|
||||
if ( s.endsWith( "MiB" ) )
|
||||
{
|
||||
valuePart = s.left( s.length() - 3 );
|
||||
m_unit = Absolute;
|
||||
}
|
||||
|
||||
if ( ( m_unit != None ) && !valuePart.isEmpty() )
|
||||
m_value = valuePart.toInt();
|
||||
|
||||
if ( !m_value )
|
||||
m_unit = None;
|
||||
}
|
||||
|
||||
|
||||
ResizeFSJob::ResizeFSJob( QObject* parent )
|
||||
: Calamares::CppJob( parent )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ResizeFSJob::~ResizeFSJob()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
QString
|
||||
ResizeFSJob::prettyName() const
|
||||
{
|
||||
return tr( "Resize Filesystem Job" );
|
||||
}
|
||||
|
||||
|
||||
Calamares::JobResult
|
||||
ResizeFSJob::exec()
|
||||
{
|
||||
return Calamares::JobResult::ok();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ResizeFSJob::setConfigurationMap( const QVariantMap& configurationMap )
|
||||
{
|
||||
m_fsname = configurationMap["fs"].toString();
|
||||
m_devicename = configurationMap["dev"].toString();
|
||||
|
||||
if ( m_fsname.isEmpty() && m_devicename.isEmpty() )
|
||||
{
|
||||
cWarning() << "No fs or dev configured for resize.";
|
||||
return;
|
||||
}
|
||||
|
||||
m_size = RelativeSize( configurationMap["size"].toString() );
|
||||
m_atleast = RelativeSize( configurationMap["atleast"].toString() );
|
||||
}
|
||||
|
||||
CALAMARES_PLUGIN_FACTORY_DEFINITION( ResizeFSJobFactory, registerPlugin<ResizeFSJob>(); )
|
@ -0,0 +1,75 @@
|
||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||
*
|
||||
* Copyright 2018, Adriaan de Groot <groot@kde.org>
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef RESIZEFSJOB_H
|
||||
#define RESIZEFSJOB_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QVariantMap>
|
||||
|
||||
#include <CppJob.h>
|
||||
|
||||
#include <utils/PluginFactory.h>
|
||||
|
||||
#include <PluginDllMacro.h>
|
||||
|
||||
class PLUGINDLLEXPORT ResizeFSJob : public Calamares::CppJob
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
class RelativeSize
|
||||
{
|
||||
public:
|
||||
RelativeSize();
|
||||
RelativeSize( const QString& );
|
||||
|
||||
enum Unit
|
||||
{
|
||||
None,
|
||||
Percent,
|
||||
Absolute
|
||||
};
|
||||
|
||||
quint64 value() const { return m_value; }
|
||||
Unit unit() const { return m_unit; }
|
||||
|
||||
private:
|
||||
quint64 m_value;
|
||||
Unit m_unit;
|
||||
} ;
|
||||
|
||||
public:
|
||||
explicit ResizeFSJob( QObject* parent = nullptr );
|
||||
virtual ~ResizeFSJob() override;
|
||||
|
||||
QString prettyName() const override;
|
||||
|
||||
Calamares::JobResult exec() override;
|
||||
|
||||
void setConfigurationMap( const QVariantMap& configurationMap ) override;
|
||||
|
||||
private:
|
||||
RelativeSize m_size;
|
||||
RelativeSize m_atleast;
|
||||
QString m_fsname; // Either this, or devicename, is set, not both
|
||||
QString m_devicename;
|
||||
};
|
||||
|
||||
CALAMARES_PLUGIN_FACTORY_DECLARATION( ResizeFSJobFactory )
|
||||
|
||||
#endif // RESIZEFSJOB_H
|
@ -0,0 +1,30 @@
|
||||
# Module that resizes a single FS to fill the entire (rest) of
|
||||
# a device. This is used in OEM situations where an image is
|
||||
# flashed onto an SD card (or similar) and used to boot a device,
|
||||
# after which the FS should expand to fill the SD card.
|
||||
#
|
||||
# Example: a distro produces a 6GiB large image that is
|
||||
# written to an 8GiB SD card; the FS should expand to take
|
||||
# advantage of the unused 2GiB. The FS should expand much
|
||||
# more if the same image is written to a 16GiB card.
|
||||
--
|
||||
|
||||
# Which FS needs to be grown? Choose one way to identify it:
|
||||
# - *fs* names a mount point which should already be mounted
|
||||
# in the system.
|
||||
# - *dev* names a device
|
||||
fs: /
|
||||
# dev: /dev/mmcblk0p1
|
||||
|
||||
# How much of the total remaining space should the FS use?
|
||||
# The only sensible amount is "all of it". The value is
|
||||
# in percent, so set it to 100. Perhaps a fixed size is
|
||||
# needed (that would be weird though, since you don't know
|
||||
# how big the card is), use MiB as suffix in that case.
|
||||
size: 100%
|
||||
|
||||
# Resizing might not be worth it, though. Set the minimum
|
||||
# that it must grow; if it cannot grow that much, the
|
||||
# resizing is skipped. Can be in percentage or absolute
|
||||
# size, as above.
|
||||
atleast: 1000MiB
|
Loading…
Reference in New Issue