core3: fix mounting modules.img

This commit is contained in:
Wojtek Porczyk 2015-10-02 16:02:51 +02:00
parent 15c59f938c
commit c9cbf8ffe2
5 changed files with 44 additions and 35 deletions

View File

@ -44,8 +44,7 @@ class VMStorage(object):
in mind.
''' # pylint: disable=abstract-class-little-used
def __init__(self, vm, private_img_size=None, root_img_size=None,
modules_img=None, modules_img_rw=False):
def __init__(self, vm, private_img_size=None, root_img_size=None):
#: Domain for which we manage storage
self.vm = vm
@ -60,10 +59,6 @@ class VMStorage(object):
if root_img_size is not None \
else qubes.config.defaults['root_img_size']
# For now compute this path still in QubesVm
self.modules_img = modules_img
self.modules_img_rw = modules_img_rw
#: Additional drive (currently used only by HVM)
self.drive = None
@ -87,6 +82,36 @@ class VMStorage(object):
return self.abspath(qubes.config.vm_files['volatile_img'])
@property
def kernels_dir(self):
'''Directory where kernel resides.
If :py:attr:`self.vm.kernel` is :py:obj:`None`, the this points inside
:py:attr:`self.vm.dir_path`
'''
return os.path.join(qubes.config.system_path['qubes_base_dir'],
qubes.config.system_path['qubes_kernels_base_dir'], self.vm.kernel) \
if self.vm.kernel is not None \
else os.path.join(self.vm.dir_path,
qubes.config.vm_files['kernels_subdir'])
@property
def modules_img(self):
'''Path to image with modules.
Depending on domain, this may be global or inside domain's dir.
'''
return os.path.join(self.kernels_dir, 'modules.img')
@property
def modules_img_rw(self):
''':py:obj:`True` if module image should be mounted RW, :py:obj:`False`
otherwise.'''
return self.vm.kernel is None
def abspath(self, path, rel=None):
'''Make absolute path.

View File

@ -102,6 +102,8 @@ class XenVMStorage(qubes.storage.VMStorage):
args['volatiledev'] = self._format_disk_dev(self.volatile_img,
self.volatile_dev)
args['kerneldir'] = self.kernels_dir
if self.modules_img is not None:
args['otherdevs'] = self._format_disk_dev(self.modules_img,
self.modules_dev, rw=self.modules_img_rw)

View File

@ -354,8 +354,6 @@ class BaseVM(qubes.PropertyHolder):
args = {}
args['name'] = self.name
if hasattr(self, 'kernels_dir'):
args['kerneldir'] = self.kernels_dir
args['uuid'] = str(self.uuid)
args['vmdir'] = self.dir_path
args['pcidevs'] = ''.join(lxml.etree.tostring(self.lvxml_pci_dev(dev))

View File

@ -370,20 +370,6 @@ class QubesVM(qubes.vm.BaseVM):
return self.storage.volatile_img
@property
def kernels_dir(self):
'''Directory where kernel resides.
If :py:attr:`self.kernel` is :py:obj:`None`, the this points inside
:py:attr:`self.dir_path`
'''
return os.path.join(qubes.config.system_path['qubes_base_dir'],
qubes.config.system_path['qubes_kernels_base_dir'], self.kernel) \
if self.kernel is not None \
else os.path.join(self.dir_path,
qubes.config.vm_files['kernels_subdir'])
# XXX shouldn't this go elsewhere?
@property
def updateable(self):
@ -525,12 +511,6 @@ class QubesVM(qubes.vm.BaseVM):
# Initialize VM image storage class
self.storage = qubes.storage.get_storage(self)
# XXX should be moved to defaults in storage class
# if self.kernels_dir is not None: # it is None for AdminVM
# self.storage.modules_img = os.path.join(self.kernels_dir,
# 'modules.img')
# self.storage.modules_img_rw = self.kernel is None
# fire hooks
self.fire_event('domain-init')
@ -1102,6 +1082,7 @@ class QubesVM(qubes.vm.BaseVM):
p.communicate(input=self.default_user)
# TODO move to storage
def create_on_disk(self, source_template=None):
'''Create files needed for VM.
@ -1117,7 +1098,7 @@ class QubesVM(qubes.vm.BaseVM):
self.storage.create_on_disk(source_template)
if self.updateable:
kernels_dir = source_template.kernels_dir
kernels_dir = source_template.storage.kernels_dir
self.log.info(
'Copying the kernel (unset kernel to use it): {0}'.format(
kernels_dir))
@ -1125,8 +1106,7 @@ class QubesVM(qubes.vm.BaseVM):
os.mkdir(self.dir_path + '/kernels')
for filename in ("vmlinuz", "initramfs", "modules.img"):
shutil.copy(os.path.join(kernels_dir, filename),
os.path.join(self.dir_path,
qubes.config.vm_files["kernels_subdir"], filename))
os.path.join(self.storage.kernels_dir, filename))
self.log.info('Creating icon symlink: {} -> {}'.format(
self.icon_path, self.label.icon_path))
@ -1556,6 +1536,7 @@ class QubesVM(qubes.vm.BaseVM):
return qubes.utils.get_disk_usage(self.dir_path)
# TODO move to storage
def verify_files(self):
'''Verify that files accessed by this machine are sane.
@ -1564,14 +1545,16 @@ class QubesVM(qubes.vm.BaseVM):
self.storage.verify_files()
if not os.path.exists(os.path.join(self.kernels_dir, 'vmlinuz')):
if not os.path.exists(
os.path.join(self.storage.kernels_dir, 'vmlinuz')):
raise qubes.QubesException('VM kernel does not exist: {0}'.format(
os.path.join(self.kernels_dir, 'vmlinuz')))
os.path.join(self.storage.kernels_dir, 'vmlinuz')))
if not os.path.exists(os.path.join(self.kernels_dir, 'initramfs')):
if not os.path.exists(
os.path.join(self.storage.kernels_dir, 'initramfs')):
raise qubes.QubesException(
'VM initramfs does not exist: {0}'.format(
os.path.join(self.kernels_dir, 'initramfs')))
os.path.join(self.storage.kernels_dir, 'initramfs')))
self.fire_event('verify-files')

View File

@ -9,6 +9,7 @@
<loader>hvmloader</loader>
<boot dev='cdrom'/>
<boot dev='hd'/>
<!-- server_ip is the address of stubdomain. It hosts it's own DNS server. -->
{disable_network1}<cmdline>-net lwip,client_ip={ip},server_ip={dns2},dns={dns1},gw={gateway},netmask={netmask}</cmdline>{disable_network2}
</os>
<features>