9. Maintenance (Debian)

We’re together

9.1. Review

You’ve learnt a lot about Linux. You know what the purpuse of a distribution is and why you need one. You know the most essential parts of any Linux operating system already. You know how the system interacts with programs. You know who maintains a system. You know how the file tree and to locate stuff.

9.1.1. Test questions

  1. Which part of the OS is maintained by the Linux foundation?
  2. How do you search in less? How do you go through the search results?
  3. How are programs represented in a computer?
  4. Explain in your own words what a daemon is.
  5. What is a library? Where is it stored?
  6. Which daemon deals with system monitoring?

9.2. Some clever title

One of the best features of Debian is how you manage software. If you’re familiar with the Windows system, you’re used to download programs from shady websites and run them as Administrator (which is similar to the root user). This is bad. Like really, really bad. And you won’t need to resort to this on Debian [1]. Even better, you don’t need to spend hours searching for halfway usable programs. OK, there’s still a lot of discussion about which software is the best (the more adult discussions at least consider the context). But you get this as free as in ‘free beer’ and it’s usually considered a good thing to have a choice.

The way you install software on Debian is via a central repository. At the first glance, it’s a list of approved, supported and tested software. That’s already a good thing but there’s more. The repository also contains the software itself. And a tool to download and install the software. We call a system like this a package manager. In a nutshell, your benefits are

  • One trusted source of software.
  • Easy installation through a single command.
  • An integrated updating mechanism.
  • Clean system and automatic dependency resolution.

The last point needs some more explanation. You’ve already learnt that program code can be spread among several files. That’s because programmers are lazy. If someone else has already written code you need, why bother writing it a second time? No, let’s just copy it! So, in fact many programs share the same source code. The shared code is kept seperate from the program’s main code. You’ve seen this before, the files containing shared code are called libraries and are usually stored in a lib directory. This way you install the shared code only once instead of once per program. In fact, this setup is the same on every Unix system (so basically all OS besides Windows [2]).

But for every program, you have to know which libraries you have to install. We call this a dependency. Pretty obviously because the program depends on the existence of the library. So when you install a program, the package manager checks for you what else is needed and installs it (unless it’s already there). That’s the automatic dependency resolution. With this technique, you’ll have to download less and the system requires less disk space - at no extra maintenance effort.

On Debian, the package manager comes in two parts: The Debian Package Manager dpkg and the Advanced Package Tool apt. The former installs and removes software (i.e. what to put where, how software is delivered to you). The latter handles the external repository and the dependencies. The repository is stored on an internet server, so apt requires an internet connection.

OK, enough work, let’s have a look at this. First, let’s show a list of packages you have installed. A package anything installed, mostly (but not limited to) programs [3].

dpkg --get-selections

Wow, this is a huge list.

_images/less_dpkg_selection.png

Most of the packages come with the base system and are there because they’re a dependency to another program. So don’t worry if you haven’t seen most of the items there. The list is alphabetically sorted, so check if flite is there and installed. It’s probably not the case, so we can install it. First, let’s run a search.

apt-cache search flite

apt keeps a local copy of the package index - that’s the list of available packages, their description and dependencies. This local copy is the cache. With the apt-cache command you can run operations on the cache, such as searching (name and description). Other methods provide you more details about the package (show) or its dependencies (depends).

_images/apt_search_flite.png

So the above versions searches the packages for any one matching flite. You see the simple flite there, that’s the one we’re going to install. From the description, you see what it is going to do.

sudo apt-get install flite

The program and all of its dependencies are automatically downloaded from the Debian repository. You need to have internet connection or the download (and installation) fails. If you’re unsure about what apt-get install does, you can add the -s argument (simulate) to see what would be done.

_images/apt_install_flite.png

But let’s assume that the installation worked and we can continue. Actually, we’ve already finished, the installation is complete. You now have flite at your command. Turn on your speakers to full volume and hear the computer’s mighty voice.

flite "Hello petty human"

