Linux Boot Loader/GRUB2

From The Brainwrecked Wiki
Jump to navigation Jump to search
${BOOT}/grub/grub.cfg
insmod	part_<gpt|msdos>
insmod	<btrfs|ext4|f2fs|fat32|jfs|ntfs|xfs|zfs>
insmod	gettext

search	--no-floppy --set=root --label <Boot_Filesystem_Label>

loadfont "/grub/fonts/unicode.pf2"
terminal_input	console
terminal_output	console

function set_resolutions {
	for resolution in 1920x1080 1680x1050 1440x900 1368x768 1366x768 1360x768 1280x720 1280x1024 1024x600 1024x768 800x480 800x600 640x480; do
		for colordepth in 32 16 8; do
			modes=${modes}${resolution}x${colordepth},
		done
	done
	modes=${modes}auto
}  

function load_gfxterm {
	insmod	all_video
	insmod	gfxterm
	set	gfxpayload=keep
	set_resolutions
	set	gfxmode=${modes}
	terminal_output	gfxterm
}

function load_theme {
	insmod	png
	load_gfxterm
	set	theme=/grub/themes/<theme-name>/theme.txt
}

set	timeout=2
set	default=0

menuentry 'Arch Linux (default)' --class desktop {
	echo	'Loading kernel...'
	linux	/arch/boot/vmlinuz-linux-zen root=LABEL=<Root_Filesystem_Label> rootfs=<fs-type> rootflags=noatime,compress-force=zstd,subvol=arch rw consoleblank=0 nvidia-drm.modeset=1 quiet splash loglevel=3 rd.udev.log_priority=3 rd.systemd.show_status=auto vt.global_cursor_default=0
	echo	'Loading initramfs...'
	initrd	/arch/boot/initramfs-linux-zen.img
	load_gfxterm
}

menuentry 'Arch Linux (verbose)' --class desktop {
	echo	'Loading kernel...'
	linux	/arch/boot/vmlinuz-linux-zen root=LABEL=<Root_Filesystem_Label> rootfs=<fs-type> rootflags=noatime,compress-force=zstd,subvol=arch rw consoleblank=0 nvidia-drm.modeset=1
	echo	'Loading initramfs...'
	initrd	/arch/boot/initramfs-linux-zen.img
	load_gfxterm
}

menuentry 'Arch Linux (fallback)' --class desktop {
	echo	'Loading kernel...'
	linux	/arch/boot/vmlinuz-linux-zen root=LABEL=<Root_Filesystem_Label> rootfs=<fs-type> rootflags=noatime,compress-force=zstd,subvol=arch rw consoleblank=0 nvidia-drm.modeset=1
	echo	'Loading initramfs...'
	initrd	/arch/boot/initramfs-linux-zen-fallback.img
	load_gxfterm
}

menuentry 'Arch Linux (console)' --class desktop {
	echo	'Loading kernel...'
	linux	/arch/boot/vmlinuz-linux-zen root=LABEL=<Root_Filesystem_Label> rootfs=<fs-type> rootflags=noatime,compress-force=zstd,subvol=arch rw consoleblank=0 nvidia-drm.modeset=1 systemd.unit=multi-user.target
	echo	'Loading initramfs...'
	initrd	/arch/boot/initramfs-linux-zen-fallback.img
	load_gfxterm
}

menuentry 'Arch Linux (rescue)' --class desktop {
	echo	'Loading kernel...'
	linux	/arch/boot/vmlinuz-linux-zen root=LABEL=<Root_Filesystem_Label> rootfs=<fs-type> rootflags=noatime,compress-force=zstd,subvol=arch rw consoleblank=0 nvidia-drm.modeset=1 systemd.unit=rescue.target
	echo	'Loading initramfs...'
	initrd	/arch/boot/initramfs-linux-zen-fallback.img
	load_gfxterm
}

if [ ${grub_platform} == "efi" ]; then
	menuentry 'UEFI Firmware Settings' --id 'uefi-firmware' {
		fwsetup
	}
	if [ ${grub_cpu} == x86_64 ]; then
		if [ -e /EFI/tools/fwupdx64.efi ]; then
			menuentry 'Firmware Update' --id 'uefi-update' {
				insmod	chain
				search	--no-floppy --set=root --file /EFI/tools/fwupdx64.efi
				chainloader /EFI/tools/fwupdx64.efi
			}
		fi
		if [ -e /shellx64.efi ]; then
			menuentry 'UEFI Shell' --id 'uefi-shell' {
				insmod	chain
				search	--no-floppy --set=root --file /shellx64.efi
				chainloader /shellx64.efi
			}
		fi
		if [ -e /memtest86/bootx64.efi ]; then
			menuentry 'MemTest86' --id 'memtest' {
				insmod	chain
				search	--no-floppy --set=root --file /memtest86/bootx64.efi
				chainloader /memtest86/bootx64.efi
			}
		fi
	elif [ ${grub_cpu} == i386 ]; then
		if [ -e /EFI/tools/fwupdia32.efi ]; then
			menuentry 'UEFI Firmware Settings' --id 'uefi-update' {
				insmod	chain
				search	--no-floppy --set=root --file /EFI/tools/fwupdia32.efi
				chainloader /EFI/tools/fwupdia32.efi
			}
		fi
		if [ -e /shellia32.efi ]; then
			menuentry 'UEFI Shell' --id 'uefi-shell' {
				insmod	chain
				search	--no-floppy --set=root --file /shellia32.efi
				chainloader /shellia32.efi
			}
		fi
		if [ -e /memtest86/bootia32.efi ]; then
			menuentry 'MemTest86' --id 'memtest' {
				insmod	chain
				search	--no-floppy --set=root --file /memtest86/bootia32.efi
				chainloader /memtest86/bootia32.efi
			}
		fi
	fi
elif [ ${grub_platform} == "pc" ]; then
	if [ -e /memtest86+/memtest.bin ]; then
		menuentry "Memtest86+" {
			linux16	/memtest86+/memtest.bin
		}
	elif [ -e /boot/memtest86+/memtest.bin ]; then
		menuentry "Memtest86+" {
			linux16	/boot/memtest86+/memtest.bin
		}
	fi
fi

menuentry "System restart" {
	echo 'System rebooting...'
	reboot
}

menuentry "System shutdown" {
	echo 'System shutting down...'
	halt
}