> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/stratosphere-ve/ozone/llms.txt
> Use this file to discover all available pages before exploring further.

# Launch a QEMU Virtual Machine with Ozone's qemu.Start()

> The qemu.Start() function prompts for a VM name, loads its config via vmparser, and launches qemu-system-x86_64 with q35 machine type and QMP over TCP.

`qemu.Start()` is Ozone's entry point for launching a virtual machine. It interactively prompts for a VM name, reads the corresponding JSON configuration through `vmparser.VMParser`, and then spawns a `qemu-system-x86_64` process with a fixed set of hardware flags — including Q35 machine type, a QCow2 disk image, a Debian ISO as the optical drive, and a QMP control socket bound to `127.0.0.1:4444`.

## Usage

```go theme={null}
import "github.com/stratosphere-ve/ozone/qemu"

func main() {
    qemu.Start()
}
```

## QEMU Flags

When `Start()` builds the `qemu-system-x86_64` command it passes the following flags in order:

| Flag       | Value                              | Purpose                                       |
| ---------- | ---------------------------------- | --------------------------------------------- |
| `-machine` | `q35`                              | Use the Q35 chipset (PCIe, AHCI, modern BIOS) |
| `-m`       | `""` (empty string)                | Amount of RAM to allocate to the guest        |
| `-smp`     | `4`                                | Expose 4 virtual CPUs to the guest            |
| `-drive`   | `file=myvm.qcow2,format=qcow2`     | Attach the primary disk in QCow2 format       |
| `-cdrom`   | `debian.iso`                       | Mount `debian.iso` as the optical drive       |
| `-boot`    | `d`                                | Set the boot order to CD-ROM first            |
| `-qmp`     | `tcp:127.0.0.1:4444,server,nowait` | Expose the QEMU Machine Protocol over TCP     |

<Note>
  The `-m` flag is sourced from the package-level variable `memsize`, which is initialized to an empty string (`""`). This means memory size is **not yet wired to the VM configuration** loaded by `vmparser`. The VM config is read and printed, but its fields are not currently used to populate the QEMU command. Until `memsize` is set, QEMU will receive an empty value for `-m` and may fail to start.
</Note>

<Note>
  The QMP socket listens on `127.0.0.1:4444` for the lifetime of the VM process. You can connect any QMP-compatible client (e.g. `socat` or a custom Go client) to this address for machine introspection, query commands, and live control without stopping the guest. Note that `qemu.Stop()` does **not** use this socket — it operates independently.
</Note>

<Warning>
  `qemu-system-x86_64` must be installed on the host and available on the system `PATH`. On Debian/Ubuntu systems you can install it with `apt install qemu-system-x86`. If the binary is missing, `exec.Command` will return an error and `Start()` will print it and return without launching the VM.
</Warning>

## Startup Sequence

<Steps>
  <Step title="Prompt for VM name">
    `Start()` prints `"What VM would you like to start?"` to stdout and then calls `fmt.Scanln` to read a single token from stdin into the `vmname` variable. The function blocks here until the user presses Enter.
  </Step>

  <Step title="Load VM configuration">
    The name is passed to `vmparser.VMParser(vmname)`, which reads the JSON file for that VM and returns a populated config struct. If the file cannot be read or parsed, an error is printed and `Start()` returns immediately without launching QEMU. On success, the parsed config is printed via `fmt.Printf("VM info: %+v\n", vmInfo)` — however, the config fields are not yet used to build the QEMU command.
  </Step>

  <Step title="Build the QEMU command">
    `exec.Command` assembles the `qemu-system-x86_64` invocation with all flags listed in the table above. The `-m` value comes from the package-level `memsize` variable, which is currently an empty string and is not populated from the loaded VM config.
  </Step>

  <Step title="Execute and capture output">
    `cmd.Output()` runs the process and captures its stdout. Any execution error is printed via `fmt.Printf`. On success the captured output is printed to stdout.
  </Step>
</Steps>
