Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resizing disk space on vagrant box

I'd like to give my box some more disk space. I'm trying to do this through the vagrantfile as follows:

Vagrant::Config.run do |config|
    # ..
    config.vm.customize ["modifyvm", :id, "--memory", 1024]
    config.vm.customize ["modifyhd", :id, "--resize", 4096]
end

This gives me the error:

A customization command failed:
["modifyhd", "e87d8786-88be-4805-9c2a-45e88b8e0e56", "--resize", "4096"]

The following error was experienced:

VBoxManage: error: The given path 'e87d8786-88be-4805-9c2a-45e88b8e0e56' is not fully qualified
VBoxManage: error: Details: code VBOX_E_FILE_ERROR (0x80bb0004), component Medium, interface IMedium, callee nsISupports
VBoxManage: error: Context: "OpenMedium(Bstr(pszFilenameOrUuid).raw(), enmDevType, enmAccessMode, fForceNewUuidOnOpen, pMedium.asOutParam())" at line 178 of file VBoxManageDisk.cpp


Please fix this customization and try again.

I'm trying to piece the information together from http://docs.vagrantup.com/v1/docs/config/vm/customize.html http://www.virtualbox.org/manual/ch08.html#vboxmanage-modifyvdi

like image 632
schellsan Avatar asked Feb 17 '13 02:02

schellsan


People also ask

Can you resize VirtualBox disk?

VirtualBox 6 added a graphical option for resizing virtual disks. You can find it at the file tab of VirtualBox home page. Select one of your virtual machines in the list, click on Properties from the top and then use the “Size” slider or type the size value that you need. Once done click “Apply”.

How do I resize a VM disk?

Select a virtual machine in the Virtual Machine Library window and click Settings. In the Settings window, click the hard disk you want to resize. Use the Disk size slider to set the new size. The maximum disk size for any hard disk is 8TB.


2 Answers

You are sending modifyhd the UUID of the VM (provided by vagrant) while it expects the UUID of the VDI. You will need to use the absolute path to the actual VDI file or its UUID. You can use the following command to get the UUID of the VDI: VBoxManage showhdinfo <filename> (see virtualbox - how to check what is the uuid of a vdi?)

like image 181
Dror Bereznitsky Avatar answered Oct 22 '22 19:10

Dror Bereznitsky


I created a new disk, added and extended the older.

My Vagrantfile:

Vagrant.configure(2) do |config|
config.vm.box = "bseller/oracle-standard"
config.vm.define :oracle do |oracle| 
  oracle.vm.hostname = 'oraclebox'
  oracle.vm.synced_folder ".", "/vagrant", owner: "oracle", group: "oinstall" 
  oracle.vm.network :private_network, ip: '192.168.33.13'
  oracle.vm.network :forwarded_port, guest: 1521, host: 1521
  oracle.vm.provider :virtualbox do |vb|
     vb.customize ["modifyvm", :id, "--memory", "4096"]
     vb.customize ["modifyvm", :id, "--name", "oraclebox"]
     if !File.exist?("disk/oracle.vdi")
       vb.customize [
            'createhd', 
            '--filename', 'disk/oracle', 
            '--format', 'VDI', 
            '--size', 60200
            ] 
       vb.customize [
            'storageattach', :id, 
            '--storagectl', "SATA", 
            '--port', 1, '--device', 0, 
            '--type', 'hdd', '--medium', 'disk/oracle.vdi'
            ]
     end     
  end
  oracle.vm.provision "shell", path: "shell/add-oracle-disk.sh"
  oracle.vm.provision "shell", path: "shell/provision.sh"
end
end

This will create new disk in

disk
    |-- oracle.vdi
shell
    |-- provision.sh
Vagrantfile

and add in your box. The new disk is of 60GB My shell provision.sh

set -e
set -x

if [ -f /etc/disk_added_date ] ; then
   echo "disk already added so exiting."
   exit 0
fi

sudo fdisk -u /dev/sdb <<EOF
n
p
1


t
8e
w
EOF

sudo pvcreate /dev/sdb1
sudo vgextend VolGroup /dev/sdb1
sudo lvextend -L50GB /dev/VolGroup/lv_root
sudo resize2fs /dev/VolGroup/lv_root
date > /etc/disk_added_date

This script was adapted from SHC to box bseller/oracle-standard. For full code, see my project oraclebox in GitHub

like image 3
acfreitas Avatar answered Oct 22 '22 20:10

acfreitas