If you don’t hear anything for some reason or want to keep the recording, you might use the alternative version of the command.

flite "Hello petty human" /tmp/greetings.wav

That was cool, but we don’t actually need flite installed. Because we want our system to be as clean as it gets (and exercise a bit), let’s remove the program again.

There’s basically two options you have. Either you simply remove the program, which leaves traces like config files on your system. Or you purge it instead, also wiping configuration off the disk. We really want flite gone, so let’s pick the latter one.

apt-get purge flite

And we’re back at the original state. Of course there’s much more about software installation. For example the installation might partially complete, a program you need is not part of the repository or you don’t want to install software from the internet but use another medium (CD, HD, Flash drive) instead. You can do this and much more with apt and dpkg as well. You’ll get by with the commands presented here but if you want to really know the system, read the man pages of the two commands!

_images/apt_purge_flite.png

We’re going to discuss the next important feature of the package manager: updates. Debian is known for profound testing before each release. But still, sometimes severe bugs are found after the release. You don’t want to install a new Debian version each time this is the case, so they provide an easy to use update mechanism [4].

First, you need to get the latest package list. With it, the system can check if there’s any update it hasn’t received yet.

apt-get update

This command checks all your package list sources (check out /etc/apt/sources.list) and updates the cache. Now you’re ready to update the programs.

_images/apt_update.png
apt-get upgrade

And that’s it. Now your system is again up to date.

_images/apt_upgrade.png

Before you hear it from somewhere else: Some people prefer aptitude. It’s a program similar to apt and also used to install and remove software. Which one you use is a matter of taste. Try it out and make up your mind. Important is only that you stick to your choice. Especially removing a package with one will leave traces if you installed it with the other. So test them both, then use whichever you like better.

9.2.1. Exercises

  1. Explain the difference between a package and a program.
  2. Find out what clean, autoclean and autoremove does for apt-get.
  3. Find an alternative way to accomplish the same as apt-get purge.
  4. Install busybox.
  5. Pick any program, install it and remove it afterwards.
  6. Upgrade your system.

9.3. The time machine

“Wuaaaa, what’s happening?” Sounds familiar? Every once in a while stuff breaks. Guaranteed. Murphy taught me so.

There’s two reasons why you’ll need logs:

  1. Something doesn’t work anymore.
  2. Something doesn’t work yet.

In the second case, you’re trying to install something new but it just doesn’t work properly. You need to find out why and for this, you require some information about what the program does. In the first case, your system misbehave somehow and you need to find the cause. Again, you depend on information from the system.

The logging system provides a centralized mechanism for programs to report their status, events, unexpected input, strange behaviour. Whatever the programmer feels might be relevant information and help you find problems. This system is powered by the system logger, or syslog for short. Various programs exist, on my system it’s rsyslog, with some config files in /etc. It usually works like this, that you can define some rules to put log entries of a certain program in a specific file. The concrete syslog service you have installed may offer more, less or simply other functionality. But unless you’re working in a professional environment, there’s probably no need to change the default settings. So just be aware that you could do much fine-tuning here.

The log files are all stored in /var/log. So you should start your investigation here. You’ll see several files, like syslog, dmesg, messages, mail.log, ... Root privileges are required to read them. Let’s look inside.

sudo less -S /var/log/syslog

You see that there are many lines. Each line usually carries information about the date, command and the log message. Parts of a log entry are defined by syslog (file, date, command), others are program dependent (log message).

_images/less_syslog.png

Often, you’ll spot some strange log entries which already give you a clue about what’s wrong. You can also easily search (what was the key in less again?) for the command you’re suspecting to produce errors. There’s really not much more help I can offer, what you do with the log files depends strongly on your situation.

One more trick I can show, however. Often you can identify the faulty program and maybe even trigger the error. This is especially the case if you are trying to get something to work. In this case, you’ll only need the last couple of log entries. Check out the following.

sudo tail -f /var/log/syslog

