感谢支持
我们一直在努力

在Ubuntu 10.04 LTS Server上通过SSH安装Virtualbox 4.0

直接在Server上安装virtualbox-ose(Open Source Edition)版本后, 启动老是提示出错:

MyServer:~#/etc/init.d/virtualbox-ose start
* Starting VirtualBox host networking… [ OK ]
* Starting VirtualBox kernel module vboxdrv
* No suitable module for running kernel found.

后来发现官方网站上闭源版本的介绍, 真是很详尽: http://www.virtualbox.org/wiki/Linux_Downloads

MyServer:~#vi /etc/apt/sources.list

添加一句:

deb http://download.virtualbox.org/virtualbox/debian lucid contrib

MyServer:~#wget http://download.virtualbox.org/virtualbox/debian/Oracle_vbox.asc
MyServer:~# apt-key add oracle_vbox.asc
MyServer:~#wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc -O- | sudo apt-key add –
MyServer:~# apt-get update
MyServer:~# apt-get install virtualbox-4.0

第一次运行出错:

MyServer:~# /etc/init.d/vboxdrv setup
* Stopping VirtualBox kernel modules [ OK ]
* Uninstalling old VirtualBox DKMS kernel modules [ OK ]
* Trying to register the VirtualBox kernel modules using DKMS
Error! Your kernel headers for kernel 2.6.32-28-server cannot be found at
/lib/modules/2.6.32-28-server/build or /lib/modules/2.6.32-28-server/source.
 
* Failed, trying without DKMS
* Recompiling VirtualBox kernel modules
* Look at /var/log/vbox-install.log to find out what went wrong

查找错误日志 /var/log/vbox-install.log 发现提示要安装linux-headers-2.6.32-28-server

apt-get install linux-headers-2.6.32-28-server

或者

apt-get install linux-headers-`uname -r`
apt-get install linux-headers-generic

再次启动就正常了

MyServer:~# /etc/init.d/vboxdrv start
* Starting VirtualBox kernel modules [ OK ]

运行Setup看看:

MyServer:~# /etc/init.d/vboxdrv setup
* Stopping VirtualBox kernel modules [ OK ]
* Uninstalling old VirtualBox DKMS kernel modules [ OK ]
* Trying to register the VirtualBox kernel modules using DKMS [ OK ]
* Starting VirtualBox kernel modules

如果Linux内核升级后,出现 Failed, trying without DKMS

/etc/init.d/vboxdrv setup
* Stopping VirtualBox kernel modules [ OK ]
* Uninstalling old VirtualBox DKMS kernel modules [ OK ]
* Removing old VirtualBox netadp kernel module [ OK ]
* Removing old VirtualBox netflt kernel module [ OK ]
* Removing old VirtualBox kernel module [ OK ]
* Trying to register the VirtualBox kernel modules using DKMS
* Failed, trying without DKMS
* Recompiling VirtualBox kernel modules [ OK ]
* Starting VirtualBox kernel modules [ OK ]

那就安装dkms

apt-get install dkms

好了, 现在可以用普通用户的身份来使用虚拟机了
Ubuntu1010是网上下载的IDE硬盘系统
Ubuntu1004是自己装的Sata硬盘系统
在上传虚拟机镜像之前,最好在本地打开虚拟机,清除一下网卡MAC addresses的Cache后再关机:

sudo rm /etc/udev/rules.d/70-persistent-net.rules

创建Windows的虚拟机

user@MyServer:~$VBoxManage createvm –name Ubuntu1010 –register
Virtual machine ‘Ubuntu1010’ is created and registered.
UUID: b066726c-8559-48f1-b998-fd7ad742e7ce
Settings file: ‘/home/user/VirtualBox VMs/Ubuntu1010/Ubuntu1010.vbox’
 
user@MyServer:~$VBoxManage createvm –name Ubuntu1004 –register
Virtual machine ‘Ubuntu1004’ is created and registered.
UUID: 9e2a7030-953e-4935-aad7-07de8269ab1c
Settings file: ‘/home/www/VirtualBox VMs/Ubuntu1004/Ubuntu1004.vbox’

顺便贴一下如何删除虚拟机,包括虚拟机文件, 下手前要三思:

user@MyServer:~$VBoxManage unregistervm Ubuntu1004 –delete

创建虚拟机所需的存储控制器

user@MyServer:~$VBoxManage storagectl Ubuntu1010 –name “IDE Controller” –add ide –controller PIIX4 –hostiocache on
user@MyServer:~$VBoxManage storagectl Ubuntu1004 –name “SATA Controller” –add sata –controller IntelAHCI –hostiocache on

网上下载一个已经装好了的Virtualbox镜像 (user/passwd: Ubuntu/reverse), 解压, 移到相应目录下

user@MyServer:~$wget http://downloads.sourceforge.net/project/virtualboximage/Ubuntu%20Linux/10.10/Ubuntu%2010.10.vdi.bz2
bzip2 -d Ubuntu\ 10.10.vdi.bz2
mv Ubuntu\ 10.10.vdi /home/user/VirtualBox\ VMs/Ubuntu1010/Ubuntu1010.vdi
 
user@MyServer:~$mv Ubuntu\ 1004.vdi /home/user/VirtualBox\ VMs/Ubuntu1004/Ubuntu1004.vdi

添加硬盘到虚拟机

