Commit 26bab2b0 authored by Samir Noir's avatar Samir Noir 🧀

Correctly set the kernel to use when creating Debian images

It can happen that after the initial upgrade, a kernel upgrade occures.
In such case, the links /{vmlinuz,/initrd.img} point to the "old" kernel
version. Also, the Nvidia driver is compiled for the currently running
kernel.
Now, the last kernel while be used to correct both cases.
parent 98aa56d6
Facter.add(:installed_kernelreleases) do
setcode do
kernels = Dir.glob('/boot/{vmlinuz,vmlinux}-*')
kernels.sort_by! do |k|
m = /^\/boot\/vmlinu[zx]-(\d+)\.(\d+)\.(\d+)(_|-)(\d+).*$/.match(k)
[m[1].to_i, m[2].to_i, m[3].to_i, m[5].to_i]
end
kernels.map { |k| k.gsub(/\/boot\/vmlinu[zx]-(\d+\.\d+\.\d+(_|-)\d+.*)/, '\1') }
end
end
...@@ -29,7 +29,7 @@ class env::big::configure_nvidia_gpu::drivers () { ...@@ -29,7 +29,7 @@ class env::big::configure_nvidia_gpu::drivers () {
user => root, user => root,
require => Package['module-assistant']; require => Package['module-assistant'];
'install_nvidia_driver': 'install_nvidia_driver':
command => "/tmp/NVIDIA-Linux.run -qa --no-cc-version-check --ui=none --dkms; /bin/rm /tmp/NVIDIA-Linux.run", command => "/tmp/NVIDIA-Linux.run -qa --no-cc-version-check --ui=none --dkms -k ${installed_kernelreleases[-1]}; /bin/rm /tmp/NVIDIA-Linux.run",
timeout => 1200, # 20 min, timeout => 1200, # 20 min,
user => root, user => root,
require => [Exec['prepare_kernel_module_build'], File['/tmp/NVIDIA-Linux.run'], Package['dkms']]; require => [Exec['prepare_kernel_module_build'], File['/tmp/NVIDIA-Linux.run'], Package['dkms']];
......
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
class env::min ( $variant = "min", $parent_parameters = {} ) { class env::min ( $variant = "min", $parent_parameters = {} ) {
stage { 'last':
require => Stage['main'],
}
$min_parameters = { $min_parameters = {
misc_root_pwd => '$1$qzZwnZXQ$Ak1xs7Oma6HUHw/xDJ8q91', misc_root_pwd => '$1$qzZwnZXQ$Ak1xs7Oma6HUHw/xDJ8q91',
} }
......
...@@ -11,4 +11,8 @@ class env::min::configure_kernel_and_blacklist_some_modules { ...@@ -11,4 +11,8 @@ class env::min::configure_kernel_and_blacklist_some_modules {
# initramfs regeneration declaration # initramfs regeneration declaration
include env::min::kernel::initramfs include env::min::kernel::initramfs
# Remove old kernel if exist: it can happen that the running kernel (the installer's one) is not the most recent (installed after upgrade)
class { 'env::min::kernel::remove_old':
stage => last,
}
} }
class env::min::kernel::remove_old {
# Remove the current kernel if it's not the last one
if $kernelrelease != $installed_kernelreleases[-1] {
package { "linux-image-$kernelrelease":
ensure => 'purged'
}
file {
"/lib/modules/$kernelrelease":
ensure => absent,
force => true;
"/usr/lib/modules/$kernelrelease":
ensure => absent,
force => true;
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment