2008-06-26

VMware Fusion の仮想ハードディスクを再構築

VMware Fusion の仮想ハードディスクを2GBに分割 の続き

前回は仮想ディスクファイルをWindowsにコピーしてWindows上で分割という手間のかかる事をしていましたが、Mac版にも vmware-vdiskmanager があった、というところで終わっていました。
今回はMac上で仮想ハードディスクを変換してみます。

昔のVMwareは事前割当がデフォルトでしたが、VMware Fusion は可変サイズがデフォルトになっています。
これはこれで便利なのですが、どうもディスクIOがボトルネックになっているような気がして仕方がないので、可変サイズから事前割当に変換する事にしました。
(仮想ハードディスク内と仮想ハードディスクファイルそのものが2重に断片化するせいでしょうか?SDDを使えば解決するのだろうか?)

まず、使えるコマンドを表示してみましょう。
ターミナルを起動して
$ /Library/Application\ Support/VMware\ Fusion/vmware-vdiskmanager
と入力すると以下のようにヘルプが表示されます。
(使用バージョンは VMware Fusion 2.0 beta 1 です)
VMware Virtual Disk Manager - build 89933.
Usage: vmware-vdiskmanager OPTIONS <disk-name> | <mount-point>
Offline disk manipulation utility
Operations, only one may be specified at a time:
-c : create disk. Additional creation options must
be specified. Only local virtual disks can be
created.
-d : defragment the specified virtual disk. Only
local virtual disks may be defragmented.
-k : shrink the specified virtual disk. Only local
virtual disks may be shrunk.
-n <source-disk> : rename the specified virtual disk; need to
specify destination disk-name. Only local virtual
disks may be renamed.
-p : prepare the mounted virtual disk specified by
the drive-letter for shrinking.
-r <source-disk> : convert the specified disk; need to specify
destination disk-type. For local destination disks
the disk type must be specified.
-x <new-capacity> : expand the disk to the specified capacity. Only
local virtual disks may be expanded.

Other Options:
-q : do not log messages

Additional options for create and convert:
-a <adapter> : (for use with -c only) adapter type
(ide, buslogic or lsilogic)
-s <size> : capacity of the virtual disk
-t <disk-type> : disk type id

Options for remote disks:
-h <hostname> : hostname of remote server
-u <username> : username for remote server
-f <filename> : file containing password
-P <port> : optional TCP port number (default: 902)
-S : specifies that the source disk is remote, by default
the remote options are assumed to refer to the
destination.
Disk types:
0 : single growable virtual disk
1 : growable virtual disk split in 2GB files
2 : preallocated virtual disk
3 : preallocated virtual disk split in 2GB files
4 : preallocated ESX-type virtual disk
5 : compressed disk optimized for streaming

The capacity can be specified in sectors, KB, MB or GB.
The acceptable ranges:
ide adapter : [1MB, 950.0GB]
scsi adapter: [1MB, 950.0GB]
ex 1: vmware-vdiskmanager -c -s 850MB -a ide -t 0 myIdeDisk.vmdk
ex 2: vmware-vdiskmanager -d myDisk.vmdk
ex 3: vmware-vdiskmanager -r sourceDisk.vmdk -t 0 destinationDisk.vmdk
ex 4: vmware-vdiskmanager -x 36GB myDisk.vmdk
ex 5: vmware-vdiskmanager -n sourceName.vmdk destinationName.vmdk
ex 6: vmware-vdiskmanager -r sourceDisk.vmdk -t 4 -h esx-name.mycompany.com ¥
-u username -f passwordfile "[storage1]/path/to/targetDisk.vmdk"
ex 7: vmware-vdiskmanager -k myDisk.vmdk
ex 8: vmware-vdiskmanager -p <mount-point>
(A virtual disk first needs to be mounted at <mount-point>)
最後にコマンド例がいくつか示されているのがありがたいですね。
今回、私は "事前割当(2GB分割)" にしたいので以下のようなコマンドを実行します。
$ /Library/Application\ Support/VMware\ Fusion/vmware-vdiskmanager -r ~/Documents/Virtual\ Machines.localized/仮想マシン名.vmwarevm/仮想ディスクファイル名.vmdk -t 3 ~/Documents/Virtual\ Machines.localized/仮想ディスクファイル名.vmdk
-r の後ろは変換元の仮想ハードディスク、-t の後ろの 3 が "事前割当(2GB分割)" を表します。最後のパラメータは出力ファイル名です。変換元と異なるフォルダにファイル名は変えずに出力します。

