Debian / Ubuntu: viewing the apt change log

I am running rkhunter as a cron job and thus receiving notification any time I’ve installed something. Ideally I should be checking the output immediately and updating its database if it is just reporting a change due to a software update I’ve performed. But very often I don’t have time to do it right away and end up forgetting for days. At some point in time, I do check the logs and see that some pieces of software have been changed. By that time I usually do not remember what packages I’ve updated since last rkhunter database update. So I needed a way to check the history of installation of packages.

The bad news is that there is no apt-history command which would easily display the history of installed, updated and removed packages. The good news is that there are some log files which contain the whole history and can be used as a basis to extract this information.

There are actually two location where you can find such log files:

  • /var/log/apt/history.log* –> This contains the apt history logs
  • /var/log/dpkg.log* –> This contains the dpkg logs

Note that older log files are compressed with gzip. For the apt history logs, only the latest file is uncompressed. For the dpkg logs, the two latest files are uncompressed. Luckily, you can use the -f option of zcat to output the contents of those log files, no matter whether they are compressed or not. And combining it with ls -tr you can basically decompress them and concatenate them on the fly in the proper order:

zcat -f $(ls -tr /var/log/apt/history.log*)
zcat -f $(ls -tr /var/log/dpkg.log*)

Before we start, I wanted to mention that I do know that aptitude also writes a log file (/var/log/aptitude) but when I looked at it, it only contained information about what happened in the past 8 days. So it wasn’t really useful for my purpose. There is probably a way to configure aptitude to store more history in there but since I found another good solution, let’s stick to this… Also if you use Synaptic, there is also a “View History” function in the GUI. But it only shows changes made with Synaptic, not from the command line or automatically e.g. by Plesk auto-installer.

First I had a look at the contents of the apt history log files. It looks like this:

Start-Date: 2014-02-17  21:53:00
Install: libserf1:amd64 (1.3.4-1+WANdisco, automatic), php5-imagick:amd64 (3.1.0~rc1-1+b2, automatic), php5-pgsql:amd64 (5.4.4-14+deb7u7, automatic), php5-mcrypt:amd64 (5.4.4-14+deb7u7, automatic), php5-intl:amd64 (5.4.4-14+deb7u7, automatic)
Upgrade: owncloud:amd64 (5.0.13-1, 6.0.1-1), subversion:amd64 (1.7.13-1+WANdisco, 1.7.14-1+WANdisco), libsvn1:amd64 (1.7.13-1+WANdisco, 1.7.14-1+WANdisco), libapache2-svn:amd64 (1.7.13-1+WANdisco, 1.7.14-1+WANdisco)
End-Date: 2014-02-17  21:53:20

Processing it with Unix tools is possible but it is a pain because you have to consider groups of lines, between a Start-Date and an End-Date, and the number of lines inbetween is not always the same (potentially one line for installs, one line for upgrades and one line for removals). This can of course be procesed with some grep, awk, sed and other utilities. But this has two problems: first I’m lazy, second if the command is too complex I will never remember it even if I use it daily.

So I decided to have a look at the dpkg log files and see whether they were friendlier:

2014-02-17 21:53:00 startup archives unpack
2014-02-17 21:53:00 install libserf1:amd64  1.3.4-1+WANdisco
2014-02-17 21:53:00 status half-installed libserf1:amd64 1.3.4-1+WANdisco
2014-02-17 21:53:00 status unpacked libserf1:amd64 1.3.4-1+WANdisco
2014-02-17 21:53:00 status unpacked libserf1:amd64 1.3.4-1+WANdisco
2014-02-17 21:53:01 install php5-intl:amd64  5.4.4-14+deb7u7
2014-02-17 21:53:01 status triggers-pending libapache2-mod-php5:amd64 5.4.4-14+deb7u7
2014-02-17 21:53:01 status not-installed php5-intl:amd64 
2014-02-17 21:53:01 status half-installed php5-intl:amd64 5.4.4-14+deb7u7
2014-02-17 21:53:01 status unpacked php5-intl:amd64 5.4.4-14+deb7u7
2014-02-17 21:53:01 status unpacked php5-intl:amd64 5.4.4-14+deb7u7
2014-02-17 21:53:02 install php5-mcrypt:amd64  5.4.4-14+deb7u7
2014-02-17 21:53:02 status not-installed php5-mcrypt:amd64 
2014-02-17 21:53:02 status half-installed php5-mcrypt:amd64 5.4.4-14+deb7u7
2014-02-17 21:53:02 status unpacked php5-mcrypt:amd64 5.4.4-14+deb7u7
2014-02-17 21:53:02 status unpacked php5-mcrypt:amd64 5.4.4-14+deb7u7
2014-02-17 21:53:02 install php5-pgsql:amd64  5.4.4-14+deb7u7
2014-02-17 21:53:02 status not-installed php5-pgsql:amd64 
2014-02-17 21:53:02 status half-installed php5-pgsql:amd64 5.4.4-14+deb7u7
2014-02-17 21:53:03 status unpacked php5-pgsql:amd64 5.4.4-14+deb7u7
2014-02-17 21:53:03 status unpacked php5-pgsql:amd64 5.4.4-14+deb7u7
2014-02-17 21:53:03 upgrade subversion:amd64 1.7.13-1+WANdisco 1.7.14-1+WANdisco
2014-02-17 21:53:03 status half-configured subversion:amd64 1.7.13-1+WANdisco
2014-02-17 21:53:03 status unpacked subversion:amd64 1.7.13-1+WANdisco
2014-02-17 21:53:03 status half-installed subversion:amd64 1.7.13-1+WANdisco
2014-02-17 21:53:03 status triggers-pending man-db:amd64 2.6.2-1
2014-02-17 21:53:04 status half-installed subversion:amd64 1.7.13-1+WANdisco
2014-02-17 21:53:04 status half-installed subversion:amd64 1.7.13-1+WANdisco
2014-02-17 21:53:04 status unpacked subversion:amd64 1.7.14-1+WANdisco
2014-02-17 21:53:04 status unpacked subversion:amd64 1.7.14-1+WANdisco
2014-02-17 21:53:04 upgrade libsvn1:amd64 1.7.13-1+WANdisco 1.7.14-1+WANdisco
2014-02-17 21:53:04 status half-configured libsvn1:amd64 1.7.13-1+WANdisco
2014-02-17 21:53:04 status unpacked libsvn1:amd64 1.7.13-1+WANdisco
2014-02-17 21:53:04 status half-installed libsvn1:amd64 1.7.13-1+WANdisco
2014-02-17 21:53:05 status half-installed libsvn1:amd64 1.7.13-1+WANdisco
2014-02-17 21:53:05 status unpacked libsvn1:amd64 1.7.14-1+WANdisco
2014-02-17 21:53:05 status unpacked libsvn1:amd64 1.7.14-1+WANdisco
2014-02-17 21:53:05 upgrade libapache2-svn:amd64 1.7.13-1+WANdisco 1.7.14-1+WANdisco
2014-02-17 21:53:05 status half-configured libapache2-svn:amd64 1.7.13-1+WANdisco
2014-02-17 21:53:05 status unpacked libapache2-svn:amd64 1.7.13-1+WANdisco
2014-02-17 21:53:05 status half-installed libapache2-svn:amd64 1.7.13-1+WANdisco
2014-02-17 21:53:05 status half-installed libapache2-svn:amd64 1.7.13-1+WANdisco
2014-02-17 21:53:05 status unpacked libapache2-svn:amd64 1.7.14-1+WANdisco
2014-02-17 21:53:05 status unpacked libapache2-svn:amd64 1.7.14-1+WANdisco
2014-02-17 21:53:06 upgrade owncloud:all 5.0.13-1 6.0.1-1
2014-02-17 21:53:06 status half-configured owncloud:all 5.0.13-1
2014-02-17 21:53:06 status unpacked owncloud:all 5.0.13-1
2014-02-17 21:53:06 status half-installed owncloud:all 5.0.13-1
2014-02-17 21:53:11 status half-installed owncloud:all 5.0.13-1
2014-02-17 21:53:11 status unpacked owncloud:all 6.0.1-1
2014-02-17 21:53:11 status unpacked owncloud:all 6.0.1-1
2014-02-17 21:53:12 install php5-imagick:amd64  3.1.0~rc1-1+b2
2014-02-17 21:53:12 status half-installed php5-imagick:amd64 3.1.0~rc1-1+b2
2014-02-17 21:53:12 status unpacked php5-imagick:amd64 3.1.0~rc1-1+b2
2014-02-17 21:53:12 status unpacked php5-imagick:amd64 3.1.0~rc1-1+b2
2014-02-17 21:53:12 trigproc libapache2-mod-php5:amd64 5.4.4-14+deb7u7 5.4.4-14+deb7u7
2014-02-17 21:53:12 status half-configured libapache2-mod-php5:amd64 5.4.4-14+deb7u7
2014-02-17 21:53:12 status installed libapache2-mod-php5:amd64 5.4.4-14+deb7u7
2014-02-17 21:53:13 trigproc man-db:amd64 2.6.2-1 2.6.2-1
2014-02-17 21:53:13 status half-configured man-db:amd64 2.6.2-1
2014-02-17 21:53:13 status installed man-db:amd64 2.6.2-1
2014-02-17 21:53:14 startup packages configure
2014-02-17 21:53:14 configure libserf1:amd64 1.3.4-1+WANdisco 
2014-02-17 21:53:14 status unpacked libserf1:amd64 1.3.4-1+WANdisco
2014-02-17 21:53:14 status half-configured libserf1:amd64 1.3.4-1+WANdisco
2014-02-17 21:53:14 status installed libserf1:amd64 1.3.4-1+WANdisco
2014-02-17 21:53:14 configure php5-intl:amd64 5.4.4-14+deb7u7 
2014-02-17 21:53:14 status triggers-pending libapache2-mod-php5:amd64 5.4.4-14+deb7u7
2014-02-17 21:53:14 status unpacked php5-intl:amd64 5.4.4-14+deb7u7
2014-02-17 21:53:15 status unpacked php5-intl:amd64 5.4.4-14+deb7u7
2014-02-17 21:53:15 status half-configured php5-intl:amd64 5.4.4-14+deb7u7
2014-02-17 21:53:15 status triggers-awaited php5-intl:amd64 5.4.4-14+deb7u7
2014-02-17 21:53:15 configure php5-mcrypt:amd64 5.4.4-14+deb7u7 
2014-02-17 21:53:15 status unpacked php5-mcrypt:amd64 5.4.4-14+deb7u7
2014-02-17 21:53:15 status unpacked php5-mcrypt:amd64 5.4.4-14+deb7u7
2014-02-17 21:53:15 status half-configured php5-mcrypt:amd64 5.4.4-14+deb7u7
2014-02-17 21:53:16 status triggers-awaited php5-mcrypt:amd64 5.4.4-14+deb7u7
2014-02-17 21:53:16 configure php5-pgsql:amd64 5.4.4-14+deb7u7 
2014-02-17 21:53:16 status unpacked php5-pgsql:amd64 5.4.4-14+deb7u7
2014-02-17 21:53:16 status unpacked php5-pgsql:amd64 5.4.4-14+deb7u7
2014-02-17 21:53:16 status half-configured php5-pgsql:amd64 5.4.4-14+deb7u7
2014-02-17 21:53:17 status triggers-awaited php5-pgsql:amd64 5.4.4-14+deb7u7
2014-02-17 21:53:17 configure php5-imagick:amd64 3.1.0~rc1-1+b2 
2014-02-17 21:53:17 status unpacked php5-imagick:amd64 3.1.0~rc1-1+b2
2014-02-17 21:53:17 status half-configured php5-imagick:amd64 3.1.0~rc1-1+b2
2014-02-17 21:53:18 status installed php5-imagick:amd64 3.1.0~rc1-1+b2
2014-02-17 21:53:18 trigproc libapache2-mod-php5:amd64 5.4.4-14+deb7u7 
2014-02-17 21:53:18 status half-configured libapache2-mod-php5:amd64 5.4.4-14+deb7u7
2014-02-17 21:53:18 status installed php5-pgsql:amd64 5.4.4-14+deb7u7
2014-02-17 21:53:18 status installed php5-mcrypt:amd64 5.4.4-14+deb7u7
2014-02-17 21:53:18 status installed php5-intl:amd64 5.4.4-14+deb7u7
2014-02-17 21:53:18 status installed libapache2-mod-php5:amd64 5.4.4-14+deb7u7
2014-02-17 21:53:18 configure owncloud:all 6.0.1-1 
2014-02-17 21:53:18 status unpacked owncloud:all 6.0.1-1
2014-02-17 21:53:19 status unpacked owncloud:all 6.0.1-1
2014-02-17 21:53:19 status unpacked owncloud:all 6.0.1-1
2014-02-17 21:53:19 status half-configured owncloud:all 6.0.1-1
2014-02-17 21:53:19 status installed owncloud:all 6.0.1-1
2014-02-17 21:53:19 configure subversion:amd64 1.7.14-1+WANdisco 
2014-02-17 21:53:19 status unpacked subversion:amd64 1.7.14-1+WANdisco
2014-02-17 21:53:19 status unpacked subversion:amd64 1.7.14-1+WANdisco
2014-02-17 21:53:19 status unpacked subversion:amd64 1.7.14-1+WANdisco
2014-02-17 21:53:19 status unpacked subversion:amd64 1.7.14-1+WANdisco
2014-02-17 21:53:19 status half-configured subversion:amd64 1.7.14-1+WANdisco
2014-02-17 21:53:19 status installed subversion:amd64 1.7.14-1+WANdisco
2014-02-17 21:53:19 configure libsvn1:amd64 1.7.14-1+WANdisco 
2014-02-17 21:53:19 status unpacked libsvn1:amd64 1.7.14-1+WANdisco
2014-02-17 21:53:19 status half-configured libsvn1:amd64 1.7.14-1+WANdisco
2014-02-17 21:53:19 status installed libsvn1:amd64 1.7.14-1+WANdisco
2014-02-17 21:53:20 configure libapache2-svn:amd64 1.7.14-1+WANdisco 
2014-02-17 21:53:20 status unpacked libapache2-svn:amd64 1.7.14-1+WANdisco
2014-02-17 21:53:20 status unpacked libapache2-svn:amd64 1.7.14-1+WANdisco
2014-02-17 21:53:20 status unpacked libapache2-svn:amd64 1.7.14-1+WANdisco
2014-02-17 21:53:20 status half-configured libapache2-svn:amd64 1.7.14-1+WANdisco
2014-02-17 21:53:20 status installed libapache2-svn:amd64 1.7.14-1+WANdisco

It’s much more verbose but each line contains both the date and time and what was performed. All you need to do is use a grep to extract the information you need. So depending what you’re after you’ll use one of these 3 commands:

zcat -f $(ls -tr /var/log/dpkg.log*) | grep " install "
zcat -f $(ls -tr /var/log/dpkg.log*) | grep " upgrade "
zcat -f $(ls -tr /var/log/dpkg.log*) | grep " remove "

You will then see something like this:

# zcat -f $(ls -tr /var/log/dpkg.log*) | grep " remove "
2014-12-01 18:43:15 remove libneon27-gnutls:amd64 0.29.6-3 <keine>
2014-12-01 18:43:16 remove libnss3-1d:amd64 2:3.14.5-1+deb7u3 <keine>
2014-12-01 18:43:16 remove libtommath0:amd64 0.42.0-1 <keine>

Note that keine means “none” in German, so removing a package is going from a certain version to none.

Debian/Ubuntu: The following packages have been kept back

Note that for all commands below, you might need to add a leading sudo depending on your system.

When updating your packages using apt-get, you might get the following message:

# apt-get upgrade
Building Dependency Tree… Done
The following packages have been kept back:
xxxxxx xxxxxx xxxxxx xxxxxx
0 upgraded, 0 newly installed, 0 to remove and 4 not upgraded.

This means that there are packages which can be updated but they were not. So what are the reasons why some packages wouldn’t be updated ?

First let’s look at what apt-get upgrade does:

apt-get upgrade installs the newest versions of all packages which are already installed on the system from the configured sources. What apt-get upgrade doesn’t do is install additional packages or remove existing ones. The fact that it doesn’t install new packages is the reason why your packages are being kept back. These packages have an updated list of dependencies and apt-get would need to install new packages in order to install the new version of the software.

So what can you do about it ? There are basically 3 ways to handle it.

dist-upgrade

The first one is to use dist-upgrade. apt-get dist-upgrade does basically the same as upgrade. But additionally, it removes and installs packages in order to accommodate the updated list of dependencies of newer versions of the install packages.

When using diet-upgrade, you will be presented with a list of changes which will be applied. There will be a list of packages being additionally installed and a list of packages which will be removed.

You have to especially pay attention to the list of packages to be removed. In the list of packages to be removed, you will not only find packages being removed because they are not needed anymore but also packages which will be removed because they are not compatible with the latest version of the packages you are updating.

On my system, this is very often the case for Plesk which tends to force me to keep outdated packages for a little longer. Forcing an update of these packages would result in Plesk being uninstalled. Recovering from this is not very easy… Also, if you install beta versions of some software, you might also end up getting long list of packages to be removed because they would not be compatible anymore.

Also, you might in some cases have packages required by others but not cleanly listed as a dependency (once had this problem with subversion).

install

If you want to have the required packages installed but do not want to have packages removed, you can use apt install:

apt-get install <list of packages>

This will first resolve the kept-back dependencies and will offer to install additionally required packages.

aptitude

Start aptitude, select the list of upgradable packages, press “g” twice to install.

Then answer the questions and follow the instructions.

Still problems?

If all of this doesn’t work, you may want to give some of the following a try. These are various things I’ve needed in some cases to get rid of conflicts using apt-get.

Reinstalling the packages kept back:

apt-get install --reinstall <list of packages>

Checking for a given package, the installed and the versions available from the configured sources:

apt-cache policy <package name>

Use aptitude instead of apt-get:

aptitude update && aptitude upgrade

Use aptitude safe-upgrade to upgrade currently installed packages as well as install new packages to resolve new dependencies, but without removing installed packages:

aptitude safe-upgrade

 

SVN: Subversion 1.8 on Debian 7 (Wheezy)

Debian 7 (Wheezy) is still only shipping with Subversion 1.6 (see Details of package subversion in wheezy).

First you need to add the WANdisco GPG key to the apt sources keyring:

$ wget -q http://opensource.wandisco.com/wandisco-debian.gpg -O- | apt-key add -

Then you need to add the appropriate apt source. You can either extend /etc/apt/sources.list or create a new file in /etc/apt/sources.list.d. We’ll go for the second option:

$ echo "deb http://staging.opensource.wandisco.com/debian wheezy svn18" > /etc/apt/sources.list.d/subversion.list

Now you can have apt-get download the package lists from the new repository and update the dependencies:

$ apt-get update

Now apt-cache will show you (at least) two versions:

$ apt-cache show subversion
Package: subversion
Version: 1.8.8-3+WANdisco
Architecture: amd64
Maintainer: Philip Herron <opensource@wandisco.com>
Installed-Size: 4423
Depends: libsvn1 (= 1.8.8-3+WANdisco), libapr1 (>= 1.3.2), libaprutil1 (>= 1.2.7+dfsg), libc6 (>= 2.3), libexpat1 (>= 2.0.1), libsasl2-2 (>= 2.1.24), zlib1g (>= 1:1.1.4)
Suggests: subversion-tools, db4.8-util, patch
Filename: dists/wheezy/svn18/binary-amd64/subversion_1.8.8-3+WANdisco_amd64.deb
Size: 1453080
MD5sum: 8b23345878430ab7c5d22aabd461bbd6
SHA1: bc8125dfcc3c7bee34b09eca6919d5e64a7513d4
SHA256: 861987aebdcd2fa9f03ba9f758572fb05f8b345341533c0d072b5ef573443999
Section: vcs
Priority: optional
Homepage: http://wandisco.com
Description: Advanced version control system

Package: subversion
Version: 1.6.17dfsg-4+deb7u4
Installed-Size: 4108
Maintainer: Peter Samuelson <peter@p12n.org>
Architecture: amd64
Depends: libsvn1 (= 1.6.17dfsg-4+deb7u4), libapr1 (>= 1.2.7), libc6 (>= 2.3), libsasl2-2 (>= 2.1.24)
Suggests: subversion-tools, db5.1-util, patch
Description: Advanced version control system
Homepage: http://subversion.apache.org/
Description-md5: 15da1bb51fb2e9ea5e25b3a489b864d9
Tag: devel::rcs, implemented-in::c++, implemented-in::python,
 interface::commandline, network::client, network::server,
 protocol::http, protocol::ssh, protocol::webdav, role::program,
 use::storing, use::synchronizing
Section: vcs
Priority: optional
Filename: pool/main/s/subversion/subversion_1.6.17dfsg-4+deb7u4_amd64.deb
Size: 1319636
MD5sum: 608ed74ad8856546afd0a38ad171d0a5
SHA1: 46b53dc63ae20c59c39e152d65d68397c951051f
SHA256: a4a7fd1aefc7f160aa4a270792e5b7812a3804623d36b34f41055ed7a4b083a0

You can now install the new version using:

$ apt-get install subversion

Now Subversion 1.8 will be installed, you can check it with:

$ svn --version
svn, Version 1.8.8 (r1568071)
...

If you have already done all this for Subversion 1.7 and only want to upgrade to versino 1.8, it’s even easier. You just have to find where the source is defined (you don’t need to import the key as you already have it):

$ grep -R svn17 /etc/apt/
/etc/apt/sources.list.d/WANdisco.list:deb http://staging.opensource.wandisco.com/debian wheezy svn17

Then replace svn17 by svn18 in this file:

$ sed -i 's/svn17/svn18/' /etc/apt/sources.list.d/WANdisco.list

Now you can have apt-get download the package lists from the new repository and upgrade subversion:

$ apt-get update && apt-get upgrade

Debian: use SSHFS to mount a remote directory

In a previous post, I’ve shown how to use SSHFS to mount a remote directory as a volume in Mac OS X. Of course the same can be done to connect two Linux boxes.

Here’s a short description how to do it on Debian.

First you’ll need to install sshfs using apt-get:

apt-get install sshfs

Note that this will also install fuse as a dependency.

Then you need to have a public key authentication in place. I’m assuming that ssh is already installed on the server. You now should do the following, on the Linux box where the file system should be mounted:

apt-get install openssh-client

Now you can generate a key:

mkdir ~/.ssh
chmod 700 ~/.ssh
cd ~/.ssh
ssh-keygen -t rsa -C "henri.benoit@gmail.com"

Of course replace my email address by yours. You can then print the key:

cat id_rsa.pub

This should be added to the file ~/.ssh/authorized_keys on the server.

You also need to make sure that PubkeyAuthentication is set to yes in /etc/ssh/sshd_config so that public key authentication is supported at all.

Now you can connect using ssh without password and can mount over ssh:

mkdir ~/amazingweb
sshfs -p 22 USER@xxx.xxx.xxx.xxx:/var/www/vhosts ~/amazingweb -oauto_cache,reconnect

Replace USER by the user for which you’ve setup the public key authentication.
Replace xxx.xxx.xxx.xxx by the IP address of the remote server.
Replace ~/amazingweb by the path where you want to mount the remote file system.

It’s basically the same command as under Mac OS X except that you have to remove the 3 following options which are not available under Debian:

  • defer_permissions
  • noappledouble
  • volname

Debian: using netselect-apt to find the fastest archive mirror

If you need to quickly find the fastest Archive mirror to download Debian packages, you can either use apt-spy as shown here or use a tool called netselect-apt.

netselect-apt can be installed with apt-get:

# apt-get install netselect-apt
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  netselect
The following NEW packages will be installed:
  netselect netselect-apt
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 37.9 kB of archives.
After this operation, 171 kB of additional disk space will be used.
Do you want to continue [Y/n]? 
Get:1 http://ftp.de.debian.org/debian/ squeeze/main netselect amd64 0.3.ds1-14+squeeze1 [25.8 kB]
Get:2 http://ftp.de.debian.org/debian/ squeeze/main netselect-apt all 0.3.ds1-14+squeeze1 [12.0 kB]
Fetched 37.9 kB in 0s (201 kB/s)         
Preconfiguring packages ...
Selecting previously deselected package netselect.
(Reading database ... 106538 files and directories currently installed.)
Unpacking netselect (from .../netselect_0.3.ds1-14+squeeze1_amd64.deb) ...
Selecting previously deselected package netselect-apt.
Unpacking netselect-apt (from .../netselect-apt_0.3.ds1-14+squeeze1_all.deb) ...
Processing triggers for man-db ...
Setting up netselect (0.3.ds1-14+squeeze1) ...
Setting up netselect-apt (0.3.ds1-14+squeeze1) ...

You can then start it with the distribution (e.g. stable, testing, unstable, lenny, squeeze…) as parameter:

# netselect-apt stable
Using distribution stable.
Retrieving the list of mirrors from www.debian.org...

--2012-12-25 21:20:46--  http://www.debian.org/mirror/mirrors_full
Resolving www.debian.org... 86.59.118.148, 2001:858:2:2:214:22ff:fe0d:7717
Connecting to www.debian.org|86.59.118.148|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 337765 (330K) [text/html]
Saving to: “/tmp/netselect-apt.UJfxkZ”

100%[==================================================================================================================================================================>;] 337,765     1.68M/s   in 0.2s    

2012-12-25 21:20:46 (1.68 MB/s) - “/tmp/netselect-apt.UJfxkZ” saved [337765/337765]

Choosing a main Debian mirror using netselect.
netselect: 389 (23 active) nameserver request(s)...       
Duplicate address 212.36.0.70 (http://ftp.bg.debian.org/debian/, http://debian.spnet.net/debian/); keeping only under first name.
...
Duplicate address 128.61.240.89 (http://128.61.240.89/debian/, http://debian.gtisc.gatech.edu/debian/); keeping only under first name.
Running netselect to choose 1 out of 379 addresses.      
..................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
The fastest server seems to be:
        http://debian.cruisix.net/debian/

Writing sources.list.
Done.

It is much faster than apt-spy and produces a sources.list file in the current directory:

# cat ./sources.list 
# Debian packages for stable
deb http://debian.cruisix.net/debian/ stable main contrib
# Uncomment the deb-src line if you want 'apt-get source'
# to work with most packages.
# deb-src http://debian.cruisix.net/debian/ stable main contrib

# Security updates for stable
deb http://security.debian.org/ stable/updates main contrib

netselect-apt is faster than apt-spy but supports less option and it is e.g. not so easy to select a region or country.

netselect-apt is also faster because it doesn’t actually benchmark the mirrors but just pings them. So the speed measurements made by netselect-apt are not as accurate as the one done by apt-spy.

Another difference is that netselect-apt automatically gets the latest list of archive mirror. With apt-spy you’d need to first run it with the update option.

Debian: using apt-spy to find the fastest archive mirror

apt-spy is a tool which tests the bandwidth of Debian archive mirrors and generates a file in /etc/apt/sources.list.d with the source list for the fastest mirror.

The most useful options for apt-spy are:

  • -d to define which distribution to use. You can use stable, testing or unstable. You can alternatively also use a distribution name e.g. squeeze. You need to set a value to this parameter.
  • -a to define the area to check. If not set, apt-spy will check all known mirrors world-wide. Use one of these values: Africa, Asia, Europe, North-America, Oceania or South-America.

To check all mirrors worldwide and generate a sources.list file for stable packages:

# apt-spy -d stable

Of course, if apt-spy is not installed yet, you’ll need to install it first:

# apt-spy -d stable
-bash: apt-spy: command not found
# apt-get install apt-spy
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
apt-spy
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 33.4 kB of archives.
After this operation, 209 kB of additional disk space will be used.
Get:1 http://ftp.de.debian.org/debian/ squeeze/main apt-spy amd64 3.1-19 [33.4 kB]
Fetched 33.4 kB in 0s (190 kB/s)
Selecting previously deselected package apt-spy.
(Reading database ... 106526 files and directories currently installed.)
Unpacking apt-spy (from .../apt-spy_3.1-19_amd64.deb) ...
Processing triggers for man-db ...
Setting up apt-spy (3.1-19) ...

Without using the -a parameter, checking the bandwidth of all mirrors will take some time.

Eventually it will find some pretty fast servers:

SERVER: ftp.at.debian.org
Benchmarking FTP...
Downloaded 7100595 bytes in 2.10 seconds
Download speed: 3302.32 kB/sec

Some very slow servers:

SERVER: debian.indika.net.id
Benchmarking HTTP...
Downloaded 67776 bytes in 20.24 seconds
Download speed: 3.27 kB/sec

Some extremely fast servers:

SERVER: ftp.sk.debian.org
Benchmarking FTP...
Downloaded 7100595 bytes in 1.27 seconds
Download speed: 5442.81 kB/sec

And some servers with issues:

...

SERVER: mirror.publicns.net
Benchmarking FTP...
Error: Couldn't resolve host 'mirror.publicns.net'

...

SERVER: ftp.linuxforum.net
Benchmarking FTP...
Error: connect() timed out!

...

SERVER: ftp.it.debian.org
Benchmarking FTP...
Error: couldn't connect to host

...

SERVER: debian.uni.edu.ni
Benchmarking HTTP...
Error: name lookup timed out

...

SERVER: ftp.3logic.net
Benchmarking FTP...
Error: Server denied you to change to the given directory

...

When it is done it will write a sources.list file:

...

Writing new sources.list file: /etc/apt/sources.list.d/apt-spy.list 
# cat /etc/apt/sources.list.d/apt-spy.list 
# sources.list generated by apt-spy v3.1
#
# Generated using:
#
# apt-spy \
# 	-d stable
#
deb ftp://ftp.sk.debian.org/debian/ stable main #contrib non-free
deb-src ftp://ftp.sk.debian.org/debian/ stable main #contrib non-free
deb http://security.debian.org/ stable/updates main

 

Next time you run apt-get update you’ll see that the new mirror is used.

VMWare: The path “/usr/bin/gcc” is not valid path to the gcc binary

Since I’ve wasted way too much time with this problem, I thought I’d share how I solved it…

But first the problem:

I wanted to install the vmware tools in a Debian Squeeze virtual machine. So I chose Install VMWare Tools in VMWare Workstation. Then mounted the CD:

mount /dev/cdrom

Unpacked the tools to the /tmp directory:

cd /tmp
tar xvfz /media/cdrom0/VMwareTools-8.8.4-743747.tar.gz

I then started the tools installation:

cd vmware-tools-distrib/
./vmware-install.pl

Most of it went fine but I reached the point where the installer looks for gcc and got the following message:

Searching for GCC...
The path "" is not valid path to the gcc binary.
Would you like to change it? [yes]

I said yes, looked for the path to gcc and saw it wasn’t installed. So I stopped the installer and installed gcc:

# apt-get install gcc

I restarted the installer and same problem… I now checked the path to gcc:

# which gcc
/usr/bin/gcc

And entered it at the prompt:

What is the location of the gcc program on your machine? /usr/bin/gcc

The path "/usr/bin/gcc" is not valid path to the gcc binary.
Would you like to change it? [yes]

So gcc is now there but somehow the tools installer doesn’t like it.

After googling for ages, I ended up installing the following packages:

  • make
  • gcc-4.3
  • libglib2.0-0
  • linux-headers-2.6.32-5-amd64

Of course if you have another kernel, you should install the appropriate version of the Linux kernel headers. You can install it all like this:

aptitude install make gcc-4.3 linux-headers-`uname -r` libglib2.0-0

gcc-4.3 is required and not the version 4.4 which got installed when I ran apt-get install gcc because it’s the version which was used to compile the kernel. You can check this on your system using:

# cat /proc/version
Linux version 2.6.32-5-amd64 (Debian 2.6.32-45) (dannf@debian.org) (gcc version 4.3.5 (Debian 4.3.5-4) ) #1 SMP Sun May 6 04:00:17 UTC 2012

After that the installation of the vmware tools was at last successful.

I’m not 100% sure that all 4 packages are needed but in the end after installing all 4 it worked and I really don’t want to test the different combination with 3 packages to see whether I could have installed one package less.

Debian: Configure a static IP address

In order to configure a network device statically, you have to edit /etc/network/interfaces:

# vi /etc/network/interfaces

There you can configure a static IP address and the subnet mask:

auto eth0
iface eth0 inet static
address 192.168.128.128
netmask 255.255.255.0

In order to have the changes enabled, you need to restart the network interface either with:

# /etc/init.d/networking restart

or

# /etc/init.d/networking stop
# /etc/init.d/networking start

or

# ifdown eth0
# ifup eth0

You can then check the new eth0 settings with:

# ifconfig -a

 

Debian: change the keyboard layout from the console

I’ve installed a new test system to play around a little bit (a Debian Squeeze install). Since I was too lazy to install it from scratch and I’m using VMWare anyway, I thought I’d just download a pre-installed virtual machine.

Now this virtual machine had a US keyboard configured and I’m using a German keyboard. After googling for how to change the keyboard layout from the console, I found a few hints:

dpkg-reconfigure console-data

Unfortunately the package console-data is not installed on my system.

Then I found the following:

dpkg-reconfigure keyboard-configuration

This package is installed and you can choose a keyboard layout. Great !

After saving, I pressed “Z” and got a “Y” on the console. So still having a US keyboard configured.

Since keyboard-configuration modifies the file /etc/default/keyboard, I checked this file:

# cat /etc/default/keyboard
# Check /usr/share/doc/keyboard-configuration/README.Debian for
# documentation on what to do after having modified this file.
# The following variables describe your keyboard and can have the same
# values as the XkbModel, XkbLayout, XkbVariant and XkbOptions options
# in /etc/X11/xorg.conf.

XKBMODEL=”pc105″
XKBLAYOUT=”de”
XKBVARIANT=”nodeadkeys”
XKBOPTIONS=””

# If you don’t want to use the XKB layout on the console, you can
# specify an alternative keymap. Make sure it will be accessible
# before /usr is mounted.
# KMAP=/etc/console-setup/defkeymap.kmap.gz

Everything looks fine… But the hint in the beginning of the file might be pointing to the solution. So let’s check this README.Debian file:

# cat /usr/share/doc/keyboard-configuration/README.Debian
After modifying /etc/default/keyboard, you can apply the changes to the linux console by running setupcon. If X is configured to use that file too, then the changes will become visible to X only if

udevadm trigger –subsystem-match=input –action=change

There is the solution:

#setupcon

And the keyboard layout is German !!

Debian: Remove packages in status rc

The status rc says that the package was removed but the configuration files are still on disk. This happens either when the packages are deleted with apt-get remove or they are automatically removed due to a dependency. In this second case, it also happens if the main package was purged and not only removed.

You can determine which package are in this status with:

# dpkg -l | grep ^rc

So executing this will return only the names of all these packages:

# dpkg -l | grep ^rc | awk ‘{print $2}’

And to purge all these packages:

# dpkg -l | grep ^rc | awk ‘{print $2}’ | xargs dpkg -P

If you want to first see what dpkg would do, use:

# dpkg -l | grep ^rc | awk ‘{print $2}’ | xargs dpkg –no-act -P