diff --git a/core-modules/001QubesResizableVm.py b/core-modules/001QubesResizableVm.py index 5e898b40..f50ead70 100644 --- a/core-modules/001QubesResizableVm.py +++ b/core-modules/001QubesResizableVm.py @@ -36,7 +36,7 @@ from time import sleep class QubesResizableVm(QubesVm): - def resize_root_img(self, size): + def resize_root_img(self, size, allow_start=False): if self.template: raise QubesException("Cannot resize root.img of template-based VM" ". Resize the root.img of the template " @@ -57,8 +57,14 @@ class QubesResizableVm(QubesVm): class QubesResizableVmWithResize2fs(QubesResizableVm): - def resize_root_img(self, size): - super(QubesResizableVmWithResize2fs, self).resize_root_img(size) + def resize_root_img(self, size, allow_start=False): + super(QubesResizableVmWithResize2fs, self).\ + resize_root_img(size, allow_start=allow_start) + if not allow_start: + raise QubesException("VM start required to complete the " + "operation, but not allowed. Either run the " + "operation again allowing VM start this " + "time, or run resize2fs in the VM manually.") self.start(start_guid=False) self.run("resize2fs /dev/mapper/dmroot", user="root", wait=True, gui=False) diff --git a/qvm-tools/qvm-grow-root b/qvm-tools/qvm-grow-root index 93c55bb2..5e650ab7 100755 --- a/qvm-tools/qvm-grow-root +++ b/qvm-tools/qvm-grow-root @@ -34,6 +34,10 @@ def main(): usage = "usage: %prog " parser = OptionParser (usage) + parser.add_option("--allow-start", action="store_true", + dest="allow_start", default=False, + help="Allow VM to be started to complete the operation") + (options, args) = parser.parse_args () if (len (args) != 2): parser.error ("You must specify VM name and new size!") @@ -57,7 +61,7 @@ def main(): exit(1) try: - vm.resize_root_img(size_bytes) + vm.resize_root_img(size_bytes, allow_start=options.allow_start) except (IOError, OSError, QubesException) as err: print >> sys.stderr, "ERROR: {0}".format(err) exit (1) diff --git a/tests/vm_qrexec_gui.py b/tests/vm_qrexec_gui.py index c64da4d4..aa4e3da4 100644 --- a/tests/vm_qrexec_gui.py +++ b/tests/vm_qrexec_gui.py @@ -731,7 +731,9 @@ class TC_05_StandaloneVM(qubes.tests.SystemTestsMixin, qubes.tests.QubesTestCase source_template=self.qc.get_default_template()) self.qc.save() self.qc.unlock_db() - testvm1.resize_root_img(20*1024**3) + with self.assertRaises(QubesException): + testvm1.resize_root_img(20*1024**3) + testvm1.resize_root_img(20*1024**3, allow_start=True) timeout = 60 while testvm1.is_running(): time.sleep(1)