VirtualBox

出自Centos

跳转到: 导航, 搜索

目录

VirtualBox概况

对于 VMWare、Virtual PC 这些虚拟机软件,可能大家都比较熟悉。VirtualBox也是一款虚拟机软件。VirtualBox 是一款功能强大的 x86 虚拟机软件,它不仅具有丰富的特色,而且性能也很优异。更可喜的是,VirtualBox 于数日前走向开源,成为了一个发布在 GPL 许可之下的自由软件。VirtualBox 可以在 Linux 和 Windows 主机中运行,并支持在其中安装 Windows (NT 4.0、2000、XP、Server 2003、Vista)、DOS/Windows 3.x、Linux (2.4 和 2.6)、OpenBSD 等系列的客户操作系统。 官方地址:http://www.virtualbox.org/

安装VitualBox

下载相应的rpm包,官方有提供地址:http://www.virtualbox.org/wiki/Downloads Centos请访问http://www.virtualbox.org/wiki/Linux_Downloads 此地址提供各linux版本的二进制安装包, 下载centos5对应的rpm安装包

[root@xingke disk1]# wget http://download.virtualbox.org/virtualbox/2.0.2/VirtualBox-2.0.2_36488_rhel5-1.i386.rpm

查看kernel-devel包是否安装,安装VirtualBox需要此包编译模块

[root@xingke disk1]# rpm -q kernel-devel
kernel-devel-2.6.18-92.el5

如未安装,请使用如下命令先安装

[root@xingke disk1]# yum -y install kernel-devel
kernel-devel-2.6.18-92.el5

安装VirtualBox

[root@xingke disk1]# rpm -Uvh VirtualBox-2.0.2_36488_rhel5-1.i386.rpm 
Preparing...                ########################################### [100%]
   1:VirtualBox             ########################################### [100%]
chcon: can't apply partial context to unlabeled file /usr/lib/virtualbox/VirtualBox
chcon: can't apply partial context to unlabeled file /usr/lib/virtualbox/VBoxSDL
chcon: can't apply partial context to unlabeled file /usr/lib/virtualbox/VBoxHeadless
chcon: can't apply partial context to unlabeled file /usr/lib/virtualbox/vboxwebsrv

Creating group 'vboxusers'. VM users must be member of that group!

No precompiled module for this kernel found -- trying to build one. Messages
emitted during module compilation will be logged to /var/log/vbox-install.log.

Success!

把打算使用的用户添加安装vboxusers用户组里

[root@xingke disk1]#sudo usermod -a -G vboxusers username

经过上述几个步骤,VirtualBox在centos5上以成功安装


添加网卡桥接功能

先安装桥接使用工具

[root@xingke ~]# yum -y install bridge-utils
Loading "fastestmirror" plugin
Loading mirror speeds from cached hostfile
 * base: 192.168.3.13
 * updates: 192.168.3.13
 * addons: 192.168.3.13
 * extras: 192.168.3.13
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
--> Running transaction check
---> Package bridge-utils.i386 0:1.1-2 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size 
=============================================================================
Installing:
 bridge-utils            i386       1.1-2            base               27 k

Transaction Summary
=============================================================================
Install      1 Package(s)         
Update       0 Package(s)         
Remove       0 Package(s)         

Total download size: 27 k
Downloading Packages:
(1/1): bridge-utils-1.1-2 100% |=========================|  27 kB    00:00     
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing: bridge-utils                 ######################### [1/1] 

Installed: bridge-utils.i386 0:1.1-2
Complete!
[root@xingke ~]# 

新建一个br0桥接网卡

vi /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE=br0
TYPE=Bridge
BOOTPROTO=dhcp
ONBOOT=yes

在原来的eth0网卡配置文件/etc/sysconfig/network-scripts/ifcfg-eth0末尾添加BRIDGE=br0

vi /etc/sysconfig/network-scripts/ifcfg-eth0
.
//此处省略
.
BRIDGE=br0

然后重启网络

sudo /sbin/service network restart

增加桥接的主机网卡

[root@xingke ~]# VBoxAddIF vbox0 root br0  <--此处的root是网卡用户帐号,谁可以使用此网卡,这里我用了root
VirtualBox host networking interface creation utility, version 2.0.2
(C) 2005-2007 Sun Microsystems, Inc.
All rights reserved.

Creating the permanent host networking interface "vbox0" for user root.

Failed to add the interface "vbox0" to the bridge "br0".
Make sure that the bridge exists and that you currently have sufficient
permissions to do this.
[root@xingke ~]# 

添加虚拟客户机

运行VirtualBox

[root@xingke ~]#VirtualBox

弹出管理界面

Image:VirtualBox-install-01.png‎

其他的按一般的虚拟主机设置,特别的地方是网卡,附上一截图

Image:VirtualBox-install-02.png‎

Attached to选择host interface

interface name填写上面新建的vbox0

才可以使用到桥接功能

安装鼠标增强组件

安装后需要安装格外的一个增强组件,可以在主机和客户机鼠标方便移动

lihaixin@lihaixin-desktop:~$ sudo /media/cdrom/VBoxLinuxAdditions-x86.run 
[sudo] password for lihaixin: 
Verifying archive integrity... All good.
Uncompressing VirtualBox 2.0.2 Guest Additions for Linux installation.........................................................................................................................................................................................
VirtualBox 2.0.2 Guest Additions installation
Building the VirtualBox Guest Additions kernel module...
Building the shared folder support kernel module...
Installing the VirtualBox Guest Additions...

Successfully installed the VirtualBox Guest Additions.
You must restart your guest system in order to complete the installation.
lihaixin@lihaixin-desktop:~$ 

一些技巧

  • guest全屏幕的方法是在guest操作模式下按ctrl-f(键盘右边的ctrl),切换也是一样的按键组合
  • 另外我本来想在kernel-xen此核心上安装,这样可以同时运行xen虚拟机和VirtualBox,但是在编译模块的时候不成功,应该是VirtulBox不能在此核心运行
  • 建议把默认VirtualBox两个守护进程设置为不自动运行
[root@xingke ~]# chkconfig --level 345 vboxdrv off
[root@xingke ~]# chkconfig --level 345 vboxnet off

使用sh脚本运行,建立/home/disk1/VirtulBox/VirtualBox-start.sh

#!/bin/sh
/etc/init.d/vboxdrv start > /dev/null
/etc/init.d/vboxnet start > /dev/null
/usr/bin/VirtualBox

参考资料

官方手册:http://download.virtualbox.org/virtualbox/2.0.2/UserManual.pdf

针对本文的建议

http://www.lihaixin.com/2008/10/virtualbox-install-ok-407.html

个人工具