Category Archives: linux

Quick How-to: Automatically Enable Keyboard Wakeup From Suspend

If you like your power usage low, you probably put your computer to sleep (suspend) as much as possible when idle. If you want to wake up the machine by hitting a key on your keyboard you may need to break some sweat. Even in laptops where this feature is enabled by default, sometimes extra keyboards won’t work.

If you’re using a modern Linux kernel (3.2 and above) and have udev installed you can automatically enable wakeup upon connecting a keyboard by adding the following script to your system.
Simply put the following under your udev rules (e.g. /etc/udev/rules.d/90-keyboardwakeup.rules):

#Whenever a keyboard is connected to the machine, enable wakeup on its parent device
#Note: Conditions are *string* match, not numerical. Check your /sys files for the exact string 
#Enable wakeup on any keyboard connected. Keyboards are HID (class 3) protocol 1 devices.
SUBSYSTEM=="usb", ATTRS{bInterfaceClass}=="03", ATTRS{bInterfaceProtocol}=="01" RUN+="/bin/sh -c 'echo enabled > /sys$env{DEVPATH}/../power/wakeup'" 

The example is based on this post but instead of restricting to a single vendor/product the script should match any USB keyboard (I used a wireless Logitech to test it).

The above should work, but if you need to troubleshoot continue reading.

Note: Accessing device information in Linux (and especially USB devices) can be very confusing, proceed with patience and be ready to go reading around.

To test the script above, you can use udevadm (finding your sysfs /dev/bus/… file is a little tricky. You can go over all of them until you find your device).
Replace the /dev/bus index with the appropriate one:

sudo udevadm test /dev/bus/001/005

If the condition matches you should see in the command output something like (output truncated and highlighted):

ID_MODEL_FROM_DATABASE=Unifying Receiver
ID_VENDOR_FROM_DATABASE=Logitech, Inc.

run: ‘/bin/sh -c ‘echo enabled > /sys/devices/pci0000:00/0000:00:14.0/usb1/1-5/1-5:1.0/../power/wakeup”
Unload module index
Unloaded link configuration context.

Another test is to restart the udev service, disconnect and reconnect the USB keyboard and run (again, replace device index with appropriate one):

cat /sys/bus/usb/devices/1-5/power/wakeup

Output of the last command should be enabled.

Note that the device itself is 1-5:1.0  but the test is for device 1-5. The reason is that power control is on USB hub rather than the device (keyboard) itself. In this case the ‘hub’ was actually the IR receiver but in wired keyboard it will be one of the computer’s USB hubs

Note that I did not find it necessary to enable wakeup on the parent USB hub as recommended here. You may need to do so.

To do the ultimate test put your computer to sleep (example below assumes you have system.d installed. It takes control over power events over HAL):

sudo dbus-send --system --print-reply --dest=org.freedesktop.login1 /org/freedesktop/login1 "org.freedesktop.login1.Manager.Suspend
" boolean:true

The computer should put itsef to sleep. Hit the keyboard and check it comes back online.

Advertisements

Leave a comment

Filed under howto, linux

Debian Squeeze Released

Just in time for the Super Bowl Debian 6.0 (Squeeze) was released earlier today. I’ve been using it on multiple installations fr servers, desktops and laptop and I can report it is rock solid as we’ve come to expect from Debian. Hardware support is very broad (although I don’t know if Intel’s latest Sandy Bridge chipset is supported completely). The software collection is mostly up-to-date, with the exception of desktop environments that are a bit lagged behind (Gnome 2.30, KDE 4.4.5 and Xfce 4.6), all in the name of stability and safe migration from the current stable release.

If you’re planning to install Debian 6.0, please note that this is the first time Debian is releasing their mainline image with no non-free firmware images. This is done to make sure the image is true to the Debian spirit. The step may cause problems to users with hardware that includes non-free firmware (Broadcom NIC’s for example). It is recommended to use the Debian alternative CD or to checkout Debian’s Firmware page.

Debian also launched an updated website with a new branding and good accessibility. The look is refreshing, but a couple of things might be nice to add to the new site. First, it will be useful to link instructions about non-free firmware on the main page and the download links. Second, an official Virtualbox image of Debian would be much appreciated.

While for some people this mark the dist-upgrade season for their servers, I’m planning to move my laptop to the new testing repository and get the all the bleeding-edge latest software releases that were held up due to Squeeze release.

Congratulations to the entire Debian team for this achievement and happy installation for everyone.

Leave a comment

Filed under linux

Nokia and Canonical, the Odd Couple?

What would you say about Canonical and Nokia merger?

On one hand Canonical created Ubuntu, the most popular Linux distribution on desktops, but isn’t getting a significant share in the growing mobile market. Nokia on the other hand, once mobile king, is struggling to hold its place in the new world of smatrphones and tablets. Nokia’s traditional friendly approach to phones now seemed quaint and uninspired on a touch-screen smartphone and Canonical is all but invisible in that market.

Both companies has more in common. Nokia’s experience with open source software hasn’t been completely successful. In the past Nokia purchased and open sourced the Symbian mobile OS, but failed to create community traction. Nokia’s other major open source move, the purchase of the popular Qt framework, has been fruitful , but Nokia isn’t capitalizing on it yet.
Nokia’s latest adventure is a strategic effort to enter the Linux world with Meego, a Linux distribution for the mobile market (actually a joint venture with Intel, AMD, and other non-leaders in the mobile world).
From Canonical’s side things are similar. During the netbook-smartphone-tablet turmoil of the past couple of years, Canonical remained oddly quiet, releasing only the Ubuntu netbook edition. Only recently Canonical started investigating the whole mobile interface with Unity. That marked another step closer to Nokia by choosing Qt as the framework for Unity 2D (which turned to a hit even before official release with upcoming Ubuntu 11.4).
On the practical end of things, Nokia had very little to show in the last CES, especially when it comes to Meego. This may mean Nokia is taking it slow with Linux. Canonical had some mixed experience cooperating with hardware vendors in the past, but it is obvious that both firms has lots to gain from this move. Nokia can become a major player in the Linux world, and Ubuntu can be a valid Apple competitor with the powerful combination of OS and an experienced hardware house.

Leave a comment

Filed under linux, opinion

Powering-Off Discrete Graphics on Switchable Graphics Laptops

Switchable graphics is gaining popularity as a solution to balance performance and power consumption. Linux support for this feature is still very much in development, and until it is the discrete graphics card may take resources even when you don’t use it.

The development of switchable graphics on Linux is being led by Hybrid graphics Linux group. They recently released a driver to turn off the external graphics card. On my system shutting down the card reduced power consumption by 5-10 watts.
Note: This is experimental stuff, your computer may hang or act unexpectedly. Please make sure the discrete graphics card is not being used before proceeding.

Here’s how to test it:
First, install and run poewrtop to get an idea for power consumption (the laptop needs to be disconnected from AC adapter):

sudo apt-get install powertop
sudo powertop

Second, it is recommended to rmmod any kernel modules that may be mapped to the device. For example if you have an Nvidia discrete graphics with the closed source driver running, you should:

sudo rmmod nvidia

Next, download and build the driver:

sudo apt-get install git linux-headers-`uname -r` build-essential
git clone http://github.com/mkottman/acpi_call.git
cd acpi_call
make
sudo insmod acpi_call.ko
sudo ./test_off.sh

The result of a run should look like (depending on your laptop’s hardware):

Trying \_SB.PCI0.P0P1.VGA._OFF: failed
Trying \_SB.PCI0.P0P2.VGA._OFF: failed
Trying \_SB_.PCI0.OVGA.ATPX: failed
Trying \_SB_.PCI0.OVGA.XTPX: failed
Trying \_SB.PCI0.P0P2.PEGP._OFF: failed
Trying \_SB.PCI0.MXR0.MXM0._OFF: failed
Trying \_SB.PCI0.PEG1.GFX0._OFF: failed
Trying \_SB.PCI0.PEG1.GFX0.DOFF: failed
Trying \_SB.PCI0.XVR0.Z01I.DGOF: failed
Trying \_SB.PCI0.PEGR.GFX0._OFF: failed
Trying \_SB.PCI0.PEG.VID._OFF: works!

Running powertop now should give you about 5-10 watts less.
To test the card is really off you can run the following command:

sudo lspci -vvx

Locate your external graphics card (look for VGA controller with the right make). The card’s PCI configuration space should not be accessible, so it should look something like:

01:00.0 VGA compatible controller: nVidia Corporation GT218 [NVS 3100M] (rev ff) (prog-if ff)
        !!! Unknown header type 7f
00: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
...

To re-enable the card, reboot the machine.

Please consider joining the Hybrid graphics Linux mailing list to help the development effort.

