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

 

Linux: just installed Linux on my last Windows machine at home

I switched to a MacBook Pro 3,5 years ago. Until then, I’ve mostly had Windows machines at home even though I’ve always been more of a Unix/Linux guy. We still had a netbook which was delivered with Windows 7 Starter. I quickly upgraded to Windows Home Basic. Not sure why this Starter Edition even exists. It’s just an operating system with so many restrictions that any OS available 10 years ago would actually be better. Well, the netbook has an Atom N455 processor and 2 GB of RAM. As always with Windows, the longer the machine was in use, the slower it was getting and with this low spec machine, it was even worse. So yesterday, we got fed up with waiting all the time while planning our next vacation and decided to install Linux.

I first had a look at which distribution would make sense. I of course needed a low footprint distribution so that it can still run smoothly on this netbook which is already a few years old. Also I didn’t want to spend weeks trying to get all drivers working. Also I needed to be able to install it without an optical drive which I do not have in the netbook (and I didn’t want to spend hours looking for the external DVD drive I have somewhere in a box in the cellar).

I finally decided to install Easy Peasy.
easypeasy
Easy Peasy is based on Ubuntu (so you can use the Ubuntu package administration) and was specially build for netbooks. It has a low footprint, the ISO is less 900 MB and it brings most drivers you need on a netbook. The UI is also optimize for smaller displays. It uses the Netbook-Launcher from the Ubuntu Netbook Remix and application windows are maximized and displayed without a title bar.

Easy Peasy also brings quite a few open source applications like OpenOffice, Songbird and Firefox. The nice update management makes sure that you always have the latest version of the different software.

You can write the ISO on a memory stick using UNetbootin. Like this you can also first test it and see whether it works for you before overwriting your previous OS. I had a small problem. My Wireless adapter needed a Broadcom driver which wasn’t part of the default package and needed to be downloaded. Of course without driver, no Wireless connection and thus no Internet to download the driver from. So I first had to find a network cable and connect the netbook directly to the router. Installing the driver was no issue at all and I only needed the network cable for a few minutes.

Easy Peasy is a further development of Ubuntu Eee but is now not only limited to Asus Eee PCs (although I actually do have one) but is meant to be used on any netbook.

I still need to test it a little bit more but I’m already very happy with the UI, the performance and the ease of installation and update.

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.

Linux: Disable Address space layout randomization (ASLR) on SLES and Ubuntu

Address space layout randomization (ASLR) is a method to make hacker’s life more difficult by randomizing the position of the heap, stack, executable and libraries in the address space of the process. ASLR is enabled by default in Linux since kernel version 2.6.12.

It’s a nice security feature. Unfortunately it does break some software. If you run some software having this issue, you can switch off ASLR using the following:

sudo bash -c "echo 0 > /proc/sys/kernel/randomize_va_space"

to check the current value of the ASLR setting you can use the following:

cat /proc/sys/kernel/randomize_va_space