mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-10-10 17:19:51 +00:00
Partitioning fixes
This commit is contained in:
parent
c78866f103
commit
6ddd8809a3
8 changed files with 18 additions and 22 deletions
|
@ -70,7 +70,7 @@ class AbstractPartitionMap(FSMProxy):
|
||||||
def _before_unmap(self, event):
|
def _before_unmap(self, event):
|
||||||
volume = event.volume
|
volume = event.volume
|
||||||
for partition in self.partitions:
|
for partition in self.partitions:
|
||||||
if partition.is_blocking():
|
if partition.is_state('mounted'):
|
||||||
msg = 'The partition {partition} prevents the unmap procedure'.format(partition=partition)
|
msg = 'The partition {partition} prevents the unmap procedure'.format(partition=partition)
|
||||||
raise PartitionError(msg)
|
raise PartitionError(msg)
|
||||||
log_check_call(['/sbin/kpartx', '-d', volume.device_path])
|
log_check_call(['/sbin/kpartx', '-d', volume.device_path])
|
||||||
|
|
|
@ -7,14 +7,15 @@ from common.tools import log_check_call
|
||||||
class GPTPartitionMap(AbstractPartitionMap):
|
class GPTPartitionMap(AbstractPartitionMap):
|
||||||
|
|
||||||
def __init__(self, data):
|
def __init__(self, data):
|
||||||
self.boot = None
|
self.partitions = []
|
||||||
self.swap = None
|
|
||||||
if 'boot' in data:
|
if 'boot' in data:
|
||||||
self.boot = GPTPartition(data['boot']['size'], data['boot']['filesystem'], 'boot', None)
|
self.boot = GPTPartition(data['boot']['size'], data['boot']['filesystem'], 'boot', None)
|
||||||
|
self.partitions.append(self.boot)
|
||||||
self.root = GPTPartition(data['root']['size'], data['root']['filesystem'], 'root', self.boot)
|
self.root = GPTPartition(data['root']['size'], data['root']['filesystem'], 'root', self.boot)
|
||||||
|
self.partitions.append(self.root)
|
||||||
if 'swap' in data:
|
if 'swap' in data:
|
||||||
self.swap = GPTSwapPartition(data['swap']['size'], self.root)
|
self.swap = GPTSwapPartition(data['swap']['size'], self.root)
|
||||||
self.partitions = filter(lambda p: p is not None, [self.boot, self.root, self.swap])
|
self.partitions.append(self.swap)
|
||||||
|
|
||||||
super(GPTPartitionMap, self).__init__()
|
super(GPTPartitionMap, self).__init__()
|
||||||
|
|
||||||
|
@ -26,7 +27,7 @@ class GPTPartitionMap(AbstractPartitionMap):
|
||||||
partition.create(volume)
|
partition.create(volume)
|
||||||
|
|
||||||
boot_idx = self.root.get_index()
|
boot_idx = self.root.get_index()
|
||||||
if self.boot is not None:
|
if hasattr(self, 'boot'):
|
||||||
boot_idx = self.boot.get_index()
|
boot_idx = self.boot.get_index()
|
||||||
log_check_call(['/sbin/parted', '--script', volume.device_path,
|
log_check_call(['/sbin/parted', '--script', volume.device_path,
|
||||||
'--', 'set ' + str(boot_idx) + ' boot on'])
|
'--', 'set ' + str(boot_idx) + ' boot on'])
|
||||||
|
|
|
@ -7,14 +7,15 @@ from common.tools import log_check_call
|
||||||
class MBRPartitionMap(AbstractPartitionMap):
|
class MBRPartitionMap(AbstractPartitionMap):
|
||||||
|
|
||||||
def __init__(self, data):
|
def __init__(self, data):
|
||||||
self.boot = None
|
self.partitions = []
|
||||||
self.swap = None
|
|
||||||
if 'boot' in data:
|
if 'boot' in data:
|
||||||
self.boot = MBRPartition(data['boot']['size'], data['boot']['filesystem'], None)
|
self.boot = MBRPartition(data['boot']['size'], data['boot']['filesystem'], None)
|
||||||
|
self.partitions.append(self.boot)
|
||||||
self.root = MBRPartition(data['root']['size'], data['root']['filesystem'], self.boot)
|
self.root = MBRPartition(data['root']['size'], data['root']['filesystem'], self.boot)
|
||||||
|
self.partitions.append(self.root)
|
||||||
if 'swap' in data:
|
if 'swap' in data:
|
||||||
self.swap = MBRSwapPartition(data['swap']['size'], self.root)
|
self.swap = MBRSwapPartition(data['swap']['size'], self.root)
|
||||||
self.partitions = filter(lambda p: p is not None, [self.boot, self.root, self.swap])
|
self.partitions.append(self.swap)
|
||||||
|
|
||||||
super(MBRPartitionMap, self).__init__()
|
super(MBRPartitionMap, self).__init__()
|
||||||
|
|
||||||
|
@ -26,7 +27,7 @@ class MBRPartitionMap(AbstractPartitionMap):
|
||||||
partition.create(volume)
|
partition.create(volume)
|
||||||
|
|
||||||
boot_idx = self.root.get_index()
|
boot_idx = self.root.get_index()
|
||||||
if self.boot is not None:
|
if hasattr(self, 'boot'):
|
||||||
boot_idx = self.boot.get_index()
|
boot_idx = self.boot.get_index()
|
||||||
log_check_call(['/sbin/parted', '--script', volume.device_path,
|
log_check_call(['/sbin/parted', '--script', volume.device_path,
|
||||||
'--', 'set ' + str(boot_idx) + ' boot on'])
|
'--', 'set ' + str(boot_idx) + ' boot on'])
|
||||||
|
|
|
@ -9,7 +9,7 @@ class NoPartitions(object):
|
||||||
self.partitions = [self.root]
|
self.partitions = [self.root]
|
||||||
|
|
||||||
def is_blocking(self):
|
def is_blocking(self):
|
||||||
return self.root.is_blocking()
|
return self.root.is_state('mounted')
|
||||||
|
|
||||||
def get_total_size(self):
|
def get_total_size(self):
|
||||||
return self.root.size
|
return self.root.size
|
||||||
|
|
|
@ -22,9 +22,6 @@ class AbstractPartition(FSMProxy):
|
||||||
cfg = {'initial': 'nonexistent', 'events': self.events, 'callbacks': {}}
|
cfg = {'initial': 'nonexistent', 'events': self.events, 'callbacks': {}}
|
||||||
super(AbstractPartition, self).__init__(cfg)
|
super(AbstractPartition, self).__init__(cfg)
|
||||||
|
|
||||||
def is_blocking(self):
|
|
||||||
return self.is_state('mounted')
|
|
||||||
|
|
||||||
def get_uuid(self):
|
def get_uuid(self):
|
||||||
[uuid] = log_check_call(['/sbin/blkid', '-s', 'UUID', '-o', 'value', self.device_path])
|
[uuid] = log_check_call(['/sbin/blkid', '-s', 'UUID', '-o', 'value', self.device_path])
|
||||||
return uuid
|
return uuid
|
||||||
|
|
|
@ -18,9 +18,6 @@ class BasePartition(AbstractPartition):
|
||||||
self.previous = previous
|
self.previous = previous
|
||||||
super(BasePartition, self).__init__(size, filesystem)
|
super(BasePartition, self).__init__(size, filesystem)
|
||||||
|
|
||||||
def is_blocking(self):
|
|
||||||
return self.get_state() in ['mapped', 'mounted', 'formatted']
|
|
||||||
|
|
||||||
def get_index(self):
|
def get_index(self):
|
||||||
if self.previous is None:
|
if self.previous is None:
|
||||||
return 1
|
return 1
|
||||||
|
|
|
@ -9,7 +9,7 @@ class PartitionVolume(Task):
|
||||||
phase = phases.volume_preparation
|
phase = phases.volume_preparation
|
||||||
|
|
||||||
def run(self, info):
|
def run(self, info):
|
||||||
info.volume.partition_map.create()
|
info.volume.partition_map.create(info.volume)
|
||||||
|
|
||||||
|
|
||||||
class MapPartitions(Task):
|
class MapPartitions(Task):
|
||||||
|
@ -19,7 +19,7 @@ class MapPartitions(Task):
|
||||||
after = [PartitionVolume]
|
after = [PartitionVolume]
|
||||||
|
|
||||||
def run(self, info):
|
def run(self, info):
|
||||||
info.volume.partition_map.map()
|
info.volume.partition_map.map(info.volume)
|
||||||
|
|
||||||
|
|
||||||
class UnmapPartitions(Task):
|
class UnmapPartitions(Task):
|
||||||
|
@ -29,4 +29,4 @@ class UnmapPartitions(Task):
|
||||||
after = [filesystem.UnmountRoot]
|
after = [filesystem.UnmountRoot]
|
||||||
|
|
||||||
def run(self, info):
|
def run(self, info):
|
||||||
info.volume.partition_map.unmap()
|
info.volume.partition_map.unmap(info.volume)
|
||||||
|
|
|
@ -30,9 +30,9 @@ class ConfigureGrub(Task):
|
||||||
p_map.boot.unmount()
|
p_map.boot.unmount()
|
||||||
p_map.root.unmount()
|
p_map.root.unmount()
|
||||||
if not isinstance(p_map, NoPartitions):
|
if not isinstance(p_map, NoPartitions):
|
||||||
p_map.unmap()
|
p_map.unmap(info.volume)
|
||||||
fn()
|
fn()
|
||||||
p_map.map()
|
p_map.map(info.volume)
|
||||||
else:
|
else:
|
||||||
fn()
|
fn()
|
||||||
p_map.root.device_path = info.volume.device_path
|
p_map.root.device_path = info.volume.device_path
|
||||||
|
@ -70,4 +70,4 @@ class ConfigureGrub(Task):
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
if isinstance(info.volume, LoopbackVolume):
|
if isinstance(info.volume, LoopbackVolume):
|
||||||
remount(info.volume, info.volume.unlink_dm_node)
|
remount(info.volume.unlink_dm_node)
|
||||||
|
|
Loading…
Add table
Reference in a new issue