Every so often it is necessary to reboot a computer. When things are behaving strangely and your machine has been up for a while, shutting everything down and powering up again is a great first step to diagnosing the issue, and often resolves the problem.
A few months ago, I noticed that my server occasionally wouldn't come back up after a reboot. This was particularly painful to troubleshoot because my server is headless (no monitor). After lugging the machine over to my TV and hooking it up, I powered it up and was greeted with a black screen displaying a flashing cursor.
This caused quite the scare the first time it happened. Why can't it find the OS?? After a few Google searches, I found a boot repair program that reinstalls the grub bootloader. Sounds like it's worth a try!
I shut down my server, plugged in a bootable Ubuntu 14.04 Desktop USB, changed my BIOS settings to boot from it, and powered back up.
Once booted, I used the boot repair program to install grub on my SSD. After it finished, I changed my BIOS back to boot from the SSD, held my breath, and rebooted.
I saw the trusty1 wine-colored Ubuntu background, a few seconds later my desktop appeared, and nothing looked out of place. It worked!
Sigh of relief.
Over the next few months, the issue recurred seemingly randomly. I got to the point where I was reluctant to reboot for fear of it not coming back up. I'm an engineer; we like to solve problems, not live with them.
I knew the problem was grub-related, since reinstalling it consistently resolved the issue. I first hypothesized a permissions issue with /etc/grub, but this couldn't be the case since the file is only writable by root, as a quick ls -lsa revealed.
Finally, one day I had to reboot a few times without a hitch, then updated my software:
$ sudo apt-get update
$ sudo apt-get upgrade
I then rebooted, and my server didn't come back up. This couldn't be coincidental — whatever I updated must have broken grub!
I checked aptitude to see what was recently updated (Source):
cat /var/log/dpkg.log | grep "\ install\ "
I noticed grub in the list. That must be the culprit. A few minutes of searching revealed the command I needed (Source):
$ sudo debconf-show grub-pc
...
* grub-pc/install_devices: /dev/disk/by-id/[My USB drive ID here]
...
As you can see from the output above, when grub updates, it was installing on my USB stick, not my SSD. This made sense — when I first built my server, I was booting from a USB 3.0 drive. That turned out to be impractical, but grub never forgot.
To change grub's install location to my SSD, I ran:
sudo dpkg-reconfigure grub-pc
This opens a set of prompts guiding you through changing the grub install destination. Use the arrow keys and space to select the correct drive, then press Return. I re-ran debconf-show grub-pc to verify it listed my SSD.
Since making this change, I have updated grub and rebooted many times without issue. Case officially closed.
If you have any questions, comments, or corrections, please feel free to reach out!
1 "Trusty Tahr" is the codename for Ubuntu 14.04 LTS.