例: Fedora イメージ

この例は、Fedora イメージのインストール方法を説明します。おもに Fedora 25 を対象にしています。Fedora のインストールプロセスはバージョンにより異なる可能性があるため、違うバージョンの Fedora を使用している場合、インストール手順が異なる可能性があります。

Fedora インストール ISO のダウンロード

  1. Visit the Fedora download site.

  2. Navigate to the Download Fedora Server page for a Fedora Server ISO image.

  3. Choose the ISO image you want to download.

    For example, the Netinstall Image is a good choice because it is a smaller image that downloads missing packages from the Internet during installation.

インストールプロセスの開始

すでに説明したように、コマンド virt-managervirt-install を使用して、インストールプロセスを開始します。 virt-install コマンドを使用する場合、必ず VNC クライアントを仮想マシンに接続してください。

以下を前提としています。

  • 仮想マシンイメージの名前は fedora です。 virsh コマンドを使用してイメージの状態を操作する際に、この名前が必要になります。

  • ネットワークインストール ISO イメージは /tmp ディレクトリーに保存されています。

virt-install をコマンド使用する場合、このコマンドは以下のようになるでしょう。

# qemu-img create -f qcow2 /tmp/fedora.qcow2 10G
# virt-install --virt-type kvm --name fedora --ram 1024 \
  --disk /tmp/fedora.qcow2,format=qcow2 \
  --network network=default \
  --graphics vnc,listen=0.0.0.0 --noautoconsole \
  --os-type=linux --os-variant=fedora23 \
  --location=/tmp/Fedora-Server-netinst-x86_64-25-1.3.iso

インストールのステップ実行

After the installation program starts, choose your preferred language and click Continue to get to the installation summary. Accept the defaults.

Review the Ethernet status

Ensure that the Ethernet setting is ON. Additionally, make sure that IPv4 Settings' Method is Automatic (DHCP), which is the default.

ホスト名

インストーラーでは、ホスト名を入力できます。デフォルトの localhost.localdomain が良いでしょう。後ほど cloud-init パッケージをインストールします。これにより、このイメージを使用して展開された新規インスタンスの起動時に、ホスト名が設定されます。

ディスクのパーティション作成

ディスクのパーティションは、さまざまな選択肢があります。デフォルトでは、LVM パーティションが使用され、3 つのパーティション (/boot/swap) が作成されます。これでうまく動作します。この代わりに、単一の ext4 パーティション を作成し、 / にマウントしたい場合もあるでしょう。これもうまく動作します。

よくわからない場合、インストーラーのデフォルトのパーティション設定を使用します。基本的には、他のスキーマより良くありませんが、最終パーティションに動的リサイズできるパーティションを作成することにより、他のパーティションの境界をまたがることなくリサイズできます。

Select software to install

デフォルトのオプションを使用して、インストールをステップ実行します。最も簡単な方法は、「最小インストール (Minimal Install)」インストールを選択することです。SSH サーバーがインストールされます。

Set the root password

During the installation, remember to set the root password when prompted.

CD-ROM の取り出しと再起動

Wait until the installation is complete.

virsh コマンドを使用して、ディスクを取り出すために、CD-ROM が前に接続されていた場所と同じ場所に、libvirt が空のディスクを接続する必要があります。この場所は、 hda でしょう。 virsh dumpxml vm-image コマンドを使用して、適切な接続先を確認できます。

# virsh dumpxml fedora
<domain type='kvm' id='30'>
  <name>fedora</name>
...
    <disk type='file' device='cdrom'>
      <driver name='qemu' type='raw'/>
      <source file='/tmp/Fedora-Server-netinst-x86_64-25-1.3.iso'/>
      <backingStore/>
      <target dev='hda' bus='ide'/>
      <readonly/>
      <alias name='ide0-0-0'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>
...
</domain>

virsh を使用して、ディスクを取り出し、再起動するために、ホストから root として以下のコマンドを実行します。 virt-manager を使用している場合、以下のコマンドを使用することもできますが、GUI を使用して、ディスクを切断し、手動で停止および起動を実行することもできます。

