+declare -A ADDITIONAL_MODULES
+ADDITIONAL_MODULES[i386-pc]="biosdisk"
+
+if ifclass AMD64 ; then
+ if [ -r "${target}"/usr/lib/grub/x86_64-efi/moddep.lst ] ; then
+ ARCHS+=(x86_64-efi)
+ ADDITIONAL_MODULES[x86_64-efi]="efi_gop efi_uga"
+ else
+ echo "/usr/lib/grub/x86_64-efi/moddep.lst could not be found, skipping."
+ echo "NOTE: grub-efi-amd64-bin not installed?"
+ fi
+fi
+
+BOOTX64="${BOOTX64##${target}}"
+EFI_IMG="${EFI_IMG##${target}}"
+TMP_CONFIG="${TMP_CONFIG##${target}}"
+
+for arch in ${ARCHS[@]} ; do
+$ROOTCMD grub-mkimage -O $arch -o /boot/$arch.img --prefix=/boot/grub/ --config="$TMP_CONFIG" \
+ bitmap boot btrfs cat chain cmp configfile cpio echo elf ext2 \
+ fat gfxmenu gfxterm gzio help iso9660 jpeg linux loopback lvm \
+ memdisk minicmd multiboot normal part_gpt part_msdos play png \
+ probe raid regexp reiserfs search search_fs_file search_fs_uuid \
+ search_label squash4 terminal test video videoinfo xfs ${ADDITIONAL_MODULES[$arch]}
+done
+
+if [ -f "${target}/boot/i386-pc.img" ] ; then
+ mv "${target}/boot/i386-pc.img" "${target}/boot/grub/grub.img"
+fi
+
+if [ -f "${target}/boot/x86_64-efi.img" ] ; then
+ mv "${target}/boot/x86_64-efi.img" "${target}/${BOOTX64}"
+fi