Whenever a new log line is written into the file, it will be displayed. This way you’ll only see the latest couple of log entries. Which is nice if your log file is huge (like a couple of thousand lines). If you now trigger the error, you’ll spot it very quickly.

_images/tail_syslog.png

9.3.1. Exercises

  1. With what argument can you control the number of lines shown by tail?
  2. What’s the purpose of the command head.
  3. Which user logged in last on your system? At which time?
  4. What was the last message from cron?
  5. Which is the oldest log entry on your system? Which program wrote it?
  6. Which program was installed last? When was the installation started? When finished?

9.4. Network configuration

We’re not really going into networks here, but it’s still good to know a little something. And it’s important to be mentioned as the network configuration is different on almost every distribution. Let’s quickly show how Debian does it.

All you need is stored in /etc/network/interfaces. An interface roughly corresponds to a network adapter on your motherboard. It’s usually called eth0, eth1, ... See the next chapter to find out more.

I just present two options here, which should get you over the most simple cases. First, there’s the fully automatic network configuration. If you see the two lines below in /etc/network/interfaces, it means that you rely on a router to assign you the network address and equip you with all the necessary information. It’s usually the easiest way and if you don’t run your own network probably what you’ll need.

auto eth0
iface eth0 inet dhcp

Similarly often, you want to set the network address yourself. You can put the lines below instead of the ones above.

iface eth0 inet static
    address 192.168.0.123
    netmask 255.255.255.0

Just replace the parts after address and netmask with the values you intend to use. Ask the network administrator what address and netmask you should pick.

_images/interfaces.png

When adding configuration in this file, the network is automatically started when the system boots. Or, you can start/stop it manually with the two commands

sudo ifdown eth0
sudo ifup eth0
_images/ifupdown.png

9.4.1. Exercises

  1. What interfaces do you have configured on your system? How (static or dhcp)?
  2. Restart your interface.

9.5. Summary

You’ve learnt how to configure your own system to your liking. You know how to keep it up to date. You’re aware of your choices and know how to experiment. You can keep your system clean, even over a long time. You know how to supervise your machine and troubleshoot problems if any should appear. You’ve learnt more about programs and your file tree. You’re aware of your network configuration.

9.5.1. Exercises

  1. What is a dependency?
  2. Name three reasons why the package manager is so awsome.
  3. What other ways of software distribution do you know? How are they related to the Debian package manager?
  4. Why do you need updates?
  5. Who decides what is logged?
  6. How can you spot errors from a log file?
  7. If there’s not enough information in the log, how can you increase its verbosity?

9.6. Cheatsheet

  • dpkg [--get-selections]
  • apt-cache search KEYWORD
  • apt-cache show PACKAGE
  • apt-cache depends PACKAGE
  • apt-get install [-s] PACKAGE
  • flite TEXT [WAVEFILE]
  • apt-get remove PACKAGE
  • apt-get purge PACKAGE
  • apt-get update
  • apt-get upgrade
  • tail [-f] [FILE]
  • ifdown INTERFACE
  • ifup INTERFACE
[1]At least not very often. And if you do, you’ll have good reasons and will probably trust the software you’re about to run. And hey, this is an open source world. If you’re really that interested (and paranoid) you can read the source code and check for yourself what an application does.
[2]Windows also knows this technique but it’s a pain. And because they don’t have a package manager, you have to supply all dependencies with your program (because you don’t know what’s already there). Leading to huge downloads and a bloated system.
[3]Some programs offer seperate packages for the program and the documentation. For example, if the documentation is rather large and most users won’t need it. There are also many packages which only contain libraries, not an executable program.
[4]To be a bit more precise, you don’t update to new software versions. The program version is fixed for the debian release and you only receive fixes for the version you’ve installed. And actually only security fixes. The reason for this is that the system is tested and released with a fixed set of software of a specific version. Upgrading the software to a later version would render this test useless. This method is quite safe but also implies that a Debian system runs outdated (yet not insecure) software pretty soon. Some programs (e.g. firefox) circumvent this by providing an update mechanism of their own.