% Chapter 8 - Troubleshooting
% Author: Elan Kugelmass (up to Maverick)

% Author: Mario Burgos (Natty) 
% Author: Steve Richards (Natty)
% Editor: Kartik Sulakhe (Natty)

% Author: Karry (Oneiric)
% Co-Author: Tom Swartz (Oneiric)
% Co-Author: Ryan (Oneiric)

%Editor: Mario Burgos (Precise)

%Author: Patrick Dickey (Raring)
%Editor: David Pires (Raring)

\chapter{Troubleshooting}
\label{ch:troubleshooting}

\section{Resolving problems}
\label{sec:troubleshooting:resolving-problems}

Sometimes things may not work as they should. Luckily, problems encountered while working with Ubuntu are often easily fixed. This chapter is meant as a guide for resolving basic problems users may encounter while using Ubuntu. If you need any additional help beyond what is provided in this chapter, take a look at other support options that are discussed in \seclink{sec:finding-additional-help-and-support} later in this book.

\section{Troubleshooting guide}
\label{sec:troubleshooting:troubleshooting-guide}

The key to effective troubleshooting is to work slowly, complete all of the troubleshooting steps, and to document the changes you made to the utility or application you are using. This way, you will be able to undo your work, or give fellow users the information about your previous attempts\dash the latter is particularly helpful in cases when you look to the community of Ubuntu users for support. 


