显示标签为“Linux”的博文。显示所有博文
显示标签为“Linux”的博文。显示所有博文

2007年8月23日星期四

2007 Desktop Linux Survey results revealed(Zz)

先转一个中文的点评吧,英文原文附在后面

发信人: RealShrek (燃烧吧,小宇宙!), 信区: LinuxApp
标 题: 2007 年桌面 Linux 的一份统计zz
发信站: 水木社区 (Fri Aug 24 00:31:19 2007), 站内

著名的 DesktopLinux 今天发布了 2007 年桌面 Linux 的一份统计。如果想了解统计的具体内容和相关数据,还是请您看看原文,这里不再重复了。这份统计很有意思,很多数据也很有代表性,我就这份数据随便扯淡一下。

07 年最受欢迎的 Linux 发行版:SuSE

“有没有搞错,是 Ubuntu 吧!”看完上面那个标题,你一定会有这样的疑问。显然,单单从统计结果上来看,Ubuntu 确实以 30% 的使用率独占鳌头,但以 21% 使用率紧随其后的 SuSE 很有看头。06 年时,SuSE 使用率仅仅占 Linux 各发行版中 13%,而短短一年则有 8 个百分点的提升,这确实是很惊人的。而 Ubuntu 相对去年同期增长不过1%,从发展势头上看 SuSE 确实是后劲十足。因此,我说他是今年最受欢迎的发行版一点也不过分。

这个结果一定程度上也说明了一个问题:对于一款桌面系统,方便好用是根本,但漂亮也是不可或缺的。Ubuntu 和 SuSE 从易用性上在 Linux 发行版中都是佼佼者,但 SuSE 就是赢在了漂亮上。我身边很多人装过 openSuSE 后就再也看不上其它 Linux 发行版了。所以 Ubuntu 在 7.10 中迫不及待的加入 Compiz Fusion,也显示出 Eye Candy 对于个人用户还是非常必要的。

此外,Fedora 只占 9% 确实有点出乎我的意料,看来昔日 Linux 霸主 RedHat 彻底转战企业领域了。

桌面环境:GNOME KDE 平分秋色

作为 Linux 上最出色的两个窗口环境,GNOME 和 KDE 依然霸占着 Linux 用户的桌面。丰富的软件,以及大多发行版的预设是造成这一结果的原因。不过貌似很多高手都很喜欢秀 Xfce,不过我是懒得折腾那个东西,老老实实用 GNOME 吧。也许“怕麻烦”代表了不少桌面系统使用者的心态,所以就不难理解 Mac OS X 为什么那么火了。

浏览器:Firefox 的天下

对于 Firefox,Linux 绝对是一块儿沃土。这个后起之秀如今已经占据 60% 的 Linux市场,而另一款非常优秀的浏览器 Konqueror 虽排第二位,却落后他近 40 个百分点。但如今 Mozilla 基金会发展的重点似乎是 Windows 平台,我倒是觉得 Firefox 应该利用这个优势,为开源桌面环境的普及出点力。

作为 Web 开发者,估计恨不得全世界人都用 Linux,这样就再也不用做很多无用功去CrossBrowser 了。全都用 Firefox,世界太平了。

Email 客户端:Web Mail 时代到来

各项评比中,差距最不明显的就是这一项了。尽管 ThunderBird 相比第二名的 Evolution 要强大很多,但使用者却多不了多少。而 Evolution 看似领先 Kmail 不少,但那是因为 GNOME 领先 KDE 造成的差距。用哪个桌面环境自然用它配套的客户端了,要不然还要为满足依赖关系装好几百兆的包。

造成这种平均化的原因,我认为是如今大量的用户开始转向 WebMail 平台,而放弃了传统的客户端。Gmail 的推出彻底颠覆了 WebMail 的概念:超大的容量让你无须删除邮件;丰富的功能让你快捷的完成一切需要的操作。随着三大邮箱的跟进,如今 WebMail 已经具备了传统 Email 客户端软件的一切优点,取代它们只是时间的问题了。

Windows 模拟:速度第一

Linux 再好,应用还是不如 Windows 软件质量高(主要是一些商业软件)。因此 Linuxer 们还是常常要运行一下 Windows 程序救急。统计结果表明,更多的使用者还是倾向于用 Wine 这样的 API 转换平台,而不是虚拟平台。

其实 Wine 相对 VMWare 这样的虚拟平台,易用性兼容性等方面都差很多。但速度却非常的快。只要是 Wine 可以顺利跑起来的程序,速度和在 Windows 上跑没什么差别。在这个效率至上的时代,速度见长的 Wine 占了优势。

当然,随着虚拟化技术的不断发展以及硬件上(特别是 CPU)对虚拟化技术的支持,虚拟系统和本地系统的速度差距将会越来越小。到时候我估计 Wine 就不会如此风光了。


原文作者对 VirtualBox 的异军突起感到惊讶,因为它似乎还不如 Qemu/XEN 这样的虚拟环境有名。但需要注意的是,VirtualBox 是 Ubuntu 默认的虚拟机程序,这就是捆绑的力量。

其实现在的 Linux 系统确实非常好用了。要不是因为我实在受不了没有 Photoshop 造成的不便,我想我每天用 Ubuntu 的时间会比现在更长(现在写 Blog 还是会切回 Vista)。过于强调开源导致优秀商业程序的缺失已经严重制约 Linux 成为流行的桌面系统。当然,Windows 发展至今天这个程度,是十几年经验累积的结果。Linux 要想成为一个流行的 Desktop OS,还有很长的路要走。

英文原始统计统计资料:
http://www.desktoplinux.com/news/NS8454912761.html

2007 Desktop Linux Survey results revealed Aug. 22, 2007

Analysis -- According to DesktopLinux.com's just completed survey, the number of Desktop Linux users has more than doubled in the past year, and Ubuntu remains their Linux distribution of choice.

Spread the word:
digg this story

Since DesktopLinux.com's recently completed survey is a self-selected group, we can't claim scientific proof that the number of desktop Linux users has more than doubled in the past year. Still, this year's survey produced 38,500 votes versus 14,535 votes over the same number of days in a similar survey one year ago.

Part of the increase undoubtedly was because this year's survey received front page coverage on both Digg and the German news site, Heise Online. That said, we've also seen an increased interest in Desktop Linux, based on our own website statistics. We've seen significant increases during the last year both in terms of unique visitors and site page hits.

You don't need to believe our numbers or surveys, though. Dell and Lenovo didn't invest in pre-loading Linux desktops to win points with the cool Linux kids. Both companies did it because they want to make money with the Linux desktop. Dell, in fact, has expanded its Ubuntu Linux offerings both in the U.S. with its 1420 laptop line, in Europe, and in the Chinese office desktop market. Today, Linux desktops are a business, not just a hobby.

So, what are desktop Linux users of 2007 using?

Desktop distributions

The leading Linux distribution is the Ubuntu family -- 30 percent of our survey respondents are using Ubuntu or one of its sister distributions: Kubuntu, Xubuntu, and Edubuntu. While there are other distributions that owe a great deal to Ubuntu -- Linspire, Freespire, MEPIS, Linux Mint, and Pioneer all come quickly to mind -- we decided not to count them for Ubuntu this year, since some, like Freespire, have just made the switch, while others, such as MEPIS, are switching back to Debian, and Pioneer is going in its own direction.


Which Linux distros do you use on your home or office desktop system(s)?
(Click to enlarge)

Next in popularity, after the ever-popular Ubuntu family, comes the SUSE Linux family with 21 percent. In our survey, we found mostly openSUSE users (19.7 percent) with a scattering of SLED (SUSE Linux Enterprise Desktop) users (1.3 percent). This isn't too surprising, since our preliminary analysis of our survey data showed that the majority of our respondents were individual rather than corporate users.

It's also noteworthy that the SUSE Linuxes have taken a major step forward. In 2006's survey, the SUSE family came in a distant second place with only 13 percent of the user base. In terms of year-over-year growth, openSUSE and SLED were the real winners, in fact, with a jump of 8 percentage points. The Ubuntu family, by comparison, built on its lead by only 1.2 percent.

In third place this year we have "other Debian," which includes Debian and all of its relatives besides Ubuntu: Debian, Freespire, Linspire, Linux Mint, MEPIS, and Xandros. While this group, at 14.2 percent, may have dropped behind SUSE this year, if you add in Ubuntu -- the most popular Debian-based distribution of them all -- Debian once again dominates the desktop Linux landscape, accounting for near half -- 44.6 percent -- of this year's distribution votes.

The Red Hat/Fedora family -- which this year includes CentOS -- came in at the fourth spot with 9 percent. This represents a small loss from last year when Fedora had 7 percent, while Red Hat added in a mere 2.2 percent, for a total, including smaller Red Hat/Fedora-based distributions of less than 10 percent.

Finally, in our "top five," we have Gentoo, which also declined -- from 9.6 percent to 7 percent. After that we come to a group of smaller, independent distributions. Of these also-ran distributions Mandriva showed the best.

Perhaps the most surprising result of our survey was that PCLinuxOS showed so poorly. On DistroWatch, PCLinuxOS has been at the top of the site's page hit ranking for the last 30 days. Frankly, we're not sure why this popular, easy-to-use community distribution didn't do better. The site supporting it had recently had problems, but that problem's long been history. Perhaps, it's simply that unlike the other popular community distributions -- Ubuntu, openSUSE, and Fedora -- PCLinuxOS doesn't have corporate backing. Canonical, Novell, and Red Hat all provide support and hardware partnerships for their community distributions that PCLinuxOS can't match.

Desktop environments

The desktop environment results held little in the way of surprises. GNOME, in large part because it's Ubuntu's default desktop, came in first with 45 percent of the users. KDE took second place with 35 percent. Interestingly, this is the first time in DesktopLinux.com's surveys that GNOME has out-polled KDE. Signs of a looming upset in standings were apparent last year, when KDE scored 38 percent and GNOME was right behind it at 35 percent.

The only "shocker" this year was that Xfce took third with a substantial 8 percent of the vote. In fact, 20 percent of our survey's respondents indicated that they use desktop environments other than the big two. Given this, and the loss of KDE's desktop dominance, it strikes us that there's still a chance for some other Linux desktop environment to make a go of it.


Which windowing environments do you frequently use on your Linux desktop(s)?
(Click to enlarge)

Browsers

You can probably guess without even looking at our graph of the survey's results what the most popular Linux web browser is. If you guessed Firefox (aka IceWeasel), you'd be right.


Which web browsers do you frequently use on your Linux desktop(s)?
(Click to enlarge)

Linux users love their Firefox, with 60 percent of all users making it their web browser of choice. Trailing in the rear, you'll find KDE's Konqueror, with 14 percent, followed by what I find an interestingly strong performance by Opera, with 12 percent, and then the rest of the crew.

Email clients

Thunderbird, Firefox's email sibling, is the most popular Linux email client, but it's not nearly as popular as Firefox. Thunderbird commands the loyalty of 37 percent of Linux users, but Evolution is right behind it at 32 percent. KMail takes third place with 17 percent. We also found that many Linux users -- over 10 percent -- have abandoned email clients for web-based email systems like Google's Gmail or Yahoo Mail.


Which email clients do you frequently use on your Linux desktop(s)?
(Click to enlarge)

Running Windows applications on Linux

When it comes to running Windows applications on Linux, nearly half of our survey's respondents -- 39 percent -- say they simply don't bother.


Which of these methods do you use to run Windows apps on your Linux desktop(s)?
(Click to enlarge)

Of those that do, many turn to Wine (Wine Is Not an Emulator ), which runs the Windows API (application program interface) on top of Linux. More than 44 percent use Wine for their Windows applications needs.

I suspect that many Wine users actually use Wine with the help of programs that makes deploying Windows applications on Linux easier. However, of the two most important of these programs, Cedega, which specializes in running Windows games on Linux, and CrossOver, which focuses on Windows business and productivity applications, only 6 percent of our survey respondents said they used Cedega, while even less, 5 percent, said they used CrossOver.

What they did use, however, was VMware, the well-known proprietary virtualization program, which was selected by 27 percent of all users. In third place was something of a shocker: VirtualBox, with 8 percent. Why a shocker? Well, here at DesktopLinux.com, we like to think we've at least heard of all the popular Linux virtualization programs -- Xen, KVM, etc. -- but we've never heard of this one. Needless to say, we're going to be taking a closer look at VirtualBox soon.

Based on our survey results, we think that everyone should be taking a closer look at desktop Linux. What we see here is a quickly maturing line of desktops that are capable of replacing Windows desktops for both home and business uses.

The Linux desktop is gaining quickly in popularity, and it's not because of technology-happy fans. It's gaining users because it's an inexpensive, secure, and efficient alternative to today's mainstream desktop operating systems. After all, 38,000 plus users and two major PC companies can't be wrong.

For the full results of our survey, see the raw data on the DesktopLinux.com survey site.


--Steven J. Vaughan-Nichols

2007年8月22日星期三

Shake some sense into your Linux ThinkPad


Thinkpad还是一如既往的疯狂

最近在折腾硬盘保护的事情,说实话,弄了好久,还没搞定

不过意外中看到一个非常有趣的东西

转载自:http://www.ibm.com/developerworks/library/os-linuxthinkpad/index.html

Shake some sense into your Linux ThinkPad

Use open source software and accelerometer-enabled ThinkPads to listen for percussive impacts and shaking to kick-off user commands or a reset

developerWorks


Level: Intermediate

Nathan Harrington (harrington.nathan@gmail.com), Programmer, IBM

07 Nov 2006

Place your computer on the leading edge of cathartic interfaces by modifying the kernel to reset your Linux® laptop automatically when shaken during a kernel panic. Implement a shake-detection algorithm in the kernel and user space to perform automatic shutdowns and restarts when certain kinetic conditions are met.

In 2003, IBM® started selling ThinkPad laptop computers with integrated accelerometers and associated software for a commercial operating systems to protect the hard disks when the ThinkPad is dropped. Enterprising hackers from IBM and elsewhere have worked to develop modules for the Linux kernel to take advantage of these sensors. On-screen display orientation, desktop switching, even game control and real-time 3-D models of the tilt of the laptop are now available.

In mid-2006, knock-based commands for Linux laptops became available with user-space Perl scripts (as opposed to C-based code buried in kernel space), allowing users to run arbitrary commands based on specific knock sequences. This article describes the process of modifying the Linux kernel to add an oft-demanded feature: feedback on physical input. When the Linux kernel panics, the user can shake the computer (or perform any number of other developer-configurable physical movements of the laptop), and the machine will reset.

Also covered are methods for performing a normal shutdown in nonpanic mode. For example, if the user inadvertently places the computer in a laptop bag still turned on, we want the computer to detect a normal walking or driving motion and turn the computer off.

Requirements

Hardware

Many IBM ThinkPads manufactured in 2003 and later sport hdaps hardware. If you are unsure of your hardware configuration, check out the technical details on Lenovo's Web site. You need a ThinkPad for this code to function. Some MacBooks have the accelerometers and the same general methods available to access them through the kernel. However, the code here was not tested on Apple hardware and was developed and tested on two IBM ThinkPad T42p models. See Resources for links on how to find ThinkPad hardware that will support your desire to get physical with your laptop.

Software

This article assumes familiarity with the kernel build process, as well as experience with the inconsistencies among distributions when it comes to kernel compilation. For an introduction to the kernel build process, as well as some great examples on how to get started, see Resources.

As of kernel V2.6.15, the hdaps driver is included in the Linux kernel. Grab the latest kernel for the sake of simplicity. For ease of development and administration, this article was developed on Fedora Core V5. The following instructions used to set up the kernel build environment are specific to Fedora Core, but the general principles are applicable to any Linux distribution.





Kernel development setup

Kernel configuration, compilation, and testing

To modify the kernel, follow the instructions from the excellent release notes. Open a Web browser and start following the instructions in section 8.6: "Preparing for Kernel Development." When you get to section 2, you may have a problem with the second command: su -c 'yumdownloader --source kernel'. If the command does not pull down the kernel-2.6.15-1.2054_FC5.src.rpm package for you, use wget to get it with the command: wget ftp://ftp.linux.ncsu.edu/pub/fedora/linux/core/5/source/SRPMS/kernel-2.6.15-1.2054_FC5.src.rpm.

When you get to step 5, select the basic i686 default config with the command: cp configs/kernel-2.6.15-i686.config .config. Make sure to change the EXTRAVERSION section in the makefile from -prep to -1.2054_FC5. Update the build configuration with make oldconfig. Install the kernel development modules, as well with the command su -c "yum install kernel-devel". This will be used for compilation of our panic instigation module.

We have now completed the relevant portions of the kernel configuration from the Fedora Core V5 Release Notes document. The remaining steps are standard to any kernel build process. I recommend building and installing your new kernel, modules, and RAM disk setup now to make sure things are working as expected. You can skip the following steps and head right to the kernel modification section if you are confident about your new kernel configuration.

Build your new kernel with the make command. When the kernel is built successfully, copy it to the /boot directory with the command su -c "cp ./arch/i386/boot/bzImage /boot/vmlinuz-2.6.15hdaps". You'll need to build your modules with the command su -c "make modules_install". The final build step is to create a RAM disk for the hdaps kernel with the command su -c "/sbin/mkinitrd hdapsInitrd.img 2.6.15-1.2054_FC5". Copy this new RAM disk to the boot area with the command su -c "cp hdapsInitrd.img /boot/". As root, update the grub.conf file with the following lines:


Listing 1. grub configuration
title Fedora Core (2.6.15hdaps)
root (hd0,0)
kernel /vmlinuz-2.6.15hdaps ro root=/dev/VolGroup00/LogVol00 rhgb quiet
initrd /hdapsInitrd.img

Modification of panic.c and hdaps.c

Now you are ready to start some shake-and-bake kernel hacking. Make sure you are in the ~/rpmbuild/BUILD/kernel-2.6.15/linux-2.6.15.i686 directory. The first priority is to include the hdaps module as a built-in component of the kernel, so it will be ready to provide for shake detection anywhere in the machine's run modes.

Use the command make menuconfig and select Device Drivers > Hardware Monitoring Support. Type a Y to include the Hardware Monitoring Support module since the hdaps module is dependent on it. Scroll to the bottom of the list and place another Y next to the IBM Hard Drive Active Protection System (hdaps) entry. Back out of the menus and save your configuration.

Open the file drivers/hwmon/hdaps.c and add the following text to the includes section: #include . Also add the new subroutine below directly after the hdaps_read_pair subroutine:


Listing 2. Full panicShake subroutine from hdaps.c
/*
* panicShake - reboot the machine if shaken
*/
extern void panicShake(void)
{
int ret, x, y; // return value and x,y from hdaps
int int baseX = -5000; // off scale default values
int baseY = -5000;
int totalDev = 0; // running total of deviations from rest (shaking total)
int devThreshold = 4000; // larger threshold for more shaking
int dimShiftX = 150; // in case your users shake more in a certain dimension
int dimShiftY = 150;

while(1)
{
ret = hdaps_read_pair(HDAPS_PORT_XPOS, HDAPS_PORT_YPOS, &x, &y);
if (!ret)
{
if( x != 0 && y != 0 )
{
// if its a successful read and not a zero read
if( baseX == -5000 )
{
baseX = x;
baseY = y;
}
if( abs(baseX - x) > dimShiftX || abs(baseY - y) > dimShiftY )
{
totalDev += abs(baseX - x);
totalDev += abs(baseY - y);
}
if( totalDev > devThreshold )
{
printk(KERN_EMERG "ok, ok! you're shaking my substrate - restarting");
emergency_restart();
}
}//if not a zero value
}//if successful read of hdaps data

}//infinite while

}//panicShake

With our shake-detection routine in place, we need to call it upon system panic. Open the kernel/panic.c file and place a call to the panicShake(); subroutine directly before the panicBlink conditional section. Issue a make command. Let's review the shake-detection code while your kernel is being rebuilt. First, we set up some variables:


Listing 3. panicShake variables
int ret, x, y; // return value and x,y from hdaps
int baseX = -5000; // off scale default values
int baseY = -5000;
int totalDev = 0; // running total of deviations from rest (shaking total)
int devThreshold = 4000; // larger threshold for more shaking
int dimShiftX = 150; // in case your users shake more in a certain dimension
int dimShiftY = 150;

Of particular note is the deviation threshold parameter and the dimensional shift parameters. These may require tuning based on the unique characteristics of the motion you are trying to detect. For example, if you feel the urge to shake your computer like you were performing a basketball pass, try decreasing the dimShiftX parameter to more easily detect motions perpendicular to the screen of the computer. Conversely, if your shaking impulse instigates motions of a sawing-timber nature, consider decreasing the dimShiftY parameter to quickly pick up on shaking moments of frustration parallel to the screen and reset your computer before further damage can occur.

The selections of 150 for dimensional parameters and 4000 for the total deviation are designed to acquire the typical shaking motions of an average user. For immediate response to inputs, try decreasing the dimensional shift parameters to 10 or less and a total deviation parameter of 10 or less. These values will cause other types of inputs to be immediately recognized, such as bashing the keyboard in frustration or smacking the display case in abject disgust.

Next, we consider the infinite loop statement and conditionals.


