LoginSignup
0
1

More than 5 years have passed since last update.

Vagrantfileで大きめのストレージを作る方法

Posted at

概要

Vagrant経由のVMで作業したいけど、大きめのディスク容量を確保したい。
予め判っているなら、Vagrantfileで済ませたい。そういうこと、まれによくある
マウント手順も怪しいのでメモ。本当はもっとスマートにしたかったけど知識が足りない。

初心者なもんですから、何でもかんでもメモっておきたくて。

環境

  • Vagrant 1.7.4
  • VirtualBox 5.0.10
  • CentOS 7.1

手順

Vagrantfile

Vagrantfileに下記を追記します

Vagrantfile
  config.vm.provider :virtualbox do |vb|
    file_to_disk = "./disk1.vdi"
    unless File.exist?(file_to_disk)
      vb.customize ['createhd', '--filename', file_to_disk, '--format', 'VDI', '--size', 20 * 1024, '--variant', 'Standard']
      vb.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', file_to_disk]
    end
  end

ssh

fdisk -l を実行し、/dev/sdb が表示されることを確認します

sh
# fdisk -l

fdisk /dev/sdb を実行し、対話式で下記の通り操作します

sh
# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x60b67fe0.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-41943039, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): 
Using default value 41943039
Partition 1 of type Linux and of size 20 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

mkfs を実行後、マウントポイントを作成します

sh
# mkfs -t ext4 /dev/sdb1
# mkdir /disk1

/etc/fstab の末尾に下記を追記します

/etc/fstab
/dev/sdb1 /disk1 ext4 defaults 0 0

マウントします

sh
mount -a

以上

0
1
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
0
1