mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-24 07:26:29 +00:00
37 lines
1.3 KiB
Python
37 lines
1.3 KiB
Python
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):
|
|
self.partitions = []
|
|
if 'boot' in data:
|
|
self.boot = MBRPartition(data['boot']['size'], data['boot']['filesystem'], None)
|
|
self.partitions.append(self.boot)
|
|
self.root = MBRPartition(data['root']['size'], data['root']['filesystem'],
|
|
getattr(self, 'boot', None))
|
|
self.partitions.append(self.root)
|
|
if 'swap' in data:
|
|
self.swap = MBRSwapPartition(data['swap']['size'], self.root)
|
|
self.partitions.append(self.swap)
|
|
|
|
super(MBRPartitionMap, self).__init__()
|
|
|
|
def get_total_size(self):
|
|
return sum(p.size for p in self.partitions) + 1 # Post-MBR gap for embedding grub
|
|
|
|
def _before_create(self, event):
|
|
volume = event.volume
|
|
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()
|
|
if hasattr(self, 'boot'):
|
|
boot_idx = self.boot.get_index()
|
|
log_check_call(['/sbin/parted', '--script', volume.device_path,
|
|
'--', 'set ' + str(boot_idx) + ' boot on'])
|