Vagrant で仮想マシンを構築する(6) 仮想マシンの設定

Vagrant で起動した仮想マシンのホスト名や cpu 数、メモリサイズなどの設定方法です。
変更頻度が高めの項目に絞っています。
プロバイダは VirtualBox です。

ホスト名

仮想マシン os のホスト名を設定します。

Vagrant.configure(2) do |config|
  config.vm.hostname = "vm-host01"
end

vm

VirtualBoxGUI ツールで表示される vm 名を設定します。

Vagrant.configure(2) do |config|
  config.vm.provider "virtualbox" do |vb|
    vb.name = "vm-host01"
  end
end

cpu 数

仮想マシンの cpu 数(コア数)を設定します。

Vagrant.configure(2) do |config|
  config.vm.provider "virtualbox" do |vb|
    vb.cpus = 2
  end
end

メモリサイズ

仮想マシンのメモリサイズを設定します。

Vagrant.configure(2) do |config|
  config.vm.provider "virtualbox" do |vb|
    vb.memory = 1024
  end
end

その他、設定

VBoxManage modifyvm の項目は設定可能です。

cpu の使用率制限設定は、以下の感じです。

Vagrant.configure(2) do |config|
  config.vm.provider "virtualbox" do |vb|
    vb.customize ["modifyvm", :id, "--cpuexecutioncap", "50"]
  end
end

config.vm - Vagrantfile - Vagrant Documentation
Configuration - VirtualBox Provider - Vagrant Documentation