\subsection{Ubuntu fails to start after I've installed Windows}
\index{booting!troubleshooting}

% Using the command line from Ubuntu live DVD to reinstall Grub.

Occasionally you may install Ubuntu and then decide to install Microsoft Windows as a second operating system running side-by-side with Ubuntu. This is supported in Ubuntu, but you might also find after installing Windows that you will no longer be able to start Ubuntu.

When you first turn on your computer, a ``bootloader'' is responsible for initiating the start of an operating system, such as Ubuntu or Windows. 
\marginnote{A \define{bootloader} is the initial software that loads the operating system when the computer is powered up.}
When you installed Ubuntu, you automatically installed an advanced bootloader called \define{\acronym{GRUB}}. \acronym{GRUB} allows you to choose between the various operating systems installed on your computer, such as Ubuntu, Windows, Solaris, or Mac \acronym{OS~X}. If Ubuntu was installed first, then Windows was installed, the Windows installation removed \acronym{GRUB} and replaced the bootloader with it's own. As a result, you can no longer choose an operating system to use. You can restore \acronym{GRUB} and regain the ability to choose your operating system by following the steps below, using the same \acronym{DVD} you used to install Ubuntu. 

First, insert your Ubuntu \acronym{DVD} into your computer and then restart the computer, making sure to instruct your computer to boot from the \acronym{DVD} drive and not the hard drive (see \chaplink{ch:installation}). Next, choose your language (\eg, English) and select \menu{Try Ubuntu}. Once Ubuntu starts, click on the top-most icon in the Launcher (the Dash icon). Then, search for \userinput{Terminal} using the search box. Then, select Terminal in the search results. A window should open with a blinking prompt line. Enter the following, and press the  \keystroke{Enter} key:

\begin{terminal}
\prompt \userinput{sudo fdisk -l}
\begin{verbatim}
Disk /dev/hda: 120.0 GB, 120034123776 bytes
255 heads, 63 sectors/track, 14593 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1        1224       64228+  83  Linux
/dev/sda2   *        1225        2440     9767520   a5  Windows
/dev/sda3            2441       14593    97618972+   5  Extended
/dev/sda4           14532       14593      498015   82  Linux swap

Partition table entries are not in disk order
\end{verbatim}
\end{terminal}

\marginnote{The device (\texttt{/dev/sda1}, \texttt{/dev/sda2}, etc.) we are looking for is identified by the word ``Linux'' in the System column. Modify the instructions below if necessary, replacing \texttt{/dev/sda1} with the name of your Linux device.}
This output shows that your system (Linux, on which Ubuntu is based) is installed on device \texttt{/dev/sda1}, but as indicated by the asterisk in the Boot column, your computer is booting to \texttt{/dev/sda2} (where Windows is located). We need to fix this by telling the computer to boot to the Linux device instead. 

To do this, create a place to connect your existing Ubuntu installation with your temporary troubleshooting session:

\begin{terminal}
\prompt \userinput{sudo mkdir /mnt/root}
\end{terminal}

Next, link your Ubuntu installation and this new folder:

\begin{terminal}
\prompt \userinput{sudo mount /dev/sda1 /mnt/root}
\end{terminal}

If you've done this correctly, then you should see the following:

\begin{terminal}
\prompt \userinput{ls /mnt/root}
bin    dev      home        lib    mnt   root     srv  usr
boot   etc      initrd      lib64  opt   sbin     sys  var
cdrom  initrd.img  media  proc  selinux  tmp  vmlinuz
\end{terminal}

Now, you can reinstall \acronym{GRUB}:

\begin{terminal}
\prompt \userinput{sudo grub-install -{}-root-directory=/mnt/root /dev/sda}
Installation finished. No error reported.

This is the contents of the device map /boot/grub/device.map.
Check if this is correct or not. If any of the lines is incorrect,
fix it and re-run the script \commandlineapp{grub-install}.
(hd0) /dev/sda
\end{terminal}

Next you'll want to unmount the hard drive. This ensures that the drive won't become corrupted when you reboot:

\begin{terminal}
\prompt \userinput{sudo umount /mnt/root}
\end{terminal}

Finally, remove the Ubuntu disc from your \acronym{DVD-ROM} drive, reboot your computer, and then start enjoying your Ubuntu operating system once again.

%The current version of the referenced doc does not mention Grub2. \marginnote{When following the instructions, please note that your Ubuntu installation uses Grub2. This guide replicates the method described in the first section of the referenced web page. Please consider starting with the third section, \url{https://help.ubuntu.com/community/RecoveringUbuntuAfterInstallingWindows}.}

This guide may not work for all Ubuntu users due to differences in the various system configuration. Still, this is the recommended and most successful method for restoring the \acronym{GRUB} bootloader. If you are following this guide and if it does not restore \acronym{GRUB} on your computer, then try the other troubleshooting methods at \url{https://help.ubuntu.com/community/RecoveringUbuntuAfterInstallingWindows}.


\subsection{I forgot my password}
\index{security!resetting passwords}
If you forgot your password in Ubuntu, you will need to reset it using the ``Recovery mode.''

To start the Recovery mode, shut down your computer and then start again.
As the computer starts up, press \keystroke{Shift}.
Select the \menu{Recovery mode} option using the arrow keys on your keyboard. Recovery mode should be the second item in the list. \screenshot{07-troubleshooting-grub-boot-screen.png}{ss:grub-boot-screen}{This is the grub screen in which you can choose recovery mode.}

Wait until Ubuntu starts up \dash this may take a few minutes. Once booted, you \emph{will not} be able to see a normal login screen. Instead, you will be presented with the \menu{Recovery Menu}. Select \menu{root} using the arrow keys and press \keystroke{Enter}.

You will now be at a terminal prompt:

\begin{terminal}
root@ubuntu:\textasciitilde\#
\end{terminal}

To reset your password, enter:

\begin{terminal}
\# \userinput{passwd \emph{username}}
\end{terminal}

Replace ``username'' above with your username, after which Ubuntu will prompt you for a new password. Enter your desired password, press the \keystroke{Enter} key, and then re-type your password again, pressing the \keystroke{Enter} again when done. (Ubuntu asks for your password twice to make sure you did not make a mistake while typing). Once you have restored your password, return to the normal system environment by entering:

\begin{terminal}
\# \userinput{init 2}
\end{terminal}

Login as usual and continue enjoying Ubuntu.

\subsection{I accidentally deleted some files that I need}
\index{files!recovering}
If you've deleted a file by accident, you may be able to recover it from Ubuntu's \application{Trash} folder. This is a special folder where Ubuntu stores deleted files before they are permanently removed from your computer.

\begin{comment}
\marginnote{The \application{Trash} folder is called different things in various parts of the desktop, resulting in some confusion to newer Ubuntu users. This is a known issue and will be resolved in the next version of \acronym{GNOME}. The \application{Trash} folder is also known as the ``Wastebasket'' or ``Deleted Items Folder.''}
\end{comment}

To access the \application{Trash} folder click on the trash icon at the bottom of the Unity Launcher.

%c7p - No classic ubuntu theme anymore, so i deleted the relevant paragraph 

If you want to restore deleted items from the \application{Trash}:

\begin{enumerate}
  \item Open \application{Trash}
  \item Click on each item you want to restore to select it. Press and hold \keystroke{Ctrl} to select multiple items.
  \item Click \button{Restore Selected Items} to move the deleted items back to their original locations.
\end{enumerate}

\subsection{How do I clean Ubuntu?}
Ubuntu's software packaging system accumulates unused packages and temporary files through regular updates and use. These temporary files, also called caches, contain files from all of the installed packages. Over time, this cache can grow quite large.  Cleaning out the cache allows you to reclaim space on your computer's hard drive for storing your documents, music, photographs, or other files.

To clear the cache, you can either use the \code{clean}, or the \code{autoclean} option for the command-line program \commandlineapp{apt-get}.

\marginnote{The \code{clean} command will remove every single cached item, while the \code{autoclean} command only removes cached items that can no longer be downloaded (these items are often unnecessary).}
To run \code{clean}, open \application{Terminal} and enter:

\begin{terminal}
\prompt \userinput{sudo apt-get clean}
\end{terminal}

Packages can also become unused over time. If a package was installed to assist with running another program\dash and that program was subsequently removed\dash you no longer need the supporting package. You can remove it with \code{apt-get autoremove}.

Load \application{Terminal} and enter:

\begin{terminal}
\prompt \userinput{sudo apt-get autoremove}
\end{terminal}


\subsection{I can't play certain audio or video files}
\index{sound!troubleshooting}
\index{video!troubleshooting}
Many of the formats used to deliver rich media content are \emph{proprietary}, meaning they are not free to use, modify, or distribute with an open-source operating system like Ubuntu. 
Therefore, Ubuntu does not include the capability to use these formats by default; however, users can easily configure Ubuntu to use these proprietary formats. 
For more information about the differences between open source and proprietary software, see \chaplink{ch:learning-more}.

If you find yourself in need of a proprietary format, you can install the required files from the Ubuntu Software Center. Ensure that you have the Universe and Multiverse repositories enabled before continuing. See the \seclink{sec:software-sources} section to learn how to enable these repositories.
When you are ready to continue, install the necessary software as follows:

\begin{enumerate}
  \item Open the \application{Ubuntu Software Center} by searching for it from the Dash (the top-most button on the Launcher).
  \item Search for \filepath{ubuntu-restricted-extras} by typing ``Ubuntu restricted extras'' in the search box on the right-hand side of the Ubuntu Software Center main window. When the Software Center finds the appropriate software, click the arrow next to its title.
  \item Click \button{Install}, then wait while Ubuntu installs the software.
\end{enumerate}

One program that can play many of these formats is \acronym{VLC} media player. It can be installed from the \application{Ubuntu Software Center}. Once Ubuntu has successfully installed this software, your rich media content should work properly.

\subsection{How can I change my screen resolution?}
\index{display!troubleshooting}
The image on every monitor is composed of millions of little colored dots called pixels. Changing the number of pixels displayed on your monitor is called ``changing the resolution.'' Increasing the resolution will make the displayed images sharper, but will also tend to make them smaller. The opposite is true when screen resolution is decreased. Most monitors have a ``native resolution,'' which is a resolution that most closely matches the number of pixels in the monitor. Your display will usually be sharpest when your operating system uses a resolution that matches your display's native resolution.

The Ubuntu configuration utility \application{Displays} allows users to change the resolution. Open it by clicking on the \menu{session indicator} and then on \menu{Displays\ldots}.
The resolution can be changed using the drop-down list within the program. Picking options higher up on the list (for example, those with larger numbers) will increase the resolution.

\screenshot{07-troubleshooting-display-properties.png}{ss:display-properties}{You can change your display settings.}

You can experiment with various resolutions by clicking \button{Apply} at the bottom of the window until you find one that is comfortable. Typically, the highest resolution will be the native resolution. Selecting a resolution and clicking \button{Apply} will temporarily change the screen resolution to the selected value, and a dialog box will also be displayed for 30 seconds. This dialog box allows you to revert to the previous resolution setting or keep the new resolution setting. If you've not accepted the new resolution and/or 30 seconds have passed, the dialog box will disappear and the display's resolution will return to its previous setting.

\screenshot{07-troubleshooting-display-properties-confirm.png}{ss:08-display-properties-confirm}{You can revert back to your old settings if you need to.} This feature was implemented to prevent someone from being locked out of the computer by a resolution that distorts the monitor output and makes it unusable. When you have finished setting the screen resolution, click \button{Close}.

% Section withheld for future manual version..
%\subsection{Performing a file system check}

%---End withheld section -- b^2

\subsection{Ubuntu is not working properly on my Apple MacBook or MacBook Pro}
\index{MacBook!troubleshooting}
When installed on notebook computers from Apple \dash such as the MacBook or MacBook Pro \dash Ubuntu does not always enable all of the computer's built-in components, including the iSight camera and the Airport wireless Internet adapter. Luckily, the Ubuntu community offers documentation on fixing these and other problems. If you are having trouble installing or using Ubuntu on your Apple notebook computer, please follow the instructions at \url{https://help.ubuntu.com/community/MacBook}. You can select the appropriate guide after identifying your computer's model number. 

\subsection{Ubuntu is not working properly on my Asus EeePC}
\index{EeePC!troubleshooting}
When installed on netbook computers from Asus \dash such as the EeePC \dash Ubuntu does not always enable all of the computer's built-in components, including the keyboard shortcut keys and the wireless Internet adapter. The Ubuntu community offers documentation on enabling these components and fixing other problems. If you are having trouble installing or using Ubuntu on your Asus EeePC, please follow the instructions at \url{https://help.ubuntu.com/community/EeePC}. This documentation page contains information pertaining specifically to EeePC netbooks.

To enable many of the features and Function Keys, a quick fix is to add ``acpi\_osi=Linux'' to your grub configuration. From the Terminal
\begin{terminal}
\prompt \userinput{gksudo gedit /etc/default/grub}
\end{terminal}
and very carefully change the line
\begin{terminal}
GRUB\_CMDLINE\_LINUX\_DEFAULT="quiet splash"
\end{terminal}
to
\begin{terminal}
GRUB\_CMDLINE\_LINUX\_DEFAULT="quiet splash acpi\_osi=Linux"
\end{terminal}
Save and close the file. Then, from the terminal:
\begin{terminal}
\prompt \userinput{sudo update-grub}
\end{terminal}
After the command finishes, and you restart the computer, you will be able to use the \keystroke{Fn} keys normally.

\subsection{My hardware is not working properly}
\index{hardware!troubleshooting}
Ubuntu occasionally has difficulty running on certain computers, usually when hardware manufacturers use non-standard or proprietary components. The Ubuntu community offers documentation to help you troubleshoot many common issues in this situation, including problems with wireless cards, scanners, mice, and printers. You can find the complete hardware troubleshooting guide on Ubuntu's support wiki, accessible at \url{https://wiki.ubuntu.com/HardwareSupport}. If your hardware problems persist, please see \seclink{sec:troubleshooting:getting-more-help} for more troubleshooting options or information on obtaining support or assistance from an Ubuntu user.

\section{Getting more help}
\label{sec:troubleshooting:getting-more-help}

This guide does not cover every possible workflow, task, issue, or problem in Ubuntu. If you require assistance beyond the information in the manual, you can find a variety of support opportunities online. 

More details about many support options available to you can be found at \seclink{sec:finding-additional-help-and-support} later in this book.

% Commented out by Chris Woollard as I felt it was better to not duplicated the options available. They are covered much better in the learning more chapter.

%You can access extensive and free documentation, buy professional support services, query the community for free support or explore technical solutions.
%More information is available here: \url{http://www.ubuntu.com/support}

