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

时间:2021-09-20 23:41:20

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 Interface 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   | 子命令可以改变虚拟机的运行状态,
其中常用的几个选项是:

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

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

QHo@qhoferrari1k:~$ VBoxManage list runningvms 
VirtualBox Command Line Management Interface 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 Interface 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       | [--details]

[--machinereadable]

VBoxManage showvminfo       | --log

VBoxManage registervm      

VBoxManage unregistervm     | [--delete]

VBoxManage createvm         --name

[--ostype ]

[--register]

[--basefolder ]

[--uuid ]

VBoxManage modifyvm        

[--name ]

[--ostype ]

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

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

[--cpuidremove ]

[--cpuidremoveall]

[--hardwareuuid ]

[--cpus ]

[--cpuhotplug on|off]

[--plugcpu ]

[--unplugcpu ]

[--cpuexecutioncap <1-100>]

[--rtcuseutc on|off]

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

[--biossystemtimeoffset ]

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

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

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

[--nicgenericdrv<1-N>

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

[--keyboard ps2|usb

[--uart<1-N> off| ]

[--uartmode<1-N> disconnected|

                 server |

                 client |

                 file |

                 ]

[--guestmemoryballoon ]

[--gueststatisticsinterval ]

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

[--audiocontroller ac97|hda|sb16]

[--clipboard disabled|hosttoguest|guesttohost|

             bidirectional]

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

[--snapshotfolder default|]

[--teleporter on|off]

[--teleporterport ]

[--teleporteraddress



[--teleporterpassword ]

VBoxManage clonevm          |

[--snapshot |]

[--mode machine|machineandchildren|all]

[--options link|keepallmacs|keepnatmacs|

           keepdisknames]

[--name ]

[--basefolder ]

[--uuid ]

[--register]

VBoxManage import          

[--dry-run|-n]

[--options keepallmacs|keepnatmacs]

[more options]

(run with -n to have options displayed

 for a particular OVF)

VBoxManage export           --output|-o

[--legacy09]

[--manifest]

[--vsys ]

        [--product ]

        [--producturl ]

        [--vendor ]

        [--vendorurl ]

        [--version ]

        [--eula ]

        [--eulafile ]

VBoxManage startvm          |...

[--type gui|sdl|headless]

VBoxManage controlvm        |

pause|resume|reset|poweroff|savestate|

acpipowerbutton|acpisleepbutton|

keyboardputscancode [ ...]|

setlinkstate<1-N> on|off |

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

         [] |

nictrace<1-N> on|off

nictracefile<1-N>

nicproperty<1-N> name=[value]

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

              ,[],

natpf<1-N> delete

guestmemoryballoon ]

gueststatisticsinterval ]

usbattach |

|

usbdetach |

|

vrde on|off |

vrdeport |

vrdeproperty |

vrdevideochannelquality

setvideomodehint [display] |

screenshotpng [display] |

setcredentials

               [--allowlocallogon ] |

teleport --host --port

       [--maxdowntime ] [--password password]

plugcpu

unplugcpu

cpuexecutioncap <1-100>

VBoxManage discardstate     |

 

VBoxManage adoptstate       |

 

VBoxManage snapshot         |

take [--description ] [--pause] |

delete | |

restore | |

restorecurrent |

edit ||--current

     [--name ]

     [--description ] |

showvminfo |

VBoxManage closemedium      disk|dvd|floppy |

[--delete]

VBoxManage storageattach    

--storagectl

[--port ]

[--device ]

[--type dvddrive|hdd|fdd]

[--medium none|emptydrive|

          ||host:|iscsi]

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

         readonly|multiattach]

[--comment ]

[--setuuid ]

[--setparentuuid ]

[--passthrough on|off]

[--tempeject on|off]

[--nonrotational on|off]

[--bandwidthgroup ]

[--forceunmount]

[--server |]

[--target ]

[--tport ]

[--lun ]

[--encodedlun ]

[--username ]

[--password ]

[--intnet]

VBoxManage storagectl      

--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    

--name

[--add disk|network]

[--limit

[--delete]

VBoxManage showhdinfo       |

 

VBoxManage createhd         --filename

--size |--sizebyte

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

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

VBoxManage modifyhd         |

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

        readonly|multiattach]

[--autoreset on|off]

[--compact]

[--resize |--resizebyte ]

VBoxManage clonehd          | |

[--format VDI|VMDK|VHD|RAW|]

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

[--existing]

VBoxManage convertfromraw  

[--format VDI|VMDK|VHD]

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

VBoxManage convertfromraw   stdin

[--format VDI|VMDK|VHD]

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

VBoxManage getextradata     global||

|enumerate

VBoxManage setextradata     global||

 

[] (no value deletes key)

VBoxManage setproperty      machinefolder default| |

vrdeauthlibrary default| |

websrvauthlibrary default|null| |

vrdeextpack null| |

loghistorycount

VBoxManage usbfilter        add

--target ||global

--name

--action ignore|hold (global filters only)

[--active yes|no] (yes)

[--vendorid ] (null)

[--productid ] (null)

[--revision ] (null)

[--manufacturer ] (null)

[--product ] (null)

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

[--serialnumber ] (null)

[--maskedinterfaces ]

VBoxManage usbfilter        modify

--target ||global

[--name ]

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

[--active yes|no]

[--vendorid |""]

[--productid |""]

[--revision |""]

[--manufacturer |""]

[--product |""]

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

[--serialnumber |""]

[--maskedinterfaces ]

VBoxManage usbfilter        remove

--target ||global

VBoxManage sharedfolder     add |

--name --hostpath

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

VBoxManage sharedfolder     remove |

--name [--transient]

VBoxManage guestproperty    get |

[--verbose]

VBoxManage guestproperty    set |

[ [--flags ]]

VBoxManage guestproperty    enumerate |

[--patterns ]

VBoxManage guestproperty    wait |

[--timeout ] [--fail-on-timeout]

VBoxManage guestcontrol     |

exec[ute]

--image

--username --password

[--dos2unix]

[--environment "= [=]"]

[--timeout ] [--unix2dos] [--verbose]

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

[-- [] ... []]

copyfrom

 

--username --password

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

copyto|cp

 

--username --password

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

createdir[ectory]|mkdir|md

 

--username --password

[--parents] [--mode ] [--verbose]

stat

 

--username --password

[--verbose]

updateadditions

[--source ] [--verbose]

VBoxManage debugvm          |

dumpguestcore --filename |

info [args] |

injectnmi |

osdetect |

osinfo |

getregisters [--cpu ] |all ... |

setregisters [--cpu ] = ... |

statistics [--reset] [--pattern ]

[--descriptions]

VBoxManage metrics          list [*|host| []]

                     (comma-separated)

VBoxManage metrics          setup

[--period ] (default: 1)

[--samples ] (default: 1)

[--list]

[*|host| []]

VBoxManage metrics          query [*|host| []]

VBoxManage metrics          enable

[--list]

[*|host| []]

VBoxManage metrics          disable

[--list]

[*|host| []]

VBoxManage metrics          collect

[--period ] (default: 1)

[--samples ] (default: 1)

[--list]

[--detach]

[*|host| []]

VBoxManage hostonlyif       ipconfig

[--dhcp |

--ip [--netmask (def: 255.255.255.0)] |

--ipv6 [--netmasklengthv6 (def: 64)]]

create |

remove

VBoxManage dhcpserver       add|modify --netname |

           --ifname

[--ip

--netmask

--lowerip

--upperip ]

[--enable | --d