Skip to content

Commit

Permalink
generate files for UEFI Grub/Grub2 support
Browse files Browse the repository at this point in the history
closes GH-276
  • Loading branch information
lzap authored and mmoll committed Sep 7, 2016
1 parent 55f169d commit d5794d8
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 1 deletion.
2 changes: 1 addition & 1 deletion manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@
$tftp_listen_on = 'https'
$tftp_managed = true
$tftp_manage_wget = true
$tftp_dirs = ["${tftp_root}/pxelinux.cfg","${tftp_root}/boot","${tftp_root}/ztp.cfg","${tftp_root}/poap.cfg"]
$tftp_dirs = ["${tftp_root}/pxelinux.cfg","${tftp_root}/grub","${tftp_root}/grub2","${tftp_root}/boot","${tftp_root}/ztp.cfg","${tftp_root}/poap.cfg"]
$tftp_servername = undef

# DHCP settings - requires optional DHCP puppet module
Expand Down
88 changes: 88 additions & 0 deletions manifests/tftp.pp
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,92 @@
root => $foreman_proxy::tftp_root,
}
}

case $::osfamily {
'RedHat': {
$osreleasemajor = regsubst($::operatingsystemrelease, '^(\d+)\..*$', '\1') # workaround for the possibly missing operatingsystemmajrelease
if versioncmp($osreleasemajor, '6') <= 0 {
$grub_type = 'redhat_old'
} else {
$grub_type = 'redhat'
}
# taken from http://pkgs.fedoraproject.org/cgit/rpms/grub2.git/tree/grub2.spec
$grub_modules = 'all_video boot btrfs cat chain configfile echo efifwsetup efinet ext2 fat font gfxmenu gfxterm gzio halt hfsplus iso9660 jpeg loadenv loopback lvm mdraid09 mdraid1x minicmd normal part_apple part_msdos part_gpt password_pbkdf2 png reboot search search_fs_uuid search_fs_file search_label serial sleep syslinuxcfg test tftp video xfs linux backtrace usb usbserial_common usbserial_pl2303 usbserial_ftdi usbserial_usbdebug linuxefi'
}
'Debian': {
$grub_type = 'debian'
# taken from https://anonscm.debian.org/cgit/pkg-grub/grub.git/tree/debian/build-efi-images
$grub_modules = 'all_video boot btrfs cat chain configfile echo efifwsetup efinet ext2 fat font gettext gfxmenu gfxterm gfxterm_background gzio halt hfsplus iso9660 jpeg keystatus loadenv linux lsefi lsefimmap lsefisystab lssal memdisk minicmd normal part_apple part_msdos part_gpt password_pbkdf2 png reboot search search_fs_uuid search_fs_file search_label sleep test true video zfs zfscrypt zfsinfo linuxefi lvm mdraid09 mdraid1x raid5rec raid6rec tftp'
}
default: {
warning("Unable to detect EFI loader for OS family '${::osfamily}'")
$grub_type = 'unknown'
}
}

$efi_dir = '/usr/lib/grub/x86_64-efi'
case $::operatingsystem {
'Fedora': {
$grub_efi_path = 'fedora'
}
'CentOS': {
$grub_efi_path = 'centos'
}
/^(RedHat|Scientific|OracleLinux)$/: {
$grub_efi_path = 'redhat'
}
default: {
$grub_efi_path = 'unknown'
}
}

