For now this is done by borrowing prep-bootdev.c from grub-installer, incurring a dependency on libparted.