Skip to content

Instantly share code, notes, and snippets.

@vrthra
Created September 30, 2022 08:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vrthra/2036ea460780423be6eeb3e2413ca2ff to your computer and use it in GitHub Desktop.
Save vrthra/2036ea460780423be6eeb3e2413ca2ff to your computer and use it in GitHub Desktop.
Resizing Ubuntu Vagrant VM
unless Vagrant.has_plugin?("vagrant-disksize")
raise Vagrant::Errors::VagrantError.new, "vagrant-disksize plugin is missing. Please install it using 'vagrant plugin install vagrant-disksize' and rerun 'vagrant up'"
end
Vagrant.configure("2") do |config|
config.vm.box = "bento/ubuntu-20.04"
config.disksize.size = '400GB'
config.vm.provision "shell", inline: <<-SHELL
ROOT_DISK_DEVICE="/dev/sda"
ROOT_DISK_DEVICE_PART="/dev/sda3"
LV_PATH=`lvdisplay -c | sed -n 1p | awk -F ":" '{print $1;}'`
FS_PATH=`df / | sed -n 2p | awk '{print $1;}'`
ROOT_FS_SIZE=`df -h / | sed -n 2p | awk '{print $2;}'`
echo "The root file system (/) has a size of $ROOT_FS_SIZE"
echo "> Increasing disk size of $ROOT_DISK_DEVICE to available maximum"
sgdisk -e $ROOT_DISK_DEVICE
sgdisk -d 3 $ROOT_DISK_DEVICE
sgdisk -N 3 $ROOT_DISK_DEVICE
partprobe $ROOT_DISK_DEVICE
pvresize $ROOT_DISK_DEVICE_PART
lvextend -l 100%VG $LV_PATH
resize2fs -p $FS_PATH
pvresize $ROOT_DISK_DEVICE_PART
ROOT_FS_SIZE=`df -h / | sed -n 2p | awk '{print $2;}'`
echo "The root file system (/) has a size of $ROOT_FS_SIZE"
apt-get update
apt-get -y install ca-certificates curl gnupg lsb-release
mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
apt-get update
apt-get -y install docker-ce docker-ce-cli containerd.io docker-compose-plugin
groupadd docker
usermod -aG docker vagrant
newgrp docker
systemctl enable docker.service
systemctl enable containerd.service
service docker start
docker run hello-world
SHELL
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment