linux

Some info about Linux console

Most people never need to worry about the Linux keyboard and console HOWTO. Although it's written in 2002, I still find it worth reading, and below is a summary.

The kbd package contains important programs to tweak console settings. It also contains data such as keymaps and fonts. Debian family likes to split packages so the data resides in another package known as console-data. There's also a kbd clone, namely console-tools.

When a key is pressed, the keyboard controller sends scancode to the kernel keyboard driver. Unless in scancode mode, the driver parses scancodes into keycodes. Unless in keycode mode, the keycodes are looked up in the keymap (which can be changed with loadkeys or xmodmap), and the characters found there are transmitted to the application. The program showkey can examine scancodes and keycodes. Under X, use xev.

Fonts are loaded into the video card's character ROM, and can be changed using setfont.

Why is it that you sometimes get a lot of line-drawing characters, e.g., after catting a binary to the screen? Well, there are various character set changing escape sequences, and by accident your binary might contain some of these.

Bash, Emacs and X all do their own tty input handling.

By default, to get a screen to scroll, Linux leaves the text in video memory as it is, but change the viewing origin. The kernel console driver will write text starting at the top of the video memory, continuing to the bottom, then copy the bottom part to the top again, and continue. You can scroll back until the top of the video memory by using Shift-PageUp and scroll down again using Shift-PageDown, assuming a default keymap. The amount of scrollback is thus limited to the amount of video memory you happen to have and you cannot increase this amount. Upon changing virtual consoles, the screen content of the old VT is copied to kernel memory, and the screen content of the new VT is copied from kernel memory to video memory. Only the visible screen is copied, not all of video memory, so switching consoles means losing the scrollback information.

Gentoo Linux on Dell Inspiron 700m

Useful tools

gentoolkit

portage-utils

sunrise

Description of use flags

/usr/portage/profiles/use.desc
/usr/portage/profiles/use.local.desc

Autostart programs

Edit /etc/conf.d/local or /etc/conf.d/local.start.

Auto login

For agetty, use "-l" to change the login program, and "-n" to avoid prompting for username.
For the custom login program, use "exec login -f username"

Wireless network

In the kernel, enable ipw2200 support. Then emerge ipw2200-firmware. You should NOT build ipw2200 into the kernel. Because it looks for the firmware on the file system, which is not ready yet. See the documentation when you config the kernel. It's easiest to build it as a module. Or, you can use an initramfs.

Udev obsoletes hotplug/coldplug, so you don't need them.

After the driver is installed, just emerge wpa_supplicant and edit your /etc/wpa_supplicant/wpa_supplicant.conf. Everything else should be taken care of automatically.

Portage tips

Exclude packages

http://www.gentoo-wiki.info/HOWTO_Create_an_Updated_Ebuild

autounmask

Tweaking configure. Man 5 ebuild tells us that we can pass extra options to ./configure by setting the environment variable EXTRA_ECONF. There's also EXTRA_EMAKE and EXTRA_EINSTALL. An example looks like this: EXTRA_ECONF="--enable-gold" emerge -av '=sys-devel/binutils-2.18.50.0.6'.

Function keys

First of all, build the i8k support in the kernel. The usespace tool i8kutils is not necessary. Its README could be helpful though. In particular, read "THE I8000 MULTIMEDIA BUTTONS" section. I ended up using the solution described here and here to map mute, volume-down, volume-up buttons under X. I don't know much about sound output, but setting PCM is only effective when "PCM Out" is set to "pre 3D". Setting Master is more reliable.

.Xmodmap

keycode 160 = XF86AudioMute
keycode 174 = XF86AudioLowerVolume
keycode 176 = XF86AudioRaiseVolume
.xbindskeyrc

"amixer set Master toggle"
XF86AudioMute

"amixer set Master 5%-"
XF86AudioLowerVolume

"amixer set Master 5%+"
XF86AudioRaiseVolume

I believe the Fn-CRT/LCD combination is to be handled by the BIOS, but it doesn't seem to do the job. We can use i855crt instead. Examples: i855crt off, i855crt on 1024x768@70.

Bugs and fixes

Fixing broken portage or python

glibc-2.9_p20081201 breaks portage

--as-needed introduction and fixing guide

glibc-2.9_p20081201-r1 breaks firefox-3

升级X的讨论。I didn't encounter this problem on my system, which has evdev and no hal. However, downgrading X to 1.5.2 did cause some issues.

Tips

http://en.gentoo-wiki.com/wiki/Maintain_Gentoo_-_%22Best_Practices%22

http://en.gentoo-wiki.com/wiki/Laptops

http://www.gentoo.org/doc/en/kernel-config.xml

http://www.gentoo.org/doc/en/alsa-guide.xml

http://www.gentoo.org/doc/en/openrc-migration.xml

http://www.gentoo.org/doc/en/utf-8.xml

http://www.gentoo.org/proj/en/lisp/emacs/emacs.xml

http://kunxi.org/archives/2007/07/howto-gentoo-20070-on-dell-700m/

http://forums.gentoo.org/viewtopic-t-279395-highlight-bookstack.html

http://forums.gentoo.org/viewforum-f-12.html

http://www.celifornia.com/documents/dell700m.html

http://www.gentoo-wiki.info/HOWTO_ATAPI_CD_Burning

http://www.gentoo-wiki.info/TIP_Recommended_Packages

X

