Jun
9

[Xen]DomainUをさくっと作る方法

ジョグノートでは開発や実験を行うための環境として Xen を使っています。

Xen のバーチャルマシンは DomainU と呼ばれていて、DomainU の作成方法としてはここで紹介されているように virt-install を使う方法が一般的なようです。
しかし virt-install はいろいろな仮想化技術をラップするライブラリである libvirt を使っていて、Xen の DomainU を作成するために Xen 以外のソフトウエアのお世話になるのは少々大袈裟な気がします。

なので Xen の機能のみ使って DomainU を作成できればと思い、調べてみました。基本的にはここにある方法で作業を進めていきます。

以下は CentOS 5.0 が動いている Domain0 上で CentOS 4.6 がインストールされた DomainU を作成するための手順です。

DomainU を新規に作成する場合には OS のインストーラを DomainU として走らせる必要があり、まずはインストーラのための DomainU の設定ファイルを作成します。
インストーラのための設定ファイルを /etc/xen/centos4.installation として以下のように作成します。
ちなみに /etc/xen は root 以外はディレクトリの中に入ることもできないので、実際に作業をする時には sudo bash などして root 権限でシェルを立ち上げてから作業をしたほうがやりやすいでしょう。

kernel = "/var/lib/xen/images/vmlinuz-CentOS4.6-Installer"
ramdisk = "/var/lib/xen/images/initrd-CentOS4.6-Installer.img"
extra = "text ks=http://somewhere/devel-ks.cfg"
name = "centos4.dev"
memory = "256"
disk = [ 'tap:aio:/var/lib/xen/images/centos4.dev.img,xvda,w', ]
vif = [ 'mac=00:16:3e:5b:b3:ec, bridge=xenbr0', ]
uuid = "722e88f7-99bd-47ac-b644-89dab714ee22"
vcpus=1
on_reboot = 'destroy'
on_crash = 'destroy'

設定ファイルの記述については man xmdomain.cfg で調べることができます。このインストーラを走らせるための設定ファイルの要点を見ていきます。

まず kernel と ramdisk にはインストーラ用のものを指定します。これは CentOS のインストーラの ISO9660 イメージに含まれていて、/images/xen/{vmlinuz,initrd.img} がそれぞれカーネルとシステムイメージになります。
これらは例えば次のようにして ISO9660 イメージから取り出して、設定ファイルで指定した場所にコピーしておきます。

% sudo mount -o loop /path/to/CentOS-4.6-i386-binDVD.iso /mnt
% sudo cp /mnt/images/xen/vmlinuz /var/lib/xen/images/vmlinuz-CentOS4.6-Installer
% sudo cp /mnt/images/xen/initrd.img /var/lib/xen/images/initrd-CentOS4.6-Installer.img

次に extra にはインストーラを起動する時に指定するパラメータを指定します。ここではコンソールでインストールを行うので text と、後述するインスールの自動化のための Kickstart ファイルへの PATH を指定しておきます。

name はこの DomainU につける名前で、他とかぶらないようなわかりやすい名前を適当につけておきます。memory は 256 を指定しています。これ以上少ないと確かインストーラにメモリが少ないと怒られたり、インストールした後も運用上問題があったような気がするので、256MB 以上を割り当てたほうがいいでしょう。

disk では DomainU がハードディスクとして扱うためのイメージファイルを指定します。ここで指定したファイルは実際に存在しなければいけないので、インストーラを走らせる前に作成しておきます。
参考にしたCentOSのWikiの記述によると、virt-install では

# dd if=/dev/zero of=/srv/xen/mailserver.img oflag=direct bs=1M seek=2047 count=1

のようにして 2GB のファイルを作成する場合でも、作成する時点では最小限の大きさにしておいて、ファイルへの書き込みと共にサイズが成長していくような作り方をしているようですが、この方法で作成するとインストール中とか yum update してる時とかファイルサイズが大きくなるような作業をしている時に膨大な時間がかかります。確かOSのインストールに4時間ほどの時間がかかりました。なので

