- Your System
- Applications
- Multimedia
- Networking
- Hardware
- System Administration
- Other
- Summary
System Administration
Traditionally, Linux has been very popular with system administrators. This has not only been due to Linux's incredible flexibility and power, but also the Unix philosophy that drives much of the Linux platform. System administrators spend much of their day in the command line crafting strings of commands that hook together to do something interesting. With this powerful underlying command line platform, so much is possible.
System administration is sometimes fraught with its own fair share of problems though. This section lines up some of the problems and attempts to resolve them.
How Do I Schedule Things to Happen?
Built right into Ubuntu is a very powerful system to schedule things to happen at specific times or at regular intervals. This system, called cron, allows you to specify the timing details and the command to run in a special file called a crontab.
The crontab is a simple text file that holds a list of commands that are to be run at specified times. These commands, and their related run times, are controlled by the cron daemon and are executed in the system's background. More information can be found by viewing the crontab's man page, and we will run through a simple crontab example later to demonstrate how it is used.
The system maintains a crontab for each user on the system. In order to edit or create a crontab, you need to load it into a text editor. This text editor is opened when you use the -e option on the crontab command. To create a crontab, open a terminal and run the following command:
foo@bar:~$ crontab -e
The default nano text editor will open an empty crontab file. When adding crontab instructions, each line represents a separate crontab entry, also known as a cron job.
Crontab Sections
A typical line in a crontab looks like this:
00 1 3 5 10 ps ax
Each of the sections is separated by a space, with the final section having one or more spaces in it. No spaces are allowed within Sections 1–5, only between them. Sections 1–5 are used to indicate when and how often you want the task to be executed. This is how a cron job is laid out from the left to right:
- minute: (0–59)
- hour: (0–23, 0 = midnight)
- day: (1–31)
- month: (1–12)
- weekday: (0–6, 0 = Sunday)
- command: Code
If you read each line in the crontab from the left and use the above column descriptions, you can see how the instruction is built up. As an example:
01 04 1 1 1 /usr/bin/somedirectory/somecommand
The above example runs /usr/bin/somedirectory/somecommand at 4:01 A.M. on any Monday which falls on January 1. An asterisk (*) can be used so that every instance (every hour, every weekday, every month, etc.) of a time period is used. Code:
01 04 * * * /usr/bin/somedirectory/somecommand
The above example will run /usr/bin/somedirectory/somecommand at 4:01 A.M. on every day of every month.
Comma-separated values can be used to run more than one instance of a particular command within a time period. Dash-separated values can be used to run a command continuously:
01,31 04,05 1-15 1,6 * /usr/bin/somedirectory/somecommand
The above example will run /usr/bin/somedirectory/somecommand at 01 and 31 past the hours of 4:00 A.M. and 5:00 A.M. on the 1st through the 15th of every January and June.
The /usr/bin/somedirectory/somecommand text in the above examples indicates the task which will be run at the specified times. It is recommended that you use the full path to the desired commands as shown in the above examples. The crontab will begin running as soon as it is properly edited and saved.
Crontab Command Options
There are a number of options you can pass to the crontab command to make it do different things. Here are some common options:
- The -l option causes the current crontab to be displayed on standard output.
- The -r option causes the current crontab to be removed.
- The -e option is used to edit the current crontab using the editor specified by the VISUAL or EDITOR environment variables.
When you edit a crontab file, the modified crontab is checked for accuracy and, if there are no errors, installed automatically.
An Example
Below is an example of how to set up a crontab to run updatedb, which updates the slocate database: Open Konsole and type crontab-e and press Enter, and type the following line, substituting the full path for the one shown below, into the editor:
45 04 * * * /usr/bin/updatedb
Save your changes, and exit the editor. Crontab will let you know if you made any mistakes. The crontab will be installed and begin running if there are no errors. That's it. You now have a cron job setup to run updatedb, which updates the slocate database, every morning at 4:45.
Note that a semicolon (;) or the double-ampersand (&&) can also be used in the command section to run multiple commands consecutively:
45 04 * * * /usr/sbin/chkrootkit && /usr/bin/updatedb
The semicolon will cause both commands to be executed. The double ampersand will cause the second command to execute only if the first command does not fail. The above example will run chkrootkit and updatedb at 4:45 A.M. daily, providing you have all listed applications installed.
How Can I Copy a File from One Computer to Another?
The easiest way to copy files between machines is to use the Places > Connect to Server dialog box to make a connection using the graphical file manager. If you would prefer to do this on the command line, use the following command:
foo@bar:~$ scp file.txt jimmy@chin.com:/home/jimmy
The scp command works the same as the normal cp command, but it copies the file (file.txt) to another server (chin.com) using a specific user account (jimmy) and into a particular directory on the remote computer (/home/jimmy).
I Know an Application Is Available in Ubuntu but Synaptic Can't Find It
If you are browsing through Synaptic and can't find a package that you know is available for Ubuntu, it is likely that you have not enabled the additional repositories.
To fix this, load Synaptic and click Settings > Repositories. Click the Add button, and select the Community and Nonfree checkboxes. Click OK to accept the settings and then OK on the Repositories window. Finally, click the Reload button to refresh the package list. Your package should now be listed.
I Am Running Ubuntu on an Older Computer, and I Would Like a Faster Desktop
Unlike other OS, Linux has the flexibility to scale incredibly well across different computers with different levels of horsepower. With the huge range of Open Source available, you can tweak your system so that it can be optimized in lots of different areas. This is particularly useful for recycling PCs. A number of large organizations will throw out older hardware that is unable to run the latest OS from Microsoft. In many cases, these computers are actually perfectly usable if the software is optimized a little. Some Open Source groups have set up to take these old machines, install Linux, and provide them to their local communities.
The first aspect to optimize is the GUI. The default desktop in Ubuntu uses GNOME, and GNOME requires a reasonable degree of processing power. If you don't need many of the features in GNOME and literally just want to start applications, using something such as ICEWM may be a better choice. Load Synaptic, and ensure the Community repository is enabled. Install the icewm and menu packages. Now log out, and before you log back in, click the Options menu to change your session from the default one to the icewm one. A number of alternative desktop environments are available. For more functionality than icewm, try installing the xubuntu-desktop package and running the xfce session, also seen in Xubuntu (see Figure 6-9).
Figure 6-9 Also look at the Xubuntu distribution, which includes the lightweight xfce4 instead of GNOME.
You may also want to explore applications that are more lightweight. As an example, instead of using OpenOffice.org for word processing, try Abiword. It is a featureful but lightweight word processor. Try the following alternatives:
- Web Browser: Instead of Firefox, use Galeon.
- Terminal: Use an xterm instead of the GNOME terminal.
- Spreadsheet: An alternative to OpenOffice.org for spreadsheets is Gnumeric.
I Have Reinstalled Windows, and Now Ubuntu Won't Start!
The first thing your computer does when you turn it on is read a special place on your hard disk called the master boot record (MBR). The information written there tells the computer what to do next. When you installed Ubuntu, it placed a boot menu on the MBR that lets you choose from which system to boot.
Unfortunately, when you reinstall Windows it will recreate the MBR, not taking into consideration that any other OS may exist and replacing it with an MBR that only boots Windows. This is no good, and you naturally want to be able to replace it with the menu that lets you choose which system to boot.
Grab the CD you used to install Ubuntu on your computer. If you don't have it anymore, download a CD image from www.Ubuntu.com/download, and burn it on a blank CD. If you used the desktop CD to install, you will need to use the alternate install CD with the traditional text mode installer.
Insert the CD in the drive, and restart your computer. It will boot on the CD instead of using the hard disk as usual. Now highlight the Rescue a Broken System line, and press Enter. Select your language and keyboard, and let the installer detect the network (for the computer name, you can leave the default Ubuntu) just like when you installed Ubuntu for the first time.
You will then be presented with a list of available partitions on your hard disks. Don't worry about the first line (/dev/disks/disk0/part1). Start looking at the other lines. You need to remember on which disk and on which partition Ubuntu is installed. Most of the time, you probably have just one disk. If you have Windows installed on it, it is probably located on the first partition of this disk, and Ubuntu should be on the second one. Therefore, you probably want to select /dev/disks/disk1/part2 (then press Enter), unless your situation is more complex.
On the last screen, select the first line Execute a shell in.... You can now enter commands. Start by mounting the disks on your system:
foo@bar:~# mount -a
Now type:
foo@bar:~# df
Look at the list printed on the screen. Search the last column for the single / character, and on the corresponding line look for the first column. It should say something such as /dev/hda2 (the last few characters may be different for you). Now type the following command, and replace /dev/hda with what you have just read, but without the last digit (/dev/hda instead of /dev/hda2 in the above example):
foo@bar:~# grub-install /dev/hda
Wait for the process to finish. It might take a few minutes. About a dozen lines should have appeared on the screen. Check whether you find the text "installation finished." If you do, everything went fine. You can now restart your computer by typing
foo@bar:~# exit
Eject the CD, and then select Reboot the System. Welcome back to Ubuntu!
How Do I Fix My Disk after a Power Failure?
Although the Ubuntu development team takes every care to ensure every possible situation is catered for, one of the most difficult problems is power outages. Computers rely on power, and when it is dramatically removed from the system, the whole Ubuntu world in your computer shuts down immediately. The problem with this is that sudden power failure causes your Ubuntu machine to shut down improperly. When you next start the computer you may then be prompted with a confusing fsck message. What is this and how do you fix it?
The fsck program is a little tool to fix hard disks that don't have consistent filesystems; filesystems typically made inconsistent by power failures. When the disk is inconsistent, Ubuntu automatically runs fsck to fix it. It asks you a bunch of questions that only a filesystem developer really understands, and you feel obliged to say Yes to each of them. As such, you sit there hammering the Y key over and over answering the questions.
There is a quick and simple fix to this problem. Instead of wearing out your Y key, you can simply edit one file and have any errors automatically fixed for you.
If your system is already running the desktop, open a terminal. and enter the following command:
foo@bar:~$ sudo gedit /etc/default/rcS
Now change the FSCKFIX line to the following:
FSCKFIX=yes
Save the file, and the next time you reboot fsck will fix any detected disk problems without you having to intervene.
If you are using the character-based login, use the following command:
foo@bar:~$ sudo nano /etc/default/rcS
Change the FSCKFIX line as above and then press Ctrl-O and Ctrl-X to save and exit.
Ubuntu Takes Up Too Much Disk Space on My Old Computer
If you are running Ubuntu on an older computer with a limited amount of disk space, you may want to choose software with more limited space requirements. Luckily, Ubuntu is incredibly flexible in choosing which software you want to install.
Install Ubuntu from the alternate install disk (not the desktop CD). When you have booted the installer, choose Install a Server, and install Ubuntu as usual. When you have rebooted into your minimal install, log in and type:
foo@bar:~$ sudo nano /etc/apt/sources.list
Press the down cursor until you reach the line
# deb http://archive.Ubuntu.com/Ubuntu/ dapper universe main restricted multiverse
Press the X key twice to delete the # symbol at the beginning of that line. Save the file by typing :wq, and then hit Enter. Here you have enabled a repository. If you have enabled repositories in the past in Synaptic, this is what happens behind the scenes. You can manage your repositories by simply editing /etc/apt/source.list.
Now run the following commands:
foo@bar:~$ sudo apt-get update foo@bar:~$ sudo apt-get install x-window-system-core xterm wdm icewm menu
This whole system can be installed on a disk with less than 1G of free space.
My Computer Is Running Quite Slowly—How Can I Find Out What Is Going On?
If you are having performance problems, there may be a particular process on your computer gobbling up all of the memory. To find out what is happening, run the following command:
foo@bar:~$ top
The top command shows the current processes on your computer that are using the most system resources. If you see a particular program taking up an unusual amount of resources, that may be the culprit.
Some processes (such as the Apache Web server) fork and replicate themselves when used. Another useful technique is to see how many of these processes are running:
foo@bar:~$ ps ax | grep theprogram | wc -1
This command takes a listing of the processes running on the system, uses grep to search for a specific process and then counts the number of lines returned, thus indicating how many processes are running.
How Can I Find Out the Different Options for Commands?
Every command that is included in Ubuntu has a small reference card, called a man page, included. This page displays the range of options that are available. Access it by typing man, and then enter the command:
foo@bar:~$ man grep
Another method of listing the options is to use the -h or –help options:
foo@bar:~$ grep –help
How Do I Get My Root Account Back?
In a default Ubuntu installation, the root account is disabled. Instead, the user account that is created in the installation process is used with sudo to access administrator facilities. The sudo command is used extensively to temporarily take on root privileges when needed.
If you want to get the root account back, run the following command:
foo@bar:~$ sudo passwd root
Now enter your user account's password and then enter a new root password. You will be asked to verify the new root password.
To disable the root account at a later date, run the following command:
foo@bar:~$ sudo passwd -l root
This will lock the root account.
I Forgot My System Password—What Can I Do?
Although passwords are indefinably essential and useful, they are also prone to being forgotten. With an increasing number of nasties out there on the Internet wanting to suck your password away, you need to think of more complex passwords, which are in turn harder to remember and easier to forget.
If you forget the system password, you need to jump through a few more hoops to reset your password. Reset your computer and when you see the word GRUB appear on the screen, press Escape to see the boot menu. Select the recovery mode option from the menu. When the computer boots it will present you with a root shell. At the prompt type:
foo@bar:~# passwd <username>
Follow the prompts to set a new password. Finally, reboot the computer with the following command:
foo@bar:~# reboot
How Do I Access My Windows Partitions?
If you are running Ubuntu on a computer with a Windows disk, you may want to read and write to the disk. Ubuntu can safely read the Windows NT NTFS partitions and can read and write to Windows 95/98/2000 FAT32 partitions.
First, load a terminal, and use the fdisk command to know what partitions you currently have:
foo@bar:~$ sudo fdisk -l
The output should be similar to this:
Disk /dev/hda: 81.9 GB Device Boot Start End Blocks Id System /dev/hda1 * 1 1306 10490413+ 7 HPFS/NTFS /dev/hda2 1307 1311 40162+ 83 Linux /dev/hda3 1312 1344 265072+ 82 Linux swap /dev/hda4 1345 9964 69240150 f W95 Ext'd (LBA) /dev/hda5 1345 1606 2104483+ b W95 FAT32 /dev/hda6 1607 2852 10008463+ 83 Linux ...
In this output, the /dev/hda1 partition (the first partition on the first disk) is a 10GB Windows NTFS partition (probably called C:) and /dev/hda5 is a 2GB FAT32 partition (probably called D:).
When you access a disk, you need to mount it first. To mount it, you need to indicate a directory where the files from the disk are accessed—this is called a mount point. Create mount points in /media for the Windows partitions. It is good to use /media/C for C: and /media/D for D:, etc. to make things easy to remember.
foo@bar:~$ sudo mkdir /media/C /media/D
To make the disks accessible when you boot the computer, you need to add a few lines to /etc/fstab. This file indicates which disks are available. Add the following two lines:
/dev/hda1 /media/C ntfs nls=utf8,umask=0222 0 0 /dev/hda5 /media/D vfat defaults,umask=0000 0 0
The fourth column lets you specify options for mounting the partition, and nls=utf8,umask=0222 means that any user can read the NTFS partition.
To mount the two partitions without restarting, run the following command:
foo@bar:~$ sudo mount -a
The two partitions are now available and will be automatically mounted the next time Ubuntu is restarted.
Ubuntu Is Slow on My AMD K7 Computer
The computer world is filled with different processors, including but not limited to Intel, AMD, Cyrix, Transmeta, Arm, Sun, and IBM processors. Although Linux supports each of these processors, the Linux kernel can often be optimized for specific processors.
First, load Synaptic. Click the Search button, and type in k7. Find and install the Linux-k7 package. Close Synaptic, and restart the computer. Hit Escape when you see GRUB appear to display the boot menu. Select the k7 kernel, and it will use the new kernel. Your system will work exactly the same as before, but it will be that little bit quicker.
How Do I Add Users?
To add a new user to your computer select System > Administration > Users and Groups. When the window loads, click the Add User button, and then just fill in the details. To do this in the command line, use the adduser command:
foo@bar:~$ sudo adduser jimmy
This adds a user called Jimmy.