2011-06-14

使用Mac OS做pxe server安装linux

要装一台RHEL,但是服务器的光驱是cdrom,又只有dvd光盘。而我的MBP上只安装了Mac OS,没有装Linux,于是想用MBP做PXE服务器,利用网络来安装Linux。弄了一下弄成功了。

需要的软件和在Linux下一样,就是tftpd+dhcpd。Mac OS Server版自带tftpd和dhcpd,而桌面版只有tftpd,需要自己装dhcpd。Server版的方法见 http://www.shawnhogan.com/2011/05/pxe-network-boot-linux-with-mac-os-x-server.html

1.先装dhcpd。我选择使用Macports

  • sudo port install dhcpd #安装dhcpd
  • cd /otp/local/etc/dhcp
  • sudo cp dhcpd.conf.sample dhcpd.conf

修改 dhcpd.conf 确保有以下内容
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.70 192.168.1.100;
filename "pxelinux.0";
next-server 192.168.1.50;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.1.255;
option routers 192.168.1.1;
}
这里根据实际情况修改

然后启动dhcpd
sudo launchctl load -w /Library/LaunchDaemons/org.macports.dhcpd.plist

2.配置 tftp
先 sudo -H -s切为root用户,以下命令以root执行

  • cd /private/tftpboot
  • wget http://ftp.uk.debian.org/debian/dists/lenny/main/installer-i386/current/images/netboot/debian-installer/i386/pxelinux.0 #下载一个pxelinux.0
  • mkdir pxelinux.cfg
  • mkdir -p rhel/5.4/i386

在 pxelinux.cfg 目录下新建一个default的文件
文件内容如下

DISPLAY boot.txt
DEFAULT rhel5.4_i386_install

LABEL rhel5.4_i386_install
kernel rhel/5.4/i386/vmlinuz
append vga=normal initrd=rhel/5.4/i386/initrd.img --
PROMPT 1
TIMEOUT 0
接下来需要从rhel的光盘中拷贝pxeboot所需要的文件,在光盘的images/pxeboot目录下,把vmlinuz和initrd.img拷到 /private/tftpboot/rhel/5.4/i386目录

再启动tftp
sudo launchctl load -w /System/Library/LaunchDaemons/tftp.plist


基本就可以了,装完以后想关掉tftp和dhcp,执行以下命令就可以了

sudo launchctl unload -w /Library/LaunchDaemons/org.macports.dhcpd.plist
sudo launchctl unload -w /System/Library/LaunchDaemons/tftp.plist
可参考我以前的这篇 http://geektang.blogspot.com/2009/07/debian-pxe.html

2011-03-03

ubuntu10.10升级到11.04过程中python2.7升级出错的解决方法

10.10默认python是2.6
11.04默认python是2.7

这个问题貌似在debian上也会出现

现象就是升级python2.7 python2.7-minimal时提示
Preconfiguring packages ...
Setting up python2.7-minimal (2.7.1-1ubuntu4) ...
Linking and byte-compiling packages for runtime python2.7...
E: pycompile:240: Requested versions are not installed
dpkg: error processing python2.7-minimal (--configure):
 subprocess installed post-installation script returned error exit status 3
Errors were encountered while processing:
 python2.7-minimal


问题出在python2.7-minimal的postinst脚本会去执行 /usr/share/python/runtime.d/public_modules.rtinstall 脚本,在public_modules.rtinstall中需要执行
pycompile -V 2.7 /usr/lib/python2.7 ,而这时候python2.7根本还没装,就导致循环出错了


解决方法:
在提示出错后,修改 /usr/share/python/runtime.d/public_modules.rtinstall ,注释掉所有的内容,
然后 apt-get -f install
待正常后,再执行一次 pycompile -V 2.7 /usr/lib/python2.7/dist-packages 就行了

2011-01-14

找到一个清理邮件队列的脚本

功能就是清理指定邮箱的队列
如果复制粘帖不好用,这里有个纯文本的 http://www.arschkrebs.de/postfix/scripts/delete-from-mailq


脚本如下
#!/usr/bin/perl

$REGEXP = shift || die "no email-adress given (regexp-style, e.g. bl.*\@yahoo.com)!";

@data = qx;
for (@data) {
  if (/^(\w+)(\*|\!)?\s/) {
     $queue_id = $1;
  }
  if($queue_id) {
    if (/$REGEXP/i) {
      $Q{$queue_id} = 1;
      $queue_id = "";
    }
  }
}

