VirtualBox 命令行模式操作简述

用迁移虚拟机做个例子

1. 在另外一台有GUI 界面的机器export Ubuntu16.04.ova 文件


2. 在没有GUI 界面的机器导入ova 文件
# vboxmanage import /Path/To/Ubuntu16.04.ova

如果你想改变默认安装目录,在执行上面这句前执行

# vboxmanage setproperty machinefolder


3. 查看导入的 vms (导入的时候这个vms已经注册了,所以可以列出来)
# vboxmanage list vms
"Ubuntu16.04" {ab5688fc-44e1-4f7a-9746-d6e07e94e622}

Ubuntu16.04 是这个vms的名字
ab5688fc-44e1-4f7a-9746-d6e07e94e622 是这个vms的uuid
在下面的命令中,可以用vms的名字也可以用这个uuid

4. 修改虚拟机配置

如果你在有GUI界面机器设置一个网络接口是 Bridge 模式。这会绑定当前机器实际的网络接口。当你在新的环境执行,你需要修改这个配置,绑定你当前机器的一个网络接口
例子:
a) 查看当前的虚拟机配置

# vboxmanage showvminfo ab5688fc-44e1-4f7a-9746-d6e07e94e622
Name:            Ubuntu16.04
Groups:          /
Guest OS:        Ubuntu (64-bit)
UUID:            ab5688fc-44e1-4f7a-9746-d6e07e94e622
Config file:     /work/Ubuntu16.04-VM2/Ubuntu16.04-VM2.vbox
Snapshot folder: /work/Ubuntu16.04-VM2/Snapshots
Log folder:      /work/Ubuntu16.04-VM2/Logs
Hardware UUID:   92a884f4-89f5-4dd2-90cd-0f0904de5fff
Memory size:     2048MB
Page Fusion:     off
VRAM size:       16MB
CPU exec cap:    100%
HPET:            off
Chipset:         piix3
Firmware:        BIOS
Number of CPUs:  2
PAE:             off
Long Mode:       on
Triple Fault Reset: off
APIC:            on
X2APIC:          on
CPUID Portability Level: 0
CPUID overrides: None
Boot menu mode:  message and menu
Boot Device (1): DVD
Boot Device (2): HardDisk
Boot Device (3): Not Assigned
Boot Device (4): Not Assigned
ACPI:            on
IOAPIC:          on
BIOS APIC mode:  APIC
Time offset:     0ms
RTC:             UTC
Hardw. virt.ext: on
Nested Paging:   on
Large Pages:     off
VT-x VPID:       on
VT-x unr. exec.: on
Paravirt. Provider: Default
Effective Paravirt. Provider: KVM
State:           powered off (since 2018-09-28T04:23:12.000000000)
Monitor count:   1
3D Acceleration: off
2D Video Acceleration: off
Teleporter Enabled: off
Teleporter Port: 0
Teleporter Address: 
Teleporter Password: 
Tracing Enabled: off
Allow Tracing to Access VM: off
Tracing Configuration: 
Autostart Enabled: off
Autostart Delay: 0
Default Frontend: 
Storage Controller Name (0):            IDE
Storage Controller Type (0):            PIIX4
Storage Controller Instance Number (0): 0
Storage Controller Max Port Count (0):  2
Storage Controller Port Count (0):      2
Storage Controller Bootable (0):        on
Storage Controller Name (1):            SATA
Storage Controller Type (1):            IntelAhci
Storage Controller Instance Number (1): 0
Storage Controller Max Port Count (1):  30
Storage Controller Port Count (1):      1
Storage Controller Bootable (1):        on
IDE (1, 0): Empty
SATA (0, 0): /work/Ubuntu16.04-VM2/Ubuntu16.04-VM2-disk001.vmdk (UUID: 51b0b7ed-09ec-49b7-9ed3-18d1a3547bd1)
NIC 1:           MAC: 0800270C376E, Attachment: NAT, Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none
NIC 1 Settings:  MTU: 0, Socket (send: 64, receive: 64), TCP Window (send:64, receive: 64)
NIC 1 Rule(0):   name = HTTP, protocol = tcp, host ip = , host port = 10081, guest ip = , guest port = 80
NIC 1 Rule(1):   name = SSH, protocol = tcp, host ip = , host port = 10023, guest ip = , guest port = 22
NIC 2:           MAC: 080027D2D77A, Attachment: Bridged Interface 'enp0s25', Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none
NIC 3:           disabled
NIC 4:           disabled
NIC 5:           disabled
NIC 6:           disabled
NIC 7:           disabled
NIC 8:           disabled
Pointing Device: USB Tablet
Keyboard Device: PS/2 Keyboard
UART 1:          disabled
UART 2:          disabled
UART 3:          disabled
UART 4:          disabled
LPT 1:           disabled
LPT 2:           disabled
Audio:           disabled
Clipboard Mode:  disabled
Drag and drop Mode: disabled
VRDE:            disabled
USB:             enabled
EHCI:            disabled
XHCI:            disabled

USB Device Filters:



Bandwidth groups:  

Shared folders:  

Video capturing:    not active
Capture screens:    0
Capture file:       /work/Ubuntu16.04-VM2/Ubuntu16.04-VM2.webm
Capture dimensions: 1024x768
Capture rate:       512 kbps
Capture FPS:        25

Guest:

Configured memory balloon size:      0 MB


上面例子中设置了两个网络接口,Nic1 是 NAT 模式, Nic2 是 Bridge 模式。这里 Nic2 绑定的网络接口名字是 enp0s25. 下面我们改成当前机器的网络接口名字

# vboxmanage modifyvm --bridgeadapter2 enp2s0

根据需要,可以用 modifyvm 来调整当前的 vms 的配置

5. 启动虚拟机
# vboxmanage startvm ab5688fc-44e1-4f7a-9746-d6e07e94e622 --type headless
6. 关闭虚拟机
# vboxmanage controlvm ab5688fc-44e1-4f7a-9746-d6e07e94e622 poweroff

你可能感兴趣的:(VirtualBox 命令行模式操作简述)