最后更新于2020.08.06
VirtualBox命令行工具是VBoxManage.exe,在VirtualBox安装目录下。
如果有兴趣可以点击这里跳转到文章底部看看英文的帮助信息
如果有需求可以点击这里跳转到查看详细翻译的文档
长文告警,持续更新
好了,现在进入正文。
很多主机(如服务器)没有图像显示设备,甚至只支持命令行没有GUI,所以如果要在这一类主机上搭建虚拟机只能采取这种方法。
VBoxManage createvm --name <名称> --ostype <系统类型> --register
其中<名称>
是自定义的,但是必须用英文双引号包围,如:"test"
<系统类型>
可以是如下的表格的第一列。(一个个字敲上去的QwQ)
跳到表格下方
名称 | 描述 | 隶属 | 制造商 | 是否为x64系统 |
---|---|---|---|---|
Other | Other/Unknown | Other | Other | |
Other_64 | Other/Unknown(64-bit) | Other | Other | |
Windows31 | Windows3.1 | Windows | MicrosoftWindows | |
Windows95 | Windows95 | Windows | MicrosoftWindows | |
Windows98 | Windows98 | Windows | MicrosoftWindows | |
WindowsMe | WindowsME | Windows | MicrosoftWindows | |
WindowsNT4 | WindowsNT4 | Windows | MicrosoftWindows | |
Windows2000 | Windows2000 | Windows | MicrosoftWindows | |
WindowsXP | WindowsXP(32-bit) | Windows | MicrosoftWindows | |
WindowsXP_64 | WindowsXP(64-bit) | Windows | MicrosoftWindows | |
Windows2003 | Windows2003(32-bit) | Windows | MicrosoftWindows | |
Windows2003_64 | Windows2003(64-bit) | Windows | MicrosoftWindows | |
WindowsVista | WindowsVista(32-bit) | Windows | MicrosoftWindows | |
WindowsVista_64 | WindowsVista(64-bit) | Windows | MicrosoftWindows | |
Windows2008 | Windows2008(32-bit) | Windows | MicrosoftWindows | |
Windows2008_64 | Windows2008(64-bit) | Windows | MicrosoftWindows | |
Windows7 | Windows7(32-bit) | Windows | MicrosoftWindows | |
Windows7_64 | Windows7(64-bit) | Windows | MicrosoftWindows | |
Windows8 | Windows8(32-bit) | Windows | MicrosoftWindows | |
Windows8_64 | Windows8(64-bit) | Windows | MicrosoftWindows | |
Windows81 | Windows8.1(32-bit) | Windows | MicrosoftWindows | |
Windows81_64 | Windows8.1(64-bit) | Windows | MicrosoftWindows | |
Windows2012_64 | Windows2012(64-bit) | Windows | MicrosoftWindows | |
Windows10 | Windows10(32-bit) | Windows | MicrosoftWindows | |
Windows10_64 | Windows10(64-bit) | Windows | MicrosoftWindows | |
Windows2016_64 | Windows2016(64-bit) | Windows | MicrosoftWindows | |
WindowsNT | OtherWindows(32-bit) | Windows | MicrosoftWindows | |
WindowsNT_64 | OtherWindows(64-bit) | Windows | MicrosoftWindows | |
Linux22 | Linux2.2 | Linux | Linux | |
Linux24 | Linux2.4(32-bit) | Linux | Linux | |
Linux24_64 | Linux2.4(64-bit) | Linux | Linux | |
Linux26 | Linux2.6/3.x/4.x(32-bit) | Linux | Linux | |
Linux26_64 | Linux2.6/3.x/4.x(64-bit) | Linux | Linux | |
ArchLinux | ArchLinux(32-bit) | Linux | Linux | |
ArchLinux_64 | ArchLinux(64-bit) | Linux | Linux | |
Debian | Debian(32-bit) | Linux | Linux | |
Debian_64 | Debian(64-bit) | Linux | Linux | |
OpenSUSE | openSUSE(32-bit) | Linux | Linux | |
OpenSUSE_64 | openSUSE(64-bit) | Linux | Linux | |
Fedora | Fedora(32-bit) | Linux | Linux | |
Fedora_64 | Fedora(64-bit) | Linux | Linux | |
Gentoo | Gentoo(32-bit) | Linux | Linux | |
Gentoo_64 | Gentoo(64-bit) | Linux | Linux | |
Mandriva | Mandriva(32-bit) | Linux | Linux | |
Mandriva_64 | Mandriva(64-bit) | Linux | Linux | |
RedHat | RedHat(32-bit) | Linux | Linux | |
RedHat_64 | RedHat(64-bit) | Linux | Linux | |
Turbolinux | Turbolinux(32-bit) | Linux | Linux | |
Turbolinux_64 | Turbolinux(64-bit) | Linux | Linux | |
Ubuntu | Ubuntu(32-bit) | Linux | Linux | |
Ubuntu_64 | Ubuntu(64-bit) | Linux | Linux | |
Xandros | Xandros(32-bit) | Linux | Linux | |
Xandros_64 | Xandros(64-bit) | Linux | Linux | |
Oracle | Oracle(32-bit) | Linux | Linux | |
Oracle_64 | Oracle(64-bit) | Linux | Linux | |
Linux | OtherLinux(32-bit) | Linux | Linux | |
Linux_64 | OtherLinux(64-bit) | Linux | Linux | |
Solaris | OracleSolaris105/09andearlier(32-bit) | Solaris | Solaris | |
Solaris_64 | OracleSolaris105/09andearlier(64-bit) | Solaris | Solaris | |
OpenSolaris | OracleSolaris1010/09andlater(32-bit) | Solaris | Solaris | |
OpenSolaris_64 | OracleSolaris1010/09andlater(64-bit) | Solaris | Solaris | |
Solaris11_64 | OracleSolaris11(64-bit) | Solaris | Solaris | |
FreeBSD | FreeBSD(32-bit) | BSD | BSD | |
FreeBSD_64 | FreeBSD(64-bit) | BSD | BSD | |
OpenBSD | OpenBSD(32-bit) | BSD | BSD | |
OpenBSD_64 | OpenBSD(64-bit) | BSD | BSD | |
NetBSD | NetBSD(32-bit) | BSD | BSD | |
NetBSD_64 | NetBSD(64-bit) | BSD | BSD | |
OS2Warp3 | OS/2Warp3 | OS2 | IBMOS/2 | |
OS2Warp4 | OS/2Warp4 | OS2 | IBMOS/2 | |
OS2Warp45 | OS/2Warp4.5 | OS2 | IBMOS/2 | |
OS2eCS | eComStation | OS2 | IBMOS/2 | |
OS21x | OS/21.x | OS2 | IBMOS/2 | |
OS2 | OtherOS/2 | OS2 | IBMOS/2 | |
MacOS | MacOSX(32-bit) | MacOS | MacOSX | |
MacOS_64 | MacOSX(64-bit) | MacOS | MacOSX | |
MacOS106 | MacOSX10.6SnowLeopard(32-bit) | MacOS | MacOSX | |
MacOS106_64 | MacOSX10.6SnowLeopard(64-bit) | MacOS | MacOSX | |
MacOS107_64 | MacOSX10.7Lion(64-bit) | MacOS | MacOSX | |
MacOS108_64 | MacOSX10.8MountainLion(64-bit) | MacOS | MacOSX | |
MacOS109_64 | MacOSX10.9Mavericks(64-bit) | MacOS | MacOSX | |
MacOS1010_64 | MacOSX10.10Yosemite(64-bit) | MacOS | MacOSX | |
MacOS1011_64 | MacOSX10.11ElCapitan(64-bit) | MacOS | MacOSX | |
MacOS1012_64 | macOS10.12Sierra(64-bit) | MacOS | MacOSX | |
MacOS1013_64 | macOS10.13HighSierra(64-bit) | MacOS | MacOSX | |
DOS | DOS | Other | Other | |
Netware | Netware | Other | Other | |
L4 | L4 | Other | Other | |
QNX | QNX | Other | Other | |
JRockitVE | JRockitVE | Other | Other | |
VBoxBS_64 | VirtualBoxBootsectorTest(64-bit) | Other | Other |
回到表格上方
如果没有指定–register参数,那么需要在后续的命令中使用registervm命令
为虚拟机指定设置信息:
VBoxManage modifyvm "ubuntu" --memory 256 --acpi on --boot1 dvd --nic1 nat
为虚拟机创建虚拟硬盘(例如,20GB):
VBoxManage createhd --filename "ubuntu.vdi" --size 20000
VBoxManage storagectl "ubuntu" --name "IDE Controller" --add ide --controller PIIX4
VBoxManage storageattach "ubuntu" --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium "ubuntu.vdi"
VBoxManage storageattach "ubuntu" --storagectl "IDE Controller" --port 0 --device 1 --type dvddrive --medium /full/path/to/iso.iso
VBoxManage startvm "ubuntu" --type headless
关闭虚拟机:
VBoxManage controlvm "ubuntu" poweroff
因为<>|[](){}这些符号显示会有问题,所以放代码块里面结合示例讲解。
使用:
VBoxManage [<常规选项>] <命令>
常规选项:
[-v|--version] 打印版本号并退出
[-q|--nologo] 关闭徽标功能
[--settingspw ] 提供设置密码
[--settingspwfile ] 提供包含设置密码的文件
[@] 从给定的响应文件中加载参数(bourne风格)
p.s.不知道怎么翻译bourne
命令:
list [--long|-l] [--sorted|-s]
vms|runningvms|ostypes|hostdvds|hostfloppies|
intnets|bridgedifs|hostonlyifs|natnets|dhcpservers|
hostinfo|hostcpuids|hddbackends|hdds|dvds|floppies|
usbhost|usbfilters|systemproperties|extpacks|
groups|webcams|screenshotformats
showvminfo [--details]
[--machinereadable]
showvminfo --log
registervm
unregistervm [--delete]
createvm --name
[--groups , ...]
[--ostype ]
[--register]
[--basefolder ]
[--uuid ]
modifyvm
[--name ]
[--groups , ...]
[--description ]
[--ostype ]
[--iconfile ]
[--memory ]
[--pagefusion on|off]
[--vram ]
[--acpi on|off]
[--pciattach 03:04.0]
[--pciattach 03:04.0@02:01.0]
[--pcidetach 03:04.0]
[--ioapic on|off]
[--hpet on|off]
[--triplefaultreset on|off]
[--apic on|off]
[--x2apic on|off]
[--paravirtprovider none|default|legacy|minimal|
hyperv|kvm]
[--paravirtdebug [, ...]]
[--hwvirtex on|off]
[--nestedpaging on|off]
[--largepages on|off]
[--vtxvpid on|off]
[--vtxux on|off]
[--pae on|off]
[--longmode on|off]
[--ibpb-on-vm-exit on|off]
[--ibpb-on-vm-entry on|off]
[--spec-ctrl on|off]
[--cpu-profile "host|Intel 80[86|286|386]"]
[--cpuid-portability-level <0..3>
[--cpuid-set ]
[--cpuid-remove ]
[--cpuidremoveall]
[--hardwareuuid ]
[--cpus ]
[--cpuhotplug on|off]
[--plugcpu ]
[--unplugcpu ]
[--cpuexecutioncap <1-100>]
[--rtcuseutc on|off]
[--graphicscontroller none|vboxvga|vmsvga]
[--monitorcount ]
[--accelerate3d on|off]
[--accelerate2dvideo on|off]
[--firmware bios|efi|efi32|efi64]
[--chipset ich9|piix3]
[--bioslogofadein on|off]
[--bioslogofadeout on|off]
[--bioslogodisplaytime ]
[--bioslogoimagepath ]
[--biosbootmenu disabled|menuonly|messageandmenu]
[--biosapic disabled|apic|x2apic]
[--biossystemtimeoffset ]
[--biospxedebug on|off]
[--boot<1-4> none|floppy|dvd|disk|net>]
[--nic<1-N> none|null|nat|bridged|intnet|hostonly|
generic|natnetwork]
[--nictype<1-N> Am79C970A|Am79C973|
82540EM|82543GC|82545EM|
virtio]
[--cableconnected<1-N> on|off]
[--nictrace<1-N> on|off]
[--nictracefile<1-N> ]
[--nicproperty<1-N> name=[value]]
[--nicspeed<1-N> ]
[--nicbootprio<1-N> ]
[--nicpromisc<1-N> deny|allow-vms|allow-all]
[--nicbandwidthgroup<1-N> none|]
[--bridgeadapter<1-N> none|]
[--hostonlyadapter<1-N> none|]
[--intnet<1-N> ]
[--nat-network<1-N> ]
[--nicgenericdrv<1-N>
[--natnet<1-N> |default]
[--natsettings<1-N> [],[],
[],[],
[]]
[--natpf<1-N> [],tcp|udp,[],
,[],]
[--natpf<1-N> delete ]
[--nattftpprefix<1-N> ]
[--nattftpfile<1-N> ]
[--nattftpserver<1-N> ]
[--natbindip<1-N>
[--natdnspassdomain<1-N> on|off]
[--natdnsproxy<1-N> on|off]
[--natdnshostresolver<1-N> on|off]
[--nataliasmode<1-N> default|[log],[proxyonly],
[sameports]]
[--macaddress<1-N> auto|]
[--mouse ps2|usb|usbtablet|usbmultitouch]
[--keyboard ps2|usb
[--uart<1-N> off| ]
[--uartmode<1-N> disconnected|
server |
client |
tcpserver |
tcpclient |
file |
]
[--lpt<1-N> off| ]
[--lptmode<1-N> ]
[--guestmemoryballoon ]
[--audio none|null|dsound]
[--audioin on|off]
[--audioout on|off]
[--audiocontroller ac97|hda|sb16]
[--audiocodec stac9700|ad1980|stac9221|sb16]
[--clipboard disabled|hosttoguest|guesttohost|
bidirectional]
[--draganddrop disabled|hosttoguest]
[--vrde on|off]
[--vrdeextpack default|
[--vrdeproperty ]
[--vrdeport ]
[--vrdeaddress ]
[--vrdeauthtype null|external|guest]
[--vrdeauthlibrary default|
[--vrdemulticon on|off]
[--vrdereusecon on|off]
[--vrdevideochannel on|off]
[--vrdevideochannelquality ]
[--usb on|off]
[--usbehci on|off]
[--usbxhci on|off]
[--usbrename ]
[--snapshotfolder default|]
[--teleporter on|off]
[--teleporterport ]
[--teleporteraddress
[--teleporterpassword ]
[--teleporterpasswordfile |stdin]
[--tracing-enabled on|off]
[--tracing-config ]
[--tracing-allow-vm-access on|off]
[--usbcardreader on|off]
[--autostart-enabled on|off]
[--autostart-delay ]
[--videocap on|off]
[--videocapscreens all| [ ...]]
[--videocapfile ]
[--videocapres ]
[--videocaprate ]
[--videocapfps ]
[--videocapmaxtime ]
[--videocapmaxsize ]
[--videocapopts [, ...]]
[--defaultfrontend default|]
clonevm
[--snapshot |]
[--mode machine|machineandchildren|all]
[--options link|keepallmacs|keepnatmacs|
keepdisknames]
[--name ]
[--groups , ...]
[--basefolder ]
[--uuid ]
[--register]
import
[--dry-run|-n]
[--options keepallmacs|keepnatmacs|importtovdi]
[more options]
(run with -n to have options displayed
for a particular OVF)
export --output|-o .
[--legacy09|--ovf09|--ovf10|--ovf20|--opc10]
[--manifest]
[--iso]
[--options manifest|iso|nomacs|nomacsbutnat]
[--vsys ]
[--product ]
[--producturl ]
[--vendor ]
[--vendorurl ]
[--version ]
[--description ]
[--eula ]
[--eulafile ]
startvm ...
[--type gui|sdl|headless|separate]
[-E|--putenv [=]]
controlvm
pause|resume|reset|poweroff|savestate|
acpipowerbutton|acpisleepbutton|
keyboardputscancode [ ...]|
keyboardputstring [ ...]|
keyboardputfile |
setlinkstate<1-N> on|off |
nic<1-N> null|nat|bridged|intnet|hostonly|generic|
natnetwork [] |
nictrace<1-N> on|off |
nictracefile<1-N> |
nicproperty<1-N> name=[value] |
nicpromisc<1-N> deny|allow-vms|allow-all |
natpf<1-N> [],tcp|udp,[],
,[], |
natpf<1-N> delete |
guestmemoryballoon |
usbattach |
[--capturefile ] |
usbdetach | |
audioin on|off |
audioout on|off |
clipboard disabled|hosttoguest|guesttohost|
bidirectional |
draganddrop disabled|hosttoguest |
vrde on|off |
vrdeport |
vrdeproperty |
vrdevideochannelquality |
setvideomodehint
[[] [ |
[ ]]] |
screenshotpng [display] |
videocap on|off |
videocapscreens all|none|,[...] |
videocapfile
videocapres x
videocaprate
videocapfps
videocapmaxtime
videocapmaxsize
setcredentials
--passwordfile |
[--allowlocallogon ] |
teleport --host --port
[--maxdowntime ]
[--passwordfile |
--password ] |
plugcpu |
unplugcpu |
cpuexecutioncap <1-100>
webcam | |
addencpassword
|-
[--removeonsuspend ]
removeencpassword
removeallencpasswords
discardstate
adoptstate
snapshot
take [--description ] [--live]
[--uniquename Number,Timestamp,Space,Force] |
delete |
restore |
restorecurrent |
edit |--current
[--name ]
[--description ] |
list [--details|--machinereadable] |
showvminfo
closemedium [disk|dvd|floppy]
[--delete]
storageattach
--storagectl
[--port ]
[--device ]
[--type dvddrive|hdd|fdd]
[--medium none|emptydrive|additions|
|host:|iscsi]
[--mtype normal|writethrough|immutable|shareable|
readonly|multiattach]
[--comment ]
[--setuuid ]
[--setparentuuid ]
[--passthrough on|off]
[--tempeject on|off]
[--nonrotational on|off]
[--discard on|off]
[--hotpluggable on|off]
[--bandwidthgroup ]
[--forceunmount]
[--server |]
[--target ]
[--tport ]
[--lun ]
[--encodedlun ]
[--username ]
[--password ]
[--passwordfile ]
[--initiator ]
[--intnet]
storagectl
--name
[--add ide|sata|scsi|floppy|sas|usb|pcie]
[--controller LSILogic|LSILogicSAS|BusLogic|
IntelAHCI|PIIX3|PIIX4|ICH6|I82078|
[ USB|NVMe]
[--portcount <1-n>]
[--hostiocache on|off]
[--bootable on|off]
[--rename ]
[--remove]
bandwidthctl
add --type disk|network
--limit [k|m|g|K|M|G] |
set
--limit [k|m|g|K|M|G] |
remove |
list [--machinereadable]
(limit units: k=kilobit, m=megabit, g=gigabit,
K=kilobyte, M=megabyte, G=gigabyte)
showmediuminfo [disk|dvd|floppy]
createmedium [disk|dvd|floppy] --filename
[--size |--sizebyte ]
[--diffparent |
[--format VDI|VMDK|VHD] (default: VDI)
[--variant Standard,Fixed,Split2G,Stream,ESX]
modifymedium [disk|dvd|floppy]
[--type normal|writethrough|immutable|shareable|
readonly|multiattach]
[--autoreset on|off]
[--property ]
[--compact]
[--resize |--resizebyte ]
[--move ]
clonemedium [disk|dvd|floppy]
[--format VDI|VMDK|VHD|RAW|]
[--variant Standard,Fixed,Split2G,Stream,ESX]
[--existing]
mediumproperty [disk|dvd|floppy] set
[disk|dvd|floppy] get