# dd if=/dev/zero of=/srv/xen/mailserver.img oflag=direct bs=1M count=2048

のようにして、あらかじめ所定の大きさのファイルを作成しておいたほうが快適に DomainU を使うことができます。
なおディスクイメージのサイズですが、コンパイラなどの開発環境や Apache や MySQL などの動作環境をインストールすると 4GB でもすぐにいっぱいになってしまうので、8GB くらいで作成しておいたほうが後々の使い勝手がよいです。次のようにして 8GB のディスクイメージを作成します。

% sudo dd if=/dev/zero of=/var/lib/xen/images/centos4.dev.img oflag=direct bs=1M count=8192

vif ではネットワークインターフェースの設定をします。mac に指定する mac address はここで紹介されている、次のような Python のスクリプトを使って生成します。最初の 0x00, 0x16, 0x3e, は Xen が取得しているベンダコードです。

#! /usr/bin/python
# macgen.py script generates a MAC address for Xen guests
#
import random
mac = [ 0x00, 0x16, 0x3e,
random.randint(0x00, 0x7f),
random.randint(0x00, 0xff),
random.randint(0x00, 0xff) ]
print ':'.join(map(lambda x: "%02x" % x, mac))

これを macgen.py などと適当な名前で保存して、次のようにして実行します。

% python macgen.py
00:16:3e:1b:82:61

uuid には同一の Domain0 上で実行する他の DomainU とかぶらない一意な値を指定します。これは uuidgen コマンドを用いて作成することができます。

% uuidgen
722e88f7-99bd-47ac-b644-89dab714ee22

on_reboot と on_crash には destroy を指定しておきます。こうしておくとインストーラが終了すると DomainU も終了してくれます。

RedHat 系の Linux のインストーラである Anaconda はKickstart と呼ばれる設定ファイルを用意しておくことにより、インストールの手順を自動化することができます。Kickstart についてはここが参考になります。
ここでは次の内容で Kickstart ファイルを作成します。

install
url --url http://somewhere/centos
lang en_US.UTF-8
network --device eth0 --bootproto static --ip 192.168.109.49 --netmask 255.255.255.0 --gateway 192.168.109.254 --nameserver 192.168.109.1
rootpw itsasecret
firewall --enabled --trust=eth0 --port=22:tcp,80:tcp
authconfig --enableshadow --enablemd5
selinux --disabled
timezone --utc Asia/Tokyo
bootloader --location=mbr --driveorder=xvda --append="console=xvc0"
reboot

# Partitioning
clearpart --all --initlabel --drives=xvda
part /boot --fstype ext3 --size=100 --ondisk=xvda
part / --fstype ext3 --size=1024 --grow
part swap --fstype swap --size=512

%packages
@core
@development-libs
@development-tools
@legacy-software-development

この Kickstart ファイルも要所を見ていきます。

url には CentOS のインストールイメージがあるところを指定しておきます。外部のサイトを指定してもよいですが、それだとネットワークの回線が細いとインストールに時間がかかるので、インストーラの ISO9660 のイメージをダウンロードしておいて、上述のように ISO9660 イメージをシステムにマウントして、インストールイメージが入っているディレクトリが http で見えるように設定しておくといいでしょう。

lang には en_US.UTF-8 を指定します。日本語が通らないかもしれないコンソールで作業をすることが多いので、必ず表示できる設定を選んでおいたほうがよいかと思います。ただ、何故かここで un_US.UTF-8 を選んだのにインストールの時には確認のプロンプトが表示されました。ここは自動化しないのですかね。

network には静的にアドレスを割り振るように設定しました。DHCP Client にするための設定は上述のWikiに詳しい解説があります。

root のパスワードもここで指定します。

firewall は iptables の設定です。ここでは ssh と http の通信は通すように設定しておきます。

selinux は使わないので disabled を指定しておきます。

