lima-vm / lima

Linux virtual machines, with a focus on running containers
https://lima-vm.io/
Apache License 2.0
15.49k stars 608 forks source link

VirtualBox driver, for legacy compatibility and portability #1287

Open afbjorklund opened 1 year ago

afbjorklund commented 1 year ago

Description

Once upon a time, there was something called Docker Machine and it was running on VirtualBox.

It did have some other drivers, like qemu, but the virtualbox driver was the portable and default...

Now that Lima has a driver framework, it could be useful to have a "vbox" driver next to the "qemu" ?

It does support features like host networking and shared folders, that QEMU is still struggling with.


Pros: might run on more platforms, such as legacy releases or other operating systems

Cons: only supports Intel images, no support for COW images (resulting in larger files)

But the biggest advantage is having another driver that also works on non-Mac hosts.

And it can help to improve the driver API, if testing with more different implementations ?

afbjorklund commented 1 year ago

Here is the initial PR:

NAME    STATUS     SSH                VMTYPE    ARCH      CPUS    MEMORY    DISK      DIR
vbox    Running    127.0.0.1:36191    vbox      x86_64    2       2GiB      100GiB    ~/.lima/vbox

The host networking and shared folders are not yet implemented, and might require loading a kernel module.

afbjorklund commented 1 year ago

Regarding ARM Macs (M1), there is a beta version out for VirtualBox 7.0 but it only runs Intel images:

https://forums.virtualbox.org/viewtopic.php?f=8&t=107344

So it is not anticipated that this driver will ever be useful for newer Macs, fortunately those have Vz ?

afbjorklund commented 1 year ago

We need a "delete" callback in Lima, in order to clean up the VirtualBox registry after stopping the VM

    CreateDisk() error

    Start(_ context.Context) (chan error, error)

    Stop(_ context.Context) error

    Register(_ context.Context) error

    Unregister(_ context.Context) error

It will be part of pkg/stop, like how "CreateDisk" is part of pkg/start. Maybe it should be called Unregister ?

afbjorklund commented 1 year ago

The additional disk was hardcoded to /dev/vdb, so that broke when it was using /dev/sdb (SATA)

Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 sectors
Disk model: VBOX HARDDISK   
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 089874F4-B779-47D7-93FE-9363737526EB

Device      Start       End   Sectors  Size Type
/dev/sda1  227328 209715166 209487839 99.9G Linux filesystem
/dev/sda14   2048     10239      8192    4M BIOS boot
/dev/sda15  10240    227327    217088  106M EFI System

Partition table entries are not in disk order.

Disk /dev/sdb: 50 GiB, 53687091200 bytes, 104857600 sectors
Disk model: VBOX HARDDISK   
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 3698C6D1-6EFE-9D42-A692-06339D7F2FC9

Device     Start       End   Sectors Size Type
/dev/sdb1   2048 104857566 104855519  50G Linux filesystem

Added a hardcoded parameter for it, but it should probably be talking to the driver...

afbjorklund commented 9 months ago

https://cyberus-technology.de/articles/vbox-kvm-public-release