Skip to content

Latest commit

 

History

History
54 lines (33 loc) · 3.08 KB

README.md

File metadata and controls

54 lines (33 loc) · 3.08 KB

The 512-byte VM (Cloud native!)

GitHub release (latest by date) GitHub license GitHub branch checks state

This is a virtual machine that fits in 512 bytes (the boot sector).

Why?!

Because when you test integration with virtualization systems such as oVirt (hint, hint), you often need a VM image to upload. If you have to run dozens or hundreds of test cases you don't want to be uploading GB-sized images.

Can I use it?

Sure! Go grab it from the releases section! We have raw, QCOW2, VDI, VMDK, VHD and ISO images.

How?

Very much simplified, the first thing that loads when a computer, or a VM starts is the BIOS (or UEFI in newer systems). The BIOS provides some very basic functions, such as being able to print to the screen conveniently.

At any rate, the BIOS loads the boot loader from the MBR on the disk (first 512 bytes). UEFI is much smarter, but let's not deal with that right now. The MBR is a set of purely machine instructions that will be run pretty much as it is. This is different from how operating systems load binaries such as EXE files or ELF binaries, since those contain a header and a bunch of other information. The only requirement for the boot sector code is that it must end in 0xAA55 and the BIOS will happily execute it.

So, we compile 512-byte-vm.asm using the NASM assembler and that's it, that's our disk image:

nasm -o 512-byte-vm.raw 512-byte-vm.asm

Beautiful, raw data, right on the disk. You can run it directly using qemu:

qemu-system-x86_64 -drive file=512-byte-vm.raw,format=raw

Alternatively, you can convert it to various formats using qemu-img:

qemu-img convert -c -f raw -O qcow2 512-byte-vm.raw 512-byte-vm.qcow2
qemu-img convert -f raw -O vmdk 512-byte-vm.raw 512-byte-vm.vmdk

Alternatively, you could also use the build script.

Where can I learn more?

We didn't come up with this on our own. Here are a few resources that should get you started:

  • The OSDev Wiki contains a wealth of material in case you want to write your own OS. The Roll Your Own Bootloader section is especially useful if you want to do something similar.
  • The Interrupt Jump Table contains an index of several (older) interrupts that can be used to interact with hardware.
  • This page contains the x86 CPU opcodes that the ASM instructions compile to.

Can I contribute?

Sure! Here's the detailed guide on how to do that!