Help us shape the future of Go! Take the 2026 Go Developer Survey

vm

package
v1.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package vm builds the command lines of QEMU and virtiofsd for the aibox VM.

Index

Constants

View Source
const (
	GuestUID uint32 = 1000
	GuestGID uint32 = 1000
)

GuestUID and GuestGID are the user Claude Code runs as in the VM.

View Source
const ClipboardPort uint16 = 3132

ClipboardPort is the port on the loopback of the VM where xclip and wl-paste in the VM reach the clipboard of the host.

View Source
const GuestCID uint32 = 3

GuestCID is the vsock address of the VM. Every VM has the same one, because each has a vsock namespace of its own.

View Source
const RootCmdline = "root=/dev/vda rootfstype=ext4 ro console=hvc0 quiet"

RootCmdline boots the root disk read-only on the virtio console, whichever VMM boots the VM. The root stays read-only, as the VMM opened it: the init mounts an overlay for what it has to write.

Variables

This section is empty.

Functions

This section is empty.

Types

type Files

type Files struct {
	KVM        int
	Vhost      int
	Kernel     string
	Rootfs     int
	StateRead  int
	StateWrite int
	Console    int
	Shares     []int
}

Files are the numbers of the files QEMU was started with: the KVM and vhost-vsock devices, the root disk, the state disk opened read-only and once more read-write, the socket QEMU writes the console to, and one connection to virtiofsd per entry of Machine.Shares, in the same order. Kernel is a path, not a number, because the kernel loader of QEMU cannot take a descriptor. The state disk comes in both modes because QEMU opens a drive read-only first and asks the fdset for a read-write descriptor when the device attaches.

type Machine

type Machine struct {
	Kernel string
	// KernelDigest is the SHA-256 the kernel must have, or empty
	KernelDigest string
	Rootfs       string
	State        string
	MemoryMiB    int
	CPUs         int
	Shares       []Share
	Shell        bool
	Task         bool
	HyperV       bool
	ProxyPort    uint32
	TerminalPort uint32
	Loopback     []uint16
	Owner        *Owner
}

Machine is a VM that boots a kernel with a root disk and keeps its state on a second disk. Shell boots it into a shell instead of Claude Code, Task runs the task of the task share unattended. HyperV tells the guest it runs on Hyper-V, which shares the folders of the host over Plan 9 and has SCSI disks, instead of virtio-fs and virtio disks. ProxyPort and TerminalPort are the vsock ports of the proxy and the terminal session on the host, and 0 leaves the port off the kernel command line. Loopback are the ports on the loopback of the host the VM reaches through the proxy. Owner is the host user the VM user stands for in the shares, and nil leaves the ids as they are.

func (Machine) Cmdline

func (m Machine) Cmdline(start string) string

Cmdline is the kernel command line that starts with what the VMM needs and goes on with the words of the guest.

func (Machine) GuestWords

func (m Machine) GuestWords() []string

GuestWords are the words of the kernel command line that tell the guest its settings, the vsock ports of the host, the mounts of the host and the ports on the loopback of the host it may reach, whichever VMM boots it.

func (Machine) QEMUArgs

func (m Machine) QEMUArgs(files Files) []string

QEMUArgs returns the arguments for qemu-system-x86_64. QEMU gets every file through the numbers in files, so that it opens no path of the host.

type Owner

type Owner struct {
	UID uint32
	GID uint32
}

Owner is a user on the host. In the shares, the VM user sees this user's files as its own. Files of other host users appear as nobody.

type Share

type Share struct {
	Tag      string
	Dir      string
	Socket   string
	Guest    string
	ReadOnly bool
}

Share is a host folder that virtiofsd serves to the VM. The guest mounts it by its tag. Guest is set for a share beyond the project and the home: the path the guest mounts it on, read-only. ReadOnly makes a share read-only that the guest knows where to mount by its tag.

func (Share) IsReadOnly added in v1.2.0

func (s Share) IsReadOnly() bool

IsReadOnly tells whether the VM may only read the share.

func (Share) VirtiofsdArgs

func (s Share) VirtiofsdArgs(owner *Owner) []string

VirtiofsdArgs returns the arguments for virtiofsd that serve the share to the VM user standing for the owner.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL