#
set pref=/boot/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=en_US
  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

# Uncomment the following for serial console
# The command serial initializes the serial unit 0 with the speed 38400bps.
# The serial unit 0 is usually called ‘COM1’. If COM2, use ‘--unit=1’ instead.
#serial --unit=0 --speed=38400
#terminal_input serial
#terminal_output serial

# 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 /live/vmlinuz
  $linux_cmd /live/vmlinuz boot=live union=overlay username=user config components quiet noswap  ip= net.ifnames=0  nosplash 
  $initrd_cmd /live/initrd.img
}

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

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

submenu 'Other modes of GParted Live' {
  menuentry --hotkey=K "GParted Live (KMS)"{
    search --set -f /live/vmlinuz
    $linux_cmd /live/vmlinuz boot=live union=overlay username=user config components quiet noswap vga=791 ip= net.ifnames=0  nosplash
    $initrd_cmd /live/initrd.img
  }

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

  menuentry "GParted Live Safe graphic settings (vga=normal)"{
    search --set -f /live/vmlinuz
    $linux_cmd /live/vmlinuz boot=live union=overlay username=user config components quiet noswap ip= net.ifnames=0 nomodeset vga=normal nosplash
    $initrd_cmd /live/initrd.img
  }
  
  menuentry "GParted Live (Failsafe mode)"{
    search --set -f /live/vmlinuz
    $linux_cmd /live/vmlinuz boot=live union=overlay username=user config components quiet noswap acpi=off irqpoll noapic noapm nodma nomce nolapic nosmp ip= net.ifnames=0 nomodeset vga=normal nosplash
    $initrd_cmd /live/initrd.img
  }
}  

menuentry "Local operating system (if available)" --id local-disk {
  echo "Booting first local disk..."
  # Generate boot menu automatically
  configfile /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 /live/memtest
#  linux16 /live/memtest
#}

menuentry 'uEFI firmware setup' 'uefi-firmware' {
  echo "Entering uEFI firmware setup..."
  fwsetup
}

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
}

