VirtualBox从USB设备启动方法

Kvm、VMware、Virtualbox、Xen、Qemu 等
头像
muzuiget
帖子: 1097
注册时间: 2007-12-31 14:57

VirtualBox从USB设备启动方法

#1

帖子 muzuiget » 2008-09-21 23:54

VirtualBox虚拟机中按F12的启动菜单中是没有从USB启动的,一直都找不到从USB设备启动方法,也有人说VirtualBox不支持USB设备启动,那是我搜中文的结果。把闪盘装上Linux都是在Vmware下测试的,Vmware下是把闪盘当成SCSI硬盘挂载的。我想这点应该VirtualBox也行啊。

我Google一下英文“virtualbox usb boot”(中文我得把“virtualbox”、“u盘”、“usb”、“闪盘”、“优盘”、“随身碟”、“引导”、“启动”、“开机”混搭使用,而还是一大堆无关结果,所以翻译叫法还是统一点好),结果第一条就找到了,虽然没写具体怎么做,至少老外说行,有这么一行
It is not passible directly but it is possible indirectly. Configure your USB drive as a raw disk in VirtualBox (page 105 of the manual). Then the guest will see your USB drive as a IDE drive and will be able to boot on it.
VirtualBox的确不支持USB设备直接启动,但能把USB设备当成硬盘间接启动,“raw disk”,看起来原理跟Vmware一样,把它当成硬盘挂就行了。至于那个“page 105 of the manual”,我已经升级到VirtualBox 2.0.2,手册是CHM格式没有页码,还好找到了,是在“9.9. Using a raw host hard disk from a guest”这一节,讲解的非常详细。这次又是STFW和RTFM发挥了功效。

步骤如下
  1. Ubuntu软件库里那个VirtualBox OSE版是不能支持USB设备的,我用的是从官方下那个,并按这个帖子搞定了启动虚拟机USB出错那个问题。不过这里是把闪盘当成硬盘用,我想用OSE也应该行,因为支持USB是Ubuntu(当成硬盘)而不是VirtualBox,所以用OSE或许会成功,不过我懒得测试,有谁成功告诉一声。3楼caozhzh测试过,1.5.6是不行的,第3步那个命令没有创建虚拟磁盘功能,7楼的wjjs测试新版的2.0.4就行。
  2. 当前必须属于“vboxusers”组,运行

    代码: 全选

    sudo usermod -G vboxusers -a `whoami`
    然后重新登录(注一)。
  3. 运行下面那个命令为闪盘添加访问权限,之前我老是提示没权限,

    代码: 全选

    sudo chmod o+rw /dev/sdc
    我有2个硬盘,所以闪盘就是“/dev/sdc”,如果不确定的话就用“df”命令查看。因为每次拔出闪盘后,“sdc”就会消失了,插回去,又出现,所以还要重新设置权限,重新运行命令,比较常用的话就添加一个alias
  4. 然后就为闪盘建立一个虚拟硬盘镜像,其中参数“filename”后的路径就是虚拟硬盘镜像的保存位置,我这里用默认的 “~/.VirtualBox/VDI/”,手册里说路径一定要用绝对路径。创建出来vmdk文件只有几百字节而已,不需要担心空间,参数后 “rawdisk”就是你的闪盘设备路径,

    代码: 全选

    VBoxManage internalcommands createrawvmdk -filename ~/.VirtualBox/VDI/UsbDisk.vmdk -rawdisk /dev/sdc -register
    运行后出现

    代码: 全选

    VirtualBox Command Line Management Interface Version 2.0.2
    (C) 2005-2008 Sun Microsystems, Inc.
    All rights reserved.
    RAW host disk access VMDK file /home/yourname/.VirtualBox/VDI/UsbDisk.vmdk created successfully.
    表示创建成功了。
  5. 然后就启动VirtualBox,在需要测试的虚拟机设置里的“硬盘”一页,换成刚才那个vmdk文件,如果不是建立在“~/.VirtualBox/VDI/”的话要用虚拟介质管理器注册一下。
  6. 最后把硬盘设置成优先启动就搞定啦,成功启动了我闪盘里的Grub4DOS,切换启动项VirtualBox比用Vmware还要简单,不需要在虚拟机里的BIOS切换。
我这里是整个闪盘挂载,其实也可以挂载单个或几个分区,也可以直接挂载真实硬盘上的XP,参考这帖《Boot an existing XP (Physical HD) install with VirtualBox》,也可以为建立的虚拟硬盘镜像自定义MBR,方法看手册有关章节吧。