timezone は Asia/Tokyo を指定します。ここで指定できる値は、既にOSが入っている環境なら /usr/share/zoneinfo の中にあるファイルの名前を見れば一覧できます。

ハードディスクのパーティッションの切り方は clearpert と part によって指定します。
まずは全てのパーティッションを削除します。そして /boot に 100MB、スワップに 512MB、/ に残りの容量を割り当てます。
最近の RedHat 系の Linux はデフォルトで LVM を使ってパーティッションを構成していますが、DomainU として運用する場合、LVM のディスクイメージを Domain0 から見る場合に手順がいろいろと面倒なので、古典的な方法でパーティッションを切った方が運用しやすいです。
Domain0 から LVM で構成されたディスクイメージをマウントするための方法としてはこのへんが参考になります。

パッケージは必要最小限のものだけインストールします。本当に必要最小限のものだけなら core のみを指定すればいいのですが、それだと gcc をはじめとした開発環境がインストールされないので、development-libs, development-tools, legacy-software-development も指定しておきます。

作成した Kickstart ファイルは、インストーラが動く DomainU から http で見えるところに置いておきます。

ここまでできたら、インストーラを動かすための DomainU を作成します。

% sudo xm create -c /etc/xen/centos4.installation

Kickstart に記述した手順で次々とインストーラの画面が切り替わっていきます。

インストールが終了したら、DomainU の設定ファイルをインストーラ用のものから実際に運用するものに置き換えます。修正個所は次の通りです。

--- centos4.dev.installer     2008-06-04 16:14:33.000000000 +0900
+++ centos4.dev       2008-06-04 15:41:19.000000000 +0900
-kernel = "/var/lib/xen/images/vmlinuz-CentOS4.6-Installer"
-ramdisk = "/var/lib/xen/images/initrd-CentOS4.6-Installer.img"
-extra = "text ks=http://somewhare/devel-ks.cfg"
 name = "centos4.dev"
 memory = "256"
 disk = [ 'tap:aio:/var/lib/xen/images/centos4.dev.img,xvda,w', ]
 vif = [ 'mac=00:16:3e:5b:b3:ec, bridge=xenbr0', ]
 uuid = "722e88f7-99bd-47ac-b644-89dab714ee22"
+bootloader="/usr/bin/pygrub"
 vcpus=1
-on_reboot = 'destroy'
-on_crash = 'destroy'
+on_reboot = 'restart'
+on_crash = 'restart'

kernel と ramdisk の指定をやめて bootloader を指定します。これでハードディスクイメージにインストールされたカーネルから起動するようになります。extra もインストーラのための指定で実運用には必要ないので削除します。on_reboot と on_crash には restart を指定しておきます。

設定ファイルを作成したら、次のようにして起動します。

% sudo xm create -c /etc/xen/centos4

これでインストールした OS が正常に起動すれば DomainU 作成完了です。

以上、virt-install のお世話にならず Xen の機能のみを使って DomainU を作成する方法でした。

133 Responses to “[Xen]DomainUをさくっと作る方法”

You know so many interesting infomation. You might be very wise. I like such people. Don’t top writing.

Posted on June 17th, 2009.

Your site is worth beeing in the top cause it contains really amazing information.

Posted on July 7th, 2009.

Great post, thanks for sharing this with me :)

I look forward to reading your future posts!

Posted on July 19th, 2009.

This was an interesting post to read. Please give me more detail via e-mail.

Thanks :)

Posted on July 24th, 2009.

I usually don’t post in Blogs but your blog forced me to, amazing work.. beautiful …

Posted on August 7th, 2009.

Extenze said:

It sounds like you’re creating problems yourself by trying to solve this issue instead of looking at why their is a problem in the first place.

Posted on August 20th, 2009.

Sebastien said:

Nice write up…usually I never reply to these thing but this time I will,Thanks for the great info :)

Posted on August 30th, 2009.

Timmy R. said:

Thanks for writing this great blog I really enjoyed.

Posted on August 31st, 2009.

