Fedora 23でFedora Cloudイメージをvagrant-libvirtで動かすメモ

Vagrantlibvirt使えるならそっちのほうが便利だよなーというところで、まずは軽くお試しを。 Fedoralibvirt providerのインストールに関しては最近公開されたFedora Developer PotalのVagrant with libvirt support installationにあるとおりで、dnfコマンドでvagrant-libvirtパッケージをインストールすれば依存関係諸々含めてインストールできます。

sudo dnf install vagrant-libvirt


Vagrantのboxイメージはどうしよかなというところですが、まあ、Fedora23のイメージで行くかーってことで、Fedora Cloudのページから適当なlibvirt/kvmのイメージをダウンロードします。ここではBase Imagesのタブにあるlibvirt/KVM イメージをダウンロードしました。

ここから先は普通のVagrantの使い方と一緒ですね。Fedora 22での場合のやり方がfedora MagazineのRunning Vagrant on Fedora 22という記事にあります。

最初にvagrant initして、

masami@saga:~/codes/fedora-vagrant$ vagrant init
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.


  # Every Vagrant development environment requires a box. You can search for
 14   # boxes at https://atlas.hashicorp.com/search.
 15   config.vm.box = "fedora23"

vagrant box addでboxファイルをadd。

masami@saga:~/codes/fedora-vagrant$ vagrant box add Fedora-Cloud-Base-Vagrant-23-20151030.x86_64.vagrant-libvirt.box --name fedora23
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'fedora23' (v0) for provider:
    box: Unpacking necessary files from: file:///home/masami/codes/fedora-vagrant/Fedora-Cloud-Base-Vagrant-23-20151030.x86_64.vagrant-libvirt.box
==> box: Successfully added box 'fedora23' (v0) for 'libvirt'!

vagrant box listで確認。

masami@saga:~/codes/fedora-vagrant$ vagrant box list
fedora23 (libvirt, 0)

そして、vagrant up。

masami@saga:~/codes/fedora-vagrant$ vagrant up
Bringing machine 'default' up with 'libvirt' provider...
==> default: Creating image (snapshot of base box volume).
==> default: Creating domain with the following settings...
==> default:  -- Name:              fedora-vagrant_default
==> default:  -- Domain type:       kvm
==> default:  -- Cpus:              1
==> default:  -- Memory:            512M
==> default:  -- Base box:          fedora23
==> default:  -- Storage pool:      default
==> default:  -- Image:             /var/lib/libvirt/images/fedora-vagrant_default.img
==> default:  -- Volume Cache:      default
==> default:  -- Kernel:
==> default:  -- Initrd:
==> default:  -- Graphics Type:     vnc
==> default:  -- Graphics Port:     5900
==> default:  -- Graphics IP:
==> default:  -- Graphics Password: Not defined
==> default:  -- Video Type:        cirrus
==> default:  -- Video VRAM:        9216
==> default:  -- Keymap:            en-us
==> default:  -- Command line :
==> default: Creating shared folders metadata...
==> default: Starting domain.
==> default: Waiting for domain to get an IP address...
==> default: Waiting for SSH to become available...
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Configuring and enabling network interfaces...
==> default: Rsyncing folder: /home/masami/codes/fedora-vagrant/ => /vagrant

vagrant sshでログインできることを確認。

masami@saga:~/codes/fedora-vagrant$ vagrant ssh
[vagrant@localhost ~]$ uname -a
Linux localhost 4.2.3-300.fc23.x86_64 #1 SMP Mon Oct 5 15:42:54 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux




masami@saga:~/codes/fedora-vagrant$ vagrant box remove fedora23
Removing box 'fedora23' (v0) with provider 'libvirt'...
Vagrant-libvirt plugin removed box only from you LOCAL ~/.vagrant/boxes directory
From libvirt storage pool you have to delete image manualy(virsh, virt-manager or by any other tool)

実践 Vagrant

実践 Vagrant