http://en.gentoo-wiki.com/wiki/X.Org/Dual_Monitors

http://www.gentoo.org/doc/en/dri-howto.xml

http://en.gentoo-wiki.com/wiki/Intel_GMA

http://en.gentoo-wiki.com/wiki/X.Org/xsession

http://www.thinkwiki.org/wiki/Xorg_RandR_1.2

http://en.gentoo-wiki.com/wiki/Synaptics_Touchpad

http://wiki.archlinux.org/index.php/Xorg_input_hotplugging

Fonts

The blessed way of configuration is through eselect fontconfig.

Free fonts

Distcc

I have some Debian machines to speed up compilation. It's important to make sure that all machines have the same version of gcc, in this case, gcc-4.3.2. With older versions of distcc, the client must preprocess the source files first and then send the preprocessed files to the servers. With distcc-3, there's this so-called pump mode that allows the client to send the source files with the header files, and have the servers to do the preprocessing. Enabling pump mode in Gentoo is simple:

distcc-config --set-hosts "foo,cpp,lzo bar,cpp,lzo baz,cpp,lzo"
pump emerge -u world

Unfortunately, Debian only has distcc-2.18. Debian's distcc has a nice zeroconf feature that Gentoo's missing: auto discovery of servers. Check out /usr/share/doc/distcc/README.Debian.

Using the default setup, you're most likely to see errors with exit code 110. The man page of distcc tells us it's "compiler not found". That's because Gentoo uses i686-pc-linux-gnu-gcc as the default compiler, whereas Debian only has i486-linux-gnu-gcc. The solution is to create symlinks on Debian.

For debugging info, we can look at /var/log/distccd.log on the server side. The file was empty on the first run, but restarting the server solved the issue. On the client side, we can DISTCC_DIR="/var/tmp/portage/.distcc/" distccmon-text 5.

Power management

First config your kernel to add in necessary support. Then, install acpid, which receives kernel events and performs actions by matching user-defined rules. In my case, I'd like to suspend to ram when I close the lid. The package hibernate-script does just that. It installs two programs: hibernate, and hibernate-ram. Their behavior can be fine-tuned by editing files under /etc/hibernate/. Under the hood, they rely on either one of the two kernel implementations. For more information, refer to /usr/share/doc/hibernate-script-1.98.1/README. The preferred uswusp implementation, which requires the userspace program suspend, doesn't work well with X on my computer.

Now, I'd like to put the computer to sleep when I close the lid. First observe the log file (depending on the syslogd program you use, the file may differ), and I saw a pair of events when I pressed and released the lid button:

acpid: received event "button/lid LID0 00000080 00000001"
acpid: rule from /etc/acpi/events/default matched
acpid: executing action "/etc/acpi/default.sh button/lid LID0 00000080 00000001"
BEGIN HANDLER MESSAGES
END HANDLER MESSAGES
acpid: action exited with status 0
acpid: 1 total rule matched
acpid: completed event "button/lid LID0 00000080 00000001"
acpid: received event "button/lid LID0 00000080 00000002"
acpid: rule from /etc/acpi/events/default matched
acpid: executing action "/etc/acpi/default.sh button/lid LID0 00000080 00000002"
BEGIN HANDLER MESSAGES
END HANDLER MESSAGES
acpid: action exited with status 0
acpid: 1 total rule matched 
acpid: completed event "button/lid LID0 00000080 00000002"

Instead of looking at the log, you can also run acpi_listen.

Below are my files for handling the lid closing event:

# /etc/acpi/events/lid 
# To only trigger on one, you may use the line
# event=button[ /]lid .*[02468ace]$
# to match only every second event. 

# It is more reliable, however, to check the state of the lid:
event=button/lid
action=/etc/acpi/lid.sh %e
#!/bin/sh
# /etc/acpi/lid.sh 
if grep -q closed /proc/acpi/button/lid/$2/state ; then
  hibernate-ram
fi

lesspipe.sh, a preprocessor for less

in

今天才通过zhllg知道less的这个功能。

less可以通过LESSOPEN 这个环境变量来设置 input preprocessor,从而扩展其可以解释的文件,很好很强大。Debian本身带了一个预处理的shell脚本,放在/usr/bin/lesspipe,但似乎功能没有另外一个专门的lesspipe.sh强大,支持的文件更多,以及语法高亮(在文件尾加':'去除高亮)。

要替换的话,修改~/.bashrc的一行:
[ -x /usr/bin/lesspipe ] && eval "$(lesspipe)"
=>
[ -x /usr/local/bin/lesspipe.sh ] && eval "$(lesspipe.sh)"

iBus - Intelligent Input Bus for Linux / Unix OS

in

今天知道一个新的输入法项目,也许会很有前途,特此记之。

UDPATE: http://www.gnome.asia/static/upload/event_file/Input_Methods.pdf

THE documentation for linux kernel (and beyond)

in

http://kernel.org/doc/

This is just a work in progress at the moment. But its table of content looks very interesting. For more information, check out Where Linux Documentation Hides published in OLS 08.

Why you need separate root and /usr partitions

via LWN.

A user can do ln /usr/sbin/sendmail ~/sendmail then wait for a security bug to be reported in sendmail. Even though the administrator upgrades /usr/sbin/sendmail the buggy setuid sendmail is still available in the user's home directory.

This is one reason to have separate root and /usr partitions, because hardlinking across filesystems isn't possible.

Syndicate content