2013-08-10 20:03:20 +02:00
|
|
|
from base import Task
|
|
|
|
from common import phases
|
|
|
|
from common.tools import log_check_call
|
2013-08-11 18:33:35 +02:00
|
|
|
import filesystem
|
2013-08-11 23:03:44 +02:00
|
|
|
import loopback
|
2013-08-10 20:03:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
class PartitionVolume(Task):
|
|
|
|
description = 'Partitioning the volume'
|
|
|
|
phase = phases.volume_preparation
|
|
|
|
|
|
|
|
def run(self, info):
|
|
|
|
# parted
|
2013-08-11 23:03:44 +02:00
|
|
|
log_check_call(['parted', '-a', 'optimal', '-s', info.bootstrap_device['path'],
|
|
|
|
'--', 'mklabel', 'msdos'])
|
|
|
|
log_check_call(['parted', '-a', 'optimal', '-s', info.bootstrap_device['path'],
|
2013-08-10 20:03:20 +02:00
|
|
|
'--', 'mkpart', 'primary', 'ext4', '32k', '-1'])
|
2013-08-11 23:03:44 +02:00
|
|
|
log_check_call(['parted', '-s', info.bootstrap_device['path'],
|
2013-08-10 20:03:20 +02:00
|
|
|
'--', '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'
|
2013-08-11 23:03:44 +02:00
|
|
|
|
|
|
|
[root_loopback_path] = log_check_call(['/sbin/losetup', '--find'])
|
|
|
|
log_check_call(['/sbin/losetup', root_loopback_path, root_partition_path])
|
|
|
|
|
|
|
|
info.bootstrap_device['partitions'] = {'root_path': root_loopback_path}
|
2013-08-10 20:03:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
class FormatPartitions(Task):
|
|
|
|
description = 'Formatting the partitions'
|
|
|
|
phase = phases.volume_preparation
|
2013-08-11 18:33:35 +02:00
|
|
|
before = [filesystem.TuneVolumeFS]
|
2013-08-10 20:03:20 +02:00
|
|
|
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
|
2013-08-11 23:03:44 +02:00
|
|
|
before = [loopback.Detach]
|
2013-08-11 18:33:35 +02:00
|
|
|
after = [filesystem.UnmountVolume]
|
2013-08-10 20:03:20 +02:00
|
|
|
|
|
|
|
def run(self, info):
|
2013-08-11 23:03:44 +02:00
|
|
|
log_check_call(['/sbin/losetup', '-d', info.bootstrap_device['partitions']['root_path']])
|
2013-08-10 20:03:20 +02:00
|
|
|
del info.bootstrap_device['partitions']['root_path']
|
2013-08-11 23:03:44 +02:00
|
|
|
|
|
|
|
log_check_call(['kpartx', '-d', info.bootstrap_device['path']])
|