virtualbox直接用物理分区作虚拟机的硬盘的问题

Kvm、VMware、Virtualbox、Xen、Qemu 等
brglng
帖子: 198
注册时间: 2008-02-05 20:26

virtualbox直接用物理分区作虚拟机的硬盘的问题

#1

帖子 brglng » 2009-04-15 17:21

我用一个物理分区做虚拟机的硬盘,在使用时有时会把host上的文件系统变成只读属性。host机的fstab里面是umask=000的,开机时是可读写的,运行虚拟机后一开始也没问题,但用着用着那个分区在host上就变成只读了,重新挂载也没用。
头像
day2up
帖子: 60
注册时间: 2009-04-14 23:51

Re: virtualbox直接用物理分区作虚拟机的硬盘的问题

#2

帖子 day2up » 2009-04-21 21:42

virtualbox 可以直接用物理分区吗?
我没找到方法呢
清 凉散 人
帖子: 89
注册时间: 2008-11-18 8:50

Re: virtualbox直接用物理分区作虚拟机的硬盘的问题

#3

帖子 清 凉散 人 » 2009-04-25 22:51

怎么使用的啊,我也一直想知道方法。能像vm那样使用物理磁盘吗,,
头像
百草谷居士
帖子: 3921
注册时间: 2006-02-10 16:36
系统: Mint21.1/Deepin20.8

Re: virtualbox直接用物理分区作虚拟机的硬盘的问题

#4

帖子 百草谷居士 » 2011-02-06 13:17

在virtualbox帮助上是这样描述的:

代码: 全选

9.6.1.2. Access to individual physical hard disk partitions
This "raw partition support" is quite similar to the "full hard disk" access described above. However, in this case, any partitioning information will be stored inside the VMDK image, so you can e.g. install a different boot loader in the virtual hard disk without affecting the host's partitioning information. While the guest will be able to see all partitions that exist on the physical disk, access will be filtered in that reading from partitions for which no access is allowed the partitions will only yield zeroes, and all writes to them are ignored.
To create a special image for raw partition support (which will contain a small amount of data, as already mentioned), on a Linux host, use the command
VBoxManage internalcommands createrawvmdk -filename /path/to/file.vmdk
      -rawdisk /dev/sda -partitions 1,5
As you can see, the command is identical to the one for "full hard disk" access, except for the additional -partitions parameter. This example would create the image /path/to/file.vmdk (which, again, must be absolute), and partitions 1 and 5 of /dev/sda would be made accessible to the guest.
VirtualBox uses the same partition numbering as your Linux host. As a result, the numbers given in the above example would refer to the first primary partition and the first logical drive in the extended partition, respectively.
On a Windows host, instead of the above device specification, use e.g. \\.\PhysicalDrive0. On a Mac OS X host, instead of the above device specification use e.g. /dev/disk1. Note that on OS X you can only use partitions which are not mounted (eject the respective volume first). Partition numbers are the same on Linux, Windows and Mac OS X hosts.
The numbers for the list of partitions can be taken from the output of
VBoxManage internalcommands listpartitions -rawdisk /dev/sda
The output lists the partition types and sizes to give the user enough information to identify the partitions necessary for the guest.
Images which give access to individual partitions are specific to a particular host disk setup. You cannot transfer these images to another host; also, whenever the host partitioning changes, the image must be recreated.
Creating the image requires read/write access for the given device. Read/write access is also later needed when using the image from a virtual machine. If this is not feasible, there is a special variant for raw partition access (currently only available on Linux hosts) that avoids having to give the current user access to the entire disk. To set up such an image, use
VBoxManage internalcommands createrawvmdk -filename /path/to/file.vmdk
      -rawdisk /dev/sda -partitions 1,5 -relative
When used from a virtual machine, the image will then refer not to the entire disk, but only to the individual partitions (in the example /dev/sda1 and /dev/sda5). As a consequence, read/write access is only required for the affected partitions, not for the entire disk. During creation however, read-only access to the entire disk is required to obtain the partitioning information.
In some configurations it may be necessary to change the MBR code of the created image, e.g. to replace the Linux boot loader that is used on the host by another boot loader. This allows e.g. the guest to boot directly to Windows, while the host boots Linux from the "same" disk. For this purpose the -mbr parameter is provided. It specifies a file name from which to take the MBR code. The partition table is not modified at all, so a MBR file from a system with totally different partitioning can be used. An example of this is
VBoxManage internalcommands createrawvmdk -filename /path/to/file.vmdk
      -rawdisk /dev/sda -partitions 1,5 -mbr winxp.mbr
The modified MBR will be stored inside the image, not on the host disk.
For each of the above variants, you can register the resulting image for immediate use in VirtualBox by adding -register to the respective command line. The image will then immediately appear in the list of registered disk images. An example is
VBoxManage internalcommands createrawvmdk -filename /path/to/file.vmdk
      -rawdisk /dev/sda -partitions 1,5 -relative -register
which creates an image referring to individual partitions, and registers it when the image is successfully created.
我以此而行,在虚拟机中挂载这个磁盘文件时,却总是提示错误。
希望有经验的朋友能帮帮我。
debian 12 / 深度系统 20.9 / Mint 21.3

为何热衷于搞发行版的多,搞应用程序开发的少?Linux最多余的就是各种发行版,最缺的就是应用程序,特别是行业应用程序。
头像
百草谷居士
帖子: 3921
注册时间: 2006-02-10 16:36
系统: Mint21.1/Deepin20.8

Re: virtualbox直接用物理分区作虚拟机的硬盘的问题

#5

帖子 百草谷居士 » 2011-02-06 13:48

建立磁盘文件的过程如下:

代码: 全选

sudo VBoxManage internalcommands createrawvmdk -filename /home/lpl/.VirtualBox/HardDisks/rawsda5.vmdk -rawdisk /dev/sda -partitions 5 -relative 
RAW host disk access VMDK file /home/lpl/.VirtualBox/HardDisks/rawsda5.vmdk created successfully.
挂载磁盘文件及错误提示如下:

代码: 全选

VBoxManage storageattach mediaxp --storagectl "IDE 控制器" --port 0 --device 1 --type hdd --medium /home/lpl/.VirtualBox/HardDisks/rawsda5.vmdk 
VBoxManage: error: The medium '/home/lpl/.VirtualBox/HardDisks/rawsda5.vmdk' can't be used as the requested device type
VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component Medium, interface IMedium, callee nsISupports
Context: "OpenMedium(Bstr(pszFilenameOrUuid).raw(), enmDevType, AccessMode_ReadWrite, pMedium.asOutParam())" at line 209 of file VBoxManageDisk.cpp
VBoxManage: error: Invalid UUID or filename "/home/lpl/.VirtualBox/HardDisks/rawsda5.vmdk"
我估计是访问权限的问题,涉及到fstab中对sda5如何设置。但我不知道如何做。
debian 12 / 深度系统 20.9 / Mint 21.3

为何热衷于搞发行版的多,搞应用程序开发的少?Linux最多余的就是各种发行版,最缺的就是应用程序,特别是行业应用程序。
头像
百草谷居士
帖子: 3921
注册时间: 2006-02-10 16:36
系统: Mint21.1/Deepin20.8

Re: virtualbox直接用物理分区作虚拟机的硬盘的问题

#6

帖子 百草谷居士 » 2011-02-06 20:34

顶一下,求解
debian 12 / 深度系统 20.9 / Mint 21.3

为何热衷于搞发行版的多,搞应用程序开发的少?Linux最多余的就是各种发行版,最缺的就是应用程序,特别是行业应用程序。
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

Re: virtualbox直接用物理分区作虚拟机的硬盘的问题

#7

帖子 eexpress » 2011-02-06 20:37

检查磁盘试试。
用着用着,,,就变了???
● 鸣学
tycable
帖子: 66
注册时间: 2011-01-01 8:14

Re: virtualbox直接用物理分区作虚拟机的硬盘的问题

#8

帖子 tycable » 2011-02-06 22:13

既然怀疑是权限问题,改了所有者。

sudo chown -hR <yourName> <Directory>

若不对,再改成 root 比较保险。
Blog <http://ffb-all.com/>
Linux User #529415 with Linux Counter <http://counter.li.org/>
PGP keyID F73D6274 hkp://keyserver.ubuntu.com
头像
百草谷居士
帖子: 3921
注册时间: 2006-02-10 16:36
系统: Mint21.1/Deepin20.8

Re: virtualbox直接用物理分区作虚拟机的硬盘的问题

#9

帖子 百草谷居士 » 2011-02-07 21:09

改了磁盘文件权限,但是不行。
debian 12 / 深度系统 20.9 / Mint 21.3

为何热衷于搞发行版的多,搞应用程序开发的少?Linux最多余的就是各种发行版,最缺的就是应用程序,特别是行业应用程序。
tycable
帖子: 66
注册时间: 2011-01-01 8:14

Re: virtualbox直接用物理分区作虚拟机的硬盘的问题

#10

帖子 tycable » 2011-02-08 16:15

用户与组 里有一个 vboxusers, 你有没有把自己加进去。

下面是 命令行做法,也可以直接在 系统 > 管理 > 用户与组 里设置。

sudo gpasswd -a <yourName> vboxusers
Blog <http://ffb-all.com/>
Linux User #529415 with Linux Counter <http://counter.li.org/>
PGP keyID F73D6274 hkp://keyserver.ubuntu.com
头像
百草谷居士
帖子: 3921
注册时间: 2006-02-10 16:36
系统: Mint21.1/Deepin20.8

Re: virtualbox直接用物理分区作虚拟机的硬盘的问题

#11

帖子 百草谷居士 » 2011-02-09 10:18

把自己加到vboxusers组里,倒是早就这么做了。我觉得应该是因为普通用户没有对/dev/sda设备的访问权导致的。
debian 12 / 深度系统 20.9 / Mint 21.3

为何热衷于搞发行版的多,搞应用程序开发的少?Linux最多余的就是各种发行版,最缺的就是应用程序,特别是行业应用程序。
头像
百草谷居士
帖子: 3921
注册时间: 2006-02-10 16:36
系统: Mint21.1/Deepin20.8

Re: virtualbox直接用物理分区作虚拟机的硬盘的问题

#12

帖子 百草谷居士 » 2011-02-09 11:06

在virtualbox官方论坛看到这样的方法,回头试试。

代码: 全选

# Change permissions of the relevant partitions or disks.
This involves giving yourself read and write access to a whole disk or partition, for example:


    sudo chmod 666 /dev/sdb2


This is however still somewhat dangerous since any application running under your account has full access to that partition (or disk).
debian 12 / 深度系统 20.9 / Mint 21.3

为何热衷于搞发行版的多,搞应用程序开发的少?Linux最多余的就是各种发行版,最缺的就是应用程序,特别是行业应用程序。
头像
百草谷居士
帖子: 3921
注册时间: 2006-02-10 16:36
系统: Mint21.1/Deepin20.8

Re: virtualbox直接用物理分区作虚拟机的硬盘的问题

#13

帖子 百草谷居士 » 2011-02-09 12:24

基本成功。一是需要把物理分区设置为当前用户可读写,二是把磁盘配置文件(注意分区是两个)设置为当前用户可读写。
但是仍然存在两个问题。
1、虽然赋予了当前用户对指定分区的读写权限,但是系统会自动取消这个权限。我想如何在fstab中设定这个读写权限?
2、在客户机XP系统中的计算机管理中,看到的不是这个分区,而是整个磁盘,怪吓人的!
debian 12 / 深度系统 20.9 / Mint 21.3

为何热衷于搞发行版的多,搞应用程序开发的少?Linux最多余的就是各种发行版,最缺的就是应用程序,特别是行业应用程序。
tycable
帖子: 66
注册时间: 2011-01-01 8:14

Re: virtualbox直接用物理分区作虚拟机的硬盘的问题

#14

帖子 tycable » 2011-02-10 11:56

貌似 fstab 实现不了。

试试更改 /etc/profile 吧。

让 ubuntu 启动时更改相应配置。

你自己找找吧,我不清楚具体怎么做,说不定可以在里面找到相应的配置。

思路就是 找到“系统会自动取消这个权限” 的配置位置,然后改变它。
Blog <http://ffb-all.com/>
Linux User #529415 with Linux Counter <http://counter.li.org/>
PGP keyID F73D6274 hkp://keyserver.ubuntu.com
jtshs256
帖子: 22323
注册时间: 2010-07-19 21:41
系统: OS X

Re: virtualbox直接用物理分区作虚拟机的硬盘的问题

#15

帖子 jtshs256 » 2011-02-10 11:57

加个mode=666试试……
躺平
回复