VBoxManage control and manage Virtualbox from command line(转)
VBoxManage control and manage Virtualbox from command lineIntroduction
VirtualBox is according to developers:
VirtualBox is a powerful x86 and AMD64/Intel64 virtualization product for enterprise as well as home use. Not only is VirtualBox an extremely feature rich, high performance product for enterprise customers, it is also the only professional solution that is freely available as Open Source Software under the terms of the GNU General Public License (GPL). See “About VirtualBox” for an introduction.
And according to Wikipedia:
Oracle VM VirtualBox is an x86 virtualization software package, originally created by software company innotek GmbH, purchased by Sun Microsystems, and now developed by Oracle Corporation as part of its family of virtualization products. It is installed on an existing host operating system; within this application, additional guest operating systems, each known as a Guest OS, can be loaded and run, each with its own virtual environment.
Supported host operating systems include Linux, Mac OS X, Windows XP, Windows Vista, Windows 7, Solaris, and OpenSolaris; there is also a port to FreeBSD (only OSE version). Supported guest operating systems include a small number NetBSD versions and various versions of Windows, Linux, DragonFlyBSD, FreeBSD, OpenBSD, OS/2 Warp, Solaris, OpenSolaris, Haiku, Syllable, ReactOS, and SkyOS.
From this, we may know that it is a powerful and useful tool, for those trying to test new Operating Systems, or try new configurations on Known Operating Systems. I use it a lot to test new Linux distribution, without the need to install them on my Hard Disk.
Another great use for it, is to have separated servers on the same hardware just to improve security, I mean: Why to have DNS server, FTP server, Web server and all others on the same environment, where an attack to one of these server may compromise all the others, you can install Linux on a good Hardware, and VirtualBox on it, and three or four different virtual machines running Linux to have all those functions mentioned before on different Virtual Machines, thus increasing the security of your configuration.
But, enough talking about this, this will be material of another article, let’s focus on how to manage VirtualBox from the command line, as you usually will do it from the GUI.
List virtual machines from command line
The command we will use for this is VBoxManage and different sub-commands it has, to list the virtual machines installed run:
VBoxManage list vms
This will list all virtual machines on the server, with an output like this:
Oracle VM VirtualBox Command Line Management Interface Version 3.2.12
(C) 2005-2010 Oracle Corporation
All rights reserved.
"win7" {3f157880-c642-4be2-b641-85d7aedb5090}
"msn" {acc458d0-435b-44c7-806d-41c4948bb490}
"itunes" {41238c30-5f05-4fda-b008-5169d69505f6}
"Linux-Mint" {c25e1257-dfed-4789-a22b-8489c4d4df05}
"ubuntu" {fee70808-ab0e-473a-8991-d9b711773672}
"xp" {c75ec9b7-90b2-4f97-9e07-1267a3a03cb1}
"ubuntu-netop" {3d216ab8-3b44-46fd-8738-8c631801176e}
"slackware" {f65d5b26-6491-4523-8c06-970cbe6844d5}
"peppermint" {32b1845f-dd72-4c8a-bfe7-8cc3e83d0109}
If you specify -l then, you will get a detailed information about each one of those.
VBoxManage list vms -l
How to start virtual machines from command line
Now that you know which virtual machines are already installed, let’s see how to start them.
VBoxManage startvm "slackware"
or
VBoxManage startvm f65d5b26-6491-4523-8c06-970cbe6844d5
You can add those commands to your startup scripts, so virtual machines are started when you to boot your primary Linux server.
How to stop a virtual machine from command line
Now we know how to start virtual machines, we need to know how to stop them, there are some options.
Pause the virtual machine
This will just put the virtual machine on hold, until un-paused.
VBoxManage controlvm "slackware" pause
Resume the paused virtual machine
VBoxManage controlvm "slackware" resume
Reset -restart- the virtual machien
VBoxManage controlvm "slackware" reset
This will close the virtual machine, and restart immediately, you unsaved data on the virtual machine will not be saved, and will be lost! you have been warned.
Poweroff or shut down the virtual machine
VBoxManage controlvm "slackware" poweroff
This will poweroff the virtual machine, and once again any unsaved data will be lost.
Stop virtual machine, and save data
VBoxManage controlvm "slackware" savestate
This will save current state of the virtual machine and stop it, I think of this more or less, like hibernate the virtual machine.
Create a new virtual machine
You can also create new virtual machines from command line:
VBoxManage createvm -name "LinuxMint" -register
This create a new virtual machine, with default options.
Change Settings on the virtual machine from command line
Now we have a new virtual machine created, let’s change some of its default settings, like the allocated RAM:
VBoxManage modifyvm "LinuxMint -memory "1024MB"
Check the complete set of parameters.
Conclusion
As you can see, VirtualBox is very flexible and fully managed from the command line, so it can be used on a Dedicated server, in a remote data center, and you may have all your virtual machines under control.
I’m not saying this is the best option to go for professional virtualization, but it is certainly a good one, and an easy one too.
If you liked this article please share it.
from: http://go2linux.garron.me/linux/2011/01/vboxmanage-control-and-manage-virtualbox-command-line-890
--------------------------------------------------------------------------------------------------------
Create VirtualBox VM from the command line
As something of a follow-up post to the previous entry, here’s a quick recipe for creating a Virtual Machine using the VirtualBox command line tools:
We’re using Windows Server 2008 64bit as an example, modify to taste.
$ VM='Windows-2008-64bit'
Create a 32GB “dynamic” disk.
$ VBoxManage createhd --filename $VM.vdi --size 32768
You can get a list of the OS types VirtualBox recognises using:
$ VBoxManage list ostypes
Then copy the most appropriate one into here.
$ VBoxManage createvm --name $VM --ostype "Windows2008_64" --register
Add a SATA controller with the dynamic disk attached.
$ VBoxManage storagectl $VM --name "SATA Controller" --add sata \
>--controller IntelAHCI
$ VBoxManage storageattach $VM --storagectl "SATA Controller" --port 0 \
>--device 0 --type hdd --medium $VM.vdi
Add an IDE controller with a DVD drive attached, and the install ISO inserted into the drive:
$ VBoxManage storagectl $VM --name "IDE Controller" --add ide
$ VBoxManage storageattach $VM --storagectl "IDE Controller" --port 0 \
>--device 0 --type dvddrive --medium /path/to/windows_server_2008.iso
Misc system settings.
$ VBoxManage modifyvm $VM --ioapic on
$ VBoxManage modifyvm $VM --boot1 dvd --boot2 disk --boot3 none --boot4 none
$ VBoxManage modifyvm $VM --memory 1024 --vram 128
$ VBoxManage modifyvm $VM --nic1 bridged --bridgeadapter1 e1000g0
Configuration is all done, boot it up! If you’ve done this one a remote machine, you can RDP to the console via vboxhost:3389.
$ VBoxHeadless -s $VM
Once you have configured the operating system, you can shutdown and eject the DVD.
$ VBoxManage storageattach $VM --storagectl "IDE Controller" --port 0 \
>--device 0 --type dvddrive --medium none
Finally, it’s a good idea to take regular snapshots so that you can always revert back to a known-good state rather than having to completely re-install.
$ VBoxManage snapshot $VM take
And, if you need to revert back to a particular snapshot:
$ VBoxManage snapshot $VM restore
Enjoy!
from: http://www.perkin.org.uk/posts/create-virtualbox-vm-from-the-command-line.html
------------------------------------------------------------------------------------------------------
资料:
http://www.howtoforge.com/vboxheadless-running-virtual-machines-with-virtualbox-4.1-on-a-headless-ubuntu-12.04-server
http://www.pclinuxos.com/forum/index.php?topic=103651.0
页:
[1]