Saturday, December 27, 2008

Backing Up in Ubuntu

One of the most frequent questions on the forums is "How do I back up in Ubuntu?"

Before I started using Ubuntu, I thought the best method was just to copy and paste files using the file manager (that's one way, of course, but it has its limitations). I'm going to recommend a few popular methods. This list isn't comprehensive--it just gives you some places to start. You can always investigate further once you're more comfortable with Ubuntu.

Backing Up Personal Files
rsync is what I use for backing up personal files. I used to copy and paste files using the file manager, but that would involve taking about an hour to back up all my music and erase all the old copies. rsync gives me the ability to copy over only the files that have been modified or added since the last time I backed up. Now, backups take me only about fifteen seconds a week.

The most basic way to use rsync is like this (command goes into the terminal):

rsync -av /path/to/source/directory /path/to/target/directory
For example, let's say your username is alice and you wanted to back up your home directory to your external hard drive that mounts at /media/usbdrive, you would use the command
rsync -av /home/alice /media/usbdrive

If rsync doesn't seem sophisticated enough for you, you can type

man rsync
to find more options than just -av. You can also explore rdiff-backup, which allows you to store (and restore) different date-stamped versions of the same file without taking up too much extra space. And, if you hate the command-line, try installing grsync, which is the graphical frontend to rsync. Here are some screenshots of grsync in action.

Backing Up Whole Installations
Not that System Restore is foolproof in Windows, but it's still a nice feature... at least in theory. Right now, Ubuntu doesn't have anything like System Restore. So if you're going to do any kind of experimental stuff with Ubuntu (for example, installing Beryl or Compiz), it's best to back up your system first.

PartImage is a nice little program that creates an image of your entire partition. You'll need a live CD for this, and you can find more details here about how to use it.

tar is an archiving command, but it can also be used to archive your entire system into one little zipped up bundle. Someone on the Ubuntu Forums wrote a nice little HowTo on backing up and restoring your entire installation using tar.

ddrescue allows you to copy a partition byte for byte to another partition or to a .img file. It's mainly designed for recovery of a crashed drive, but you can also use it as a way to back up (a non-graphical PartImage of sorts). The trick is that the name of the package is ddrescue in the repositories, but the command to use it is dd_rescue. So if you wanted to copy /dev/hda1 to /dev/sda1, you would type in the terminal:

dd_rescue /dev/hda1 /dev/sda1
Keep in mind that /dev/hda1 cannot be in use or mounted. If that requires you using a live CD, then so be it. You can also, if you don't want to erase /dev/sda1 completely, ddrescue to an image file and then mount the image to get the files off it:
dd_rescue /dev/hda1 /dev/sda1/hda1backup.img
sudo mkdir /recovery sudo mount /dev/sda1/hda1backup.img /recovery

How to install MP3 playback in Ubuntu

Assuming you're using Ubuntu 7.04 or later, the easiest way to install MP3 playback in Ubuntu is to just try to play an MP3 file. So start off by finding an MP3 file and then double-click it.

If you're using Ubuntu 6.10 or earlier, the community documentation will show you other methods for installing MP3 playback.

 
Once you do that, Totem will try to play the MP3 file and then realize you do not have the necessary codecs to play MP3 files. It'll ask if you want to search for the appropriate codec. Click onYes to continue.

 
You'll then see a list of possible codecs to install. As you can see, the first one shown enables MP3 playback. So check (or tick) the box next to Gstreamer extra plugins.

 
If you haven't already enabled extra repositories, you'll be asked if you want to install community-maintained software. This will be necessary in order to install the codecs. If you don't know what a repository is, read this overview of software installation in Ubuntu.

 
Wait for the package information to download. Ubuntu is checking to see what software packages and versions are currently available in the community-maintained software repositories.

Once that finishes, try once again to check (or tick) the box next to Gstreamer extra plugins.

 
You'll be warned that this is restricted software and asked if you want to continue. I think this is a generic warning for all non-free software (by the way, non-free refers to freedom, not money). As far as I know, MP3 codecs are legal for users to install in all countries. If you have qualms about installing the necessary codecs, read more about MP3 at Wikipedia. Otherwise, click OK to proceed.

 
Click Apply to install the codecs. Then, just wait for them to install.

 
First, Ubuntu will download the installer files for the codecs.

 
Then, Ubuntu will actually install the codecs.

 
Once the changes have been applied, click Close, and your MP3 should start playing in Totem.


Mounting Windows Partitions in Ubuntu

Ubuntu will automatically mount external drives, but for some reason it will not automatically mount internal drives. So this will show you how to mount (or make available for use) internal NTFS-formatted (i.e., Windows) drives in Ubuntu.

Mount Windows through the file browser

 
If you have your file browser window open, you should be able to double-click on the drive in the sidebar to mount it (or make it available for use). Unfortunately, at least as of Ubuntu 8.04, the drive is identified by its size (in this case, 2.0 GB), so that's how you'll have to figure out which one is the drive you're looking for.

You may have to authenticate the first time, but if you check (or tick) the Remember authorization box, you shouldn't be bothered for it again.

Mount Windows through the menu

If you don't already have your file browser open, you can also mount Windows drives through the menu.

 
Go to Places and find your drive (again, by its size).

 
Whether you mount the drive through the file browser sidebar or through the menu, you can unmount the drive by right-clicking it and selecting Unmount Volume.

Install NTFS Config

But let's say you don't want to manually mount the Windows drive every time you boot up Ubuntu. If you want it permanently mounted, a little utility called NTFS Config can help you.

 
To install it, go to Applications and select Add/Remove

 
Make sure All available applications is showing.

 
Search for ntfs, check (or tick) the box next to NTFS Configuration Tool. Then click Apply Changes in the bottom right of the window and confirm by clicking Apply in the resulting dialogue box.

 
Enter your password when asked.

 
Wait for NTFS Config to install.

Mount an NTFS drive permanently

Now that NTFS Config is installed, let's use it.

 
Go to Applications > System Tools > NTFS Configuration Tool

 
Check (or tick) the box next to the drive (here called /dev/sdb1—what Windows would probably called D:\)

 
Click in the mount point box to name a folder you use to access the Windows drive once it's mounted.

 
If you want it to be mounted at /media/windows, type

windows
Do not type /media/windows or you'll get an error message.

 
When you're done, click Apply

 
Check (or tick) the appropriate boxes, and then click OK

How to install Nvidia drivers in Ubuntu

Ubuntu doesn't include Nvidia drivers in a default installation for a number of reasons. You can read more about Ubuntu's philosophical approach to free and non-free (think freedom, not cost) software and firmware in Mark Shuttleworth's blog. Mark Shuttleworth is Ubuntu's founder and currently its primary funder. New users tend to favor immediate functionality over long-term ideological gains, so if you have an Nvidia graphics card, you may want to install the Nvidia drivers for it.

 
First, go to System > Administration > Hardware Drivers

 
You'll then see that Nvidia drivers are not in use. Check (or tick) the box underneath Enabled to enable the drivers.

 
You'll then be asked (after a brief explanation about desktop effects) if you want to enable the driver. Click Enable Driver.

 
Wait for the installer file to download.

 
Wait for the drivers to be installed.

 
Then, click Close once the changes have been applied.

 
You'll then see that the drivers are enabled and will be available for use upon a reboot.

Editing Files that Belong to Root

If you have experience with Linux but are new to Ubuntu

If you're already familiar with Linux and just wonder why Ubuntu/Kubuntu uses sudo instead of root, this page isn't for you. You're really looking forhttps://help.ubuntu.com/community/RootSudo. It has a full explanation of why Ubuntu uses sudo instead of root and what the advantages and disadvantages of that choice are.

If you are new to Linux and Ubuntu

This page is for people who are new to Linux and Ubuntu/Kubuntu and want to know what the deal is with file permissions.

What you may be used to

My guess is you're probably a typical ex-Windows user (as I was), used to running as Administrator and being able to edit pretty much any file you want—even system files, even the registry—at will, very little stopping you... maybe the occasional "read-only" file that you can just make read/write by checking a little box in the Properties dialogue.

You may also never have installed and configured an operating system before (especially if you bought a computer with Windows preinstalled for you).

The need to edit system files

Some in the Linux camp will say "you shouldn't have to edit such-and-such a file." That's simply not true. Most Linux users aren't just users—they have to install and configure stuff themselves (as Dell or HP won't do it for them), usually configuration files and system files that normal users don't have to touch (say, in order to adjust the possible screen resolutions or install new software). You do have to edit these files from time to time. It's in your best security interests to have to go out of your way to edit them, but you should still be able to occasionally edit, move, copy, and rename files that only an Administrator (or Root) can modify.

Frequently edited system files

In Linux, the only files a user can modify are the ones in her home directory. For example, if the user's name is Bronte, the files she can modify live in the /home/bronte/ folder. Anything outside the /home/bronte folder she will not be able to modify. Some of the top files new installers need to modify are:

/etc/fstab (making hard drives and partitions viewable as folders)
/boot/grub/menu.lst (controlling the boot menu that lets you choose which operating system to boot to)
/etc/apt/sources.list (the list of sources from which you can easily install software)
/etc/X11/xorg.conf (screen resolution options, among other things)

and all of these files need Root privileges to modify.

Why do people recommend the command-line?

If you're like a lot of new Linux users, you probably have not yet embraced the command-line. Some people may have told you to "just"
sudo rm -r /usr/share/icons/themename
as if "rm" really means anything to you yet. The fact of the matter is that people recommend command lines because they're easier instructions to give than "Click on that button that looks like a purple arrow. A new dialogue will pop up with three choices. Pick the left-most choice."

Making system-wide changes graphically

Most new Linux users just want to be able to click and drag and drop. So one of these commands should be your new best friends...

If you're using Ubuntu (Gnome), press Alt-F2 and type

gksudo nautilus

If you're using Kubuntu (KDE), press Alt-F2 and type

kdesu konqueror

If you're using Xubuntu (XFCE), press Alt-F2 and type

gksudo thunar

What does sudo do?

What do these commands do? They allow you to generally operate as a regular user but have a temporary window within your user account to operate as Root (just within the Nautilus or Konqueror window you've opened). Once you close the Root window, it's just as if you're a user again. You don't have to log out of user, log in as Root, make changes, log out of Root, and log back in as user again. You can be Root and user simultaneously.

Mac OS X users may be familiar with this security model (Mac uses sudo, believe it or not!). As a Mac user, you operate as a user. When you want to install something, a dialogue box comes up asking for your administrator (sudo/root) password. Once it's installed, you're a user again.

So how does this work? Let's say you want to edit the /etc/apt/sources.list file. If you want to do it command-line style, you'd

sudo nano /etc/apt/sources.list
and then use Nano to edit it. If you do it the graphical way we've been talking about, you'd run the gksudo nautilus or kdesu konqueror command and a file browser window will pop up (with Root/administrator privileges just in that window). You'd browse to /etc/apt and find the file called sources.list. You'd click to open it, edit it, close it, and close the browser window, and it would be done.

Final recommendations

If you find that (especially right after the initial Ubuntu/Kubuntu install) that you're making a lot of changes as Root, create a launcher with the command gksudo nautilus or kdesu konqueror. Then, when you click on that launcher, you can type in your password, make root changes, and then close the window and be a user again.

Warning: Always make backup copies of any configuration files you modify before modifying them.

Enabling Extra Repositories

Why enable extra repositories?

Repositories contain software. Extra repositories give you extra software. Some people like that. If you need help installing software, check out this page.

Enabling extra repositories the point-and-click way

Many new users are intimidated by the terminal and do not even want to copy and paste commands. If you do not want libdvdcss2 (commercial DVD playback—legality questionable, depending on your country of residence) or w32codecs (Windows codecs—legality extremely questionable, regardless of where you live), the vast majority of your software needs can be met in a very simple point-and-click way—by enabling extra software sources using the GUI (graphical user interface).

 
First, go to System > Administration > Software Sources. In 6.06, it may be called Software Properties. In 6.10 and higher, the name changed to Software Sources.

 
A dialogue will appear that shows you which repositories are currently enabled. The ones with the checked (or ticked) boxes are enabled. The others are not enabled.

 
Check (or tick) the unchecked (or unticked) boxes. You may also want to choose to use a local server instead of the main server. I chose Server for United States, since I live in the United States. You may also want to uncheck (or untick) the CD-ROM/DVD source. Otherwise, every time you try to install software, you may be prompted to insert the Ubuntu installer disc. If you have a working internet connection, you will want to use the online servers for software installation.

 
Once you do this, you'll be asked to reload the repository information. This allows Ubuntu to see what software is newly available to you. Click Reload to continue.

 
Then, wait for the information to be reloaded. Once that's done, the window will disappear, and you'll be able to use apt-get, Synaptic, or Add/Remove to install new programs. More information about software installation can be found here.

Adding a key for Medibuntu

Paste this command into the terminal so you don't get a key error when you see what new software is available:

wget -q http://packages.medibuntu.org/medibuntu-key.gpg -O- | sudo apt-key add -

Backing up and opening the repositories list file

Open up a terminal and type in

If you're using Ubuntu (Gnome):

sudo mv /etc/apt/sources.list /etc/apt/sources.list_backup
gksudo gedit /etc/apt/sources.list

If you're using Kubuntu (KDE):

sudo mv /etc/apt/sources.list /etc/apt/sources.list_backup
kdesu kwrite /etc/apt/sources.list

If you're using Xubuntu (XFCE):

sudo mv /etc/apt/sources.list /etc/apt/sources.list_backup
gksudo mousepad /etc/apt/sources.list

Updating the list for Intrepid

Then copy and paste the following into the (currently empty) text file if you're using Intrepid (8.10):

deb http://archive.canonical.com/ubuntu intrepid partner

deb http://archive.ubuntu.com/ubuntu/ intrepid main universe restricted multiverse

deb http://security.ubuntu.com/ubuntu/ intrepid-security universe main multiverse restricted

deb http://archive.ubuntu.com/ubuntu/ intrepid-updates universe main multiverse restricted

deb http://packages.medibuntu.org/ intrepid free non-free

Updating the list for Hardy

Then copy and paste the following into the (currently empty) text file if you're using Hardy (8.04):

deb http://archive.canonical.com/ubuntu hardy partner

deb http://archive.ubuntu.com/ubuntu/ hardy main universe restricted multiverse

deb http://security.ubuntu.com/ubuntu/ hardy-security universe main multiverse restricted

deb http://archive.ubuntu.com/ubuntu/ hardy-updates universe main multiverse restricted

deb http://packages.medibuntu.org/ hardy free non-free

Updating the list for 7.10 (Gutsy)

Then copy and paste the following into the (currently empty) text file if you're using 7.10 (Gutsy):

## Uncomment the following two lines to fetch updated software from the network
deb http://archive.ubuntu.com/ubuntu gutsy main restricted
deb-src http://archive.ubuntu.com/ubuntu gutsy main restricted

## Uncomment the following two lines to fetch major bug fix updates produced 
## after the final release of the distribution.
deb http://archive.ubuntu.com/ubuntu gutsy-updates main restricted
deb-src http://archive.ubuntu.com/ubuntu gutsy-updates main restricted

## Uncomment the following two lines to add software from the 'universe'
## repository.
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## universe WILL NOT receive any review or updates from the Ubuntu security
## team.
deb http://archive.ubuntu.com/ubuntu gutsy universe
deb-src http://archive.ubuntu.com/ubuntu gutsy universe

deb http://security.ubuntu.com/ubuntu gutsy-security main restricted
deb-src http://security.ubuntu.com/ubuntu gutsy-security main restricted

deb http://security.ubuntu.com/ubuntu gutsy-security universe
deb-src http://security.ubuntu.com/ubuntu gutsy-security universe

deb http://archive.ubuntu.com/ubuntu gutsy multiverse
deb-src http://archive.ubuntu.com/ubuntu gutsy multiverse

deb http://archive.ubuntu.com/ubuntu gutsy-backports main restricted universe multiverse

deb http://archive.canonical.com/ubuntu gutsy partner

deb http://packages.medibuntu.org/ gutsy free non-free

Updating the list for 6.06 (Dapper)

Then copy and paste the following into the (currently empty) text file if you're using Dapper (6.06):

## Uncomment the following two lines to fetch updated software from the network
deb http://archive.ubuntu.com/ubuntu dapper main restricted
deb-src http://archive.ubuntu.com/ubuntu dapper main restricted

## Uncomment the following two lines to fetch major bug fix updates produced
## after the final release of the distribution.
deb http://archive.ubuntu.com/ubuntu dapper-updates main restricted
deb-src http://archive.ubuntu.com/ubuntu dapper-updates main restricted

## Uncomment the following two lines to add software from the 'universe'
## repository.
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## universe WILL NOT receive any review or updates from the Ubuntu security
## team.
deb http://archive.ubuntu.com/ubuntu dapper universe
deb-src http://archive.ubuntu.com/ubuntu dapper universe

deb http://security.ubuntu.com/ubuntu dapper-security main restricted
deb-src http://security.ubuntu.com/ubuntu dapper-security main restricted

deb http://security.ubuntu.com/ubuntu dapper-security universe
deb-src http://security.ubuntu.com/ubuntu dapper-security universe

deb http://archive.ubuntu.com/ubuntu dapper multiverse
deb-src http://archive.ubuntu.com/ubuntu dapper multiverse

deb http://archive.ubuntu.com/ubuntu dapper-backports main restricted universe multiverse

deb http://archive.canonical.com/ubuntu dapper-commercial main

deb http://packages.medibuntu.org/ dapper free non-free

Making the changes take effect

Save your file and close kwrite, mousepad, or gedit. Lastly, and most importantly, paste this into the terminal
sudo apt-get update


Installing Software in Ubuntu

Introduction

Most Windows users who migrate to Ubuntu end up confused about software installation. They go to a website, download a .tar.gz file, double-click it, and don't see a Next-Next-Next-Finish wizard. This tutorial is intended to introduce you to the preferred methods of software installation in Ubuntu.

Rather than leaving it up to the user to track down installer files and keep applications updated, Ubuntu (like many other Linux distributions) has a software package management system that provides a searchable database of easily installable applications (like an online shopping cart but the software is cost-free), which it will download and install for you with a few clicks.

Installing 101: Add/Remove
The best place to start with this package management process is to use a simple interface for it called Add/Remove.

  
Start by going to Applications and selecting Add/Remove. Add/Remove will then check to see what applications are installed and/or available for installation.

 
The default filter shows Supported applications only. These are the official packages released by Canonical, the company behind Ubuntu.

Third party applications can be maintained by the Ubuntu user community or an outside business.

All Open Source applications will show the software that isn't proprietary.

Probably, when you're starting out, you want to show All available applications, just so you have the largest selection of software to choose from.

  
You then have the option to search and/or browse for applications. In this case, I searched for hearts to find the card game Hearts. Since it's in the community-maintained online software repository, and this is the first time I'm accessing that repository, Add/Remove will confirm with me that I want to Enable it.

   
Then, to install Hearts, I check (or tick) the box next to the program, click Apply, enter my password, and click OK.

   
Add/Remove will then fetch the installer files, install the files, and then let you know when the software is installed. Afterwards, it gives you the option to start the application you just installed, add or remove more applications, or just close Add/Remove.

Advanced interface: Synaptic Package Manager
Another interface for the package manager is Synaptic. Synaptic works very similarly to Add/Remove, but it has more advanced options. It allows you more categories and custom filters, and shows you supporting libraries (not just user applications).

  
To access Synaptic, go to System > Administration > Synaptic Package Manager. Then enter your password and click OK

   
You can click the Search button or press Control-F to search for software. Once you've found the software you want to install, right-click it and mark it for installation.

    
Once you've marked all the software packages you want to install (or remove, too), click Apply, confirm by clicking Apply when prompted, and then wait for the package files to download and install. Once they've installed, click Close.

Manual download: .deb
Most of the time, if you need software, you can use Add/Remove or Synaptic to install it from the online repositories. Sometimes, software is not available in the repositories, and you have to go to a website to download it. If you are able to download a file with a .deb extension, this is the software package format Ubuntu prefers.

   
For example, Skype is not in the default Ubuntu repositories, so you can go to the Skype website, and download the Ubuntu package.

Note: Skype doesn't always update their Ubuntu packages. So, for example, in this screenshot Skype lists the installer file as being for Ubuntu 7.04, but I'm using Ubuntu 8.04. Opera, on the other hand, even if it hasn't changed its browser version numbers will have all the Ubuntu release versions to choose from. Try to select whichever version seems most appropriate.

    
Once the .deb file is on your desktop, double-click it to install it. You'll be prompted for your password, and then you can just wait for it to install.

 
You should then be able to use Skype or whatever application you installed.

Last resorts: .rpm and .tar.gz
The preferred way to install software in Ubuntu is to use the package manager, which you can access through Add/Remove or Synaptic. As we've seen with Skype, sometimes you can also find a .deb for software not in the repositories. But what if you can't find a .deb?

.rpm
If you can't find a .deb, you can try a .rpm. These files are packaged for other Linux distributions (usually Fedora or Mandriva), but there is an application called alien (which you can install using Synaptic) that allows you (most of the time) to convert .rpm files to .deb. Read more about this process.

.tar.gz
As a last resort, you can download a .tar.gz file. The .tar.gz file extension indicates the file is a compressed set of files and folders (the compressed files you see in Windows usually have a .zip extension). If you see the .tar.gz, it could be compressed files that have a precompiled binary file, or it could be compressed files that have the source code allowing you to compile the application from source.