仮想ディスクファイル名は、仮想マシンファイルを右クリックして "パッケージ内容を表示" で調べます。拡張子vmdkのファイルがソレです。2GB分割している場合にはファイル名末尾に "-f001" のような連番がついたファイルが出来ていますが、末尾に連番の付いてない物が親ですので、連番なしのファイル名のみ使用します。

変換が終わるとこのように表示されます。
Creating disk '/Users/ユーザー名/Documents/Virtual Machines.localized/仮想ディスクファイル名.vmdk'
Convert: 100% done.
Virtual disk conversion successful.
変換が終わったら現在の仮想ディスクファイルと変換した仮想ディスクファイルを入れ替えて仮想マシンを起動してみます。
問題なく起動できたら古い仮想ディスクファイルを削除します。

さてさて、これで効果があったのかというと





速くなった気がします。
プラシーボ効果?

久しぶりにblog書いているので広告の入れ方忘れたorz

2008-06-06

lnp を使用して Cygwin と RCX の通信を行う 2

brickOS 版の lnpd は Cygwin 上でコンパイルできなかったので lnphost を使用する事にしました。
ちなみに legOS 版の lnpd は試していません。

lnphost の導入手順はこんな感じです。
$ curl -O 'http://easynews.dl.sourceforge.net/sourceforge/lnphost/lnphost-1.0a.zip'
$ unzip lnphost-1.0a.zip
$ cd lnphst
$ make
Cygwin側では
./lnpdump -d //./legotower1 > recieve.txt
のようにすれば受信待ちになり、Ctrl + C でプログラムを止めるまでの間に受信したデータを recieve.txt に保存できるはずです。

RCX 側は
int lnp_addressing_write (const unsigned char *data, unsigned char length, unsigned char dest, unsigned char srcport)
を使用してデータを送信します。
data には送信データの先頭アドレスを渡します。
length には送信データのサイズを渡します。unsigned char なので型としては 0 〜 255 ですが、実際に送信できるサイズはもう少し小さいようです。おそらくヘッダとかパリティとかを含めたパケットのサイズが255byteなのでしょう。調べるのが面倒なので私は安全に200byteに分割して送る事にしました。
dest には Cygwin 側の待ち受けアドレスを設定します。上位4bitがアドレス、下位4bitがポートのようです。
srcport には RCX 側の送信ポートを設定します。恐らく0x0〜0xF が有効な値です。

RCX 側のアドレスはどうなっているかというと brickOS の boot/config.h 内の
#define CONF_LNP_HOSTADDR 0 //!< LNP host address
で設定されているようです。

Cygwin(lnphost) 側は・・・特にソースコード内では決めていない?ようです。

さて、RCX のアドレスなんですが、コレがみんな同じだとトラブルが起きないんでしょうか?
変えておいた方がいいんでしょうかねぇ・・・

中途半端ですが時間がないのでとりあえずここまで

メモリ領域についてメモ

メモリ領域には大きく分けて
  • プログラム領域
    実行プログラムが置かれる
  • 静的領域
    外部変数や静的変数が置かれる
  • スタック領域
    自動変数、一時変数、関数の引数や返値などが置かれる
  • ヒープ領域
    プログラム内で動的に確保したメモリはこの領域が使われる
の4つがあるそうです。
ただし処理系によって異なるらしい。

2008-06-05

lnp を使用して Cygwin と RCX の通信を行う 1

