I will guess that the SD card is not booted fully before your code tries to access it.