2012年10月8日月曜日

OpenBSDでvirtioを利用する

OpenBSDにvirtioが入ったようなので、早速使ってみる。
今のところ5.2には無く-currentにのみ入っているようなので、素直に-currentをビルド。 -currentならGENERICにvirtioが入っているので、特別な設定は要らない。 ビルド手順については、 公式のドキュメント通りに行った。

…がしかし、 sys/arch/amd64/amd64/cpu.cのコンパイルが失敗する。

{standard input}: Assembler messages: 
{standard input}:198: Error: no such instruction: `rdrand %rbx'
*** Error code 1

どうやらインラインアセンブラでこけているようだが、rdrandなんて見たこと無いのでググってみた。
http://en.wikipedia.org/wiki/RdRand
どうやら、インなんとかさんのIvy Bridgeで追加された乱数生成命令らしい。 そんなものうちのAMD E-450には無いので、rdrand()の中を全部さくっとコメントアウト。 ついでにrdrandでgrepして引っかかったidentcpu.cのhas_rdrand = 1をhas_rdrand = 0に変更。
rdrand()自体がr1.51で最近追加されたばかりの関数のようなので、 たぶんこれで大丈夫じゃないかなーと思いビルドしなおしたらあっさり通った。 そしてユーザランドも問題なくコンパイルできた。
dmesgは以下の通り。

OpenBSD 5.2-current (HACHUNE.MP) #0: Mon Oct  8 17:23:02 JST 2012
    root@obsd.k.hachune.net:/usr/src/sys/arch/amd64/compile/HACHUNE.MP
real mem = 1072685056 (1022MB)
avail mem = 1024802816 (977MB)
mainbus0 at root
bios0 at mainbus0: SMBIOS rev. 2.4 @ 0xfd980 (11 entries)
bios0: vendor Bochs version "Bochs" date 01/01/2007
bios0: Bochs Bochs
acpi0 at bios0: rev 0
acpi0: sleep states S3 S4 S5
acpi0: tables DSDT FACP SSDT APIC HPET SSDT
acpi0: wakeup devices
acpitimer0 at acpi0: 3579545 Hz, 24 bits
acpimadt0 at acpi0 addr 0xfee00000: PC-AT compat
acpihpet0 at acpi0: 100000000 Hz
acpiprt0 at acpi0: bus 0 (PCI0)
mpbios0 at bios0: Intel MP Specification 1.4
cpu0 at mainbus0: apid 0 (boot processor)
cpu0: QEMU Virtual CPU version 1.2.0, 1646.91 MHz
cpu0: FPU,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,MMX,FXSR,SSE,SSE2,SSE3,CX16,POPCNT,NXE,LONG,LAHF,SVM,ABM,SSE4A
cpu0: 64KB 64b/line 2-way I-cache, 64KB 64b/line 2-way D-cache, 512KB 64b/line 16-way L2 cache
cpu0: ITLB 255 4KB entries direct-mapped, 255 4MB entries direct-mapped
cpu0: DTLB 255 4KB entries direct-mapped, 255 4MB entries direct-mapped
cpu0: apic clock running at 1009MHz
cpu1 at mainbus0: apid 1 (application processor)
cpu1: QEMU Virtual CPU version 1.2.0, 1663.20 MHz
cpu1: FPU,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,MMX,FXSR,SSE,SSE2,SSE3,CX16,POPCNT,NXE,LONG,LAHF,SVM,ABM,SSE4A
cpu1: 64KB 64b/line 2-way I-cache, 64KB 64b/line 2-way D-cache, 512KB 64b/line 16-way L2 cache
cpu1: ITLB 255 4KB entries direct-mapped, 255 4MB entries direct-mapped
cpu1: DTLB 255 4KB entries direct-mapped, 255 4MB entries direct-mapped
mpbios0: bus 0 is type PCI   
mpbios0: bus 1 is type ISA   
ioapic0 at mainbus0: apid 2 pa 0xfec00000, version 11, 24 pins
ioapic0: misconfigured as apic 0, remapped to apid 2
pci0 at mainbus0 bus 0
pchb0 at pci0 dev 0 function 0 "Intel 82441FX" rev 0x02
pcib0 at pci0 dev 1 function 0 "Intel 82371SB ISA" rev 0x00
pciide0 at pci0 dev 1 function 1 "Intel 82371SB IDE" rev 0x00: DMA, channel 0 wired to compatibility, channel 1 wired to compatibility
pciide0: channel 0 disabled (no drives)
atapiscsi0 at pciide0 channel 1 drive 0
scsibus0 at atapiscsi0: 2 targets
cd0 at scsibus0 targ 0 lun 0:  ATAPI 5/cdrom removable
cd0(pciide0:1:0): using PIO mode 4, DMA mode 2
piixpm0 at pci0 dev 1 function 3 "Intel 82371AB Power" rev 0x03: apic 2 int 9
iic0 at piixpm0
iic0: addr 0x4c 48=00 words 00=0000 01=0000 02=0000 03=0000 04=0000 05=0000 06=0000 07=0000
iic0: addr 0x4e 48=00 words 00=0000 01=0000 02=0000 03=0000 04=0000 05=0000 06=0000 07=0000
vga1 at pci0 dev 2 function 0 "Cirrus Logic CL-GD5446" rev 0x00
wsdisplay0 at vga1 mux 1: console (80x25, vt100 emulation)
wsdisplay0: screen 1-5 added (80x25, vt100 emulation)
virtio0 at pci0 dev 3 function 0 "Qumranet Virtio Network" rev 0x00: Virtio Network Device
vio0 at virtio0: address 52:54:00:12:34:56
virtio0: apic 2 int 11
virtio1 at pci0 dev 4 function 0 "Qumranet Virtio Storage" rev 0x00: Virtio Block Device
vioblk0 at virtio1
scsibus1 at vioblk0: 2 targets
sd0 at scsibus1 targ 0 lun 0:  SCSI3 0/direct fixed
sd0: 5000MB, 512 bytes/sector, 10240000 sectors
virtio1: apic 2 int 11
isa0 at pcib0
isadma0 at isa0
com0 at isa0 port 0x3f8/8 irq 4: ns16550a, 16 byte fifo
com0: console
pckbc0 at isa0 port 0x60/5
pckbd0 at pckbc0 (kbd slot)
pckbc0: using irq 1 for kbd slot
wskbd0 at pckbd0: console keyboard, using wsdisplay0
pms0 at pckbc0 (aux slot)
pckbc0: using irq 12 for aux slot
wsmouse0 at pms0 mux 0
pcppi0 at isa0 port 0x61
spkr0 at pcppi0
lpt0 at isa0 port 0x378/4 irq 7
fdc0 at isa0 port 0x3f0/6 irq 6 drq 2
fd0 at fdc0 drive 0: 1.44MB 80 cyl, 2 head, 18 sec
fd1 at fdc0 drive 1: density unknown
nvram: invalid checksum
mtrr: Pentium Pro MTRR support
vscsi0 at root
scsibus2 at vscsi0: 256 targets
softraid0 at root
scsibus3 at softraid0: 256 targets
root on sd0a (cf20ab2e3b470529.a) swap on sd0b dump on sd0b
clock: unknown CMOS layout

肝心のディスク読み書き速度は以下の通り。

  • virtioなし: read 29767487 bytes/sec, write 21957414 bytes/sec
  • virtioあり: read 53455607 bytes/sec, write 46648054 bytes/sec

virtioを有効にするとだいたい2倍ぐらい速くなるようだ。 これでOpenBSDのBHyVe上への導入も捗る…?

追記: 先にユーザランド更新しとけばrdrandで文句言われなくなるんじゃね?と教えていただいたので、やりなおしてみます。
-> 無事できましたヾ(@⌒ー⌒@)ノ

2012年9月15日土曜日

OSC 2012 Tokyo/Fallにmikutterユーザ会として出展しました

9月7,8日に開催されたオープンソースカンファレンス2012 Tokyo/Fallに mikutterユーザ会として出展しました。
http://www.ospn.jp/osc2012-fall/

去年のOSC仙台以来2回目の参加でいきなりブース出展、しかも一番規模が大 きな東京会場ということでかなり不安もありましたが、お隣の日本NetBSDユー ザグループさんやmikutterのユーザさん達等からいろいろと支援して頂いたり しつつ、mikutterの薄い本vol.2の印刷が間に合わないトラブル等もありましたが、 なんとか無事に終えることが出来ました。ありがとうございました。

mikutterブースの様子。mikutter開発者の @toshi_aさんは、残念ながら お仕事の都合で来れないということで、モックアップとしての参加に。隣に ちびづるん(モックアップ)なるものも参加していたり。 (あっ、マミさ…あれ? 違う… という参加者のつぶやきが聞こえてきたりも)

いろいろなキャラクターが同居しているのもオープンソース界隈ではよくあること(?)
(ちなみに、mikutterグッズはほぼ全てお隣のNetBSDユーザーグループさんからの提供です。)

いろいろと頂いたもの。「mikutterブース」として用意していったものは LiveUSBメモリイメージとmikutterのうすい本 vol.2のサンプル程度だったのですが、 いろいろなブースを巡っていたらいつの間にかバッグがノベルティだらけに。 特にデカかったのはOpenSolarisの本。1000ページ近くあり、持って帰るのが大変な位でした。 (オライリー本は一日目に買っておいて良かった...)

流石に何も作らず持って行かないのはマズいと急遽作成したmikutter LiveUSBメモリイメージ。 配布条件が「4GB以上の全削除可能なUSBメモリを持っている事」 という割と狭い感じでしたが、それでも10人近くの方がUSBメモリを持参してきてくれました。 (中にはわざわざ新品を買ってきたという方も。もうしわけねぇヽ('ω')ノ三ヽ('ω')ノ)

そしてこのカンファレンス中に「mikutterがDebianのパッケージになる…かもしれない」という話が 浮上。Debianのパッケージになると、その派生ディストリビューションにもパッケージとして入ること もあるため、これはwktkしつつ待ちたいところ。
(mikutterのDebianパッケージの問題として、mikutter本体とskinデータのライセンスの違いが一番大きい。 mikutter本体はGPLv3であるものの、skinデータは初音ミクの歌声データ等が含まれる為GPL互換にはできず、 DFSGに適合できない。その点について解決するために、初音ミクに関連するskinを含まないmikutterを 準備する必要がある…という感じ。)

その他にも、お名前.comさんからmikutterユーザ会として VPS(KVM) 4GBプラン 1年分を頂いたりもしました。 今後これを皆で使えるように整備するのが当面の仕事になりそう。

これからもmikutterをよろしくお願いしますヾ(@⌒ー⌒@)ノ

2012年9月13日木曜日

OpenSMTPDからGmailのSMTPサーバを利用する

OpenSMTPDとは

OpenSMTPDはOpenBSDプロジェクトのうちの一部として開発されているSMTPデー モンで、OpenBSDの標準システムに含まれており、またLinux等への移植性も確 保されている。

今回は、Arch Linux上のOpenSMTPDを用いて自宅ローカルネットワークからの メールをGmailのSMTPサーバを経由して送信できるようにする。

OpenSMTPDのインストール

ArchLinuxのOpenSMTPDパッケージはAURにあるので、yaourtを用いてビルドし インストールする。特にPKGBUILDの編集などは必要ないようだ。

$ yaourt -S opensmtpd

インストールされる全ファイルの一覧は以下の通りである。軽量・安全・簡単を 売りにしているだけあって、ファイル数は少なく抑えられている。

[miku@test mail]$ yaourt -Ql opensmtpd
opensmtpd /etc/
opensmtpd /etc/mail/
opensmtpd /etc/mail/smtpd.conf
opensmtpd /etc/rc.d/
opensmtpd /etc/rc.d/smtpd
opensmtpd /usr/
opensmtpd /usr/bin/
opensmtpd /usr/bin/mailq
opensmtpd /usr/bin/newaliases
opensmtpd /usr/lib/
opensmtpd /usr/lib/systemd/
opensmtpd /usr/lib/systemd/system/
opensmtpd /usr/lib/systemd/system/smtpd.service
opensmtpd /usr/libexec/
opensmtpd /usr/libexec/mail.local
opensmtpd /usr/libexec/opensmtpd-portable/
opensmtpd /usr/libexec/opensmtpd-portable/makemap
opensmtpd /usr/sbin/
opensmtpd /usr/sbin/makemap
opensmtpd /usr/sbin/smtpctl
opensmtpd /usr/sbin/smtpd
opensmtpd /usr/share/
opensmtpd /usr/share/man/
opensmtpd /usr/share/man/man5/
opensmtpd /usr/share/man/man5/smtpd.conf.5.gz
opensmtpd /usr/share/man/man8/
opensmtpd /usr/share/man/man8/makemap.8.gz
opensmtpd /usr/share/man/man8/newaliases.8.gz
opensmtpd /usr/share/man/man8/smtpctl.8.gz
opensmtpd /usr/share/man/man8/smtpd.8.gz

smtpd.confの編集

デフォルトのsmtpd.confは以下のようになっている。設定ファイルの形式は、 pf.conf等に似ている。127.0.0.1でlistenしているため、内部へのmbox形式の メール配送と外部へのメール送信のリレーのみを行うようになっている。

listenするインターフェース又はネットワークを10.0.0.0/8等に変更すれば、 LAN内のホストからの要求も受け付けるようになる。この際、accept from 〜等で ネットワーク毎にルールを設定することもできる。

# $OpenBSD: smtpd.conf,v 1.2 2009/11/03 22:32:10 gilles Exp $

# This is the smtpd server system-wide configuration file.
# See smtpd.conf(5) for more information.

# XXX try to find a portable way to get the IP interface
#listen on lo0
listen on 127.0.0.1

map "aliases" { source db "/etc/mail/aliases.db" }

accept for local alias aliases deliver to mbox
accept for all relay

しかし、このままでは内部への配送は正しく行われるが、外部へのリレーは利 用しているプロバイダや回線の契約によってはOP25Bにより正しく行われない可 能性がある。そこで、GmailのSMTPサーバを経由し外部へのメール送信を行う ように設定を変更する。

Gmailでは、STARTTLSを用いた認証を行うことでSMTPサーバを利用できる。 サーバホスト名はsmtp.gmail.com、ポート番号は587、アカウント名は"gmail アカウント@gmail.com"、パスワードはGmailのものを用いる。

以上の変更点を適用したsmtpd.confは以下のようになった。

listen on lo

map "aliases" { source db "/etc/mail/aliases.db" }
map "secrets" { source db "/etc/mail/secrets.db" }

accept for local alias "aliases" deliver to mbox
accept from all for all relay via tls+auth://smtp.gmail.com:587 auth "secrets"

この他にも、Gmailのユーザ名とパスワードを保持刷るためのファイル /etc/mail/secrets.dbが必要になる。このファイルはプレーンテキストで以下 のように書かれた/etc/mail/secretsを、makemapコマンドを用いて変換したも のである。

smtp.gmail.com Gmailのアカウント名@gmail.com:Gmailのパスワード

このsecretsとsecrets.dbのパーミッションは640、オーナーはroot:_smtpdに 設定する。

smtpdの起動

smtpdの動作を確認するため、まずはコマンドラインから-d(Do not daemonize)と-v(verbose output)オプションを付けて起動する。

試しにメールを送信してみる。

[miku@test ~]$ telnet localhost 25
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 test.k.hachune.net ESMTP OpenSMTPD
EHLO hachune.net
250-test.k.hachune.net Hello hachune.net [IPv6:::1], pleased to meet
you
250-8BITMIME
250-ENHANCEDSTATUSCODES
250-SIZE 18446744073709551615
250 HELP
MAIL FROM:
250 2.1.0 Sender ok
RCPT TO:
250 2.0.0 Recipient ok
DATA
354 Enter mail, end with "." on a line by itself
Subject: SMTPD Test
From: Miku Hachune
To: Phenomer
Date: Thu, 13 Sep 2012 17:29:26 +0900

mikumiku
.
QUIT

メールが正しく届いていればOK、もし届いていないようであればmailqや端末 上のログを確認する。 このままOpenSMTPDを使い続ける場合は、/etc/rc.confのDAEMONSにsmtpdを追 加しておく。

参考

OpenSMTPD
http://www.opensmtpd.org/

その他のメール クライアントの設定 - Gmail ヘルプ
https://support.google.com/mail/bin/answer.py?hl=ja&answer=78799

2012年5月16日水曜日

Arch LinuxのXenでxlコマンドが利用できない件

ノートPC(X121e)にArchLinuxを入れてXen DOM0で遊んでいるのだが、xlコマンドがうまく動作せず、 Xen4.1の時点ではdeprecatedなxmコマンドをずっと使っていた。しかし乗り換えない訳にもいかないので 原因を探ってみた。

xenstored起動スクリプトの修正

まず一つ目の、xenstoredが起動しているにも関わらずxenstoredが動いてない(?)と怒られる問題。 単純にpidファイルのパスがArchとXenとで合っていなかっただけだった。 /etc/rc.d/xencommonsのxenstored起動部分を書き換えるだけでOK。

# xenstored --pid-file=/run/daemons/xenstored.pid $XENSTORED_ARGS
xenstored --pid-file=/var/run/xenstored.pid $XENSTORED_ARGS

停止時も考慮しないといけないよなぁ、と思ってdo_stop()を見てみたが、

printhl "WARNING: Not stopping xenstored, as it cannot be restarted."

そいつは一度起動したら止められないぜ!…ということらしい。

xl consoleの不具合

xlコマンドは実行できるようになったものの、何故かxl consoleで consoleに入れない。エラー内容も「失敗した」と出るだけ。 仕方がないのでstraceしてみたら…

execve("/usr/lib64/xen/bin/xenconsole", ["/usr/lib64/xen/bin/xenconsole", "4", "--num", "0", "--type", "pv"],
 [/* 15 vars */]) = -1 ENOENT (No such file or directory)

/usr/lib64ってなんですかー。 どうやら、xenconsoleバイナリの参照先が/usr/lib64決め打ちになっている模様。どこのディストリの名残りなのやら…。 とりあえずln -s /usr/lib /usr/lib64してあっさり解決。

miku@hachune% sudo xl create -c netbsd.cfg
パスワード:
Parsing config file netbsd.cfg
xc: error: panic: xc_dom_bzimageloader.c:556: xc_dom_probe_bzimage_kernel: kernel is not a
 bzImage: Invalid kernel
Daemon running with PID 6683
                            Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 
2004, 2005,
    2006, 2007, 2008, 2009, 2010, 2011, 2012
    The NetBSD Foundation, Inc.  All rights reserved.
Copyright (c) 1982, 1986, 1989, 1991, 1993
    The Regents of the University of California.  All rights reserved.

NetBSD 6.0_BETA (HACHUNE_U) #0: Thu Apr 26 19:16:15 JST 2012
        miku@hachune.hachune.net:/tmp/netbsd/sys/arch/amd64/compile/HACHUNE_U
total memory = 512 MB
avail memory = 486 MB
mainbus0 (root)
hypervisor0 at mainbus0: Xen version 4.1.2
vcpu0 at hypervisor0: AMD E-450 APU with Radeon(tm) HD Graphics, id 0x500f20
xenbus0 at hypervisor0: Xen Virtual Bus Interface
xencons0 at hypervisor0: Xen Virtual Console Driver
xenbus: can't get state for device/suspend/event-channel (2)
xbd0 at xenbus0 id 0: Xen Virtual Block Device Interface
xennet0 at xenbus0 id 0: Xen Virtual Network Interface
xennet0: MAC address 00:16:3e:39:03:10
balloon0 at xenbus0 id 0: Xen Balloon driver
balloon0: current reservation: 524288 KiB
xennet0: using RX copy mode
xenbus: can't get state for device/suspend/event-channel (2)
balloon0: current reservation: 131072 pages => target: 131072 pages
ignore shutdown request: 
xenbus: can't get state for device/suspend/event-channel (2)
xenbus: can't get state for device/suspend/event-channel (2)
xenbus: can't get state for device/suspend/event-channel (2)
xenbus: can't get state for device/suspend/event-channel (2)
xenbus: can't get state for device/suspend/event-channel (2)
xenbus: can't get state for device/suspend/event-channel (2)
xenbus: can't get state for device/suspend/event-channel (2)
xenbus: can't get state for device/suspend/event-channel (2)
boot device: xbd0
root on xbd0a dumps on xbd0b
root file system type: ffs
Wed May 16 09:56:39 JST 2012
Starting root file system check:
/dev/rxbd0a: file system is clean; not checking
Starting file system checks:
Setting tty flags.
Setting sysctl variables:
ddb.onpanic: 1 -> 0
Starting network.
Hostname: netbsd.hachune.net
IPv6 mode: host
Configuring network interfaces: xennet0add net default: gateway 10.39.3.1
.
Adding interface aliases:.
Building databases: dev, utmp, utmpx.
Starting syslogd.
Mounting all filesystems...
Clearing temporary files.
Updating fontconfig cache: done.
Checking quotas: done.
Starting virecover.
Checking for core dump...
savecore: /dev/rxbd0b: Device not configured
May 16 09:56:46 netbsd savecore: /dev/rxbd0b: Device not configured
Starting local daemons:.
Updating motd.
Starting powerd.
Starting sshd.
Starting inetd.
Starting cron.
Wed May 16 09:56:53 JST 2012

NetBSD/amd64 (netbsd.hachune.net) (console)

login: miku
Password:
May 16 10:23:51 netbsd login: miku on tty console
Last login: Tue Apr 24 03:50:07 2012 on console
Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
    2006, 2007, 2008, 2009, 2010, 2011, 2012
    The NetBSD Foundation, Inc.  All rights reserved.
Copyright (c) 1982, 1986, 1989, 1991, 1993
    The Regents of the University of California.  All rights reserved.

NetBSD 6.0_BETA (HACHUNE_U) #0: Thu Apr 26 19:16:15 JST 2012

Welcome to NetBSD!

This system is running a beta release of the NetBSD operating system, aimed
at stabilizing the next formal release.  It is close to formal release quality,
but may still contain bugs, even serious ones.  Please bear this in mind and
use the system with care.

You are encouraged to test this version as thoroughly as possible.  Should you
encounter any problem, please report it back to the development team using the
send-pr(1) utility (requires a working MTA).  If yours is not properly set up,
use the web interface at: http://www.NetBSD.org/support/send-pr.html

Thank you for helping us test and improve this beta NetBSD release.

netbsd$

DOMUがNetBSDだからかInvalid kernelとか出ていたり、いろいろとエラーメッセージが出ているが、 とりあえず動いているので気にしないことにする。

Xen Documentation
http://xen.org/support/generated.html