Managing Disk Storage
1. Checking Disk Usage
| Command | Description | Notes |
|---|---|---|
| vagrant status | Shows the current state of all Vagrant boxes | Includes disk usage info in the output |
| vagrant global-status | Lists all Vagrant environments and their status | Useful for checking disk usage across multiple boxes |
| vagrant box list | Lists all downloaded Vagrant boxes | Shows size of each box image |
2. Resizing VM Disk
| Command | Description | Notes |
|---|---|---|
| vagrant resize | Resize the disk of a running VM | Available in Vagrant 2.3.0+ |
Note: The
vagrant resize command requires the vagrant-disksize plugin to be installed.
Warning: Resizing the disk may require a reboot of the VM to apply changes.
Summary of Steps
- Install the
vagrant-disksizeplugin usingvagrant plugin install vagrant-disksize - Run
vagrant resize disk --size <new-size>to resize the disk - Reboot the VM if necessary to apply changes
3. Attaching Additional Disks
| Option | Values | Description |
|---|---|---|
| config.vm.synced_folder | "/path/to/host/folder" |
Maps a folder from the host machine to the guest |
| config.vm.disk | "disk1" |
Defines a new disk to be attached |
Example: Attach Additional Disk
vagrant<span>.</span>config<span>.</span>vm<span>.</span>disk <span>do</span> |disk|
disk<span>.</span>name = "data"
disk<span>.</span>size = "10GB"
disk<span>.</span>type = "vdi"
<span>end</span>
Note: The disk must be created and attached via VirtualBox or another provider before it can be used in Vagrant.
4. Configuring Disk Controllers
| Property | Description | Default | Notes |
|---|---|---|---|
| disk.controller | Specifies the type of disk controller to use | ide |
Valid options: ide, sata, scsi, virtio |
| disk.size | Size of the virtual disk in MB or GB | 10240 |
Example: 50GB or 2048MB |
| disk.type | Specifies the disk type (e.g., vdi, vmdk) |
vdi |
Supported formats depend on the provider (VirtualBox, VMware, etc.) |
Example: Configuring Disk Controller in Vagrantfile
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/focal64"
# Configure disk controller and size
config.vm.provider "virtualbox" do |vb|
vb.customize ["storagectl", :id, "--name", "SATA", "--controller", "IntelAHCI"]
vb.customize ["createhd", "--filename", "disk.vdi", "--size", 10240]
vb.customize ["storageattach", :id, "--storagectl", "SATA", "--attach", "disk.vdi"]
end
end
Note: The
storagectl and createhd commands are specific to VirtualBox. Other providers like VMware or Libvirt may require different configuration methods.
5. Using SATA vs IDE Controllers
| Controller Type | Performance | Compatibility | Notes |
|---|---|---|---|
| SATA | High | Modern | Default for most VMs, better I/O performance |
| IDE | Low | Legacy | Backward compatibility for older systems |
Example: Setting SATA Controller in Vagrantfile
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/focal64"
config.vm.provider "virtualbox" do |vb|
vb.customize ["storagectl", "<VM_NAME>", "--name", "SATA", "--controller", "IntelAHCI"]
end
end
Example: Setting IDE Controller in Vagrantfile
Vagrant.configure("2") do |config|
config.vm.box = "centos/7"
config.vm.provider "virtualbox" do |vb|
vb.customize ["storagectl", "<VM_NAME>", "--name", "IDE", "--controller", "PIIX4"]
end
end
6. Setting Disk Size
| Option | Values | Notes |
|---|---|---|
| config.vm.disk | size |
Set the size of the disk in MB, GB, or TB |
| config.vm.disk | name |
Name of the disk (optional) |
Example: Setting Disk Size
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/focal64"
config.vm.disk size: "20GB", name: "primary"
end
Note: The disk size setting is only available in Vagrant 2.2.0 and later versions.
7. Managing Snapshot Storage
| Command | Description | Options |
|---|---|---|
| vagrant snapshot save | Saves a snapshot with the given name | --force to overwrite existing snapshot |
| vagrant snapshot list | Lists all snapshots for the current VM | None |
| vagrant snapshot go | Restores the VM to a specific snapshot | --no-destroy to avoid destroying the VM before restore |
| vagrant snapshot delete | Deletes a specific snapshot | --force to delete without confirmation |
| vagrant snapshot restore | Restores the VM to the last saved snapshot | None |
Note: Snapshots are stored in the
.vagrant/ directory and can be used to quickly revert a VM to a previous state.
Warning: Snapshots do not persist across Vagrant box updates or changes to the Vagrantfile.
8. Cleaning Up Old Boxes
| Command | Description | Notes |
|---|---|---|
| vagrant box remove <box-name> | Removes a specific box from the local system | Can specify by name or provider |
| vagrant box remove --force <box-name> | Removes a box without confirmation | Use with caution |
Note: Removing a box will delete all associated files from the local storage. Ensure that no running Vagrant environments depend on this box before removal.
9. Removing Unused Disks
| Command | Description | Notes |
|---|---|---|
| vagrant box remove | Removes a box from the local system | Use with caution as this removes the base box image |
| vagrant box list | Lists all downloaded boxes | Use to identify which boxes to remove |
Note: Removing a box will not affect running VMs that are using it, but new VMs will need to re-download the box.
10. Optimizing Disk I/O
| Option | Values | Description |
|---|---|---|
| config.vm.synced_folder | ["/host/path", "/guest/path", { "type": "nfs" }] |
Use NFS for faster I/O in development environments |
| config.vm.synced_folder | ["/host/path", "/guest/path", { "type": "rsync" }] |
Use rsync for better performance with large files |
| config.vm.synced_folder | ["/host/path", "/guest/path", { "type": "virtualbox" }] |
Default VirtualBox shared folder implementation |
Example: NFS Synced Folder Configuration
Vagrant.configure("2") do |config|
config.vm.synced_folder "/host/data", "/guest/data", type: "nfs"
end
Example: Rsync Synced Folder Configuration
Vagrant.configure("2") do |config|
config.vm.synced_folder "/host/data", "/guest/data", type: "rsync"
end
Note: NFS requires additional setup on the host machine and is not available on all platforms.
Warning: Rsync is slower for frequent file changes but efficient for large files.