bootstrap-vz/base/fs/partitionmaps/gpt.py

37 lines
1.3 KiB
Python
Raw Normal View History

from abstract import AbstractPartitionMap
from ..partitions.gpt import GPTPartition
from ..partitions.gpt_swap import GPTSwapPartition
from common.tools import log_check_call
class GPTPartitionMap(AbstractPartitionMap):
def __init__(self, data):
2013-10-05 20:41:05 +02:00
self.partitions = []
if 'boot' in data:
self.boot = GPTPartition(data['boot']['size'], data['boot']['filesystem'], 'boot', None)
2013-10-05 20:41:05 +02:00
self.partitions.append(self.boot)
self.root = GPTPartition(data['root']['size'], data['root']['filesystem'], 'root',
getattr(self, 'boot', None))
2013-10-05 20:41:05 +02:00
self.partitions.append(self.root)
if 'swap' in data:
self.swap = GPTSwapPartition(data['swap']['size'], self.root)
2013-10-05 20:41:05 +02:00
self.partitions.append(self.swap)
super(GPTPartitionMap, self).__init__()
2013-09-25 23:27:31 +02:00
def _before_create(self, event):
volume = event.volume
log_check_call(['/sbin/parted', '--script', '--align', 'none', volume.device_path,
'--', 'mklabel', 'gpt'])
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'):
boot_idx = self.boot.get_index()
log_check_call(['/sbin/parted', '--script', volume.device_path,
'--', 'set ' + str(boot_idx) + ' boot on'])
2013-09-25 23:27:31 +02:00
log_check_call(['/sbin/parted', '--script', volume.device_path,
'--', 'set ' + str(boot_idx) + ' bios_grub on'])