GRUB: Difference between revisions

252 bytes added ,  29 days ago
m
Bot: Replace deprecated source tag with syntaxhighlight
[unchecked revision][unchecked revision]
(→‎Explanation: Explain that the multiboot command only works for multiboot v1)
m (Bot: Replace deprecated source tag with syntaxhighlight)
Line 47:
 
=== Floppy instructions ===
<sourcesyntaxhighlight lang="bash">
mkdir tmp
grub-mkimage -p /boot -o tmp/core.img multiboot sh fat # This should work... I hope :D
</syntaxhighlight>
</source>
 
==== Explanation ====
Line 80:
Here's a sample configuration file (NOTE: This file should be placed into the <tt>/boot/grub</tt> folder of your disk image, and be named '''grub.cfg'''):
 
<sourcesyntaxhighlight lang="bash">
set timeout=15
set default=0 # Set the default menu entry
Line 90:
boot
}
</syntaxhighlight>
</source>
 
That's basically it. Copy these files to a disk image, pop it in an emulator, and you're done!
Line 188:
 
1. First, create a blank, raw image with DD, with the required size. Here, I'll make a 80MB image -- 163840 sectors of 512 bytes.
<sourcesyntaxhighlight lang="bash">
dd if=/dev/zero of=disk.img count=163840 bs=512
</syntaxhighlight>
</source>
 
2. For an explaination on calculating the CHS values from the LBA / size see [[Floppy_Disk_Controller#CHS]]
Line 223:
4. Now that the MBR Partition Table is initialised, you'll want to make a Filesystem on the disk. But first.
Here, we separate the MBR bit, and the actual FS bit.
<sourcesyntaxhighlight lang="bash">
dd if=disk.img of=mbr.img bs=512 count=2047
dd if=disk.img of=fs.img bs=512 skip=2047
</syntaxhighlight>
</source>
 
5. Because we're on OS X, we need to attach the disk image first, without actually mounting it.
<sourcesyntaxhighlight lang="bash">
hdiutil attach -nomount fs.img
</syntaxhighlight>
</source>
 
6. Use 'diskutil list' to find out which device your image is, use that below.
 
7. Now, make a FAT12/16/32 filesystem on the FS.img disk. Remember, use FS.img -- not disk.img
<sourcesyntaxhighlight lang="bash">
newfs_msdos -F 32 /dev/diskX
</syntaxhighlight>
</source>
 
8. Now you'll want to unmount it, then recombine the two images, then install GRUB.
<sourcesyntaxhighlight lang="bash">
hdiutil detach /dev/diskX
cat mbr.img fs.img > disk.img
Line 250:
grub-install --modules="part_msdos biosdisk fat multiboot configfile" --root-directory="/Volumes/NO NAME" disk.img
Installation finished. No error reported.
</syntaxhighlight>
</source>
 
And there it is! You know have a disk.img, that will have GRUB 2 installed, ready to go. It should be mountable in OS X simply by double clicking (or with the mount command).
Line 283:
 
'''1.''' Clone the developer version of the sources:
<sourcesyntaxhighlight lang="bash">git clone git://git.savannah.gnu.org/grub.git</sourcesyntaxhighlight>
(This was tested on revision: 77063f4cb672f423272db7e21ca448cf3de98dcf)
 
Line 304:
===Compiling GRUB===
Older GRUB versions are riddled with nasty bugs. As this probably includes the version from your package management, you should be compiling GRUB from source. As we're compiling for UEFI, you should pass the appropriate flags to configure. An example invocation might look something like this:
<sourcesyntaxhighlight lang="text">
../grub-2.02~rc2/configure --prefix="$HOME/opt/grub" --target=x86_64 --with-platform=efi
</syntaxhighlight>
</source>
 
After completing the build, GRUB refused to do anything as it was missing a font file. To fix this, run
<sourcesyntaxhighlight lang="text">
bin/grub-mkfont -o share/grub/unicode.pf2 /usr/share/fonts/truetype/unifont/unifont.ttf
</syntaxhighlight>
</source>
 
GRUB might warn you about share/locale/ missing. To solution is to create the missing directory.
Line 323:
 
Start off with creating the memdisk grub.cfg. I saved it at build/grub.cfg (we'll need this path later on):
<sourcesyntaxhighlight lang="text">
insmod part_msdos
configfile (hd0,msdos1)/boot/grub/grub.cfg
</syntaxhighlight>
</source>
All this does is loading the module for reading the disk partitions (line 1) and loading the configuration file from the disk (line 2). Note that it doesn't have to be located at /boot/grub/grub.cfg; you can change this path on the disk to whatever you like, just remember to apply the changes to the memdisk grub.cfg.
 
The second grub.cfg (the one on the disk) is pretty much up to you, except that you have to load the part_msdos module and set the root (which by default is memdisk):
<sourcesyntaxhighlight lang="text">
insmod part_msdos
set root=(hd0,msdos1)
</syntaxhighlight>
</source>
Add your regular GRUB2 configuration below the <code>set root</code> line.
 
Finally, all that's left is to create the binary. Note that you have to specify what file to include at what path in the memdisk:
<sourcesyntaxhighlight lang="text">
bin/grub-mkstandalone -O x86_64-efi -o BOOTX64.EFI "boot/grub/grub.cfg=build/grub.cfg"
</syntaxhighlight>
</source>
 
===Blessing the binary on macOS===
Macs require bootable binaries to be 'blessed' by a utility:
<sourcesyntaxhighlight lang="text">
bless --verbose --folder=/Volumes/EFI --file=/Volumes/EFI/EFI/BOOT/BOOTX64.EFI --setBoot
</syntaxhighlight>
</source>
 
== See Also ==