Xen Setup · 3 min read · Feb 09, 2026
Debian Sargeのための完璧なXen 3.0.3セットアップ - ページ7
5.2 仮想マシンを作成する (domU)
(注意: 画像の作成は、ソースからXenをインストールしたか、バイナリからインストールしたかによって異なります。ソースからXenをインストールした場合は、4.4章を参照してください!)
次に、仮想マシンのイメージを作成します。これは基本的なDebianシステムになります。このイメージは、すべての仮想マシンのテンプレートとなります。新しい仮想マシンを作成したいときは、このイメージをコピーし、新しいXen設定ファイルを作成してコピーをブートし、その後、コピーを必要に応じて設定できます(例: メールサーバー、ウェブサーバー、DNSサーバーなどをインストールする)。すべてのイメージは、私たちが持っている中で最も大きな/vserverパーティションに保存されます。
mkdir /vserver/vm_base
mkdir /vserver/images次に、1 GBのイメージファイルと500 MBのスワップイメージを作成します。最終的に、仮想マシンは1 GBのスペースと500 MBのスワップを持ちます。これは単なる例の値であり、実際には仮想マシンにもっと多くのスペースが必要になるかもしれません(例: 5 GBから30 GBの間)。そのため、より大きなイメージを作成するためにcountの値を増やしてください。
dd if=/dev/zero of=/vserver/images/vm_base.img bs=1024k count=1000
dd if=/dev/zero of=/vserver/images/vm_base-swap.img bs=1024k count=500次に、/vserver/images/vm_base.imgをext3でフォーマットし、vm_base-swap.imgをスワップでフォーマットします:
mkfs.ext3 /vserver/images/vm_base.img次のメッセージが表示されたら、yで応答してください:
/vserver/images/mail.img is not a block special device.
Proceed anyway? (y,n) <-- ymkswap /vserver/images/vm_base-swap.img5.2.1 イメージに基本的なDebianをインストールする
基本的なDebianシステムをイメージにインストールするために、イメージをマウントし、debootstrapといくつかのコマンドを実行します:
mount -o loop /vserver/images/vm_base.img /vserver/vm_base
debootstrap --arch i386 sarge /vserver/vm_base/ http://ftp2.de.debian.org/debianchroot /vserver/vm_base
apt-setup次の質問が表示されます:
Archive access method for apt: <– http
次に、あなたの近くのミラーを選択します。
その後、/etc/apt/sources.listを編集し、testingをstableに置き換えます。私の/etc/apt/sources.listは次のようになります:
vi /etc/apt/sources.list| deb http://ftp2.de.debian.org/debian/ stable main deb-src http://ftp2.de.debian.org/debian/ stable main deb http://security.debian.org/ stable/updates main |
次に、実行します
apt-get update今、ロケールを設定します。これを今行わないと、base-config中に次のような醜い警告が表示されます:
| perl: warning: Setting locale failed. perl: warning: Please check that your locale settings: LANGUAGE = "en_DE:en_US:en_GB:en", LC_ALL = (unset), LANG = "en_US" are supported and installed on your system. perl: warning: Falling back to the standard locale ("C"). locale: Cannot set LC_CTYPE to default locale: No such file or directory locale: Cannot set LC_MESSAGES to default locale: No such file or directory locale: Cannot set LC_ALL to default locale: No such file or directory |
それらは深刻ではありませんが、醜いです… だから、私たちは実行します
apt-get install localeconfいくつかの質問が表示されます:
Select locales to be generated. <– en_US ISO-8859-1
Which locale should be the default in the system environment? <– en_US
Manage locale configuration files with debconf? <– Yes
Environment settings that should override the default locale: <– do not select anything
Replace existing locale configuration files? <– Yes
Default system locale: <– e.g. en_US ISO-8859-1
次に実行します
base-configインストールオプションのメニューが表示されます。私たちが行うことは次のとおりです:
- タイムゾーンを設定する
- ユーザーとパスワードを設定する
- パッケージを選択してインストールする(Choose software to install:の時に、好きなものを選択できますが、私は基本的なシステムをインストールしたいので何も選択しません。)
- 基本システムの設定を完了する
他のメニュー項目には関与しないでください。必要ありません。次に、nfs-commonを削除し、/etc/hostnameを削除します:
apt-get remove nfs-common次に、/etc/fstabを編集します。次のようになります:
vi /etc/fstab| /dev/hda1 / ext3 defaults 1 2 /dev/hda2 none swap sw 0 0 /dev/pts devpts gid=5,mode=620 0 0 none /dev/shm tmpfs defaults 0 0 |
次に、/etc/hostsを作成します:
vi /etc/hosts| 127.0.0.1 localhost.localdomain localhost # The following lines are desirable for IPv6 capable hosts ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters ff02::3 ip6-allhosts |
次に、次のようにします:
mkdir /lib/modules/2.6.16.29-xen
depmod 2.6.16.29-xen次に、スクリプト/etc/init.d/hwclock.shと/etc/init.d/hwclockfirst.shを編集し、最初にexit 0の行を追加します。そうしないと、これらの2つのスクリプトが仮想マシンの起動を本当に遅くしてしまいます:
vi /etc/init.d/hwclock.sh| #!/bin/sh # hwclock.sh Set and adjust the CMOS clock, according to the UTC # setting in /etc/default/rcS (see also rcS(5)). # # Version: @(#)hwclock.sh 2.00 14-Dec-1998 [email protected] # # Patches: # 2000-01-30 Henrique M. Holschuh <[email protected]> # - Minor cosmetic changes in an attempt to help new # users notice something IS changing their clocks # during startup/shutdown. # - Added comments to alert users of hwclock issues # and discourage tampering without proper doc reading. # WARNING: Please read /usr/share/doc/util-linux/README.Debian.hwclock # before changing this file. You risk serious clock # misbehaviour otherwise. exit 0 [...] |
vi /etc/init.d/hwclockfirst.sh| #!/bin/bash # hwclockfirst.sh Set system clock to hardware clock, according to the UTC # setting in /etc/default/rcS (see also rcS(5)). # # WARNING: Runs without write permission on /etc, and before # mounting all filesystems! If you need write permission # to do something, do it in hwclock.sh. # # WARNING: If your hardware clock is not in UTC/GMT, this script # must know the local time zone. This information is # stored in /etc/localtime. This might be a problem if # your /etc/localtime is a symlink to something in # /usr/share/zoneinfo AND /usr isn't in the root # partition! The workaround is to define TZ either # in /etc/default/rcS, or in the proper place below. # # REMEMBER TO EDIT hwclock.sh AS WELL! # Set this to any options you might need to give to hwclock, such # as machine hardware clock type for Alphas. exit 0 HWCLOCKPARS= [...] |
今、chroot環境を出ます:
exit次に、イメージをアンマウントします:
mv /vserver/vm_base/lib/tls /vserver/vm_base/lib/tls.disabled
fuser -k /vserver/vm_base
umount /vserver/vm_baseこれで、仮想マシンイメージのテンプレートが準備完了です!
新しい投稿を受信箱で受け取る
スパムはありません。いつでも購読を解除できます。