vmdk parmeter "-mbr"
vmdk parmeter "-mbr"
I need help in understanding how to use the -mbr parm of the vmdk create vboxmanage command.
If I have a large ssd running (gpt uefi) manjaro and add 3 distros, would building a file that contains the "MBR" after each installation be useful in defining the seperate distros for virtualbox vmdk usage ?
If I have a large ssd running (gpt uefi) manjaro and add 3 distros, would building a file that contains the "MBR" after each installation be useful in defining the seperate distros for virtualbox vmdk usage ?
-
- Site Moderator
- Posts: 20945
- Joined: 30. Dec 2009, 20:14
- Primary OS: MS Windows 10
- VBox Version: PUEL
- Guest OSses: Windows, Linux
Re: vmdk parmeter "-mbr"
In section 9.7.1.2 it says:
That's all I can find. I don't know how to create the MBR file.In some configurations it may be necessary to change the MBR code of the created image. For
example, to replace the Linux boot loader that is used on the host by another boot loader. This
enables for example the guest to boot directly to Windows, while the host boots Linux from the
“same” disk. For this purpose the -mbr option is provided. It specifies a file name from which to
take the MBR code. The partition table is not modified at all, so a MBR file from a system with
totally different partitioning can be used. An example of this is:
$ VBoxManage internalcommands createrawvmdk -filename
<path-to-file>.vmdk -rawdisk /dev/sda -partitions 1,5 -mbr winxp.mbr
The modified MBR will be stored inside the image, not on the host disk.
The created image can be attached to a storage controller in a VM configuration as usual.
-
- Site Moderator
- Posts: 39134
- Joined: 4. Sep 2008, 17:09
- Primary OS: MS Windows 10
- VBox Version: PUEL
- Guest OSses: Mostly XP
Re: vmdk parmeter "-mbr"
The MBR is the first sector of an MBR formatted (i.e. not GPT formatted) drive. The easiest way to create one is to copy the first 512 bytes of an existing image to a file, then edit that file using your favorite tool, e.g. a hex editor or something you knock up in C.
This is NOT a prescriptive solution. The MBR contains a partition map which must correctly describe the layout of the disk.
This is NOT a prescriptive solution. The MBR contains a partition map which must correctly describe the layout of the disk.
Edit: CloneVDI contains source code for an MBR, see attachment. This includes a declaration for the partition table (at the end), which is currently blank but you could conceivably construct the partition table there and then reassemble to create your MBR file. This may be more convenient than using a hex editor. |
- Attachments
-
- mbr.zip
- (3.25 KiB) Downloaded 10 times
-
- Volunteer
- Posts: 5677
- Joined: 14. Feb 2019, 03:06
- Primary OS: Mac OS X other
- VBox Version: PUEL
- Guest OSses: Linux, Windows 10, ...
- Location: Germany
Re: vmdk parmeter "-mbr"
Not in this special case: VirtualBox uses only the first 190 446 (0x01be) bytes from the given MBR file.mpack wrote:The MBR contains a partition map which must correct describe the layout of the disk.
Last edited by fth0 on 10. Sep 2022, 15:41, edited 1 time in total.
-
- Site Moderator
- Posts: 39134
- Joined: 4. Sep 2008, 17:09
- Primary OS: MS Windows 10
- VBox Version: PUEL
- Guest OSses: Mostly XP
Re: vmdk parmeter "-mbr"
Are you referring to the VirtualBox feature? Are you saying that VirtualBox constructs a new partition map and ignores the one in the MBR?fth0 wrote: Not in this special case: VirtualBox uses only the first 190 (0x01be) bytes from the given MBR file.
Come to think of it, the CloneVDI feature is similar. CloneVDI can treat partition images as complete disks, that's where the above MBR source came from. CloneVDI too synthesizes the partition map, hence why the one in the source is just a stub. Only the boot code is honoured. But the partition map offset is at 446, not 190. 0x1BE is correct tho.
Oh well, in that case the mbr.bin file I provided above may be directly usable in a classically booted VM (not GPT, not grub).
-
- Volunteer
- Posts: 5677
- Joined: 14. Feb 2019, 03:06
- Primary OS: Mac OS X other
- VBox Version: PUEL
- Guest OSses: Linux, Windows 10, ...
- Location: Germany
Re: vmdk parmeter "-mbr"
Yes, no and yes. VirtualBox uses the partition map of the physical disk as follows:mpack wrote:Are you referring to the VirtualBox feature? Are you saying that VirtualBox constructs a new partition map and ignores the one in the MBR?fth0 wrote: Not in this special case: VirtualBox uses only the first 190 (0x01be) bytes from the given MBR file.
As documented in 9.7.1.2. Access to Individual Physical Hard Disk Partitions, VirtualBox lets the guest "see all partitions that exist on the physical disk", but "access will be filtered in that reading from partitions for which no access is allowed the partitions will only yield zeroes, and all writes to them are ignored. [...] In some configurations it may be necessary to change the MBR code of the created image. [...] For this purpose the -mbr option is provided. It specifies a file name from which to take the MBR code. The partition table is not modified at all, so a MBR file from a system with totally different partitioning can be used."
Ok, you got me. (I know "0xC0" by heart from the well-known local IPv4 addresses and my brain ignored the "1".)mpack wrote:But the partition map offset is at 446, not 190. 0x1BE is correct tho.
-
- Site Moderator
- Posts: 39134
- Joined: 4. Sep 2008, 17:09
- Primary OS: MS Windows 10
- VBox Version: PUEL
- Guest OSses: Mostly XP
Re: vmdk parmeter "-mbr"
You (and that paragraph from the manual), seems to be citing the case when an MBR is not provided, which is not the case raised by the OP.fth0 wrote: As documented in 9.7.1.2. Access to Individual Physical Hard Disk Partitions, VirtualBox lets the guest "see all partitions that exist on the physical disk"
I would cite this other paragraph in the same user manual section.
So it appears I was right the first time: VirtualBox honors the partition table in the MBR.User manual section 9.7.1.2 wrote: In some configurations it may be necessary to change the MBR code of the created image. For example, to replace the Linux boot loader that is used on the host by another boot loader. This enables for example the guest to boot directly to Windows, while the host boots Linux from the "same" disk. For this purpose the -mbr option is provided. It specifies a file name from which to take the MBR code. The partition table is not modified at all, so a MBR file from a system with totally different partitioning can be used.
-
- Volunteer
- Posts: 5677
- Joined: 14. Feb 2019, 03:06
- Primary OS: Mac OS X other
- VBox Version: PUEL
- Guest OSses: Linux, Windows 10, ...
- Location: Germany
Re: vmdk parmeter "-mbr"
I cited the same sentences (leaving out the example part), but it looks like I interpret them differently:
For example, you can take an MBR from any Windows XP installation with any partition table (or none at all) and provide it to VirtualBox, because the partition table within that MBR file is ignored. If you're not convinced, have a look into the VirtualBox source code, file src/VBox/Frontends/VBoxManage/VBoxInternalManage.cpp, function CmdCreateRawVMDK() and follow the variable pszMBRFilename.
But perhaps I'm misunderstanding what you mean:
VirtualBox takes the MBR code, not the partition table.User manual section 9.7.1.2 wrote:It specifies a file name from which to take the MBR code.
Here the partition table of the physical disk is meant.User manual section 9.7.1.2 wrote:The partition table is not modified at all, [...]
Used as a parameter for the -mbr option.User manual section 9.7.1.2 wrote:[...] so a MBR file from a system with totally different partitioning can be used
For example, you can take an MBR from any Windows XP installation with any partition table (or none at all) and provide it to VirtualBox, because the partition table within that MBR file is ignored. If you're not convinced, have a look into the VirtualBox source code, file src/VBox/Frontends/VBoxManage/VBoxInternalManage.cpp, function CmdCreateRawVMDK() and follow the variable pszMBRFilename.
But perhaps I'm misunderstanding what you mean:
Which MBR are you talking about. The one in the given MBR file or the one of the physical disk?mpack wrote:VirtualBox honors the partition table in the MBR.
Last edited by fth0 on 10. Sep 2022, 19:10, edited 1 time in total.
-
- Site Moderator
- Posts: 39134
- Joined: 4. Sep 2008, 17:09
- Primary OS: MS Windows 10
- VBox Version: PUEL
- Guest OSses: Mostly XP
Re: vmdk parmeter "-mbr"
The one in the MBR file, that being the whole point of the exercise!fth0 wrote: Which MBR are you talking about. The one in the given MBR file or the one of the physical disk?
-
- Volunteer
- Posts: 5677
- Joined: 14. Feb 2019, 03:06
- Primary OS: Mac OS X other
- VBox Version: PUEL
- Guest OSses: Linux, Windows 10, ...
- Location: Germany
Re: vmdk parmeter "-mbr"
Ok, I think I understand both your and my reasoning, and both can be possible interpretations of the documentation. Finally, the VirtualBox source code decides what really happens.
Re: vmdk parmeter "-mbr"
Actually after reading other info (I had read vbox manual before posting.) I realized that since my disk is UEFI/GPT the -mbr parm probably has nothing to do with my reason for asking. IIRC UEFI in my PC's microcode doesn't use the mbr code installed IE (Core grub code below 2048).
-
- Volunteer
- Posts: 5677
- Joined: 14. Feb 2019, 03:06
- Primary OS: Mac OS X other
- VBox Version: PUEL
- Guest OSses: Linux, Windows 10, ...
- Location: Germany
Re: vmdk parmeter "-mbr"
AFAICS, the VirtualBox (U)EFI BIOS can only boot from (virtual or raw) GPT disks, and the VirtualBox legacy BIOS can only boot from MBR disks. If you want to use raw disk access for the boot partition(s), you should use the (U)EFI BIOS for your VMs.
Re: vmdk parmeter "-mbr"
I do set the EFI flag in virtualbox settings for each VM client I set up. It works fine. My original question was in regard to the -mbr parm when creating the vmdk file. Clearly the -mbr parm would not apply to a uefi boot process so my question should be withdrawn. Sorry for the miss leading question, though it did spark a good discussion regarding mbr.
-
- Volunteer
- Posts: 5677
- Joined: 14. Feb 2019, 03:06
- Primary OS: Mac OS X other
- VBox Version: PUEL
- Guest OSses: Linux, Windows 10, ...
- Location: Germany
Re: vmdk parmeter "-mbr"
Thanks for reporting back!
-
- Site Moderator
- Posts: 39134
- Joined: 4. Sep 2008, 17:09
- Primary OS: MS Windows 10
- VBox Version: PUEL
- Guest OSses: Mostly XP
Re: vmdk parmeter "-mbr"
Technically true, but someone who understands VMDK and GPT could do something equivalent - which is what I assume is going on in the background with the -mbr case.lpmanjaro wrote:Clearly the -mbr parm would not apply to a uefi boot process
To clarify: a VMDK has a descriptor which lists one or more "extents" which are appended together virtually to make a complete disk image. Each extent can be the contents of a file, or direct access to a block device, or zero filled space for padding. Someone who knew what he was doing could provide the primary and backup GPT partition tables and potentially the EFI system (boot manager) partition too, to boot a host partition in isolation from the host OS.