% 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)

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

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

Sometimes, things may not work as they should. Luckily, problems that are encountered while working with Ubuntu are often easily fixed. Below, we offer a guide for resolving the basic problems that users may encounter while using Ubuntu. If you need any additional help beyond what this chapter provides, 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 an effective troubleshooting is to work slowly, complete all of troubleshooting steps, and to document the changes that you make to Ubuntu. This way, you will be able to undo your work, or give fellow users the information about your previous attempts in cases when you need to turn to the community for support. 


\subsection{Ubuntu fails to start after I've installed Windows}
\index{boot!cannot choose Ubuntu}
% Using the command line from Ubuntu live CD 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 by Ubuntu, but you might also find that after installing Windows you will no longer be able to start Ubuntu.

When you first turn on your computer, a ``bootloader'' must start Ubuntu or another operating system. 
\marginnote{A \define{bootloader} is the initial software that loads the operating system when you switch on the computer.}
When you installed Ubuntu, you installed an advanced bootloader called \define{\acronym{GRUB}} which allows you to choose between the various operating systems on your computer, such as Ubuntu, Windows, Solaris or Mac OS X. However, when you installed Windows, it replaced the \acronym{GRUB} with its own bootloader, thus removing the ability to choose which operating system you'd like to use. You can restore \acronym{GRUB} and regain the ability to choose your operating system by using the same \acronym{CD} you used to install Ubuntu. 

First, insert your Ubuntu \acronym{CD} into your computer and then restart it, making sure to have your computer start from the \acronym{CD} (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 and then select Terminal in the search results. A window should open with a blinking prompt line. Enter the following, and press Enter:

\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 (/dev/sda1, /dev/sda2, etc) we are looking for is identified by the word ``Linux'' in the System column. Modify the instructions below if necessary, replacing /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 /dev/sda1, but your computer is booting to /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, first create a place to connect your existing existing Ubuntu installation with your temporary troubleshooting session:

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

Next, link your Ubuntu installation and this new folder:

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

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

\begin{terminal}
\prompt \userinput{ls /media/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=/media/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}

Finally, remove the Ubuntu disc from your \acronym{CD-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{Ubuntu doesn't present the login screen when my computer boots}
\index{login screen!missing}
The simplest and easiest way to correct this issue is to reset the graphics configuration. Press and hold \keystroke{Ctrl+Alt+F1}. You should now see a black and white screen with a prompt for your username and password.
\marginnote[-2\baselineskip]{(Characters \emph{will not} appear on the screen as you enter your password. This behavior is normal and was implemented for security purposes).}

Enter your username, and press \keystroke{Enter}. Then, enter your password and press \keystroke{Enter}. Next, enter the following commands, pressing \keystroke{Enter} after each line. You will be asked for your password again.

\begin{terminal}
\prompt \userinput{sudo cd /etc/X11}
\prompt \userinput{sudo mv ./xorg.conf ./xorg.conf\_old}
\prompt \userinput{sudo service gdm stop}
\prompt \userinput{sudo X -configure}
\prompt \userinput{sudo mv ./xorg.conf.new ./xorg.conf}
\prompt \userinput{sudo reboot now}
\end{terminal}

Now Ubuntu will reboot, and your login screen should be restored.

\subsection{I forgot my password}
\index{security!passwords, resetting}
If you forget 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{08-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 and press the Enter key and then re-type your password again, and press Enter. (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!deleting and recovering}
If you've deleted a file by accident, you may be able to recover it from Ubuntu's trash folder. This is a special folder where Ubuntu stores deleted files before they are permanently removed from your computer.

\begin{comment}
\marginnote{The Trash folder is called different things in various parts of the desktop. This could cause confusion. This is a known issue and will be resolved in the next version of \acronym{GNOME}. The Trash folder could also be know as the ``Wastebasket'' or ``Deleted Items Folder.''}
\end{comment}

To access the 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 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?}
\index{Ubuntu!clean!removing temporary files}
Over time, Ubuntu's software packaging system can accumulate unused packages and temporary files. These temporary files, also called caches, contain files from all of the packages that you have installed.  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 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! will not play}
\index{video! will not play}
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 may install the files necessary for using this format from the Ubuntu Software Center. Ensure that you have Universe and Multiverse repositories enabled before continuing. See the \seclink{sec:software-sources} section to learn how to do this.
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 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!resolution, 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.

%\screenshotTODO{gnome-display-properties screenshot with resolution dropdown open}
\screenshot{08-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 for you. 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. It allows you to revert to the previous resolution setting or keep the new resolution. The dialog box will disappear in 30 seconds, restoring the old resolution.

%\screenshotTODO{gnome-display-properties screenshot of confirm or revert dialog}
\screenshot{08-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 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!help, 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. For instructions on doing this, visit the web page above.

\subsection{Ubuntu is not working properly on my Asus EeePC}
\index{EeePC!help, 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}
sudo update-grub
\end{terminal}
After the command finishes, and you restart the computer, you will be able to use the Fn Keys normally. 

\subsection{My hardware is not working properly}
\index{hardware!troubleshooting}
Ubuntu occasionally has difficulties running on certain computers, generally when hardware manufacturers use non-standard or proprietary components. The Ubuntu community offers documentation to help you troubleshoot many common issues that may arise from this situation, including problems with wireless cards, scanners, mouse 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 or issue 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}

