AzuWis Blog

Blogging Like a Hacker.

Debootstrap X86_64 Debian on an I386 Debian

I know that an i386 Debian can be easily installed using debootstrap on a already installed x86_64 Debian.

But the scenario is an i386 Debian is already installed on a machine that has a x86_64 CPU, and I want to bootstrap a x86_64 Debian on it. Can this be done?

The answer is yes, with a bit more extra work.

First install a x86_64 kernel, so that debootstrap can run x86_64 apps in the chroot. An i386 system can run under a x86_64 kernel, and Debian has prepared everything for you, just:

1
2
3
# aptitude install linux-image-2.6-amd64
# update-grub # just in case dpkg won't run this for you
# reboot

Select x86_64 kernel in the grub menu and boot, and the rest is just a normal debootstrap process:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# fdisk /dev/sdX # partition
# mkdir /mnt/target
# mount /mnt/target # mount all target partitions, including /boot, /home...
# debootstrap --verbose --arch amd64 unstable /mnt/target
# mount -o bind /proc /mnt/target/proc
# mount -o bind /dev /mnt/target/dev
# chroot /mnt/target
# dpkg-reconfigure debconf # set to low
# dpkg-reconfigure -a # reconfigure all packages
# aptitude # install needed packages, remember to install locales
# vi /etc/fstab
# aptitude install linux-image-2.6-amd64 # install kernel inside the chroot
# passwd # change root password
# useradd -m -s /bin/bash normal_user # add a normal user

Exit chroot and add the new entry in grub’s config file, reboot. Now you have a newly installed x86_64 Debian.

For more detail, see this chapter of Debian GNU/Linux Installation Guide and debootstrap manual.

Autohotkey Script for Fullscreen Windowed War3

If you like me, press alt+tab a lot when playing war3, maybe here is what you want.

In normal fullscreen mode of war3, video display mode will change and cause flicking every time you alt-tab out and in. This is annoying.

Add -window param to the war3 startup shortcut, this will let war3 run in window mode. Use this piece of autohotkey script to remove the window decoration and border, and make window fullscreen:

1
2
WinSet, Style, -0xC40000, Warcraft III
WinMaximize, Warcraft III

Script file here, base on Window Tools.

Custom Debian Repository

This is not a complete howto, I just wrote it for memorizing.

preparation

$ git clone git://git.debian.org/git/buildd-tools/buildd.git
$ cd buildd && debuild binary
# dpkg -i ../buildd_*.deb
# aptitude install sbuild wanna-build buildd quin-diff dupload reprepro inoticoming

sbuild

create chroots, watch final output:

# useradd -m -s /bin/bash buildd
# sbuild-createchroot --include="pkg-config" --arch=i386 sid /home/buildd/chroot/unstable http://ftp.debian.org/debian

refine auto added schroot config file:

# mv /etc/schroot/chroot.d/sid-i386-sbuild.pk4BSL /etc/schroot/chroot.d/sid-i386-sbuild
# edit /etc/schroot/chroot.d/sid-i386-sbuild, add [unstable-i386-sbuild]

edit /home/buildd/chroot/unstable/etc/apt/sources.list and /home/buildd/chroot/unstable/etc/apt/preferences:

  • add local repo to sources.list:

      deb http://your-repo/debian sid main
      deb-src http://your-repo/debian sid main
    

Compare Debian Style Version Numbers

I wanted to write a script to comparing debian style version numbers, for a reason I don’t remember. Today, I’ve just discover this:

$ dpkg --compare-versions 1.5.1 gt 1.5.1~svn && echo "1.5.1 is greater"
1.5.1 is greater

And there’re some api in package libapt-pkg-perl to, see:

$ /usr/share/doc/libapt-pkg-perl/examples/apt-version compare 1.5.1~svn 1.5.1
[System: Debian dpkg interface; Versioning type: Standard .deb]
* package version `1.5.1~svn' is earlier than `1.5.1'

Pastbinit

在 IRC 里问问题的时候经常要贴一些 log,而 http://pastebin.com 就是贴 log 的好地方,甚至还有人专门写了一个工具来贴 log,这个工具在 Debian 里有包:

# aptitude install pastebinit

就可以安装,使用很简单:

$ pastebinit file_to_paste
http://pastebin.com/f2a9b78ec

Directly Modity Meta Info of Deb Package

Sometime I want to modify the meta info of some deb packages directly, remove dependences, increase version number, etc.

For example, fusion-icon, in compiz-fusion debian repository by shames, depends on compiz-kde | compiz-gnome.

In fact, compiz-kde or compiz-gnome are not necessary. If the desktop environment is Xfce or KDE4, those packages are not needed at all.

So, here is how to directly modify deb packages without recompiling, remove dependence:

# apt-cache policy fusion-icon
fusion-icon:
  Installed: (none)
  Candidate: 0.1.2+git20080216.shame-1
  Version table:
     0.1.2+git20080216.shame-1 0
        500 http://download.tuxfamily.org ./ Packages
     0.0.0+git20071028-3 0
        500 http://ftp.debian.org lenny/main Packages
        300 http://ftp.debian.org sid/main Packages
