Tag Archives: Linux

Resume from Hibernate Failed on Ubuntu Gutsy Gibbon

For many years I’ve enjoyed the reliability of the Ubuntu/Kubuntu Linux hibernate functionality (just the opposite of Windows). However, today it actually failed. When I powered up the system, it didn’t resume from the swap file. Instead, it just booted up as if I had previously killed the power.

Upon checking into the problem, I noticed that the UUID for the swap partition had changed. I don’t know why. After much hunting and trial-and-error, I was able to reinitialize the swap partition, update the necessary config files and get the system to resume from hibernate once again.

1. First, you need to know the /dev path to your swap file (e.g. /dev/hda2). If you don’t know what it is, take a look inside the /etc/fstab file. In the recent versions of Ubuntu, there is a comment above each device’s UUID entry to tell you what path it points to. Look for a line with

UUID=a-bunch-of-letters-and-numbers none swap sw 0 0

On the line above it should be a comment that says what partition it is (e.g. # /dev/hda2)

Now, armed with that information, do the following:

2. sudo mkswap /dev/your-swap-partition
For /dev/your-swap-partition, fill in the swap partition path you found in the /etc/fstab file. This will reinitialize your swap partition and create a new UUID. Copy down the new UUID (e.g. copy it to the clipboard).

3. sudo gedit /etc/fstab
Look for the same UUID= line from step #1 (the one for your swap partition). Replace the existing UUID value with the new one that you copied in step #2. Then, save the file.

4. sudo gedit /etc/initramfs-tools/conf.d/resume
Replace the old UUID value that appears after RESUME=UUID= in the file with the new value from step #2. Save.

5. cd /dev/disk/by-uuid
This directory contains symlinks from UUIDs to actual partitions.

6. sudo rm your-old-UUID
Enter the old UUID for the swap partition in place of your-old-UUID. This will remove the old, incorrect symlink.

7. sudo ln -s ../../your-swap-partition your-new-UUID
Now, create a new symlink from your swap partition to the new UUID.

8. sudo swapon -va
This will mount the swap partition based on the UUID settings you entered. If it succeeds, you didn’t make any mistakes. If it fails, then you need to verify that you have the correct UUID and partitions in the steps above.

9. sudo update-initramfs -u
This will create a new initramfs image. When it’s done, you’ll be able to hibernate and resume again.

That was a really weird problem. Thanks to a combination of techniques from these two sources, I was able to get it back to normal:

Suddenly my swap drive was missing
Kubuntu Edgy: swap failed when awaken from hibernate

Pidgin Has No Sound In Ubuntu Gutsy Gibbon

For some reason, Pidgin, which is included in Ubuntu 7.10 Gutsy Gibbon, has no notification sounds even though other applications do play properly. Whether I selected Automatic or ALSA as the output method, no sounds would play. Here’s how I fixed it.

  1. In Pidgin, select Preferences from the Tools menu (or press Ctrl+P)
  2. Click on the Sounds tab
  3. In the Method drop down list, select Command
  4. In the Sound command text box, enter the following: aplay %s
  5. Select an event with an assigned sound from the Sound Events list
  6. Click the Test button. You should now hear the notification sound
  7. Click the Close button

Aplay is the command-line ALSA sound player. I tested it on the command line and it played audio files just fine. So, it also works in Pidgin.

Syntax Errors Running sh Scripts on Ubuntu

Normally, I install programs from the Ubuntu repositories but today I needed to install a VPN client from a tarball using a shell script. When I ran the included install.sh file, I got a couple syntax errors:

install.sh: 22: function: not found
install.sh: 24: Syntax error: “}” unexpected

Looking inside the script, I saw that it runs /bin/sh. Nothing unusual there. Well, it turns out that on Ubuntu, sh is a symlink to dash. Apparently, since the Edgy version of Ubuntu, sh has been pointing to dash and causing various compatibility problems with custom scripts meant for sh. I’m running Gutsy so my sh points to dash as well.

Two quick ways to fix the problem is to either change #!/bin/sh in the script file to #!/bin/bash (which I did) or change the symlink for /bin/sh to point to bash instead of dash. I may opt for the latter but the former worked just fine to get my VPN client installed.

Monitor Linux Exit Codes on the Command Line

As you may already know, when programs end in Linux they return a value to the shell known as an exit or error code. It’s often a zero when everything is OK and a positive or negative number when something goes wrong (the actual definition is program-dependent). Normally, this value is used by scripts to know if a command failed so that it can act accordingly. However, as a power user, it’s good to know about this value as well.

The most common way to determine what exit code was returned by a command is to output the contents of the special shell variable ‘?’ to the console. This is accomplished as follows:

echo $?

For example,

~$ date
Wed Nov 13 21:24:07 PST 2007
~$ echo $?
0
~$ _

Here, I ran the date command which displayed the current system date/time. Then, by echoing the ‘?’ variable, I see that the date command exited with a code of zero indicating that everything was fine. Contrast this with the following:

~$ ls foo
ls: foo: No such file or directory
~$ echo $?
2
~$ _

According to the man page for the ls command, the exit codes are defined as “Exit status is 0 if OK, 1 if minor problems, 2 if serious trouble.” Since there was no file or directory named ‘foo’, the ls command returned an exit code of two to indicate “serious trouble”.

OK, so what if you always want to be able to tell what the exit code of a command is without having to always remember to echo it to the console? Well, you can add the value to the command prompt. Simply insert the string ‘$?’ wherever you like in your existing prompt string (PS1, PS2, PS3 and/or PS4).

My original PS1 was

‘u:w$ ‘

which looks like,

peter:~$ _

So, I added ‘:E$?’ between the user name (u) and colon and exported the new string to PS1.

export PS1=’u:E$?:w$ ‘

Now, my prompt looks like,

peter:E0:~$ _

I added the ‘E’ character to remind me that this is an error/exit code but you can leave it off. Going back to the ls example, let’s see what happens with the new prompt.

peter:E0:~$ ls foo
ls: foo: No such file or directory
peter:E2:~$ _

As you can see, my new prompt makes the exit code 2 plainly visible. I no longer have to bother to type the echo command and I can even check previous exit codes in the backscroll buffer. You can’t do that with the echo command since the ‘?’ shell variable is overwritten after every command.

Got more cool Linux tricks? Share them in the comments.

Fixed White Borders in Compiz Fusion

As I mentioned the other day, I upgraded one of my systems from Kubuntu Feisty Fawn to Gutsy Gibbon and had to fix some quirks with Compiz Fusion. Another anomaly I had was the appearance of wide white borders around application menus as well as the K-Menu in KDE. It appeared as though the menu shadows weren’t being rendered properly.

Fortunately, the fix for that was quite easy. Instead of the default KDE window decorator, gtk-window-decorator, use Emerald. The package can be found in Adept. After installing it, run emerald –replace to turn it on without having to log out. To adjust settings and customize the window decorations, go to Settings in the K-Menu and run Emerald Theme Manager.

So far, I’m liking Compiz Fusion. It hasn’t crashed and it’s very fast. I don’t notice any performance penalty as compared to using the regular 2D desktop. Granted, the 3D animations are just eye candy but they’re fun.