2014-11-29 13:46:57 -08:00
|
|
|
from bootstrapvz.base import Task
|
|
|
|
from .. import phases
|
|
|
|
from ..tasks import packages
|
2015-01-16 01:53:35 +01:00
|
|
|
import logging
|
2014-11-29 13:46:57 -08:00
|
|
|
|
|
|
|
|
|
|
|
class AddDKMSPackages(Task):
|
|
|
|
description = 'Adding DKMS and kernel header packages'
|
|
|
|
phase = phases.package_installation
|
|
|
|
successors = [packages.InstallPackages]
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def run(cls, info):
|
|
|
|
info.packages.add('dkms')
|
|
|
|
kernel_pkg_arch = {'i386': '686-pae', 'amd64': 'amd64'}[info.manifest.system['architecture']]
|
|
|
|
info.packages.add('linux-headers-' + kernel_pkg_arch)
|
|
|
|
|
|
|
|
|
|
|
|
class UpdateInitramfs(Task):
|
|
|
|
description = 'Rebuilding initramfs'
|
|
|
|
phase = phases.system_modification
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def run(cls, info):
|
|
|
|
from bootstrapvz.common.tools import log_check_call
|
2015-01-16 01:53:35 +01:00
|
|
|
# Update initramfs (-u) for all currently installed kernel versions (-k all)
|
2014-11-29 13:46:57 -08:00
|
|
|
log_check_call(['chroot', info.root, 'update-initramfs', '-u', '-k', 'all'])
|
2015-01-16 01:53:35 +01:00
|
|
|
|
|
|
|
|
|
|
|
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<version>.+)$')
|
|
|
|
|
|
|
|
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))
|