现在的位置: 首页 > 综合 > 正文

virtualbox虚拟机使用笔记-安装、增强功能、网络、usb设备、共享目录

2013年10月10日 ⁄ 综合 ⁄ 共 5877字 ⁄ 字号 评论关闭

virtualbox虚拟机使用笔记-安装、增强功能、网络、usb设备、共享目录

摘要:virtualbox虚拟机的安装、增强功能、网络、usb设备、共享目录

主系统:ubuntu8.10
虚拟系统:ubuntu8.04

准备工作
安装当前内核头文件
sudo apt-get install linux-header-2.6.xx
开始:

1.添加下面的源:
deb http://download.virtualbox.org/virtualbox/debian intrepid non-free

2.下载米钥文件并导入:
wget -q http://download.virtualbox.org/virtualbox/debian/sun_vbox.asc -O- | sudo apt-key add -
这步还可以这样做:
a.下载密钥文件 http://download.virtualbox.org/virtualbox/debian/sun_vbox.asc
b.打开软件源->身份验证->导入密钥文件,选择你刚才下载的sun_vbox.asc

3.更新源
sudo apt-get update

4.安装
apt-get install virtualbox-2.2 dkms
virtualbox-2.2是我们要安装的虚拟机,dkms可以确保你的主机内核升级后,虚拟机运行所需要的vboxdrv、vboxnetflt等内核模块也会随着升级。
因为我原来装过vbox,在安的过程中会提示你是否使用原来的配置,当然使用原来的配置了,因为我原来的vbox上装了系统,还要继续用的。

5.先不要急着找主菜单里相应的虚拟机启动项,因为现在还没安装完成,重启主机吧。

6.vbox网络部分
打开虚拟机,配置网络:Bridged adapter, eth0
启动你虚拟系统,打开终端,ifconfig会发现你的虚拟机和主机是在一个网段上的(我主机局域网是自动dhcp的),互ping一下试试,应该是ok的;另外主、宿两个系统访问外网也没问题。

许多人在配置虚拟机网络的时候会把主机的网络搞坏,如果出现这种情况:
你的主机ubuntu的网络连接显示断开连接,并有“没有找到有效的激活的连接”的提示,但你的实际上却可以上网(更多的情况下不能上网),你可以这样:打开终端(主ubuntu)
sudo vi /etc/network/interfaces
除了包含lo的行,其他的行全部删除,保存,退出。
重启主ubuntu.ok.

7.安装增强功能包
点vbox的主菜单的设备->安装增强功能,会在虚拟机上出现一个虚拟光盘,打开终端,进入光盘挂载目录:
sudo ./VBoxLinuxAdditions-x86.run
安装完重启虚拟机。

8.设置vbox共享目录
可以参照 http://blog.redzone.com.cn/read.php/50.htm
使用共享目录每次都要挂载,简便点的方法(是在虚拟机上的操作):
在/etc/rc.local里添一行:
mount -t vboxsf software /mnt/share
这样每次启动不需要手动挂载了。
相对繁琐点做法是根据ubuntu的启动级别,用update-rc.d来做,具体做法见我的令一篇帖子《vbox上ubuntu开机自动挂载共享目录》。

9.设置vbox的usb设备
这部分主要摘自 http://forum.ubuntu.org.cn/viewtopic.php?f=65&t=164209
照着做就行了

------------------------------------------*
为virtualbox开启usb设备支持
virtualbox默认是不支持usb设备的,需要手工修改一些设置才能使用。

1.修改为usb设备增加普通用户权限
1.1 增加一个名为usbfs的用户组
代码:
xmoney@xmoney-laptop:~$ sudo groupadd usbfs
[sudo] password for xmoney:

1.2 增加当前用户到工作组
代码:
xmoney@xmoney-laptop:~$ sudo adduser xmoney usbfs  //其中xmoney是本人系统的登录名字
[sudo] password for xmoney:

1.3 得到usbfs组的id
执行如下命令
代码:
xmoney@xmoney-laptop:~$ cat /etc/group | grep usbfs
usbfs:x:1002:xmoney,root

其中1002就是usbfs组的id了。

1.4 修改 /etc/fstab 文件
代码:
xmoney@xmoney-laptop:~$ sudo gedit /etc/fstab

在文件的末尾增加一行
代码:
none /proc/bus/usb usbfs devgid=1002,devmode=664 0 0

其中 devgid=1002,其中的1002就是刚才的usbfs的组id

1.5 为 /proc/bus/usb 增加权限
首先为/proc/bus/usb放开所有权限,也就是所有人都能访问。
代码:
xmoney@xmoney-laptop:~$ sudo chmod 777 /proc/bus/usb
xmoney@xmoney-laptop:~$

然后为/proc/bus/usb设置所有者为当前用户,我的当前用户是xmoney。
代码:
xmoney@xmoney-laptop:~$ sudo chown xmoney /proc/bus/usb
xmoney@xmoney-laptop:~$

1.6 重启电脑
代码:
xmoney@xmoney-laptop:~$ sudo reboot

