Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FAI-CD: Add Grub2 background image + DejaVuSansMono font. #124

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 48 additions & 5 deletions bin/fai-cd
Original file line number Diff line number Diff line change
Expand Up @@ -208,19 +208,56 @@ copy_kernel_initrd() {
echo "$isoversion" > $tmp/FAI-CD
}
# - - - - - - - - - - - - - - - - - - - - - - - - - -
create_grub2_image_arm64() {
copy_background_and_font() {
# copy background image and fonts.

set -x
local _font="/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf"
local _bgimg="/usr/share/images/desktop-base/desktop-grub.png"
_bgimg="$(chroot "$NFSROOT" realpath ${_bgimg})"

if ! chroot "$NFSROOT" ls "${_font}"; then
echo "Couldn't found font '${_font}', skipping installing grub2 background image."
set +x
return
fi

mkdir -p $tmp/boot/grub
if ! chroot "$NFSROOT" ls "${_bgimg}"; then
echo "Couldn't found image '${_bgimg}', skipping installing grub2 background image."
set +x
return
fi

mkdir -p "${NFSROOT}/tmp/boot/grub"

# Needs 'desktop-base' package.
cp -p "${NFSROOT}/${_bgimg}" "${NFSROOT}/tmp/boot/grub/background.png"

# Needs 'grub2-common' and 'fonts-dejavu-core' packages.
grub-mkfont -s 16 -o "${NFSROOT}/tmp/boot/grub/$(basename ${_font%.ttf}.pf2)" "${NFSROOT}/${_font}"

echo "Adding background image to grub menu"
}
# - - - - - - - - - - - - - - - - - - - - - - - - - -
create_grub2_image_arm64() {
if [ -d $NFSROOT/usr/lib/grub/arm64-efi ]; then

prepare_grub_cfg

mkdir -p $tmp/boot/grub

declare -a grub_background_plus_font=()
if copy_background_and_font; then
grub_background_plus_font+=("boot/grub/DejaVuSansMono.pf2=/tmp/boot/grub/DejaVuSansMono.pf2" "boot/grub/background.png=/tmp/boot/grub/background.png")
fi

# create arch.efi and copy to vfat file system
TMPDIR=tmp chroot $NFSROOT grub-mkstandalone \
--format=arm64-efi \
--output=/tmp/grubaa64.efi \
--locales="" \
"boot/grub/grub.cfg=/tmp/grub.cfg"
"boot/grub/grub.cfg=/tmp/grub.cfg" \
"${grub_background_plus_font[@]}"
mv $NFSROOT/tmp/grubaa64.efi $scratch

mkfs.vfat -C $scratch/efiboot.img 6000 >/dev/null
Expand All @@ -236,6 +273,11 @@ create_grub2_image_x86() {

mkdir -p $tmp/boot/grub

declare -a grub_background_plus_font=()
if copy_background_and_font; then
grub_background_plus_font+=("boot/grub/DejaVuSansMono.pf2=/tmp/boot/grub/DejaVuSansMono.pf2" "boot/grub/background.png=/tmp/boot/grub/background.png")
fi

if [ -d $NFSROOT/usr/lib/grub/x86_64-efi ]; then

prepare_grub_cfg
Expand All @@ -262,9 +304,10 @@ create_grub2_image_x86() {
--format=i386-pc \
--output=/tmp/core.img \
--locales="" --fonts="" \
--install-modules="linux normal iso9660 biosdisk memdisk search ls echo test chain msdospart part_msdos part_gpt minicmd ext2 keystatus all_video font sleep gfxterm regexp" \
--install-modules="linux normal iso9660 biosdisk memdisk search ls echo test chain msdospart part_msdos part_gpt minicmd ext2 keystatus all_video font sleep gfxterm regexp gfxterm_background png" \
--modules="linux normal iso9660 biosdisk search" \
"boot/grub/grub.cfg=/tmp/grub.cfg"
"boot/grub/grub.cfg=/tmp/grub.cfg" \
"${grub_background_plus_font[@]}"
cat $NFSROOT/usr/lib/grub/i386-pc/cdboot.img $NFSROOT/tmp/core.img > $scratch/bios.img
rm -rf $NFSROOT/tmp/core.img $NFSROOT/tmp/grub
else
Expand Down
157 changes: 157 additions & 0 deletions conf/grub.cfg.gfxmode
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
## grub2 configuration
set default="Boot OS from first partition on first disk"
set timeout=20

# make sure we can access partitions
insmod part_msdos
insmod part_gpt
insmod regexp

function load_video {
insmod gfxterm
insmod png
insmod font

set gfxmode="1280x720, auto"
terminal_output gfxterm

if [ x$feature_all_video_module = xy ]; then
insmod all_video
else
insmod efi_gop
insmod efi_uga
insmod ieee1275_fb
insmod vbe
insmod vga
insmod video_bochs
insmod video_cirrus
fi
}

function load_background {
insmod gfxterm_background

if background_image (memdisk)/boot/grub/background.png; then
set color_normal=white/black
set color_highlight=red/black
else
set menu_color_normal=white/black
set menu_color_highlight=black/yellow
fi
}

# Chroot into FAI-CD
search --set=root --file /FAI-CD

# Load font, graphics mode and background image.
set font="(memdisk)/boot/grub/DejaVuSansMono.pf2"
if loadfont $font ; then
load_video
load_background
fi

menuentry " +------------------------------------------------------+" {
set timeout=20
}

menuentry " | Fully Automatic Installation |" {
set timeout=20

}
menuentry " | _VERSIONSTRING_ |" --unrestricted {
set timeout=20

}
menuentry " | (c) Thomas Lange [email protected] |" {
set timeout=20
}
menuentry " +------------------------------------------------------+" {
set timeout=20
}

menuentry "" {
set timeout=20
}

menuentry "Client standalone installation - select installation type from menu " {
search --set=root --file /FAI-CD
linux /boot/vmlinuz FAI_FLAGS="menu,verbose,createvt" FAI_ACTION=install FAI_CONFIG_SRC=detect:// rd.live.image root=live:CDLABEL=FAI_CD rd.neednet quiet
initrd /boot/initrd.img
}

menuentry "Boot OS from first partition on first disk" {

if [ "$grub_platform" = "efi" ]; then

for d in (hd*,gpt*); do
for cfg in efi/debian/grub.cfg grub/grub.cfg boot/grub/grub.cfg ; do
if [ -e "$d/$cfg" ]; then
found=true
echo "FOUND $d/$cfg"
sleep 1
configfile "$d/$cfg"
fi
done
done

if [ "$found" != true ]; then
echo "Cannot find grub.cfg"
sleep 7
fi

else

# legacy BIOS booting
# detect which disk has a DOS partitions, and boot the MBR via chainloader
found=false
for d in (hd*,msdos*) (hd*,gpt*); do
if [ "$found" == "false" ]; then
regexp -s device '^\((.+),' $d
if [ -e "($device)/FAI-CD" ]; then
# FAI-CD detected, ignore it
device=""
continue
fi
if [ "$device" != "" ]; then
if [ "$device" == "hd*" ]; then
continue
fi
found=true
set root=($device)
chainloader +1
fi
fi
done
if [ "$device" != "" ]; then
echo "Booting from $device"
sleep 2
else
echo "Cannot find grub.cfg"
sleep 7
fi
fi
}

menuentry "Rescue system, no installation" {
search --set=root --file /FAI-CD
linux /boot/vmlinuz FAI_FLAGS="verbose,createvt" FAI_ACTION=sysinfo FAI_CONFIG_SRC=detect:// rd.live.image root=live:CDLABEL=FAI_CD quiet
initrd /boot/initrd.img
}

menuentry "FAI server installation - using external DHCP server" {
search --set=root --file /FAI-CD
linux /boot/vmlinuz FAI_FLAGS="verbose,createvt" FAI_ACTION=install hostname=faiserver FAI_CONFIG_SRC=detect:// rd.live.image root=live:CDLABEL=FAI_CD rd.neednet quiet
initrd /boot/initrd.img
}

menuentry "FAI server installation - using internal DHCP and a fixed IP" {
search --set=root --file /FAI-CD
linux /boot/vmlinuz FAI_FLAGS="verbose,createvt" FAI_ACTION=install ip=192.168.33.250::192.168.33.1:255.255.255.0:faiserver:eth0:off FAI_CONFIG_SRC=detect:// rd.live.image root=live:CDLABEL=FAI_CD quiet net.ifnames=0 hostname=faiserver
initrd /boot/initrd.img
}

if [ ${grub_platform} == "efi" ]; then
menuentry 'UEFI Firmware Settings' --id 'uefi-firmware' {
fwsetup
}
fi