Since GRUB supports the Multiboot specification , yes you can. You will get the code downloaded by GRUB, then you will have to load the operating system yourself (which you could do by supporting the Multiboot specification yourself ...). Depending on what you want to do, this may not be the easiest way to do this.
If you want to run some custom code before loading a Linux-based operating system, creating custom initramfs will be much easier.
source
share