case $grub_type {
'redhat': {
ensure_packages(['grub2-efi','grub2-efi-modules','grub2-tools','shim'], { ensure => 'installed', })

exec {'build-grub2-efi-image':
command => "/usr/bin/grub2-mkimage -O x86_64-efi -d ${efi_dir} -o ${foreman_proxy::tftp_root}/grub2/grubx64.efi -p '' ${grub_modules}",
creates => "${foreman_proxy::tftp_root}/grub2/grubx64.efi",
require => [File[$foreman_proxy::tftp_dirs], Package['grub2-tools']],
}

foreman_proxy::tftp::copy_file{"/boot/efi/EFI/${grub_efi_path}/shim.efi":
target_path => "${foreman_proxy::tftp_root}/grub2",
require => File[$foreman_proxy::tftp_dirs],
}
}
'redhat_old': {
ensure_packages(['grub'], { ensure => 'installed', })

file {"${foreman_proxy::tftp_root}/grub/grubx64.efi":
ensure => file,
source => "/boot/efi/EFI/${grub_efi_path}/grub.efi",
require => File[$foreman_proxy::tftp_dirs],
}

file {"${foreman_proxy::tftp_root}/grub/shim.efi":
ensure => 'link',
target => 'grubx64.efi',
require => File[$foreman_proxy::tftp_dirs],
}
}
'debian': {
ensure_packages(['grub-common','grub-efi-amd64-bin'], { ensure => 'installed', })

exec {'build-grub2-efi-image':
command => "/usr/bin/grub-mkimage -O x86_64-efi -d ${efi_dir} -o ${foreman_proxy::tftp_root}/grub2/grubx64.efi -p '' ${grub_modules}",
creates => "${foreman_proxy::tftp_root}/grub2/grubx64.efi",
require => [File[$foreman_proxy::tftp_dirs], Package['grub-common','grub-efi-amd64-bin']],
}

file {"${foreman_proxy::tftp_root}/grub2/shim.efi":
ensure => 'link',
target => 'grubx64.efi',
require => File[$foreman_proxy::tftp_dirs],
}
}
default: {
warning('UEFI PXE firmware is not being deployed')
}
}
}
55 changes: 55 additions & 0 deletions spec/classes/foreman_proxy__config__spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@
end

if facts[:osfamily] == 'Debian'
it { should contain_package('grub-common').with_ensure('installed') }
it { should contain_package('grub-efi-amd64-bin').with_ensure('installed') }

if facts[:operatingsystem] == 'Ubuntu' && facts[:operatingsystemrelease] == '14.04'
it 'should copy the correct default files for Ubuntu 14.04' do
should contain_foreman_proxy__tftp__copy_file('/usr/lib/syslinux/chain.c32')
Expand All @@ -290,6 +293,58 @@
should contain_foreman_proxy__tftp__copy_file('/usr/lib/syslinux/modules/bios/menu.c32')
end
end
it 'should generate efi image from grub2 modules for Debian' do
should contain_exec('build-grub2-efi-image')
end
if facts[:operatingsystem] == 'Ubuntu'
it 'should create shim.efi symlink for Ubuntu' do
should contain_file('/var/lib/tftpboot/grub2/shim.efi').with_ensure('link')
end
else
it 'should create shim.efi symlink for Debian' do
should contain_file('/srv/tftp/grub2/shim.efi').with_ensure('link')
end
end
elsif facts[:osfamily] == 'RedHat'
it 'should copy the correct default files for Red Hat' do
should contain_foreman_proxy__tftp__copy_file('/usr/share/syslinux/chain.c32')
should contain_foreman_proxy__tftp__copy_file('/usr/share/syslinux/mboot.c32')
should contain_foreman_proxy__tftp__copy_file('/usr/share/syslinux/menu.c32')
should contain_foreman_proxy__tftp__copy_file('/usr/share/syslinux/memdisk')
should contain_foreman_proxy__tftp__copy_file('/usr/share/syslinux/pxelinux.0')
end

if facts[:operatingsystemmajrelease].to_i > 6
it { should contain_package('grub2-efi').with_ensure('installed') }
it { should contain_package('grub2-efi-modules').with_ensure('installed') }
it { should contain_package('grub2-tools').with_ensure('installed') }
it { should contain_package('shim').with_ensure('installed') }
it 'should generate efi image from grub2 modules' do
should contain_exec('build-grub2-efi-image')
end
case facts[:operatingsystem]
when /^(RedHat|Scientific|OracleLinux)$/
it 'should copy the shim.efi for Red Hat and clones' do
should contain_foreman_proxy__tftp__copy_file('/boot/efi/EFI/redhat/shim.efi')
end
when 'Fedora'
it 'should copy the shim.efi for Fedora' do
should contain_foreman_proxy__tftp__copy_file('/boot/efi/EFI/fedora/shim.efi')
end
when 'CentOS'
it 'should copy the shim.efi for CentOS' do
should contain_foreman_proxy__tftp__copy_file('/boot/efi/EFI/centos/shim.efi')
end
end
else
it { should contain_package('grub').with_ensure('installed') }
it 'should copy grub1 files for Red Hat version 6 and older' do
should contain_file('/var/lib/tftpboot/grub/grubx64.efi').with_ensure('file')
end
it 'should create shim.efi symlink for Red Hat version 6 and older' do
should contain_file('/var/lib/tftpboot/grub/shim.efi').with_ensure('link')
end
end
end

it 'should generate correct realm.yml' do
Expand Down

0 comments on commit d5794d8

Please sign in to comment.