Create an Apple Mac .disk_label with grub-render-label
Apple's firmware is fussy about disk labels, and grub-render-label is the GRUB tool that renders one. Feed it a short string or a text file and it writes out the binary .disk_label the firmware expects. Allow about ten minutes. You need a Linux shell, the grub-render-label command from grub-common, and a GRUB PF2 font. The examples use GRUB 2.12-1ubuntu7.3, installed here on Ubuntu.
The route
Jump straight to the step you need, or tick off Done means at the end.
- What it does. Produces an Apple-specific GRUB label image, nothing more.
- What it will not touch. It does not install GRUB, alter boot entries, write a disk, or change firmware settings.
- Where it writes. The examples write under
/tmpor your working directory, so none of them needsudo.
1. Check the installed command and font
First confirm which program will run and record its version:
$ command -v grub-render-label
/usr/bin/grub-render-label
$ grub-render-label --version
grub-render-label (GRUB) 2.12-1ubuntu7.3
The installed manual documents -f or --font as accepting a PF2 font file. Common GRUB installations provide unicode.pf2 under /usr/share/grub. Locate one rather than guessing a path:
$ find /usr/share/grub -type f -name '*.pf2' -print
/usr/share/grub/unicode.pf2
/usr/share/grub/euro.pf2
/usr/share/grub/ascii.pf2
Use a font that contains the characters in your label. If no PF2 file is found, stop here and install the GRUB package through your normal distribution process. Do not copy a font from an arbitrary website into a boot directory.
2. Render a label from a string
Supply the label with -t and the destination with -o. This example keeps the generated file in a temporary directory while you check it:
$ workdir=$(mktemp -d /tmp/grub-label-XXXXXX)
$ grub-render-label \
--font=/usr/share/grub/unicode.pf2 \
--text='Example Mac' \
--output="$workdir/example.disk_label"
$ printf 'status=%s\n' "$?"
status=0
There is no text preview in the terminal: a successful run just produces binary data. Check its type and size instead of eyeballing it:
$ file "$workdir/example.disk_label"
/tmp/grub-label-XXXXXX/example.disk_label: data
$ wc -c < "$workdir/example.disk_label"
1671
Tip
The byte count depends on the text, font and rendering options, so do not treat 1671 as a target. The two facts worth checking are a zero exit status and a non-empty file. file may report simply data, because a .disk_label is not always recognised by its magic number.
3. Read the label from a file
Use -i or --input when the label is maintained in a file, or handed over by another step in a build. Keep the input as plain text:
$ printf '%s\n' 'Recovery Mac' > "$workdir/label.txt"
$ grub-render-label \
--font=/usr/share/grub/unicode.pf2 \
--input="$workdir/label.txt" \
--output="$workdir/recovery.disk_label"
$ test -s "$workdir/recovery.disk_label" && echo 'label created'
label created
The input file is read, not replaced. Keep it under version control or in your build inputs if the label must be reproducible. A trailing newline can end up as part of the input, so write the file deliberately and check the rendered result on the target Mac.
4. Keep binary output away from the terminal
The manual says the default output is standard output. That is fine in a pipeline, but running an unredirected render in an interactive terminal is asking for trouble: the result is binary, not readable text.
$ grub-render-label \
--font=/usr/share/grub/unicode.pf2 \
--text='Example Mac' \
> "$workdir/piped.disk_label"
$ test -s "$workdir/piped.disk_label" && echo 'standard output captured'
standard output captured
Use --output when the destination is a named file, and shell redirection only when the command is one stage in a pipeline. A zero exit status only tells you this render completed; it is not proof that a bootloader will accept the label.
5. Choose colours or verbose diagnostics carefully
The command exposes separate options for background and text colour, but the installed manpage does not define a colour vocabulary. Do not assume a value accepted by another GRUB tool is valid here: test any chosen values in a temporary output file before they go anywhere near an image-building script.
Add --verbose when a render fails and you need to know why. Keep the output file separate while testing:
$ grub-render-label --verbose \
--font=/usr/share/grub/unicode.pf2 \
--text='Example Mac' \
--output="$workdir/verbose.disk_label"
$ printf 'status=%s, bytes=%s\n' "$?" "$(wc -c < "$workdir/verbose.disk_label")"
status=0, bytes=1671
That byte count is an example from this installed version, not a required constant. A different label, font or package build produces a different size.
6. Avoid overwriting a useful label
Warning
Writing to an existing path can replace the previous label. Render to a new temporary name, verify it, and only then move it into place, deliberately:
$ new_label="$workdir/example.disk_label.new"
$ grub-render-label \
--font=/usr/share/grub/unicode.pf2 \
--text='Example Mac' \
--output="$new_label"
$ test -s "$new_label"
$ mv -- "$new_label" "$workdir/example.disk_label"
$ test -s "$workdir/example.disk_label" && echo 'replacement installed'
replacement installed
The mv only changes the destination within the temporary directory, so if rendering fails, the old file is untouched because the new path was separate all along. If you are replacing a label inside a boot image or a mounted system, follow that image's backup and recovery procedure first: this command itself has no undo.
7. Diagnose the common failures
Missing arguments usually means the command was not given enough to render. Check that you supplied a text or input file, an output destination or redirection, and a usable font:
$ test -r /usr/share/grub/unicode.pf2 && echo 'font readable'
font readable
$ test -r "$workdir/label.txt" && echo 'input readable'
input readable
$ grub-render-label --help
- Input path wrong? Check it with
ls -landtest -rwithout changing anything. - Font path wrong? Rerun
find /usr/share/grub -type f -name '*.pf2'. - Output empty? Inspect the exit status and stderr before reusing the destination.
- Do not reach for sudo as a generic repair. It fixes none of the above: not a missing argument, an invalid font, or a bad path.
For a final check, compare the output size and, where possible, inspect the label through the Apple Mac boot workflow that will actually consume it. Keep the original input and any previous boot image until that check succeeds.
Done means
- Version and font checked.
grub-render-labelis the intended GRUB version and a readable PF2 font was selected. - Source is deliberate. The label came from
--textor a plain-text--inputfile you chose on purpose. - Output captured, not printed. Binary output was written to a file, never left unredirected into an interactive terminal.
- Result verified. The output has a zero exit status and is non-empty.
- Replacement staged safely. Any replacement was rendered to a separate path first, with the previous file kept until verified.