Skip to content

Commit

Permalink
Mount ro first, remount rw in background
Browse files Browse the repository at this point in the history
Makes Berryboot feel more responsive recovering after unclean shutdown
  • Loading branch information
maxnet committed Aug 14, 2014
1 parent a1360c3 commit 394f5cb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
30 changes: 28 additions & 2 deletions BerrybootGUI2.0/bootmenudialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ void BootMenuDialog::initialize()

if (QFile::exists(runonce_file))
{
waitForRemountRW();
qpd.setLabelText(tr("Removing runonce file"));
QApplication::processEvents();
QByteArray runonce = file_get_contents(runonce_file);
Expand Down Expand Up @@ -298,6 +299,7 @@ void BootMenuDialog::bootImage(const QString &name)
{
int currentmemsplit = currentMemsplit();
int needsmemsplit = imageNeedsMemsplit(name);
waitForRemountRW();

if (_i->isMemsplitHandlingEnabled() && needsmemsplit && needsmemsplit != currentmemsplit)
{
Expand Down Expand Up @@ -347,6 +349,7 @@ void BootMenuDialog::startInstaller()
{
startNetworking();
mountSystemPartition();
waitForRemountRW();
accept();
}

Expand Down Expand Up @@ -460,7 +463,7 @@ QByteArray BootMenuDialog::getBootOptions()

bool BootMenuDialog::mountDataPartition(const QString &dev)
{
QString mountoptions = "-o noatime";
QString mountoptions = "-o noatime,ro";

if (!QFile::exists("/mnt"))
mkdir("/mnt", 0755);
Expand All @@ -475,8 +478,13 @@ bool BootMenuDialog::mountDataPartition(const QString &dev)
mountoptions += " -t ext4";
}

if (QProcess::execute("mount "+mountoptions+" /dev/"+dev+" /mnt") != 0)
/* Try mounting read-only first.
* If that fails try mounting read-write straight away as it might recover from journal */
if (QProcess::execute("mount "+mountoptions+" /dev/"+dev+" /mnt") != 0
&& QProcess::execute("mount "+mountoptions.replace(",ro","")+" /dev/"+dev+" /mnt") != 0)
{
return false;
}

if (!QFile::exists("/mnt/images"))
{
Expand All @@ -487,9 +495,27 @@ bool BootMenuDialog::mountDataPartition(const QString &dev)
return false;
}

/* Remount read-write in the background */
_remountproc.start("mount -o remount,rw /mnt");

return true;
}

void BootMenuDialog::waitForRemountRW()
{
if (_remountproc.state() != _remountproc.NotRunning)
{
QProgressDialog qpd(tr("Remounting data partition read-write"), QString(), 0, 0, this);
qpd.show();
QApplication::processEvents();

if (!_remountproc.waitForFinished())
{
QMessageBox::critical(this, tr("Error remounting data partition"), tr("Timed out waiting for remounting data partition read-write to complete"), QMessageBox::Ok);
}
}
}

bool BootMenuDialog::waitForDevice(const QString &dev)
{
QTime t;
Expand Down
6 changes: 6 additions & 0 deletions BerrybootGUI2.0/bootmenudialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <QDialog>
#include <QTimer>
#include <QModelIndex>
#include <QProcess>

namespace Ui {
class BootMenuDialog;
Expand Down Expand Up @@ -150,11 +151,16 @@ class BootMenuDialog : public QDialog
* Stop SSH daemon
*/
void stopSSHserver();
/*
* Wait for remount RW
*/
void waitForRemountRW();

Ui::BootMenuDialog *ui;
Installer *_i;
int _countdown;
QTimer _countdownTimer;
QProcess _remountproc;

protected slots:
void on_bootButton_clicked();
Expand Down

0 comments on commit 394f5cb

Please sign in to comment.