My hard disk is
/dev/sdb in machine B. Later it should be used as
/dev/sda in machine A. It contains the root partition
/ and boot directory
/boot for machine A.
Is it possible to install grub in advance in machine B?
Just install grub to /dev/sdb
grub, by default, uses uuid, so it should work.
If you have problems for any reason, you would need to reinstall grub after the transfer.