注一:
原来这步我是这样做的,运行

代码: 全选

sudo usermod -G disk,vboxusers -a `whoami`
然后重新登录生效,考虑到把当前用户添加到“disk”组会危险,因为“/dev/sdc”属于“disk”组,格式化“mkfs”之类命令就不用加“sudo”运行了。所以用第3步的方法代替,临时加上读写权限给“/dev/sdc”,每次运行一次添加权限总比添加到“disk”组好。
上次由 muzuiget 在 2008-10-30 21:23,总共编辑 6 次。
头像
想入非非
帖子: 8078
注册时间: 2008-07-14 22:42
来自: Beijing
联系:

Re: VirtualBox从USB设备启动方法

#2

帖子 想入非非 » 2008-09-22 12:49

谢谢你的教程。。。 :oops:
Ubuntu User
caozhzh
帖子: 21
注册时间: 2005-12-21 17:37

Re: VirtualBox从USB设备启动方法

#3

帖子 caozhzh » 2008-10-06 23:10

感谢楼主发帖。
我在1.5.6_ose里面试了一下,出现下列问题:
VirtualBox Command Line Management Interface Version 1.5.6_OSE
(C) 2005-2008 innotek GmbH
All rights reserved.

Usage: VBoxManage internalcommands <command> [command arguments]

Commands:

loadsyms <vmname>|<uuid> <symfile> [delta] [module] [module address]
This will instruct DBGF to load the given symbolfile
during initialization.

unloadsyms <vmname>|<uuid> <symfile>
Removes <symfile> from the list of symbol files that
should be loaded during DBF initialization.

setvdiuuid <filepath>
Assigns a new UUID to the given VDI file. This way, multiple copies
of VDI containers can be registered.

WARNING: This is a development tool and shall only be used to analyse
problems. It is completely unsupported and will change in
incompatible ways without warning.

Syntax error: Invalid command 'createrawvmdk'
搜索了一下,发现是这个问题:
I had the same problem on debian/lenny.
After searching the net, I found that the problem is, that the createrawvmdk command is not avaliable in the open source edition.

看来ose还是不行。
头像
muzuiget
帖子: 1097
注册时间: 2007-12-31 14:57

Re: VirtualBox从USB设备启动方法

#4

帖子 muzuiget » 2008-10-06 23:49

caozhzh 写了:感谢楼主发帖。
我在1.5.6_ose里面试了一下,出现下列问题:
VirtualBox Command Line Management Interface Version 1.5.6_OSE
(C) 2005-2008 innotek GmbH
All rights reserved.

Usage: VBoxManage internalcommands <command> [command arguments]

Commands:

loadsyms <vmname>|<uuid> <symfile> [delta] [module] [module address]
This will instruct DBGF to load the given symbolfile
during initialization.

unloadsyms <vmname>|<uuid> <symfile>
Removes <symfile> from the list of symbol files that
should be loaded during DBF initialization.

setvdiuuid <filepath>
Assigns a new UUID to the given VDI file. This way, multiple copies
of VDI containers can be registered.

WARNING: This is a development tool and shall only be used to analyse
problems. It is completely unsupported and will change in
incompatible ways without warning.

Syntax error: Invalid command 'createrawvmdk'
搜索了一下,发现是这个问题:
I had the same problem on debian/lenny.
After searching the net, I found that the problem is, that the createrawvmdk command is not avaliable in the open source edition.

看来ose还是不行。

代码: 全选

Syntax error: Invalid command 'createrawvmdk'
看来是没有createrawvmdk这个参数,谢谢你的测试。
caozhzh
帖子: 21
注册时间: 2005-12-21 17:37

Re: VirtualBox从USB设备启动方法

#5

帖子 caozhzh » 2008-10-09 23:36

不必客气,呵呵
uranus0206
帖子: 129
注册时间: 2006-06-03 5:10

Re: VirtualBox从USB设备启动方法

#6

帖子 uranus0206 » 2008-10-28 18:28

$ VBoxManage internalcommands createrawvmdk -filename ~/.VirtualBox/VDI/UsbDisk.vmdk -rawdisk /dev/sdb1 -register
VirtualBox Command Line Management Interface Version 2.0.4
(C) 2005-2008 Sun Microsystems, Inc.
All rights reserved.

Error while creating the raw disk VMDK: VERR_FILE_NOT_FOUND
The raw disk vmdk file was not created


不行耶!!!!!!!!

後來用絕對路徑才可以
wjjs
帖子: 145
注册时间: 2007-07-08 19:21

