Friday, October 28, 2016

VirtualBox Command Line


List of those Vms
$ VBoxManage list vms 

View the VMs that are running at the moment
$ VBoxManage list runningvms

Detailed list of running vms
$ VBoxManage list -l runningvms

Check the supported OS types
$ VBoxManage list ostypes...

Install ubuntu16.04 (64 bit)
$ VBoxManage createvm --name ubuntu16.04 --ostype Linux_64 --register

Show current settings of the VM

$ VBoxManage showvminfo  ubuntu16.04



Memory and cpus configuration

$ VBoxManage modifyvm ubuntu16.04 --cpus 2 --memory 2048 --vram 12 
memory size is mb

Get Memory Information
$ VBoxManage showvminfo ubuntu16.04 | grep "Memory size"
Memory size:     2048MB


Configuring a Virtual Network Adapter




$ VBoxManage modifyvm ubuntu16.04 --nic1 bridged --bridgeadapter1 eth0
$ VBoxManage modifyvm ubuntu16.04 --nic2 bridged --bridgeadapter2 eth1

To remove the network interface vboxnet0, execute the following command
VBoxManage modifyvm "vm" --nic5 none
add hostonly Network


VBoxManage modifyvm "vm" --hostonlyadapter5 vboxnetX
VBoxManage modifyvm "vm" --nic5 hostonly

result


Attaching Virtual Media to a VM




$ VBoxManage createhd --filename /path/to/hard_drive_image/OracleLinux6Test.vdi --size 5120 --variant Standard 



Note:
stantard = dyanmic
fix = fix amount of harddisk
$ VBoxManage modifyhd --filename /path/to/hard_drive_image/OracleLinux6Test.vdi --size 10240 --variant Standard 



if above not working, you will can try below
vboxmanage modifyhd /media/data-6/edx-platform/ubuntu-16.04/ubuntu16.04.vdi --resize 20480



VMDK is not native to vbox. So we need to convert it to vdi format. Then we will can resize harddisk
VBoxManage clonehd "source.vmdk" "cloned.vdi" --format vdi
VBoxManage modifyhd "cloned.vdi" --resize 51200
VBoxManage clonehd "cloned.vdi" "resized.vmdk" --format vmdk



add a storage controller to be used with that hard disk:
$ VBoxManage storagectl ubuntu16.04 --name "SATA Controller" --add sata --bootable on

Finally, you need to attach the hard disk to the controller:
$ VBoxManage storageattach ubuntu16.04 --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium /path/to/hard_drive_image/OracleLinux6Test.vdi

If two harddisk contain same uuid, erro will be show up. We will need to set new uuid to each harddisk.

VBoxManage internalcommands sethduuid "/home/user/VirtualBox VMs/drupal/drupal.vhd"


Attache iso file to boot the guest os
VBoxManage.exe storageattach ubuntu16.04 --storagectl IDE --port 0 --device 0 --type dvddrive --medium "X:\Folder\containing\the.iso"

Detached iso file from guest os
$ VBoxManage storageattach ubuntu16.04 --storagectl "IDE Controller" --port 0 --device 0 --type dvddrive --medium none 

Installing a Guest OS into a VM


Adding an IDE controller for the CD/DVD drive.
$ VBoxManage storagectl ubuntu16.04 --name "IDE Controller" --add ide
Connecting the VM's virtual CD/DVD drive to the physical CD/DVD drive on the host computer:
$ VBoxManage storageattach ubuntu16.04 --storagectl "IDE Controller" --port 0  --device 0 --type dvddrive --medium host:/dev/dvd 
Get information related to the VM's IDE controller:
$ VBoxManage showvminfo ubuntu16.04 | grep "IDE Controller"
Start the guest installation
$ VBoxManage startvm OracleLinux6Test 


Starting a VM on a Headless Server (without gui)

$ VBoxManage modifyvm ubuntu16.04 --vrde on 

$ VBoxManage showvminfo testMachine | grep VRDEVRDE:  enabled (Address 0.0.0.0, Ports 3389, MultiConn: off, ReuseSingleConn: off, Authentication type: null)
VRDE property: TCP/Ports  = "3389"
VRDE property: TCP/Address = <not set>
...
VRDE Connection:    not active

Setup VM for remote access,

$ VBoxManage startvm ubuntu16.04 --type headlessWaiting for VM "OracleLinux6Test" to power on...
VM "OracleLinux6Test" has been successfully started.

Switch off by physical computer:
$ VBoxManage controlvm ubuntu16.04 acpipowerbutton
Switch off by computer's power button:
$ VBoxManage controlvm ubuntu16.04 poweroff 
Finally, since the OS is installed in the guest, you can remove the DVD from the VM configuration:
$ VBoxManage storageattach ubuntu16.04 --storagectl "IDE Controller" --port 0 --device 0 --type dvddrive --medium none 

Run guest OS without GUI
VBoxManage startvm ubuntu-server --type headless

clone vdi
boxmanage clonevm ubuntu16.04 --name ubuntu16.04clone

file location : /home/edu/VirtualBox Vms/ubuntu16.04clone/

vboxmanage registervm /media/kolwin/A/vmbox/ubuntu16.04clone/ubuntu16.04clone.vbox 

remove
VBoxManage unregistervm <uuid>|<name> [--delete]

Create vmdk drives that read from real drives




VBoxManage internalcommands createrawvmdk \
    -filename /path/to/file.vmdk \
    -rawdisk /dev/sda
After virtual harddisk created, we should add it to the vbox
settings --> storage --> add harddisk --> locate .vmdk file


Troubleshooting
can't mount physical harddisk

verr_error_access

check permition of harddisk

/dev/sdb* ls -l
change sudo chmod 666 /dev/sdb5
attached storage



change uuid in harddisk
VBoxManage internalcommands sethduuid "/home/user/VirtualBox.vdi (vmdk)

If you trouble with using right ctl to toggal mouse pointer, here is the solution

hdd delete
vboxmanage closemedium disk <uuid> --delete



Reference:
https://community.oracle.com/docs/DOC-890092

No comments:

Post a Comment