Adding new partition to the existing Vagrant VM
This will be a tutorial about adding new partition to the existing Vagrant (Virtual Box) machine. It should be safe to follow but please backup your data before proceeding.
Use vagrant-disksize plugin from https://github.com/sprotheroe/vagrant-disksize
Installation is easy
Execute inside you Vagrant VM folder:
vagrant plugin install vagrant-disksize
Modify your Vagrantfile according to plugin Usage section:
Vagrant.configure('2') do |config| config.vm.box = 'ubuntu/xenial64' config.disksize.size = '50GB' end
Now the tricky part
If you are not an experienced Linux user it might be not so easy. You will have to create and format new partition using command line.
Enter your Vagrant box
Become root user
sudo su -
Enter partitioning utility
pto check current partitions table (just for your information)
nin order to create new partition
eto create extended (logical) partition
- Select its number (or hit ENTER to leave the default selection which should be OK in most cases)
- Select first sector (or hit ENTER to leave the default number which should be OK in most cases)
- Select last sector (hit ENTER to leave the default number which should ensure that entire available space will be used)
pand check that you have now a new partition (compared to step 1.)
wto save your modifications
After these steps you should see output similar to this one:
The partition table has been altered. Calling ioctl() to re-read partition table. Re-reading the partition table failed.: 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).
You shouldn't worry about
...: Device or resource busy message
Exit your Vagrant box
Yes execute it two times: first one leaves root and second one exits Vagrant.
Restart your Vagrant box
vagrant halt and
vagrant up if you prefer)
You may check with
df -h that your new partition is not currently mounted
Format new partition
Assuming that you new partition is located at
sudo mkfs -t ext4 /dev/sda3
If it asks you about proceeding Proceed anyway? you should probably answer with
Mount your new partition!
sudo mkdir /mnt/new_partition sudo mount /dev/sda3 /mnt/new_partition
So it is now available on
That's it you are done.
Automounting new partition
After setting up new partition you will probably want it to mount on VM startup without need for manual
Check the https://askubuntu.com/a/165462/175659 for info about automount setup using
If you want to play with resizing existing disk please refer to the: https://gist.github.com/christopher-hopper/9755310 and/or (I had no luck with this solution but it might work): https://askubuntu.com/a/116367/175659