LoginSignup
21
20

More than 5 years have passed since last update.

VagrantのVMに複数のディスクを追加する方法

Last updated at Posted at 2016-07-04

Vagrantにはvagrant-persistent-storageという便利なプラグインがありますが、複数のディスク追加はまだサポートしてないようです。そんなことをしたい人はなかなかいないと思うのですが、ごく稀に、例えばCephやLustreを手元でテストしたい場合にはメタデータ用とオブジェクト用に複数のディスクが必要になります。

ということで似たような目的がある方は下記のVagrantfileをご参考にどうぞ。

Vagrantfile

このVagrantfileは50GBの/dev/sdbと100GBの/dev/sdcを追加してVMを立ち上げてくれます。

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure(2) do |config|

  config.vm.box = "ubuntu/trusty64"

  config.vm.provider :virtualbox do |p|
    #
    # ディスクを1つ追加する
    #
    p.customize [
      'createmedium', 'disk',
      '--filename', "/tmp/sdb.vdi",
      '--format', 'VDI',
      '--size', 50 * 1024]
    p.customize [
      'storageattach', :id,
      '--storagectl', 'SATAController',
      '--port', 1,
      '--device', 0,
      '--type', 'hdd',
      '--medium', "/tmp/sdb.vdi"]
    #
    # portcountをディスクの数だけ増やす(例:2つ)
    #
    p.customize [
      'storagectl', :id,
      '--name', 'SATAController',
      '--portcount', 2]
    #
    # 2つ目のディスクを追加する
    #
    p.customize [
      'createmedium', 'disk',
      '--filename', "/tmp/sdc.vdi",
      '--format', 'VDI',
      '--size', 100 * 1024]
    p.customize [
      'storageattach', :id,
      '--storagectl', 'SATAController',
      '--port', 2,
      '--device', 0,
      '--type', 'hdd',
      '--medium', "/tmp/sdc.vdi"]
  end

end

補足

--storagectlの値は使うboxによって異なります。僕が知る限りでもSATAControllerSATA ControllerSATAとさまざまですが、下記の手順で調べることができます。

# ひとまず追加ディスク無しでvmを立ち上げます。
vagrant up

# vmのidを調べます。
VBoxManage list vms

# 例えばidが"837b8fb9-3a03-4ca4-916d-d5481bb5141b"の場合、
# 下記のコマンドでコントローラの名前を表示することができます。
VBoxManage showvminfo 837b8fb9-3a03-4ca4-916d-d5481bb5141b|grep "Storage Controller Name"

参考リンク

21
20
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
21
20