#open(POSTSUPER,"|cat") || die "couldn't open postsuper" ;
open(POSTSUPER,"|postsuper -d -") || die "couldn't open postsuper" ;

foreach (keys %Q) {
  print POSTSUPER "$_\n";
};
close(POSTSUPER);

完美解决centos5.5上vsftpd编码问题

一直以来 vsftpd 有个讨厌的乱码问题(据说在2.10以上版本就解决了,但我还没有测试),这个问题是这样的:如果服务器是UTF-8的locale,那么从windows上不支持ftp编码设置的客户端(比如ftp.exe)往vsftpd上传带有中文的文件名或者目录,那么在服务器上看到的文件名或者目录都是乱码(当然可以临时修改LC_LANG变量再修改终端的charset解决),更关键的是/var/log/vsftpd.log里也都是不可读的,全是疑问号。

公司里用centos5.5 + vsftpd,今天特地搜了一下,解决了这个问题。

最早应该是linuxsir的网友制作了vsftpd的中文编码补丁,centos5.5上的2.0.5版本的版本在这里  http://www.linuxsir.org/bbs/thread301341-3.html

我根据centos5.5上vsftpd 2.0.5的srpm重新编译了一个rpm包,可以直接从这里下载
http://fileape.com/dl/0jZnsbpdwvsPXcT5
http://www.multiupload.com/9RV57H2LTI

安装后 /etc/vsftpd/vsftpd.conf 添加以下三个选项即可

charset_filter_enable=YES
charset_client=GB2312
charset_server=UTF8

2011-01-04

php里用gpg解密文件

花了好长时间测试一直解不了,但把命令行在shell里执行却是可以的

在这里记录一下以供后来人参考吧

http://devzone.zend.com/article/1265 这篇文章很不靠谱,看了下面的讨论一条条试下来终于找到可用的了...

用这个即可

<?php
$gpg = '/usr/bin/gpg';
$passphrase = 'password';
$unencrypted_file = "foo";
$encrypted_file = "bar";
$cmd = "$gpg --no-tty --homedir /var/www/.gnupg --yes --passphrase=$passphrase -o $unencrypted_file -d $encrypted_file";
shell_exec($cmd);
?>

重点是 --no-tty 选项和 --homedir选项

2010-12-29

ibook使用英汉字典

首先你的iOS设置必须越狱,不想越狱或者没有办法越狱的请绕行了...

ibook使用的字典和Mac上的字典是一样的 当然Mac自带的字典也只有英英字典,要使用英汉字典可以用 DictUnifier 转换 stardict 的字典为Mac字典的格式

不想自己转换的话,这里有个现成的 http://ifile.it/gm8do2y

弄完后,把字典的目录名称改为 New Oxford American Dictionary.dictionary,然后修改 New Oxford American Dictionary.dictionary/Contents/Info.plist

修改如下的内容 这里不改ibook是不能识别的
<key>CFBundleDisplayName</key>
<string>New Oxford American Dictionary.dictionary</string>
<key>CFBundleIdentifier</key>
<string>com.apple.dictionary.NOAD</string>
接下来就是用scp或者其它任意的方法把字典传到 iOS 的/Library/Dictionaries 目录

当然在上传之前最好把原来的 /Library/Dictionaries/New Oxford American Dictionary.dictionary 改个名备份一下

最后重启一下设备或者重启springboard就可以了

2010-12-27

virtualbox镜象转换为kvm镜象

方法很简单,两个步骤

1.
VBoxManage clonehd --format RAW source.vdi dest.img

2.
qemu-img convert -f raw dest.img -O qcow2 dest.qcow

但是有两点要注意,我就是在这上面吃了亏

1.virtualbox如果曾经使用过sanpshot,而要把之前的snapshot都删掉,让virtualbox把snapshot和当前状态进行merge。否则如果直接拿vdi文件转换则是老的数据而不是当前虚拟机正在运行的数据

2.virtualbox新建虚拟机时选定的文件是多大则用VBoxManage转换时需要的剩余空间要多大。比如vbox虚拟机分配的空间是20G,则当前剩余空间必须达到20G,否则第一步VBoxManage转换会出错

update:
直接qemu-img convert -f vdi source.vdi -O qcow2 dest.qcow 转换就可以了