2011年4月13日水曜日

PIL で bin2png

ちょっと驚き... こちら blogger 然りでバイナリデータをブログに載せたい時って
どうすれば良いやら。長いテキストとかであれば a2ps | enscript で PostScript
にした後 ps2pdf とか。で PDF がアップロードできるか知らないし、やっぱイメー
ジデータでしょう。

と探すもステガノグラフィ (outguess steghide snowdrop) まで凝った話でもなく、
サイズも大きくなるし a2png だって? と試すもそのまま a2ps の png 版だったり。
sourceforge にあるも Java だったり...

むーん libpng とか使って自作? とか思い始めたところ # 長い前置き
Python Imaging Library (PIL) のハンドブック眺めてみたところ、ソレらしきメソ
ッドが。でお試し
$ python
Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> fname = "patch-2.6.38.2.gz"
>>> import os
>>> os.stat(fname).st_size
52847
>>> f = open(fname)
>>> b = bytearray()
>>> b.extend(f.read())
>>> len(b)
52847
>>> import Image
>>> im = Image.new('L', (52847, 1))
>>> im.putdata(b)
>>> im.save("2.6.38.2.png")
>>> (Ctrl-D)
$ ls -l 2.6.38.2.png 
-rw-r--r-- 1 chamaken chamaken 52921 2011-04-12 23:35 2.6.38.2.png
PNG フォーマットとか全く知らないので new() のモードわからないし、最大約数を
探すのも面倒がってサイズもおかしいど、もちろん可逆で
$ python
Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import Image
>>> im = Image.open("2.6.38.2.png")
>>> f = open("write.back", 'wb')
>>> f.write(bytearray(im.getdata()))
>>> f.close()
>>> (Ctrl-d)
$ cmp patch-2.6.38.2.gz write.back 
$ 
おどろいた。この 2.6.38.2.png を貼ると大変なことになりそうなので超てきとー
いいかげんにパディングしたものを貼ってみるテスト

2011年4月7日木曜日

obs600 で 再度 debian squeeze - その 3 - で一段落

お待ちかね。OBS600 側
  • CF 積んで
  • ETHER-0 に UTP ケーブル接続して
  • INIT ボタンをボールペンで押さえて
電源投入。ちなみに手元にあるのは 8G の CF。root でログインした後
  1. パーティション分割 & ファイルシステム作成
  2. 8G を 6G / 2G に分割。冗長だけど全部
    # fdisk /dev/sda
    
    Command (m for help): p
    
    Disk /dev/sda: 8019 MB, 8019099648 bytes
    247 heads, 62 sectors/track, 1022 cylinders
    Units = cylinders of 15314 * 512 = 7840768 bytes
    
       Device Boot      Start         End      Blocks   Id  System
    
    Command (m for help): n
    Command action
       e   extended
       p   primary partition (1-4)
    p
    Partition number (1-4): 1
    First cylinder (1-1022, default 1):
    Using default value 1
    Last cylinder or +size or +sizeM or +sizeK (1-1022, default 1022): +6144M
    
    
    Command (m for help): n
    Command action
       e   extended
       p   primary partition (1-4)
    p
    Partition number (1-4): 2
    First cylinder (786-1022, default 786):
    Using default value 786
    Last cylinder or +size or +sizeM or +sizeK (786-1022, default 1022):
    Using default value 1022
    
    Command (m for help): p
    
    Disk /dev/sda: 8019 MB, 8019099648 bytes
    247 heads, 62 sectors/track, 1022 cylinders
    Units = cylinders of 15314 * 512 = 7840768 bytes
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1               1         785     6010714   83  Linux
    /dev/sda2             786        1022     1814709   83  Linux
    
    Command (m for help): w
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    sd 0:0:0:0: [sda] 15662304 512-byte hardware sectors: (8.01 GB/7.46 GiB)
    sd 0:0:0:0: [sda] Write Protect is off
    sd 0:0:0:0: [sda] Assuming drive cache: write through
     sda: sda1 sda2
    sd 0:0:0:0: [sda] 15662304 512-byte hardware sectors: (8.01 GB/7.46 GiB)
    sd 0:0:0:0: [sda] Write Protect is off
    sd 0:0:0:0: [sda] Assuming drive cache: write through
     sda: sda1 sda2
    Syncing disks.
    # mke2fs -j -b 4096 -L / /dev/sda1
    mke2fs 1.39 (29-May-2006)
    Filesystem label=/
    OS type: Linux
    Block size=4096 (log=2)
    Fragment size=4096 (log=2)
    752192 inodes, 1502678 blocks
    75133 blocks (5.00%) reserved for the super user
    First data block=0
    46 block groups
    32768 blocks per group, 32768 fragments per group
    16352 inodes per group
    Superblock backups stored on blocks:
            32768, 98304, 163840, 229376, 294912, 819200, 884736
    
    Writing inode tables: done
    Creating journal (32768 blocks): done
    Writing superblocks and filesystem accounting information: done
    
    This filesystem will be automatically checked every 28 mounts or
    180 days, whichever comes first.  Use tune2fs -c or -i to override.
    
  3. マウント & ファイル取得準備
  4. # mount /dev/sda1 /mnt
    kjournald starting.  Commit interval 5 seconds
    EXT3 FS on sda1, internal journal
    EXT3-fs: mounted filesystem with ordered data mode.
    # ip link ls eth0
    2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast
    state UP qlen 1000
        link/ether 00:1a:88:0c3:12:bb brd ff:ff:ff:ff:ff:ff
        inet 192.168.253.254/24 brd 192.168.253.255 scope global eth0
    
    # ping -c 4 192.168.253.1
    PING 192.168.253.1 (192.168.253.1): 56 octets data
    64 octets from 192.168.253.1: icmp_seq=0 ttl=64 time=2.2 ms
    64 octets from 192.168.253.1: icmp_seq=1 ttl=64 time=0.3 ms
    64 octets from 192.168.253.1: icmp_seq=2 ttl=64 time=0.3 ms
    64 octets from 192.168.253.1: icmp_seq=3 ttl=64 time=0.3 ms
    
    --- 192.168.253.1 ping statistics ---
    4 packets transmitted, 4 packets received, 0% packet loss
    round-trip min/avg/max = 0.3/0.7/2.2 ms
    
  5. 開発機側のファイルツリーをごっそり取得
  6. (長いコマンドライン)
    # ssh chamaken@192.168.253.1 \
    > "cd ~/obs600/rootfs && tar -cp --numeric-owner -f - *" \
    > | tar -xpv --numeric-owner -f - -C /mnt
    The authenticity of host '192.168.253.1 (192.168.253.1)' can't be established.
    RSA key fingerprint is d1:72:98:8b:42:11:e6:a6:7b:c8:6f:8b:95:ba:a3:a8.
    Are you sure you want to continue connecting (yes/no)? yes
    Warning: Permanently added '192.168.253.1' (RSA) to the list of known hosts.
    Password:
    ...
    var/cache/debconf/
    var/spool/
    
  7. チルっと
  8. # chroot /mnt
    I have no name!@ssd-linux:/# ls -1
    bin
    boot
    debootstrap
    dev
    etc
    home
    lib
    lib64
    lost+found
    mnt
    proc
    sbin
    selinux
    sys
    tmp
    usr
    var
    I have no name!@ssd-linux:/# cd /debootstrap
    I have no name!@ssd-linux:/debootstrap# ./debootstrap --second-stage
    I: Installing core packages...
    ...
    I: Base system installed successfully.
    I have no name!@ssd-linux:/debootstrap#
    
  9. /uImage.initrd-cfboot の作成
  10. I have no name!@ssd-linux:/debootstrap# cd
    I have no name!@ssd-linux:~# ls -1
    linux-image-2.6.32_0.91_powerpc.deb
    obs600.dtb
    vmlinux.bin.gz
    
    いろいろ叱られるし、長いけど
    I have no name!@ssd-linux:~# dpkg -i linux-image-2.6.32_0.91_powerpc.deb
    Selecting previously deselected package linux-image-2.6.32.
    (Reading database ... 9174 files and directories currently installed.)
    Unpacking linux-image-2.6.32 (from linux-image-2.6.32_0.91_powerpc.deb) ...
    Done.
    Setting up linux-image-2.6.32 (0.91) ...
    
     Hmm. There is a symbolic link /lib/modules/2.6.32/build
     However, I can not read it: No such file or directory
     Therefore, I am deleting /lib/modules/2.6.32/build
    
    
     Hmm. The package shipped with a symbolic link /lib/modules/2.6.32/source
     However, I can not read the target: No such file or directory
     Therefore, I am deleting /lib/modules/2.6.32/source
    
    Running depmod.
    Examining /etc/kernel/postinst.d.
    run-parts: executing /etc/kernel/postinst.d/initramfs-tools 2.6.32
    /boot/vmlinux-2.6.32
    update-initramfs: Generating /boot/initrd.img-2.6.32
    df: Warning: cannot read table of mounted file systems: No such file
    or directory
    warning: can't open /etc/mtab: No such file or directory
    warning: can't open /etc/mtab: No such file or directory
    I have no name!@ssd-linux:~#
    
    また長いコマンドライン。くどいけど参照
    • $SSDSRC/usr/src/contrib/debootstrap/post-debootstrap
    • $SSDSRC/usr/src/contrib/developers/kimura/lenny_based_firmware/uimage/create_uImage.sh
    I have no name!@ssd-linux:~# mkimage -n "original.$(date +'%FT%T')" \
    > -A ppc -O linux -T multi -C gzip \
    > -d vmlinux.bin.gz:/boot/initrd.img-2.6.32:obs600.dtb \
    > /uImage.initrd-cfboot
    Image Name:   original.2011-04-01T12:34:56
    Created:      Tue Apr  1 12:34:56 2011
    Image Type:   PowerPC Linux Multi-File Image (gzip compressed)
    Data Size:    3847277 Bytes = 3757.11 kB = 3.67 MB
    Load Address: 00000000
    Entry Point:  00000000
    Contents:
       Image 0: 1925764 Bytes = 1880.63 kB = 1.84 MB
       Image 1: 1913443 Bytes = 1868.60 kB = 1.82 MB
       Image 2: 8053 Bytes = 7.86 kB = 0.01 MB
    I have no name!@ssd-linux:~#
    
  11. 普通の? 必須修正
  12. I have no name!@ssd-linux:~# passwd
    Enter new UNIX password:
    Retype new UNIX password:
    passwd: password updated successfully
    I have no name!@ssd-linux:~# cd /etc
    I have no name!@ssd-linux:/etc# cp inittab inittab.dpkg-dist
    I have no name!@ssd-linux:/etc# vi inittab
    ...
    I have no name!@ssd-linux:/etc# diff -uw inittab.dpkg-dist inittab
    --- inittab.dpkg-dist   2011-03-31 12:34:56.000000000 +0000
    +++ inittab     2011-03-31 12:34:56.000000000 +0000
    @@ -51,16 +51,16 @@
     # Note that on most Debian systems tty7 is used by the X Window System,
     # so if you want to add more getty's go ahead but skip tty7 if you run X.
     #
    -1:2345:respawn:/sbin/getty 38400 tty1
    -2:23:respawn:/sbin/getty 38400 tty2
    -3:23:respawn:/sbin/getty 38400 tty3
    -4:23:respawn:/sbin/getty 38400 tty4
    -5:23:respawn:/sbin/getty 38400 tty5
    -6:23:respawn:/sbin/getty 38400 tty6
    +# 1:2345:respawn:/sbin/getty 38400 tty1
    +# 2:23:respawn:/sbin/getty 38400 tty2
    +# 3:23:respawn:/sbin/getty 38400 tty3
    +# 4:23:respawn:/sbin/getty 38400 tty4
    +# 5:23:respawn:/sbin/getty 38400 tty5
    +# 6:23:respawn:/sbin/getty 38400 tty6
    
     # Example how to put a getty on a serial line (for a terminal)
     #
    -#T0:23:respawn:/sbin/getty -L ttyS0 9600 vt100
    +T0:23:respawn:/sbin/getty -L ttyS0 115200 vt100
     #T1:23:respawn:/sbin/getty -L ttyS1 9600 vt100
    
     # Example how to put a getty on a modem line.
    I have no name!@ssd-linux:/etc#
    
    そのほか /etc/hostname/etc/network/interfaces など
    必要に応じて作成、変更 - in debian's way で

  13. オリジナルツールのコピー
  14. 後でやっつけパッケージ作るけど、とり急ぎ
    I have no name!@ssd-linux:/etc# exit
    # cd /usr/sbin
    # cp flashcfg runled pshd /mnt/usr/sbin/
    
  15. CF ブートとしてリブート
  16. # flashcfg -h
    usage: flashcfg                 Show this.
           flashcfg -b              Show current boot setting
           flashcfg -c rootdev      Change root file system [initrd|cf|sda-sdd[1-8]]
                                    initrd       - Boot from FlashROM, / on Ramdisk
                                    sda-sdd[1-8] - Boot from FlashROM, / on CF
                                    cf           - Boot from CF,       / on CF
           flashcfg -f boot_image   Load boot image to flash
           flashcfg -s list_file    Save files to Parameter area
           flashcfg -S list_file    Save files to User area
           flashcfg -x              Restore files from Parameter area
           flashcfg -X              Restore files from User area
           flashcfg -d              Delete saved files from Parameter area
           flashcfg -D              Delete saved files from User area
           flashcfg -E env_file     Save params to U-Boot Environment area
           flashcfg -L env_file     Load params from U-Boot Environment area
           flashcfg -h              Show this.
    # flashcfg -c cf
    # shutdown -r now
    