# virsh attach-disk --type cdrom --mode readonly fedora "" hda
# virsh reboot fedora

ACPI サービスのインストール

ハイパーバイザーがインスタンスを再起動やシャットダウンできるようにするために、ゲストシステムに acpid サービスをインストールし実行しておく必要があります。

Log in as root to the Fedora guest and run the following commands to install the ACPI service and configure it to start when the system boots:

# dnf install acpid
# systemctl enable acpid

メタデータ取得の cloud-init の設定

インスタンスは、起動時にいくつかの処理を実行するために、メタデータサービスと通信する必要があります。例えば、インスタンスが SSH 公開鍵を取得し、ユーザーデータエージェントを実行する必要があります。インスタンスが確実にこれらの処理を実行するために、 cloud-init パッケージを使用します。

The cloud-init package automatically fetches the public key from the metadata server and places the key in an account. Install cloud-init inside the Fedora guest by running:

# yum install cloud-init

アカウントはディストリビューションにより異なります。 Fedora 系の仮想マシンの場合、アカウントは fedora という名前です。

You can change the name of the account used by cloud-init by editing the /etc/cloud/cloud.cfg file and adding a line with a different user. For example, to configure cloud-init to put the key in an account named admin, use the following syntax in the configuration file:

users:
  - name: admin
    (...)

パーティションのリサイズをサポートするための cloud-utils-growpart のインストール

In order for the root partition to properly resize, install the cloud-utils-growpart package, which contains the proper tools to allow the disk to resize using cloud-init.

# dnf install cloud-utils-growpart

zeroconf ルートの無効化

インスタンスがメタデータサービスにアクセスできるようにするために、デフォルトの zeroconf ルートを無効化する必要があります。

# echo "NOZEROCONF=yes" >> /etc/sysconfig/network

コンソールの設定

nova console-log コマンドが Fedora で正しく動作させるためには、以下の作業が必要な場合があります。

  1. /etc/default/grub ファイルを編集し、 GRUB_CMDLINE_LINUX オプションを設定します。 rhgb quiet を削除し、オプションに console=tty0 console=ttyS0,115200n8 を追加します。

    ...
    GRUB_CMDLINE_LINUX="rd.lvm.lv=fedora/root rd.lvm.lv=fedora/swap console=tty0 console=ttyS0,115200n8"
    
  2. 以下のコマンドを実行し、設定を反映します。

    # grub2-mkconfig -o /boot/grub2/grub.cfg
    Generating grub configuration file ...
    Found linux image: /boot/vmlinuz-4.10.10-200.fc25.x86_64
    Found initrd image: /boot/initramfs-4.10.10-200.fc25.x86_64.img
    Found linux image: /boot/vmlinuz-0-rescue-c613978614c7426ea3e550527f63710c
    Found initrd image: /boot/initramfs-0-rescue-c613978614c7426ea3e550527f63710c.img
    done
    

インスタンスのシャットダウン

インスタンス内で root として以下を実行します。

# poweroff

クリーンアップ (MAC アドレスの詳細の削除)

オペレーティングシステムは、インストール中に仮想 Ethernet カードの MAC アドレスを /etc/sysconfig/network-scripts/ifcfg-eth0 などの場所に記録します。しかしながら、イメージが起動するたびに、仮想 Ethernet カードの MAC アドレスは別の値になります。そのため、この情報は設定ファイルから削除する必要があります。

virt-sysprep というユーティリティーがあります。これは、MAC アドレス参照の削除など、さまざまなクリーンアップ作業を実行します。決まった場所にある仮想マシンイメージをクリーンアップします。

# virt-sysprep -d fedora

libvirt ドメインの定義削除

これで、イメージを Image service にアップロードできます。今後は、この仮想マシンイメージは libvirt により管理する必要がありません。virsh undefine vm-image コマンドを使用して libvirt に通知します。

# virsh undefine fedora

イメージの完成

The underlying image file that you created with the qemu-img create command is ready to be uploaded. For example, you can upload the /tmp/fedora.qcow2 image to the Image service by using the openstack image create command. For more information, see the python-openstackclient command list.