% Chapter 8 - Troubleshooting
% Author: Karry
% Co-Author: Tom Swartz
% Co-Author: Ryan

\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 easily fixed. Below, we offer a guide for resolving the basic problems that users may encounter while using Ubuntu OS. If you need any additional help beyond what this chapter provides, then the support options available to you are discussed in \seclink{sec:finding-additional-help-and-support} later in this book. % Completely Re-written - Karry

\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 your Ubuntu OS. This way, you will always be able to roll back your work and give fellow users the information about your previous attempts, in an unlikely event you can turn to the community for support. 
% Completely Re-written - Karry

\subsection{Ubuntu fails to start after I've installed Windows}

% 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. However this is supported by Ubuntu, you might also find that after installing Windows you will no longer be able to start Ubuntu. % Paraphrased - Karry

When you first turn on your computer, a ``bootloader'' must start Ubuntu or another operating system. 
\marginnote{A \textbf{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 \textbf{\acronym{GRUB}} which allows you to choose between the various operating systems on your computer, such as Ubuntu, Windows, Solaris or Mac. 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. % Paraphrased - Karry

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  e.g. English and select \textbf{Try Ubuntu}. Wait until the software loads, after loading you will need to type some commands in order to restore your bootloader. Click on the top-most icon in the launcher, and search for `Terminal' using the search box and then select Terminal in the search results. Now enter the following: % Completely Re-written - Karry

\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 manipulate your Ubuntu installation:

\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 with your Ubuntu operating system once again.

%The current version of the referenced doc does not mention Grub2. - Karry \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}. % Paraphrased - Karry


\subsection{Ubuntu doesn't present the login screen when my computer boots}

The simplest and easiest way to correct this issue is to reset the graphics configuration. Press and hold \textbf{Control} + \textbf{Alt} + \textbf{F1}. You should now see a black and white screen with a prompt for your username and password.
% Paraphrased - Karry

\marginnote{(Characters \textit{will not} appear on the screen as you enter your password. Don't worry this behaviour is normal and was implemented for security purposes).}
% Paraphrased - Karry

Enter your username, and press \textbf{Enter}. Then, enter your password and press \textbf{Enter}. Next, enter the following commands. You will be asked for your password again. % Re-written - Karry

\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}

If you forget your password in Ubuntu, you will need to reset it using the ``Recovery mode.''

To start the Recovery mode, shutdown your computer and then start again.
As the computer starts up, press \textbf{Shift}.
Select the \textbf{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.} % Paraphrased - Karry

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

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 enter 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: % Paraphrased - Karry

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

Login as usual and continue enjoying Ubuntu.

\subsection{I accidentally deleted some files that I need}

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.

\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.''}

Access the trash folder (Unity):

\begin{itemize}
  \item Click on the Trash icon at the bottom of the Unity Launcher.
\end{itemize}

Access the trash folder (Ubuntu Classic):

\begin{itemize}
  \item Click on the trash applet at the far right of the bottom panel.
\end{itemize}

To restore deleted items:

\begin{enumerate}
  \item Click on each item you want to restore to select it. Press and hold \textbf{ctrl} to select multiple items.
  \item Click "Restore Selected Items" to move the deleted items back to their original locations.
\end{enumerate}

\subsection{How do I clean Ubuntu?}

Over time, Ubuntu's software packaging system can accumulate unused packages or 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 \textbf{Terminal} and type:

\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 \textbf{Terminal} and type:

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


\subsection{I can't play certain audio or video files}

Many of the formats used to deliver rich media content are \textbf{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 with one command. Before initiating this command, ensure that you have Universe and Multiverse repositories enabled. See the \seclink{sec:synaptic} 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 Centre} by searching for it from the Dash which is accessed with the top-most button on the Launcher.
  \item Search for \textbf{Ubuntu-restricted-extras} by typing ``Ubuntu restricted extras'' in the search box on the right-hand side of the Ubuntu Software Centre main window. When the Software Centre 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 downloaded from the \application{Ubuntu Software Centre}. Once Ubuntu has successfully installed the software, your rich media content should work properly.

\subsection{How can I change my screen resolution?}

The image on every monitor is composed of millions of little coloured 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 \textbf{Monitors} allows users to change the resolution. Open it by searching for `monitor' from the Dash and selecting it from the search results. 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 \textbf{Apply} will temporarily change the screen resolution to the selected value. 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 \textbf{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}

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}

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.

\subsection{My hardware is not working properly}

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}

