作者:jicanmeng
时间:2014年11月1日
在windows下安装virtualbox非常简单,下载了安装文件后,一直点击"下一步"就可以安装成功了。但是在centos下安装就麻烦一些。下面是安装的过程。
[jicanmeng@centos01-64 Desktop]$ sudo wget -P /etc/yum.repos.d/ http://download.virtualbox.org/virtualbox/rpm/rhel/virtualbox.repo
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
[sudo] password for jicanmeng:
jicanmeng is not in the sudoers file. This incident will be reported.
[jicanmeng@centos01-64 Desktop]$ su -
Password:
[root@centos01-64 ~]# vim /etc/sudoers
[root@centos01-64 etc]# logout
[jicanmeng@centos01-64 ~]$ cd Desktop
[jicanmeng@centos01-64 Desktop]$ sudo wget -P /etc/yum.repos.d/ http://download.virtualbox.org/virtualbox/rpm/rhel/virtualbox.repo
[sudo] password for jicanmeng:
--2014-11-01 16:12:25-- http://download.virtualbox.org/virtualbox/rpm/rhel/virtualbox.repo
Resolving download.virtualbox.org... 137.254.120.26
Connecting to download.virtualbox.org|137.254.120.26|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 243 [text/plain]
Saving to: “/etc/yum.repos.d/virtualbox.repo”
100%[======================================>] 243 --.-K/s in 0s
2014-11-01 16:12:29 (14.5 MB/s) - “/etc/yum.repos.d/virtualbox.repo” saved [243/243]
[jicanmeng@centos01-64 Desktop]$ yum info VirtualBox-4.3
Loaded plugins: fastestmirror, refresh-packagekit, security
Determining fastest mirrors
* base: mirrors.btte.net
* extras: mirrors.btte.net
* updates: mirrors.btte.net
base | 3.7 kB 00:00
base/primary_db | 4.6 MB 00:08
extras | 3.3 kB 00:00
extras/primary_db | 19 kB 00:00
updates | 3.4 kB 00:00
updates/primary_db | 171 kB 00:00
virtualbox | 951 B 00:00
virtualbox/primary | 5.3 kB 00:00
virtualbox: [###################################### ] 19/29Available Packages
Name : VirtualBox-4.3
Arch : x86_64
Version : 4.3.18_96516_el6
Release : 1
Size : 68 M
Repo : virtualbox
Summary : Oracle VM VirtualBox
URL : http://www.virtualbox.org/
License : GPLv2
Description : VirtualBox is a powerful PC virtualization solution allowing
: you to run a wide range of PC operating systems on your Linux
: system. This includes Windows, Linux, FreeBSD, DOS, OpenBSD
: and others. VirtualBox comes with a broad feature set and
: excellent performance, making it the premier virtualization
: software solution on the market.
[jicanmeng@centos01-64 Desktop]$ sudo yum install VirtualBox-4.3
Loaded plugins: fastestmirror, refresh-packagekit, security
base | 3.7 kB 00:00
base/primary_db | 4.6 MB 00:08
extras | 3.3 kB 00:00
extras/primary_db | 19 kB 00:00
updates | 3.4 kB 00:00
updates/primary_db | 171 kB 00:00
virtualbox | 951 B 00:00
virtualbox/primary | 5.3 kB 00:00
virtualbox: [###################################### ] 19/29Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package VirtualBox-4.3.x86_64 0:4.3.18_96516_el6-1 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
VirtualBox-4.3 x86_64 4.3.18_96516_el6-1 virtualbox 68 M
Transaction Summary
================================================================================
Install 1 Package(s)
Total download size: 68 M
Installed size: 144 M
Is this ok [y/N]: y
Downloading Packages:
http://download.virtualbox.org/virtualbox/rpm/el/6/x86_64/VirtualBox-4.3-4.3.18_96516_el6-1.x86_64.rpm: [Errno 12] Timeout on http://download.virtualbox.org/virtualbox/rpm/el/6/x86_64/VirtualBox-4.3-4.3.18_96516_el6-1.x86_64.rpm: (28, 'Operation too slow. Less than 1 bytes/sec transfered the last 30 seconds')
Trying other mirror.
Error Downloading Packages:
VirtualBox-4.3-4.3.18_96516_el6-1.x86_64: failure: VirtualBox-4.3-4.3.18_96516_el6-1.x86_64.rpm from virtualbox: [Errno 256] No more mirrors to try.
[jicanmeng@centos01-64 Desktop]$ sudo rpm -ivh VirtualBox-4.3-4.3.18_96516_el6-1.x86_64.rpm
[sudo] password for jicanmeng:
warning: VirtualBox-4.3-4.3.18_96516_el6-1.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 98ab5139: NOKEY
Preparing... ########################################### [100%]
1:VirtualBox-4.3 ########################################### [100%]
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.
Stopping VirtualBox kernel modules [ OK ]
Recompiling VirtualBox kernel modules [ OK ]
Starting VirtualBox kernel modules [ OK ]
[jicanmeng@centos01-64 Desktop]$
[jicanmeng@centos01-64 Desktop]$ sudo usermod -a -G vboxusers jicanmeng
[jicanmeng@centos01-64 Desktop]$ sudo yum install kernel-headers kernel-devel gcc
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
* base: mirrors.btte.net
* extras: mirrors.btte.net
* updates: mirrors.btte.net
Setting up Install Process
Resolving Dependencies
……………
Dependency Updated:
cpp.x86_64 0:4.4.7-11.el6 gcc-c++.x86_64 0:4.4.7-11.el6 gcc-gfortran.x86_64 0:4.4.7-11.el6 libgcc.x86_64 0:4.4.7-11.el6 libgfortran.x86_64 0:4.4.7-11.el6
libgomp.x86_64 0:4.4.7-11.el6 libstdc++.x86_64 0:4.4.7-11.el6 libstdc++-devel.x86_64 0:4.4.7-11.el6
Complete!
[jicanmeng@centos01-64 Desktop]$ cd /usr/src/kernels/
[jicanmeng@centos01-64 kernels]$ ls
2.6.32-431.el6.x86_64 2.6.32-504.el6.x86_64
[jicanmeng@centos01-64 kernels]$ ll
total 8
drwxr-xr-x. 22 root root 4096 Jun 8 21:12 2.6.32-431.el6.x86_64
drwxr-xr-x. 22 root root 4096 Nov 1 16:58 2.6.32-504.el6.x86_64
[jicanmeng@centos01-64 kernels]$ echo $KERN_DIR
[jicanmeng@centos01-64 kernels]$ sudo echo $KERN_DIR
[jicanmeng@centos01-64 kernels]$ KERN_DIR=/usr/src/kernels/2.6.32-431.el6.x86_64
[jicanmeng@centos01-64 kernels]$ echo $KERN_DIR
/usr/src/kernels/2.6.32-431.el6.x86_64
[jicanmeng@centos01-64 kernels]$ service vboxdrv setup
Stopping VirtualBox kernel modules [FAILED]
(Cannot unload module vboxpci)
[jicanmeng@centos01-64 kernels]$ sudo service vboxdrv setup
Stopping VirtualBox kernel modules [ OK ]
Removing old VirtualBox pci kernel module [ OK ]
Removing old VirtualBox netadp kernel module [ OK ]
Removing old VirtualBox netflt kernel module [ OK ]
Removing old VirtualBox kernel module [ OK ]
Recompiling VirtualBox kernel modules [ OK ]
Starting VirtualBox kernel modules [ OK ]
[jicanmeng@centos01-64 kernels]$ virtualbox &
[1] 12179
[jicanmeng@centos01-64 kernels]$
1. 第一次执行sudo wget -P /etc/yum.repos.d/ http://download.virtualbox.org/virtualbox/rpm/rhel/virtualbox.repo
命令失败后,切换到root用户,打开/etc/sudoers文件,在root ALL=(ALL) ALL这一行的下面一行,添加jicanmeng ALL=(ALL) ALL。这样,再次执行上面的命令就会成功了。
2. 执行sudo yum install VirtualBox-4.3
命令失败了。就直接下载了VirtualBox-4.3-4.3.18_96516_el6-1.x86_64.rpm文件,然后使用rpm命令安装了。
3. 在引用文章1中提到"请为每一个会执行 VirtualBox 的用户执行: usermod -a -G vboxusers 用户名称"。所以执行sudo usermod -a -G vboxusers jicanmeng
命令。