Since commit 8aa517eb7 it is necessary to call _mount_device_and_volumes() prior making any modifications to boot files. In addition handle potential errors from the grub.cfg modification better.
8aa517eb7