-
Notifications
You must be signed in to change notification settings - Fork 0
/
resize-vm-disk
executable file
·50 lines (37 loc) · 1.33 KB
/
resize-vm-disk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
set -e
set -x
# adapted from: https://gist.github.com/christopher-hopper/9755310
# Prereq: VirtualBox installed, Vagrant VM provisioned but not currently running
export VM_NAME=$1
export DESIRED_SIZE=$2
export KILL_OLD_VMDK=$3
# whine if $VM_NAME is blank
if [ "$VM_NAME" = "" ]; then
echo "Must specify the name of your Vagrant VM whose disk you wish to resize!"
exit 1
fi
# default $DESIRED_SIZE to 102400 (100GB)
if [ "$DESIRED_SIZE" = "" ]; then
export DESIRED_SIZE=102400
fi
# default $KILL_OLD_VMDK to "no"
if [ "$KILL_OLD_VMDK" = "" ]; then
export KILL_OLD_VMDK="no"
fi
# switch to vm path
pushd ~/VirtualBox\ VMs/$VM_NAME
# clone .vmdk to .vdi
VBoxManage clonehd "ubuntu-xenial-16.04-cloudimg.vmdk" "clone-disk1.vdi" --format vdi
# resize the .vdi to $DESIRED_SIZE
VBoxManage modifyhd "clone-disk1.vdi" --resize $DESIRED_SIZE
# wire up the resized .vdi to your VM
VBoxManage storageattach $VM_NAME --storagectl "SCSI" --port 0 --device 0 --type hdd --medium clone-disk1.vdi
VBoxManage storageattach jjh-ubuntu-vagrant --storagectl "SCSI" --port 0 --device 0 --type hdd --medium clone-disk1.vdi
# remove the old .vmdk if specified
if [ "$KILL_OLD_VMDK" != "no" ]; then
echo "Deleting ubuntu-xenial-16.04-cloudimg.vmdk as specified"
rm ubuntu-xenial-16.04-cloudimg.vmdk
fi
# jump back to starting dir
popd