Coder Social home page Coder Social logo

goldyfruit / puppet-grub2 Goto Github PK

View Code? Open in Web Editor NEW
9.0 3.0 27.0 172 KB

Puppet module for managing GRUB2

Home Page: https://forge.puppetlabs.com/goldyfruit/grub2

License: Apache License 2.0

Puppet 57.23% Ruby 28.86% HTML 13.26% Shell 0.64%
grub puppet grub-default kernel cmdline-linux grub2 hiera puppet-grub2 mbr

puppet-grub2's Introduction

puppet-grub2

Build Status Puppet Forge License

This module manages GRUB 2 bootloader (Hiera & EFI)

Supported distributions

  • Ubuntu
  • Debian
  • Red Hat
  • CentOS
  • Gentoo
  • SLES / OpenSuse
  • Arch Linux

Setup requirements

This module has the following dependencies:

Parameters

background_image

  • Specify a path to a background image
  • STRING : Empty by default

badram

  • Define some memory addresses for BadRAM filtering
  • STRING : Empty by default

config_template

  • Template used for GRUB config file
  • STRING : 'grub2/default_grub.erb'

cmdline_linux

  • Arguments passed to the kernel
  • STRING : Empty by default

cmdline_linux_default

  • Arguments passed to the kernel
  • STRING : 'quiet'

cmdline_linux_recovery

  • Arguments passed to the kernel
  • STRING : Empty by default

cmdline_xen

  • Arguments passed to Xen
  • STRING : Empty by default

default_entry

  • Define on which kernel the system will boot
  • STRING : '0'

device_install

  • Define on which hard drive the MBR will be write
  • ARRAY : Empty by default

disable_uuid

  • Define if GRUB should use the UUID in the root= path
  • BOOL : false

disable_os_prober

  • Define if GRUB should add the results of os-prober to the menu
  • BOOL : false

disable_recovery

  • Define if GRUB should display the recovery entry in the menu
  • BOOL : false

disable_submenu

  • Define if GRUB should display the submenu
  • BOOL : false

enable_cryptodisk

  • Define if GRUB should check for encrypted disks and generate additional commands needed to access them during boot
  • BOOL : false

enable_blscfg

  • Define if BootLoaderSpec configuration should be used
  • BOOL : false

gfxmode

  • Define which resolution should be used if VBE is used
  • STRING : Empty by default

hidden_timeout

  • Define how long (in seconds) grub should wait for a user to enter the menu
  • STRING : Not present in config file by default

hidden_timeout_quiet

  • Define if the hidden timeout is quiet or not
  • BOOL : false

install_binary

  • Path to GRUB installation command
  • ABSOLUTE_PATH : Value depends on Linux distribution

update_binary

  • Path to GRUB configuration file update command
  • ABSOLUTE_PATH : Value depends on Linux distribution

install_grub

  • Install the GRUB packages and install GRUB in the MBR
  • BOOL : false

package_ensure

  • Puppet stuff, define in which state should be the GRUB packages
  • STRING : 'present'

password

  • Enable password to protect the GRUB configuration
  • BOOL : false

password_username

  • Set the username that will be able to edit the GRUB configuration
  • STRING : Empty by default

password_pbkdf2_hash

  • Set PBKDF2 password hash generated via grub-mkpasswd-pbkdf2 or grub2-mkpasswd-pbkdf2 commands
  • STRING : Empty by default

preload_modules

  • Preload additional modules
  • STRING : Empty by default

recordfail_timeout

  • Set default timeout value for GRUB2. Useful to stop headless machines stalling during boot.
  • INTEGER : 5

save_default

  • If true, the last selected entry will become the new default one GRUB_DEFAULT should be set to "saved" and not to 0
  • BOOL : false

serial_command

  • Set settings for the serial console
  • STRING : Empty by default

suse_btrfs_snapshot_booting

  • Whether the root disk is a btrfs snapshot or not
  • BOOL : false

terminal

  • Define on which terminal the ouput should be display
  • STRING : Empty by default

timeout

  • Define how long (in seconds) that the menu should appear
  • INTEGER : 5

timeout_style

  • Define what to display while waiting for timeout to expire
  • STRING : 'countdown'

