#
set pref=/grub
set default="0"
# For grub 2.04, a workaround to avoid boot failure is to add "rmmod tpm": https://bugs.debian.org/975835. However, it might fail in secure boot uEFI machine, and the error is like:
# error: verification requested but nobody cares: /live/vmlinuz.
# Out of range pointer 0x3000000004040
# Aborted. Press any key to exit. 
# rmmod tpm

# Load graphics (only corresponding ones will be found)
# (U)EFI
insmod efi_gop
insmod efi_uga
# legacy BIOS
# insmod vbe

if loadfont $pref/unicode.pf2; then
  set gfxmode=auto
  insmod gfxterm
  # Set the language for boot menu prompt, e.g., en_US, zh_TW...
  set lang=de_DE
  terminal_output gfxterm
fi
set timeout="30"
set hidden_timeout_quiet=false

insmod png
if background_image $pref/Gsplash.png; then
  set color_normal=black/black
  set color_highlight=magenta/black
else
  set color_normal=cyan/blue
  set color_highlight=white/blue
fi

# Decide if the commands: linux/initrd (default) or linuxefi/initrdefi
set linux_cmd=linux
set initrd_cmd=initrd
export linux_cmd initrd_cmd
if [ "${grub_platform}" = "efi" -a -e "/amd64-release.txt" ]; then
  # Only amd64 release we switch to linuxefi/initrdefi since it works better with security boot (shim)
  set linux_cmd=linuxefi
  set initrd_cmd=initrdefi
fi

# Since no network setting in the squashfs image, therefore if ip=, the network is disabled.

menuentry "GParted Live (Default settings)" --id live-default {
  search --set -f isos/gparted/live/vmlinuz
  $linux_cmd isos/gparted/live/vmlinuz boot=live union=overlay username=user config components quiet noswap  ip=dhcp net.ifnames=0  nosplash
  $initrd_cmd isos/gparted/live/initrd.img
}

menuentry --hotkey=r "GParted Live (Default settings & To RAM)" --id live-toram {
  search --set -f isos/gparted/live/vmlinuz
  $linux_cmd isos/gparted/live/vmlinuz boot=live union=overlay username=user config components quiet noswap toram=filesystem.squashfs ip=dhcp net.ifnames=0  nosplash
  $initrd_cmd isos/gparted/live/initrd.img
}

menuentry --hotkey=l "GParted Live (VGA with large font & To RAM)" --id live-vga-large-font-toram {
  search --set -f isos/gparted/live/vmlinuz
  $linux_cmd isos/gparted/live/vmlinuz boot=live union=overlay username=user config components quiet noswap nomodeset toram=filesystem.squashfs ip=dhcp net.ifnames=0  nosplash live_console_font_size=16x32
  $initrd_cmd isos/gparted/live/initrd.img
}

menuentry "Local operating system (if available)" --id local-disk {
  echo "Booting first local disk..."
  # Generate boot menu automatically
  configfile isos/gparted/boot/grub/boot-local-efi.cfg
  # If not chainloaded, definitely no uEFI boot loader was found.
  echo "No uEFI boot loader was found!"
  sleep 15
}

menuentry "memtest"{
  search --set -f isos/gparted/live/memtest
  $linux_cmd isos/gparted/live/memtest
}

menuentry "GParted Live 1.3.1-1-amd64 info"{
  echo GParted.
  echo Gnome Partition Editor.
  echo https://gparted.org
  echo \* Boot menu for EFI machine
  echo \* GParted live version: 1.3.1-1-amd64. Live version maintainer: Steven Shiau
  echo \* Disclaimer: GParted live comes with ABSOLUTELY NO WARRANTY
  sleep --verbose --interruptible 10
}

