2016-09-22 12:43:57 +00:00
---
title: About the grub_conf Resource
2018-02-16 00:28:15 +00:00
platform: linux
2016-09-22 12:43:57 +00:00
---
# grub_conf
2019-04-26 18:24:29 +00:00
Grub is a boot loader on the Linux platform used to load and then transfer control to an operating system kernel, after which that kernel initializes the rest of the operating system. Use the `grub_conf` Chef InSpec audit resource to test boot loader configuration settings that are defined in the `grub.conf` configuration file.
2016-09-22 12:43:57 +00:00
2017-10-03 21:35:10 +00:00
<br>
2018-08-09 12:34:49 +00:00
## Availability
### Installation
2019-04-26 18:24:29 +00:00
This resource is distributed along with Chef InSpec itself. You can use it automatically.
2018-08-09 12:34:49 +00:00
### Version
This resource first became available in v1.0.0 of InSpec.
2016-09-27 19:03:23 +00:00
## Syntax
2016-09-22 12:43:57 +00:00
A `grub_conf` resource block declares a list of settings in a `grub.conf` file:
describe grub_conf('path', 'kernel') do
its('setting') { should eq 'value' }
end
or:
describe grub_conf('path') do
its('default') { should eq '0' } #
its('setting') { should eq 'value' }
end
where
* `'service_name'` is a service listed in the `grub.conf` file
* `'path'` is the path to the `grub.conf` file
* `'kernel'` specifies the default kernel (by using `'default'`) or a specific kernel; `'default'` defines the position in the list of kernels at which the default kernel is defined, i.e. `should eq '0'` for the first kernel listed or `'path', 'default'` to use the default kernel as specified in the `grub.conf` file
* `'value'` is the value that is expected
2017-10-03 21:35:10 +00:00
<br>
2016-09-22 12:43:57 +00:00
2016-09-27 19:03:23 +00:00
## Examples
2016-09-22 12:43:57 +00:00
2019-04-26 18:24:29 +00:00
The following examples show how to use this Chef InSpec audit resource.
2016-09-22 12:43:57 +00:00
2016-09-27 19:03:23 +00:00
### Test a grub.conf file
2016-09-22 12:43:57 +00:00
A Grub configuration file located at `/etc/grub.conf` is similar to the following:
# grub.conf generated by anaconda
#
2018-02-08 21:45:42 +00:00
# Note: You do not need to rerun grub after making changes to this file
2016-09-22 12:43:57 +00:00
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/hda6
# initrd /initrd-version.img
#boot=/dev/hda
default=0
timeout=10
splashimage=(hd0,0)/grub/splash.xpm.gz
title Red Hat Enterprise Linux ES (2.6.32-573.7.1.el6.x86_64)
root (hd0,0)
kernel /vmlinuz-2.6.32-573.7.1.el6.x86_64 ro root=/dev/hda6
initrd /initrd-2.6.32-573.7.1.el6.x86_64.img
title Red Hat Enterprise Linux ES (2.6.32-358.14.1.el6.x86_64)
root (hd0,0)
kernel /vmlinuz-2.6.32-358.14.1.el6.x86_64 ro root=/dev/hda6 ramdisk_size=400000
initrd /initrd-2.6.32-358.14.1.el6.x86_64.img
This file defines two versions of RedHat Enterprise Linux, with version `2.6.32-573.7.1.el6.x86_64` specified as the default.
The following test verifies the kernel, ensures that kernel is the default kernel, its initial RAM disk (`initrd`), and the timeout:
describe grub_conf('/etc/grub.conf', 'default') do
its('kernel') { should include '/vmlinuz-2.6.32-573.7.1.el6.x86_64' }
its('initrd') { should include '/initrd-2.6.32-573.7.1.el6.x86_64.img' }
its('default') { should_not eq '1' }
its('timeout') { should eq '10' }
end
2018-03-20 12:43:30 +00:00
The following test verifies the `ramdisk_size` for the non-default kernel:
2016-09-22 12:43:57 +00:00
describe grub_conf('/etc/grub.conf', 'Red Hat Enterprise Linux ES (2.6.32-358.14.1.el6.x86_64)') do
its('kernel') { should include 'ramdisk_size=400000' }
end
2016-09-27 19:03:23 +00:00
### Test a configuration file and boot configuration
2016-09-22 12:43:57 +00:00
describe grub_conf('/etc/grub.conf', 'default') do
its('kernel') { should include '/vmlinuz-2.6.32-573.7.1.el6.x86_64' }
its('initrd') { should include '/initramfs-2.6.32-573.el6.x86_64.img=1' }
its('default') { should_not eq '1' }
its('timeout') { should eq '5' }
end
2016-09-27 19:03:23 +00:00
### Test a specific kernel
2016-09-22 12:43:57 +00:00
grub_conf('/etc/grub.conf', 'CentOS (2.6.32-573.12.1.el6.x86_64)') do
its('kernel') { should include 'audit=1' }
end
2017-10-03 21:35:10 +00:00
<br>
## Matchers
2018-02-16 03:07:18 +00:00
For a full list of available matchers, please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).