If you need to shut down X server to get to a command prompt or install NVidia graphics drivers, you can do so by typing the following command:
sudo init 3
That command will not only shut down GDM and lightDM, it will shut down X server as well. To resume X server, type the following command:
sudo init 5