1 Comment

Filed under howto, linux

Skype on Debian Testing (Squeeze) 64-bit (Workaround)

Short Version

  1. Install 32-bit libs:
    apt-get install ia32-libs ia32-libs-gtk
  2. Download 64-bit version for Ubuntu from skype.com, install the deb:
    dpkg -i skype-ubuntu-intrepid_2.1.0.81-1_amd64.deb
    apt-get install -f
  3. Get skype-wrapper from here
    (You need two files skype_wrapper.c and Makefile)
  4. Install a compiler and 32-bit headers:
    apt-get install gcc libc6-dev-i386
  5. Compile the shared library:
    make
  6. Run Skype with the wrapper:
    LD_PRELOAD=./libskype_wrapper.so skype

    Note: If you want to add LD_PRELOAD to a script or Skype shortcut remember to use its absolute path (i.e: LD_PRELOAD=/home/user/src/skype-wrapper/libskype_wrapper.so)

Long Version

Although not free software, Skype is found on many Linux installations. A couple of bugs in Debian testing prevents it from running properly. This guide supplies a workaround to get it working.

Skype for Linux 64-bit is actually a 32-bit application packed in a 64-bit package. Since it’s a dynamically linked application, you’ll need all the 32-bit libraries it uses:
apt-get install ia32-libs ia32-libs-gtk

Note that we installed ia32-libs-gtk, even though Skype is a Qt application. There’s an open Debian bug for this.

After installing the  dependencies, you can download Skype for Linux from skype.com. Note that there is no Debian 64-bit version, only Ubuntu. It will install fine anyway:
dpkg -i skype-ubuntu-intrepid_2.1.0.81-1_amd64.deb
And update dependencies by running:
apt-get install -f

