diff --git a/bootstrapvz/common/task_groups.py b/bootstrapvz/common/task_groups.py index d6370d0..f5b3592 100644 --- a/bootstrapvz/common/task_groups.py +++ b/bootstrapvz/common/task_groups.py @@ -15,6 +15,7 @@ from tasks import locale from tasks import network from tasks import initd from tasks import ssh +from tasks import kernel def get_standard_groups(manifest): @@ -26,6 +27,7 @@ def get_standard_groups(manifest): if 'boot' in manifest.volume['partitions']: group.extend(boot_partition_group) group.extend(mounting_group) + group.extend(kernel_group) group.extend(get_fs_specific_group(manifest)) group.extend(get_network_group(manifest)) group.extend(get_apt_group(manifest)) @@ -76,6 +78,9 @@ mounting_group = [filesystem.CreateMountDir, filesystem.DeleteMountDir, ] +kernel_group = [kernel.DetermineKernelVersion, + ] + ssh_group = [ssh.AddOpenSSHPackage, ssh.DisableSSHPasswordAuthentication, ssh.DisableSSHDNSLookup, diff --git a/bootstrapvz/common/tasks/kernel.py b/bootstrapvz/common/tasks/kernel.py index be978f7..5acecf6 100644 --- a/bootstrapvz/common/tasks/kernel.py +++ b/bootstrapvz/common/tasks/kernel.py @@ -1,6 +1,7 @@ from bootstrapvz.base import Task from .. import phases from ..tasks import packages +import logging class AddDKMSPackages(Task): @@ -22,5 +23,30 @@ class UpdateInitramfs(Task): @classmethod def run(cls, info): from bootstrapvz.common.tools import log_check_call - # Update initramfs (-u) for all currently installed kernel versions (-k all) + # Update initramfs (-u) for all currently installed kernel versions (-k all) log_check_call(['chroot', info.root, 'update-initramfs', '-u', '-k', 'all']) + + +class DetermineKernelVersion(Task): + description = 'Determining kernel version' + phase = phases.package_installation + predecessors = [packages.InstallPackages] + + @classmethod + def run(cls, info): + # Snatched from `extlinux-update' in wheezy + # list the files in boot/ that match vmlinuz-* + # sort what the * matches, the first entry is the kernel version + import os.path + import re + regexp = re.compile('^vmlinuz-(?P.+)$') + + def get_kernel_version(vmlinuz_path): + vmlinux_basename = os.path.basename(vmlinuz_path) + return regexp.match(vmlinux_basename).group('version') + from glob import glob + boot = os.path.join(info.root, 'boot') + vmlinuz_paths = glob('{boot}/vmlinuz-*'.format(boot=boot)) + kernels = map(get_kernel_version, vmlinuz_paths) + info.kernel_version = sorted(kernels, reverse=True)[0] + logging.getLogger(__name__).debug('Kernel version is {version}'.format(version=info.kernel_version))