Here's what my grub-mkimage looks like (without the preamble)
prefix=
test_only=false
for option in "$@"; do
case "$option" in
--prefix=*) prefix=`echo "$option" | sed 's/--prefix=//'` ;;
--test)
test_only=: ;;
esac
done
GRUB_DEVICE="`grub-probe --target=device /boot`"
case ${GRUB_DEVICE} in
/dev/loop/*|/dev/loop[0-9])
loop_file=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"`
;;
esac
# Is the root loop-mounted from a file on another filesystem?
if [ "x${loop_file}" = x ] || [ ! -f "${loop_file}" ]; then
exit 1
fi
mtpt="${loop_file%/*}"
while [ -n "$mtpt" ]; do
while read DEV MTPT FSTYPE OPTS REST; do
if [ "$MTPT" = "$mtpt" ]; then loop_file=${loop_file#$MTPT} host_mountpoint=$MTPT
break
fi
done < /proc/mounts
mtpt="${mtpt%/*}"
[ -z "$host_mountpoint" ] || break
done
if [ "x${host_mountpoint}" = x ]; then
exit 1
fi
target="${host_mountpoint}/wubildr"
if [ ! -f "$target" ]; then
exit 1
fi
if $test_only; then
exit 0
fi
# TODO You might want to have this as a proper file somewhere in /usr/share
lupin_embedded_cfg=$(tempfile)
cat << EOF >> $lupin_embedded_cfg
set show_panic_message=true
if search -s -f -n $loop_file; then
if loopback loop0 $loop_file; then
set root=(loop0)
if [ -e /grub/grub.cfg ]; then
if configfile /grub/grub.cfg; then
set show_panic_message=false
fi
fi
fi
fi
if [ \${show_panic_message} = true ]; then
echo "It is not possible to boot from the Ubuntu image."
echo "The Windows partition might be corrupted."
echo "Please reboot into Windows and run: chkdsk /r"
echo "Then try again."
fi
EOF
# Watch the modules order!
modules=" \
loadenv biosdisk part_msdos part_gpt fat ntfs ext2 ntfscomp iso9660 loopback \
search linux boot minicmd cat cpuid chain halt help ls reboot \
echo test configfile sh sleep"
Here's what my grub-mkimage looks like (without the preamble)
prefix=
test_only=false
for option in "$@"; do
prefix= `echo "$option" | sed 's/--prefix=//'` ;;
case "$option" in
--prefix=*)
--test)
test_only=: ;;
esac
done
GRUB_DEVICE= "`grub- probe --target=device /boot`" loop/*| /dev/loop[ 0-9]) file=`losetup ${GRUB_DEVICE} | sed -e "s/^[^( ]*(\([^ )]\+\)) .*/\1/" `
case ${GRUB_DEVICE} in
/dev/
loop_
;;
esac
# Is the root loop-mounted from a file on another filesystem?
if [ "x${loop_file}" = x ] || [ ! -f "${loop_file}" ]; then
exit 1
fi
mtpt="$ {loop_file% /*}"
loop_ file=${ loop_file# $MTPT}
host_ mountpoint= $MTPT "${mtpt% /*}"
while [ -n "$mtpt" ]; do
while read DEV MTPT FSTYPE OPTS REST; do
if [ "$MTPT" = "$mtpt" ]; then
break
fi
done < /proc/mounts
mtpt=
[ -z "$host_mountpoint" ] || break
done
if [ "x${host_ mountpoint} " = x ]; then
exit 1
fi
target= "${host_ mountpoint} /wubildr"
if [ ! -f "$target" ]; then
exit 1
fi
if $test_only; then
exit 0
fi
# TODO You might want to have this as a proper file somewhere in /usr/share cfg=$(tempfile) message= true message= false panic_message} = true ]; then
lupin_embedded_
cat << EOF >> $lupin_embedded_cfg
set show_panic_
if search -s -f -n $loop_file; then
if loopback loop0 $loop_file; then
set root=(loop0)
if [ -e /grub/grub.cfg ]; then
if configfile /grub/grub.cfg; then
set show_panic_
fi
fi
fi
fi
if [ \${show_
echo "It is not possible to boot from the Ubuntu image."
echo "The Windows partition might be corrupted."
echo "Please reboot into Windows and run: chkdsk /r"
echo "Then try again."
fi
EOF
# Watch the modules order!
modules=" \
loadenv biosdisk part_msdos part_gpt fat ntfs ext2 ntfscomp iso9660 loopback \
search linux boot minicmd cat cpuid chain halt help ls reboot \
echo test configfile sh sleep"
grub-mkimage ${prefix: +--prefix= "$prefix" } -c $lupin_embedded_cfg $modules | cat /usr/lib/ grub/i386- pc/lnxboot. img - > "$target"
rm $lupin_embedded_cfg || true