CentOS 7のKVMで仮想マシンを作成

Contents

 

CentOS 7 にKVMをインストールしたので、基本的なオプションでCUIインストールできるか確認します。
今回はDHCPで簡単に設定しようと思うので、KVMインストール時に自動で作成されるブリッジインターフェースvirbr0(NAT)を無効にしていた場合は有効にしておきます。

virbr0の有効と自動起動

[root@localhost ~]# virsh net-start default
[root@localhost ~]# virsh net-autostart default
[root@localhost ~]# virsh net-list --all
 Name                 State      Autostart     Persistent
----------------------------------------------------------
 default              active     yes           yes

[root@localhost ~]# brctl show
bridge name     bridge id               STP enabled     interfaces
br10            8000.6805ca181bbc       no              bond0.10
br11            8000.6805ca181bbc       no              bond0.11
virbr0          8000.525400bbef66       yes             virbr0-nic

 

ISOファイルの配置

ローカルに配置したISOファイルからインストールをするため、ISOファイルを配置しておきます。

/var/lib/libvirt/images/CentOS-7-x86_64-Minimal-1511.iso

 

インストール

  1. virt-install
    [root@localhost ~]# virt-install \
    --name centos7 \
    --hvm \
    --os-variant=rhel7 \
    --ram 1024 \
    --vcpu=1 \
    --graphics none \
    --disk=/var/lib/libvirt/images/centos7,format=qcow2,size=10,bus=virtio \
    --location=/var/lib/libvirt/images/CentOS-7-x86_64-Minimal-1511.iso \
    --extra-args 'console=ttyS0,115200n8'
  2. "Installation"の画面で必要な項目を設定します。
    ================================================================================
    ================================================================================
    Installation
    
     1) [x] Language settings                 2) [!] Timezone settings
            (English (United States))                (Timezone is not set.)
     3) [!] Installation source               4) [!] Software selection
            (Processing...)                          (Processing...)
     5) [!] Installation Destination          6) [x] Kdump
            (No disks selected)                      (Kdump is enabled)
     7) [ ] Network configuration             8) [!] Root password
            (Not connected)                          (Password is not set.)
     9) [!] User creation
            (No user will be created)
      Please make your choice from above ['q' to quit | 'b' to begin installation |
      'r' to refresh]:
    
    [anaconda] 1:main* 2:shell  3:log  4:storage-lo> Switch tab: Alt+Tab | Help: F1
  3. 今回は1~9をすべて登録したので[x]の表示になっています。"b"キー入力して、Enterキーでインストールが始まります。
    ================================================================================
    ================================================================================
    Installation
    
     1) [x] Language settings                 2) [x] Timezone settings
            (English (United States))                (Asia/Tokyo timezone)
     3) [x] Installation source               4) [x] Software selection
            (Local media)                            (Minimal Install)
     5) [x] Installation Destination          6) [x] Kdump
            (Automatic partitioning selecte          (Kdump is enabled)
            d)                                8) [x] Root password
     7) [x] Network configuration                    (Password is set.)
            (Wired (eth0) connected)
     9) [x] User creation
            (Administrator defuser will be
            created)
      Please make your choice from above ['q' to quit | 'b' to begin installation |
      'r' to refresh]:
    [anaconda] 1:main* 2:shell  3:log  4:storage-lo> Switch tab: Alt+Tab | Help: F1
  4. 最後に"Installation complete.  Press return to quit"が表示されたらEnterキーで、プロント表示まで進みます。
    ...(省略)...
    Configuring installed system
    .
    Writing network configuration
    .
    Creating users
    .
    Configuring addons
    .
    Generating initramfs
    .
    Running post-installation scripts
    .
            Use of this product is subject to the license agreement found at /usr/share/centos-release/EULA
    
            Installation complete.  Press return to quit
    [anaconda] 1:main* 2:shell  3:log  4:storage-lo> Switch tab: Alt+Tab | Help: F1
    
    ↓
    Enterキー押す
    ↓
    
    [  OK  ] Started Command Scheduler.
             Starting Command Scheduler...
             Starting Wait for Plymouth Boot Screen to Quit...
             Starting Terminate Plymouth Boot Screen...
    [  OK  ] Started Network Manager.
             Starting Network Manager Wait Online...
    [    7.844669] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
    
    CentOS Linux 7 (Core)
    Kernel 3.10.0-327.el7.x86_64 on an x86_64
    
    centos7 login:
  5. ログインしてIPアドレスを確認してみるとDHCPで割り当てられているっぽい。
    [root@centos7 ~]# ip addr | grep inet | grep -v inet6
        inet 127.0.0.1/8 scope host lo
        inet 192.168.122.72/24 brd 192.168.122.255 scope global dynamic eth0
  6. [Ctrl]+"]"キーで仮想マシンから一度抜けます。物理ホストから仮想マシンを確認します。
    [root@localhost ~]# virsh list --all
     Id    Name                           State
    ----------------------------------------------------
     8     centos7                        running
  7. 作成した仮想マシンにデフォルトのブリッジインターフェース(NAT)が割り当てられていることを確認
    [root@localhost ~]# virsh dumpxml centos7 | grep network
        <interface type='network'>
          <source network='default' bridge='virbr0'/>

 

仮想マシンからはGatewayにpingも通って、yumでインストールもできました。検証用途で使用するときはこれで十分ですが、対話入力が面倒なのでkickstartは用意しておきたいですね。

 

参考
仮想マシン作成#1