tune

  • Define if GRUB should make a beep when he starts
  • STRING : Empty by default

update_grub

  • Regenerate the GRUB configuration after updates
  • BOOL : true

Example

    class { 'grub2':
      update_grub               => false,
      install_grub              => false,
      cmdline_linux_default     => 'quiet crashkernel=256M nmi_watchdog=0 console=tty0 console=ttyS1,115200n8',
      terminal                  => 'serial console',
      default_entry             => 0,
      timeout                   => 5,
      serial_command            => 'serial --speed=115200 --unit=1 --word=8 --parity=no --stop=1',
      disable_uuid              => true,
      disable_recovery          => true,
      tune                      => '480 440 1',
      device_install            => ['/dev/sda'],
      hidden_timeout            => 0,
      hidden_timeout_quiet      => false,
      recordfail_timeout        => 5,
      password                  => true,
      password_username         => 'chewbacca',
      password_pbkdf2_hash      => 'grub.pbkdf2.sha512.10000.EDBE1B820072D36A7B0059C7C33A2AA8B9D60888B0A44E7A566CB92E35F16A0F20770E79FB2E283680715ED916498D59B72F02599B461E4A087704E5E8A2A92D.911F2E7867A16DE76C170AD6E1C14D3F0AE2B7E1B58D1D967F98CEC9F2C2EAF7397ADE15CFB661CA94F6B7963A9C98BEFFB3026A4285FC04DB9F4118BDA39D58',
    }

Hiera support

This module also supports the configuration of the parameters it exposes using Hiera. You can do this by namespacing around grub2. For instance, to set the value of timeout to 10, you would use something like that in your Hiera files:

grub2::timeout: 10

EFI support

Module will now take into account whether a system has booted with BIOS or with (U)EFI and will then place the grub.cfg file in the correct directory.

The efi fact represents whether a system has booted with EFI or BIOS and returns a boolean; true or false depending on the system.

puppet-grub2's People

Contributors

ajlanghorn avatar baurmatt avatar bb-wkr avatar ex3cv avatar flokli avatar goldyfruit avatar gurbmeister avatar hansmi avatar pschichtel avatar rvicinus avatar saz avatar sbadia avatar tampakrap avatar weastur avatar wilman0 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

puppet-grub2's Issues

use of puppet 4 features

Salut!

Since I started using your module at my workplace, I'd like to work on making the module use a bit more of the puppet 4 syntax to make the code lighter to read and also more malleable for future changes, might there be some required. However, before actually working I'd just like to know how interested in this you are.

I'm thinking at least of

  • using types in parameter definitions instead of using validate_*() from stdlib
  • to replace the anchor pattern by the use of the "contain" keyword
    ** this would also let us drop use of inheritance for install, config, update

were you thinking of keeping support for an older version of puppet, 3.x or 2.7 ? or would you be willing to start moving towards code that's more in the puppet 4 realm?

Cheers!

Don't overwrite EFI grub.cfg

This module uses an exec to grub-mkconfig -o /boot/efi/EFI/ubuntu/grub.cfg which overrides the default contents, but this file should not contain a "normal" grub configuration, instead the EFI grub.cfg should look like this to reference /boot/grub/grub.cfg on the right partition:

search.fs_uuid {uuid} root hd0,{partition}
set prefix=($root)'/boot/grub'
configfile $prefix/grub.cfg

Because this module overwrites the EFI grub.cfg, and the kernel postinstall scripts only call grub-update, which only updates /boot/grub/grub.cfg, this module effectively breaks kernel updates as they will never show up in grub.

install_grub only in case of changes

Is there a possibility to install grub to the configured install devices only in case there are changes?

Currently, I have to toggle the install_grub parameter every time I want to write, as the bootloader will otherwise get written again and again on each puppet run, which might be bad for some disks (read: flash storage).

I'm not sure whether grub-install produces state files somewhere, but maybe this module could otherwise store information about which grub version is installed on which disk, and only perform the installation in case there is a new grub version or a new disk selected.

Regression: Module broken for setups without grub password

#36 introduced a change which ensures that update-grub gets triggered if the password file changes. This ignore the fact that the file isn't in the catalog if no password was specified.

mbaur@puppet-development:~ $ puppet apply --modulepath=Sources/ -e 'include grub2'
Warning: This method is deprecated, please use the stdlib validate_legacy function,
                    with Stdlib::Compat::String. There is further documentation for validate_legacy function in the README. at ["/home/mbaur/Sources/grub2/manifests/init.pp", 221]:["unknown", 1]
   (location: /home/mbaur/Sources/stdlib/lib/puppet/functions/deprecation.rb:28:in `deprecation')
Warning: This method is deprecated, please use the stdlib validate_legacy function,
                    with Stdlib::Compat::Absolute_Path. There is further documentation for validate_legacy function in the README. at ["/home/mbaur/Sources/grub2/manifests/init.pp", 227]:["unknown", 1]
   (location: /home/mbaur/Sources/stdlib/lib/puppet/functions/deprecation.rb:28:in `deprecation')
Warning: This method is deprecated, please use match expressions with Stdlib::Compat::String instead. They are described at https://docs.puppet.com/puppet/latest/reference/lang_data_type.html#match-expressions. at ["/home/mbaur/Sources/grub2/manifests/init.pp", 230]:["unknown", 1]
   (location: /home/mbaur/Sources/stdlib/lib/puppet/functions/deprecation.rb:28:in `deprecation')
Warning: This method is deprecated, please use the stdlib validate_legacy function,
                    with Stdlib::Compat::Array. There is further documentation for validate_legacy function in the README. at ["/home/mbaur/Sources/grub2/manifests/init.pp", 234]:["unknown", 1]
   (location: /home/mbaur/Sources/stdlib/lib/puppet/functions/deprecation.rb:28:in `deprecation')
Warning: This method is deprecated, please use the stdlib validate_legacy function,
                    with Stdlib::Compat::Bool. There is further documentation for validate_legacy function in the README. at ["/home/mbaur/Sources/grub2/manifests/init.pp", 236]:["unknown", 1]
   (location: /home/mbaur/Sources/stdlib/lib/puppet/functions/deprecation.rb:28:in `deprecation')
Warning: This method is deprecated, please use the stdlib validate_legacy function,
                    with Stdlib::Compat::Integer. There is further documentation for validate_legacy function in the README. at ["/home/mbaur/Sources/grub2/manifests/init.pp", 255]:["unknown", 1]
   (location: /home/mbaur/Sources/stdlib/lib/puppet/functions/deprecation.rb:28:in `deprecation')
Error: Could not find resource 'File[/etc/grub.d/50_password]' in parameter 'subscribe' (file: /home/mbaur/Sources/grub2/manifests/update.pp, line: 7) on node puppet-development

Bug: parameter package_name_legacy is not optional

The parameter package_name_legacy in init.pp is not String instead of Optional[String]. On all supported OS but Debian it gets set Undef from params.pp and the Puppetrun therefore failes with:

Info: Using configured environment 'test'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Retrieving locales
Info: Loading facts
Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Resource Statement, Class[Grub2]: parameter 
'package_name_legacy' expects a String value, got Undef (file: /etc/puppetlabs/code/environments/test/modules/internal/profile/manifests/grub.pp, line: 24, column
: 11) on node testserver
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run

A workaround is to set the parameter to a String when calling the class:

class { 'grub2':
      package_name_legacy  => 'workaround',

No tag/release for 1.0.8?

Hello,

version 1.0.8 is available on Puppet Forge, however there is no corresponding git tag here on GitHub.
It would be great, if the git tag could be included in the repository.

Regards,
Stefan

Dependency update

Since #7 was merged, the dependency on puppetlabs/stdlib has changed - this module now needs at least 4.6.0 since that is when the validate_integer function was introduced. I'll look at fixing this in metadata.json shortly.

Release 0.0.5

Hi @goldyfruit,

Please can you consider releasing 0.5.0? When using this with librarian-puppet after my recent changes, the 0.4.0 release is downloaded and cached locally, which omits the feature I just added. The only way to get this working with the 0.4.0 release would be to pin this to a SHA-1 locally, which I'd rather not do if you'd be prepared to release 0.5.0.

Thanks!

Andrew

update-grub run every puppetrun

class grub2::update inherits grub2 {

if $grub2::update_grub {
exec { 'Update GRUB':
command => $grub2::update_binary,
}
}

}

We should refresh only if the config file was changed only. Above class with parameter "update_grub=true" , grub2::update run everytime puppet run whenever the config file is changed or not. If we set parameter "update_grub=false", grub2::update never be run.

Support BootLoaderSpec style configuration

In CentOS 8 BLS is used to configure GRUB menuentries: https://fedoraproject.org/wiki/Changes/BootLoaderSpecByDefault

puppet-grub2 should support this option to be able to configure CentOS 8 GRUB in the standard way.

To implement this a seperate bool parameter in https://github.com/goldyfruit/puppet-grub2/blob/master/manifests/init.pp#L186 is needed which activates the GRUB_ENABLE_BLSCFG=$value in https://github.com/goldyfruit/puppet-grub2/blob/master/templates/default_grub.erb

Refresh (update-grub) always triggered

When using "update_grub => true" a refresh is always triggered, not only when there's an update to the manifest. So it executes update-grub at every puppet agent run.

RHEL 8 + Puppet 7.18 never exports superusers

The /etc/grub.d/50_password file gets setup and included in the file /boot/grub2/grub.cfg just fine.

But the only place that calls logic to actually export the defined superusers is in /etc/grub.d/01_users as follows:

#!/bin/sh -e cat << EOF if [ -f \${prefix}/user.cfg ]; then source \${prefix}/user.cfg if [ -n "\${GRUB2_PASSWORD}" ]; then set superusers="root" export superusers password_pbkdf2 root \${GRUB2_PASSWORD} fi fi EOF

This module doesn't do its work in 01_users however so that code block never gets touched and you end up with a /boot/grub2/grub.cfg that contains a superuser definition and its hashed password but export superusers is never called so no password is ever required.

I tested and fixed by fudging in export superusers to the end of the /etc/grub.d/50_password file that the module generates. This module needs to include that export command to achieve its stated effect.

version bump

Hey,

awesome module, thanks!

Could you release a newer version of it to the Puppetforge?

I'd like to use the multi-device install features, but so far, this can only be found by pointing to git master…

Could not match |$device|

Hello,

I try to run this module with the next options in Centos 7.2 with

class { 'grub2':
      update_grub           => false,
      install_grub          => false,
      cmdline_linux_default => 'crashkernel=auto rd.lvm.lv=vg00/lv_root rhgb quiet audit=1',
      terminal              => 'console',
      default_entry         => 0,
      timeout               => 5,
      disable_submenu       => true,
      save_default          => true,
      disable_recovery      => true,
      device_install            => ['/dev/sda'],
    }

I only want to add audit=1 in cmdline_linux_default

More over my disk configuration is

Disk /dev/sda: 599.0 GB, 598999040000 bytes, 1169920000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000c2fac

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048  1169919999   584446976   8e  Linux LVM

Disk /dev/mapper/vg00-lv_root: 31.5 GB, 31457280000 bytes, 61440000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/vg00-lv_var: 567.0 GB, 566973431808 bytes, 1107369984 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

But I found the following error

Error 400 on SERVER: Could not match |$device| at /etc/puppet/environments/mauso/modules/grub2/manifests/install.pp:12

I think that maybe the problem is in install.pp, because module always use it

recordfail_timeout should be an integer an not an undef value

If recordfail_timeout option is not defined as an integer in params.pp, an error occur:

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: validate_integer(): Expected first argument to be an Integer or Array, got String at /srv/data/puppet/envs/production/modules/grub2/manifests/init.pp:176 on node vm002

To fix that, we have to replace the default value:

$recordfail_timeout    = undef

By:

$recordfail_timeout    = 5

Symbolic link

tar ztvf goldyfruit-grub2-0.0.1.tar.gz
...
lrwxrwxrwx root/root 0 2014-03-03 15:47 goldyfruit-grub2-0.0.1/spec/fixtures/modules/grub2 -> /srv/data/puppet/envs/production/modules/grub2
...

And it gripes
Error: No such file or directory - /etc/puppet/modules/grub2/spec/fixtures/modules/grub2
Error: Try 'puppet help module install' for usage

Error in 50_password.erb

Hi!
Seems 50_password.erb have error:
exec tail -n +3 $0 must be on second line, after #!/bin/sh

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.