QCOW形式のディスクイメージをマウントする
ゲストOS用のディスクイメージを、そのゲストOSを起動することなくDomain0でマウントしたい場合は、xm block-attachコマンドを使用する。
参考:http://lxr.xensource.com/lxr/source/tools/blktap/
manドキュメント:
block-attach domain-id be-dev fe-dev mode [bedomain-id] Create a new virtual block device. This will trigger a hotplug event for the guest. OPTIONS domain-id The domain id of the guest domain that the device will be attached to. be-dev The device in the backend domain (usually domain 0) to be exported. This can be specified as a physical partition (phy:sda7) or as a file mounted as loopback (file://path/to/loop.iso). fe-dev How the device should be presented to the guest domain. It can be specified as either a sym- bolic name, such as /dev/hdc, for common devices, or by device id, such as 0x1400 (/dev/hdc device id in hex). mode The access mode for the device from the guest domain. Supported modes are w (read/write) or r (read-only). bedomain-id The back end domain hosting the device. This defaults to domain 0.
実際には次のようなコマンドを実行する。
xm block-attach 0 tap:qcow:/path/to/qcow/image/image.qcow /dev/xvda1 w 0
最初の"0"は関連づけるドメイン番号。今回はホストOS(Domain0)にそのディスクイメージを関連づけたいので"0"を指定する。
次の文字列はイメージの指定。QCOWイメージを指定する場合には、blktapドライバ/QCOWドライバを使用することを明示するために "tap:qcow:"ではじめる。
(正確にはバックエンドドライバの指定)
"/dev/xvda1"は1つめの引数で指定したドメインで、イメージをマウントするデバイスファイル名。
(正確にはフロントエンドドライバの指定)
"w"はマウントモードで、"r"にすれば読み取り専用に。
あとは通常通りmountコマンドでマウントすればよい。
アンマウントする場合には、umountでアンマウントしてから次のコマンドを実行する。
# xm block-detach 0 /dev/xvda1
block-listコマンドで、現在関連づけられているデバイスの一覧を表示できる。
# xm block-list 0 Vdev BE handle state evt-ch ring-ref BE-path 51713 0 0 4 29 8 /local/domain/0/backend/tap/0/51713
…まぁ、そのイメージの中身がWindows用だったりするとうまくマウントできないわけですが…