22

Today I started getting errors on simple operations, like creating small files in vim, the bash completion started to complain as well.

Here is the result of df -h :

vagrant@machine:/vagrant$ df -h
Filesystem                           Size  Used Avail Use% Mounted on
/dev/sda1                             40G   38G  249M 100% /
none                                 4.0K     0  4.0K   0% /sys/fs/cgroup
udev                                 2.0G   12K  2.0G   1% /dev
tmpfs                                396M  396K  395M   1% /run
none                                 5.0M     0  5.0M   0% /run/lock
none                                 2.0G     0  2.0G   0% /run/shm
none                                 100M     0  100M   0% /run/user
overflow                             1.0M  148K  876K  15% /tmp
192.168.50.1:/Users/nha/repo/assets  233G  141G   93G  61% /var/www/assets
vagrant                              233G  141G   93G  61% /vagrant

So apparently / doesn`t have space anymore ? Isn't it weird since I have space in the other filesystems (or am I misreading something) ?

How do I get more space on my vm ?

nha
  • 17,623
  • 13
  • 87
  • 133

4 Answers4

21

Even though you have space on your Guest OS, the VM is limited.There are couple of steps required in order to increase the size of your disk:

first, vagrant haltto close your VM

resize disk

VBoxManage clonehd box-disk1.vmdk box-disk1.vdi --format vdi
VBoxManage modifyhd box-disk1.vdi --resize 50000

start Virtual box and change configuration of the VM to associate the new disk

use fdisk to resize disk

you need to create a new partition with the new space and allocate it, so first start the VM and logged on as super user

vagrant up && vagrant ssh
su -

the command (as illustrated from my instance) are

[root@oracle ~]# fdisk /dev/sda

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): p

Disk /dev/sda: 52.4 GB, 52428800000 bytes
255 heads, 63 sectors/track, 6374 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00041a53

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          39      307200   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              39        2611    20663296   8e  Linux LVM

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (2611-6374, default 2611):
Using default value 2611
Last cylinder, +cylinders or +size{K,M,G} (2611-6374, default 6374):
Using default value 6374

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

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@oracle ~]#

note you might need to change /dev/sda compare to your configuration

create a new partition (again logged on as super user su -)

su -
[root@oracle ~]# pvs
  PV         VG    Fmt  Attr PSize  PFree
  /dev/sda2  linux lvm2 a--  19.70g    0
[root@oracle ~]# pvcreate /dev/sda3
  Physical volume "/dev/sda3" successfully created
[root@oracle ~]# pvs
  PV         VG    Fmt  Attr PSize  PFree
  /dev/sda2  linux lvm2 a--  19.70g     0
  /dev/sda3        lvm2 a--  28.83g 28.83g

[root@oracle ~]# vgextend linux /dev/sda3
  Volume group "linux" successfully extended
[root@oracle ~]# lvextend -l +100%FREE /dev/linux/root
[root@oracle ~]# resize2fs /dev/linux/home
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/linux/home is mounted on /home; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 2
Performing an on-line resize of /dev/linux/home to 7347200 (4k) blocks.
The filesystem on /dev/linux/home is now 7347200 blocks long.
Geo
  • 12,666
  • 4
  • 40
  • 55
Frederic Henri
  • 51,761
  • 10
  • 113
  • 139
  • Sorry I accepted it too fast. I destroyed/rebuilt my machine, and it doesn't work but I now noticed in virtualbox gui that the the virtual size if 40GB but the actual size is 1.33GB. (?) – nha Jul 31 '15 at 14:00
  • @nha, when building the vm, vagrant will not reserve all the space you have allocated for the disk - in your case you define the VM with an hard drive of 40 GB but you're only using 1GB or so, so vagrant/VirtualBox will reserve 1.33 GB and will grow. they can grow until they reach 40GB which is the size limite you have allocated for this hard drive on the VM (if you want its like if the VM had a physical HD of 40GB) when you reach this limit you need to either extend the size limite of the HD attached to the VM (method I gave you) or attach another hard drive – Frederic Henri Jul 31 '15 at 14:06
  • Thank you I understand that. However I am getting errors related to space right now (like when starting mongo, I get "Please make at least 3379MB available in /data/db/journal or use --smallfiles") – nha Jul 31 '15 at 14:11
  • However in my welcome login message I have something like "Usage of /: 96.6% of 39.34GB"... something is wrong isn't it ? – nha Jul 31 '15 at 14:12
  • 2
    indeed, there is something strange. do you have something in /tmp that is eating your space ? – Frederic Henri Jul 31 '15 at 14:16
  • Well I rebuilt the whole thing again and now it works... I'll accept your answer thank you for your help – nha Jul 31 '15 at 14:59
4

You can increase space in your box, without losing data or creating new partitions.

  1. Halt your VM;

  2. Go to /home_dir/VirtualBox VMs

  3. Change file format from .vmdk to .vdi. Then use command from the answer above to increase space.

  4. Change the file extension back and change the file name.

  5. Attach an extended disk to your VM.

    VBoxManage storageattach <your_box_name> --storagectl "IDE Controller" --
    port 0 --device 0 --type hdd --medium new_extended_file.vmdk
    
  6. In your VirtualBox application go to Your_VM -> Settings -> Storage. Click on the controller and choose 'add new disk' below. Choose from existing disks the one you have just expanded.

Here's a step by step instruction how to expand the space in your vagrant box or virtual machine.

Frits
  • 7,341
  • 10
  • 42
  • 60
Ria
  • 158
  • 2
  • 6
4

The easiest way to increase the size of the vagrant box is with the vagrant-disksize plugin.

In your vagrant root folder, run vagrant plugin install vagrant-disksize

Then add the new size to the Vagrantfile:

Vagrant.configure('2') do |config|
  ...
  config.disksize.size = '60GB'
end

Then vagrant halt and vagrant up.
vagrant reload will not work.

I have read that the plugin has issues shrinking disk size if you overshoot.

EDIT:
On Mac, this plugin also resized the partition within the Guest OS (Ubuntu in my case).
On Windows, Vagrant reserves the space on the host OS (it enlarges the disk), but you can't use the space until resizing the partition from within the Guest OS.
I used GParted, but other solutions look simpler, such as: https://nguyenhoa93.github.io/Increase-VM-Partition

SamGoody
  • 13,758
  • 9
  • 81
  • 91
0

I sometimes have to destroy the machine and build it up again which in my case frees up quite a lot of space, you can do that by running

vagrant destroy

vagrant up

Please note this will result in database data being lost.

ii iml0sto1
  • 1,654
  • 19
  • 37