Jose R. said:

I don’t usually post but I enjoyed your blog a lot,Thanks alot for the great read :)

Posted on September 8th, 2009.

I don’t usually post but I enjoyed your blog a lot,Thanks alot for the great read :)

Posted on September 8th, 2009.

Good job!

Posted on September 8th, 2009.

Timmy R. said:

I don’t usually post but I enjoyed your blog a lot.

Posted on September 9th, 2009.

Samuel C. said:

I don’t usually post but I enjoyed your blog a lot.

Posted on September 11th, 2009.

Madison said:

You made some good points on this topic.

Posted on September 13th, 2009.

Destinee said:

Keep up the good work.

Posted on September 15th, 2009.

Geovanni said:

Does it cost much to make a blog?

Posted on September 17th, 2009.

“We dare you to hit one into our bay!” Being from CA, we saw a lot of Bonds’ HRs go into the SF Bay, but unless you “get” the joke, it won’t be funny. Sorry, I tried. :-)

Posted on September 19th, 2009.

Cameron said:

Thank you for a great blog, I will be sure to bookmark your site and check back later :)

Posted on September 22nd, 2009.

Alani said:

Thank you for a great blog, I will be sure to bookmark your site and check back later :)

Posted on September 27th, 2009.

Arely said:

Really great blog here. Thanks! :)

Posted on September 27th, 2009.

Trisha A. said:

Seems like you really took your time on this. Keep up the good work! :)

Posted on October 2nd, 2009.

Chaim said:

I am really glad I found this blog. Great Job! :)

Posted on October 3rd, 2009.

Brady said:

I was going to write a similar blog concerning this topic, you beat me to it. You did a nice job!

Posted on October 7th, 2009.

buyvigrx said:

In searching for sites related to web hosting and specifically comparison hosting linux plan web, your site came up.

Posted on October 9th, 2009.

Laura said:

I was lucky enough to find your website through google. I have been searching all day for this information, Thank You.

Posted on October 10th, 2009.

Pharma590 said:

Very nice site! cheap viagra

Posted on October 25th, 2009.

Pharmc787 said:

