Dealing with no display in Ubuntu

I thought I’d managed to kill Ubuntu today, reinstalled a sound driver that wasn’t working, rebooted and found that I could only boot to a command line. After a short and sensible period of panic, I booted into Windows and searched for a solution. The suggestion that worked was as follows:

startkde had no effect once logged in (still in the command line only). startx launched, but I only got a cursor and a greyish screen, nothing else happened. So I reinstalled the desktop with:

sudo apt-get install ubuntu-desktop

and strictly speaking you want a reboot, but I didn’t need it, startx worked fine for me from there.