さて、長期にわたり放置を続けている当Blogであるが、サボってるわけではない。
単純に精神的な余裕がなくて近寄るのもイヤな状態だっただけだ。

さて、東海地区試走会を2日後に控えた今頃になってRCXからログを転送する方法を調べているわけだが、これがなかなか上手くいかない。

lnpdを使用すればよさそうだという事がわかったので早速brickOSのページからダウンロードしてコンパイルしてみた。
Cygwin上で以下のように実行した。
$ curl -O 'http://easynews.dl.sourceforge.net/sourceforge/brickos/lnpd-0.9.0.tar.gz'
$ tar -xzf lnpd-0.9.0.tar.gz
$ cd lnpd-0.9.0/
$ ./configure
$ make
ちなみにこれらのコマンドが何を意味しているのか、理解していません。
他のところでこうしてるのを見たので真似ただけです。
何かが間違ってる気がしますが…

で、結果は
$ make
make all-recursive
make[1]: Entering directory `/home/Administrator/brickos/lnpd-0.9.0'
Making all in lnpd+liblnp
make[2]: Entering directory `/home/Administrator/brickos/lnpd-0.9.0/lnpd+liblnp'

Making all in liblnp
make[3]: Entering directory `/home/Administrator/brickos/lnpd-0.9.0/lnpd+liblnp/liblnp'
/bin/sh ../../libtool --mode=compile gcc -DHAVE_CONFIG_H -I. -I. -I../.. -D_GNU_SOURCE -g -O2 -c lnptest.c
mkdir .libs
gcc -DHAVE_CONFIG_H -I. -I. -I../.. -D_GNU_SOURCE -g -O2 -c lnptest.c -DPIC -o .libs/lnptest.o
gcc -DHAVE_CONFIG_H -I. -I. -I../.. -D_GNU_SOURCE -g -O2 -c lnptest.c -o lnptest.o >/dev/null 2>&1
/bin/sh ../../libtool --mode=compile gcc -DHAVE_CONFIG_H -I. -I. -I../.. -D_GNU_SOURCE -g -O2 -c stub.c
gcc -DHAVE_CONFIG_H -I. -I. -I../.. -D_GNU_SOURCE -g -O2 -c stub.c -DPIC -o .libs/stub.o
stub.c: In function `lnp_init':
stub.c:381: error: `O_ASYNC' undeclared (first use in this function)
stub.c:381: error: (Each undeclared identifier is reported only once
stub.c:381: error: for each function it appears in.)
stub.c:383: error: `F_SETSIG' undeclared (first use in this function)
make[3]: *** [stub.lo] Error 1
make[3]: Leaving directory `/home/Administrator/brickos/lnpd-0.9.0/lnpd+liblnp/liblnp'
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/home/Administrator/brickos/lnpd-0.9.0/lnpd+liblnp'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/Administrator/brickos/lnpd-0.9.0'
make: *** [all-recursive-am] Error 2
・・・見事にコンパイルできませんでした。
O_ASYNC と F_SETSIG の定義がないとの事。
どう対応したらよいのか調べてみましたが。

O_ASYNC の方は
legOS : 439
that's an OS issue - your host system should define O_ASYNC. Some older
systems define FASYNC instead, try that one.

You can work around this more elegantly, too:

#ifndef O_ASYNC
#define O_ASYNC FASYNC
#endif

And hope for the best.
O_ASYNC は古いシステムでは FASYNC を使って試してみてね。との事。

F_SETSIG の方は
legOS : 3945
・・・全く同じ現象の質問だが放置プレイ状態

legOS : 25788
こちらも全く同じ現象の質問ですが、こちらには回答が付いていました
lnphost is perfect. Thank you for the reference.
えっと、Cygwin上でlnpdは使えません。lnphostを使いましょう。
との事でした。

かなりせっぱ詰まっているので走り書き状態ですが、これで一度公開します。
試走会、何も出来ない可能性が極めて高いのです。
余裕が出来たら手直しします。