Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Find your VM name
- VBoxManage list vms
- VMNAME="YOUR_VM_NAME"
- # Get VM disk path.
- VMDISK1=$(VBoxManage showvminfo "${VMNAME}" --machinereadable | grep -E '^\"SATA' | head -n1 | cut -d'=' -f2 | sed -e 's/^"//' -e 's/"$//')
- # Convert disk to VDI
- if [ "${VMDISK##*.}" != "vdi" ]; then
- VMDISK2="${VMDISK1%%.*}.$(cat /dev/urandom | env LC_CTYPE=C tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1).vdi"
- VBoxManage clonemedium "${VMDISK1}" "${VMDISK2}" --format VDI
- # Attach new disk
- VMDISK_INFO=$(VBoxManage showvminfo "${VMNAME}" --machinereadable | grep -E '^\"SATA' | head -n1 | cut -d'=' -f1 | sed -e 's/^"//' -e 's/"$//')
- VMDISK_CONTROLLER=$(echo "${VMDISK_INFO}" | cut -d'-' -f1)
- VMDISK_PORT=$(echo "${VMDISK_INFO}" | cut -d'-' -f2)
- VMDISK_DEVICE=$(echo "${VMDISK_INFO}" | cut -d'-' -f3)
- VBoxManage storageattach "${VMNAME}" \
- --storagectl "${VMDISK_CONTROLLER}" \
- --port "${VMDISK_PORT}" \
- --device "${VMDISK_DEVICE}" \
- --type hdd \
- --medium "${VMDISK2}"
- else
- VMDISK2="${VMDISK1}"
- fi
- # Resize disk
- VBoxManage modifymedium "${VMDISK2}" --resize NEW_SIZE
- # Resize primary partition with GParted Live CD.
Add Comment
Please, Sign In to add comment