So Tired !_! 逆水行舟, 不进则退!

16Nov/10

How to Fix VirtualBox USB Device Support UBUNTU

Posted by Nick Xu

It is actually a known fact that there

is an issue with VirtualBox and the attached USB devices that many of us are trying to use in the virtual machine. Here is a real-life example:

I am a 100% Linux user and I have a photo printer that Linux can't recognize. Let's say that I want to print some photos quickly, to give them to someone. I have a Windows installation in a virtual machine just for this reason (sad, I know) and I want to access my printer, which is connected via a USB port. To my surprise, I can see the printer in the USB device list of VirtualBox, but I can't access it (very frustrating). Firing up Firefox and searching on Google for a fix takes too long, because there are many old tutorials that teach you how to modify various files or change permissions, etc. What to do? Well, below is the answer to the endless VirtualBox – USB issue (and it's pretty damn simple too!).

This tutorial was created mostly for my needs, but I am sure that many of you will find it very helpful. Ready?

This is how a default installation of VirtualBox in Ubuntu 9.04 shows the USB devices, and we need to fix it.

Review image

Go to System -> Administration -> Users and Groups...

Review image

Click the "Unlock" button...

Review image

Type your password and click the "Authenticate" button....

Review image

Click on the "Manage Groups" button...

Review image

In the "Groups settings" window that will appear, scroll down until you see the vboxusers entry. Select it and then click on the "Properties" button...

Review image

Another window will appear, called "Group 'vboxusers' Properties. Just check the box in front of your username and click the "OK" button when you're done...

Review image

Close the "Group settings" and "Users Settings" windows and log out. Log in and open up VirtualBox, start your virtual machine and you will see that you can now access the USB devices!

Review image

Yes... it was that simple!

10Nov/10

VirtualBox的VRDP运行模式

Posted by Nick Xu

其实没什么深奥的,所谓VRDP运行模式,就是虚拟机运行的时候,没有图形窗口,但可以用VirtualBox的RDP模式远程管理,说是远程其实 在本机上用很方便,用起来和windows下的远程桌面一样。如果虚拟机上安装了vncserver之类的远程控制软件,并且从主机上能够通过tcp访 问,也一样可以管理的。

我使用的是非开源的VirtualBox,开源版本少一些功能。以下操作在windows下也是可以参照使用的。

启动VM的命令:/usr/bin/VBoxManage startvm WinXP -type vrdp,默认是-type gui即以图形界面启动虚拟机。

控制VM比如保存状态关闭的命令:/usr/bin/VBoxManage controlvm WinXP savestate

以上命令中WinXP是虚拟机的名称,也可以用uuid替代。

开启VRDP后远程控制端口默认是3389,默认认证方式是null,即无认证,任何人都可以连接上随意控制,放在网络环境下是很不安全的。还有一种认证方式是external,可以使用主机上的用户机制来认证,不过使用之前要稍微作一下设置:

cd /lib
sudo ln -s libpam.so.0 libpam.so

不然认证无法进行,连接闪一下就关闭了。远程桌面的客户端在gnome中可以用Terminal Server Client(tsclient)或者rdesktop-vrdp -u fwolf -p - localhost

要想随重启或者关机自动关闭虚拟机,要稍微麻烦一些了,首先在/etc/init.d/下创建一个文件fwolfrc

#! /bin/sh 
# Using LSB funtions:
. /lib/lsb/init-functions
set -e
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="Fwolf's Init"
NAME=fwolfrc
SCRIPTNAME=/etc/init.d/$NAME

# Function that starts the daemon/service.
d_start() {
    touch /var/lock/subsys/$NAME
    log_daemon_msg "Starting $DESC" "$NAME"
}

# Function that stops the daemon/service.
d_stop() {
    su -c "/usr/bin/VBoxManage controlvm WinXP savestate" fwolf
    rm /var/lock/subsys/$NAME
}

# Function that sends a SIGHUP to the daemon/service.
case "$1" in
  start)
        d_start
    ;;
  stop)
        d_stop
    ;;
  *)
    log_warning_msg "Usage: $SCRIPTNAME {start|stop}" >&2
    exit 3
    ;;
esac

exit 0

我也是直接从/etc/init.d/里套过来修改的,详细信息可以看参考文章或者其它关于关机自动执行脚本的资料。然后把这个文件ln为以下几个:

  • /etc/rc0.d/K01fwolfrc
  • /etc/rc6.d/K01fwolfrc
  • /etc/rc3.d/S99fwolfrc
  • /etc/rc5.d/S99fwolfrc

可以看到开机时是最后执行,而关机时是最先执行。注意我上面的脚本里,在开机是并没有自动启动虚拟机,习惯手工开。

29Oct/10

VirtualBox直接使用物理硬盘作虚拟机磁盘

Posted by Nick Xu

前段时间我的小黑ibm x30网卡退休了,买了个硬盘盒,把硬盘拆来当移动硬盘用,硬盘已经装有系统debian,用Vmware建虚拟机选择磁盘的时候可以直接选择物理磁盘作 为系统磁盘,这样就很方便启动原来笔记本装有的debian系统,最近换了VirtualBox,发现不能像Vmware那样傻瓜化操作,只能用命令行来 建立磁盘才可以使用物理硬盘。

1.运行cmd,cd进入你的VirtualBox目录,如:  cd C:\Program Files\Sun\VirtualBox
2.命令行运行VBoxManage.exe,如:VBoxManage internalcommands createrawvmdk -filename  d:\x30.vmdk -rawdisk \\.\PhysicalDrive1
\\.\PhysicalDrive1 表示我的机器上的第二块硬盘,\\.\PhysicalDrive0是第一块,\\.\PhysicalDrive3是第三块,以此类推。
网上有朋友说在windows 的磁盘管理中能看到硬盘的分区路径,格式如\\.\PhysicalDrive0。但是我没有找到,如果有朋友能知道这个怎得来的请告诉我,谢谢。

附 VBoxManage internalcommands createrawvmdk 命令:

VBoxManage internalcommands createrawvmdk  创建一个vmdk格式的硬盘
-filename <filename> vmdk格式的硬盘所对应的vmdk文件
-rawdisk <diskname>  vmdk文件所对应的物理硬盘
[-partitions <list of partition numbers>  vmdk文件对应的物理硬盘的分区
[-mbr <filename>] ] 将这个文件包含的引导记录写到vmdk文件
[-register] 将这个新创建的硬盘注册到virtualbox
[-relative] 激活这个新创建的硬盘的分区

   
site
site