でけた?

2011年4月6日水曜日

obs600 で 再度 debian squeeze - その 2

また引用。
OpenBlockS 600D - 開発環境の構築
クロス開発 (VMware等のx86環境上での開発)
  1. ベースとなる環境の用意
  2. タイトル通り squeeze (amd64) で

  3. emdebian のリポジトリを追加します
  4. sources.list の準備
    /etc/apt/sources.list.d に以下 emdebian.list というファイルを追加
    # cat /etc/apt/sources.list.d/emdebian.list
    deb     http://www.emdebian.org/debian/ squeeze main
    deb-src http://www.emdebian.org/debian/ squeeze main
    
    アップデート
    $ sudo aptitude update
    
    キーリングを追加
    $ sudo aptitude install emdebian-archive-keyring
    
  5. 必要なパッケージを追加します
  6. $ sudo aptitude install \
    > build-essential u-boot libc6-powerpc-cross \
    > libc6-dev-powerpc-cross binutils-powerpc-linux-gnu gcc-4.4-powerpc-linux-gnu \
    > g++-4.4-powerpc-linux-gnu \
    > autoconf dpkg-cross linux-headers-2.6.32-5-common linux-source-2.6.32 \
    > kernel-package libncurses5-dev
    
    最後の二行は今後のモロモロのために

  7. カーネルのソースコードを展開します
  8. ありがたいことに SSDLinux のパッチもあるので上記通り linux-source-2.6.32 で。

  9. 開発用ディレクトリの作成と SSD/Linux のソース取得、展開
  10. テンポラリディレクトリ作成
    $ mkdir -p $HOME/obs600/tmp
    
    src.tgz の取得
    $ wget -nd -N -P $HOME/obs600/tmp \
    > http://ftp.plathome.co.jp/pub/ssdlinux/0.5-LATEST/source/src.tgz
    
    各種展開
    $ cd $HOME/obs600
    $ tar xzf tmp/src.tgz -C tmp
    $ tar xjf /usr/src/linux-source-2.6.32.tar.bz2 -C .
    
  11. カーネルパッケージ作成
  12. カーネルパッチあて
    SSD/Linux のソース usr/src/mkdist/kernel/2.6.32/patches/ に各種パッチあり
    $ cd linux-source-2.6.32
    $ for i in ../tmp/usr/src/mkdist/kernel/2.6.32/patches/*.patch; do
    > patch -p1 $i
    > done
    ...
    patching file Makefile
    Reversed (or previously applied) patch detected!  Assume -R? [n]
    Apply anyway? [n]
    (ここはエンター。デフォルトの n で OK)
    Skipping patch.
    4 out of 4 hunks ignored -- saving rejects to file Makefile.rej
    patching file scripts/Makefile.modinst
    
    ごめんなさい - scripts.patch
    +ifdef NOGZIP
           cmd_modules_install = mkdir -p $(2); cp $@ $(2) ;
    $(mod_strip_cmd) $(2)/$(notdir $@)
    +else
    +      cmd_modules_install = mkdir -p $(2); cp $@ $(2) ;
    $(mod_strip_cmd) $(2)/$(notdir $@) ;gzip -9 $(2)/$(notdir $@)
    +endif
    
    なので make 時に -D NOGZIP する

    .config などのコピー
    ワーキングディレクトリは $HOME/obs600/linux-source-2.6.32 のままで
    $ cp ../tmp/usr/src/mkdist/kernel/2.6.32/dot.config.powerpc-obs600 dot.config
    $ cp dot.config .config
    $ cp ../tmp/usr/src/mkdist/kernel/2.6.32/obs600.dts arch/powerpc/boot/dt
    $ cp ../tmp/usr/src/mkdist/kernel/2.6.32/obs600.dts arch/powerpc/boot/dts/
    
    menuconfig
    $ make-kpkg -j4 --arch powerpc --config menuconfig configure
    
    menuconfig はお好みで gconfig とか。DRBD 使ってみるので
    • Device Drivers ---> Connector を M に
    • Device Drivers ---> Block Devices ---> DRBD も M に
    その他お好みで。個人的には cgroup と namespace veth など。diff 取ると
    $ diff -uw dot.config .config
    +CONFIG_CONNECTOR=m
    +CONFIG_BLK_DEV_DRBD=m
    
    といったあたり。削除されてる
    -CONFIG_UNION_FS=y
    http://download.filesystems.org/unionfs/unionfs-2.x/
    あたりからパッチ持ってきてあてる必要あり。でも CF ブートなので割愛。

    kernel_image
    $ MAKEFLAGS="NOGZIP=1" make-kpkg -j4 --rootcmd=fakeroot --arch=powerpc \
    > --revision 0.91 --initrd kernel_image
    
  13. その他 uImage に必要なもの
  14. dtb
    参照:
    • $SSDSRC/usr/src/contrib/debootstrap/post-debootstrap
    • $SSDSRC/usr/src/contrib/developers/kimura/lenny_based_firmware/uimage/create_uImage.sh
    $ make ARCH=powerpc obs600.dtb
    /home/chamaken/obs600/linux-source-2.6.32/scripts/dtc/dtc -O dtb -o
    arch/powerpc/boot/obs600.dtb -b 0 -p 1024
    /home/chamaken/obs600/linux-source-2.6.32/arch/powerpc/boot/dts/obs600.dts
    DTC: dts->dtb  on file
    "/home/chamaken/obs600/linux-source-2.6.32/arch/powerpc/boot/dts/obs600.dts"
    $ cp arch/powerpc/boot/obs600.dtb ../
    
    vmlinux.bin.gz
    $ powerpc-linux-gnu-objcopy -O binary vmlinux ../vmlinux.bin
    $ cd ..
    $ gzip vmlinux.bin
    $ ls -1
    linux-image-2.6.32_0.91_powerpc.deb
    linux-source-2.6.32
    obs600.dtb
    tmp
    vmlinux.bin.gz
    
    すっごい長くなった上に番外。
    ここまでやっておくと次回 obs600 側になるので

  15. (何と言えばよいのか) 開発機側で OBS600 バイナリのファイルツリー準備
  16. include のパッケージは最低限。お好みで... drbb8-utils も
    $ su
    # debootstrap --foreign --arch=powerpc \
    > --include "ssh less u-boot initramfs-tools" \
    > squeeze rootfs http://ftp.jp.debian.org/debian
    I: Retrieving Release
    I: Retrieving Packages
    I: Validating Packages
    ...
    I: Extracting xz-utils...
    I: Extracting zlib1g...
    # ls -1
    linux-image-2.6.32_0.91_powerpc.deb
    linux-source-2.6.32
    obs600.dtb
    rootfs
    tmp
    vmlinux.bin.gz
    # cp linux-image-2.6.32_0.91_powerpc.deb obs600.dtb vmlinux.bin.gz rootfs/root/
    # chmod 0755 rootfs/root
    
    最後の chmod 忘れずに

2011年4月5日火曜日

obs600 で 再度 debian squeeze - その 1

まずはおかしくなった時の準備。tftp サーバを適当な debian マシンにインストールしておく
ファームウェアアップデートを実行したら起動しなくなりました。どうすれば復旧できますか。
からの引用

Q. ファームウェアアップデートを実行したら起動しなくなりました。どうすれば復旧できますか。
A. TFTP サーバを利用したファームウェアのアップデートを行うことで復旧できます。
  1. パッケージのインストール
  2. $ sudo apt-get install tftpd-hpa (ディレクトリはデフォルトの /srv/tftp)
    
    Starting HPA's tftpd: in.tftpdinvoke-rc.d: initscript tftpd-hpa,
    action "start" failed.
    dpkg: error processing tftpd-hpa (--configure):
     subprocess installed post-installation script returned error exit status 71
    configured to not write apport reports
                                          Errors were encountered while processing:
     tftpd-hpa
    E: Sub-process /usr/bin/dpkg returned an error code (1)
    IPv6 無効にしていると上記エラー。/var/log/daemon.log を眺めると
    Apr  5 21:06:29 devobs600 in.tftpd[16485]: cannot open IPv6 socket,
    disable IPv6: Address family not supported by protocol
    Apr  5 21:06:29 devobs600 in.tftpd[16485]: Cannot set nonblock flag on
    socket: Bad file descriptor
    なんて出力があるので /etc/default/tftpd-hpa を変更
    # diff -uw tftpd-hpa.dpkg-dist tftpd-hpa
    --- tftpd-hpa.dpkg-dist        2011-04-05 08:09:46.000000000 +0900
    +++ tftpd-hpa                  2011-04-05 08:09:56.000000000 +0900
    @@ -3,4 +3,4 @@
     TFTP_USERNAME="tftp"
     TFTP_DIRECTORY="/srv/tftp"
     TFTP_ADDRESS="0.0.0.0:69"
    -TFTP_OPTIONS="--secure"
    +TFTP_OPTIONS="--secure -4"
  3. ファームウェアをダウンロードしておき TFTP サーバ側で指定した場所におきます。
  4. TFTP サーバのディレクトリに置く
    $ su
    # wget -nd -N -P /srv/tftp \
    > http://ftp.plathome.co.jp/pub/OBS600/0.5-LATEST/powerpc-obs600/installation/uImage.initrd
  5. ETHER-0 と PC を添付のクロス・ケーブル (緑色) で接続します。
  6. アドレス追加。ハブやスイッチ介しても同じ L2 ドメインであればクロスケーブルじゃなくてもOK
    # ip addr ls eth0
    2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast
    state UP qlen 1000
        link/ether 00:ed:cb:a9:87:65 brd ff:ff:ff:ff:ff:ff
        inet 10.1.2.3/16 brd 10.1.255.255 scope global eth0
    # ip addr add 192.168.253.1/24 dev eth0
    # ip addr ls eth0
    2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast
    state UP qlen 1000
        link/ether 00:ed:cb:a9:87:65 brd ff:ff:ff:ff:ff:ff
        inet 10.1.2.3/16 brd 10.1.255.255 scope global eth0
        inet 192.168.253.1/24 scope global eth0
    
  7. 本体の ディップ・スイッチ 2 を ON にします。

  8. 電源を入れます。
  9. 待つことしばし

  10. ファームウェアのアップデートが完了しますと本体の緑色の LED が点滅します。

  11. 電源を抜き、ディップ・スイッチ 2 を OFF にします。

  12. 追記 - INIT ボタンを押しながら電源を入れる
  13. いや、CF 起動でおかしな状態にして数日放置。で tftp ブートでイメージ読み込んだ後、度々忘れるので...

2011年3月30日水曜日

softdog / CONFIG_WATCHDOG_NOWAYOUT

いつも唐突。
Documentation/watchdog/src/watchdog-simple.c の抜粋
int fd = open("/dev/watchdog", O_WRONLY);
while (1) {
ret = write(fd, "\0", 1);
if (ret != 1) {
ret = -1;
break;
}
ret = fsync(fd);
if (ret)
break;
sleep(10);
}
close(fd);
定期的に書き込みがあればカーネルが大丈夫、問題ないよ。と判断。書き込みがないと...リブート。じゃクローズは? が次

Documentation/watchdog/watchdog-api.txt の抜粋意訳

モジュールパラメタ nowayout (CONFIG_WATCHDOG_NOWAYOUT)
"Magic Close" がサポートされていなければデバイスを close すると watchdog も (何もせず) 終了。watchdog デーモンにバグがあってクラッシュした場合なんか考えるとちょっとマズい。この挙動のためいくつかのドライバでは "Disable watchdog shutdown on close", CONFIG_WATCHDOG_NOWAYOUT
というオプション設定ができる。これを Y としてコンパイルすると一度 watchdog が開始した後に watchdog を無効にする方法がなくなる。つまりは watchdog デーモンがクラッシュするとシステムが指定のタイムアウト後にリブートする

Magic Close
ドライバが Magic Close をサポートしていると close 直前に特定の文字 'V' が /dev/watchdog に送られないと (書き込まれないと) watchdog が無効にならない。ユーザスペースのデーモンが、この特定の文字を送らずに close するとドライバはデーモンが watchdog を無効にする前に亡くなったと見なす。で、時間内に再度 open しないとリブート。softdog も
if (c == 'V')
expect_close = 42;
...
static long softdog_ioctl(struct file *file, unsigned int cmd,
unsigned long arg)
...
static const struct watchdog_info ident = {
.options = WDIOF_SETTIMEOUT |
WDIOF_KEEPALIVEPING |
WDIOF_MAGICCLOSE,
...
なんてあったりする

ha.cf のサンプルコメントから
ソフトウェア watchdog を使っているならモジュールロードのパラメタに nowayout=0 あるいは CONFIG_WATCHDOG_NOWAYOUT を無効にしてコンパイルするんじゃないかな。さもないと heartbeat をマトモに終了させたとしてもリブートしてしまうって挙動はお望みじゃないと思う

うーん... heartbeat の watchdog か、別立て watchdog デーモンか...

2011年3月28日月曜日

TIPS: squeeze on raw format KVM

さっき作ったイメージ drbd1.img は最初に / 用の sda1 次が何も手を加えていない sda2。最後が swap の sda3。これをホスト側で見るには qcow2 の場合 nbd として扱えるらしけど -f raw でイメージを作成したので...要 root

# file drbd1.img 
drbd1.img: x86 boot sector; partition 1: ID=0x83, active, starthead 32, startsector 2048, 11716608 sectors; partition 2: ID=0x83, starthead 115, startsector 11718656, 3905536 sectors; partition 3: ID=0x82, starthead 143, startsector 15624192, 1150976 sectors, code offset 0x63
# losetup -o $((512 * 2048)) /dev/loop1 drbd1.img
# mkdir mnt_drbd1
# mount /dev/loop1 mnt_drbd1/
# ls mnt_drbd1/
bin boot dev etc home initrd.img lib lib32 lib64 lost+found media mnt opt proc root sbin selinux srv sys tmp usr var vmlinuz
# chroot mnt_drbd1/
root@parent:/# ls
bin boot dev etc home initrd.img lib lib32 lib64 lost+found media mnt opt proc root sbin selinux srv sys tmp usr var vmlinuz
root@parent:/# cat /etc/hostname
drbd1
root@parent:/# exit
exit
# umount mnt_drbd1
# losetup -d /dev/loop1
とまぁ、ホスト側でも操作可能。なので /etc/inittab 書き換え忘れたとか、/etc/default/grub 書き換えたけど update-grub 忘れたとかも後になってでもできる

他ネットワーク周りは...現況は tap 使うが良さげ。ホスト側で適当にブリッジ作っておいて...毎度手は面倒なので /etc/network/interface に

auto br0
iface br0 inet static
address 192.168.1.254
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255

bridge_ports none
bridge_fd 0
bridge_stp off
とか書いといて、KVM (に限らず、仮想ゲストマシン全て) 最初のブリッジに足のばすとすると /etc/kvm/kvm-ifup はこんな感じ
#! /bin/sh
BRCTL=/usr/sbin/brctl

uplinks=$(ip link ls | awk -F: '/^[1-9].*UP> / { print $2; }')
for switch in $uplinks; do
if [ -d /sys/class/net/$switch/bridge/. ]; then
$BRCTL addif $switch $1
break
fi
done

ip link set $1 up
でホスト側で isc-dhcp-server を動かすとゆー... 面倒だね

ターミナルで kvm, debian squeeze

obs600 休憩。間違いもあるので、後日直すコト > 自分

で、唐突めいているけど、あちこち調べながら X なしで squeeze を KVM にてインストールする方法。あちこち調べたのは良いけど、ポロポロ忘れるので...

目的としては DRBD や heartbeat 試したく lxc 使おうとしたけど、今々は lxc 上で DRBD 動かず。ちょっと挑戦した けど、8.4 で connector 止めて genetlink 使う予定だそうなので、素直に? 挫折、待たせてもらうことに。d-i をイジる手もあるそうだけど、素の netinst.iso で何度か試してみて忘れがちなコト
  • 真っ黒画面でスペース & linux test
  • /etc/default/grub の編集 & update-grub
  • /etc/inittab の編集
イメージの作成
$ kvm-img create -f raw drbd1.img 8G
Formatting 'drbd1.img', fmt=raw size=8589934592
$ ls
debian-6.0.0-amd64-netinst.iso drbd1.img

-f qcow2 が正統? なのだろうけど、後々ホスト側からイジるにあたって
kvm-nbd とか面倒なので...で起動
$ kvm -cdrom debian-6.0.0-amd64-netinst.iso -hda drbd1.img -boot d -curses
真っ黒画面の真ん中に
    640x480
で、何も表示されないけどスペース一回押した後に (ここ何押下するかよく忘れる)
    linux text
とすると...
                           Welcome to Debian GNU/Linux!                                F1


This is a Debian 6.0 (squeeze) installation CD-ROM.
It was built 20110205-14:31; d-i 20110106+b1.

HELP INDEX

KEY TOPIC

<F1> This page, the help index.
<F2> Prerequisites for installing Debian.
<F3> Boot methods for special ways of using this CD-ROM
<F4> Additional boot methods; rescue mode.
<F5> Special boot parameters, overview.
<F6> Special boot parameters for special machines.
<F7> Special boot parameters for selected disk controllers.
<F8> Special boot parameters for the install system.
<F9> How to get help.
<F10> Copyrights and warranties.



Press F2 through F10 for details, or ENTER to boot:
こんな画面。ここで F8
            SPECIAL BOOT PARAMETERS - INSTALLATION SYSTEM                                 F8


You can use the following boot parameters at the boot: prompt,
in combination with the boot method (see <F3>). These parameters
control how the installer works.

RESULT PARAMETER
Disable framebuffer vga=normal fb=false
Don't start PCMCIA hw-detect/start_pcmcia=false
Force static network config netcfg/disable_dhcp=true
Set keyboard map bootkbd=es
Select the kde or xfce desktops desktop=kde

Accessibility options (last 2 options not available for all images):
Use high contrast theme theme=dark
Use Braille tty brltty=driver,device,texttable
Use Speakup speakup.synth=driver


For example:
boot: install vga=normal fb=false

Press F1 for the help index, or ENTER to boot:
For example そのまま
    install vga=normal fb=false
で進む。イメージファイル名の通り DRBD を試したかったのでパーティションは 6G を / に 2G は何もせず残りを swap として。Software Selection では Standard と SSH。GRUB のインストールまで終ってリブートするから CD 外してね。になったところ
               [!!] Finish the installation

Installation complete
Installation is complete, so it is time to boot into your new system.
Make sure to remove the installation media (CD-ROM, floppies), so
that you boot into the new system rather than restarting the
installation.

<Go Back> <Continue>
で Go Back。Execute Shell を選択して、ちょっと面倒だけど
BusyBox v1.17.1 (Debian 1:1.17.1-8) built-in shell (ash)
Enter 'help' for a list of built-in commands.

~ # mount
rootfs on / type rootfs (rw)
none on /proc type proc (rw,relatime)
none on /sys type sysfs (rw,relatime)
tmpfs on /dev type tmpfs (rw,relatime,mode=755)
none on /dev/pts type devpts (rw,relatime,gid=5,mode=620,ptmxmode=000)
none on /sys/kernel/debug type debugfs (rw,relatime)
/dev/sda1 on /target type ext3 (rw,relatime,errors=remount-ro,data=ordered)
/dev/sda1 on /dev/.static/dev type ext3 (rw,relatime,errors=remount-ro,data=orde
red)
tmpfs on /target/dev type tmpfs (rw,relatime,mode=755)
~ # chroot /target
# cd /etc/default
# cp grub grub.dpkg-dist
# vi grub
....
# diff -uw grub.dpkg-dist grub
--- grub.dpkg-dist 2011-03-28 11:49:36.000000000 +0900
+++ grub 2011-03-28 11:45:39.000000000 +0900
@@ -4,8 +4,8 @@
GRUB_DEFAULT=0
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
-GRUB_CMDLINE_LINUX_DEFAULT="quiet"
-GRUB_CMDLINE_LINUX=""
+GRUB_CMDLINE_LINUX="console=tty0 console=ttyS0,115200n8r"
+GRUB_SERIAL_COMMAND="serial --unit=0 --speed=115200 --word=8 --parity=no --stop
=1"

# Uncomment to enable BadRAM filtering, modify to suit your needs
# This works with Linux (no patch required) and with any kernel that obtains
@@ -13,7 +13,7 @@
#GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef"

# Uncomment to disable graphical terminal (grub-pc only)
-#GRUB_TERMINAL=console
+GRUB_TERMINAL="serial console"

# The resolution used on graphical terminal
# note that you can use only modes which your graphic card supports via VBE
# update-grub
Generating grub.cfg ...
Found linux image: /boot/vmlinuz-2.6.32-5-amd64
Found initrd image: /boot/initrd.img-2.6.32-5-amd64
done
もう一つ /etc/inittab も

# cd /etc
# cp inittab inittab.dpkg-dist
# vi inittab
...

# diff -uw inittab.dpkg-dist inittab | head
--- inittab.dpkg-dist 2011-03-28 11:52:02.000000000 +0900
+++ inittab 2011-03-28 11:53:16.000000000 +0900
@@ -52,15 +52,15 @@
# so if you want to add more getty's go ahead but skip tty7 if you run X.
#
1:2345:respawn:/sbin/getty 38400 tty1
-2:23:respawn:/sbin/getty 38400 tty2
-3:23:respawn:/sbin/getty 38400 tty3
-4:23:respawn:/sbin/getty 38400 tty4
-5:23:respawn:/sbin/getty 38400 tty5
-6:23:respawn:/sbin/getty 38400 tty6
+#2:23:respawn:/sbin/getty 38400 tty2
+#3:23:respawn:/sbin/getty 38400 tty3
+#4:23:respawn:/sbin/getty 38400 tty4
+#5:23:respawn:/sbin/getty 38400 tty5
+#6:23:respawn:/sbin/getty 38400 tty6

# Example how to put a getty on a serial line (for a terminal)
#
-#T0:23:respawn:/sbin/getty -L ttyS0 9600 vt100
+T0:23:respawn:/sbin/getty -L ttyS0 115200 vt100
#T1:23:respawn:/sbin/getty -L ttyS1 9600 vt100

# Example how to put a getty on a modem line.
# sync
# exit
~ # sync
~ # exit
でメニューの Finish the Inistallation & Continue... で再起動しないので、他コンソールから kill して再起動。今度は -curses じゃなくて -nographic で
kvm -nographic drbd1.img
でクライアントとして使う分にはソレナリ。