LoginSignup
50
53

More than 5 years have passed since last update.

KVM に virt-install でコマンドラインだけで CentOS 7 を インストール

Last updated at Posted at 2015-01-02

ホストもゲストも CentOS 7 で試しています。


CentOS 7 の ISO を適当なディレクトリにダウンロードします。

cd /iso
wget http://ftp.riken.jp/Linux/centos/7.0.1406/isos/x86_64/CentOS-7.0-1406-x86_64-Minimal.iso

ネットワークインストールすれば ISO 無しでもインストール可能ですが、かなり時間かかるので LAN 内にミラーを設けているとかでない限りは ISO 使ったほうが良いと思います。

次に KickStart ファイルを作成します。

cat <<EOS> /tmp/centos7.ks.cfg
#version=RHEL7

install
cdrom
text
cmdline
skipx

lang en_US.UTF-8
keyboard --vckeymap=jp106 --xlayouts=jp
timezone Asia/Tokyo --isUtc --nontp

network --activate --bootproto=dhcp --noipv6

zerombr
bootloader --location=mbr

clearpart --all --initlabel
part / --fstype=xfs --grow --size=1 --asprimary --label=root

rootpw --plaintext password
auth --enableshadow --passalgo=sha512
selinux --disabled
firewall --disabled
firstboot --disabled

reboot

%packages
%end
EOS

virt-install でゲストに CentOS 7 をインストールします。

virt-install \
  --name centos7 \
  --hvm \
  --virt-type kvm \
  --ram 1024 \
  --vcpus 1 \
  --arch x86_64 \
  --os-type linux \
  --os-variant rhel7 \
  --boot hd \
  --disk pool=default,size=5,format=qcow2 \
  --network network=default \
  --graphics none \
  --serial pty \
  --console pty \
  --location /iso/CentOS-7.0-1406-x86_64-Minimal.iso \
  --initrd-inject /tmp/centos7.ks.cfg \
  --extra-args "inst.ks=file:/centos7.ks.cfg console=ttyS0"

インストールのメッセージがだらーっと流れていきます。

しばらく待って、ログインプロンプトが表示されたらインストール完了です。


↑の例ではストレージプールを使っているのでディスクイメージを作成する手順はありません。

ストレージプールを使わないのであれば qemu-img でディスクイメージを作成し、

qemu-img create -f qcow2 /var/lib/libvirt/images/centos7.img 5G

次のようにディスクイメージを指定します。

virt-install \
  --name centos7 \
  --hvm \
  --virt-type kvm \
  --ram 1024 \
  --vcpus 1 \
  --arch x86_64 \
  --os-type linux \
  --os-variant rhel7 \
  --boot hd \
  --disk /var/lib/libvirt/images/centos7.img \
  --network network=default \
  --graphics none \
  --serial pty \
  --console pty \
  --location /iso/CentOS-7.0-1406-x86_64-Minimal.iso \
  --initrd-inject /tmp/centos7.ks.cfg \
  --extra-args "inst.ks=file:/centos7.ks.cfg console=ttyS0"
50
53
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
50
53