9 Advanced topics
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. Partition numbers are the same on Linux and Windows 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
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,
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
VBoxManage internalcommands createrawvmdk
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
VBoxManage internalcommands createrawvmdk
which creates an image referring to individual partitions, and registers it when the image is successfully created.
137