GRUB kernel root entry by UUID

tags = [ Linux , ArchLinux , Kernel , Grub , OS , ]

Changing GRUB root entry from root=dev/sxx which restricts the entry to a defined device dev/sxx which might change if you simply inserted a USB or another HDD/SSD to your machine, so the proper way to identify the root entry is by just adding the UUID of the partition root=UUID=xxxxxxxxxxxxxx .

Adding custom entries to GRUB menu is easy, just edit /etc/grub.d/40_custom with your custom menuentry as below.

The changes will be applied after running grub-mkconfig -o /boot/grub/grub.cfg which regenerates the GRUB entries after scanning /etc/grub.d/***

For more detailed customisation of grub-mkconfigā€™s output, you may edit the scripts in /etc/grub.d directly. /etc/grub.d/40_custom is particularly useful for adding entire custom menu entries; simply type the menu entries you want to add at the end of that file, making sure to leave at least the first two lines intact. GNU

Before

# /etc/grub.d/40_custom

menuentry 'Arch Linux (on /dev/sdd3)' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'osprober-gnulinux-simple-427c174a-bef0-4fa0-8fb7-56ccd5aa4583' {
	savedefault
	insmod part_gpt
	insmod ext2
	set root='hd3,gpt3'
	if [ x$feature_platform_search_hint = xy ]; then
	  search --no-floppy --fs-uuid --set=root --hint-ieee1275='ieee1275//disk@0,gpt3' --hint-bios=hd3,gpt3 --hint-efi=hd3,gpt3 --hint-baremetal=ahci3,gpt3  427c174a-bef0-4fa0-8fb7-56ccd5aa4583
	else
	  search --no-floppy --fs-uuid --set=root 427c174a-bef0-4fa0-8fb7-56ccd5aa4583
	fi
	linux /boot/vmlinuz-linux root=/dev/sdd3

	initrd /boot/initramfs-linux.img
}

After

# /etc/grub.d/40_custom

menuentry 'Arch Linux (on /dev/sdd3)' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'osprober-gnulinux-simple-427c174a-bef0-4fa0-8fb7-56ccd5aa4583' {
	savedefault
	insmod part_gpt
	insmod ext2
	set root='hd3,gpt3'
	if [ x$feature_platform_search_hint = xy ]; then
	  search --no-floppy --fs-uuid --set=root --hint-ieee1275='ieee1275//disk@0,gpt3' --hint-bios=hd3,gpt3 --hint-efi=hd3,gpt3 --hint-baremetal=ahci3,gpt3  427c174a-bef0-4fa0-8fb7-56ccd5aa4583
	else
	  search --no-floppy --fs-uuid --set=root 427c174a-bef0-4fa0-8fb7-56ccd5aa4583
	fi
	linux /boot/vmlinuz-linux root=UUID=427c174a-bef0-4fa0-8fb7-56ccd5aa4583

	initrd /boot/initramfs-linux.img
}