#
set pref=/boot/grub
set default="0"
set timeout="30"
# Force to set the mode. The EFI specification says that mode 0 must be available and have columns and rows of 80 and 25 respectively.
efitextmode 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

# To set authentication, check
# https://www.gnu.org/software/grub/manual/grub/grub.html#Authentication-and-authorisation
# ‘password’ sets the password in plain text, requiring grub.cfg to be secure; ‘password_pbkdf2’ sets the password hashed using the Password-Based Key Derivation Function (RFC 2898), requiring the use of grub-mkpasswd-pbkdf2 (see Invoking grub-mkpasswd-pbkdf2) to generate password hashes.
# Example:
# set superusers="root"
# password_pbkdf2 root grub.pbkdf2.sha512.10000.biglongstring
# password user1 insecure
# 
# menuentry "May be run by any user" --unrestricted {
# 	set root=(hd0,1)
# 	linux /vmlinuz
# }
# 
# menuentry "Superusers only" --users "" {
# 	set root=(hd0,1)
# 	linux /vmlinuz single
# }
# 
# menuentry "May be run by user1 or a superuser" --users user1 {
# 	set root=(hd0,2)
# 	chainloader +1
# }

# Load graphics (only correspoonding ones will be found)
# (U)EFI
insmod efi_gop
#insmod efi_uga # Debian grub 2.14 has dropped this.
# legacy BIOS
# insmod vbe
if [ x$feature_default_font_path = xy ] ; then
   font=unicode
else
   font=$prefix/unifont.pf2
fi

# A workdaround to avoid no video output on some systems
# Ref: https://savannah.gnu.org/bugs/?65503#comment2
# https://sourceforge.net/p/clonezilla/bugs/424/
echo "Loading bootloader..."

if loadfont $font; then
  # Use 1024x768 as the preferred resolution, falling back to 640x480 and auto.
  # This 4:3 ratio matches Clonezilla's 640x480 background image perfectly,
  # preventing horizontal stretching/distortion. It also guarantees readable
  # large fonts on 4K/HiDPI screens and avoids GOP driver bugs on some UEFI systems.
  set gfxmode=1024x768,640x480,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 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
# Since "linux/initrd" works for uEFI boot, no matter it's secure boot or not. Just use them.
# 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


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 loglevel=3 noswap  net.ifnames=0  nosplash  ocs_1_cpu_udev scsi_mod.use_blk_mq=0 nvme.poll_queues=1
  $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 loglevel=3 noswap  toram=filesystem.squashfs net.ifnames=0  nosplash  ocs_1_cpu_udev scsi_mod.use_blk_mq=0 nvme.poll_queues=1
  $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 loglevel=3 noswap nomodeset toram=filesystem.squashfs net.ifnames=0  nosplash live_console_font_size=16x32
  $initrd_cmd /live/initrd.img
}

menuentry "GParted Live (Verify integrity of the boot medium)" --id verify-checksums {
  search --set -f /live/vmlinuz
  $linux_cmd /live/vmlinuz boot=live union=overlay username=user config components loglevel=3 noswap  verify-checksums
  $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 loglevel=3 noswap vga=791 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 loglevel=3 noswap vga=791 toram=filesystem.squashfs 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 loglevel=3 noswap vga=791 toram=filesystem.squashfs 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 loglevel=3 noswap 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 loglevel=3 noswap acpi=off irqpoll noapic noapm nodma nomce nolapic nosmp 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 --hotkey=m "Memtester (Default settings & To RAM)" --id memtester {
  search --set -f /live/vmlinuz
  $linux_cmd /live/vmlinuz boot=live union=overlay username=user config components loglevel=3 noswap  toram=filesystem.squashfs net.ifnames=0  nosplash  ocs_1_cpu_udev scsi_mod.use_blk_mq=0 nvme.poll_queues=1 init=/bin/bash -- -c "/sbin/ocs-memtester"
  $initrd_cmd /live/initrd.img
}

menuentry "Memtest using Memtest86+" --id memtest86+ {
  search --no-floppy --set=root -f /live/mt86+x64
  linux /live/mt86+x64
}

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

menuentry "GParted Live 1.8.1-6-amd64 info"{
  echo GParted.
  echo Gnome Partition Editor.
  echo https://gparted.org
  echo \* Boot menu for EFI machine \| Created at time: Sun 30 Aug 2026 01:33:21 PM BST
  echo \* GParted live version: 1.8.1-6-amd64. Live version maintainer: Steven Shiau
  echo \* Disclaimer: GParted live comes with ABSOLUTELY NO WARRANTY
  sleep --verbose --interruptible 10
}

