仮想化 · 2 min read · Oct 22, 2025
UbuntuリポジトリからUbuntu 8.04 (Hardy Heron) サーバーにXenをインストールする - ページ 2
3 仮想マシンの作成 (domU)
さて、最初のゲストドメイン、xen1.example.comを作成しましょう。これはHardy Heron (hardy)を実行し、IPアドレスは192.168.0.101です:
xen-create-image --hostname=xen1.example.com --size=2Gb --swap=256Mb --ide \
--ip=192.168.0.101 --netmask=255.255.255.0 --gateway=192.168.0.1 --force \
--dir=/home/xen --memory=64Mb --arch=i386 --kernel=/boot/vmlinuz-2.6.24-16-xen \
--initrd=/boot/initrd.img-2.6.24-16-xen --install-method=debootstrap --dist=hardy \
--mirror=http://archive.ubuntu.com/ubuntu/ --passwd多くのスイッチはここでは不要ですが、/etc/xen-tools/xen-tools.confに同じ詳細を指定したためです。しかし、コマンドラインまたは/etc/xen-tools/xen-tools.confで希望の設定を指定できることを示しています。–ideを指定することを忘れないでください。そうしないと、仮想マシンが起動しない可能性があります!
(利用可能なオプションについて詳しく知りたい場合は、xen-create-imageのマニュアルページを見てください:
man xen-create-image)
xen-create-imageコマンドは、xen1.example.com仮想マシンを作成します。これには数分かかることがあります。出力は次のようになります:
root@server1:~# xen-create-image --hostname=xen1.example.com --size=2Gb --swap=256Mb --ide \
> --ip=192.168.0.101 --netmask=255.255.255.0 --gateway=192.168.0.1 --force \
> --dir=/home/xen --memory=64Mb --arch=i386 --kernel=/boot/vmlinuz-2.6.24-16-xen \
> --initrd=/boot/initrd.img-2.6.24-16-xen --install-method=debootstrap --dist=hardy \
> --mirror=http://archive.ubuntu.com/ubuntu/ --passwd
一般情報
--------------------
ホスト名 : xen1.example.com
ディストリビューション : hardy
パーティション : swap 256Mb (swap)
/ 2Gb (ext3)
イメージタイプ : sparse
メモリサイズ : 64Mb
カーネルパス : /boot/vmlinuz-2.6.24-16-xen
Initrdパス : /boot/initrd.img-2.6.24-16-xen
ネットワーキング情報
----------------------
IPアドレス1 : 192.168.0.101 [MAC: 00:16:3E:62:DA:BB]
ネットマスク : 255.255.255.0
ブロードキャスト : 192.168.0.255
ゲートウェイ : 192.168.0.1
パーティションイメージを作成中: /home/xen/domains/xen1.example.com/swap.img
完了
/home/xen/domains/xen1.example.com/swap.imgにスワップを作成中
完了
パーティションイメージを作成中: /home/xen/domains/xen1.example.com/disk.img
完了
/home/xen/domains/xen1.example.com/disk.imgにext3ファイルシステムを作成中
完了
インストール方法: debootstrap
完了
フックを実行中
完了
ロールスクリプトは指定されていません。 スキップ
Xen構成ファイルを作成中
完了
ルートパスワードを設定中
新しいUNIXパスワードを入力してください:
新しいUNIXパスワードを再入力してください:
passwd: パスワードが正常に更新されました
すべて完了
生成されたログファイルは:
/var/log/xen-tools/xen1.example.com.log
root@server1:~#これでxen1.example.comの構成ファイルが/etc/xen/xen1.example.com.cfgに作成されているはずです。仮想マシンの構成ファイルに慣れるために、それを見てみましょう:
cat /etc/xen/xen1.example.com.cfg| # Xenインスタンスxen1.example.comの構成ファイル、 # xen-tools 3.8によって2008年5月6日火曜日16:01:38に作成されました。 # # カーネル + メモリサイズ # kernel = '/boot/vmlinuz-2.6.24-16-xen' ramdisk = '/boot/initrd.img-2.6.24-16-xen' memory = '64' # # ディスクデバイス。 # root = '/dev/hda2 ro' disk = [ 'file:/home/xen/domains/xen1.example.com/swap.img,hda1,w', 'file:/home/xen/domains/xen1.example.com/disk.img,hda2,w', ] # # ホスト名 # name = 'xen1.example.com' # # ネットワーキング # vif = [ 'ip=192.168.0.101,mac=00:16:3E:62:DA:BB' ] # # 動作 # on_poweroff = 'destroy' on_reboot = 'restart' on_crash = 'restart' extra = '2 console=xvc0' |
file:パラメータはXen 3.2では非推奨となったため、/etc/xen/xen1.example.com.cfgを今すぐ編集し、file:をtap:aio:に置き換えなければなりません(そうしないと、次のようなエラーが発生します:
Error: Device 769 (vbd) could not be connected. losetup /dev/loop0 /home/xen/domains/xen1.example.com/swap.img failed仮想マシンを起動しようとすると - http://ubuntuforums.org/showthread.php?t=770902も参照してください):
vi /etc/xen/xen1.example.com.cfg| [...] disk = [ 'tap:aio:/home/xen/domains/xen1.example.com/swap.img,hda1,w', 'tap:aio:/home/xen/domains/xen1.example.com/disk.img,hda2,w', ] [...] |
(デュアルコアCPUを持っていて、仮想マシンが両方のCPUコアを使用するようにしたい場合は、構成ファイルにvcpus = ‘2’という行を追加してください。次のように:
vi /etc/xen/xen1.example.com.cfg| # Xenインスタンスxen1.example.comの構成ファイル、 # xen-tools 3.8によって2008年5月5日月曜日16:49:32に作成されました。 # # カーネル + メモリサイズ # kernel = '/boot/vmlinuz-2.6.24-16-xen' ramdisk = '/boot/initrd.img-2.6.24-16-xen' memory = '64' vcpus = '2' [...] |
その後、仮想マシン内で次のコマンドを実行して、両方のCPUコアが仮想マシンによって使用されていることを確認できます。
cat /proc/cpuinfo出力は、仮想マシンが両方のコアを使用している場合、次のようになります:
xen1:~# cat /proc/cpuinfo
processor : 0
vendor_id : AuthenticAMD
cpu family : 15
model : 75
model name : AMD Athlon(tm) 64 X2 Dual Core Processor 4200+
stepping : 2
cpu MHz : 2210.054
cache size : 512 KB
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 1
wp : yes
flags : fpu tsc msr pae mce cx8 apic mca cmov pat pse36 clflush mmx fxsr
sse sse2 ht syscall nx mmxext fxsr_opt lm 3dnowext 3dnow pni cx16 lahf_lm cmp_legacy svm
cr8legacy ts fid vid ttp tm stc
bogomips : 5526.81
processor : 1
vendor_id : AuthenticAMD
cpu family : 15
model : 75
model name : AMD Athlon(tm) 64 X2 Dual Core Processor 4200+
stepping : 2
cpu MHz : 2210.054
cache size : 512 KB
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 1
wp : yes
flags : fpu tsc msr pae mce cx8 apic mca cmov pat pse36 clflush mmx fxsr
sse sse2 ht syscall nx mmxext fxsr_opt lm 3dnowext 3dnow up pni cx16 lahf_lm cmp_legacy svm
cr8legacy ts fid vid ttp tm stc
bogomips : 5526.81
xen1:~#)
仮想マシンを起動するには、次のコマンドを実行します。
xm create /etc/xen/xen1.example.com.cfg次のコマンドを実行して、仮想マシンにログインします。
xm console xen1.example.com(コンソールにいる場合はCTRL+]を押すか、PuTTYを使用している場合はCTRL+5を押してdom0に戻ります)、またはSSHクライアントを使用して接続します(192.168.0.101)。
仮想マシン内で(初めて使用する場合)、次のコマンドを実行します。
mv /lib/tls /lib/tls.disabledさて、ホストシステム(dom0)に戻ります。実行中の仮想マシンのリストを取得するには、次のコマンドを入力します。
xm list出力は次のようになります:
root@server1:~# xm list
Name ID Mem VCPUs State Time(s)
Domain-0 0 569 1 r----- 103.6
xen1.example.com 1 64 1 -b---- 60.8
root@server1:~#xen1.example.comをシャットダウンするには、次のようにします:
xm shutdown xen1.example.comvm01を次回のシステム起動時に自動的に起動させたい場合は、次のようにします:
ln -s /etc/xen/xen1.example.com.cfg /etc/xen/auto以下は最も重要なXenコマンドです:
xm create -c /path/to/config - 仮想マシンを起動します。
xm shutdown
xm destroy
xm list - 実行中のシステムをリストします。
xm console
xm help - すべてのコマンドのリスト。
次に、IPアドレス192.168.0.102を持つ2番目のvm、xen2.example.comを作成しましょう:
xen-create-image --hostname=xen2.example.com --size=2Gb --swap=256Mb --ide \
--ip=192.168.0.102 --netmask=255.255.255.0 --gateway=192.168.0.1 --force \
--dir=/home/xen --memory=64Mb --arch=i386 --kernel=/boot/vmlinuz-2.6.24-16-xen \
--initrd=/boot/initrd.img-2.6.24-16-xen --install-method=debootstrap --dist=hardy \
--mirror=http://archive.ubuntu.com/ubuntu/ --passwd次に、vmの構成ファイル/etc/xen/xen2.example.com.cfgを開き、再度file:をtap:aio:に置き換えます:
vi /etc/xen/xen2.example.com.cfg| [...] disk = [ 'tap:aio:/home/xen/domains/xen2.example.com/swap.img,hda1,w', 'tap:aio:/home/xen/domains/xen2.example.com/disk.img,hda2,w', ] [...] |
その後、次のようにしてxen2.example.comを起動できます:
xm create /etc/xen/xen2.example.com.cfg(仮想マシンに初めて入ったときは、次のコマンドを忘れずに実行してください。
xm console xen2.example.comと
mv /lib/tls /lib/tls.disabled)
…そして、次のようにシャットダウンします:
xm shutdown xen2.example.comxen-create-imageコマンドで作成されたすべての仮想マシンのリストは、次のコマンドで確認できます:
xen-list-imagesroot@server1:~# xen-list-images
Name: xen1.example.com
Memory: 64
IP: 192.168.0.101Name: xen2.example.com
Memory: 64
IP: 192.168.0.102
root@server1:~#xen-toolsでできることについて詳しく知りたい場合は、次のチュートリアルを見てください: https://www.howtoforge.com/xen_tools_xen_shell_argo
4 リンク
- Xen: http://www.xensource.com/xen/
- xen-tools: http://xen-tools.org/software/xen-tools
- Ubuntu: http://www.ubuntu.com/
新しい投稿を受信箱で受け取る
スパムはありません。いつでも購読を解除できます。