alan

ubuntu

A desktop freeze is something that's not so rare nowadays – that's not good, but we shouldn't get desperate about that.

I like Compiz with Unity Desktop on my Ubuntu Trusty very much; I feel it's a step forward compared to traditional desktops. The only major nuisance I had on the previous versions was the inability to disable the global menu (which I like by itself, but I don't like the global menu disappearing when the mouse is not over it), but you can now disable it and have the menu on the window – even though you can't still enable an always-visible behaviour.

The problem is: compiz sometimes gets buggy. Running a different window manager, like metacity and/or xcompmgr just doesn't seem good, you can experience other issues and you're using the stack in a way it wasn't designed for. I don't like that approach.

So, what can you do when your desktop freezes? The symptoms are usually very clear: you can move your mouse, but you can't click nor type anything.

You don't need to reboot nor to restart X. You can fix this without losing your work.

Get a raw tty

Press Ctrl+Alt+F1 and get to a raw linux console, and login with your credentials. Make sure you use the same user you're logged into X with.

Find and kill your stuck process

pgrep compiz

This will print the PID of our stuck window manager.

Let's kill it

pkill compiz

This won't usually be enough because the process is really stuck: if you repeat the pgrep command above, you'll find it still running – i.e. pgrep will return the very same PID as above.

So let's kill it, really this time!

pkill -9 compiz

Then wait some 15-20 seconds.

Now, if you repeat the pgrep , you'll either see a) no result or b) a different PID.

If you see a different PID, it's Ubuntu that noticed the crashed process and relaunched it; press Ctrl+Alt+F7, and you should just get back a working desktop!

Relaunching

If you see nothing with pgrep, you'll need to relaunch Compiz manually.

You cannot simply relaunch compiz on the console, because it must connect to X: the proper way to do it is:

DISPLAY=:0 compiz

Now switch back to your X instance with Ctrl+Alt+F7 and enjoy!

#MostlyUnixish #linux #ancientwisdom #community #ubuntu #compiz

It might be high time to update to the latest Ubuntu 14.04.

I think that the upgrade process that is provided by Canonical is slightly underoptimal: if you're using a local mirror which can provide a very fast download of all packages, they'll usually be disabled during the upgrade process, and an official mirror (possibile one very far away) will be employed.

This can lead to a very slow and painful upgrade process.

The solution is easy.

The following instructions regard moving from 12.04 (precise) to 14.04 (trusty)

Switch your sources

Assuming that your official ubuntu sources are configured from /etc/apt/sources.list just do something like:

sudo sed -i.old -e 's/precise/trusty/g' /etc/apt/sources.list

I'm not considering other sources in /etc/apt/sources.list.d, since they'll be disabled whatsoever; but if you happen to have ubuntu sources there as well, you should repeat the SEDding process for each file.

Update your index

sudo apt-get update

Download updated packages without installing

sudo apt-get dist-upgrade --download-only

Revert to old sources

sudo mv -f /etc/apt/sources.list.old /etc/apt/sources.list

Update index again

sudo apt-get update

Rejoice!

Now you can just follow the upgrade instructions and almost nothing will be downloaded during the upgrade, because everything is already on your hard drive.

#MostlyUnixish #ubuntu #linux #upgrade

Sometimes when performing your daily apt-get update, you'll experience messages like

E: The package lists or status file could not be parsed or opened.

or

The package index files are corrupted

Such messages usually don't go away for quite a long time, and may prevent legitimate updates from installing.

This usually happens even more frequently if using a proxy to access apt archives.

While I don't know what's the root problem, I've got a quick workaround that seems to fix the immediate error:

sudo -s -H bash -c 'apt-get clean && rm -f /var/lib/apt/lists/* ; rm -f /var/lib/apt/lists/partial/* && apt-get clean && apt-get update'

#MostlyUnixish #linux #ubuntu #debian #deb #apt

Whenever I install a production system/server I tend to enable full automatic updating, because it's usually better that something breaks because of a failed update rather than leaving a production machine unpatched; and if you pick a rather stable distribution (Centos or Ubuntu LTS are good examples) chances that you'll end up with a broken system are fairly low.

Btw let's get back to the point: in such cases you may end up with a disk which was filled up with obsolete kernels. The following snippets allows you to get all outdated kernels which are not in use, so you can automagically pipe its output to an apt-get remove -y in a cron job.

That may sound trivial, but what happens if you're not careful (e.g. if you try deleting all kernels but the latest) is that you might try removing the currently running kernel – and it's pretty bad if that happens in an unattended cron job.

#!/usr/bin/env python

# print all installed kernel/headers/etc BUT the current and the latest;
# suitable to be used with apt-get remove.
# requires aptitude to be installed. Works on Ubuntu and probably Debian

from subprocess import check_output
import re

def runcmd(s):
    return check_output(s.split())

# should work for anything until kernel 3.100
kernel_version_pattern = re.compile("[23]\.\d{1,2}\.\d{1,2}-\d{1,3}")
def get_kernel_version(kernelstring):
    return kernel_version_pattern.search(kernelstring).group(0)

def get_providing_packages(pkg):
    return filter(lambda x: x != "",
        map(str.strip,
            runcmd('aptitude search ~i~P%s -F%%p' % pkg).split("\n")
            )
        )

def get_nonmatching_packages(package_list, excluding):
    return [k for k in package_list if not get_kernel_version(k) in
        excluding]

all_kernels = get_providing_packages("linux-image")
all_kernels.sort() # lexicographical

kernel_versions = map(get_kernel_version, all_kernels)
latest_version = kernel_versions[-1]
current_version = get_kernel_version(runcmd("uname -r"))

kernels_to_remove = get_nonmatching_packages(all_kernels, (current_version,
    latest_version))

impl_headers = get_providing_packages("linux-headers")

headers_to_remove = get_nonmatching_packages(impl_headers, (current_version,
    latest_version))

# This seems to be needed in Ubuntu >= 13.04
#base_headers_to_remove = [header.replace("-generic", "") for header in headers_to_remove]
#headers_to_remove += base_headers_to_remove

print " ".join(kernels_to_remove + headers_to_remove)

Suggested use in a cron job, of course, is just:

apt-get remove --purge -y `ubuntu_get_obsolete_kernel_and_headers_pkgs.py`

WARNING: recent changes to the way Ubuntu marks dependencies and provided names for kernel headers require that you uncomment a couple of lines in the script towards the end; just remove the # at the beginning of the lines 46 and 47.

UPDATE: in recent Ubuntu versions, just invoking apt-get autoremove --purge will do the trick. Such command will remove all automatically installed packages that are no longer required in the running system. It can remove other packages beyond outdated kernels, by the way.

#MostlyUnixish #linux #ubuntu #debian #update #maintenance