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

41 lines
1.4 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):
2014-01-19 01:02:29 +01:00
def __init__(self, data, bootloader):
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
2014-01-19 01:02:29 +01:00
if bootloader == 'grub':
from ..partitions.unformatted import UnformattedPartition
self.grub_boot = UnformattedPartition(2, last_partition())
self.grub_boot.flags.append('bios_grub')
self.partitions.append(self.grub_boot)
if 'boot' in data:
2014-01-19 01:02:29 +01:00
self.boot = GPTPartition(data['boot']['size'], data['boot']['filesystem'], 'boot', last_partition())
2013-10-05 20:41:05 +02:00
self.partitions.append(self.boot)
if 'swap' in data:
2013-11-30 14:33:22 +01:00
self.swap = GPTSwapPartition(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 = GPTPartition(data['root']['size'], data['root']['filesystem'], 'root', last_partition())
self.partitions.append(self.root)
2014-01-19 01:02:29 +01:00
if bootloader == 'extlinux':
getattr(self, 'boot', self.root).flags.append('legacy_boot')
super(GPTPartitionMap, self).__init__(bootloader)
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)