sprotheroe / vagrant-disksize

Vagrant plugin to resize disks in VirtualBox
MIT License
479 stars 52 forks source link

Disk resized, but /dev/sda hasn't increased #37

Open ghost opened 4 years ago

ghost commented 4 years ago

Without using this plugin, the default size for /dev/sda is 9.2G using a Debian Jessie box.

I installed the plugin and set a disk size of 15G. It looks like the disk size has been increased, when I run fdisk -l I get Disk /dev/sda: 15 GiB, 16106127360 bytes, 31457280 sectors

But running df -h shows

Filesystem                                             Size  Used Avail Use% Mounted on
/dev/sda1                                              9.2G  1.6G  7.2G  18% /

I tried deleting all partitions, and making a new sda1 with the 15GB, but when I saved and rebooted, I could no longer SSH into the box

mehdmehd commented 4 years ago

I got same problem.

I try an alternative way to modify disk size : issue

cd ~/.vagrant.d/boxes/ubuntu-VAGRANTSLASH-trusty64/20150609.0.9/virtualbox/ VBoxManage clonehd box-disk1.vmdk tmp-disk.vdi --format vdi VBoxManage modifyhd tmp-disk.vdi --resize 61440 VBoxManage clonehd tmp-disk.vdi resized-disk.vmdk --format vmdk rm tmp-disk.vdi box-disk1.vmdk mv resized-disk.vmdk box-disk1.vmdk

And same problem subsists.

PolarGoose commented 4 years ago

@mehdmehd and @paul-gene, this plugin only changes physical size of the disk. It doesn't expand logical volumes. That is why "df -h" command output doesn't change. When you use this plugin you can see the following message in the log during "vagrant up" command: "You may need to resize the filesystem from within the guest." First, check that VirtualBox, in the storage settings of your virtual machine, shows the desired size of your hard disk. If the size is correct, it means that the plugin has done its job.

The procedure of resizing logical volumes may differ depending on the vagrant box you use. I can recommend you to look at How to automatically resize virtual box disk with vagrant. For example, for "hashicorp/bionic64" your Vagrant file can look like this:

Vagrant.configure("2") do |config|
  config.vm.box = "hashicorp/bionic64"

  # Extend disk size
  config.disksize.size = '200GB'
  config.vm.provision "shell", inline: <<-SHELL
    parted /dev/sda resizepart 1 100%
    pvresize /dev/sda1
    lvresize -rl +100%FREE /dev/mapper/vagrant--vg-root
  SHELL
end
clbarnes commented 3 years ago

I was using the above snippet on bento/ubuntu-18.04 for some time; I've just updated to bento/ubuntu-20.04 (and also tried ubuntu/focal64) and it doesn't seem to work (vagrant 2.2.15, manjaro).

    your-vm: Warning: Partition /dev/sda1 is being used. Are you sure you want to continue?

    your-vm:   0 physical volume(s) resized or updated / 0 physical volume(s) not resized
    your-vm:   Failed to find physical volume "/dev/sda1".
    your-vm:   Volume group "vagrant-vg" not found
    your-vm:   Cannot process volume group vagrant-vg

I've also tried piping echo yes and just yes into pvresize.

gabrielsebag commented 1 year ago

@clbarnes I know it's late, but for those that are facing the same issue, here's the snippet that works on bento/ubuntu-20.04 :

Vagrant.configure(2) do |config|
  config.vm.box = 'bento/ubuntu-20.04'
  config.disksize.size = '100GB'

  config.vm.provision "shell", inline: <<-SHELL
    sudo sgdisk /dev/sda -e
    sudo parted /dev/sda resizepart 3 100%
    sudo pvresize /dev/sda3
    sudo lvextend -r -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
    sudo resize2fs -p /dev/mapper/ubuntu--vg-ubuntu--lv
  SHELL
end

@PolarGoose Snippet doesn't work on bento/ubuntu-20.04 because the partitions names and indexes have changed. The script has to be tweaked a bit to work again with that ubuntu version.

I think that you can update the script for any OS. You can find partitions names and indexes using the process described on the following article : https://medium.com/@kanrangsan/how-to-automatically-resize-virtual-box-disk-with-vagrant-9f0f48aa46b3

Hope that it helps.