Last active
September 11, 2019 08:16
-
-
Save aderixon/03e9c196d4ce83c9ee8da5f0c51b9bba to your computer and use it in GitHub Desktop.
Cobbler post-sync trigger script to generate GRUB2 per-client configurations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Write configs for UEFI boot from Cobbler, see: | |
# http://sapitnotes.com/cobbler-загрузка-по-pxe-в-режиме-uefi-centos-7/ | |
# Translation: | |
# https://translate.google.com/translate?hl=en&sl=ru&u=http://sapitnotes.com/cobbler-%25D0%25B7%25D0%25B0%25D0%25B3%25D1%2580%25D1%2583%25D0%25B7%25D0%25BA%25D0%25B0-%25D0%25BF%25D0%25BE-pxe-%25D0%25B2-%25D1%2580%25D0%25B5%25D0%25B6%25D0%25B8%25D0%25BC%25D0%25B5-uefi-centos-7/&prev=search | |
# Adaptations by ajr, 2019-06 | |
# Make executable and place in /var/lib/cobbler/triggers/sync/post/uefi.sh | |
# or equivalent for your Cobbler installation | |
for o_name in $(ls -A1 /var/lib/tftpboot/grub/ | grep -E '(.{2}-){6}.{2}'); | |
do | |
n_name=grub.cfg-$(echo ${o_name} | tr '[A-Z]' '[a-z]'); | |
## GRUB-legacy configs, skip: | |
#cp -a /var/lib/tftpboot/grub/${o_name} /var/lib/tftpboot/uefi/${n_name}; | |
# fudge a GRUB2 config instead (experimental!), sisar1: | |
cat > /var/lib/tftpboot/uefi/${n_name} << _EOF | |
set default="0" | |
set timeout=5 | |
function load_video { | |
insmod efi_gop | |
insmod efi_uga | |
insmod video_bochs | |
insmod video_cirrus | |
insmod all_video | |
} | |
load_video | |
set gfxpayload=keep | |
insmod net | |
insmod efinet | |
insmod tftp | |
insmod gzio | |
insmod part_gpt | |
insmod ext2 | |
_EOF | |
# grep menu entry from GRUB1 config: | |
awk '/^title/ {printf("menuentry \"%s\" {\n",$2)}' /var/lib/tftpboot/grub/${o_name} >> /var/lib/tftpboot/uefi/${n_name} | |
awk '/kernel / {printf(" linuxefi %s\n",(substr($0, index($0,$2))))}' /var/lib/tftpboot/grub/${o_name} >> /var/lib/tftpboot/uefi/${n_name} | |
awk '/initrd / {printf(" initrdefi %s\n",(substr($0, index($0,$2))))}' /var/lib/tftpboot/grub/${o_name} >> /var/lib/tftpboot/uefi/${n_name} | |
echo '}' >> /var/lib/tftpboot/uefi/${n_name} | |
# create compatible links for GRUB include (remove leading -01 and change | |
# MAC addresses to standard form): | |
l_name=$(echo $n_name | sed -e 's/\-/\:/g' -e 's/:01:/\-/') | |
rm -f /var/lib/tftpboot/uefi/${l_name} | |
ln -s ${n_name} /var/lib/tftpboot/uefi/${l_name} | |
done | |
# write default grub.cfg: | |
cat > /var/lib/tftpboot/grub/grub.cfg << _EOgrub | |
configfile=uefi/grub.cfg-\$net_default_mac | |
source "\$configfile" | |
_EOgrub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment