2013-09-18 00:46:58 +02:00
|
|
|
from abstract import AbstractPartitionMap
|
|
|
|
from ..partitions.mbr import MBRPartition
|
|
|
|
from ..partitions.mbr_swap import MBRSwapPartition
|
|
|
|
from common.tools import log_check_call
|
|
|
|
|
|
|
|
|
|
|
|
class MBRPartitionMap(AbstractPartitionMap):
|
|
|
|
|
|
|
|
def __init__(self, data):
|
2013-10-05 20:41:05 +02:00
|
|
|
self.partitions = []
|
2013-11-30 14:33:22 +01:00
|
|
|
|
|
|
|
def last_partition():
|
|
|
|
return self.partitions[-1] if len(self.partitions) > 0 else None
|
2013-09-18 00:46:58 +02:00
|
|
|
if 'boot' in data:
|
|
|
|
self.boot = MBRPartition(data['boot']['size'], data['boot']['filesystem'], None)
|
2013-10-05 20:41:05 +02:00
|
|
|
self.partitions.append(self.boot)
|
2013-09-18 00:46:58 +02:00
|
|
|
if 'swap' in data:
|
2013-11-30 14:33:22 +01:00
|
|
|
self.swap = MBRSwapPartition(data['swap']['size'], last_partition())
|
2013-10-05 20:41:05 +02:00
|
|
|
self.partitions.append(self.swap)
|
2013-11-30 14:33:22 +01:00
|
|
|
self.root = MBRPartition(data['root']['size'], data['root']['filesystem'], last_partition())
|
|
|
|
self.partitions.append(self.root)
|
2013-09-18 00:46:58 +02:00
|
|
|
|
2013-09-22 21:20:09 +02:00
|
|
|
super(MBRPartitionMap, self).__init__()
|
|
|
|
|
2013-10-08 23:12:03 +02:00
|
|
|
def get_total_size(self):
|
|
|
|
return sum(p.size for p in self.partitions) + 1 # Post-MBR gap for embedding grub
|
|
|
|
|
2013-09-22 21:20:09 +02:00
|
|
|
def _before_create(self, event):
|
|
|
|
volume = event.volume
|
2013-09-18 00:46:58 +02:00
|
|
|
log_check_call(['/sbin/parted', '--script', '--align', 'none', volume.device_path,
|
|
|
|
'--', 'mklabel', 'msdos'])
|
|
|
|
for partition in self.partitions:
|
|
|
|
partition.create(volume)
|
|
|
|
|
|
|
|
boot_idx = self.root.get_index()
|
2013-10-05 20:41:05 +02:00
|
|
|
if hasattr(self, 'boot'):
|
2013-09-18 00:46:58 +02:00
|
|
|
boot_idx = self.boot.get_index()
|
|
|
|
log_check_call(['/sbin/parted', '--script', volume.device_path,
|
|
|
|
'--', 'set ' + str(boot_idx) + ' boot on'])
|