Support more VM types in qvm-grow-root

QubesOS/qubes-issues#1268
This commit is contained in:
Michal Rostecki 2015-10-04 22:07:50 +02:00
parent 2b7bd1f1f5
commit 3be8bb31fb
4 changed files with 97 additions and 32 deletions

View File

@ -0,0 +1,67 @@
#!/usr/bin/python2
# -*- encoding: utf8 -*-
#
# The Qubes OS Project, http://www.qubes-os.org
#
# This program 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 2
# of the License, or (at your option) any later version.
#
# This program 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 this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
#
from __future__ import (
absolute_import,
division,
print_function,
unicode_literals,
)
from qubes.qubes import (
register_qubes_vm_class,
QubesException,
QubesVm,
)
class QubesResizableVm(QubesVm):
def resize_root_img(self, size):
if self.template:
raise QubesException("Cannot resize root.img of template-based VM"
". Resize the root.img of the template "
"instead.")
if self.is_running():
raise QubesException("Cannot resize root.img of running VM")
if size < self.get_root_img_sz():
raise QubesException(
"For your own safety shringing of root.img is disabled. If "
"you really know what you are doing, use 'truncate' manually.")
f_root = open(self.root_img, "a+b")
f_root.truncate(size)
f_root.close()
class QubesResizableVmWithResize2fs(QubesResizableVm):
def resize_root_img(self, size):
super(QubesResizableVmWithResize2fs, self).resize_root_img(size)
self.start()
self.run("sudo resize2fs /dev/mapper/dmroot")
self.shutdown()
register_qubes_vm_class(QubesResizableVm)
register_qubes_vm_class(QubesResizableVmWithResize2fs)

View File

@ -23,14 +23,20 @@
# #
import os import os
import subprocess
import sys import sys
from qubes.qubes import QubesVm,register_qubes_vm_class,dry_run from qubes.qubes import (
from qubes.qubes import QubesVmCollection,QubesException,QubesVmLabels defaults,
from qubes.qubes import defaults,system_path,vm_files,vmm dry_run,
register_qubes_vm_class,
system_path,
vmm,
QubesResizableVmWithResize2fs,
QubesVmCollection,
)
class QubesTemplateVm(QubesVm):
class QubesTemplateVm(QubesResizableVmWithResize2fs):
""" """
A class that represents an TemplateVM. A child of QubesVm. A class that represents an TemplateVM. A child of QubesVm.
""" """

View File

@ -24,9 +24,15 @@
import os.path import os.path
from qubes.qubes import QubesVm,QubesVmLabel,register_qubes_vm_class,system_path from qubes.qubes import (
register_qubes_vm_class,
system_path,
QubesResizableVmWithResize2fs,
QubesVmLabel,
)
class QubesAppVm(QubesVm):
class QubesAppVm(QubesResizableVmWithResize2fs):
""" """
A class that represents an AppVM. A child of QubesVm. A class that represents an AppVM. A child of QubesVm.
""" """

View File

@ -26,16 +26,20 @@ import os
import os.path import os.path
import signal import signal
import subprocess import subprocess
import stat
import sys import sys
import re
import shutil import shutil
import stat
from xml.etree import ElementTree from xml.etree import ElementTree
from qubes.qubes import QubesVm,register_qubes_vm_class,vmm,dry_run from qubes.qubes import (
from qubes.qubes import system_path,defaults dry_run,
from qubes.qubes import QubesException defaults,
register_qubes_vm_class,
system_path,
vmm,
QubesException,
QubesResizableVm,
)
system_path["config_template_hvm"] = '/usr/share/qubes/vm-template-hvm.xml' system_path["config_template_hvm"] = '/usr/share/qubes/vm-template-hvm.xml'
@ -44,7 +48,7 @@ defaults["hvm_private_img_size"] = 2*1024*1024*1024
defaults["hvm_memory"] = 512 defaults["hvm_memory"] = 512
class QubesHVm(QubesVm): class QubesHVm(QubesResizableVm):
""" """
A class that represents an HVM. A child of QubesVm. A class that represents an HVM. A child of QubesVm.
""" """
@ -235,24 +239,6 @@ class QubesHVm(QubesVm):
self.storage.resize_private_img(size) self.storage.resize_private_img(size)
def resize_root_img(self, size):
if self.template:
raise QubesException("Cannot resize root.img of template-based VM"
". Resize the root.img of the template "
"instead.")
if self.is_running():
raise QubesException("Cannot resize root.img of running HVM")
if size < self.get_root_img_sz():
raise QubesException(
"For your own safety shringing of root.img is disabled. If "
"you really know what you are doing, use 'truncate' manually.")
f_root = open (self.root_img, "a+b")
f_root.truncate (size)
f_root.close ()
def get_config_params(self): def get_config_params(self):
params = super(QubesHVm, self).get_config_params() params = super(QubesHVm, self).get_config_params()