Running Linux from a vmdk virtual disk on real hardware and VirtualBox

There was a need to provide Linux operation both on a virtual machine (VirtualBox) and on real hardware. After a lot of searching and trying to run Linux from a virtual disk in VHD format, like Windows, which are either too complicated or not working, I came up with a fairly simple way to do it. True, not from disks in VHD format, but from a disk partition image in VMDK format.







Linux can be booted from a partition image. Now we need to make sure that we have both a disk image that VirtualBox understands and a partition image that grub can load.







The following is a description of how this can be done quickly and without unnecessary headaches.







Everything else is done from Windows.







Create a new fixed size disk in vmdk format:







VBoxManage createmedium disk --format VMDK --variant Fixed --filename test1.vmdk --size 10000
      
      





We have the files created:







  • test1.vmdk



    - disk descriptor, text file
  • test1-flat.vmdk



    - a file with a disk image


Now you need to add one more piece of 1M size to the beginning of the disk.







Create a 1M file test1-boot.vmdk:







fsutil file createnew test1-boot.vmdk 1048576
      
      





In test1.vmdk, change createType="custom"



to createType="monolithicFlat"



. This will mean that the disk consists of several files.







Add test1-boot.vmdk



in test1.vmdk



, first. After adding it test.vmdk



should look something like this:







...
createType="monolithicFlat"

RW 2048 FLAT "test1-boot.vmdk" 0
RW 20480000 FLAT "test1-flat.vmdk" 0
...
      
      





where 2048



is 2048 * 512 = 1048576 bytes (1M) for this part of the disk.







Linux, test1.vmdk



ubuntu/kubuntu/xubunu. , 18.04 ( ) 21.04, .







: 1M. .







/dev/sda, /dev/sda1. .







, , VirtualBox, , Linux .







Linux . .







( usb-) Ventoy (https://www.ventoy.net/).







ventoy\ventoy_grub.cfg



:







menuentry 'boot linux from vmdk part' { 
    set imgfile="/mydisks/test1-flat.vmdk"
    set d_label="MYDISK"
    search --set=root --label ${d_label} 
    loopback loop0 ${imgfile}
    set root=(loop0)
    linux /boot/vmlinuz root=/dev/disk/by-label/${d_label} loop=${imgfile} rw nosplash
    initrd /boot/initrd.img
}
      
      





:







  • imgfile="/mydisks/test1-flat.vmdk"



    β€”
  • d_label="MYDISK"



    β€” , test1-flat.vmdk





, F6 , "boot linux from vmdk part". Linux.







OS, VirtualBox Linux .







, , Windows Linux VirtualBox, … .







It should be borne in mind that if updates affect grub, then they will not be completed correctly in a system running on real hardware, because there is no partition with a bootloader. However, this does not interfere with normal operation. And such updates can be applied through VirtualBox.







By the way, the image test1-flat.vmdk



can be copied to a Ventoy flash drive, and run from it, it also works.







And lastly. Ventoy can boot linux from vhd, but requires additional manipulations with installed Linux ( https://www.ventoy.net/en/plugin_vtoyboot.html ). But, unfortunately, for me these manipulations led to the fact that the download works either on real hardware or in VirtualBox. And here and there with one image does not work.








All Articles