0

How can I access an internal drive from my guest systems? My host is Windows 7. I tried the manual, but when I attach the new vmdk to a Windows 7 guest, it is displayed as unformatted with zero disk space. The command for creating the vmdk is:

VBoxManage.exe internalcommands createrawvmdk -filename C:\Users\me\.Virtualbox\VDI\mydrive.vmdk -rawdisk \\.\PhysicalDrive0

Where the number behind PhysicalDrive is the disk number in Computermanagement->Diskmanagement. If I understand the problem correctly, the manual rather seems to address using the harddrive as a boot device instead of storage. My motivation to simply add another disk to my virtual guest is that I have additional storage that can be accessed without virtualization overhead. Sharing data is not an issue. The disk itself does not store data that is important, though I would not like to delete it if this is an option. I am going to use shared folders for now, but afaik they are slow in comparison.

[EDIT] Sorry for the confusion, the vm image I used is Windows XP, not Windows 7. I created a new vmdk with administrator privileges as suggested in the comments. The bahavior did not change though. Next, I tried to access the disk in my Ubuntu vm. On the first start, I got an error VERR_ACCESS_DENIED, make sure there is enough free space. After restarting the vm forcefully, I could access the disk through the file manager. I also tried to access the disk from a Windows 7 vm (yes this time really Windows 7). There the same VERR_ACCESS_DENIED error occurred. In contrast to the Ubuntu vm it reappeared everytime I restarted (three times).

[EDIT2] The implementation seems to be flawed. I wrote a script to write 10GB of 1MB files, 10GB of 2GB, and so on. First I got an error on the 6200.th 1MB file. In the next run, the same error occurred on the first 3MB file:

/bin/dd: opening `/media/Ultra_/samplefiles/3MB_1': Input/output error

Thereafter, I get an IO error when trying to access the samplefiles directory in any way.

[EDIT3] Here is a test script to reproduce the error. If I access the disk through my host system, I cannot see the files/folders that I wrote to it through the guest. On the guest itself the files are visible, and the file system size of the raw file system visible through df -h decreases as I write files to it. I can still access other files on the disk after the error occurred.

    #!/usr/bin/python
"""Generate directory of files for testing."""
import sys, os
import argparse
try:
    import sh
    from sh import dd
except:
    print 'Please install the python sh module first : pip install sh'
    exit(1)

class MyParser(argparse.ArgumentParser):
    def error(self, message):
        print_help()
        sys.exit(1)

def print_help():
   print
   print '  Not enough arguments.\n'
   print '      Example: '
   print '          %s directory_for_generated_files' %  sys.argv[0]
   print '          Generate 10GB worth of 1MB, 2MB, 3MB, 4MB, 5MB, and 6MB files to the directory *directory_for_generated_files*.'
   print

def main():
    parser = MyParser()
    parser.add_argument('directory')
    args = parser.parse_args()
    directory = args.directory
    if not os.path.exists(directory):
        os.makedirs(directory)
    filesize_arr = [1,2,3,4,5,6]
    filequantity_arr = [10000,5000,3333,2500,2000,1667]

    idx = 0 
    for size in filesize_arr:
        for nr in range(1,filequantity_arr[idx]+1):  # from 1 to file quantity
            filename =  directory+'/'+str(size)+'MB_'+str(nr)
            print "writing "+directory+'/'+str(size)+'MB_'+str(nr)
            dd('if=/dev/zero', 'of='+filename, 'bs=1MB', 'count='+str(size))
        idx += 1

if __name__ == '__main__':
    main()

[EDIT4] The changes made to the file system are not visible after restart of the virtual machine.

3
  • Are you running the vboxmanage command with administrative rights?
    – K.A.Monica
    Commented Nov 22, 2013 at 0:59
  • Not sure if has changed but used to need to run VirtualBox as administrator for it to have access to raw disks.
    – Brian
    Commented Nov 22, 2013 at 7:17
  • Thanks, I will try this in the evening. I was not sure about this point, so I first tried it without admin priviledges. As it did not complain I thought it was fine.
    – phobic
    Commented Nov 22, 2013 at 7:32

1 Answer 1

0

Only drives and partitions that aren't mounted in host OS are accessible from VMs. I guess \\.\PhysicalDrive0 is the drive you're booting your host from, so you won't be able to use it. This is very unlikely to change in the future, as sharing a drive between two OSes would cause a number of problems, potentially leading to data corruption.

If you want to share files between host OS and guest OS, you should install VirtualBox Addons in the guest - a sharing option will appear in VM settings, allowing you to set up a shared network folder in guest that will point to some of host's folders.

6
  • I understand that my post is long, but it states explicitly that sharing is not an issue. Also, that the drive does not contain important data. So there is no operating system on it. Do you happen to know how to "unmount" the disk in Windows if you think this is the problem here?
    – phobic
    Commented Nov 23, 2013 at 21:57
  • Sorry, I have overlooked the sharing part. To "unmount" the disk, I think unassigning all drive letters or mount points from the partitions on that drive should be enough. You can do that in the Computer Management window (right-click Computer in the Start menu and click Manage). If that doesn't work, try with individual partitions instead of entire drive (a partition spanning over entire drive should work too). VBox manual covers this topic. Note that disks are indexed from 0, but partitions start from 1.
    – gronostaj
    Commented Nov 23, 2013 at 22:14
  • After unmounting the disk in Windows I can still reproduce the error with the above script.
    – phobic
    Commented Nov 23, 2013 at 23:41
  • Try rebooting. Reinstalling the same or updated version of VirtualBox may help too, there are some known issues with VMDK that are solved by VBox reinstallation.
    – gronostaj
    Commented Nov 23, 2013 at 23:45
  • After "repair" installation of the newest VB and reboot of the host and guest, I can still reliably reproduce the error.
    – phobic
    Commented Nov 25, 2013 at 11:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .