NetBSD」カテゴリーアーカイブ

NetBSD 6.1.3 → 6.1.4

前回のアップデートと同じように更新。

と思ったら、build.sh install を実行すると etcupdate が自動的に実行されてた。前回はどうだったのかな。

$ sudo ./build.sh -O ../obj -T ../tools -U install=/
...
obsolete check:
        Remove obsolete file ///lib/libcrypto.so.8.0
        Remove obsolete link ///usr/lib/libcrypto.so.8.0
        Remove obsolete file ///usr/lib/libdes.so.8.1
        Remove obsolete file ///usr/lib/libssl.so.10.0
ptyfsoldnodes check:
postinstall checks passed: bluetooth ddbonpanic defaults dhcpcd envsys fontconfig gid gpio hosts iscsi makedev motd named pam periodic pf pwd_mkdb rc ssh wscons x11 xkb uid varrwho tcpdumpchroot atf catpages ptyfsoldnodes
postinstall checks failed: mtree obsolete
To fix, run:
    /bin/sh /u5/NetBSD/src/usr.sbin/postinstall/postinstall -s '/u5/NetBSD/src' -d // fix mtree obsolete
Note that this may overwrite local changes.
...

postinstall を手動で実行するところは前回と同じ。/home/NetBSD は /u5/NetBSD へのシンボリックリンクなので実パスが表示されている。

$ sudo /bin/sh /u5/NetBSD/src/usr.sbin/postinstall/postinstall -s '/u5/NetBSD/src' -d // fix mtree obsolete
Source directory: /u5/NetBSD/src
Target directory: //
mtree fix:
        Copied /tmp/_postinstall.7561.0/NetBSD.dist to ///etc/mtree/NetBSD.dist
obsolete fix:
        Removed obsolete file ///lib/libcrypto.so.8.0
        Removed obsolete link ///usr/lib/libcrypto.so.8.0
        Removed obsolete file ///usr/lib/libdes.so.8.1
        Removed obsolete file ///usr/lib/libssl.so.10.0
postinstall fixes passed: mtree obsolete
postinstall fixes failed:
$ 

起動ドライブ (NetBSD) の引っ越し その2

HDD の引越し作業はこんな手順で行おうと思っている。

  1. 新しい HDD を PC につなぐ。デバイスは wd2。
  2. fdisk(8) で MBR を初期化する。
  3. MBR にブートコードを書き込む
  4. disklabel(8) でパーティションを作成する。
  5. 各パーティションにファイルシステムを作成する。
  6. 古いシステムドライブの中身をコピーする。
  7. パーティションテーブルにブートコードを書き込む。

以下は作業の様子。

1. 新しい HDD を PC につなぐ

こんな感じで認識された。

wd2 at atabus1 drive 1
wd2: 
wd2: drive supports 16-sector PIO transfers, LBA48 addressing
wd2: 1863 GB, 3876021 cyl, 16 head, 63 sec, 512 bytes/sect x 3907029168 sectors
wd2: 32-bit data port
wd2: drive supports PIO mode 4, DMA mode 2, Ultra-DMA mode 6 (Ultra/133)

2. fdisk(8) で MBR を初期化する

$ sudo fdisk -u wd2
Disk: /dev/rwd2d
NetBSD disklabel disk geometry:
cylinders: 3876021, heads: 16, sectors/track: 63 (1008 sectors/cylinder)
total sectors: 3907029168

BIOS disk geometry:
cylinders: 1024, heads: 255, sectors/track: 63 (16065 sectors/cylinder)
total sectors: 3907029168

Partitions aligned to 16065 sector boundaries, offset 63

Do you want to change our idea of what BIOS thinks? [n] n

Partition table:
0: 
1: 
2: 
3: 
Bootselector disabled.
No active partition.
Which partition do you want to change?: [none] 0
The data for partition 0 is:

sysid: [0..255 default: 169]
start: [0..243201cyl default: 2048, 0cyl, 1MB]
size: [0..243201cyl default: 3907027120, 243201cyl, 1907728MB]
bootmenu: [] NetBSD

Partition table:
0: NetBSD (sysid 169)
    bootmenu: NetBSD
    start 2048, size 3907027120 (1907728 MB, Cyls 0-243201/80/63)
        PBR is not bootable: All bytes are identical (0x00)
1: 
2: 
3: 
Bootselector disabled.
No active partition.
Which partition do you want to change?: [none] 

Installed bootfile doesn't support required options.
Update the bootcode from /usr/mdec/mbr_bootsel? [n] y

We haven't written the MBR back to disk yet.  This is your last chance.
Partition table:
0: NetBSD (sysid 169)
    bootmenu: NetBSD
    start 2048, size 3907027120 (1907728 MB, Cyls 0-243201/80/63)
        PBR is not bootable: All bytes are identical (0x00)
1: 
2: 
3: 
Bootselector enabled, timeout 10 seconds.
No active partition.
Should we write new partition table? [n] y

ん、オフセットは 63 じゃなくて 2048 なのか。

よくわからんが、最近は 2048 がデフォルトということのようだ。

3. MBR にブートコードを書き込む

2 の途中で MBR に /usr/mdec/mbr_bootsel が書き込むかどうか訊かれてたのでもう必要ない。

fdisk(8) の man によれば、次のようにして mbr_bootsel を書き込めるようだ。

fdisk -c /usr/mdec/mbr_bootsel /dev/rwd0d

ここでアクティパーティションも設定しておこう。

$ sudo fdisk -a wd2
Disk: /dev/rwd2d
NetBSD disklabel disk geometry:
cylinders: 3876021, heads: 16, sectors/track: 63 (1008 sectors/cylinder)
total sectors: 3907029168

BIOS disk geometry:
cylinders: 1024, heads: 255, sectors/track: 63 (16065 sectors/cylinder)
total sectors: 3907029168

Partitions aligned to 16065 sector boundaries, offset 63

Partition table:
0: NetBSD (sysid 169)
    bootmenu: NetBSD
    start 2048, size 3907027120 (1907728 MB, Cyls 0/32/33-243201/80/63)
1: 
2: 
3: 
Bootselector enabled, timeout 10 seconds.
No active partition.
Do you want to change the active partition? [n] y
Choosing 4 will make no partition active.
active partition: [0..4 default: 4] 0
Are you happy with this choice? [n] y

We haven't written the MBR back to disk yet.  This is your last chance.
Should we write new partition table? [n] y
$

4. disklabel(8) でパーティションを作成する

disklabel(8) で BSD パーティションを作成する。

用語が錯綜してわかりにくいが、FDISK のパーティションの中に BSD のパーティション構造が入るという入れ子構造だ。以前 FreeBSD 界隈では FDISK パーティションを「スライス」と読んで区別していたが、BSD と直接関係ない FDISK 関連のドキュメントを読むときには FDISK の方も単に「パーティション」と呼ばれるわけなので、FDISK パーティションに別名をついけたところで混乱が収まるわけでもないと思う。

何はともあれ、2 で作成した FDISK パーティション 0 の中に、BSD パーティション構造を作成するということだ。BSD 界隈では、「ディスクラベル」を作成する、と呼ばれる。この言い回しもわかりにくいような気がする。用いるツールは disklabel(8)。

$ sudo disklabel -i wd2
Enter '?' for help
partition> E
# /dev/rwd2d:
type: ESDI
disk: WDC WD20EFRX-68E
label: fictitious
flags:
bytes/sector: 512
sectors/track: 63
tracks/cylinder: 16
sectors/cylinder: 1008
cylinders: 3876021
total sectors: 3907029168
rpm: 3600
interleave: 1
trackskew: 0
cylinderskew: 0
headswitch: 0           # microseconds
track-to-track seek: 0  # microseconds
drivedata: 0

5 partitions:
#        size    offset     fstype [fsize bsize cpg/sgs]
 c: 3907027120      2048     unused      0     0        # (Cyl.      2*- 3876020)
 d: 3907029168         0     unused      0     0        # (Cyl.      0 - 3876020)
 e: 3907027120      2048     4.2BSD      0     0     0  # (Cyl.      2*- 3876020)
partition> a
Filesystem type [?] [unused]: 4.2bsd
Start offset ('x' to start after partition 'x') [0c, 0s, 0M]: 2048
Partition size ('$' for all remaining) [0c, 0s, 0M]: 4126720
 a:   4126720      2048     4.2BSD      0     0     0  # (Cyl.      2*-   4095)
partition> b
Filesystem type [?] [unused]: swap
Start offset ('x' to start after partition 'x') [0c, 0s, 0M]: a
Partition size ('$' for all remaining) [0c, 0s, 0M]: 16384c
 b:  16515072   4128768       swap                     # (Cyl.   4096 -  20479)
partition> e
Filesystem type [?] [unused]: 4.2bsd
Start offset ('x' to start after partition 'x') [0c, 0s, 0M]: b
Partition size ('$' for all remaining) [0c, 0s, 0M]: 32768c
 e:  33030144  20643840     4.2BSD      0     0     0  # (Cyl.  20480 -  53247)
partition> f
Filesystem type [?] [unused]: 4.2bsd
Start offset ('x' to start after partition 'x') [0c, 0s, 0M]: e
Partition size ('$' for all remaining) [0c, 0s, 0M]: 16384c
 f:  16515072  53673984     4.2BSD      0     0     0  # (Cyl.  53248 -  69631)
partition> g
Filesystem type [?] [unused]: 4.2bsd
Start offset ('x' to start after partition 'x') [0c, 0s, 0M]: f
Partition size ('$' for all remaining) [0c, 0s, 0M]: 16384c
 g:  16515072  70189056     4.2BSD      0     0     0  # (Cyl.  69632 -  86015)
partition> h
Filesystem type [?] [unused]: 4.2bsd
Start offset ('x' to start after partition 'x') [0c, 0s, 0M]: g
Partition size ('$' for all remaining) [0c, 0s, 0M]: 32768c
 h:  33030144  86704128     4.2BSD      0     0     0  # (Cyl.  86016 - 118783)
partition> i
Filesystem type [?] [unused]: 4.2bsd
Start offset ('x' to start after partition 'x') [0c, 0s, 0M]: h
Partition size ('$' for all remaining) [0c, 0s, 0M]: 786432c
 i: 792723456 119734272     4.2BSD      0     0     0  # (Cyl. 118784 - 905215)
partition> j
Filesystem type [?] [unused]: 4.2bsd
Start offset ('x' to start after partition 'x') [0c, 0s, 0M]: i
Partition size ('$' for all remaining) [0c, 0s, 0M]: 131072c
 j: 132120576 912457728     4.2BSD      0     0     0  # (Cyl. 905216 - 1036287)
partition> k
Filesystem type [?] [unused]: 4.2bsd
Start offset ('x' to start after partition 'x') [0c, 0s, 0M]: j
Partition size ('$' for all remaining) [0c, 0s, 0M]: $
 k: 2862450864 1044578304     4.2BSD      0     0     0  # (Cyl. 1036288 - 3876020)
partition> P
11 partitions:
#        size    offset     fstype [fsize bsize cpg/sgs]
 a:   4126720      2048     4.2BSD      0     0     0  # (Cyl.      2*-   4095)
 b:  16515072   4128768       swap                     # (Cyl.   4096 -  20479)
 c: 3907027120      2048     unused      0     0        # (Cyl.      2*- 3876020)
 d: 3907029168         0     unused      0     0        # (Cyl.      0 - 3876020)
 e:  33030144  20643840     4.2BSD      0     0     0  # (Cyl.  20480 -  53247)
 f:  16515072  53673984     4.2BSD      0     0     0  # (Cyl.  53248 -  69631)
 g:  16515072  70189056     4.2BSD      0     0     0  # (Cyl.  69632 -  86015)
 h:  33030144  86704128     4.2BSD      0     0     0  # (Cyl.  86016 - 118783)
 i: 792723456 119734272     4.2BSD      0     0     0  # (Cyl. 118784 - 905215)
 j: 132120576 912457728     4.2BSD      0     0     0  # (Cyl. 905216 - 1036287)
 k: 2862450864 1044578304     4.2BSD      0     0     0  # (Cyl. 1036288 - 3876020)
partition> W
Label disk [n]? y
Label written
partition> Q

5. 各パーティションにファイルシステムを作成する

newfs(8) に -O2 をつけてファイルシステムを作成する。-O2 は FFSv2 を指定するオプション。

newfs -O2 /dev/rwd2a

容量が大きいので時間がかかるかと覚悟していたのだがずいぶん早く終わった。FFSv2 だから?

6. 古いシステムドライブの中身をコピーする

$ sudo mount /dev/wd2a /mnt
$ cd /mnt
$ sudo dump -0 -a -f - /  | sudo restore -rf -

7. パーティションテーブルにブートコードを書き込む

あらかじめ dumpfs でファイルシステムの形式を確認しておく。

$ sudo dumpfs /dev/rwd2a
file system: /dev/rwd2a
format  FFSv2
...

セカンダリブートストラップコード /usr/mdec/boot を /boot (今は /mnt にマウントしてるので /mnt/boot)にコピーする。

$ sudo cp /usr/mdec/boot /mnt/boot

プライマリブートストラップコード /usr/mdec/bootxx_ffsv2 (ファイルシステムが FFSv2 の場合) を installboot(8) を使って書き込む。

$ sudo installboot -v /dev/rwd2a /usr/mdec/bootxx_ffsv2
File system:         /dev/rwd2a
Primary bootstrap:   /usr/mdec/bootxx_ffsv2
Ignoring PBR with invalid magic in sector 0 of `/dev/rwd2a'
Boot options:        timeout 5, flags 0, speed 9600, ioaddr 0, console pc

初めて実行すると “Ignoring PBR with invalid magic …” のメッセージが出るが、2回目以降では出ない。

起動ドライブ (NetBSD) の引っ越し その1

NetBSD の HDD がエラーを出すようになった。

/netbsd: wd0i: error reading fsbn 745561088 of 745561088-745561103 (wd0 bn 1102082687; cn 1093335 tn 15 sn 62), retrying
/netbsd: wd0: (aborted command)
/netbsd: ahcisata0 port 0: device present, speed: 3.0Gb/s
/netbsd: wd0i: error reading fsbn 745561088 of 745561088-745561103 (wd0 bn 1102082687; cn 1093335 tn 15 sn 62), retrying
/netbsd: wd0: (aborted command)
/netbsd: ahcisata0 port 0: device present, speed: 3.0Gb/s
/netbsd: wd0: soft error (corrected)

atactl wd0 smart status でステータスを見るとこんな感じ。数字を見ても危ないのかどうかよくわからないのだけれど、wd1 の方はエラー吐かないので、良くはなさそう。

SMART supported, SMART enabled
id value thresh crit collect reliability description                    raw
  1 200   51     yes online  positive    Raw read error rate            0
  3 195   21     yes online  positive    Spin-up time                   1208
  4 100    0     no  online  positive    Start/stop count               101
  5 200  140     yes online  positive    Reallocated sector count       0
  7 200    0     no  online  positive    Seek error rate                0
  9  93    0     no  online  positive    Power-on hours count           5479
 10 100   51     no  online  positive    Spin retry count               0
 11 100    0     no  online  positive    Calibration retry count        0
 12 100    0     no  online  positive    Device power cycle count       33
192 200    0     no  online  positive    Power-off retract count        67
193  24    0     no  online  positive    Load cycle count               528673
194 119    0     no  online  positive    Temperature                    28
196 200    0     no  online  positive    Reallocated event count        0
197 200    0     no  online  positive    Current pending sector         1
198 100    0     no  offline positive    Offline uncorrectable          0
199 200    0     no  online  positive    Ultra DMA CRC error count      344
200 100   51     no  offline positive    Write error rate               0

ということで、交換用の HDD を購入した。

製品は Western Digital の赤、WD20EFRX (3.5-inch 2TB SATA 6Gb/s 64MB Cache) 。ちなみに wd0 は 2010年に購入 したもので Western Digital WD6400BEVT (2.5-inch 640GB SATA 3Gb/s 8MB Cache 5400RPM)。

もともとサーバに 2.5-inch 入れてたのは省電力を意図していたんだけれど、WD Red の 3.5-inch もなかなかの省電力ということで今回は 3.5-inch にした。

消費電力を比較すると次の通り(WD のスペックシートより)。左から、WD6400BEVT が交換予定の 2.5-inch、WD10EADS が 3.5-inch のデータ用ドライブ (1TB)、WD20WFRX が新しく買った 3.5-inch ドライブだ。

WD6400BEVT WD10EADS WD20WFRX
Read/Write (W) 1.6 5.4 4.1
Idle (W) 0.65 2.8 3.0
Standby/Sleep (W) 0.20 0.4 0.4

2.5-inch には及ばないものの、WD20WFRX は読み書き時 4.1W、アイドル時で 3.0W と、ずいぶん優秀だ。しかし、こうして並べてみると WD10EADS もなかなかいい線いってる。

Dovecot, imapsync の更新

Dovecot 2.2.9, imapsync 1.564 の組合せにしたらエラーが出て接続できなくなった。

Error: user xxx: Initialization failed: namespace configuration error: There can be only one namespace with inbox=yes
Error: Invalid user settings. Refer to server log for more information.

/usr/pkg/etc/dovecot/local.conf にはこう書いてある。

# 略
namespace {
  separator = .
  prefix = INBOX.
  inbox = yes
}

こう修正したら、エラーは出なくなった。

# 略
namespace inbox {
# 略

あと、以前は imapsync の namespace 周りにバグがあって、オプションの –prefix2 と –sep2 で明示的に指定してやる必要があったのだけれど、今見たら必要なくなったみたい。

NetBSD 6.1.3

NetBSD 5.1.2 から 6.1.3 へのアップデート。

$ cd /home/NetBSD/src
$ cvs update -PdAC -r netbsd-6-1-3-RELEASE
$ rm -rf ../obj ../tools
$ ./build.sh -O ../obj -T ../tools -j 8 tools
$ ./build.sh -O ../obj -T ../tools -j 8 kernel=GENERIC
$ ./build.sh -O ../obj -T ../tools -j 8 -U distribution

$ sudo rm -f /onetbsd
$ sudo ln /netbsd /onetbsd
$ sudo cp /home/NetBSD/obj/sys/arch/i386/compile/GENERIC/netbsd /nnetbsd
$ sudo mv /nnetbsd /netbsd
$ sudo shutdown -r now

$ cd /home/NetBSD/src
$ sudo ./build.sh -O ../obj -T ../tools -U install=/
$ sudo /usr/sbin/etcupdate -s /home/NetBSD/src

postinstall checks passed: bluetooth ddbonpanic defaults dhcpcd envsys fontconfig gid gpio hosts iscsi makedev motd named pam periodic pf ssh wscons x11 xkb uid varrwho tcpdumpchroot atf
postinstall checks failed: mtree pwd_mkdb rc catpages obsolete ptyfsoldnodes
To fix, run:
sh /usr/sbin/postinstall -s ‘/home/NetBSD/src’ -d / fix mtree pwd_mkdb rc catpages obsolete ptyfsoldnodes
Note that this may overwrite local changes.
*** All done
$ sudo /usr/sbin/postinstall -s ‘/home/NetBSD/src’ -d / fix mtree pwd_mkdb rc catpages obsolete ptyfsoldnodes
$

postinstall fixes passed: mtree pwd_mkdb rc catpages obsolete ptyfsoldnodes
postinstall fixes failed:
$ sudo shutdown -r now

CPU: Intel Core i3 530 (2.933GHz)、Memory: 2GB での実行時間。

$ time ./build.sh -O ../obj -T ../tools -j 8 tools
real 6m37.895s
user 10m33.438s
sys 1m22.799s
$ time ./build.sh -O ../obj -T ../tools -j 8 kernel=GENERIC
real 3m14.105s
user 9m10.315s
sys 0m53.143s
$ time ./build.sh -O ../obj -T ../tools -j 8 -U distribution
real 42m3.439s
user 104m30.964s
sys 15m15.407s

参考

ASTEC-X の日本語入力

ASTEC-X 8.0 で Windows の IME 使って日本語入力するための設定。IME は Google 日本語入力を使用。ASTEC-X のコントロールパネルの「日本語入力」で XIM プロトコルは有効にしておく。

Emacs24 なら環境変数 LANG と XMODIFIERS を設定する。XMODIFIERS に何を設定するのだったかをよく忘れる。正解は @im=ASTEC_IMS 。LANG は ja_JP.eucJP とかでも可。

export LANG=ja_JP.UTF-8
export XMODIFIERS=@im=ASTEC_IMS
emacs

gedit なら、上記に加えて GTK_IM_MODULE の設定が必要。

export LANG=ja_JP.UTF-8
export XMODIFIERS=@im=ASTEC_IMS
export GTK_IM_MODULE=xim
gedit

a2ps-j

a2ps-j が古くて、pkgsrc からインストールしたのは perl-5.16.2 では動かない模様。

パッチがあった。ただし若干修正が必要。
http://ftp.cc.uoc.gr/mirrors/macports/release/ports/print/a2ps-j/files/patch-a2ps-j.diff

上記の URL からパッチをダウンロードし、/etc/mk.conf の LOCALPATCHES で指定したディレクトリに置く。

LOCALPATCHES=/anywhere/localpatches なら、
/anywhere/localpatches/print/a2ps-j/patch-a2ps-j.diff
となる。

パッチがあたっているファイル名が異なるので、修正する。

元のパッチで

--- a2ps-j.orig	2012-02-23 15:04:21.000000000 +0900
+++ a2ps-j	2012-10-02 01:58:37.000000000 +0900
@@ -1,4 +1,4 @@
-#!/usr/local/bin/perl
+#!/usr/bin/env perl
 ;#

となっているのを

--- a2ps.pl-1.45.orig   2012-02-23 15:04:21.000000000 +0900
+++ a2ps.pl-1.45        2012-10-02 01:58:37.000000000 +0900
@@ -1,4 +1,4 @@
-#!/usr/local/bin/perl
+#!/usr/bin/env perl
 ;#

のようにする。

a2ps-j の出力は PostSccript なので、PDF 変換のために ghostscript をインストールする。

pkgsrc/print/ghostscript をインスト-ル。日本語フォントを入れるときに文句を言われるので、予め /etc/mk.conf に下のオプションを指定してコンパイルする。

PKG_OPTIONS.ghostscript+=disable-compile-inits

日本語フォントとして、
pkgsrc/font/ghostscript-cidfonts-ryumin
をインストールする。フォントが複数あって、インストール時のオプションで排他的に指定するようになっている。

IPAフォントを使うのが良さそう。
PKG_OPTIONS.gcr_type+=ipa

ソースコードの印刷

コメントに日本語を含むソースコード(Fortran95)を印刷するのに良い、そして手軽なツールはないかと模索してみた。

コーディングは NetBSD 上で作成してるが、印刷環境は Windows にあるので、どっちでもいいが、とにかく手軽のものを希望。

スプリント
http://www.vector.co.jp/soft/win95/writing/se252056.html

おおむね問題ないが、一点だけ不満。

UTF-8のテキストでバックスラッシュが含まれる場合に全角で印刷されてしまう。半角のバックスラッシュか、半角の円マークで印刷して欲しいところ。

保留。

paps-0.6.8
http://lfsbookja.sourceforge.jp/BLFS/svn.ja/pst/paps.html

日本語も処理できるような記述はあるのだが、何も考えないで NetBSD の pkgsrc からインストールして実行したら日本語は表示されなかった。エラーは特に出ていない。

フォントの問題かもしれないが、ドキュメントが少なくてよくわからない。

却下。

gnome-u2ps
http://www.gnome.gr.jp/~nakai/u2ps/

pkgsrc に含まれていないようなので、見送り。gnome 関連を個別に入れるというのは敷居が高すぎる。gnome がアップデートしたときにどうなるのかよくわからないので。

却下。

u2ps (perlで記述されている)
http://u2ps.berlios.de/

こちらも pkgsrc には含まれていないが、perl ならなんとかなるかな。

と思ったらだめだった。パスとか埋め込みだったりでいろいろと手を入れないと動かなそう。

完成度がイマイチなので却下。

a2ps-j + iconv

昔なつかし a2ps-j。UTF-8 を処理できないので iconv による前処理で EUC-JP に変換する必要がある。

安定度は問題なし。バックスラッシュもちゃんとバックスラッシュとして印刷される。

iconv を通すところがちょっと面倒だけど、これが一番実用的かな?

OpenLDAPでユーザ管理 (12)

amd (am-utils) のマップを LDAP で管理する。これができないと NIS から移行できない。以前は確か NetBSD 付属の am-utils は LDAP に対応していなかったように記憶しているが、NetBSD 5.0 のアナウンス によれば、5.0 から対応していたようだ。

NetBSD のソースツリーにある、src/external/bsd/am-utils/dist/ldap.schema を /usr/pkg/etc/openldap/schema/am-utils.schema にコピーする。

LDAP サーバの /usr/pkg/etc/openldap/slapd.conf に include /usr/pkg/etc/openldap/schema/am-utils.schema を追加して再起動する。

LDAP Admin に am-utils.schema を読ませる方法がわからなかったので、下の LDIF を手書きして ldapadd で登録した。その状態で LDAP Admin で接続すると以後は LDAP Admin で am-utils.schema 内で定義された ObjectClass を扱えるようになった。

dn: cn=amdmap amd.home timestamp,ou=Amd Map,dc=example,dc=co,dc=jp
objectClass: amdmapTimestamp
cn: amdmap timestamp
amdmapTimestamp: 1365580086
amdmapName: amd.home

dn: cn=amdmap amd.home[/defaults],ou=Amd Map,dc=example,dc=co,dc=jp
objectClass: amdmap
cn: amdmap amd.home[/defaults]
amdmapName: amd.home
amdmapKey: /defaults
amdmapValue: type:=nfs;sublink:=${key};opts:=rw,intr,nodev,nosuid,resvport,tcp

“ou=Amd Map,dc=example,dc=co,dc=jp” は事前に作成しておいた organizationUnit。単に整理のために作成しただけで必須ではない。名前も任意。

am-utils では、タイムスタンプ (amdmapTimestamp) とマップ (amdmap) の2種類の Object Class を使用する。

cn の形式は src/external/bsd/am-utils/dist/scripts/amd2ldif.in に合わせた。am-utils で要求されているのかどうかはよくわからない。

amdTimestamp では “cn=amdmap $mapname timestamp” で、amdmap では “cn=amdmap $mapname[$key]” となる。ここで $mapname は、am-utils で指定するマップ名 (map_name) が、$key にはキー名が入る。この例では、amd.home というマップのタイムスタンプと、/defaults の設定をしたことになっている。

タイムスタンプの値は、perl -e ‘print time,”\n”‘ として得られる Epoch を入れた。

ここで LDAP Admin が使用できるようになるので、LDAP Admin を使って個々のエントリを作成する。

LDIF で記述すると以下の通り。

dn: cn=amdmap amd.home[alice]
objectClass: top
objectClass: amdmap
amdmapName: amd.home
amdmapKey: alice
amdmapValue:
  -rhost:=gemini;rfs:=/vol/home
  host==${rhost};type:=link;fs:=${fs}
  host!=${rhost}

amdmapValue の値は am-utils でのそれ。LDAP Admin では1行になるのでやや読みにくい。
ユーザ alice のホームディレクトリが、ファイルサーバ gemini の /vol/home/alice として置かれていて、gemini からは /home がエクスポートされている環境を想定している。gemini が同じマップを使用してマウントしようとした場合には、NFS ではなく、シンボリックリンクを作成する。

次、クライアント。

まず、/etc/amd.conf。

[global]
ldap_proto_version = 3
ldap_base = "ou=Amd Map,dc=example,dc=co,dc=jp"
ldap_hostports = aries.example.co.jp:389
restart_mounts = yes

[/home2]
map_type = ldap
map_name = amd.home

見ればだいたいわかると思う。要注意は ldap_proto_version=3 。デフォルトでは 2 なので忘れると接続できない。

あとは、/etc/rc.conf に NFS と amd に必要な設定をして、起動すれば接続できる。

OpenLDAPでユーザ管理 (11)

LDAP サーバに接続できない場合について。

クライアント側の /usr/pkg/etc/ldap.conf に “bind_policy soft” を設定する。

# Reconnect policy:
#  hard_open: reconnect to DSA with exponential backoff if
#             opening connection failed
#  hard_init: reconnect to DSA with exponential backoff if
#             initializing connection failed
#  hard:      alias for hard_open
#  soft:      return immediately on server failure
bind_policy soft

これで、LDAP サーバが起動していないとかの場合には、接続を待たないですぐにエラーが返ってきて、ローカルユーザではログインできるようになる。

pam_ldap の ignore_unknown_user とか ignore_authinfo_unavail オプションはいらないのかな? なくても大丈夫そうだったけど。