Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jj-meyer/a9d878b004542e825b47 to your computer and use it in GitHub Desktop.
Save jj-meyer/a9d878b004542e825b47 to your computer and use it in GitHub Desktop.
# Resize a vagrant box disk from an existing base box

[Also see scotch.io] (https://scotch.io/tutorials/how-to-create-a-vagrant-base-box-from-an-existing-one)

Build vagrant box from an existing one

cd homestead
vagrant package --output ../boxes/homestead.box
vagrant box add homestead_100gb ../boxes/homestead.box
cd ..
mkdir homestead_100gb
vagrant init # or copy VagrantFile from somewhere else and change config.vm.box to "homestead_100gb"
vagrant up # to confirm that it works
vagrant destroy

Resize the .vmdk image

cd ~/.vagrant.d/boxes/homestead_100gb/0/virtualbox
VBoxManage clonehd "box-disk1.vmdk" "clone-disk1.vdi" --format vdi
VBoxManage modifyhd "clone-disk1.vdi" --resize 102400
VBoxManage showhdinfo "clone-disk1.vdi"
VBoxManage clonehd "clone-disk1.vdi" "box-disk1.vmdk" --format vmdk
mv box-disk2.vmdk box-disk1.vmdk
rm clone-disk1.vdi

Resize the physical partitions on the virtual machine

vagrant up
vagrant ssh
sudo su -
fdisk /dev/sda
#[ 
#Press p to print the partition table to identify the number of partitions. By default there are two - sda1 and sda2.
#Press n to create a new primary partition.
#Press p for primary.
#Press 3 for the partition number, depending the output of the partition table print.
#Press Enter two times to accept the default First and Last cylinder.
#Press t to change the system's partition ID
#Press 3 to select the newly creation partition
#Type 8e to change the Hex Code of the partition for Linux LVM
#Press w to write the changes to the partition table. 
#Press q to quit
#]

partprobe
fdisk /dev/sda
#[ p q ]
reboot
vagrant ssh
sudo su -

fdisk /dev/sda
#[ p q ]
pvcreate /dev/sda3
# confirm that the volume groups's name is vagrant--vg-root
ls -al /dev/mapper/
vgdisplay

# extend the physical and logical drives
vgextend vagrant-vg /dev/sda3
lvextend -l +100%FREE /dev/mapper/vagrant--vg-root
resize2fs /dev/mapper/vagrant--vg-root

# confirm that the volume sizes are changed
df -vh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment