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.