Search This Blog

Friday, January 7, 2011

Basic tutorial on Virtual Box 4.0 command line

to start a virtual machine in GUI-less mode with Remote Desktop on:
VBoxManage startvm "WinXP" --type headless

to force poweroff:
VBoxManage controlvm "WinXP" poweroff

to register VM in VBox from predefined XML under certain user (active username):
VBoxManage registervm /root/.VirtualBox/Machines/WinXP/WinXP2.xml

to attach a VDI drive:
VBoxManage storageattach "WinXP2" --storagectl "IDE Controller" –type hdd --port 0 --device 0 --medium "/VMVirt/XP/2.vdi"

to clone a virtual drive (VDI) and change its UUID:
VBoxManage clonehd "full_path_in" "full_path_out"

convert drive to Fixed size (e.g. From growable type):
VBoxManage clonehd "full_path_in_vmdk" "full_path_out_vdi" --format VDI --variant Fixed

to change UUID of existing VDI drive:
VBoxManage internalcommands setvdiuuid somthing.vdi

to „hibernate” a virtual machine:
VBoxManage controlvm "VMTOMEK" savestate

to prevent machine from updating time/date from host:
VBoxManage setextradata "VMTOMEK" "VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled" "1"

to run a command inside VM:
VBoxManage guestcontrol execute TC8 "C:\Windows\system32\notepad.exe" --username Administrator --password sys --verbose --wait-for stdout

to unmount current media:
VBoxManage storageattach <vmname> --device <number> --medium emptydrive
(or use --forceunmount if this does not work)
VBoxManage storageattach Debby --storagectl "IDE Controller" --device 0 --port 0 --type dvddrive --medium emptydrive

to mount media:
VBoxManage storageattach Debby --storagectl "IDE Controller" --device 0 --port 0 --type dvddrive --medium cd351a5b-a09b-4593-bf6f-e892def83aa9

to list dvd and get their uuids:
VBoxManage list dvds
VBoxManage list vms

Some self-explaining commands:
VBoxManage showvminfo "WinXP"
VBoxManage list vms
VBoxManage list runningvms
VBoxManage modifyvm "WinXP" --bioslogodisplaytime 10000
VBoxManage modifyvm "VM name" --vrdp on
VBoxManage snapshot "WinXP2" take "Snap1" –description "Initial snapshot"
VBoxManage snapshot "WinXP2" restore "Snap1"
VBoxmanage showhdinfo Ubuntu.vdi

7 comments:

  1. Hi

    How can i read/set the description of a VM via the commandline?

    BR Andreas

    ReplyDelete
  2. You can use:
    VBoxManage showvminfo YOUR_VM_NAME --details

    then look for a row:
    "Description:"

    ReplyDelete
  3. Thx

    And for setting?

    BR Andreas

    ReplyDelete
  4. Hi Bartosz

    Do you find the requested command?
    I need it for my Webmin Modul:
    http://sourceforge.net/projects/webmin/files

    BR Andreas

    ReplyDelete
  5. Actually I was trying to help you the last time with no luck :/ When I set/read VM properties in my project VBoxCloner I edit XML VM description files. This is sometimes easier. You have to remember, though, that these XMLs are in native language. That's why I always have my GUI set to english and advise users to do to the same.


    VBoxCloner

    VBox cloner on my blog

    ReplyDelete
  6. Hi Bartosz

    Ok, i will use this way :-)

    BR Andreas

    ReplyDelete
  7. Compact (defragment and delete null space) the hard drive (VDI or VMDK):

    VBoxManage modifyhd C:\folder\hardrive.vdi --compact

    REMEMBER - it has to be a full path to the *.vdi path!

    ReplyDelete

If you like this post, please leave a comment :)