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

43 lines
1.5 KiB
Python
Raw Normal View History

from abstract import AbstractPartitionMap
from ..partitions.msdos import MSDOSPartition
from ..partitions.msdos_swap import MSDOSSwapPartition
from common.tools import log_check_call
class MSDOSPartitionMap(AbstractPartitionMap):
2014-01-19 01:02:29 +01:00
def __init__(self, data, bootloader):
from common.bytes import Bytes
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
if 'boot' in data:
2014-02-23 17:52:05 +01:00
self.boot = MSDOSPartition(Bytes(data['boot']['size']),
data['boot']['filesystem'], data['boot'].get('format_command', None),
last_partition())
2013-10-05 20:41:05 +02:00
self.partitions.append(self.boot)
if 'swap' in data:
self.swap = MSDOSSwapPartition(Bytes(data['swap']['size']), last_partition())
2013-10-05 20:41:05 +02:00
self.partitions.append(self.swap)
2014-02-23 17:52:05 +01:00
self.root = MSDOSPartition(Bytes(data['root']['size']),
data['root']['filesystem'], data['root'].get('format_command', None),
last_partition())
2013-11-30 14:33:22 +01:00
self.partitions.append(self.root)
2014-01-19 01:02:29 +01:00
getattr(self, 'boot', self.root).flags.append('boot')
if bootloader == 'grub':
self.partitions[0].offset = Bytes('2MiB')
self.partitions[0].size -= self.partitions[0].offset
2014-01-19 01:02:29 +01:00
super(MSDOSPartitionMap, self).__init__(bootloader)
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)