# aptitude download fusion-icon=0.1.2+git20080216.shame-1
# dpkg-deb -x fusion-icon_0.1.2+git20080216.shame-1_amd64.deb deb/
# dpkg-deb -e fusion-icon_0.1.2+git20080216.shame-1_amd64.deb deb/DEBIAN/
# vi deb/DEBIAN/control ...edit the file
# dpkg-deb -b deb/ my.deb
# dpkg -i my.deb

更新 Linux 内核模块的较好方法

有时候 Linux 内核模块有更新,或者有第三方的改动需要用,要替换原来的模块。

比较简单的方法是把原来的 *.ko 文件直接替换,但这样有不好的地方,如果想换回来,比较麻烦。

较好的方法是把模块装在 /lib/modules/`uname -r`/updates/ 下面,再运行 depmod,这样下次开机自动加载模块,或者用 modprobe 加载模块时,就会用 updates 下面的。如:

# cp libdrm/linux-core/drm.ko /lib/modules/`uname -r`/updates/
# depmod
# /sbin/modinfo drm
filename:       /lib/modules/2.6.25-2-amd64/updates/drm.ko
license:        GPL and additional rights
description:    DRM shared core routines
author:         Gareth Hughes, Leif Delgass, José Fonseca, Jon Smirl
depends:
vermagic:       2.6.25 SMP mod_unload
parm:           debug:Enable debug output (int)

给 Firefox 状态栏图标重新排位

Firefox 自己并不能方便的给状态栏的图标重新排序,有一个扩展叫 Organize Status Bar,可以比较方便的做这个事情。但只是是为了重新排序而装一个扩展,似乎并不值得。

其实,Firefox 状态栏的图标一般是由扩展产生的,图标的顺序跟扩展的安装顺序对应。通过改扩展的顺序,可以改变状态栏图标的顺序。

在 Firefox 的配置目录(Linux 下为 ~/.mozilla/firefox/*.default/)里,extensions.ini 这个文件记录的是扩展的顺序,如:

[ExtensionDirs]
Extension0=/home/azuwis/.mozilla/firefox/cv7nxof9.default/extensions/firebug@software.joehewitt.com
Extension1=/home/azuwis/.mozilla/firefox/cv7nxof9.default/extensions/{0C4B554C-05D9-11DB-9804-B622A1EF5492}

通过查看 extensions.rdf 这个文件,可以得到扩展的 ID 和名称的对应,如:

<RDF:Description RDF:about="urn:mozilla:item:{73a6fe31-595d-460b-a920-fcc0f8843232}"
    ...
    NS1:name="NoScript"
    ...

就知道 {73a6fe31-595d-460b-a920-fcc0f8843232} 这个 ID 是对应 NoScript 这个扩展的,根据这点修改 extensions.ini 的内容,改变扩展的顺序,重启 Firefox,状态栏图标的顺序就会跟著改变。

Using Mouse to Select Text in Aptitude

It obsessed me for a long time, but today I found the answer in aptitude’s FAQ:

1) I want to select text, why doesn't aptitude let me disable the mouse?

    When a program running in an xterm is accessing the mouse, the xterm
    disables text selection.  However, you can override this behavior and
    perform a selection by holding the Shift key down.

So, just hold down shift key, copying and pasting text in aptitude’s curses interface will work as expected.

It’s always good to look at software’s FAQ before using it.

拿 Google Calendar 来做接口给自己发短信

google calendar 的短信提醒服务支持中国移动(联通不知道是不是支持),可以通过 google 提供的 GData 接口给 google calendar 添加短信提醒,从而达到短信接口的效果。

首先是让你的 google calendar 帐号跟你的手机绑定。

下面是一个 ruby 代码实现添加提醒:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/ruby
require 'rubygems'
require 'googlecalendar'

def sms(google_acount, password, message)
  now = Time.now.utc
  # 添加一个 360 秒后的事件
  startTime = (now + 360).strftime("%Y-%m-%dT%H:%M:%S.000Z")
  endTime = (now + 3600 + 360).strftime("%Y-%m-%dT%H:%M:%S.000Z")
  g = GData.new
  g.login(google_acount + '@gmail.com', password)
  event = { :title=>message,
    :content=>message,
    :author=>google_acount,
    :email=>google_acount + '@gmail.com',
    :where=>'some place',
    :startTime=>startTime,
    :endTime=>endTime
  }
  # 给事件添加一个提前 5 分钟的 sms 提醒
  g.add_reminder(event, 5, 'sms')
  g.new_event(event)
end

sms(google_acount, password, 'a test')

googlecalendar 的 rubygem 可以用 gem install googlecalendar 来安装。

还有 gcalcli 命令行工具,可以管理 google calendar,不喜欢自己写代码的也可以用这个实现。