分享

Vmware虚拟机与VirtualBox虚拟机的硬盘镜像相互转换

 oskycar 2011-11-29
公司不允许使用盗版软件,所以工作使用虚拟机是VirtualBox,但是在使用的过程中发现这个VirtualBox的USB搞不定,无法使用USB设备。没有办法只有转投Vmware,使用免费的VmwarePlayer。只是已经安装的VirtualBox虚拟机不想浪费了,毕竟已经安装了很多的软件。
网络上大部分都在说如何把VMware导入到VirtualBox中,我在最新的版本到看到VirtualBox (3.2.2)已经支持VMware虚拟硬盘格式vmdk,所以新建一个VBox虚拟机,直接注册VMware的虚拟硬盘就可以了。
其实没有必要把整个虚拟机相互转换,只要把虚拟硬盘镜像转换就可以了,不需要转换,但是要在VMplayer中使用VDI格式的硬盘镜像就得费点劲转换一个格式了。
使用第三种虚拟机来完成这个工作--qemu,
知道可以使用qemu-img来转换,按照上面的说明安装qemu-kvm,使用过程中发现可以当前的qemu版本已经支持几乎所有的虚拟硬盘格式,参照下面的命令帮助。
在Ubuntu下可以很方便的安装
shily@hh-desktop:~#sudo apt-get install qemu-kvm
使用如下一个命令就可以轻松完成转换。
shily@hh-desktop:~#qemu-img convert  -f vdi -O vmdk Winxp.vdi Winxp.vmdk
直接修改已经建好的虚拟机,(Ubuntu系统在~/vmware/)
例如我建立的虚拟机叫Win,则修改 ~/vmware/Win/Win.vmx,找到 ide0:0.fileName = "Win.vmdk"
把其中的Win.vmdk修改成你转换生成的文件名即可。
[注]:
1,Winxp.vdi要根据VitrualBox虚拟机的名称修改,在目录~/.VirtualBox/HardDisks下可以找到。
2,.vmx 是VMware虚拟机的配置文件,是一个文本文件可以直接修改,也可以在程序中更改,删除原来的硬盘,再添加转换后的硬盘。
======================
shily@hh-desktop:~$ qemu-img
qemu-img version 0.12.3, Copyright (c) 2004-2008 Fabrice Bellard
usage: qemu-img command [command options]
QEMU disk image utility

Command syntax:
check [-f fmt] filename
create [-f fmt] [-o options] filename [size]
commit [-f fmt] filename
convert [-c] [-f fmt] [-O output_fmt] [-o options] filename [filename2 [...]] output_filename
info [-f fmt] filename
snapshot [-l | -a snapshot | -c snapshot | -d snapshot] filename

Command parameters:
'filename' is a disk image filename
'fmt' is the disk image format. It is guessed automatically in most cases
'size' is the disk image size in bytes. Optional suffixes
'k' or 'K' (kilobyte, 1024), 'M' (megabyte, 1024k), 'G' (gigabyte, 1024M)
and T (terabyte, 1024G) are supported. 'b' is ignored.
'output_filename' is the destination disk image filename
'output_fmt' is the destination format
'options' is a comma separated list of format specific options in a
name=value format. Use -o ? for an overview of the options supported by the
used format
'-c' indicates that target image must be compressed (qcow format only)
'-h' with or without a command shows this help and lists the supported formats

Parameters to snapshot subcommand:
'snapshot' is the name of the snapshot to create, apply or delete
'-a' applies a snapshot (revert disk to saved state)
'-c' creates a snapshot
'-d' deletes a snapshot
'-l' lists all snapshots in the given image

Supported formats: cow qcow vdi vmdk cloop dmg bochs vpc vvfat qcow2 parallels nbd host_cdrom host_floppy host_device raw tftp ftps ftp https http

======================
参考:Howto Convert Vmware Image to Virtualbox Image or Import Vmware Image into Virtualbox
======================================
2010-06-06 更新
警告:
安装qemu-kvm可能导致virtualbox无法启动,在我的机器上出现了如下提示:

Failed to open a session for the virtual machine WinXP.

VirtualBox can't operate in VMX root mode. Please disable the KVM kernel extension, recompile your kernel and reboot (VERR_VMX_IN_VMX_ROOT_MODE).

Details:
Result Code:
NS_ERROR_FAILURE (0x80004005)
Component:
Console
Interface:
IConsole {6375231a-c17c-464b-92cb-ae9e128d71c3}

可能导致的原因是我的系统环境比较复杂:安装在USB硬盘上,经常在T60p和Dell的740上工作,他们的CPU一个是Intel、另外一个是AMD,比较郁闷。在网上找到一个解决方案。
shily@hh-desktop:~$sudo modprobe -r kvm_intel          #因为我当前的CPU是Intel,你也可以直接使用sudo modprobe -r kvm来删除kvm模块,无论你使用什么样的CPU。
然后打开VirtualBox就可以了,但是你需要在每次重启开机后执行这个命令,如果你需要启动Vbox的话。

参照: VirtualBox can't operate in VMX root mode.

很郁闷的是,我在开启虚拟机后发现USB设备已经可以在虚拟机中正常使用了,我并不清楚什么原因导致可以使用。
==========================
最新更新:
学习了些新东西,找到了原因。
发现我系统中的 /etc/udev/rules.d/10-vboxdrv.rules 文件不知道什么原因消失了。
重新建立一个,写入以下内容:

KERNEL=="vboxdrv", NAME="vboxdrv", OWNER="root", GROUP="root", MODE="0600"
SUBSYSTEM=="usb_device", GROUP="vboxusers", MODE="0664"
SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", GROUP="vboxusers", MODE="0664"

重新启动虚拟机,就可以使用USB了。

 
 
 
网友评论:
1 2010-08-29 01:44 来自手机 | 回复
Vbox的闭源版可以分配USB
 
2 2010-10-27 11:39 | 回复
哥呀,因为usb,折腾的有点大阿。

按照下面的步骤弄好:
==============================
先要安装闭源版的VirtualBox ,OES版的不支持USB。
因为权限问题,普通用户是用不了USB的,所以还得设置下。

1。增加用户组usbfs
$ sudo groupadd usbfs

2. 查看usbfs用户组的gid
$ cat /etc/group | grep usbfs
usbfs:x:1001:

3.把当前用户增加到usbfs组
$ sudo gedit /etc/group

usbfs:x:1001:
修改为
usbfs:x:1001:youname(改成你的用户名)

4. 为USB设备重新设置权限编辑/etc/fstab文件,添加下面两行,注意你的gid可能不是1001
$ sudo gedit /etc/fstab
在末尾加上
# 1001 is the USB group IDI
none /proc/bus/usb usbfs devgid=1001,devmode=664 0 0

重新启动后,应该就可以使用USB设备了 。
==============================
结果,还是不行,virtualbox中的usb是灰色的
使用:$: VBOX_USB=USBFS VirtualBox &
问题解决

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多