Fixing boot problems
Start-up problems. That moment when – having expected yourself to be getting on with your day’s work or entertainment – you find yourself staring at a cryptic error message, or even worse, a blank screen.
No matter how many times you press reset or restart, the same impenetrable barrier blocks your path. So, what can you do? Start-up problems come in all shapes and sizes, and they can be difficult to track down.
There are, however, some sound principles to use that will resolve many errors, and in this tutorial, we’re going to look at the tools and techniques required to troubleshoot most start-up problems. You should start by examining how the boot process works.
This reveals that the boot process can be split into three broad stages centred around the Grub 2 boot loader: pre-Grub, Grub and post-Grub. Knowing this allows you to focus your troubleshooting efforts based on where in the process the error or freeze occurs.
Let’s start at the beginning. You switch on your PC. If power comes on, but nothing else happens, chances are you’ve a hardware issue to sort – if you recently poked around the innards of your PC, then check everything is connected correctly.
If not, unplug all external devices except your keyboard and try again. If this doesn’t work, open the case carefully and disconnect your internal drives too. If the computer now boots to the splash screen, you can try reconnecting the internal drives and trying again; if you’re now able to boot to the login screen, shut down your PC and start reconnecting your external peripherals to see if the problem has cleared itself or can be targeted to a single device, in which case try a different cable, or go online and Google for known boot problems involving that device.
If you’re lucky, your motherboard will emit a series of beeps or flashing lights you can use – again by enlisting the help of the internet – to identify the likely problem. This may involve replacing a component or something more drastic.
If you’re able to get as far as your PC’s splash screen, but then your computer hangs or a ‘missing operating system’ error message appears, then first think back to any recent changes.
If you’ve overclocked your PC, eg, you should now enter the system EFI or BIOS and look for the option to load fail-safe defaults. Try rebooting again.
If this fails, then the problem is likely to be with your hard drive, and so the first places to look are the MBR and Grub. If Grub isn’t set to automatically appear when your PC starts, try rebooting while holding the Shift key or tapping Esc to bring up the Grub boot menu to confirm it’s not able to even load itself.
Jump to the Boot-Repair tool section once you’ve verified it’s nowhere to be found.
If Grub is able to load, but can’t find any bootable OS you’ll find yourself with a number of scenarios: you may be presented with a basic command prompt such as grub> or grub rescue>, which indicates one or more files required by Grub are missing or corrupt.
You may get a specific error message or frozen splash screen, or you may just see Grub and nothing else, indicating it can’t even find the most basic information required to proceed.
If you press C you may be able to enter the Grub Terminal mode to perform basic checks and repairs – you can attempt to manually initiate the boot by pressing Ctrl+X or F10, eg, or use the set command to review current settings and change basic settings such as the graphics mode.
If the Grub menu appears, then the issue may lie with its configuration file if things immediately grind to a halt after you select a menu option, but if Linux does start loading before grinding to a halt, the problem will lie with your operating system, in which case skip to the Post-Grub troubleshooting section.
If you’re struggling to fix Grub issues by hand, or there’s no sign of Grub on your system at all, then you’ll need to enlist the services of your rescue media and the Boot-Repair tool, which works with all Debian-based distros, including Ubuntu.
The Boot-Repair tool itself will launch automatically when you boot from a Boot-Repair tool disc, but if you’re unable to create it, but have access to a Linux installation disc, use that in a live environment instead, then grab the Boot-Repair tool using the following commands:
$ sudo add-apt-repository ppa:yannubuntu/boot-repair
$ sudo apt-get update
$ sudo apt-get install boot-repair
The Boot-Repair tool is focussed on those early boot problems caused by the hard drive’s boot sector, MBR and Grub. It basically provides a convenient and user-friendly graphical front-end to the tools required to fix many problems.
The tool offers a ‘Recommended repair’ option that promises to fix most frequent problems, or you can click ‘Advanced options’ to see what it can do and manually select specific fixes without getting your hands dirty in the Terminal.
The step-by-step guide (see Tweak Boot-Repair tool Settings later in this guide) reveals what repairs and tweaks are possible, but note the tool is context-sensitive, and some options may be greyed out or missing depending on your setup.
The tool automatically generates a log of your system and that it attempts to do, which you can then share on the Ubuntu user forums if necessary. Before attempting any advanced tweaks on your own, it pays to try the recommended option first, then ask for help on the forums using the output logs generated – this will ensure you choose the right option and don’t cause more damage.
The Boot process
When you press your system’s power button, control is initially given to your PC’s EFI or BIOS, which starts its various components, performs basic diagnostics tests and attempts to find a bootable device, which is typically the first hard drive.
Once located, the BIOS or EFI looks for the Master Boot Record (MBR) at the very beginning of the drive, which has a tiny program inside that loads the next stage of the boot loader, reading a file (eg e2fs_stage_1_5), which in turn is able to load the Grub boot loader.
A ‘missing operating system’ error at this point means you need your rescue disc for diagnostics as something is missing – either in Grub, the MBR or the drive itself. Once Grub loads successfully it reads a file called menu.lst, which contains the list of choices you see in the boot menu. Each entry basically identifies the drive, partition and file that contains the Linux kernel, plus RAM disk file used by the kernel as it boots.
The entry will also contain any additional parameters passed to the kernel. Control is now passed to the kernel, which attempts to mount the root file system. This is a key moment, and if it fails you may get a kernel panic, or things might grind to a halt. If successful, it’ll create a single process to run the /sbin/upstart file (other distros use init) – if this goes wrong, you’ll get a panic, it may halt again or drop you into a root shell.
At this point, upstart starts running scripts and upstart events to start other services and eventually bring you to the logon screen.
Non-Grub boot issues
Your rescue disc will also come in handy should you not even get as far as Grub loading. Once booted, verify the existence and state of your hard drive.
Open the file manager and see if your partitions are visible and if you can access the files on them – this is a good time to back up any precious files before you proceed further.
If nothing shows up, check whether the hard drive has been detected by opening the Disks utility from your Ubuntu Live CD – if you’re using a Boot-Repair tool CD, you’ll need to install the gnome-disk-utility through the Synaptic Package Manager under System Tools.
Once installed, open it via the Accessibility menu. The Disks tool lists all physically attached drives – if yours isn’t visible, you may find the drive has failed, in which case you’ll be reaching for your latest backup after shelling out for a drive replacement, or starting again from scratch with a fresh Ubuntu installation and new-found love of backing up your system.
Assuming your drive does show up, select it from the left-hand menu where you can examine the partition table plus check its physical health via its SMART attributes. Don’t panic unless the drive is deemed on its last legs, but do focus your next check on the partitions themselves.
If you run the Boot-Repair tool, its recommended settings will include a full disk check, but you can manually perform this check yourself using GParted, which is on both rescue discs. GParted enables you to see how your partitions are arranged, as well as revealing which one is the boot.
Right-click this and verify Mount is greyed out before choosing ‘Check to schedule a disk check using the fsck tool’. This will check for and attempt to repair any problems it finds as soon as you click ‘Apply’, but it’s important the partition isn’t mounted before the check is run. Also give it as long as it needs to complete – this could take hours or even days in some extreme cases, and cancelling or aborting will almost certainly corrupt the partition.
Make sure the check is run on all partitions on the boot drive. In most cases, assuming the drive isn’t physically damaged or corrupt beyond repair, running these tests should ensure you’re able to at least get Grub working again.
Take a fail-safe backup
It may seem strange, but if you’re struggling with start-up issues, you should attempt to take a backup of your hard drive before you perform any repairs – this means if you mess things up completely you can always roll back your system to the state it was in when the start-up problem first manifested itself.
Of course, if you’re diligent and you back up your system regularly, you could always simply roll things back now to a working state, although bear in mind there may be data loss involved if your home folder is on the same partition as your Linux installation (as is the case with default Ubuntu installs).
You’ll need a suitable backup device – typically a USB-connected hard drive – and a tool that takes a complete drive image of your system. The dd command-line tool can be used from both Ubuntu and Boot Repair Tool live CD environments, but the backup drive needs to be at least the same size – and preferably – bigger than the drive you’re copying.
At the other end of the complexity scale is Redo Backup & Recovery. You’ll need a blank CD or DVD to burn its 261MB ISO file to, but it provides an easy to follow graphical UI.
If you find that Grub appears to be working fine, but your problems begin when you attempt to load Linux itself. Try switching to verbose mode during boot by pressing the Esc key to see if any clues appear in the messages that scroll past (or if it hangs at a certain point).
Make a note of these and do a search online for them for more advice. If this doesn’t happen, hold Shift at boot to bring up the Grub menu if necessary, then select ‘Advanced options’ followed by ‘(recovery mode)’, which will launch Ubuntu in a minimal state, plus mount the file system in read-only mode.
If this is successful, after a succession of scrolling messages you should find yourself presented with the Recovery Menu, offering nine options. The options are all pretty much self-explanatory – the clean option may be of use if your hard drive is full, which can cause boot problems.
If your problems started because a package failed to install properly, then dpkg will repair it and hopefully get things working again. The failsafeX option is a useful if you find yourself booting to a black screen or the graphical desktop doesn’t appear to be working correctly – it basically bypasses problems with your graphics drivers or X server to give you a failsafe graphics mode to troubleshoot your problem from.
We’ve touched on fsck already – this will check the drive for corrupt files, which can clear many errors, particularly if your PC crashed and has failed to boot since. The grub option isn’t relevant unless you’ve used Grub’s own recovery tools in place of the Boot-Repair tool to get this far in the boot process – selecting this will make your changes permanent.
Use the network option to re-enable networking, and the root option to drop to the shell prompt, allowing you to troubleshoot directly from there. If doing so, be sure to mount the file system in read/write mode using the following command:
mount -o remount,rw /
You can also pass temporary kernel parameters to Ubuntu during the boot process, which may help in some scenarios.
With your chosen operating system selected in Grub, press the e key to edit the kernel file. Scroll down to the line beginning linux – parameters are added to the end of this line after quiet splash . You’ll need to make sure that you leave a space between each parameter. Once done, press Ctrl+X to boot with those parameters. Note that any parameters you add here are temporary –
in other words, they’re removed the next time you boot, so you can experiment until you find a solution that works, then – if necessary – make it permanent by editing the Grub configuration file (sudo nano /etc/default/grub).
You can also pass parameters from the live CD environment using the Boot-Repair tool using the ‘Add a kernel option’, which includes 15 common parameters that can help with troubleshooting. Examples of these include acpi=off, which disables the ACPI system that’s known to cause random reboots or system freezes on certain PCs, and nomodeset, which instructs Ubuntu to only load graphics drivers after the X environment has been loaded, and not before.
These temporary parameters can be passed to your rescue disc too, in case you’re having problems getting that working. Press F6 at the initial boot screen to choose from the options on show. For more information on specific parameters, do an online search for the parameter.
There’s one last thing you can try from the Grub boot menu – if your kernel has been upgraded, it’s possible to boot using an older version of the kernel from the Advanced options screen under Grub. You’ll see each version of the kernel listed – try the previous version if you believe your boot problem is linked to the latest kernel.
If this works, you can make the version you’ve used permanent by editing the Grub configuration file – the simplest way to do this is by using the Boot-Repair tool.
If things look particularly bleak, then you may have luck reinstalling Ubuntu over the top of itself. Boot from the Ubuntu Live CD and choose the option to ‘Install Ubuntu’ when prompted. When you get to the ‘Installation type’ screen you’ll be presented with a new option, pre-selected by default: ‘Reinstall Ubuntu…’
This option basically reinstalls Ubuntu without touching your home folder or partition, which means not only should your documents and other files be preserved, but key settings and many programs may be left alone too. It’ll also leave entries in your boot menu alone, ensuring you won’t lose access to other operating systems.
What will be replaced are system-wide files, which will hopefully root out any corrupt ones and get your PC up and running again. Although it doesn’t affect your files, it’s still good practice to back up the drive – or at least your home folder or partition – before you begin.
To ensure you don’t lose anything from your system, make sure you recreate all user accounts with the same login and password, including – of course – your own during the install process.
Tweak Boot-Repair tool settings
1. Main options
The first tab offers a convenient button for backing up your current partition table, boot sector and log – click this to copy this key information. It’s also where you can reinstall Grub, restore the MBR and choose whether to hide the Grub menu.
If you think your filesystem is corrupt, tick ‘Repair file systems’ to have it checked and fixed.
2. Grub location
This tab allows you to specify which OS to boot by default in a multiboot setup. You can also choose to place Grub in its own separate /boot partition if you wish – typically this is only needed on encrypted disks, drives with LVM set up or some older PCs.
The final option specifies which drive Grub itself will be placed (sda by default).
3. Grub options
This section opens with options for making sure Grub is updated to its latest version. There’s also three specific error fixes offered. You can also add new kernel options to the Grub menu here, or purge all previous kernels before reinstalling the last one.
You may even see an option allowing you to edit the Grub configuration file directly.
4. Other tweaks
If the MBR options tab isn’t greyed out, use it to restore your MBR from a backup and choose which partition gets booted from it. The final Other options tab offers an opportunity for repairing Windows files (irrelevant in most cases) and provides options for pasting a summary of your settings online for reference.
- Enjoyed this article? Expand your knowledge of Linux, get more from your code, and discover the latest open source developments inside Linux Format. Read our sampler today and take advantage of the offer inside.