bootstrap-vz/common/tasks/filesystem.py

167 lines
4.3 KiB
Python
Raw Normal View History

2013-06-27 00:11:09 +02:00
from base import Task
from common import phases
2013-07-01 22:06:42 +02:00
from common.tools import log_check_call
2013-08-11 18:00:19 +02:00
from bootstrap import Bootstrap
import volume
2013-06-27 00:11:09 +02:00
class Format(Task):
2013-06-27 00:11:09 +02:00
description = 'Formatting the volume'
phase = phases.volume_preparation
def run(self, info):
for partition in info.volume.partition_map.partitions:
partition.format()
2013-06-27 00:11:09 +02:00
class TuneVolumeFS(Task):
description = 'Tuning the bootstrap volume filesystem'
phase = phases.volume_preparation
predecessors = [Format]
2013-06-27 00:11:09 +02:00
def run(self, info):
import re
# Disable the time based filesystem check
for partition in info.volume.partition_map.partitions:
if re.match('^ext[2-4]$', partition.filesystem) is not None:
log_check_call(['/sbin/tune2fs', '-i', '0', partition.device_path])
2013-06-27 00:11:09 +02:00
class AddXFSProgs(Task):
description = 'Adding `xfsprogs\' to the image packages'
phase = phases.preparation
def run(self, info):
include, exclude = info.img_packages
include.add('xfsprogs')
class CreateMountDir(Task):
description = 'Creating mountpoint for the root partition'
phase = phases.volume_mounting
def run(self, info):
2013-07-01 22:06:42 +02:00
import os
info.root = os.path.join(info.workspace, 'root')
os.makedirs(info.root)
class MountRoot(Task):
description = 'Mounting the root partition'
phase = phases.volume_mounting
predecessors = [CreateMountDir]
def run(self, info):
info.volume.partition_map.root.mount(info.root)
class MountBoot(Task):
description = 'Mounting the boot partition'
phase = phases.volume_mounting
predecessors = [MountRoot]
def run(self, info):
info.volume.partition_map.boot.mount(info.boot_dir)
class CreateBootMountDir(Task):
description = 'Creating mountpoint for the boot partition'
phase = phases.volume_mounting
successors = [MountBoot]
predecessors = [MountRoot]
def run(self, info):
import os
info.boot_dir = os.path.join(info.root, 'boot')
os.makedirs(info.boot_dir)
2013-07-01 20:48:51 +02:00
class MountSpecials(Task):
description = 'Mounting special block devices'
phase = phases.os_installation
predecessors = [Bootstrap]
2013-07-01 20:48:51 +02:00
def run(self, info):
info.volume.mount_specials()
2013-07-01 20:48:51 +02:00
class UnmountRoot(Task):
description = 'Unmounting the bootstrap volume'
2013-07-01 20:48:51 +02:00
phase = phases.volume_unmounting
successors = [volume.Detach]
2013-07-01 20:48:51 +02:00
def run(self, info):
info.volume.partition_map.root.unmount()
2013-07-01 20:48:51 +02:00
class UnmountBoot(Task):
description = 'Unmounting the boot partition'
phase = phases.volume_unmounting
successors = [UnmountRoot]
def run(self, info):
info.volume.partition_map.boot.unmount()
class UnmountSpecials(Task):
description = 'Unmunting special block devices'
phase = phases.volume_unmounting
successors = [UnmountRoot]
def run(self, info):
info.volume.unmount_specials()
class DeleteMountDir(Task):
description = 'Deleting mountpoint for the bootstrap volume'
phase = phases.volume_unmounting
predecessors = [UnmountRoot]
def run(self, info):
2013-07-01 22:06:42 +02:00
import os
os.rmdir(info.root)
del info.root
2013-07-07 13:02:04 +02:00
class FStab(Task):
description = 'Adding partitions to the fstab'
2013-07-07 13:02:04 +02:00
phase = phases.system_modification
def run(self, info):
import os.path
2013-09-25 23:27:31 +02:00
p_map = info.volume.partition_map
2013-10-06 13:40:27 +02:00
mount_points = [{'path': '/',
'partition': p_map.root,
'dump': '1',
'pass_num': '1',
}]
2013-09-25 23:27:31 +02:00
if hasattr(p_map, 'boot'):
2013-10-06 13:40:27 +02:00
mount_points.append({'path': '/boot',
'partition': p_map.boot,
'dump': '1',
'pass_num': '2',
})
2013-09-25 23:27:31 +02:00
if hasattr(p_map, 'swap'):
2013-10-06 13:40:27 +02:00
mount_points.append({'path': 'none',
'partition': p_map.swap,
'dump': '1',
'pass_num': '0',
})
2013-09-25 23:27:31 +02:00
fstab_lines = []
2013-10-06 13:40:27 +02:00
for mount_point in mount_points:
partition = mount_point['partition']
mount_opts = ['defaults']
2013-10-06 13:40:27 +02:00
fstab_lines.append('UUID={uuid} {mountpoint} {filesystem} {mount_opts} {dump} {pass_num}'
.format(uuid=partition.get_uuid(),
2013-10-06 13:40:27 +02:00
mountpoint=mount_point['path'],
filesystem=partition.filesystem,
2013-10-06 13:40:27 +02:00
mount_opts=','.join(mount_opts),
dump=mount_point['dump'],
pass_num=mount_point['pass_num']))
fstab_path = os.path.join(info.root, 'etc/fstab')
with open(fstab_path, 'w') as fstab:
fstab.write('\n'.join(fstab_lines))
2013-10-06 00:46:54 +02:00
fstab.write('\n')