From: Tom Hughes Date: Thu, 27 Aug 2015 18:50:03 +0000 (+0100) Subject: Simplify kernel pinning X-Git-Url: https://git.openstreetmap.org./chef.git/commitdiff_plain/1df3edbee59a60ca0bd7005124c12e99205fd2d1 Simplify kernel pinning --- diff --git a/cookbooks/hardware/attributes/default.rb b/cookbooks/hardware/attributes/default.rb index 26f126abd..f80e6a528 100644 --- a/cookbooks/hardware/attributes/default.rb +++ b/cookbooks/hardware/attributes/default.rb @@ -1,6 +1,5 @@ default[:hardware][:modules] = %w(loop lp rtc) default[:hardware][:grub][:cmdline] = %w(nomodeset) -default[:hardware][:grub][:kernel] = :latest default[:hardware][:sensors] = {} if node[:dmi] && node[:dmi][:system] diff --git a/cookbooks/hardware/recipes/default.rb b/cookbooks/hardware/recipes/default.rb index 620c7d58b..d976e89dc 100644 --- a/cookbooks/hardware/recipes/default.rb +++ b/cookbooks/hardware/recipes/default.rb @@ -124,10 +124,18 @@ end # work (e.g: https://github.com/openstreetmap/operations/issues/45) then # ensure that we have the package installed. the grub template will # make sure that this is the default on boot. -unless node[:hardware][:grub][:kernel] == :latest - package "linux-image-#{node[:hardware][:grub][:kernel]}-generic" - package "linux-image-extra-#{node[:hardware][:grub][:kernel]}-generic" - package "linux-headers-#{node[:hardware][:grub][:kernel]}-generic" +if node[:hardware][:grub][:kernel] + kernel_version = node[:hardware][:grub][:kernel] + + package "linux-image-#{kernel_version}-generic" + package "linux-image-extra-#{kernel_version}-generic" + package "linux-headers-#{kernel_version}-generic" + + boot_device = IO.popen(["df", "/boot"]).readlines.last.split.first + boot_uuid = IO.popen(["blkid", "-o", "value", "-s", "UUID", boot_device]).readlines.first.chomp + grub_entry = "gnulinux-advanced-#{boot_uuid}>gnulinux-#{kernel_version}-advanced-#{boot_uuid}" +else + grub_entry = "0" end if File.exist?("/etc/default/grub") @@ -141,7 +149,7 @@ if File.exist?("/etc/default/grub") owner "root" group "root" mode 0644 - variables :unit => unit, :speed => speed + variables :unit => unit, :speed => speed, :entry => grub_entry notifies :run, "execute[update-grub]" end end diff --git a/cookbooks/hardware/templates/default/grub.erb b/cookbooks/hardware/templates/default/grub.erb index d69a870b9..3db559191 100644 --- a/cookbooks/hardware/templates/default/grub.erb +++ b/cookbooks/hardware/templates/default/grub.erb @@ -2,22 +2,7 @@ # Boot the first entry by default, unless we have configured # it to boot a specific version. -<% if node[:hardware][:grub][:kernel] == :latest %> -GRUB_DEFAULT="0" -<% else - df = Mixlib::ShellOut.new("df /boot/grub/grub.cfg | tail -n 1 | awk '{print $1;}'") - df.run_command - df.error! - root=df.stdout - - blkid = Mixlib::ShellOut.new("blkid -o value -s UUID #{root}") - blkid.run_command - blkid.error! - uuid=blkid.stdout - - version="#{node[:hardware][:grub][:kernel]}-generic" %> -GRUB_DEFAULT="gnulinux-advanced-<%= uuid %>>gnulinux-<%= version %>-advanced-<%= uuid %>" -<% end %> +GRUB_DEFAULT="<%= @entry %>" # Wait two seconds before booting the default entry GRUB_TIMEOUT="2"