使用命令行操控VirtualBox虚拟机

时间:2023-03-09 09:00:43
使用命令行操控VirtualBox虚拟机

(1)启动虚拟机:
$ VBoxManage startvm <VMNAME> --type gui  #执行结束后,就会启动指定的虚拟机,几乎和平时没什么区别。

$ VBoxManage startvm <VMNAME> --type headless #无gui,可以配置好ip,然后远程控制

(2)关闭虚拟机
$ VBoxManage controlvm <VMNAME> acpipowerbutton # 关闭虚拟机,等价于点击系统关闭按钮,正常关机
$ VBoxManage controlvm <VMNAME> poweroff # 关闭虚拟机,等价于直接关闭电源,非正常关机

(3)保存虚拟机状态、查看虚拟机列表

$ VBoxManage controlvm <VMNAME> savestate # 保存当前虚拟机的运行状态

$ VBoxManage list runningvms # 列出运行中的虚拟机

(4) 重启虚拟机

$ VBoxManage controlvm <vm> reset #a cold reboot of the virtual machine

(5)创建虚拟机

$ VBoxManage createvm --name <VMNAME> --ostype Linux_64 --register #创建虚拟机

$ VBoxManage modifyvm <VMNAME> --memory 256 --acpi on --boot1 net --nic1 bridged --bridgeadapter1 enp4s0f0 #修改虚拟机配置

$ VBoxManage createvdi --filename ~/VirtualBox\ VMs/<VMNAME>/<VMNAME>.vdi --size 10000 #创建硬盘镜像文件

(6)删除虚拟机

$ VBoxManage unregistervm <VMNAME> --delete #注销并删除虚拟机

转自: http://blog.chinaunix.net/uid-734339-id-3188230.html

http://www.freeoa.net/osuport/sysadmin/create-vbox-vm-by-cmd_1952.html

http://nakkaya.com/2012/08/30/create-manage-virtualBox-vms-from-the-command-line/