VirtualBox上のVMをWindowsバッチコマンドで起動する
VirtualBox で VMをよく起動するのなら、「VirtualBox マネージャー」を起動してからVM名をダブルクリックして起動するが面倒ですね。 「バッチコマンド一発で起動してくれたらいいな」と思えてきます。
「VirtualBox マネージャー」には、結構CUIコマンドが用意されています。 (説明サイトは、マニュアルサイト「8.2. Commands overview」 )
VMの起動コマンド例
cd %~dp0
cd VirtualBox
echo Documentation for CUI command , see http://www.virtualbox.org/manual/ch08.html .
echo *** VM List ***
VBoxManage.exe list vms
echo *** Start linuxbean
VBoxManage.exe startvm "linuxbean"
cd %~dp0
ちょっと解説
ポイントごとの少し解説します。
@echo off
cd %~dp0
cd VirtualBox
VirtualBox
のインストールディレクトリに移動しています。環境に応じて書き換えが必要な場所です。
(cd %~dp0
はバッチファイルの配置ディレクトリに移動するおまじないです。(バッチコマンド詳しい人には蛇足かもしれませんが ))
VBoxManage.exe
が存在するディレクトリに移動しています
echo *** VM List ***
VBoxManage.exe list vms
list
で自分の環境で登録されている VM の一覧を表示します。VM名も表示されます。VM名は、VMを起動する際にも使用します。
echo *** Start linuxbean
VBoxManage.exe startvm "linuxbean"
startvm <VM名>
で VM起動します。
まとめ
- マニュアルサイト「8.2. Commands overview」 には他にも色々CUIコマンドが説明されています。
サイトには次のように書かれています。 “VBoxManage is the command-line interface to VirtualBox. With it, you can completely control VirtualBox from the command line of your host operating system.”
GUIでできることは何でもコマンドラインでできそうです。
ただ、私は今回ここまででやりたいことはできたので、これでおしまいにします。
No Comments