Guest User

Untitled

a guest
Nov 17th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. # Find your VM name
  2. VBoxManage list vms
  3. VMNAME="YOUR_VM_NAME"
  4.  
  5. # Get VM disk path.
  6. VMDISK1=$(VBoxManage showvminfo "${VMNAME}" --machinereadable | grep -E '^\"SATA' | head -n1 | cut -d'=' -f2 | sed -e 's/^"//' -e 's/"$//')
  7.  
  8. # Convert disk to VDI
  9. if [ "${VMDISK##*.}" != "vdi" ]; then
  10. VMDISK2="${VMDISK1%%.*}.$(cat /dev/urandom | env LC_CTYPE=C tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1).vdi"
  11. VBoxManage clonemedium "${VMDISK1}" "${VMDISK2}" --format VDI
  12.  
  13. # Attach new disk
  14. VMDISK_INFO=$(VBoxManage showvminfo "${VMNAME}" --machinereadable | grep -E '^\"SATA' | head -n1 | cut -d'=' -f1 | sed -e 's/^"//' -e 's/"$//')
  15. VMDISK_CONTROLLER=$(echo "${VMDISK_INFO}" | cut -d'-' -f1)
  16. VMDISK_PORT=$(echo "${VMDISK_INFO}" | cut -d'-' -f2)
  17. VMDISK_DEVICE=$(echo "${VMDISK_INFO}" | cut -d'-' -f3)
  18.  
  19. VBoxManage storageattach "${VMNAME}" \
  20. --storagectl "${VMDISK_CONTROLLER}" \
  21. --port "${VMDISK_PORT}" \
  22. --device "${VMDISK_DEVICE}" \
  23. --type hdd \
  24. --medium "${VMDISK2}"
  25. else
  26. VMDISK2="${VMDISK1}"
  27. fi
  28.  
  29. # Resize disk
  30. VBoxManage modifymedium "${VMDISK2}" --resize NEW_SIZE
  31.  
  32. # Resize primary partition with GParted Live CD.
Add Comment
Please, Sign In to add comment