9 Advanced topics 9.7 Advanced storage configuration 9.7.1 Using a raw host hard disk from a guest Starting with version 1.4, as an alternative to using virtual disk images (as described in detail in chapter 5, Virtual storage, page 71), VirtualBox can also present either entire physical hard disks or selected partitions thereof as virtual disks to virtual machines. With VirtualBox, this type of access is called “raw hard disk access” it allows a guest operating system to access its virtual hard disk without going through the host OS file system. The actual performance difference for image files vs. raw disk varies greatly depending on the overhead of the host file system, whether dynamically growing images are used and on host OS caching strategies. The caching indirectly also affects other aspects such as failure behavior, i.e. whether the virtual disk contains all data written before a host OS crash. Consult your host OS documen- tation for details on this. Warning: Raw hard disk access is for expert users only. Incorrect use or use of an outdated configuration can lead to total loss of data on the physical disk. Most impor- tantly, do not attempt to boot the partition with the currently running host operating system in a guest. This will lead to severe data corruption. Raw hard disk access both for entire disks and individual partitions is implemented as part of the VMDK image format support. As a result, you will need to create a special VMDK image file which defines where the data will be stored. After creating such a special VMDK image, you can use it like a regular virtual disk image. For example, you can use the Virtual Media Manager (chapter 5.3, The Virtual Media Manager, page 74) or VBoxManage to assign the image to a virtual machine. 9.7.1.1 Access to entire physical hard disk While this variant is the simplest to set up, you must be aware that this will give a guest operating system direct and full access to an entire physical disk. If your host operating system is also booted from this disk, please take special care to not access the partition from the guest at all. On the positive side, the physical disk can be repartitioned in arbitrary ways without having to recreate the image file that gives access to the raw disk. To create an image that represents an entire physical hard disk (which will not contain any actual data, as this will all be stored on the physical disk), on a Linux host, use the command VBoxManage internalcommands createrawvmdk -filename /path/to/file.vmdk -rawdisk /dev/sda This creates the image /path/to/file.vmdk (must be absolute), and all data will be read and written from /dev/sda. 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 get access to an entire disk if no volume is mounted from it. 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. Just like with regular disk images, this does not automatically register the newly created image in the internal registry of hard disks. If you want this done automatically, add -register: VBoxManage internalcommands createrawvmdk -filename /path/to/file.vmdk -rawdisk /dev/sda -register After registering, you can assign the newly created image to a virtual machine with e.g. VBoxManage storageattach WindowsXP --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium /path/to/file.vmdk When this is done the selected virtual machine will boot from the specified physical disk. 142
Previous Page Next Page