1 | <?xml version='1.0' encoding='UTF-8'?>
|
---|
2 | <!DOCTYPE topic PUBLIC "-//OASIS//DTD DITA Topic//EN" "topic.dtd">
|
---|
3 | <topic xml:lang="en-us" id="rawdisk-access-disk-partitions">
|
---|
4 | <title>Access to Individual Physical Hard Disk Partitions</title>
|
---|
5 |
|
---|
6 | <body>
|
---|
7 | <p>
|
---|
8 | This <i>raw partition support</i> is quite
|
---|
9 | similar to the full hard disk access described above. However,
|
---|
10 | in this case, any partitioning information will be stored
|
---|
11 | inside the VMDK image. This means that you can install a
|
---|
12 | different boot loader in the virtual hard disk without
|
---|
13 | affecting the host's partitioning information. While the guest
|
---|
14 | will be able to <i>see</i> all partitions that
|
---|
15 | exist on the physical disk, access will be filtered in that
|
---|
16 | reading from partitions for which no access is allowed the
|
---|
17 | partitions will only yield zeroes, and all writes to them are
|
---|
18 | ignored.
|
---|
19 | </p>
|
---|
20 | <p>
|
---|
21 | To create a special image for raw partition support, which
|
---|
22 | will contain a small amount of data, on a Linux host, use the
|
---|
23 | command:
|
---|
24 | </p>
|
---|
25 | <pre xml:space="preserve">$ VBoxManage createmedium disk --filename <varname>path-to-file</varname>.vmdk --format=VMDK
|
---|
26 | --variant RawDisk --property RawDrive=/dev/sda --property Partitions=1,5</pre>
|
---|
27 | <p>
|
---|
28 | The command is identical to the one for full hard disk access,
|
---|
29 | except for the additional <codeph>--property</codeph>
|
---|
30 | Partitions=1,5 parameter. This example would create
|
---|
31 | the image
|
---|
32 | <filepath><varname>path-to-file</varname>.vmdk</filepath>,
|
---|
33 | which must be absolute, and partitions 1 and 5 of
|
---|
34 | <filepath>/dev/sda</filepath> would be made accessible to the
|
---|
35 | guest.
|
---|
36 | </p>
|
---|
37 | <p>
|
---|
38 | Oracle VM VirtualBox uses the same partition numbering as your Linux
|
---|
39 | host. As a result, the numbers given in the above example
|
---|
40 | would refer to the first primary partition and the first
|
---|
41 | logical drive in the extended partition, respectively.
|
---|
42 | </p>
|
---|
43 | <p>
|
---|
44 | On a Windows host, instead of the above device specification,
|
---|
45 | use for example <filepath>\\.\PhysicalDrive0</filepath>. On a
|
---|
46 | macOS host, instead of the above device specification use
|
---|
47 | <filepath>/dev/rdisk1</filepath>, for example. Note that on OS
|
---|
48 | X you can only use partitions which are not mounted. Unmount
|
---|
49 | the respective disk first using <i>diskutil unmountDisk
|
---|
50 | <filepath>/dev/diskX</filepath>
|
---|
51 | </i>. Partition numbers
|
---|
52 | are the same on Linux, Windows, and macOS hosts.
|
---|
53 | </p>
|
---|
54 | <p>
|
---|
55 | The numbers for the list of partitions can be taken from the
|
---|
56 | output of the following command:
|
---|
57 | </p>
|
---|
58 | <pre xml:space="preserve">$ VBoxManage list hostdrives</pre>
|
---|
59 | <p>
|
---|
60 | The output lists available drives and their partitions with
|
---|
61 | the partition types and sizes to give the user enough
|
---|
62 | information to identify the partitions necessary for the
|
---|
63 | guest.
|
---|
64 | </p>
|
---|
65 | <p>
|
---|
66 | Images which give access to individual partitions are specific
|
---|
67 | to a particular host disk setup. You cannot transfer these
|
---|
68 | images to another host. Also, whenever the host partitioning
|
---|
69 | changes, the image <i>must be recreated</i>.
|
---|
70 | </p>
|
---|
71 | <p>
|
---|
72 | Creating the image requires read/write access for the given
|
---|
73 | device. Read/write access is also later needed when using the
|
---|
74 | image from a virtual machine. If this is not feasible, there
|
---|
75 | is a special variant for raw partition access, currently only
|
---|
76 | available on Linux hosts, that avoids having to give the
|
---|
77 | current user access to the entire disk. To set up such an
|
---|
78 | image, use:
|
---|
79 | </p>
|
---|
80 | <pre xml:space="preserve">$ VBoxManage createmedium disk --filename <varname>path-to-file</varname>.vmdk --format=VMDK
|
---|
81 | --variant RawDisk --property RawDrive=/dev/sda --property Partitions=1,5
|
---|
82 | --property Relative=1</pre>
|
---|
83 | <p>
|
---|
84 | When used from a virtual machine, the image will then refer
|
---|
85 | not to the entire disk, but only to the individual partitions.
|
---|
86 | In this example, <filepath>/dev/sda1</filepath> and
|
---|
87 | <filepath>/dev/sda5</filepath>. As a consequence, read/write
|
---|
88 | access is only required for the affected partitions, not for
|
---|
89 | the entire disk. During creation however, read-only access to
|
---|
90 | the entire disk is required to obtain the partitioning
|
---|
91 | information.
|
---|
92 | </p>
|
---|
93 | <p>
|
---|
94 | In some configurations it may be necessary to change the MBR
|
---|
95 | code of the created image. For example, to replace the Linux
|
---|
96 | boot loader that is used on the host by another boot loader.
|
---|
97 | This enables for example the guest to boot directly to
|
---|
98 | Windows, while the host boots Linux from the "same" disk. For
|
---|
99 | this purpose the <codeph>--property-file</codeph>
|
---|
100 | BootSector=<varname>path-to-file-with-boot-sector</varname>
|
---|
101 | parameter is provided. It specifies a file name from which to
|
---|
102 | take the MBR code. The partition table is not modified at all,
|
---|
103 | so a MBR file from a system with totally different
|
---|
104 | partitioning can be used. An example of this is:
|
---|
105 | </p>
|
---|
106 | <pre xml:space="preserve">$ VBoxManage createmedium disk --filename <varname>path-to-file</varname>.vmdk --format=VMDK
|
---|
107 | --variant RawDisk --property RawDrive=/dev/sda --property Partitions=1,5
|
---|
108 | --property-file BootSector=winxp.mbr</pre>
|
---|
109 | <p>
|
---|
110 | The modified MBR will be stored inside the image, not on the
|
---|
111 | host disk.
|
---|
112 | </p>
|
---|
113 | <p>
|
---|
114 | The created image can be attached to a storage controller in a
|
---|
115 | VM configuration as usual.
|
---|
116 | </p>
|
---|
117 | </body>
|
---|
118 |
|
---|
119 | </topic>
|
---|