2013-08-10 20:03:20 +02:00
|
|
|
from base import Task
|
|
|
|
from common import phases
|
|
|
|
from common.tools import log_check_call
|
|
|
|
from common.tasks import UnmountVolume
|
|
|
|
|
|
|
|
|
|
|
|
class PartitionVolume(Task):
|
|
|
|
description = 'Partitioning the volume'
|
|
|
|
phase = phases.volume_preparation
|
|
|
|
|
|
|
|
def run(self, info):
|
|
|
|
# parted
|
|
|
|
log_check_call(['parted', '-a', 'optimal',
|
|
|
|
'-s', info.bootstrap_device['path'],
|
|
|
|
'mklabel', 'msdos'])
|
|
|
|
log_check_call(['parted', '-a', 'optimal',
|
|
|
|
'-s', info.bootstrap_device['path'],
|
|
|
|
'--', 'mkpart', 'primary', 'ext4', '32k', '-1'])
|
|
|
|
log_check_call(['parted',
|
|
|
|
'-s', info.bootstrap_device['path'],
|
|
|
|
'--', 'set', '1', 'boot', 'on'])
|
|
|
|
|
|
|
|
|
|
|
|
class MapPartitions(Task):
|
|
|
|
description = 'Mapping volume partitions'
|
|
|
|
phase = phases.volume_preparation
|
2013-08-10 23:02:16 +02:00
|
|
|
after = [PartitionVolume]
|
2013-08-10 20:03:20 +02:00
|
|
|
|
|
|
|
def run(self, info):
|
|
|
|
log_check_call(['kpartx', '-a', '-v', info.bootstrap_device['path']])
|
|
|
|
root_partition_path = info.bootstrap_device['path'].replace('/dev', '/dev/mapper')+'p1'
|
|
|
|
info.bootstrap_device['partitions'] = {'root_path': root_partition_path}
|
|
|
|
|
|
|
|
|
|
|
|
class FormatPartitions(Task):
|
|
|
|
description = 'Formatting the partitions'
|
|
|
|
phase = phases.volume_preparation
|
|
|
|
after = [MapPartitions]
|
|
|
|
|
|
|
|
def run(self, info):
|
|
|
|
log_check_call(['/sbin/mkfs.{fs}'.format(fs=info.manifest.volume['filesystem']),
|
|
|
|
'-m', '1', '-v', info.bootstrap_device['partitions']['root_path']])
|
|
|
|
|
|
|
|
|
|
|
|
class UnmapPartitions(Task):
|
|
|
|
description = 'Removing volume partitions mapping'
|
|
|
|
phase = phases.volume_unmounting
|
|
|
|
after = [UnmountVolume]
|
|
|
|
|
|
|
|
def run(self, info):
|
|
|
|
log_check_call(['kpartx', '-d', info.loopback_file])
|
|
|
|
del info.bootstrap_device['partitions']['root_path']
|