Re: VirtualBox从USB设备启动方法

#7

帖子 wjjs » 2008-10-29 15:44

muzuiget 写了:VirtualBox虚拟机中按F12的启动菜单中是没有从USB启动的,一直都找不到从USB设备启动方法,也有人说VirtualBox不支持USB设备启动,那是我搜中文的结果。把闪盘装上Linux都是在Vmware下测试的,Vmware下是把闪盘当成SCSI硬盘挂载的。我想这点应该VirtualBox也行啊。

我Google一下英文“virtualbox usb boot”(中文我得把“virtualbox”、“u盘”、“usb”、“闪盘”、“优盘”、“随身碟”、“引导”、“启动”、“开机”混搭使用,而还是一大堆无关结果,所以翻译叫法还是统一点好),结果第一条就找到了,虽然没写具体怎么做,至少老外说行,有这么一行
It is not passible directly but it is possible indirectly. Configure your USB drive as a raw disk in VirtualBox (page 105 of the manual). Then the guest will see your USB drive as a IDE drive and will be able to boot on it.
VirtualBox的确不支持USB设备直接启动,但能把USB设备当成硬盘间接启动,“raw disk”,看起来原理跟Vmware一样,把它当成硬盘挂就行了。至于那个“page 105 of the manual”,我已经升级到VirtualBox 2.0.2,手册是CHM格式没有页码,还好找到了,是在“9.9. Using a raw host hard disk from a guest”这一节,讲解的非常详细。这次又是STFW和RTFM发挥了功效。

步骤如下
  1. Ubuntu软件库里那个VirtualBox OSE版是不能支持USB设备的,我用的是从官方下那个,并按这个帖子搞定了启动虚拟机USB出错那个问题。不过这里是把闪盘当成硬盘用,我想用OSE也应该行,因为支持USB是Ubuntu(当成硬盘)而不是VirtualBox,所以用OSE或许会成功,不过我懒得测试,有谁成功告诉一声。3楼caozhzh测试过,是不行的,第3步那个命令没有创建虚拟磁盘功能
  2. 当前必须属于“vboxusers”组,运行

    代码: 全选

    sudo usermod -G vboxusers -a `whoami`
    然后重新登录(注一)。
  3. 运行下面那个命令为闪盘添加访问权限,之前我老是提示没权限,

    代码: 全选

    sudo chmod o+rw /dev/sdc
    我有2个硬盘,所以闪盘就是“/dev/sdc”,如果不确定的话就用“df”命令查看。因为每次拔出闪盘后,“sdc”就会消失了,插回去,又出现,所以还要重新设置权限,重新运行命令,比较常用的话就添加一个alias
  4. 然后就为闪盘建立一个虚拟硬盘镜像,其中参数“filename”后的路径就是虚拟硬盘镜像的保存位置,我这里用默认的 “~/.VirtualBox/VDI/”,手册里说路径一定要用绝对路径。创建出来vmdk文件只有几百字节而已,不需要担心空间,参数后 “rawdisk”就是你的闪盘设备路径,

    代码: 全选

    VBoxManage internalcommands createrawvmdk -filename ~/.VirtualBox/VDI/UsbDisk.vmdk -rawdisk /dev/sdc -register
    运行后出现

    代码: 全选

    VirtualBox Command Line Management Interface Version 2.0.2
    (C) 2005-2008 Sun Microsystems, Inc.
    All rights reserved.
    RAW host disk access VMDK file /home/yourname/.VirtualBox/VDI/UsbDisk.vmdk created successfully.
    表示创建成功了。
  5. 然后就启动VirtualBox,在需要测试的虚拟机设置里的“硬盘”一页,换成刚才那个vmdk文件,如果不是建立在“~/.VirtualBox/VDI/”的话要用虚拟介质管理器注册一下。
  6. 最后把硬盘设置成优先启动就搞定啦,成功启动了我闪盘里的Grub4DOS,切换启动项VirtualBox比用Vmware还要简单,不需要在虚拟机里的BIOS切换。
我这里是整个闪盘挂载,其实也可以挂载单个或几个分区,也可以直接挂载真实硬盘上的XP,参考这帖《Boot an existing XP (Physical HD) install with VirtualBox》,也可以为建立的虚拟硬盘镜像自定义MBR,方法看手册有关章节吧。

注一:
原来这步我是这样做的,运行

代码: 全选

sudo usermod -G disk,vboxusers -a `whoami`
然后重新登录生效,考虑到把当前用户添加到“disk”组会危险,因为“/dev/sdc”属于“disk”组,格式化“mkfs”之类命令就不用加“sudo”运行了。所以用第3步的方法代替,临时加上读写权限给“/dev/sdc”,每次运行一次添加权限总比添加到“disk”组好。

谢谢,成功。
用于ub 8.10rc 虚拟机vbox2.04加载wxp识别usb设备 :em01
wjjs
帖子: 145
注册时间: 2007-07-08 19:21

Re: VirtualBox从USB设备启动方法

#8

帖子 wjjs » 2008-10-29 15:46

另,用的就是

代码: 全选

Ubuntu软件库里那个VirtualBox OSE版
wjjs
帖子: 145
注册时间: 2007-07-08 19:21

Re: VirtualBox从USB设备启动方法

#9

帖子 wjjs » 2008-10-29 15:55

代码: 全选

feng@feng-laptop:~/桌面$ sudo usermod -G vboxusers -a `whoami`
[sudo] password for feng: 
feng@feng-laptop:~/桌面$ sudo chmod o+rw /dev/sdc
feng@feng-laptop:~/桌面$ VBoxManage internalcommands createrawvmdk -filename ~/.VirtualBox/VDI/UsbDisk.vmdk -rawdisk /dev/sdc -register
VirtualBox Command Line Management Interface Version 2.0.4_OSE
(C) 2005-2008 Sun Microsystems, Inc.
All rights reserved.

RAW host disk access VMDK file /home/feng/.VirtualBox/VDI/UsbDisk.vmdk created successfully.
feng@feng-laptop:~/桌面$ 
wjjs
帖子: 145
注册时间: 2007-07-08 19:21

Re: VirtualBox从USB设备启动方法

#10

帖子 wjjs » 2008-10-29 15:58

:em01 :em01 :em01
附件
Screenshot-feng [正在运行] - VirtualBox OSE.png
头像
muzuiget
帖子: 1097
注册时间: 2007-12-31 14:57

Re: VirtualBox从USB设备启动方法

#11

帖子 muzuiget » 2008-10-30 21:12

wjjs 写了:

代码: 全选

feng@feng-laptop:~/桌面$ sudo usermod -G vboxusers -a `whoami`
[sudo] password for feng: 
feng@feng-laptop:~/桌面$ sudo chmod o+rw /dev/sdc
feng@feng-laptop:~/桌面$ VBoxManage internalcommands createrawvmdk -filename ~/.VirtualBox/VDI/UsbDisk.vmdk -rawdisk /dev/sdc -register
VirtualBox Command Line Management Interface Version 2.0.4_OSE
(C) 2005-2008 Sun Microsystems, Inc.
All rights reserved.

RAW host disk access VMDK file /home/feng/.VirtualBox/VDI/UsbDisk.vmdk created successfully.
feng@feng-laptop:~/桌面$ 
1.5.6的OSE不行,2.0.4的OSE却行,Sun倒挺大方的,谢谢你的测试。
gjm33
帖子: 15
注册时间: 2008-10-19 20:06

Re: VirtualBox从USB设备启动方法

#12

帖子 gjm33 » 2008-11-09 19:01

真的把U盘挂个去了,就是不知道工行的U盾是不是也能这样用呢
gjm33
帖子: 15
注册时间: 2008-10-19 20:06

Re: VirtualBox从USB设备启动方法

#13

帖子 gjm33 » 2008-11-09 19:06

我原来是sdb的,把U盘拨下后再插上去就成了sdc了,然后就用不了,真是奇怪了
头像
20youyou08
帖子: 27
注册时间: 2008-09-12 20:42
来自: 淄博
联系:

Re: VirtualBox从USB设备启动方法

#14

帖子 20youyou08 » 2008-11-17 19:58

很感谢分享!
楼主辛苦 :em11
出岫之云
帖子: 220
注册时间: 2007-06-21 22:25

Re: VirtualBox从USB设备启动方法

#15

帖子 出岫之云 » 2009-02-03 23:52

需要这么麻烦吗?我移动硬盘上的ubuntu就是在vbox中直接装上去的啊。在vbox的虚拟电脑的USB设置中挂上移动硬盘,然后挂上ubuntu安装盘的ISO文件到光驱,从此光驱启动安装ubuntu,安装过程中可以直接选择将系统安装到挂上的移动硬盘中啊。记得当时的vbox版本好像是2.0.4吧,另外好像我没为虚拟电脑建虚拟硬盘,现在记得不太清楚了。
回复