ASUS M6N Notebook
Foreword
From the times when I started my adventure in the world of Linux I remember that getting full support for the features offered by mobile computers was rather difficult to achieve. Today those kind of problems are over. We have direct support for both suspend and hibernate functions a long side with vendor specific ACPI drivers available in Kernel. Most of modern binary distributions work on mobile devices without any problems giving users ability to fully control advanced ACPI functions. There are also available specific distributions for mobile computers like Ubuntu Netbook Edition or created by Intel and Nokia MeeGo platform. Today Linux sets new trends in mobile computers market.
I have a quite old Asus M6N notebook which I'm using mostly for browsing Internet, connecting to remote servers and running presentations. I use my notebook only If I'm away from my main computer. It's not a speed daemon especially for todays standards but for those kind of tasks my notebook is perfect and I don't need a better one. I could use any Linux distribution and they would work well but fortunately I'm Gentoo Linux user and thanks to this I'm able to make my notebook work perfect. Here you can find my configuration for mobile computer, including kernel, advanced ACPI, multimedia keys and KDE desktop environment configurations that let me use my notebook the way I want to. Some of the provided here information are specific for both my distribution and my notebook but some of them should be applicable not only for any distribution but with small changes also for any notebook. I hope you will find some of provided here information useful. I will start with kernel configuration.
TuxOnIce Kernel Configuration
Default Linux kernel for my distribution has the same support for suspend and hibernation that most of Linux distribution has. It's working well but it can be done better. This better way is kernel patchset called TuxOnIce. It gives the user additional features like ability to cancel hibernation or image restoration by pressing escape, nice user interface, fast multithreaded compression support and many others. To use TuxOnIce you have to patch your distribution kernel, but in Gentoo we already have a kernel with TuxOnIce patchset available in portage tree. So for Gentoo Linux all you have to do is to run this command in terminal:
USE="symlink" emerge -av sys-kernel/tuxonice-source
To use nice TuxOnIce GUI interface I additionally installed tuxonice-userui package by running following command in terminal:
USE="fbsplash" emerge -av sys-apps/tuxonice-userui
To configure my new kernel I had to enter kernel catalog and start menuconfig by running following commands in terminal:
cd /usr/src/linux make menuconfig
Next I had to mark all kernel options needed to run TuxOnIce suspend and hibernate functions. Below you will find list of those options.
Linux Kernel Configuration: Enable TuxOnIce features |
Power management and ACPI options ---> [*] Suspend to RAM and standby [*] Hibernation (aka 'suspend to disk') (/dev/sda8) Default resume partition <*> Enhanced Hibernation (TuxOnIce) ---> *** Image Storage (you need at least one allocator) < > File Allocator <*> Swap Allocator *** General Options <*> Compression support <*> Userspace User Interface support (/sbin/tuxoniceui_fbspalsh) Default userui program location [ ] Allow Keep Image Mode [*] Replace swsusp by default [ ] Wait for initrd/ramfs to run, by default (25) Default waiting time for emergency boot messages (2000) Default extra pages allowance [*] Checksum pageset2 -*- Cryptographic API ---> <*> LZO compression algorithm |
As you can see I'm using both suspend to Ram and hibernate functions. Very important thing is to provide correct swap partition location, my swap is located on /dev/sda8. In TuxOnIce configuration I'm not using file allocator, I will use swap hibernation only. I'm also providing a fbsplash user interface location to have graphical information during suspend and resume operation. This will require additional configuration of my graphical boot up splash, more information you will find below. Last important thing is compression which will lower suspend image capacity. It's highly important to build LZO compression algorithm directly into kernel not as a module.
After marking all necessary kernel modules I'm ready to recompile, install and use new kernel. I usually do it by running this commands in terminal:cd /usr/src/linux make && make modules_install install
Now I can take care of my system splash image to make it compatible with TuxOnIce suspend GUI. Normally I would create graphical bootup splash using natural_gentoo theme by running following commands in terminal:
emerge -av splashutils splash-themes-gentoo splash_geninitramfs --verbose --res 1024x768 --generate /boot/fbsplash-natural_gentoo-1024x768 natural_gentoo
To make my splash use installed earlier TuxOnIce GUI I have to decompressed it and copy tuxoneice_fbsplash into it. To do it I need to run following commands in terminal:
mkdir ~/initrd.d cp /boot/fbsplash-natural_gentoo-1024x768 ~/initrd.d/ cd ~/initrd.d gunzip -c fbsplash-natural_gentoo-1024x768 | cpio -idm --quiet -H newc rm fbsplash-natural_gentoo-1024x768 cp /sbin/tuxoniceui_fbsplash sbin/ find . | cpio --quiet --dereference -o -H newc | gzip -9 > /boot/fbsplash-natural_gentoo-1024x768
Now I have TuxOnIce graphical notification during both hibernation and system resume.
The suspend to Ram and hibernation should work without any problem with this configuration in graphical desktop environment. I'm using KDE 4.x and KDE is using pm-utils and hal to suspend and hibernate system. This was working for me but I thought I could make it work better. To do it I use hibernate-script which has some advantages over core pm-utils implementation. Some of them are: easy to use complex plug-in based configuration with ability to suspend virtual machines before core system suspend, ability to change grub splash for suspended system, ability to unmount network file system before suspend, ability to restart chosen system services after resume and ability to change instant messengers status on suspend. To use hibernate script I have to install it. In Gentoo Linux we would do it like this:
emerge -av sys-power/hibernate-script
Main problem for me with using hibernate script is that there is no way (except changing the source code) to force KDE desktop environment to use hibernate-script instead of pm-utils and hal. But there is no need to change KDE behavior because you can force pm-utils to make a special hal script which will use hibernate-script. This solution is taken from Gentoo Linux Wiki pm-utils HowTo. Below you can find a full script which should be saved as /etc/pm/sleep.d/01HibernateScripts.
#!/bin/bash HAL_HIBERNATE="/usr/lib/hal/scripts/linux/hal-system-power-hibernate-linux" HAL_SUSPEND="/usr/lib/hal/scripts/linux/hal-system-power-suspend-linux" case $1 in hibernate) /bin/mv ${HAL_HIBERNATE} ${HAL_HIBERNATE}.original /bin/echo "#!/bin/bash" >> ${HAL_HIBERNATE} /bin/echo "/usr/sbin/hibernate" >> ${HAL_HIBERNATE} /bin/echo "exit \$?" >> ${HAL_HIBERNATE} /bin/chmod +x ${HAL_HIBERNATE} /usr/bin/killall pm-hibernate /usr/bin/chvt 7 /usr/sbin/hibernate ;; suspend) /bin/mv ${HAL_SUSPEND} ${HAL_SUSPEND}.original /bin/echo "#!/bin/bash" >> ${HAL_SUSPEND} /bin/echo "/usr/sbin/hibernate-ram" >> ${HAL_SUSPEND} /bin/echo "exit \$?" >> ${HAL_SUSPEND} /bin/chmod +x ${HAL_SUSPEND} /usr/bin/killall pm-suspend /usr/bin/chvt 7 /usr/sbin/hibernate-ram ;; esac
As you can see this file is creating special hal script which will use hibernate script commands whenever the hibernate and suspend actions are taken by user. The reason for such weird behavior is that during the system update the self created hal scripts can be overwritten. When you will create above script the hal scripts using hibernate-script will always be available in system. Now I can use hibernate script. To make full use of it I should make sure that a system service provided with the hibernate-script will be run on every computer boot. This service is called hibernate-cleanup. To make it run on every system boot I should run following command in terminal:
rc-update add hibernate-cleanup boot
The last thing to make my suspend and resume work as I would like it, is to configure hibernate-script itself. To do it I had to edit the /etc/hibernate/common.conf file. Below you can find my common.conf configuration file.
# Configuration options common for suspending to disk or RAM. # Options are not case sensitive. # # See hibernate.conf(5) for help on the configuration items. ############################################################################## ### Some global settings ############################################################################## Verbosity 1 LogFile /var/log/hibernate.log LogVerbosity 4 LogTimestamp yes # AlwaysForce yes AlwaysKill yes # HibernateVT 15 Distribution gentoo # XDisplay :0 ############################################################################## ### Scriptlets ### Scriptlets provide support for doing all sorts of things before and after ### suspending. The defaults settings here should work for most people, but ### you may wish to edit these to taste. Consult "hibernate -h" for help on ### the configuration settings. ############################################################################## ### bootsplash ## If you use bootsplash, also enabling SwitchToTextMode is recommended if ## you use X, otherwise you may end up with a garbled X display. #Bootsplash on #BootsplashConfig /etc/splash/tuxonice/1024x768.cfg ### clock SaveClock restore-only #DirectIsa ### devices # IncompatibleDevices /dev/dsp /dev/video* IncompatibleDevices /dev/video* ### diskcache DisableWriteCacheOn /dev/sda ### fbsplash (enable SwitchToTextMode if you use this) FBSplash on FBSplashTheme natural_gentoo ### filesystems # Unmount /nfsshare /windows /mnt/sambaserver UnmountFSTypes smbfs nfs vfs # UnmountGraceTime 1 # Mount /windows ### grub ChangeGrubMenu yes GrubMenuFile /boot/grub/grub.conf AlternateGrubMenuFile /boot/grub/menu-suspended.lst BackupGrubMenuFile /boot/grub/grub.conf.bak # see http://bugs.debian.org/317479 # RemountXFSBoot yes ### hardware_tweaks # IbmAcpi yes RadeonTool yes # Runi915resolution yes FullSpeedCPU yes ### lilo # EnsureLILOResumes yes ### lock (generally you only want one of the following options) ## For console you need vlock available. ## For x you need xscreensaver-command-command available. ## For gnome you need gnome-screensaver-command available. ## For kde you need dcop, kscreensaver available. ## For XAuto you need xautolock available. ## For Xtr you need xtrlock available. ## For Freedesktop (for example KDE4) you need dbus-send available # LockConsoleAs root # LockXScreenSaver yes # LockGnomeScreenSaver yes # LockFreedesktop # LockKDE yes # LockXLock yes # LockXAutoLock yes # LockXtrLock yes ### misclaunch OnSuspend 20 echo "Idę Spać Co się dziwisz czasami trzeba :D!" OnResume 20 echo "Gotów do roboty. No dalej co robimy!" ### modules UnloadModules sd_ricoh # UnloadAllModules yes UnloadBlacklistedModules yes LoadModules auto # LoadModulesFromFile /etc/modules ### modules-gentoo # GentooModulesAutoload yes ### network DownInterfaces UpInterfaces auto ### networkmanager EnableNMReconnect yes ### pause_audio MuteAudio no PauseAudio yes ### pcmcia EjectCards yes ### programs #IncompatiblePrograms ### services RestartServices hsf samba nfs nfsmount numlock lm_sensors sensord smartd hddtemp vixie-cron avahi-daemon irda ntpd distccd moblock sshd ulogd iptables laptop_mode acpi # StopServices alsasound # StartServices aumix ### vbetool #EnableVbetool yes #RestoreVbeStateFrom /var/lib/vbetool/vbestate #VbetoolPost yes #RestoreVCSAData yes ### xhacks SwitchToTextMode yes # UseDummyXServer yes # DummyXServerConfig xorg-dummy.conf ### xstatus ## This can be set to gnome, kde or x: ## For gnome you need zenity available. ## For kde you need dcop, kstart, kdialog available. ## For x you need to have xosd OR xmessage available. # XStatus x # XmessageDisable yes # XSuspendText Preparing to suspend... # XResumeText Resuming from suspend... ## When using XStatus x, and you have xosd installed: # XosdSettings --font '-misc-fixed-medium-r-semicondensed--*-120-*-*-c-*-*-*' --colour=Green --shadow 1 --pos bottom --align center --offset 50 ### xbacklight # BackLight yes ### gaim ## You need to have dbus, gaim_remote available. # LogoutGaim yes # GaimRestoreStatus yes # GaimLogoutMessage Hibernating # GaimLoginMessage Back from hibernation ### pidgin LogoutPidgin yes PidginRestoreStatus yes PidginLogoutMessage Hibernating - bye! # PidginLoginMessage I'm back! ### SSH and PGP keys # AgentsClearGPG yes # AgentsClearSSH yes ### Virtualbox SuspendVirtualbox yes
These file is quite easy to read. On the top you will find logging configuration, lower you can see list of network file systems that need to be unmounted before suspend. Then you can see grub menu configuration, I wil provide grub menu information later. The important thing is also list of kernel modules that should be unloaded. I'm unloading module for my SD card reader. Litter lower you can see list of system services that should be restarted after system resume. As you can see I'm restarting mostly network services to make sure they will work all right. I'm also locking my X environment before suspend this way after resume I will be forced to provide password to get back to normal work. Another important thing is making use of utility named radeontool. This is special tool for power management of my graphics card. With proper graphics card configuration this tool should be installed as dependency to pm-utils. Of course you can always install this tool manually by running following command in terminal:
emerge -av app-laptop/radeontool
Last thing I need to do is to create grub configuration files. First file /boot/grub/grub.conf will be responsible for normal system start. Below you can see my grub.conf file.
default 0 timeout 10 splashimage=(hd0,0)/boot/grub/gentoo.xpm.gz title Gentoo Linux TuxOnIce 2.6.32-r9 (Main) root(hd0,0) kernel /boot/vmlinuz-2.6.32-tuxonice-r9 root=/dev/sda2 resume=swap:/dev/sda8 video=uvesafb:1024x768-24@60,mtrr:2,ywrap splash=kdgraphics,silent,fadein,theme:natural-gentoo quiet CONSOLE=/dev/tty1 fbcon=scrollback:256K acpi=on lapic=yes initrd (hd0,0)/boot/fbsplash-natural_gentoo-1024x768 title Gentoo Linux TuxOnIce 2.6.32-r9 (Rescue) kernel /boot/vmlinuz-2.6.32-tuxonice-r9 root=/dev/sda2 init=/bin/bb title Memtest86Plus root(hd0,0) kernel --type=netbsd /boot/memtest86plus/memtest
You can see one important information for suspend and resume, a kernel parameter resume pointing to my swap partition location. This parameter is required only if I would not provide proper swap partition information during my kernel configuration. Second grub configuration file is /boot/grub/menu-suspended.lst. This file will be responsible for system start after hibernation. The hibernate script will take care of replacing the grub files during hibernation process. Below you can see my menu-suspended.lst file.
default 0 timeout 10 splashimage=(hd0,0)/boot/grub/gentoo.xpm.gz title Gentoo Linux TuxOnIce 2.6.32-r9 (RESUME SUSPENDED SYSTEM) root(hd0,0) kernel /boot/vmlinuz-2.6.32-tuxonice-r9 root=/dev/sda2 resume=swap:/dev/sda8 video=uvesafb:1024x768-24@60,mtrr:2,ywrap splash=kdgraphics,silent,fadein,theme:natural-gentoo quiet CONSOLE=/dev/tty1 fbcon=scrollback:256K acpi=on lapic=yes initrd (hd0,0)/boot/fbsplash-natural_gentoo-1024x768 title Gentoo Linux TuxOnIce 2.6.32-r9 (START UNSUSPENDED SYSTEM) root(hd0,0) kernel /boot/vmlinuz-2.6.32-tuxonice-r9 root=/dev/sda2 resume=swap:/dev/sda8 noresume video=uvesafb:1024x768-24@60,mtrr:2,ywrap splash=kdgraphics,silent,fadein,theme:natural-gentoo quiet CONSOLE=/dev/tty1 fbcon=scrollback:256K acpi=on lapic=yes initrd (hd0,0)/boot/fbsplash-natural_gentoo-1024x768 title Gentoo Linux TuxOnIce 2.6.32-r9 (Rescue) kernel /boot/vmlinuz-2.6.32-tuxonice-r9 root=/dev/sda2 init=/bin/bb title Memtest86Plus root(hd0,0) kernel --type=netbsd /boot/memtest86plus/memtest
As you can see there are two kernel configurations on this file. First one which should boot up and load suspended system from a swap partition and second one which has special kernel parameter noresume which will start up system in a normal way. The third grub configuration file /boot/grub/grub.conf.bak is just a copy of the first file. This is all I did to make my suspend and hibernate work as I want to. Next thing is ACPI configuration for my notebook.
ACPI configuration
ACPI configuration is two-stage process. First stage is kernel configuration, second one is installation and configuration of tools which will make use of features available in kernel. Below you will find ACPI kernel configuration for my notebook.
Linux Kernel Configuration: Enable ACPI features |
Power management and ACPI options ---> [*] Power Management support [*] Run-time PM core functionality [*] ACPI (Advanced Configuration and Power Interface) Support ---> [*] Deprecated /proc/acpi files [*] Deprecated power /proc/acpi directories < > ACPI 4.0 power meter [*] Future power /sys interface [*] Deprecated /proc/acpi/event support <M> AC Adapter <M> Battery <M> Button <M> Fan -*- Dock <*> Processor < > Processor Aggregator (0) Disable ACPI for systems before Jan 1st this year <M> Smart Battery System CPU Frequency scaling ---> [*] CPU Frequency scaling [*] Enable CPUfreq debugging <M> CPU frequency translation statistics [*] CPU frequency translation statistics details Default CPUFreq governor (userspace) ---> <*> 'performance' governor <*> 'powersave' governor <*> 'userspace' governor for userspace frequency scaling <*> 'ondemand' cpufreq policy governor <*> 'conservative' cpufreq governor <M> ACPI Processor P-States driver -*- CPU idle PM support Device Drivers ---> [*] X86 Platform Specific Device Drivers ---> <M> Asus Laptop Extras < > ASUS/Medion Laptop Extras (DEPRECATED) |
As you can see I marked most of available in kernel ACPI features including all possible CPU frequency scaling governors. Very important thing is marking direct support for ACPI features typical for a notebook vendor. For Asus notebooks it's highly important not to use old deprecated kernel module even if you have as old notebook as mine. The new support will work just fine. Now we can install some programs to use advanced capabilities of mobile computer.
If you already installed system with graphical desktop environment, you most likely has all needed software. For Gentoo Linux system is important to add two USE flags that affect advanced power management to /etc/make.conf file. Those flags are: acpi and laptop. After this you should make sure all packages using those tools will be rebuild. To do it in Gentoo Linux system we need to run following command in terminal:
emerge --deep --newuse --update world
This should end up in installing most important package for power management functions, which is pm-utils. This package should be installed as dependency to hal hardware abstraction layer package or as dependency to desktop environment power management utility. This packages can be also installed manually by running following commands in terminal:
emerge -av sys-power/pm-utils
There are also another power management tools you may want to have in your system. First one is acpid daemon for advanced power management, second is laptop-mode-tools third is cpufrequtils. You can install all those tools by running following command in terminal:
emerge -av sys-power/acpid app-laptop/laptop-mode-tools sys-power/cpufrequtils
After installing all those tools you also need to add its system services to default run level. To do it in Gentoo Linux you can run following commands in terminal:
rc-update add acpid default rc-update add laptop-mode-tools default rc-update add cpufrequtils default
Today most of the power management tasks are executed by graphical desktop environment power management utility. KDE the desktop environment I use have really good tool called PowerDevil. I added all those services to default run level because I prefer to have power management support even if I'm not logged to the graphical environment. One of those tools require additional configuration. For cpufrequtils you need to provide a CPU governor that should be setup on start and stop of the system service. This configuration should go to /etc/conf.d/cpufrequtils. Below you can find my /etc/conf.d/cpufrequtils file.
# /etc/conf.d/cpufrequtils: config file for /etc/init.d/cpufrequtils # Options when starting cpufreq (given to the `cpufreq-set` program) START_OPTS="--governor ondemand" # Options when stopping cpufreq (given to the `cpufreq-set` program) STOP_OPTS="--governor performance"
This way I have dynamic CPU frequency scaling before logging into graphical desktop environment. Now I have all tools I need the last thing to do is to setup my multimedia keys.
Multimedia Keys Configuration
Setting up multimedia keys in Linux is much easier today that it was before. Thanks to support build directly into the hal, multimedia keys for most of the notebooks are recognized as normal keys and they can be configured by any key setup utility. Earlier the setup wasn't so hard but it required a little more work to create special acpi events scripts which were performing defined actions when keys were pressed. Unfortunately not all of my notebook keys could be configured the new way. Sadly one of them wasn't recognized and another one was acting not the way I would like it. Thats why my configuration is using both approaches the new one for those buttons that were corectly recognized and old one for 2 buttons that wasn't recognized. Below you will find list of my multimedia keys and the actions I would like them to perform.
List of my keys:- Sleep button - Suspend system to ram - this button was working in KDE without the need of additional configuration.
- Wireless button (2 buttons) - Switch off and on wireless network interface.
- Brightness Up - This button has hardware support. Brightness up function is working even without operating system loaded.
- Brightness Down - This button has hardware support. Brightness down function is working even without operating system loaded.
- LCD button - This button has hardware support toggle between LCD on and off function is working even without operating system loaded.
- LCD - CRT button - Toggle between dual screen setups.
- Mute Sound button - Mute sound mixer - this button was working in KDE without the need of additional configuration.
- Volume Up button - Volume up - this button was working in KDE without the need of additional configuration.
- Volume Down button - Volume down - this button was working in KDE without the need of additional configuration.
- Mail button - lunch Kmail mail client.
- WWW button - lunch Chromium web browser.
- Touchpad button - Switch on and off the touchpad - this button wasn't recognized as normal key.
- Performance button - Toggle between available performance profiles - this button was recognized as screen saver button.
- Play | Pause button - Toggle between play and pause in Amarok player.
- Next track button - Next track in Amarok player.
- Previous track button - Previous track in Amarok player.
- Stop button - Stop playback in Amarok player.
- Lunch media button - Start Amarok media player.
As you can see some of my notebook buttons were working without the need of additional configuration. Default configuration of KDE desktop environment assumes that those buttons will be available in system. For other correctly recognized buttons I used buttons settings utility provided by KDE. For multimedia buttons: Play | Pause, Next track, Previous Track and Stop buttons I used Global keyboard Shortcuts settings for Amarok player. All I need to do was to choose Amarok action matching my key and press my multimedia key to bound it to this function. 30 seconds of work. For Mail, WWW and Media Start buttons I used Keyboard Actions settings utility. I created three new Global Shortcuts for Command/URL actions first one command /usr/bin/chromium bound to WWW button, second /usr/bin/kmail bound to Email key and last one /usr/bin/amarok bound to Media Start button. This way I'm able to lunch my Internet browser, mail client and favorite multimedia player using my notebook buttons. This was the easy part. I must admit I had more problems with setting up wireless and performance buttons. The main problem was that I couldn't find simple system or dbus commands which could help simply achieve task I would like to bound to those buttons. But where is a will there is a way. For wireless button I found a great script created by Poul Sladen for Ubuntu acpi-support package. I used his functions for checking wireless device state and toggling wireless devices on and off. I used this functions a little different that original acpi-support package was making use of it. I created 3 scripts. First one I called wireless-toggle.sh. Below you can see this script.
#Function to toggle wireless interfaces originaly created by Paul Sladen for Ubuntu acpi-support package for DEVICE in /sys/class/net/* ; do if [ -d $DEVICE/wireless ] ; then # $DEVICE is a wireless device. FOUND= # Yes, that's right... the new interface reverses the truth values. ON=1 OFF=0 for CONTROL in $DEVICE/device/rfkill/rfkill*/state; do if [ -w "$CONTROL" ]; then FOUND=1 if [ "$(cat "$CONTROL")" = "$ON" ] ; then # It's powered on. Switch it off. echo -n "$OFF" > "$CONTROL" else # It's powered off. Switch it on. echo -n "$ON" > "$CONTROL" fi fi done # it might be safe to assume that a device only supports one # interface at a time; but just in case, we short-circuit # here to avoid toggling the power twice if [ -n "$FOUND" ]; then continue fi ON=0 OFF=1 # 1 for rf_kill, 2 for power/state for CONTROL in $DEVICE/device/rf_kill $DEVICE/device/power/state ; do if [ -w $CONTROL ] ; then # We have a way of controlling the device, lets try if [ "`cat $CONTROL`" = 0 ] ; then # It's powered on. Switch it off. if echo -n $OFF > $CONTROL ; then break else OFF=2 # for power/state, second time around fi else # It's powered off. Switch it on. if echo -n $ON > $CONTROL ; then break fi fi fi done fi done
This script is using Poul Sladen function for toggling on and off all wireless devices in the system. Important thing is to remember that this script need to be run with higher system privileges. Normal user want be able to use it. A long side with toggling on and off wireless devices the user should be also informed about the current state of wireless devices by system led placed on the front side of the notebook. To do it I created the second script called wireless-led.sh. Below you can see this script.
#/bin/sh echo $1 > /sys/devices/platform/asus_laptop/wlan
As you can see this script is very basic it just passes the first script parameter to system wireless led device. To light on the led I need to run this script like this: ./wireless-led.sh 1. To light off the led I need to run this script like this: ./wireless-led.sh 0. This script also needs a higher system privileges. I saved both scripts in /usr/local/bin catalog. To make both mentioned above scripts available to normal user I used sudo utility. In Gentoo Linux you can install sudo by running following command in terminal.
emerge -av app-admin/sudo
With sudo installed in system all I needed to do is run visudo utility and create belows configuration to let anyone logged on my notebook use wireless scripts with higher privileges without the need of providing password.
ALL notebook = NOPASSWD: /usr/local/bin/wireless-led.sh ALL notebook = NOPASSWD: /usr/local/bin/wireless-toggle.sh
Last thing I did to make my wireless devices manageable by notebook buttons is providing the script which will use mentioned above scripts to toggle wireless state and notebook led. I called this script wireless.sh and saved it in /usr/local/bin catalog. Below you can see wireless.sh script.
#!/bin/sh #Function to check status originaly created by Paul Sladen for Ubuntu acpi-support package isAnyWirelessPoweredOn() { for DEVICE in /sys/class/net/* ; do if [ -d $DEVICE/wireless ]; then # Hurray for stable interfaces... now the rfkill is scarcely # associated with the network device at all (!) for RFKILL in $DEVICE/device/rfkill/rfkill*/state; do if [ -r "$RFKILL" ] && [ "$(cat "$RFKILL")" -eq 1 ] then return 0 fi done # if any of the wireless devices are turned on then return success if [ -r $DEVICE/device/power/state ] && [ "`cat $DEVICE/device/power/state`" -eq 0 ] then return 0 fi if [ -r $DEVICE/device/rf_kill ] && [ "`cat $DEVICE/device/rf_kill`" -eq 0 ] then return 0 fi fi done # otherwise return failure return 1 } if (isAnyWirelessPoweredOn); then kdialog --passivepopup "Wyłączam Interfejsy bezprzewodowe" --title "Wciśnięty przycisk Wifi" else kdialog --passivepopup "Włączam Interfejsy bezprzewodowe" --title "Wciśnięty przycisk Wifi" fi sudo /usr/local/bin/wireless-toggle.sh if (isAnyWirelessPoweredOn); then sudo /usr/local/bin/wireless-led.sh 1 else sudo /usr/local/bin/wireless-led.sh 0 fi
This script is using Poul Sladen function to check wireless device state, then is informing user by KDE popup passive dialog about action that will be taken, then is using sudo to perform wireless device and notebook led toggle. This script is the script I bound with my notebook wireless button by creating new Global Shortcut for Command/URL in Keyboard Actions utility. This way I can switch on and off my wireless devices using one of two available wireless buttons on my notebook.
Fortunately performance button required only one script. As I wrote above I would like this button to toggle between defined in system power profiles. KDE desktop environment has great PowerDevil utility to configure and manage power profiles. I created a script which is using Dbus command provided by PowerDevil to switch profile. Below you can see my performance.sh script.
#!/bin/sh PROFILES="/usr/local/bin/profiles" test -f ${PROFILES} || exit 0 TEMPFILE=/tmp/${USER}-profile.tmp if (test -f ${TEMPFILE}) then read line < ${TEMPFILE} PROFILE=${line} else PROFILE=Dynamic fi i=0 flaga=0 while read line do i=`expr $i + 1` if (test "${line}" = "${PROFILE}") then flaga=$i fi done < ${PROFILES} if (test $flaga -eq $i) then flaga=1 else flaga=`expr $flaga + 1` fi j=0 while read line do j=`expr $j + 1` if (test $flaga -eq $j) then PROFILE=${line} fi done < ${PROFILES} CMD="dbus-send --print-reply --session --dest=org.kde.powerdevil /modules/powerdevil org.kde.PowerDevil.setProfile string:" ${CMD}"${PROFILE}" echo ${PROFILE} > ${TEMPFILE}
This script loops thought profile list defined in additional file, marking currently chosen profile and switching to the next one on the list using PowerDevil Dbus setProfile command. To make use of this script I need to define additional file containing all defined in my system power profiles. Below you can see my profiles list file.
Performance Performance No3D Dynamic Presentation Powersave Aggressive Powersave Xtreme Powersave
I bound performance.sh script with performance button the same way I did this for wireless button by creating new Global Shortcut for Command/URL in Keyboard Actions utility.
There are only two buttons left. But those buttons I configured using older approach. Unfortunately my TouchPad button wasn't recognized the same way the others buttons were. Probably configuration of my quite old notebook isn't fully supported by new hal mappings. That's why I need additional tool created especially for Asus notebooks. This tool is called acpi4asus. To install this tool in Gentoo Linux system I had to run following commands in terminal:
echo "app-laptop/acpi4asus ~x86" > /etc/portage/package.keywords emerge -av app-laptop/acpi4asus
This tool provides small program which helps recognized pressed button as acpi events. Thanks to this I can configure my last two buttons. First I need to make sure that this little program will be started when ever I logged into my KDE desktop environment. To do it I created a small script which will lunch this program and I save this script inside my home in ~/.kde4/Autostart catalog. You can see my asusacpid.sh file below.
#!/bin/sh /usr/bin/asus_acpid
This way every time I will log to my KDE graphical desktop environment this small application will be lunched and ready to support my configuration. The configuration of this tool should go to hidden catalog inside my home called .asus_acpi. The configuration is fairly simple first thing we need to do is to provide a file which will map keycode acpi event with the script performing desired by user action. Below you can see my mapping file for TouchPad button.
# /etc/acpi/events/asus-touchpad # This is called when the user presses the touchpad button and calls # /etc/acpi/asus-touchpad.sh for further processing. event=hotkey (ATKD|HOTK) 0000006a action=~/.asus_acpi/actions/asus-touchpad.sh &
As you can see my key is mapped to acpid event code 0000006a. When ever I press this button asus_acpid helper program should lunch ~/.asus_acpi/actions/asus-touchpad.sh script. The script of course should be responsible for toggling on and off my touchpad. Below you can see my ~/.asus_acpi/actions/asus-touchpad.sh.
#!/bin/bash state=$(synclient -l | grep TouchpadOff | awk -F"= " '{print $2}') if [ "$state" = "0" ]; then kdialog --passivepopup "Wyłączam TouchPad" --title "Wciśnięty przycisk TouchPad" synclient TouchpadOff=1 else kdialog --passivepopup "Włączam TouchPad" --title "Wciśnięty przycisk TouchPad" synclient TouchpadOff=0 fi
As you can see this script is fairly simple. It reads the state of the touchpad and depending on the current state it informs the user using KDE passive popup dialog of action that will be performed and performing switching on and off the touchpad using synclient command. This script should work. However I found out that my synaptics touchpad driver need to be specially configured in Xorg.conf X server configuration file. Without this additional configuration the synclient command line tool wasn't able to access my touchpad. Below you can see part of my Xorg.conf file affecting synaptics driver configuration.
Section "InputDevice" Identifier "Synaptics0" Driver "synaptics" Option "Protocol" "auto" Option "SendCoreEvents" "true" Option "Protocol" "auto" Option "SHMConfig" "on" EndSection
The most important part of this configuration is Option "SHMConfig" "on". This settings make touchpad accessible to synclient settings command. This is all that need to be done to make my touchpad button work.
The last button to configure is LCD - CRT button. I want to use this button to toggle between dual screen configurations. I found out that pressing this button generate 3 different acpi event codes. First time I pressed the button it generates the code 00000061, second time it generates the code 00000062 and the third time i press it it generates the code 00000063. Thanks to this behavior I can easily assign 3 different actions and toggle between them using one key. First thing I need to do is to provide event mappings. First one I called asus-screen1. Below you can see this file.
# ~/.asus_acpi/events/asus-screen1 # This is called when the user is presing screen lcd/crt button, event=hotkey (ATKD|HOTK) 00000061 action=~/.asus_acpi/actions/screen1.sh &
Second one I called asus-screen2. Below you can see this file.
# ~/.asus_acpi/events/asus-screen2 # This is called when the user is presing screen lcd/crt button, event=hotkey (ATKD|HOTK) 00000062 action=~/.asus_acpi/actions/screen2.sh &
Third one I called asus-screen3. Below you can see this file.
# ~/.asus_acpi/events/screen3 # This is called when the user is presing screen lcd/crt button, event=hotkey (ATKD|HOTK) 00000063 action=~/.asus_acpi/actions/screen3.sh &
Every action mapping file is pointing to script created in actions catalog. First one of this scripts is called screen1.sh. Below you can see this file.
#!/bin/sh kdialog --passivepopup "Wyłączam drugi ekran" --title "Wciśnięty przycisk Screen" xrandr --output LVDS --auto --output VGA-0 --off
This script is disabling possibly attached to my notebook second screen and setting the main screen into default resolution using command line xrandr tool. Second one of this scripts is called screen2.sh. Below you can see this file.
#!/bin/sh kdialog --passivepopup "Ustawiam oba ekrany w tryb klonowania" --title "Wciśnięty przycisk Screen" xrandr --output LVDS --mode 1024x768 --output VGA-0 --mode 1024x768 --same-as LVDS
This script is setting both screen resolution to 1024x768 and setting positioning one over another enabling cloning mode. Third one of this scripts is called screen3.sh. Below you can see this file.
#!/bin/sh kdialog --passivepopup "Uaktywniam oba ekrany w trybie domyślnej rozdzielczości " --title "Wciśnięty przycisk Screen" xrandr --output LVDS --auto --output VGA-0 --auto --right-of LVDS
This script is setting both screens into it's default resolutions and placing 2nd screen on the right of the 1st screen. Now I can toggle between screen configurations using only one button. This is highly important for me as I'm very often using my computer to show something to larger audience.
This is it I have all my multimedia keys configured exactly the way I wanted. Thats why I love Gentoo Linux. If I want to achieve something I can do it I'm not bound to any default configuration. At the end I add one more quite obvious thing. All mentioned above scrips has to be made executable before you can use them. To do it you can run following command in terminal:
chmod +x /path-to-script/script-name.sh
Additional Information
To make my configuration complete I must point that I did one more thing. My notebook has a mail notification led. I would like this led to light up when my default mail client downloads new mail from one of my mailboxes. To achieve this goal I created a mailledon.sh script. Below you can see this file.
#!/bin/sh echo 1 > /sys/class/leds/asus\:\:mail/brightness
This script is passing 1 value to mail led device, which should turn on the led. Unfortunately this script has to be lunched using higher system privileges. I additionally had to run visudo utility and add belows line to sudo configuration.
ALL notebook = NOPASSWD: /usr/local/bin/mailledon.sh
This will let any user logged to my notebook use this script without the need of providing the password. I attached this script in Kmail mail client configuration in Detailed mail notification section this way:
sudo /usr/local/bin/mailledon.sh
When I'm receiving new mail the notification led is lighting now.
I copied all my configuration to /etc/skel catalog. To by more specific I copied whole ~/.asus_acpi catalog content a long side with ~/.kde4/Autostart/asusacpid.sh, ~/.kde4/share/config/khotkeysrc, ~/.kde4/share/config/kglobalshortcutsrc, ~/.kde4/share/config/powerdevilprofilesrc and ~/.kde4/share/config/powerdevilprofilesrc. This way when I was creating new user account for my girlfriend she already had all needed multimedia keys configuration in her profile. No need of painful additional configuration for her.
Most of mentioned above scripts are avaiable on my svn server. Below you can find direct links to them.
- wireless-toggle.sh
- wireless-led.sh
- wireless.sh
- performance.sh
- screen1.sh
- screen2.sh
- screen3.sh
- mailledon.sh
Prove that it's working
Sources
- Gentoo Linux Power Management Guide
- Gentoo Wiki TuxOnIce HowTo
- TuxOnIce Project Page
- Gentoo Wiki Archive PM-Utils HowTo
- man hibernate.conf
- man asus_acpid
If you have found something wrong with the information provided above or maybe you just want to speak your mind about it, feel free to leave a comment.
All comments will show up on page after being approved. Sorry for such policy but I want to make sure that my site will be free of abusive or vulgar content. I don't mind being criticized just do it using right words.
Processing a comment.