centos 6 安装virtualbox

来源:互联网 发布:mac os 10.11 cdr 编辑:程序博客网 时间:2024/05/29 14:25

以前一直用vmware,linux下一般用vmware server 但是最近升级到centos6 vmware server 安装就一直有问题。

没办法就换成virtual box

也是一个很不错的虚拟机软件,

可以完全在命令行操作,适合远程安装操作。

经过几次的安装觉得不错,记下来以便以后使用,同时也推荐给大家。

 

安装前的准备 

要安装的包,根距环境不同,会有不同 但以下几个包是必须的,其它如果没有,就增加就行了
yum install qt qt-x11 gcc kernel-devel-{内核版本号}

virtualBox默认是在DKMS内核内运行。
安装DKMS:
http://linux.dell.com/dkms/
下载后安装
rpm -ivh dkms-2.2.0.2-1.noarch.rpm

下载virtualbox安装文件:
VirtualBox-4.1-4.1.4_74291_rhel6-1.x86_64.rpm
下载扩展补定,可以用3389远程连接到桌面,否则只能用桌面安装了
Oracle_VM_VirtualBox_Extension_Pack-4.1.4-74291.vbox-extpack

开始安装:
rpm -ivh VirtualBox-4.1-4.1.4_74291_rhel6-1.x86_64.rpm
安装时会在/var/log/vbox-install.log打出安装日志,如果安装失败,则看此处文件可以知道哪有错误了,

打补定:
VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-4.1.4-74291.vbox-extpack

安装完成后开始创建配置:
创建虚拟机:
VBoxManage createvm --name win2003 --ostype Windows2003 --register --basefolder /data/virtualbox/
设置一些属性:如果CPU不支持虚拟化,则此处只能用一个CPU,且不能装64位系统。
VBoxManage modifyvm win2003 --memory 2048 --cpus 1 --ioapic on --vram 16 --acpi on --pae on --hwvirtex on
创建虚拟硬盘
VBoxManage createvdi  --filename /data/virtualbox/win2003.vdi --size 20480
创建硬盘控制器:
VBoxManage storagectl win2003 --name storage_controller_1 --add ide
挂载虚拟硬盘和光盘:
VBoxManage storageattach win2003 --storagectl storage_controller_1 --type hdd --port 0 --device 0  --medium /data/virtualbox/win2003.vdi
VBoxManage storageattach win2003 --storagectl storage_controller_1 --type dvddrive --port 1 --device 0 --medium /data/virtualbox/Windows.Server.2003.MSsetup.ISO

打开vrde模块,可以用远程桌面连接:
VBoxManage modifyvm win2003 --vrde on

设置启动顺序:
VBoxManage modifyvm win2003 --boot1 dvd
VBoxManage modifyvm win2003 --boot2 disk

配置网络(网桥方式,好处时,可以在虚拟机内设置与宿主主机一样的IP段及地址,以后虚拟机就相当于一台内网机器,我觉得这种方式非常方便):
VBoxManage modifyvm win2003 --nic1 bridged --cableconnected1 on --nictype1 82540EM --bridgeadapter1 eth0 --intnet1 brigh1 --macaddress1 auto

启动虚拟机:
VBoxHeadless -startvm win2003 &

然后用远程桌面连接一宿主机,进行安装操作系统的操作。

安装完操作系统并分配好IP后,就可以关闭3389的监听:

VBoxManage modifyvm win2003 --vrde off

如果不关闭,则任何人都可以通过3389连上虚拟机。

 

其它的一些选项:
查看已有配置:
VBoxManage showvminfo win2003 --details
管理:
VBoxManage controlvm
 pause|resume|reset|poweroff|savestate|
 暂定  恢复   重启  关机     保存

删除一个磁盘:
VBoxManage list hdds
VBoxManage  closemedium disk /data/virtualbox/win2003.vhd --delete

装好操作系统后,可以做一下磁盘备份,以便以后同操作系统时,不用再重装,但如果直接COPY的话,是无法挂载的。可以用硬盘克隆
VBoxManage clonevm


如果启动时出现:

Error: failed to start machine. Error message: VT-x features locked or unavailable in MSR. (VERR_VMX_MSR_LOCKED_OR_DISABLED)
一个原因是CPU不支持虚拟化技术,
如果支持,则可能在BIOS内没有开启虚拟化功能。打开就可以了,
否则可以把CPU改成1个也可以

 

由于服务器需要断电,但是服务器上的虚拟机并没有正常关闭,结果再开机的时候就显示下面的错误:

[root@localhost ~]# vboxmanage startvm winxp
Waiting for VM "winxp" to power on...
VBoxManage: error: The virtual machine 'winxp' has terminated unexpectedly during startup with exit code 0
VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component Machine, interface IMachine, callee


用help命令查了一下,启动的时候还有3个参数可以选用。

VBoxManage startvm |...
[--type gui|sdl|headless]


连接就没成功,可能和界面有关系。干脆用无界面的方式启动,问题解决。

[root@localhost ~]# vboxmanage startvm winxp --type headless
Waiting for VM "winxp" to power on...
VM "winxp" has been successfully started.


2013-01-22
如果硬盘位置发生改变:
先挂成空的:
VBoxManage storageattach dump --storagectl storage_controller_1 --port 0 --device 0  --medium none
找到虚拟机配置文件目录下的:name.vbox-prev 找到对应的硬路径的字附件,然后改成正确的位置。
再重新挂载一下硬盘


 先写这么多,以后有更多发现的东西再补充。。


2013-01-28
中途有发现问题,运行:VBoxManager时提示:

WARNING: The vboxdrv kernel module is not loaded. Either there is no module
         available for the current kernel (2.6.18-164.el5PAE) or it failed to
         load. Please recompile the kernel module and install it by

           sudo /etc/init.d/vboxdrv setup

         You will not be able to start VMs until this problem is fixed.

进行:
sudo /etc/init.d/vboxdrv setup
又报错,提示找不到kernel,后来发现我是单独把kernel升级造成的,
将头文件分别用yum install kernel*后运行:
/etc/init.d/vboxdrv setup

dmesg内提示:
vboxdrv: disagrees about version of symbol struct_module

找了很多资料发现还是kernel的版本问题
运行uname -r 发现版本号还是旧的,
于是把旧的版本的kernel都删除了,
然后再重启,
重启后,uname -r  显示是最近新的
/etc/init.d/vboxdrv setup
后成功,没有问题了。