Very nice site! [url=http://opxaiey.com/oyyrxry/2.html]cheap cialis[/url]

Posted on October 25th, 2009.

Pharmc535 said:

Very nice site! cheap cialis http://opxaiey.com/oyyrxry/4.html

Posted on October 25th, 2009.

Pharmb324 said:

Very nice site!

Posted on October 25th, 2009.

Taliyah said:

Thanks alot for the great read.

Posted on October 25th, 2009.

John871 said:

Very nice site! is it yours too

Posted on October 29th, 2009.

John871 said:

Very nice site! [url=http://opeyixa.com/qvoxaxa/2.html]is it yours too[/url]

Posted on October 29th, 2009.

John871 said:

Very nice site! is it yours too http://opeyixa.com/qvoxaxa/4.html

Posted on October 29th, 2009.

John871 said:

Very nice site!

Posted on October 29th, 2009.

Savion said:

Good job on your blog.

Posted on October 31st, 2009.

Pharmf134 said:

Very nice site! cheap viagra

Posted on November 3rd, 2009.

Pharme866 said:

Very nice site! [url=http://opeyixa.com/qoxaao/2.html]cheap cialis[/url]

Posted on November 3rd, 2009.

Pharmf663 said:

Very nice site! cheap cialis http://opeyixa.com/qoxaao/4.html

Posted on November 3rd, 2009.

Pharma848 said:

Very nice site!

Posted on November 3rd, 2009.

cheap said:

Hello!
buy cheap phentermine onli ne ,

Posted on November 5th, 2009.

users said:

Hello!
cialis users forum ,

Posted on November 5th, 2009.

to said:

Hello!
places to buy phentermine reviews ,

Posted on November 5th, 2009.

ed said:

Hello!
compare ed medicines cialis and levitra ,

Posted on November 5th, 2009.

Hello!
tramadol indicatii ,

Posted on November 5th, 2009.

Hello!
cheap viagra ,

Posted on November 5th, 2009.

y said:

Hello!
viagra y cialis espa ol ,

Posted on November 6th, 2009.

cialis said:

Hello!
generic cialis from india buying ,

Posted on November 6th, 2009.

pharmacy said:

Hello!
online pharmacy no prescription phentermine ,

Posted on November 6th, 2009.

norbert said:

Hello!
dr norbert seda olmo phentermine ,

Posted on November 6th, 2009.

Hello!
phentermine gnc ,

Posted on November 6th, 2009.

Hello!
no prescription and phentermine in louisiana ,

Posted on November 6th, 2009.

on said:

Hello!
tramadol on line without prescription ,

Posted on November 6th, 2009.

do said:

Hello!
what do phentermine tablets look like ,

Posted on November 6th, 2009.

real said:

Hello!
need real phentermine without rx ,

Posted on November 6th, 2009.

cialis said:

Hello!
generic cialis walmart ,

Posted on November 6th, 2009.

Hello!
drug interactions with tramadol ,

Posted on November 6th, 2009.

Hello!
medical cialis ,

Posted on November 6th, 2009.

cross said:

Hello!
blue cross blue shield massachusetts cialis ,

Posted on November 6th, 2009.

Hello!
order phentermine no rx ,

Posted on November 6th, 2009.

buycialis said:

Hello!
buycialis ,

Posted on November 6th, 2009.

retail said:

Hello!
cialis retail cost ,

Posted on November 6th, 2009.

Hello!
herbal phentermine ultra ,

Posted on November 6th, 2009.

u_cialis said:

Hello!
u cialis ,

Posted on November 6th, 2009.

pros said:

Hello!
cialis pros and cons ,

Posted on November 6th, 2009.

Hello!
cialis herpes ,

Posted on November 6th, 2009.

Hello!
prescription phentermine for sale ,

Posted on November 6th, 2009.

permanent said:

Hello!
cialis permanent blindness ,

Posted on November 6th, 2009.

Hello!
receive phentermine saturday delivery ,

Posted on November 6th, 2009.

weight said:

Hello!
alabama weight loss doctor phentermine ,

Posted on November 6th, 2009.

Hello!
cialis wmv ,

Posted on November 6th, 2009.

pharmacy said:

Hello!
superior pharmacy phentermine online ,

Posted on November 6th, 2009.

Hello!
buy azithromycin doxycycline ,

Posted on November 6th, 2009.

rx said:

Hello!
phentermine rx online consult ,

Posted on November 6th, 2009.

Hello!
buy phenterminemg ,

Posted on November 6th, 2009.

weight said:

Hello!
phentermine weight loss expectancy ,

Posted on November 6th, 2009.

ducation said:

Hello!
attestation ducation sp cialis ,

Posted on November 6th, 2009.

Hello!
buy phentermine no prescription ,

Posted on November 6th, 2009.

and said:

Hello!
nitro and cialis ,

Posted on November 6th, 2009.

Hello!
efeitos colaterais do cialis ,

Posted on November 6th, 2009.

Anonymous said:

Hello!
,

Posted on November 7th, 2009.

Hello!
buy viagra ,

Posted on November 7th, 2009.

Hello!
buy viagra ,

Posted on November 7th, 2009.

Hello!
viagra femminile ,

Posted on November 7th, 2009.

generic said:

Hello!
cialis generic viagra rss feed ,

Posted on November 7th, 2009.

Hello!
cialis dosierung ,

Posted on November 7th, 2009.

cialis said:

Hello!
acheter cialis en pharmacie ,

Posted on November 7th, 2009.

Hello!
order phentermine site post ,

Posted on November 7th, 2009.

between said:

Hello!
difference between cialis and viagra ,

Posted on November 7th, 2009.

leg said:

Hello!
cialis leg pain ,

Posted on November 7th, 2009.

Hello!
cheapest phentermine online free shipping ,

Posted on November 7th, 2009.

Hello!
cialis philippines ,

Posted on November 7th, 2009.

tramadol said:

Hello!
can tramadol be abused ,

Posted on November 7th, 2009.

with said:

Hello!
tramadol with ativan ,

Posted on November 7th, 2009.

results said:

Hello!
better results break phentermine half ,

Posted on November 7th, 2009.

found said:

Hello!
ve found the best place where you can buy phentermine online ,

Posted on November 7th, 2009.

Hello!
generic phentermine diet pills ,

Posted on November 7th, 2009.

viagra said:

Hello!
cialis viagra board ,

Posted on November 7th, 2009.

free said:

Hello!
diet free phentermine pill ,

Posted on November 7th, 2009.

Hello!
cheapest cialis ,

Posted on November 7th, 2009.

tramadol said:

Hello!
ultram tramadol uses ,

Posted on November 7th, 2009.

order said:

Hello!
10 order tramadol ,

Posted on November 7th, 2009.

Hello!
new phentermine cheap phentermine diet ,

Posted on November 7th, 2009.

to said:

Hello!
tip to purchase phentermine online ,

Posted on November 7th, 2009.

cialis said:

Hello!
generic cialis without a prescription ,

Posted on November 7th, 2009.

cialis said:

Hello!
cheap cialis pharmacy online ,

Posted on November 7th, 2009.

pharmacy said:

Hello!
canada pharmacy tramadol ,

Posted on November 7th, 2009.

and said:

Hello!
tramadol and diarrhea ,

Posted on November 7th, 2009.

pharmacy said:

Hello!
tramadol pharmacy reviews has not posted any announcements ,

Posted on November 7th, 2009.

fact said:

Hello!
cialis fact sheet ,

Posted on November 7th, 2009.

Hello!
cialis cupons ,

Posted on November 7th, 2009.

with said:

Hello!
cialis with viagra ,

Posted on November 7th, 2009.

brand said:

Hello!
cialis brand verses generic cialis ,

Posted on November 7th, 2009.

enanthate said:

Hello!
testosterone enanthate cialis ,

Posted on November 7th, 2009.

Hello!
real phentermine no dr prescription needed ,

Posted on November 7th, 2009.

tech said:

Hello!
pharmacy tech cheap tramadol ,

Posted on November 7th, 2009.

Hello!
propecia tinnitus ,

Posted on November 7th, 2009.

pills said:

Hello!
tramadol pills no rx needed ,

Posted on November 7th, 2009.

Hello!
cheapfioricet1r ,

Posted on November 7th, 2009.

overnight said:

Hello!
adipex overnight phentermine ,

Posted on November 7th, 2009.

tramadol said:

Hello!
cheap tramadol sales us ,

Posted on November 7th, 2009.

propecia said:

Hello!
buy propecia without prescription ,

Posted on November 7th, 2009.

Hello!
ranitidine tramadol ,

Posted on November 7th, 2009.

Hello!
no prescription phentermine shipped fed ex ,

Posted on November 7th, 2009.

Hello!
cialis prescripti ,

Posted on November 7th, 2009.

Hello!
buy phentermine e check ,

Posted on November 7th, 2009.

of said:

Hello!
mg of phentermine ,

Posted on November 7th, 2009.

Hello!
phentermine integrarx ,

Posted on November 7th, 2009.

why said:

Hello!
cialis why seperate tubs ,

Posted on November 7th, 2009.

compounds said:

Hello!
chemical compounds of xanax ,

Posted on November 7th, 2009.

hgh said:

Hello!
xenical hgh phentermine quit smoking ,

Posted on November 7th, 2009.

or said:

Hello!
viagra or cialis ,

Posted on November 7th, 2009.

term said:

Hello!
long term tramadol over use effects ,

Posted on November 7th, 2009.

Hello!
tramadol prescription ,

Posted on November 7th, 2009.

Leave a Reply

You must be logged in to post a comment.