2014-03-23 23:12:07 +01:00
|
|
|
from bootstrapvz.base import Task
|
|
|
|
from .. import phases
|
|
|
|
from ..tools import log_check_call
|
2014-02-23 22:03:13 +01:00
|
|
|
import apt
|
2014-03-23 23:12:07 +01:00
|
|
|
import bootstrap
|
2014-02-23 22:03:13 +01:00
|
|
|
import host
|
2013-09-15 13:19:45 +02:00
|
|
|
import volume
|
2013-06-27 00:11:09 +02:00
|
|
|
|
|
|
|
|
2014-02-23 22:03:13 +01:00
|
|
|
class AddRequiredCommands(Task):
|
2014-04-08 22:04:29 +02:00
|
|
|
description = 'Adding commands required for formatting'
|
2014-02-23 22:03:13 +01:00
|
|
|
phase = phases.preparation
|
|
|
|
successors = [host.CheckExternalCommands]
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def run(cls, info):
|
|
|
|
if 'xfs' in (p.filesystem for p in info.volume.partition_map.partitions):
|
|
|
|
info.host_dependencies['mkfs.xfs'] = 'xfsprogs'
|
|
|
|
|
|
|
|
|
2013-09-15 13:19:45 +02:00
|
|
|
class Format(Task):
|
2013-06-27 00:11:09 +02:00
|
|
|
description = 'Formatting the volume'
|
|
|
|
phase = phases.volume_preparation
|
|
|
|
|
2014-01-05 15:57:11 +01:00
|
|
|
@classmethod
|
|
|
|
def run(cls, info):
|
2014-03-23 23:53:20 +01:00
|
|
|
from bootstrapvz.base.fs.partitions.unformatted import UnformattedPartition
|
2013-09-22 21:20:09 +02:00
|
|
|
for partition in info.volume.partition_map.partitions:
|
2015-01-19 23:11:19 +01:00
|
|
|
if isinstance(partition, UnformattedPartition):
|
2015-01-01 21:09:16 +01:00
|
|
|
continue
|
|
|
|
partition.format()
|
2013-06-27 00:11:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
class TuneVolumeFS(Task):
|
|
|
|
description = 'Tuning the bootstrap volume filesystem'
|
|
|
|
phase = phases.volume_preparation
|
2013-11-21 15:54:42 +01:00
|
|
|
predecessors = [Format]
|
2013-06-27 00:11:09 +02:00
|
|
|
|
2014-01-05 15:57:11 +01:00
|
|
|
@classmethod
|
|
|
|
def run(cls, info):
|
2014-03-23 23:53:20 +01:00
|
|
|
from bootstrapvz.base.fs.partitions.unformatted import UnformattedPartition
|
2013-09-15 13:19:45 +02:00
|
|
|
import re
|
2013-06-27 22:00:01 +02:00
|
|
|
# Disable the time based filesystem check
|
2013-09-15 13:19:45 +02:00
|
|
|
for partition in info.volume.partition_map.partitions:
|
2015-01-19 23:11:19 +01:00
|
|
|
if isinstance(partition, UnformattedPartition):
|
2015-01-01 21:09:16 +01:00
|
|
|
continue
|
|
|
|
if re.match('^ext[2-4]$', partition.filesystem) is not None:
|
|
|
|
log_check_call(['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
|
2013-12-29 18:11:48 +01:00
|
|
|
predecessors = [apt.AddDefaultSources]
|
2013-06-27 00:11:09 +02:00
|
|
|
|
2014-01-05 15:57:11 +01:00
|
|
|
@classmethod
|
|
|
|
def run(cls, info):
|
2013-12-29 16:09:47 +01:00
|
|
|
info.packages.add('xfsprogs')
|
2013-06-27 22:00:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
class CreateMountDir(Task):
|
2013-09-15 13:19:45 +02:00
|
|
|
description = 'Creating mountpoint for the root partition'
|
2013-06-27 22:00:01 +02:00
|
|
|
phase = phases.volume_mounting
|
|
|
|
|
2014-01-05 15:57:11 +01:00
|
|
|
@classmethod
|
|
|
|
def run(cls, info):
|
2013-07-01 22:06:42 +02:00
|
|
|
import os
|
2013-09-15 16:59:56 +02:00
|
|
|
info.root = os.path.join(info.workspace, 'root')
|
2013-06-27 22:00:01 +02:00
|
|
|
os.makedirs(info.root)
|
|
|
|
|
|
|
|
|
2013-09-15 13:19:45 +02:00
|
|
|
class MountRoot(Task):
|
|
|
|
description = 'Mounting the root partition'
|
2013-06-27 22:00:01 +02:00
|
|
|
phase = phases.volume_mounting
|
2013-11-21 15:54:42 +01:00
|
|
|
predecessors = [CreateMountDir]
|
2013-06-27 22:00:01 +02:00
|
|
|
|
2014-01-05 15:57:11 +01:00
|
|
|
@classmethod
|
|
|
|
def run(cls, info):
|
2014-01-19 01:02:29 +01:00
|
|
|
info.volume.partition_map.root.mount(destination=info.root)
|
2013-06-27 22:00:01 +02:00
|
|
|
|
2013-09-15 13:19:45 +02:00
|
|
|
|
2013-11-27 18:06:45 +01:00
|
|
|
class CreateBootMountDir(Task):
|
|
|
|
description = 'Creating mountpoint for the boot partition'
|
2013-09-15 13:19:45 +02:00
|
|
|
phase = phases.volume_mounting
|
2013-11-21 15:54:42 +01:00
|
|
|
predecessors = [MountRoot]
|
2013-09-15 13:19:45 +02:00
|
|
|
|
2014-01-05 15:57:11 +01:00
|
|
|
@classmethod
|
|
|
|
def run(cls, info):
|
2013-11-27 18:06:45 +01:00
|
|
|
import os.path
|
|
|
|
os.makedirs(os.path.join(info.root, 'boot'))
|
2013-09-15 13:19:45 +02:00
|
|
|
|
|
|
|
|
2013-11-27 18:06:45 +01:00
|
|
|
class MountBoot(Task):
|
|
|
|
description = 'Mounting the boot partition'
|
2013-09-15 13:19:45 +02:00
|
|
|
phase = phases.volume_mounting
|
2013-11-27 18:06:45 +01:00
|
|
|
predecessors = [CreateBootMountDir]
|
2013-09-15 13:19:45 +02:00
|
|
|
|
2014-01-05 15:57:11 +01:00
|
|
|
@classmethod
|
|
|
|
def run(cls, info):
|
2013-11-27 18:06:45 +01:00
|
|
|
p_map = info.volume.partition_map
|
|
|
|
p_map.root.add_mount(p_map.boot, 'boot')
|
2013-06-27 22:21:43 +02:00
|
|
|
|
|
|
|
|
2013-07-01 20:48:51 +02:00
|
|
|
class MountSpecials(Task):
|
|
|
|
description = 'Mounting special block devices'
|
|
|
|
phase = phases.os_installation
|
2014-03-23 23:12:07 +01:00
|
|
|
predecessors = [bootstrap.Bootstrap]
|
2013-07-01 20:48:51 +02:00
|
|
|
|
2014-01-05 15:57:11 +01:00
|
|
|
@classmethod
|
|
|
|
def run(cls, info):
|
2013-11-27 18:06:45 +01:00
|
|
|
root = info.volume.partition_map.root
|
|
|
|
root.add_mount('/dev', 'dev', ['--bind'])
|
|
|
|
root.add_mount('none', 'proc', ['--types', 'proc'])
|
|
|
|
root.add_mount('none', 'sys', ['--types', 'sysfs'])
|
|
|
|
root.add_mount('none', 'dev/pts', ['--types', 'devpts'])
|
2013-07-01 20:48:51 +02:00
|
|
|
|
|
|
|
|
2013-09-15 13:19:45 +02:00
|
|
|
class UnmountRoot(Task):
|
|
|
|
description = 'Unmounting the bootstrap volume'
|
2013-07-01 20:48:51 +02:00
|
|
|
phase = phases.volume_unmounting
|
2013-11-21 15:54:42 +01:00
|
|
|
successors = [volume.Detach]
|
2013-07-01 20:48:51 +02:00
|
|
|
|
2014-01-05 15:57:11 +01:00
|
|
|
@classmethod
|
|
|
|
def run(cls, info):
|
2013-09-22 21:20:09 +02:00
|
|
|
info.volume.partition_map.root.unmount()
|
2013-07-01 20:48:51 +02:00
|
|
|
|
|
|
|
|
2013-06-27 22:21:43 +02:00
|
|
|
class DeleteMountDir(Task):
|
|
|
|
description = 'Deleting mountpoint for the bootstrap volume'
|
|
|
|
phase = phases.volume_unmounting
|
2013-11-21 15:54:42 +01:00
|
|
|
predecessors = [UnmountRoot]
|
2013-06-27 22:21:43 +02:00
|
|
|
|
2014-01-05 15:57:11 +01:00
|
|
|
@classmethod
|
|
|
|
def run(cls, info):
|
2013-07-01 22:06:42 +02:00
|
|
|
import os
|
2013-06-27 22:21:43 +02:00
|
|
|
os.rmdir(info.root)
|
|
|
|
del info.root
|
2013-07-07 13:02:04 +02:00
|
|
|
|
|
|
|
|
2013-09-15 13:19:45 +02:00
|
|
|
class FStab(Task):
|
|
|
|
description = 'Adding partitions to the fstab'
|
2013-07-07 13:02:04 +02:00
|
|
|
phase = phases.system_modification
|
|
|
|
|
2014-01-05 15:57:11 +01:00
|
|
|
@classmethod
|
|
|
|
def run(cls, info):
|
2013-07-07 13:02:04 +02:00
|
|
|
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': '/',
|
2014-04-27 11:05:53 -03:00
|
|
|
'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
|
|
|
|
2013-09-15 13:19:45 +02:00
|
|
|
fstab_lines = []
|
2013-10-06 13:40:27 +02:00
|
|
|
for mount_point in mount_points:
|
|
|
|
partition = mount_point['partition']
|
2013-09-15 13:19:45 +02:00
|
|
|
mount_opts = ['defaults']
|
2013-10-06 13:40:27 +02:00
|
|
|
fstab_lines.append('UUID={uuid} {mountpoint} {filesystem} {mount_opts} {dump} {pass_num}'
|
2013-09-15 13:19:45 +02:00
|
|
|
.format(uuid=partition.get_uuid(),
|
2013-10-06 13:40:27 +02:00
|
|
|
mountpoint=mount_point['path'],
|
2013-09-15 13:19:45 +02:00
|
|
|
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']))
|
2013-08-10 20:03:20 +02:00
|
|
|
|
2013-09-15 13:19:45 +02:00
|
|
|
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')
|