Listing 4. panicShake hdaps read and base setup
while(1)
{
ret = hdaps_read_pair(HDAPS_PORT_XPOS, HDAPS_PORT_YPOS, &x, &y);
if (!ret)
{
if( x != 0 && y != 0 )
{
// if its a successful read and not a zero read
if( baseX == -5000 )
{
baseX = x;
baseY = y;
}

The code works as follows: For the rest of time, read the current accelerometer readings from the hdaps sensor. Frequently, the read will be unsuccessful or both values will be equal to 0,0, which is unusable data. We need to avoid these spurious 0,0 readings, as about one out of every 10 readings at any orientation of the sensor will be 0,0 -- invalid data, indeed. If it's our first "successful" read, set the base parameters equal to the first x and y values. This will allow us to more robustly detect shaking or other movements if the panic occurred while the machine was on a nonflat surface, such as a person's knees.

The remainder of the subroutine is the implementation of the simple shake-detection algorithm.


Listing 5. panicShake shake detection
if( abs(baseX - x) > dimShiftX || abs(baseY - y) > dimShiftY )
{
totalDev += abs(baseX - x);
totalDev += abs(baseY - y);
baseX = x;
baseY = y;
}
if( totalDev > devThreshold )
{
printk(KERN_EMERG "ok, ok! you're shaking my substrate - restarting");
emergency_restart();
}
}//if not a zero value
}//if successful read of hdaps data

}//infinite while

If the dimensional shift in either direction is greater than our previously set threshold, increment the total deviation by the amount moved in both directions. Then set the current base to the existing level of acceleration. This repeated reinitialization of the base values will require the user to continuously exceed the dimensional shift values to increment the total deviation detected. This is useful for allowing the user to move and store the ThinkPad in panic mode as they track down the systems administrator. Remove the reinitialization assignments if you want simply setting the ThinkPad on its side or tilting it and holding it there to trigger a restart.





Testing your panicShake() kernel

To initiate a panic, we need to call the panic subroutine in the kernel. Create the following makefile: obj-m := panicCall.o, which will be used by the program panicCall.c on compilation:


Listing 6. panicCall.c kernel module source
/*
* panicCall.c - Instigate a kernel panic
*/
#include /* Needed by all modules */
#lincude /* Needed for KERN_INFO */

static char *pMesgStr = "PANIC SHAKE AND BAKE";

int init_module(void)
{
printk(KERN_INFO,"panicCall module loaded\n");
panic(pMesgStr);
return(0);
}

void cleanup_module(void)
{
printk(KERN_INFO,"panicCall module unloaded, beyond possible");
}

As root, compile the panicCall module with the command make -C /lib/modules/$(uname -r)/build SUBDIRS=$PWD modules. You now have a module you can call to trigger a panic with the command insmod panicCall.ko. Reboot if you haven't already (to activate your hdaps panic shake-enabled kernel) and run insmod panicCall.ko. You should see something similar to the following:


Listing 7. kernel panic stack strace
panicCall: module license 'unspecified' taints kernel.
Kernel panic - not syncing: PANIC SHAKE AND BAKE ACTIVE
[] panic+0x3e/0x174 [] init_module+0xb/0xc [panicCall]
[] sys_init_module+0x1382/0x1514 [] do_sync_read+0xb8/0xf3
[] autoremove_wake_function+0x0/0x2d []
_atomic_dec_and_lock+0x22/0x2c
[] mntput_no_expire+0x11/0x6d [] syscall_call+0x7/0xb

Now pick up your computer and give it a good shake, and it will print out the "shaking substrate" message and perform a restart. If you're the sort who would rather not shake a potentially active disk drive, issue the following commands as root:


Listing 8. RAM disk creation, module copying
mkdir /tmp/ramdisk0
mke2fs /dev/ram0
mount /dev/ram0 /tmp/ramdisk0/
cp /root/panicCall.ko /tmp/ramdisk0/
cp /sbin/insmod /tmp/ramdisk0/

You now have the two files you need to insert a module into the kernel located on a RAM disk. Update the /etc/init.d/halt script with the following section, directly below the fsck check section and directly above the halt execute section:


Listing 9. modification of /etc/init.d/halt
echo "disks now mounted in readonly mode, spin down in 5 seconds";
/sbin/hdparm -S 1 /dev/hda
echo "spin down hda called, waiting 10 seconds";
sleep 10
echo "calling panic from ramdisk location";
/tmp/ramdisk0/insmod /tmp/ramdisk0/panicCall.ko

Execute the command init 0 as root to send the machine into shutdown mode. Prior to the call for power off, the machine will load the panic instigator module into the kernel, and the shake detection routine will be called. If you listen to the hard disk as the system is shutting down, you can hear the distinct meatier-than-usual click, followed by the Doppler disk decrease as the arm is placed in the rest "stowage" position and the platters spun down. After about five more seconds, the panic module will be executed from RAM disk while the physical disk heads are still parked. Now you can shake your ThinkPad to your heart's content without concern for your disk's health.





User space shutdown and motion detection

Many an IT administrator has yearned for the ability to know the physical history of hardware. With the same simple shake-detection algorithm above, a Perl script, and a monitoring policy, administrators will be better able to track the status of their hardware. For example, we will use the Perl script below to shut down the machine gracefully when shaken by the user. Modifications can be made easily to send an e-mail, flash the "ThinkLight," or play a sound file based on the user's manipulation of the ThinkPad.


Listing 10. Perl script for shake detection, Part 1
#!/usr/bin/perl -w
# shakeShutdown.pl - shutdown (or other command) when the computer is shaken
use strict;
my $file = "/sys/devices/platform/hdaps/position";
my $baseX = -5000;
my $baseY = -5000;
my $totalDev = 0;
if( @ARGV != 1 ){ die "specify a threshold value" }
my $devThreshold = $ARGV[0];
my $dimShiftX = 150;
my $dimShiftY = 150;
while(1)
{
open(HD,"$file") or die "can't open file";
my $line = ;
chomp($line);
$line =~ s/\(//g;
$line =~ s/\)//g;
$line =~ s/\,/ /g;
my( $x, $y ) = split " ", $line;

As you can see, the initial program setup is nearly identical to the hdaps kernel code. The regular expressions and split commands simply change the x and y values from (5,4) to 5 and 4. The remainder of the program is also virtually identical:


Listing 11. Perl script for shake detection, Part 2
if( $x != 0 >> $y != 0 )
{
if( $baseX == -5000 )
{
$baseX = $x;
$baseY = $y;
}
if( abs($baseX - $x) > $dimShiftX || abs($baseY - $y) > $dimShiftY )
{
$totalDev += abs($baseX -$x);
$totalDev += abs($baseY -$y);
$baseX = $x;
$baseY = $y;
}
if( $totalDev > $devThreshold )
{
print "threshold passed $totalDev\n";
my $res=`/sbin/shutdown -h 1`;
}
}
close(HD);
}

Note the shutdown -h 1 command. This will give the user 60 seconds to change his ways and issue a shutdown abort. Change this command to run your favorite mailer, and you can let your systems administrator know when a user is abusing equipment. Log messages to the system log or sound the PC speaker for instant user feedback about getting physical. Run the script with the command perl shakeShutdown.lp 1000. The much-smaller deviation threshold is due to the decreased number of reads-per-time interval of the accelerometer compared with the number of reads-per-time interval in kernel space.

Modifying the dimensional shift parameters and the deviation threshold can provide for additional useful monitoring of physical activities outside kernel space. For example, to acquire a "walking" behavior, set the dimensional shift parameters to around 20 and set the deviation threshold to around 5000. This will pick up about 63 dual-axis dimensional shifts, consistent with the laptop being running while in an over-the-shoulder typical laptop bag. After this long walk is detected (as opposed to a short walk between cube and conference), the machine will enter shutdown to prevent overheating while the airflow is confined in the carrying case. Modify the dimensional shift parameters to be highly sensitive, and every significant bump, drop, or shake can be recorded.





Conclusion

With these simple algorithms for user space and kernel-level code, you now have the ability to detect, log, and respond to the full range of physical input from the user. With these code examples, you can do everything from modifying hard-drive performance parameters based on computed altitude from continuous acceleration to tracking the number of steps from your cubicle to the conference room and mail it to your space planner.



Resources

Learn

Get products and technologies
  • The Fedora Core V5 distribution includes hdaps in the kernel.

  • Innovate your next open source development project with IBM trial software, available for download or on DVD.


Discuss


About the author


Nathan Harrington is a programmer at IBM currently working with Linux and resource-locating technologies.


2007年8月20日星期一

将YY进行到底



太yy了~~~

wine下面的mplayer居然还是这么彪悍,

刚刚把wine下面的声卡调出来,想找个程序试验一下,kmp很痛快的就怪了,pplive挣扎了一下,也挂了。

改用什么程序来测试声卡呢?想来想去还是mplayer最可靠,一打开~~~真叫一个yy,几乎感觉不到是用虚拟机运行的,特别是mplayer本来就喜欢托着一个嘿嘿的命令窗口,所以那个恶心的wine窗口也不让人觉得特别突兀。至于效果,没话说~~~mplayer这个东西太bt了,一般的视频完全不在话下,只是播hdtv比较卡----这也是没办法的事情。

更nb的是,在播放的同时compiz的效果还能继续工作。下面的一副截图是windows expo + 反色 效果.哈哈,太yy了,越来越喜欢ubuntu了,快一个星期没开过windows了,唯一麻烦一点的事情是我用来打网上电话的软件,貌似没有linux的版本(开始后悔当时买的不是skype的卡了,哈哈)。接着折腾,一定要把那个网络电话的软件也在wine里面搞出来

Ubuntu上的软件列表

持续添加中,为了预防某天系统突然崩溃,先记下来

MLDonkey,以及他的firefox addon: MLDonkey Protocol handler
Mplayer,当然还有codec包
Qterm,然后给~/.qterm/里面方一个ip库
Compiz那堆东西
Pidgin
Gmail notifier
Ntfs-config
SCIM-qtim
wine
Firefox的那几个插件(这个东西是系统无关的,爽)。Adblock,Flashplayer+block(呵呵,有时player又是block),Tab mix plus


貌似就这么多东西了,折腾了这么久,呵呵

另外是MacOS和MS的字体

2007年8月18日星期六

用Xmodmap作键盘映射

因为笔记本没有windows键,所以需要另外弄一个键来代理ubuntu里面的Super键(其实主要是fusion需要用,哈哈)

Thinkwiki上面提供的方法是用Caps_Lock来作
http://www.thinkwiki.org/wiki/Installing_Ubuntu_7.04_on_a_ThinkPad_T43#Overview
这个显然不是一个明智的决定,不能切换大小写多不方便

但是这个文章是instructive的,里面提到的Xmodmap是个好东西(是不是跟我id有点神似,嘿嘿)
查了一些介绍这个软件的文章
http://www.cbi.pku.edu.cn/chinese/documents/csdoc/cman/xmodmap.html

指定的思路是用Alt_Right来当Super用,反正在windows里面也是牺牲它,嘿嘿,都被搞惯了,我又何必客气

开始实验的xmodmap配置文件如下:
remove mod1 = Alt_R
add mod4 = Alt_R

麻烦的事情是,貌似Alt_L和Alt_R是一对,只要把Alt_R挪作他用,Alt_L也就跟着罢工了,也就是说Ctrl Tab就不干活了,这个是绝对不能容忍的事情。于是又是了一下这一段

clear mod1
add mod4 = Alt_R
add mod1 = Alt_L

还是同样的问题,有点无语,理论上应该不会是逻辑问题,只好开始逐步调试

试验把Alt改成Control--相应的要把Mod1也改成Control,很意外,是work的。也就是说,至少整个代码的语法是没有问题的....剩下的,不知道应该算是bug还是什么。

恩,原则上其实Contrlol_R这个键也是永远不会用到的,跟Alt_R倒是没多少区别。不过...总是有点不甘心,准备再多试试。

尝试在上面代码的基础上做修改,思路是用keycode把Control_R和Alt_R对换,代码大致是(我这里113,109分别是Alt和Control的键值)
remove mod1 = Alt_R
remove Control = Control_R

keycode 113 = Control_R
keycode 109 = Alt_R

add mod4 = Control_R
add Control = Alt_R
很不幸的,以上配置依然是错的...

不 过好在这次是直接在xmodmap下面一句一句执行的,发现错误居然是处在最后一句上...有点无语--此时的Alt_R实际上已经关联到键盘的Ctrl 键了,居然会因为修改他和使得左侧的Alt罢工...而反对是Alt键,给它换了一个名字以后,对他作修改就不会连作到左侧的兄弟了。

问题已经很清楚了,最后的代码只有3行
! use Right Alt as Super
remove mod1 = Alt_R
keycode 113 = Super_L
add mod4 = Super_L

如果希望用键盘上的back/forward键,加上下面的两行
! back and forward browser keys
keycode 234 = F19
keycode 233 = F20
以上东西放到~/.Xmodmap文件中即可

嘿嘿,生命在于折腾

2007年8月17日星期五

Ubuntu下第一贴


什么都要自己设置,好怀念的感觉。想起当年在dos下面死磕config.sys和autoexec.bat的日子了。这年头在windows下人越来越越懒,可是不行