2019-03-31 11:00:21 +00:00
---
title: KVM で仮想環境を整えてみる – (4)
author: kazu634
date: 2011-08-02
wordtwit_post_info:
- 'O:8:"stdClass":13:{s:6:"manual";b:0;s:11:"tweet_times";i:1;s:5:"delay";i:0;s:7:"enabled";i:1;s:10:"separation";s:2:"60";s:7:"version";s:3:"3.7";s:14:"tweet_template";b:0;s:6:"status";i:2;s:6:"result";a:0:{}s:13:"tweet_counter";i:2;s:13:"tweet_log_ids";a:1:{i:0;i:5441;}s:9:"hash_tags";a:0:{}s:8:"accounts";a:1:{i:0;s:7:"kazu634";}}'
categories:
- kvm
- linux
---
< div class = "section" >
< p >
KVMでゲストOSをインストールする際に、PXEブート経由でインストールできるように仮想環境を整えてみます。なお、PXEブートを行う際にはDHCPを用いるため、NICはブリッジ接続にする必要があります。
< / p >
< p >
PXEブートの環境構築については、< a href = "http://d.hatena.ne.jp/rin_ne/20100110/1263151973" onclick = "__gaTracker('send', 'event', 'outbound-article', 'http://d.hatena.ne.jp/rin_ne/20100110/1263151973', 'PXEブート環境を作る – 基本は根性ナシな日記');" target = "_blank" > PXEブート環境を作る – 基本は根性ナシな日記< / a > を参考にすると幸せになれます。PXEブートサーバはブリッジ接続したゲストOS の Ubuntu 11.04 で構築しています。
< / p >
< h4 >
パッケージのインストール
< / h4 >
< p >
以下のコマンドを実行します:
< / p >
< pre class = "syntax-highlight" >
$ sudo aptitude < span class = "synSpecial" > -y< / span > < span class = "synStatement" > install< / span > dhcp3-server tftpd-hpa tftp-hpa syslinux nfs-kernel-server
< / pre >
< h4 >
DHCPサーバの設定
< / h4 >
< p >
次のコマンドを実行して設定変更をしていました。なお、アタリマエのことながら、DHCPサーバとなるサーバは IP アドレスを静的に設定している必要があります。
< / p >
< pre class = "syntax-highlight" >
$ < span class = "synStatement" > cd< / span > /etc/dhcp
$ sudo cp < span class = "synSpecial" > -p< / span > dhcpd.conf dhcpd.conf.orig
$ sudo vi dhcpd.conf
$ diff < span class = "synSpecial" > -u< / span > dhcpd.conf.orig dhcpd.conf
--- dhcpd.conf.orig < span class = "synConstant" > 2011-04-20< / span > < span class = "synConstant" > 00< / span > :< span class = "synConstant" > 02< / span > :< span class = "synConstant" > 15< / span > .< span class = "synConstant" > 000000000< / span > < span class = "synSpecial" > +0900< / span >
+++ dhcpd.conf < span class = "synConstant" > 2011-07-12< / span > < span class = "synConstant" > 23< / span > :< span class = "synConstant" > 30< / span > :< span class = "synConstant" > 59< / span > .< span class = "synConstant" > 670034755< / span > < span class = "synSpecial" > +0900< / span >
@@ < span class = "synConstant" > -13< / span > ,< span class = "synConstant" > 8< / span > < span class = "synSpecial" > +13< / span > ,< span class = "synConstant" > 8< / span > @@
ddns-update-style none< span class = "synStatement" > ;< / span >
< span class = "synComment" > # option definitions common to all supported networks...< / span >
-option domain-name < span class = "synStatement" > " < / span > < span class = "synConstant" > example.org< / span > < span class = "synStatement" > " ;< / span >
-option domain-name-servers ns1.example.org, ns2.example.org< span class = "synStatement" > ;< / span >
< span class = "synComment" > +# option domain-name " example.org" ;< / span >
< span class = "synComment" > +# option domain-name-servers ns1.example.org, ns2.example.org;< / span >
default-lease-< span class = "synStatement" > time< / span > < span class = "synConstant" > 600< / span > < span class = "synStatement" > ;< / span >
max-lease-< span class = "synStatement" > time< / span > < span class = "synConstant" > 7200< / span > < span class = "synStatement" > ;< / span >
@@ < span class = "synConstant" > -30< / span > ,< span class = "synConstant" > 6< / span > < span class = "synSpecial" > +30< / span > ,< span class = "synConstant" > 20< / span > @@
< span class = "synComment" > # No service will be given on this subnet, but declaring it helps the< / span >
< span class = "synComment" > # DHCP server to understand the network topology.< / span >
+subnet < span class = "synConstant" > 192< / span > .< span class = "synConstant" > 168< / span > .< span class = "synConstant" > 11< / span > .< span class = "synConstant" > < / span > netmask < span class = "synConstant" > 255< / span > .< span class = "synConstant" > 255< / span > .< span class = "synConstant" > 255< / span > .< span class = "synConstant" > < / span > < span class = "synSpecial" > {< / span >
+ range dynamic-bootp < span class = "synConstant" > 192< / span > .< span class = "synConstant" > 168< / span > .< span class = "synConstant" > 11< / span > .< span class = "synConstant" > 100< / span > < span class = "synConstant" > 192< / span > .< span class = "synConstant" > 168< / span > .< span class = "synConstant" > 11< / span > .< span class = "synConstant" > 250< / span > < span class = "synStatement" > ;< / span >
+
+ option routers ルーターのIPアドレス< span class = "synStatement" > ;< / span >
+ option subnet-mask < span class = "synConstant" > 255< / span > .< span class = "synConstant" > 255< / span > .< span class = "synConstant" > 255< / span > .< span class = "synConstant" > < / span > < span class = "synStatement" > ;< / span >
+ option domain-name-servers DNSサーバのIPアドレス< span class = "synStatement" > ;< / span >
+
+ default-lease-< span class = "synStatement" > time< / span > < span class = "synConstant" > 21600< / span > < span class = "synStatement" > ;< / span >
+ max-lease-< span class = "synStatement" > time< / span > < span class = "synConstant" > 43200< / span > < span class = "synStatement" > ;< / span >
+
< span class = "synComment" > +# next-server 192.168.1.34;< / span >
+ filename < span class = "synStatement" > " < / span > < span class = "synConstant" > pxelinux.0< / span > < span class = "synStatement" > " ;< / span >
+< span class = "synSpecial" > }< / span >
+
< span class = "synComment" > #subnet 10.152.187.0 netmask 255.255.255.0 {</ span >
< span class = "synComment" > #}< / span >
< / pre >
< h4 >
pxelinux.0ファイルをTFTPサーバの公開ディレクトリに
< / h4 >
< p >
TFTPサーバの公開ディレクトリはデフォルトは /var/lib/tftpboot/ です。ここに pxelinux.0 と menu.c32 をコピーします:
< / p >
< pre class = "syntax-highlight" >
$ sudo cp < span class = "synSpecial" > -p< / span > /usr/lib/syslinux/pxelinux.< span class = "synConstant" > < / span > /var/lib/tftpboot/
$ sudo cp < span class = "synSpecial" > -p< / span > /usr/lib/syslinux/menu.c32 /var/lib/tftpboot/
< / pre >
< h4 >
PXEブートイメージを準備する
< / h4 >
< p >
ここでは Ubuntu 11.04 をPXE経由でインストールしてみます。まずは netboot 用のブートイメージをダウンロード、解凍します:
< / p >
< pre class = "syntax-highlight" >
$ < span class = "synStatement" > cd< / span > /tmp
$ wget http://archive.ubuntu.com/ubuntu/dists/natty/main/installer-amd64/current/images/netboot/netboot.tar.gz
$ sudo ar xvzf netboot.tar.gz
< / pre >
< p >
解凍してできたディレクトリを /var/lib/tftpboot にコピーします:
< / p >
< pre class = "syntax-highlight" >
$ sudo < span class = "synStatement" > mv< / span > /tmp/ubuntu-installer /var/lib/tftpboot/ubuntu
< / pre >
< h4 >
ブートイメージ用設定ファイルを作る
< / h4 >
< p >
ブートイメージ用設定ファイルを作成します:
< / p >
< pre class = "syntax-highlight" >
$ sudo < span class = "synStatement" > mkdir< / span > /var/lib/tftpboot/pxelinux.cfg/
$ < span class = "synStatement" > cd< / span > /var/lib/tftpboot/pxelinux.cfg/
$ sudo vi default
$ cat default
DEFAULT menu.c32
PROMPT < span class = "synConstant" > < / span >
NOESCAPE < span class = "synConstant" > < / span >
TIMEOUT < span class = "synConstant" > 150< / span >
TOTALTIMEOUT < span class = "synConstant" > 600< / span >
MENU TITLE PXE Boot Menu
LABEL Boot from Storage
LOCALBOOT < span class = "synConstant" > < / span >
LABEL Ubuntu < span class = "synConstant" > 11< / span > .< span class = "synConstant" > 04< / span >
KERNEL ubuntu/amd64/linux
APPEND < span class = "synIdentifier" > vga< / span > =normal < span class = "synIdentifier" > initrd< / span > =ubuntu/amd64/initrd.gz
< / pre >
< h4 >
動作確認
< / h4 >
< p >
ホストOS側でゲストOSをpxeブートで起動してみます。例えばこんなコマンドを入力します:
< / p >
< pre class = "syntax-highlight" >
$ sudo virt-< span class = "synStatement" > install< / span > < span class = "synSpecial" > --name< / span > puppet < span class = "synSpecial" > --ram< / span > < span class = "synConstant" > 512< / span > < span class = "synSpecial" > --disk< / span > < span class = "synIdentifier" > path< / span > =< span class = "synIdentifier" > puppet.img,size< / span > =< span class = "synConstant" > 10< / span > < span class = "synSpecial" > --vcpus< / span > < span class = "synConstant" > 1< / span > < span class = "synSpecial" > --network< / span > < span class = "synIdentifier" > bridge< / span > =< span class = "synIdentifier" > br0,model< / span > =virtio < span class = "synSpecial" > --graphic< / span > < span class = "synIdentifier" > vnc,listen< / span > =< span class = "synConstant" > < / span > .< span class = "synConstant" > < / span > .< span class = "synConstant" > < / span > .< span class = "synConstant" > < / span > < span class = "synSpecial" > --pxe< / span >
< / pre >
< p >
後は VNC でのぞいていると、 PXE ブートの画面が表示されてくるはずです:
< / p >
< p >
< a href = "http://f.hatena.ne.jp/sirocco634/20110802225350" onclick = "__gaTracker('send', 'event', 'outbound-article', 'http://f.hatena.ne.jp/sirocco634/20110802225350', '');" class = "hatena-fotolife" target = "_blank" > < img src = "http://cdn-ak.f.st-hatena.com/images/fotolife/s/sirocco634/20110802/20110802225350.jpg" alt = "f:id:sirocco634:20110802225350j:image" title = "f:id:sirocco634:20110802225350j:image" class = "hatena-fotolife" / > < / a >
< / p >
2019-04-02 16:06:15 +00:00
< / div >