修改完必须重启,否则无法生效

2.获取usb设备的VendorId和ProductId
接下来需要获取usb设备的VendorId和ProductId,这两个都是virtualbox的usb设置所必须的。
命令及反馈信息如下:

代码:
xmoney@xmoney-laptop:~$ VBoxManage list usbhost

代码:
VirtualBox Command Line Management Interface Version 1.6.2
(C) 2005-2008 Sun Microsystems, Inc.
All rights reserved.

Host USB Devices:

UUID:               ca2a6d3b-66e0-4a94-9f69-dddb9a44e5e4
VendorId:           0x046d (046D)
ProductId:          0xc016 (C016)
Revision:           3.64 (0364)
Manufacturer:       Logitech
Product:            Optical USB Mouse
Address:            /proc/bus/usb/002/002
Current State:      Busy

UUID:               c491f7e6-abdc-43bb-9bce-ef31bdcb3551
VendorId:           0x13fe (13FE)
ProductId:          0x1f00 (1F00)
Revision:           1.16 (0116)
Manufacturer:       Kingston
Product:            DataTraveler 2.0
SerialNumber:       5B850F000E96
Address:            /proc/bus/usb/001/003
Current State:      Busy

3.配置virtualbox
在virtualbox的配置明细/usb中,开启usb控制器和usb2.0控制器,然后点击“从设备列表中添加筛选器”
相关设置会自动的添加到筛选器列表中。

------------------------------------*

参考:http://www.virtualbox.org/wiki/Linux_Downloads

vbox上ubuntu开机自动挂载共享目录

keyword: ubuntu 开机自动运行 vbox共享目录

先创建vbox上ubuntu/etc/init.d/mountsharedir.sh

vi /etc/init.d/mountsharedir.sh

  1
#! /bin/sh

  2 ### BEGIN INIT INFO

  3 # Provides: mountsharedir

  4 # Required-Start:

  5 # Required-Stop:

  6 # Should-Start:

  7 # Should-Stop:

  8 # Default-Start: 2 3 4 5 S

  9 # Default-Stop: 0 6

 10 # Short-Description: Mount vbox share dir.

 11 # Description:

 12 ### END INIT INFO

 13
 14 PATH=/sbin:/bin
 15
 16 case "$1" in
 17 start|"")
 18 mount -t vboxsf -o rw software
/mnt/share
>
> /var/log/mountsharedirlog 2>&1
 19 ;;
 20 restart|reload|force-reload)
 21 echo "Error: argument '$1' not supported"
>
&2
 22 exit 3
 23 ;;
 24 stop)
 25 # No-op

 26 ;;
 27 *)
 28 echo "Usage: mountsharedir.sh [start|stop]"
>&2
 29 exit 3
 30 ;;
 31 esac
 32
 33 :

2. 用update-rc.d命令注册此启动脚本
sudo update-rc.d mountsharedir.sh start 99 2 3 4 5 S .

update-rc.d的一部分工作是创建/etc/init.d/mountsharedir.sh的软连接到/etc/rc*.d/中去,但这并不是它做的唯一的事情;就是说使用update-rc.d命令和手动的在/etc/rc*.d/下面创建连接,两者的效果是有区别的;手动创建往往不起作用。

另外:
A common system administration error is to delete the links with the thought that this will "disable" the service, i.e.,  that  this  will  prevent the service from being started.  However, if all links have been deleted then the next time the package is upgraded,
the package's postinst script will run update-rc.d again and  this  will  rein-stall  links  at their factory default locations.  The correct way to disable services is to configure the service as stopped in all runlevels in which it is started by default. 
In the System V init system  this  means  renaming
 the service's symbolic links from S to K.

关于update-rc.d的使用,摘了一些man中的example:
EXAMPLES
       Insert links using the defaults:
          update-rc.d foobar defaults

       Equivalent command using explicit argument sets:
          update-rc.d foobar start 20 2 3 4 5 . stop 20 0 1 6 .

       More typical command using explicit argument sets:
          update-rc.d foobar start 30 2 3 4 5 . stop 70 0 1 6 .

       Insert links at default runlevels when B requires A
          update-rc.d script_for_A defaults 80 20
          update-rc.d script_for_B defaults 90 10
       Insert a link to a service that (presumably) will not be needed by any other daemon
          update-rc.d top_level_app defaults 98 02
       Insert links for a script that requires services that start/stop at sequence number 20
          update-rc.d script_depends_on_svc20 defaults 21 19
       Remove all links for a script (assuming foobar has been deleted already):
          update-rc.d foobar remove
       Example of disabling a service:
          update-rc.d -f foobar remove
          update-rc.d foobar stop 20 2 3 4 5 .
       Example of a command for installing a system initialization-and-shutdown script:
          update-rc.d foobar start 45 S . stop 31 0 6 .
       Example of a command for disabling a system initialization-and-shutdown script:
          update-rc.d -f foobar remove
          update-rc.d foobar stop 45 S .

抱歉!评论已关闭.