VirtualBox命令行VBoxManage创建与管理虚拟机教程

VirtualBox命令行VBoxManage创建与管理虚拟机教程VBoxManageisthecommand-lineinterfacetoVirtualBox.前言本文要操作的虚拟机信息如下:名称:UbuntuRDHome镜像名称:ubuntu-16.04.3-server-amd64.iso网络连接:桥接主机环境:$uname-a命令输出:LinuxUbuntuServer

大家好,又见面了,我是你们的朋友全栈君。

VBoxManage is the command-line interface to VirtualBox.

前言

本文要操作的虚拟机信息如下:
    名称: UbuntuRDHome
    镜像名称: ubuntu-16.04.3-server-amd64.iso
    网络连接: 桥接

主机环境:
    $ uname -a命令输出:
        Linux UbuntuServer 4.10.0-37-generic #41-Ubuntu SMP Fri Oct 6 20:20:37 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

    $ lsb_release -a命令输出:
        No LSB modules are available.
        Distributor ID: Ubuntu
        Description:    Ubuntu 17.04
        Release:        17.04
        Codename:       zesty

    $ ifconfig命令输出:
        enp5s0f0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
                inet 172.16.8.3  netmask 255.255.255.0  broadcast 172.16.8.255
                inet6 fe80::dad3:85ff:fee3:8a56  prefixlen 64  scopeid 0x20<link>
                ether d8:d3:85:e3:8a:56  txqueuelen 1000  (Ethernet)
                RX packets 12193671  bytes 5948053357 (5.9 GB)
                RX errors 0  dropped 0  overruns 0  frame 0
                TX packets 19703213  bytes 21537731944 (21.5 GB)
                TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
                device memory 0xc0400000-c041ffff  

        lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
                inet 127.0.0.1  netmask 255.0.0.0
                inet6 ::1  prefixlen 128  scopeid 0x10<host>
                loop  txqueuelen 1000  (Local Loopback)
                RX packets 12358  bytes 750596 (750.5 KB)
                RX errors 0  dropped 0  overruns 0  frame 0
                TX packets 12358  bytes 750596 (750.5 KB)
                TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

创建UbuntuRDHome虚拟机

创建虚拟机(同时注册)

VBoxManage createvm --name UbuntuRDHome --register

注册虚拟机

    VBoxManage registervm <Absolute Full Path>/UbuntuRDHome.vbox

仅注销虚拟机

    VBoxManage unregistervm UbuntuRDHome

删除虚拟机(!!!会删除所有虚拟硬盘,谨慎操作!!!)

    VBoxManage unregistervm --delete UbuntuRDHome

设置系统类型Ubuntu_64

VBoxManage modifyvm UbuntuRDHome --ostype Ubuntu_64

设置内存大小4G

VBoxManage modifyvm UbuntuRDHome --memory 4096

建立虚拟磁盘:系统盘100G

VBoxManage createmedium --filename UbuntuRDHome_HDD_SYS_100G.vdi --size 100000

建立虚拟磁盘:HOME盘100G

VBoxManage createmedium --filename UbuntuRDHome_HDD_HOME_100G.vdi --size 100000

创建存储控制器IDE、SATA

VBoxManage storagectl UbuntuRDHome --name IDE --add ide --controller PIIX4 --bootable on
VBoxManage storagectl UbuntuRDHome --name SATA --add sata --controller IntelAhci --bootable on

移除控制器:
    VBoxManage storagectl UbuntuRDHome --name IDE --remove
    VBoxManage storagectl UbuntuRDHome --name SATA --remove

关联虚拟机磁盘

VBoxManage storageattach UbuntuRDHome --storagectl SATA --port 0 --device 0 --type hdd --medium UbuntuRDHome_HDD_SYS_100G.vdi
VBoxManage storageattach UbuntuRDHome --storagectl SATA --port 1 --device 0 --type hdd --medium UbuntuRDHome_HDD_HOME_100G.vdi

解除关联:
    VBoxManage storageattach UbuntuRDHome --storagectl SATA --port 0 --device 0 --type hdd --medium none
    VBoxManage storageattach UbuntuRDHome --storagectl SATA --port 1 --device 0 --type hdd --medium none

关联镜像文件

VBoxManage storageattach UbuntuRDHome --storagectl IDE --port 0 --device 0 --type dvddrive --medium ubuntu-16.04.3-server-amd64.iso

VBoxManage storageattach UbuntuRDHome --storagectl IDE --port 1 --device 0 --type dvddrive --medium VBoxGuestAdditions_5.1.22.iso

解除关联:
    VBoxManage storageattach UbuntuRDHome --storagectl IDE --port 0 --device 0 --type dvddrive --medium none
    VBoxManage storageattach UbuntuRDHome --storagectl IDE --port 1 --device 0 --type dvddrive --medium none

设置网络为桥接(nictype和bridgeadapter要根据主机的实际情况选择)

VBoxManage modifyvm UbuntuRDHome --nic1 bridged --nictype1 82545EM --cableconnected1 on --bridgeadapter1 enp5s0f0 

设置远程桌面(可以使用VNC通过5540端口访问虚拟机桌面)

VBoxManage modifyvm UbuntuRDHome --vrdeport 5540 --vrdeaddress ""

打开远程桌面

VBoxManage modifyvm UbuntuRDHome --vrde on

关闭远程桌面

VBoxManage modifyvm UbuntuRDHome --vrde off

查看虚拟机信息

VBoxManage -v
VBoxManage list vms
VBoxManage list runningvms
VBoxManage showvminfo UbuntuRDHome
VBoxManage list hdds
VBoxManage list dvds

启动与管理虚拟机

启动虚拟机

VBoxManage startvm UbuntuRDHome --type headless

保持状态关闭虚拟机[推荐]

VBoxManage controlvm UbuntuRDHome savestate

放弃已保存的状态
    VBoxManage discardstate UbuntuRDHome

断电关闭虚拟机

VBoxManage controlvm UbuntuRDHome poweroff

正常关机[不能彻底关闭,一直处于stopping状态]

VBoxManage controlvm UbuntuRDHome acpipowerbutton

管理虚拟机更多命令

VBoxManage controlvm UbuntuRDHome XXX

高级配置

参照着VirtualBox GUI,凡是想要的功能都可以通过命令行执行。

设置CPU数量(必须打开IOAPIC)

VBoxManage modifyvm UbuntuRDHome  --ioapic on
VBoxManage modifyvm UbuntuRDHome --cpus 8

使能largepages选项

VBoxManage modifyvm UbuntuRDHome  --largepages on

设置CPU运行峰值

VBoxManage modifyvm UbuntuRDHome --cpuexecutioncap 80

虚拟硬盘的高级操作

VirtualBox的媒体是统一管理的,可以使用list查看:

VBoxManage list hdds

克隆媒体(克隆已有的虚拟硬盘文件,之后可以添加到虚拟机)

VBoxManage clonemedium hddfilename

移动虚拟硬盘位置(不是简单的cp或mv)

VBoxManage modifymedium hddfilename --move "new dir"

快照的创建和恢复(十分重要)

这里以创建快照 snap20171204-installed 为例,进行演示。

快照列表:

VBoxManage snapshot UbuntuRDHome list
VBoxManage snapshot UbuntuRDHome showvminfo snap20171204-installed

创建快照:

VBoxManage snapshot UbuntuRDHome take snap20171204-installed

删除快照:
    VBoxManage snapshot UbuntuRDHome delete snap20171204-installed

恢复快照:

VBoxManage snapshot UbuntuRDHome restore snap20171204-installed

恢复当前快照:

VBoxManage snapshot UbuntuRDHome restorecurrent

安装 Guest Additions(可选)

挂载CD/DVD虚拟光驱

sudo mount -t auto /dev/cdrom /mnt

(这里的cdrom是cd的,有时是dvd,具体有什么光驱到 /dev目录下查看)

安装

cd /mnt
sudo ./VBoxLinuxAdditions.run 

重启

sudo reboot

阅读原文 | 作者官网 | 公众号 | Feed | 订阅 | 发私信

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/133447.html原文链接:https://javaforall.net

(0)
上一篇 2022年6月8日 下午10:16
下一篇 2022年6月8日 下午10:16


相关推荐

  • C语言的字符串数组

    C语言的字符串数组在 C 语言当中 字符串数组可以使用 chara 10 或者 char a 表示第一种表示方式固定了每个字符串的最大大小 第二种没有字符串的大小限制 include lt stdio h gt include lt string h gt 该程序的功能是输入阿拉伯数字的月份数输出英文月份 intmain 一个字符串

    2026年3月18日
    2
  • 泪奔!DeepSeek + Crawl4AI搭建智能爬虫,一句话获取想要的数据

    泪奔!DeepSeek + Crawl4AI搭建智能爬虫,一句话获取想要的数据

    2026年3月16日
    2
  • GoogLeNet 神经网络结构

    GoogLeNet 神经网络结构GoogLeNet是2014年ILSVRC冠军模型,top-5错误率6.7%,GoogLeNet做了更大胆的网络上的尝试而不像vgg继承了lenet以及alexnet的一些框架,该模型虽然有22层,但参数量只有AlexNet的1/12。GoogLeNet论文指出获得高质量模型最保险的做法就是增加模型的深度(层数)或者是其宽度(层核或者神经元数),但是一般情况下更深或更宽的网络

    2022年8月14日
    12
  • Atom动态代码插件Activate Power Mode常用设置[通俗易懂]

    Atom动态代码插件Activate Power Mode常用设置[通俗易懂]相信用过Atom的人都知道它很方便,那么小编在这就介绍下ActivatePowerMode插件的一些实用设置如下:效果的起步阈值:刚装上插件后,效果是你按了20个代码后才有动态效果,在这里可以修改为立马有动态效果目录:Setting/ComboMode中找ComboMode-ActivationThreshold动态效果的声音调节:小编吐槽以下,我网上百度了下怎么调节声音大小,结果就没

    2022年7月14日
    30
  • s3c2440启动过程分析

    s3c2440启动过程分析2440启动过程分析作者:王辉 2440启动过程算是一个难点,不太容易理解,而对于2440启动过程的理解,影响了后面裸机代码执行流程的分析,从而看出2440启动过程的重要性。 1 2440启动方式和启动方式选择在S3C2440的datasheet《S3C2440A_UserManual_Rev13.pdf》中搜索map,可以在第5章中搜索到下图。 从此

    2022年6月11日
    28
  • JAVA课程设计——飞机大战(个人)

    JAVA课程设计——飞机大战(个人)

    2021年10月6日
    63

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号