现在用的桌面

上星期弄的,扔掉 icewm 了。桌面依然是 ROX-filer 的 pinboard,WM 是 Openbox,下面的 panel 是 fbpanel。原先想加上 conky,后来发现效果不佳,就去掉了。

Openbox 的配置文件是 xml 的,很易处理。我写了个 python 脚本配置主菜单。但一个问题是 Openbox 的主菜单无法直接在 panel 上调用,因为 panel 不是 Openbox 的。后来使用了 xdotool 解决了

openbox-shot-1.png

栈究竟有多大?

昨天跟骨头因为某些原因谈到了 linux 中进程的栈有多大的问题。从 ulimit -a 中可以看出,栈大小是 8M ,但经过试验,发现并非如此。看来唯有用实验的方法找了。

这是测试程序的代码

int main()
{
        char a[S_SIZE];
        a[0] = '\1';
        return 0;
}

通过控制 S_SIZE 的值,观测程序是否因段错误崩溃,就可以大致知道栈空间有多大。至于寻找 S_SIZE,我使用了二分的方法。

但奇怪的是,寻找出来的 S_SIZE 的值竟然每次都不同,骨头他也发现当 a 的大小在某个区域(大约在 8380000 字节附近)时,程序段错误出现了随机性。实在太奇怪了。

既然出现了随机性,于是便统计了成功运行(即没有出现段错误)的概率和 a 大小的关系:(骨头供图,横坐标是 a 的大小,单位字节,纵坐标是成功概率,单位 %)

i9084.png

噢,看来是线性相关哦。根据老狼的解释,程序进入 main() 之前,先进入了 glibc 里的 _start(),并占用了部分的栈。如果是这样的话,留给 main() 的栈空间大小大概为 8376000Byte ~ 8384200Byte,且呈均匀分布(即栈大小为在此区间内各值的机率是均等的)。至于为什么会这样,可能跟 _start 的实现有关,就不清楚了。

附一篇 Before main() 分析。貌似很复杂,我没深入看。

LFS 6.3 with reiser4 and initrd

上周用了一周时间搞了 LFS 6.3, 用 reiser4 作根分区.
LFS 本身没什么, 细心看 LFS Book 应该就没问题了. 我就分享一下用 reiser4 的经验吧.

www.namesys.com 无法访问, 所以 reiser4 需要的东西可以从这里下载:
http://chichkin_i.zelnet.ru/namesys/

参考文章:
http://www.linuxfromscratch.org/hints/downloads/files/initrd.txt
http://www.linuxfromscratch.org/hints/downloads/files/reiser4-on-2.6.txt

需要的 mkinitrd 脚本:
http://www.linuxfromscratch.org/hints/downloads/files/ATTACHMENTS/initrd/

首先刚开始准备分区时要格式化成 reiser4 ( LiveCD 支持 reiser4 )
然后准备内核:

tar xfv linux-2.6.22.5.tar.bz2
cd linux-2.6.22.5
zcat path-to-patch/reiser4-for-2.6.22-2.patch.gz | patch -p1
cd ..
tar jcfv linux-2.6.22.5-patched.tar.bz2 linux-2.6.22.5
rm linux-2.6.22.5

以后用到内核源码就用这个 linux-2.6.22.5-patched.tar.bz2

然后到了 grub 那节, 跳过. 用grub 启动 reiser4 比较麻烦, 用 lilo 会方便点.

第六章安装完最后一个软件 vim 后, 就要安装 reiser4 的东西了
首先是 libaal

./configure --prefix=/usr --sbindir=/sbin --enable-libminimal --enable-static
make
make install

然后是reiser4progs

./configure --prefix=/usr --sbindir=/sbin --enable-libminimal --enable-full-static
make
make install

编译内核时文件系统选上 reiser4 就可以了

下面是 initrd 用的:

第八章编译内核时要注意这几个配置:
-> General setup -> Initial RAM filesystem and RAM disk (initramfs/initrd) support 选 y
-> Device Drivers -> Block devices -> RAM disk support 选 y
-> File systems -> Ext3 journalling file system support 选 y
然后编译内核.

initrd 需要 busybox 作 shell.
下载: http://www.busybox.net/downloads/busybox-1.01.tar.bz2 切勿贪新.
配置:

make defconfig
sed -r 's/^([^#=]+).+/# \1 is not set/g' -i .config # 配置全部选 n
make menuconfig

像这样配置

	General Configuration --->
		[*] Support for devfs
			 NOTE - only if you using devfs
	Build Options  --->
		[*] Build BusyBox as a static binary (no shared libs)
	Coreutils  --->
		[*] echo (basic SUSv3 version taking no options
	Linux Module Utilities  --->
		[*] insmod
		[*]     Support version 2.1.x to 2.4.x Linux kernels
			NOTE - only if your using a 2.4 kernel
		[*]     Support version 2.6.x Linux kernels
			NOTE - only if your using a 2.6 kernel
	Another Bourne-like Shell  --->
		[*]     Optimize for size instead of speed
		[*]     Enable alias support
		(0) his×y size
	Linux System Utilities  --->
		[*] pivot_root
		[*] mount

然后编译安装:

make
cp busybox /bin/busybox.static

制作 initrd 镜像:

mkinitrd kernel_version=2.6.22.5 initrdfs=ext3 +module="piix libata ata_piix reiser4 ata_generic reiser4"

附加的 module 按需选择, 看一下 lsmod 是个好主意.

接着添加一个启动脚本, 在启动后清理 initrd :

#!/bin/sh
# Begin $rc_base/init.d/initrd

# Based on sysklogd script from LFS-3.1 and earlier.
# Rewritten by Gerard Beekmans  - gerard@linuxfromscratch.org

source /etc/sysconfig/rc
source $rc_functions

case "$1" in
        start)
        if [ -e /initrd/dev/.devfsd ]
        then   
                umount /initrd/dev
        fi
       
        if [ -e /initrd/proc ]
        then   
                umount /initrd/proc
        fi
       
        if [ -e /initrd/sys ]
        then   
                umount /initrd/sys
        fi
       
        if [ -e /initrd/linuxrc ]
        then   
                umount /initrd
                echo "Clearing Initial RAM Disk..."
                blockdev --flushbufs /dev/ram0
                evaluate_retval
        fi
        ;;
        *)
        echo "Usage: $0 {start}"
        exit 1
        ;;
esac

# End $rc_base/init.d/initrd

保存为 /etc/rc.d/init.d/initrd, 然后在 /etc/rc.d/rcsysinit.d 建一个符号链接:

ln -sf ../init.d/initrd S41initrd

Reboot and enjoy !

解决烦人的启动信息

Ubuntu 的 upstart 系统有个bug, 有时候登录提示符出了还在往屏上写启动信息. 虽然不影响功能, 但每次登录都要先 Enter 一下实在不爽.
这里找到解决方法, 看来是个老 bug.

To accomplish this task, edit /etc/event.d/tty1 and replace:
   start on runlevel 2
with:
   start on stopped rc2
With trivial modifications, it also works for runlevels other than 2 and for tty's other than 1. Note that those modifications should SOLVE the bug and should't be a workaround.
Cheers!

kvm 下跑 super pi

在带 kvm 的 qemu 里跑了一下 super pi, guest 是 XP SP2
with kvm

CPU 的性能还是不错的, 在 host 里是 23 秒.

对比没有开 kvm 的
without kvm

但是运行起来还是比较卡, 感觉是 QEMU 的磁盘 IO 的问题.

//////////////////////////

看一下9佬在 VBox 的测试, 性能很接近

KVM

无 KVM

Wine