Now if you’ll try running Skype, the main interface will load, but once you sign in you’ll get the following error:
Inconsistency detected by ld.so: dl-open.c: 611: _dl_open: Assertion `_dl_debug_initialize (0, args.nsid)->r_state == RT_CONSISTENT' failed!
This is caused by another bug in Debian. When Skype tries to open libpulse.so (the library for PulseAudio), it crashes. Running ldd /usr/lib32/libpulse.so.0 shows why:

linux-gate.so.1 => (0xf7700000)
libpulsecommon-0.9.15.so => /usr/lib32/libpulsecommon-0.9.15.so (0xf7666000)
libX11.so.6 => /usr/lib32/libX11.so.6 (0xf754a000)
libICE.so.6 => /usr/lib32/libICE.so.6 (0xf7531000)
libSM.so.6 => /usr/lib32/libSM.so.6 (0xf7529000)
libXtst.so.6 => /usr/lib32/libXtst.so.6 (0xf7524000)
libwrap.so.0 => not found
libasyncns.so.0 => /usr/lib32/libasyncns.so.0 (0xf751f000)
libdbus-1.so.3 => /lib32/libdbus-1.so.3 (0xf74e5000)
libpthread.so.0 => /lib32/libpthread.so.0 (0xf74cc000)
libcap.so.2 => /lib32/libcap.so.2 (0xf74c8000)
libgdbm.so.3 => not found
librt.so.1 => /lib32/librt.so.1 (0xf74bf000)
libdl.so.2 => /lib32/libdl.so.2 (0xf74ba000)
libm.so.6 => /lib32/libm.so.6 (0xf7494000)
libc.so.6 => /lib32/libc.so.6 (0xf734d000)
libwrap.so.0 => not found
libgdbm.so.3 => not found
libxcb.so.1 => /usr/lib32/libxcb.so.1 (0xf7333000)
libuuid.so.1 => /lib32/libuuid.so.1 (0xf732f000)
libXext.so.6 => /usr/lib32/libXext.so.6 (0xf7321000)
libresolv.so.2 => /lib32/libresolv.so.2 (0xf730d000)
libnsl.so.1 => /lib32/libnsl.so.1 (0xf72f6000)
/lib/ld-linux.so.2 (0xf7701000)
libXau.so.6 => /usr/lib32/libXau.so.6 (0xf72f2000)
libXdmcp.so.6 => /usr/lib32/libXdmcp.so.6 (0xf72ed000)

See the ‘not found’ entries? That means the library is linked with those libraries, but they do not exist in the system. That’s a packaging bug.
To prevent Skype from ever running into the bug, we need to prevent it from loading the library. That would be easy enough with an open source application, where we have access to the code, which is not the case here. Fortunately Skype can fail-over to libalsa, which works like a charm. Instead of removing the file from our system, we’ll trick Skype to think it’s not there.
The code can be found at here (You need two files skype_wrapper.c and Makefile). This little piece of code wraps the running application and prevents it from loading libpulse.so.0. That’s a very brute-force way, but non-destructive to the rest of the systems.
Since Skype is a 32-bit application, we’ll need to compile our wrapper as such. Install a compiler and 32-bit headers:
apt-get install gcc libc6-dev-i386
Compile the shared library:
make
Finally, run Skype with the wrapper:
LD_PRELOAD=./libskype_wrapper.so skype

You can now run Skype this way safely from scripts or shortcuts, just remember to point the absolute path of libskype_wrapper.so in LD_PRELOAD

Extra credit – Changing microphone volume in alsamizer:
If you run the test call and no one is able to hear you, your microphone may be mute. Run alsamixer and hit (you’ll see it points to ‘Capture’ in the View menu on top). Now you can unmute it by hitting m and setting the volume with the arrow keys.

10 Comments

Filed under howto, linux

Linux on Lenovo t410s #4: Kernel 2.6.34 and a Permanent Solution for Audio

This is an updated post to the workaround posted here. It provides a permanent solution for the sound problems, as well as provide better ACPI support.

Short Version

  1. Remove pcspkr (if you hadn’t done so already), as described here
  2. Install latest Alsa (1.0.32 and higher):
    sudo apt-get update && sudo apt-get dist-upgrade
  3. Install kernel build dependencies:
    apt-get install kernel-package libncurses5-dev fakeroot wget bzip2 build-essential
  4. Get and unpack the kernel sources:
    mkdir -p ~/src/

    cd ~/src/

    wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.34.tar.bz2

    tar xvfj linux-2.6.34.tar.bz2

    cd linux-2.6.34

  5. Config your kernel based on the system’s existing configuration:
    cp /boot/config-`uname -r` .config
    make silentoldconfig

    (Enter your way throught the several dozen new options)
  6. Build and install the kernel:
    make-kpkg -j6 --rootcmd fakeroot --append_to_version -custom-1-`dpkg --print-architecture` --initrd kernel_image kernel_headers

    sudo dpkg -i ../linux-headers-2.6.34-custom-1-amd64_2.6.34-custom-1-amd64-10.00.Custom_amd64.deb ../linux-image-2.6.34-custom-1-amd64_2.6.34-custom-1-amd64-10.00.Custom_amd64.deb

    sudo update-grub

  7. Reboot to your new kernel

Long Version
We’ll install a newer version of Alsa provides support of the soundcard in the t410s. We’ll also go through installing a new kernel version ‘the debian way’. This means we’ll compile a fresh kernel and create .deb packages for the image and headers. In addition this solves the ACPI buttons issues, so screen brightness can be controlled from the keyboard.

  1. If you still have pcspkr enabled, remove it as described here
  2. Alsa 1.0.32 was migrated to testing earlier today (see here). This version has initial official support of the HDA-Intel soundcard on the t410s. To get it, make sure you have ‘testing’ in your /etc/apt/sources.list, and run:
    sudo apt-get update && sudo apt-get dist-upgrade
    Once upgrade completed, check you have the latest version by running:
    dpkg -l | grep alsa-utils
    Check the installed package version >= 1.0.32-2
  3. The kernel requires several packages to build properly. For more information about kernel building in Debian see the The Debian GNU/Linux FAQ. Install the packages by running:
    apt-get install kernel-package libncurses5-dev fakeroot wget bzip2 build-essential
  4. Next up we’ll get the kernel sources and unpack them:
    mkdir -p ~/src/
    cd ~/src/
    wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.34.tar.bz2
    tar xvfj linux-2.6.34.tar.bz2
    cd linux-2.6.34

    Do not use /usr/src for custom kernel sources. Kernel headers will be installed there via a debian kernel headers package. For more information on the matter see Linux’s README.
    If you still choose to install the sources to /usr/src, it is highly recommended to build the kernel out-of-tree. For more information consult the README again, search for a reference to “make O=output/dir”
  5. Now we’ll configure the new kernel, based on the current running system configuration:
    cp /boot/config-`uname -r` .config
    make silentoldconfig

    A few dozen new options were added between 2.6.32 and 2.6.34, so you will be prompted to make a choice. From a quick look, the defaults seem perfectly fine, so just hit enter until you get the prompt back.
  6. Compiling the kernel will be done with debian’s make-kpkg tool, that will also build appropriate headers:
    make-kpkg -j6 --rootcmd fakeroot --append_to_version -custom-1-`dpkg --print-architecture` --initrd kernel_image kernel_headers
    The –append_to_version string is used to distinguish our version from the official ones. The resulting kernel image name will look like vmlinuz-2.6.34-custom-1-amd64
    Next up, installing the new package, with dpkg:
    sudo dpkg -i ../linux-headers-2.6.34-custom-1-amd64_2.6.34-custom-1-amd64-10.00.Custom_amd64.deb ../linux-image-2.6.34-custom-1-amd64_2.6.34-custom-1-amd64-10.00.Custom_amd64.deb
    Finally, update grub to append the new kernel to the boot image:
    sudo update-grub
  7. Now the system can be rebooted into the new kernel

In addition to sound working out-of-the-box, the new kernel also provides much better support for ACPI functions. Special keys like screen brightness and audio control now work. For some reason grub lost its VGA mode setting during boot (perhaps because AGP_INTEL is now loadable module and not compiled in).

Leave a comment

Filed under devenv, howto, linux

Linux on Lenovo t410s #3: Installing a Browser

Short Version

  1. Install ffmpeg:
    apt-get install ffmpeg
  2. Download all latest amd64 debs from: http://ftp.us.debian.org/debian/pool/main/c/chromium-browser/
  3. Install by running (change to match the downloaded version):
    dpkg -i chromium-browser_5.0.375.55~r47796-1_amd64.deb chromium-browser-inspector_5.0.375.55~r47796-1_all.deb chromium-browser-l10n_5.0.375.55~r47796-1_all.deb chromium-codecs-ffmpeg_0.5+svn20091210r34297+34315+35016-0ubuntu1~ucd1~0.1_amd64.deb
    You’ll get an error for missing packages, that’s OK.
  4. Install missing packages by running:
    apt-get install -f
  5. Get flashplayer:
    apt-get install falshplugin-nonfree

Long Version

Although KDE’s supplied Konquerer is not bad, and its engine was the foundation to today’s modern WebKit, it is outdated. The rekonq browser which is in development is showing good signs of development, it will take some time to reach stability.

If you like Firefox, you’ll have to install it manually from Mozilla, use a daily non-stable repository (not recommended). You can also get the official Debian version without the branding a.ka Iceweasel (apt-get install iceweasel), but this is quite an old version of Firefox (3.5.9).
Mozilla and Linux have a long history of partial cooperation, for a very justified gripe see this post.

On the upside of things, chromium browser can be installed. Chromium is an open-source browser released by Google, and is the base to Google Chrome. At the moment it is can only be found in the unstable repository. This is only because it is not considered for the upcoming squeeze release, not due to stability issues. For more information see here.

  1. Install ffmpeg, the media player  used by chromium:
    apt-get install ffmpeg
  2. The latest version of chromium-browser can be found at the main unstable repository, here:
    http://ftp.us.debian.org/debian/pool/main/c/chromium-browser/
  3. After downloading, install all the packages in one shot, with one dpkg -i command, for example:
    dpkg -i chromium-browser_5.0.375.55~r47796-1_amd64.deb chromium-browser-inspector_5.0.375.55~r47796-1_all.deb chromium-browser-l10n_5.0.375.55~r47796-1_all.deb chromium-codecs-ffmpeg_0.5+svn20091210r34297+34315+35016-0ubuntu1~ucd1~0.1_amd64.deb
    The system needs a few more packages, so we’ll use the automagic of apt-get to satisfy them. This is why we get the error message.
  4. Allow apt-get to download and install missing packages by running:
    apt-get install -f
  5. You’ll probably want Adobe’s Flash player, although there are several open-source replacements, they are still incomplete in terms of full support. To install, use Debian’s wrapper that gets the latest 64-bit native version of Flash player from Adobe:
    apt-get install falshplugin-nonfree
    Note: Sound will not work until we fix it permanently with new version of Alsa and a new Kernel. Update on this matter will be posted soon.

Chromium give most of the capabilities of the commercial version, including extensions, bookmarks sync and skins. Visit Google’s page for extensions like AdBlock.

Leave a comment

Filed under devenv, howto, linux