user@MyServer:~$VBoxManage storageattach Ubuntu1010 –storagectl “IDE Controller” –port 0 –device 0 –type hdd –medium /home/user/VirtualBox\ VMs/Ubuntu1010/Ubuntu1010.vdi
 
user@MyServer:~$VBoxManage storageattach Ubuntu1004 –storagectl “SATA Controller” –port 0 –device 0 –type hdd –medium /home/user/VirtualBox\ VMs/Ubuntu1004/Ubuntu1004.vdi
配置虚拟机网卡(桥接模式):

user@MyServer:~$VBoxManage modifyvm Ubuntu1010 –acpi on –memory 1024 –nic1 bridged –cableconnected1 on –bridgeadapter1 eth0
user@MyServer:~$VBoxManage modifyvm Ubuntu1004 –acpi on –memory 4096 –nic1 bridged –cableconnected1 on –bridgeadapter1 eth0

查看桥接状态:

user@MyServer:~$VBoxManage list bridgedifs
user@MyServer:~$VBoxManage showvminfo Ubuntu1004

可以看看更详细的桥接方法:


http://www.linuxidc.com/Linux/2011-03/33273.htm


想追踪网络,保存在trace.pcap文件中:

user@MyServer:~$VBoxManage modifyvm Ubuntu1004 –nictrace1 on –nictracefile1 trace.pcap

取消追踪

user@MyServer:~$VBoxManage modifyvm Ubuntu1004 –nictrace1 off

启动虚拟机, headless也就是无头模式, 显示器就是电脑的头, 形象吧

user@MyServer:~$VBoxManage startvm Ubuntu1010 –type headless
user@MyServer:~$VBoxManage startvm Ubuntu1004 –type headless

如果你装的是Windows, 想用RDP登录, 还想把3389改掉:

user@MyServer:~$VBoxManage modifyvm Windows2008 –vrdp on
user@MyServer:~VBoxManage modifyvm Windows2008 –vrdpport 3390

查看系统中正在运行的虚拟机:

user@MyServer:~$VBoxManage list runningvms
“Ubuntu1010” {b066726c-8559-48f1-b998-fd7ad742e7ce}

关机

user@MyServer:~$VBoxManage controlvm Ubuntu1010 poweroff
0%…10%…20%…30%…40%…50%…60%…70%…80%…90%…100%

poweroff 的兄弟姐妹们:

pause resume reset savestate acpipowerbutton acpisleepbutton

如果磁盘空间不够了, 那VBox4.0支持resize:

user@MyServer:~$VBoxManage modifyhd Ubuntu1010.vdi –resize 40000

clone一个虚拟机:

user@MyServer:~$VBoxManage clonehd Ubuntu1004.vdi destination.vdi

什么? 不想这么折腾了, 那删了吧:

user@MyServer:~$VBoxManage unregistervm Ubuntu1010 –delete

=======================


设置ssh端口转发:

user@MyServer:~$ VBoxManage setextradata “Ubuntu1004” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/Protocol” TCP
user@MyServer:~$ VBoxManage setextradata “Ubuntu1004” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/GuestPort” 22
user@MyServer:~$ VBoxManage setextradata “Ubuntu1004” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/HostPort” 22222

错误记录:

user@MyServer:~$VBoxManage startvm Ubuntu1004 –type headless
Waiting for the VM to power on…
VBoxManage: error: Configuration error: Failed to get the “MAC” value (VERR_CFGM_VALUE_NOT_FOUND).
VBoxManage: error: Unknown error creating VM (VERR_CFGM_VALUE_NOT_FOUND)
VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component Console, interface IConsole, callee

可能因为原来设置过nic2, 还给nic2设置了端口转发, 后来删除了nic2, 却忘了把转发删除:
设置:

user@MyServer:~$ VBoxManage setextradata “Ubuntu1004” “VBoxInternal/Devices/pcnet/1/LUN#1/Config/guestssh/Protocol” TCP
user@MyServer:~$ VBoxManage setextradata “Ubuntu1004” “VBoxInternal/Devices/pcnet/1/LUN#1/Config/guestssh/GuestPort” 22
user@MyServer:~$ VBoxManage setextradata “Ubuntu1004” “VBoxInternal/Devices/pcnet/1/LUN#1/Config/guestssh/HostPort” 22222

删除:

user@MyServer:~$ VBoxManage setextradata “Ubuntu1004” “VBoxInternal/Devices/pcnet/1/LUN#1/Config/guestssh/Protocol”
user@MyServer:~$ VBoxManage setextradata “Ubuntu1004” “VBoxInternal/Devices/pcnet/1/LUN#1/Config/guestssh/GuestPort”
user@MyServer:~$ VBoxManage setextradata “Ubuntu1004” “VBoxInternal/Devices/pcnet/1/LUN#1/Config/guestssh/HostPort”

升级:


如果升级遇到错误信息:

VirtualBox is currently running. Please close it and try again…

那就找到虚拟机进程, 然后杀掉

ps -aux | grep virtualbox
root     12909  0.0  0.0   7624   920 pts/0    S+   12:30   0:00 grep virtualbox
user     13438  0.0  0.0 167956  2628 ?        Sl   May08  13:14 /usr/lib/virtualbox/VBoxSVC –auto-shutdown

赞(0) 打赏
转载请注明出处:服务器评测 » 在Ubuntu 10.04 LTS Server上通过SSH安装Virtualbox 4.0
分享到: 更多 (0)

听说打赏我的人,都进福布斯排行榜啦!

支付宝扫一扫打赏

微信扫一扫打赏