服务器在线 - 服务器软件 - 网站地图 服务器在线,专注于服务器技术!

当前位置:主页 > 云和虚拟化 > VirtualBox > 正文

Linux下VirtualBox虚拟机的命令行启动/关闭方法和开机自动启动

时间:2015-01-15    来源:服务器在线    投稿:泡泡    点击:

SUN VirtualBox 的命令行启动/关闭方法简介 VirtualBox 详细命令 linux开机自动启动虚拟机系统

当你安装很多套Virtualbox的虚拟机器系统后,希望能在开机后自动启动虚拟机器的系统。 

开启记事本,将虚线内文字另存为"Virtualbox.bat",将档案存放到[开始]->[程式集]->[启动]内,即可在开机时同时跑3个Virtualbox虚拟机器的系统了。 

这种启动方式,让你不须要点选Virtualbox主程式,再开启你要执行的虚拟机器的OS。它会自动启动在背景执行,如果你有设定OS可以远端遥控的话,你可以在别台电脑以远端连线来控制虚拟机器的OS。

我们可以使用VBxManager 命令行管理工具来查看当前的虚拟基设置 和状态

下面通过实例来说明如何从命令行启动和关闭VirtualBox 虚拟机的两种常用方式。

第一种:使用 VRDP 方式通过命令行启动虚拟机: (虚拟机名为:dcsvr08)
QHo@qhoferrari1k:~$ VBoxManage startvm dcsvr08 -type vrdp

第二种 :使用 Headless 启动无前端图形界面方式: 
QHo@qhoferrari1k:~$ VBoxHeadless -startvm "dcsvr08"

VirtualBox Headless Inte***ce 2.1.4
(C) 2008-2009 Sun Microsystems, Inc.
All rights reserved.

3389是VRDP(远程桌面)监听端口 。 
启用VRDP后,一旦虚拟机启动完毕,我们就可以通过远程桌面/XManage等GUI远程管理工具来登录客户操作系统 。

要确认虚拟机是否在运行 ,可以使用命令VBoxManage list runningvm 来查看。
QHo@qhoferrari1k:~$ VBoxManage list runningvms

从命令行关闭虚拟机 
通过VBoxManage 命令行工具的VBoxManage controlvm   <uuid>|<name> 子命令可以改变虚拟机的运行状态,
其中常用的几个选项是:

pause resume reset poweroff savestate acpipowerbutton acpisleepbutton
下面示例使用 poweroff 选项关闭虚拟机 dcsvr08 

QHo@qhoferrari1k:~$ VBoxManage controlvm dcsvr08 poweroff 
VirtualBox Command Line Management Inte***ce Version 2.1.4
(C) 2005-2009 Sun Microsystems, Inc.
All rights reserved.

QHo@qhoferrari1k:~$ VBoxManage list runningvms 
VirtualBox Command Line Management Inte***ce Version 2.1.4
(C) 2005-2009 Sun Microsystems, Inc.
All rights reserved.

3ce3fd01-7e17-46b3-8394-be9c1b17ee66
QHo@qhoferrari1k:~$ 
在poweroff 后马上list runningvms ,可以看到dscvr08已经被关闭,现在只有一台虚机处于运行状态。

[root@server ~]# VBoxManage

Oracle VM VirtualBox Command Line Management Inte***ce Version 4.1.2

(C) 2005-2011 Oracle Corporation

All rights reserved.

Usage:

VBoxManage [-v|--version]    print version number and exit

VBoxManage [-q|--nologo] ... suppress the logo

VBoxManage list [--long|-l] vms|runningvms|ostypes|hostdvds|hostfloppies|

bridgedifs|hostonlyifs|dhcpservers|hostinfo|

hostcpuids|hddbackends|hdds|dvds|floppies|

usbhost|usbfilters|systemproperties|extpacks

VBoxManage showvminfo       <uuid>|<name> [--details]

[--machinereadable]

VBoxManage showvminfo       <uuid>|<name> --log <idx>

VBoxManage registervm       <filename>

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

VBoxManage createvm         --name <name>

[--ostype <ostype>]

[--register]

[--basefolder <path>]

[--uuid <uuid>]

VBoxManage modifyvm         <uuid|name>

[--name <name>]

[--ostype <ostype>]

[--memory <memorysize in MB>]

[--pagefusion on|off]

[--vram <vramsize in MB>]

[--acpi on|off]

[--pciattach 03:04.0]

[--pciattach 03:04.0@02:01.0]

[--pcidetach 03:04.0]

[--ioapic on|off]

[--pae on|off]

[--hpet on|off]

[--hwvirtex on|off]

[--hwvirtexexcl on|off]

[--nestedpaging on|off]

[--largepages on|off]

[--vtxvpid on|off]

[--synthcpu on|off]

[--cpuidset <leaf> <eax> <ebx> <ecx> <edx>]

[--cpuidremove <leaf>]

[--cpuidremoveall]

[--hardwareuuid <uuid>]

[--cpus <number>]

[--cpuhotplug on|off]

[--plugcpu <id>]

[--unplugcpu <id>]

[--cpuexecutioncap <1-100>]

[--rtcuseutc on|off]

[--monitorcount <number>]

[--accelerate3d on|off]

[--accelerate2dvideo on|off]

[--firmware bios|efi|efi32|efi64]

[--chipset ich9|piix3]

[--bioslogofadein on|off]

[--bioslogofadeout on|off]

[--bioslogodisplaytime <msec>]

[--bioslogoimagepath <imagepath>]

[--biosbootmenu disabled|menuonly|messageandmenu]

[--biossystemtimeoffset <msec>]

[--biospxedebug on|off]

[--boot<1-4> none|floppy|dvd|disk|net>]

[--nic<1-N> none|null|nat|bridged|intnet|hostonly|

            generic]

[--nictype<1-N> Am79C970A|Am79C973|

                82540EM|82543GC|82545EM|

                virtio]

[--cableconnected<1-N> on|off]

[--nictrace<1-N> on|off]

[--nictracefile<1-N> <filename>]

[--nicproperty<1-N> name=[value]]

[--nicspeed<1-N> <kbps>]

[--nicbootprio<1-N> <priority>]

[--nicpromisc<1-N> deny|allow-vms|allow-all]

[--nicbandwidthgroup<1-N> none|<name>]

[--bridgeadapter<1-N> none|<devicename>]

[--hostonlyadapter<1-N> none|<devicename>]

[--intnet<1-N> <network name>]

[--natnet<1-N> <network>|default]

[--nicgenericdrv<1-N> <driver>

[--natsettings<1-N> [<mtu>],[<socksnd>],

                    [<sockrcv>],[<tcpsnd>],

                    [<tcprcv>]]

[--natpf<1-N> [<rulename>],tcp|udp,[<hostip>],

              <hostport>,[<guestip>],<guestport>]

[--natpf<1-N> delete <rulename>]

[--nattftpprefix<1-N> <prefix>]

[--nattftpfile<1-N> <file>]

[--nattftpserver<1-N> <ip>]

[--natbindip<1-N> <ip>

[--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|<mac>]

[--mouse ps2|usb|usbtablet

[--keyboard ps2|usb

[--uart<1-N> off|<I/O base> <IRQ>]

[--uartmode<1-N> disconnected|

                 server <pipe>|

                 client <pipe>|

                 file <file>|

                 <devicename>]

[--guestmemoryballoon <balloonsize in MB>]

[--gueststatisticsinterval <seconds>]

[--audio none|null|oss|alsa|pulse]

[--audiocontroller ac97|hda|sb16]

[--clipboard disabled|hosttoguest|guesttohost|

             bidirectional]

[--vrde on|off]

[--vrdeextpack default|<name>

[--vrdeproperty <name=[value]>]

[--vrdeport <hostport>]

[--vrdeaddress <hostip>]

[--vrdeauthtype null|external|guest]

[--vrdeauthlibrary default|<name>

[--vrdemulticon on|off]

[--vrdereusecon on|off]

[--vrdevideochannel on|off]

[--vrdevideochannelquality <percent>]

[--usb on|off]

[--usbehci on|off]

[--snapshotfolder default|<path>]

[--teleporter on|off]

[--teleporterport <port>]

[--teleporteraddress <address|empty>

[--teleporterpassword <password>]

VBoxManage clonevm          <uuid>|<name>

[--snapshot <uuid>|<name>]

[--mode machine|machineandchildren|all]

[--options link|keepallmacs|keepnatmacs|

           keepdisknames]

[--name <name>]

[--basefolder <basefolder>]

[--uuid <uuid>]

[--register]

VBoxManage import           <ovf/ova>

[--dry-run|-n]

[--options keepallmacs|keepnatmacs]

[more options]

(run with -n to have options displayed

 for a particular OVF)

VBoxManage export           <machines> --output|-o <ovf/ova>

[--legacy09]

[--manifest]

[--vsys <number of virtual system>]

        [--product <product name>]

        [--producturl <product url>]

        [--vendor <vendor name>]

        [--vendorurl <vendor url>]

        [--version <version info>]

        [--eula <license text>]

        [--eulafile <filename>]

VBoxManage startvm          <uuid>|<name>...

[--type gui|sdl|headless]

VBoxManage controlvm        <uuid>|<name>

pause|resume|reset|poweroff|savestate|

acpipowerbutton|acpisleepbutton|

keyboardputscancode <hex> [<hex> ...]|

setlinkstate<1-N> on|off |

nic<1-N> null|nat|bridged|intnet|hostonly|generic

         [<devicename>] |

nictrace<1-N> on|off

nictracefile<1-N> <filename>

nicproperty<1-N> name=[value]

natpf<1-N> [<rulename>],tcp|udp,[<hostip>],

              <hostport>,[<guestip>],<guestport>

natpf<1-N> delete <rulename>

guestmemoryballoon <balloonsize in MB>]

gueststatisticsinterval <seconds>]

usbattach <uuid>|<address> |

usbdetach <uuid>|<address> |

vrde on|off |

vrdeport <port> |

vrdeproperty <name=[value]> |

vrdevideochannelquality <percent>

setvideomodehint <xres> <yres> <bpp> [display] |

screenshotpng <file> [display] |

setcredentials <username> <password> <domain>

               [--allowlocallogon <yes|no>] |

teleport --host <name> --port <port>

       [--maxdowntime <msec>] [--password password]

plugcpu <id>

unplugcpu <id>

cpuexecutioncap <1-100>

VBoxManage discardstate     <uuid>|<name>

 

VBoxManage adoptstate       <uuid>|<name> <state_file>

 

VBoxManage snapshot         <uuid>|<name>

take <name> [--description <desc>] [--pause] |

delete <uuid>|<name> |

restore <uuid>|<name> |

restorecurrent |

edit <uuid>|<name>|--current

     [--name <name>]

     [--description <desc>] |

showvminfo <uuid>|<name>

VBoxManage closemedium      disk|dvd|floppy <uuid>|<filename>

[--delete]

VBoxManage storageattach    <uuid|vmname>

--storagectl <name>

[--port <number>]

[--device <number>]

[--type dvddrive|hdd|fdd]

[--medium none|emptydrive|

          <uuid>|<filename>|host:<drive>|iscsi]

[--mtype normal|writethrough|immutable|shareable|

         readonly|multiattach]

[--comment <text>]

[--setuuid <uuid>]

[--setparentuuid <uuid>]

[--passthrough on|off]

[--tempeject on|off]

[--nonrotational on|off]

[--bandwidthgroup <name>]

[--forceunmount]

[--server <name>|<ip>]

[--target <target>]

[--tport <port>]

[--lun <lun>]

[--encodedlun <lun>]

[--username <username>]

[--password <password>]

[--intnet]

VBoxManage storagectl       <uuid|vmname>

--name <name>

[--add ide|sata|scsi|floppy|sas]

[--controller LSILogic|LSILogicSAS|BusLogic|

              IntelAHCI|PIIX3|PIIX4|ICH6|I82078]

[--sataideemulation<1-4> <1-30>]

[--sataportcount <1-30>]

[--hostiocache on|off]

[--bootable on|off]

[--remove]

VBoxManage bandwidthctl     <uuid|vmname>

--name <name>

[--add disk|network]

[--limit <megabytes per second>

[--delete]

VBoxManage showhdinfo       <uuid>|<filename>

 

VBoxManage createhd         --filename <filename>

--size <megabytes>|--sizebyte <bytes>

[--format VDI|VMDK|VHD] (default: VDI)

[--variant Standard,Fixed,Split2G,Stream,ESX]

VBoxManage modifyhd         <uuid>|<filename>

[--type normal|writethrough|immutable|shareable|

        readonly|multiattach]

[--autoreset on|off]

[--compact]

[--resize <megabytes>|--resizebyte <bytes>]

VBoxManage clonehd          <uuid>|<filename> <uuid>|<outputfile>

[--format VDI|VMDK|VHD|RAW|<other>]

[--variant Standard,Fixed,Split2G,Stream,ESX]

[--existing]

VBoxManage convertfromraw   <filename> <outputfile>

[--format VDI|VMDK|VHD]

[--variant Standard,Fixed,Split2G,Stream,ESX]

VBoxManage convertfromraw   stdin <outputfile> <bytes>

[--format VDI|VMDK|VHD]

[--variant Standard,Fixed,Split2G,Stream,ESX]

VBoxManage getextradata     global|<uuid>|<name>

<key>|enumerate

VBoxManage setextradata     global|<uuid>|<name>

<key>

[<value>] (no value deletes key)

VBoxManage setproperty      machinefolder default|<folder> |

vrdeauthlibrary default|<library> |

websrvauthlibrary default|null|<library> |

vrdeextpack null|<library> |

loghistorycount <value>

VBoxManage usbfilter        add <index,0-N>

--target <uuid>|<name>|global

--name <string>

--action ignore|hold (global filters only)

[--active yes|no] (yes)

[--vendorid <XXXX>] (null)

[--productid <XXXX>] (null)

[--revision <IIFF>] (null)

[--manufacturer <string>] (null)

[--product <string>] (null)

[--remote yes|no] (null, VM filters only)

[--serialnumber <string>] (null)

[--maskedinte***ces <XXXXXXXX>]

VBoxManage usbfilter        modify <index,0-N>

--target <uuid>|<name>|global

[--name <string>]

[--action ignore|hold] (global filters only)

[--active yes|no]

[--vendorid <XXXX>|""]

[--productid <XXXX>|""]

[--revision <IIFF>|""]

[--manufacturer <string>|""]

[--product <string>|""]

[--remote yes|no] (null, VM filters only)

[--serialnumber <string>|""]

[--maskedinte***ces <XXXXXXXX>]

VBoxManage usbfilter        remove <index,0-N>

--target <uuid>|<name>|global

VBoxManage sharedfolder     add <vmname>|<uuid>

--name <name> --hostpath <hostpath>

[--transient] [--readonly] [--automount]

VBoxManage sharedfolder     remove <vmname>|<uuid>

--name <name> [--transient]

VBoxManage guestproperty    get <vmname>|<uuid>

<property> [--verbose]

VBoxManage guestproperty    set <vmname>|<uuid>

<property> [<value> [--flags <flags>]]

VBoxManage guestproperty    enumerate <vmname>|<uuid>

[--patterns <patterns>]

VBoxManage guestproperty    wait <vmname>|<uuid> <patterns>

[--timeout <msec>] [--fail-on-timeout]

VBoxManage guestcontrol     <vmname>|<uuid>

exec[ute]

--image <path to program>

--username <name> --password <password>

[--dos2unix]

[--environment "<NAME>=<VALUE> [<NAME>=<VALUE>]"]

[--timeout <msec>] [--unix2dos] [--verbose]

[--wait-exit] [--wait-stdout] [--wait-stderr]

[-- [<argument1>] ... [<argumentN>]]

copyfrom

<source on guest> <destination on host>

--username <name> --password <password>

[--dryrun] [--follow] [--recursive] [--verbose]

copyto|cp

<source on host> <destination on guest>

--username <name> --password <password>

[--dryrun] [--follow] [--recursive] [--verbose]

createdir[ectory]|mkdir|md

<director[y|ies] to create on guest>

--username <name> --password <password>

[--parents] [--mode <mode>] [--verbose]

stat

<file element(s) to check on guest>

--username <name> --password <password>

[--verbose]

updateadditions

[--source <guest additions .ISO>] [--verbose]

VBoxManage debugvm          <uuid>|<name>

dumpguestcore --filename <name> |

info <item> [args] |

injectnmi |

osdetect |

osinfo |

getregisters [--cpu <id>] <reg>|all ... |

setregisters [--cpu <id>] <reg>=<value> ... |

statistics [--reset] [--pattern <pattern>]

[--descriptions]

VBoxManage metrics          list [*|host|<vmname> [<metric_list>]]

                     (comma-separated)

VBoxManage metrics          setup

[--period <seconds>] (default: 1)

[--samples <count>] (default: 1)

[--list]

[*|host|<vmname> [<metric_list>]]

VBoxManage metrics          query [*|host|<vmname> [<metric_list>]]

VBoxManage metrics          enable

[--list]

[*|host|<vmname> [<metric_list>]]

VBoxManage metrics          disable

[--list]

[*|host|<vmname> [<metric_list>]]

VBoxManage metrics          collect

[--period <seconds>] (default: 1)

[--samples <count>] (default: 1)

[--list]

[--detach]

[*|host|<vmname> [<metric_list>]]

VBoxManage hostonlyif       ipconfig <name>

[--dhcp |

--ip<ipv4> [--netmask<ipv4> (def: 255.255.255.0)] |

--ipv6<ipv6> [--netmasklengthv6<length> (def: 64)]]

create |

remove <name>

VBoxManage dhcpserver       add|modify --netname <network_name> |

           --ifname <hostonly_if_name>

[--ip <ip_address>

--netmask <network_mask>

--lowerip <lower_ip>

--upperip <upper_ip>]

[--enable | --disable]

VBoxManage dhcpserver       remove --netname <network_name> |

       --ifname <hostonly_if_name>

VBoxManage extpack          install [--replace] <tarball> |

uninstall [--force] <name> |

cleanup

如果您的问题仍未解决,还可以加入服务器在线技术交流QQ群:8017413寻求帮助。


相关内容
最新热点内容