Skip to content

Instantly share code, notes, and snippets.

@pfandl
Created March 30, 2020 01:26
Show Gist options
  • Save pfandl/19ec4ce5608d5f0f129aee88a89e169c to your computer and use it in GitHub Desktop.
Save pfandl/19ec4ce5608d5f0f129aee88a89e169c to your computer and use it in GitHub Desktop.
CentOS 8 kickstart post install snippet to set a grub2 keyboard layout.
%post
# Setup grub2 keyboard layout.
KEYBOARD_LAYOUT=at
[ -d /sys/firmware/efi ] \
&& boot_directory=/boot/efi/EFI/centos \
|| boot_directory=/boot
# Fix installation of grub2 UEFI modules on x86_64 platform, the installer installs
# grub2-pc-modules and if you explicitly specify to install grub2-efi-modules it
# would install grub2-efi-aa64-modules instead of grub2-efi-x64-modules.
{
[ "$(uname -p)" == "x86_64" ] && [ -d /sys/firmware/efi ] && {
dnf install -y grub2-efi-x64-modules
grub2-install --boot-directory=$boot_directory --efi-directory=/boot/efi
}
}
cd $boot_directory/grub2
mkdir layouts
zcat /lib/kbd/keymaps/xkb/$KEYBOARD_LAYOUT.map.gz | \
grub2-mklayout -o layouts/$KEYBOARD_LAYOUT.gkb
CUSTOM_CONF=/etc/grub.d/40_custom
echo "insmod keylayouts" >> $CUSTOM_CONF
echo "keymap \${prefix}/layouts/$KEYBOARD_LAYOUT.gkb" >> $CUSTOM_CONF
echo "terminal_input at_keyboard" >> $CUSTOM_CONF
for config_file in /etc/grub2.cfg /etc/grub2-efi.cfg
do
[ -f "$config_file" ] && grub2-mkconfig -o $(readlink -e "$config_file")
done
%end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment