VirtualBox 的命令行用法

作为一款功能强大的开源虚拟机软件,VirtualBox 不仅提供有图形化的用户界面,而且也包含命令行界面。VirtualBox 的命令行界面程序为 VBoxManage,通过它你可以完成从命令行创建虚拟机、修改虚拟机的选项设置、对虚拟机进行控制等几乎所有的操作。如果在 Headless Server 上,你将发现 VirtualBox 的命令行界面非常有用。

通过执行 VBoxManage --help 命令,你可以获得 VBoxManage 的完整用法。本文并不打算解释其中的每一个选项,仅给出创建一个虚拟机的必要步骤。如果你感兴趣,不妨亲自去探索 VBoxManage 的其他用法。

要从命令行创建虚拟机,你可以执行以下三步,我们以 Ubuntu 9.10 为例:

  1. 创建一个新的虚拟机,虚拟机的名称通过 --name 选项指定:

    VBoxManage createvm --name "Ubuntu 9.10" --register

  2. 创建该虚拟机所用的虚拟硬盘,用 --filename 指定虚拟硬盘的名称,--size 选项指定虚拟硬盘的大小,本例为 5 GB:

    VBoxManage createhd --filename "Ubuntu910.vdi" --size 5000 --remember

  3. 修改虚拟机的选项设置:

    VBoxManage modifyvm "Ubuntu 9.10" --memory "512MB" --hda "Ubuntu910.vdi" --dvd /home/linuxtoy/karmic-desktop-i386.iso --acpi on --accelerate3d on --boot1 dvd --nic1 nat

其中,

  • --memory 指定内存的大小
  • --hda 指定所用的虚拟硬盘
  • --dvd 指定所用的 ISO 映像
  • --acpi on 启用 ACPI
  • --accelerate3d on 启用 3D 加速
  • --boot1 引导次序
  • --nic1 网络设置

如果你愿意,那么现在便可以通过 VBoxManage startvm "Ubuntu 9.10" 来启动虚拟机。

Read More:

16 Comments

  1. 1 wenal Commented @ 2009-08-09 10:50Reply to this comment

    正想清理下vb呢,不知道我卸掉vb后,装了虚拟系统的那些空间都能自动的腾出来吗

  2. 2 macaulish Commented @ 2009-08-09 10:54Reply to this comment

    sf, 还是图形吧,不自招麻烦了。

    ps: 问一下kde下的一个软件: 就是可以记录你用电脑一天,记录你在每个程序上花的时间?比如 打游戏阿,,写文档之类

  3. 3 32idea Commented @ 2009-08-09 10:54Reply to this comment

    为了设置ssh登录,偶才接触到VBoxManage这个命令来设置端口,

  4. 4 hantsy Commented @ 2009-08-09 11:08Reply to this comment

    SUN 官方的文档中已经有详细的说明。

  5. 5 Rothsdad Commented @ 2009-08-09 11:13Reply to this comment

    @macaulish 自己可以写个脚本即可。自给自足,丰衣足食^_^

  6. 6 tzfox Commented @ 2009-08-09 11:38Reply to this comment

    看看。。。

  7. 7 灰瞳 Commented @ 2009-08-09 14:44Reply to this comment

    如果命令能控制虚拟的系统我肯定会用的玩玩.

  8. 8 caiaaa Commented @ 2009-08-09 16:49Reply to this comment

    最后一句启动虚拟机的命令最实用

  9. 9 eagle Commented @ 2009-08-09 19:07Reply to this comment

    这个也有命令,……

  10. 10 macaulish Commented @ 2009-08-09 20:17Reply to this comment

    @Rothsdad 有难度,gnome的面板里似乎有个的

  11. 11 G.S.Alex Commented @ 2009-08-09 22:03Reply to this comment

    也就启动实在,设置还是用图形好,谁记得那么多参数阿。

  12. 12 max Commented @ 2009-08-10 0:21Reply to this comment

    不知各位发现没有:建立硬盘时选择是动态的,结果用了一段时间后,越来越大,然而删除硬盘里面系统一些文件,硬盘大小不变,换句话说只增不减,不知怎么处理呀

  13. 13 peigen Commented @ 2009-08-10 9:29Reply to this comment

    不适很实用啊,不经常新建虚拟机嘛,对做系统测试的朋友应该比较需要,hoho

    因为公司用汪汪而开虚拟机...垃圾汪汪

  14. 14 Lucseeker Commented @ 2009-08-10 21:25Reply to this comment

    参考一下:

    http://blog.chinaunix.net/u3/93926/showart_1872556.html

  15. 15 Steve Commented @ 2009-08-13 6:35Reply to this comment

    对远程、只有ssh连接的admin很有用

  16. 16 test Commented @ 2009-08-14 13:58Reply to this comment

    要是有完整的中文帮助手册就好了。。。。