# Compiling grub2

## Suggested stuff to compile

\#find a folder name you like, and enter.\
mkdir surfacert; cd surfacert;

git clone <https://github.com/coherixmatts/grub-2.04> \
\# grub modded for RT

git clone <https://github.com/jelly/efitools>   \
\#OR\
git clone <git://git.kernel.org/pub/scm/linux/kernel/git/jejb/efitools.git>\
\#useful EFI tools

git clone <https://github.com/rhboot/shim>\
\#boot shim \
\
git clone <https://github.com/tianocore/edk2>\
\#uefi EDK2

\[You will need to have followed pre-reqs - see [Cross Compiling](https://lawrence-1.gitbook.io/surfacert-hacking/development/cross-compiling)]

## EDK2 (Tianmo)

cd edk2\
git submodule update --init\
make -C BaseTools\
./edksetup.sh\
export EDK\_TOOLS\_PATH=$(*pwd*)/BaseTools

## EFI TOOLS

/usr/local/bin/dockcross-linux-armv7 make ARCH=arm

currently erroring out with missing efi.h (fixed with apt install efitools and gnu-efi)

more issues though, as gnu-efi doesn't install all the arm bits, so you need to grab manually.&#x20;

## GRUB2 building

\
SurfaceRT2 - \
Download grub-2.04.tar.gz from <https://git.savannah.gnu.org/cgit/grub.git> \
SurfaceRT Download a pre-patched one from <https://github.com/coherixmatts/grub-2.04>\
Uncompress the download. \
cd into grub-2.04 directory \
\
&#x20;`./bootstrap` \
&#x20;`./configure --with-platform=efi --target=arm-linux-gnueabihf --enable-mm-debug --enable-boot-time`\ <br>

Grub should trundle along and end up with most things enabled as below:

`*******************************************************`\
`GRUB2 will be compiled with following components:`\
`Platform: arm-efi`\
`With devmapper support: Yes`\
`With memory debugging: Yes`\
`With disk cache statistics: No`\
`With boot time statistics: Yes`\
`efiemu runtime: No (not available on efi)`\
`grub-mkfont: Yes`\
`grub-mount: Yes`\
`starfield theme: Yes`\
`With DejaVuSans font from /usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf`\
`With libzfs support: No (need zfs library)`\
`Build-time grub-mkfont: Yes`\
`With unifont from /usr/share/fonts/X11/misc/unifont.pcf.gz`\
`With liblzma from -llzma (support for XZ-compressed mips images)`\
`*******************************************************`\
&#x20;

Next up -&#x20;

`make` \
`cd grub-core` \
`../grub-mkimage -O arm-efi -d . -o grub.efi -p / part_gpt part_msdos ntfs ntfscomp hfsplus fat ext2 normal chain boot configfile linux gfxterm videoinfo efi_gop all_video video video_fb loadenv help reboot raid6rec raid5rec mdraid1x mdraid09 lvm diskfilter zfsinfo zfscrypt gcry_rijndael gcry_sha1 zfs true test sleep search search_fs_uuid search_fs_file search_label png password_pbkdf2 gcry_sha512 pbkdf2 part_apple minicmd memdisk lsacpi lssal lsefisystab lsefimmap lsefi disk keystatus jpeg iso9660 halt gfxterm_background gfxmenu trig bitmap_scale video_colors bitmap font fshelp efifwsetup echo terminal gettext efinet net priority_queue datetime bufio cat btrfs gzio lzopio crypto acpi extcmd mmap` \
\
The compiled grub.efi should now be in the  current directory.\
\
rename that file to boot.efi and copy to the root of a USB

NOTE: The Grub2.04 built from these instructions currently only boots correctly on SurfaceRT 2 or QEMU, it does not output video yet on the Surface RT1 unless you patch it.\
To use a patch to make it work on RT1 (see imbushuo or coherixmatts github in [Interesting repo's](https://lawrence-1.gitbook.io/surfacert-hacking/development/interesting-repos)) \
\
In the interest of science, here's a pre-built version compatible for Surface RT and RT2\ <br>

{% file src="<https://569825932-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MJLRvYIRoqQ8RpdJUy4%2F-MJNizRRaDmAs12oqZtR%2F-MJNkATepTE6lQb-4KRO%2Fboot.efi?alt=media&token=c2da4eca-336c-448a-9b99-a2019dfa136a>" %}
