vm

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: BSD-3-Clause Imports: 12 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package vm provides an exec-like interface to VMs running cpud. It is designed to make running commands in a vm as easy as using exec.

For purposes of convenience, this package provides, via embed, a set of kernels and initramfs, for several architectures. Currently, it provides Linux kernels and initramfs for amd64, arm, arm64, and riscv64.

The kernels are minimal, hence small; but enable enough options to run cpud and u-root programs. The initramfs only contain the cpud and dhclient commands, and are also small.

The package asssumes that qemu for a target architecture is available on the system.

Users can not yet provide their own kernel and initramfs, though that is planned.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Uroot

func Uroot(d, GOOS, GOARCH string, opts ...string) (string, error)

Uroot builds a uroot cpio into the a directory. It returns the full path of the file, or an error.

Types

type Image

type Image struct {
	Kernel    []byte
	InitRAMFS []byte
	Cmd       []string
	Env       []string

	GOOS   string
	GOARCH string
	Opts   []string
	// contains filtered or unexported fields
}

Image defines an image, including []byte for a kernel and initramfs; a []string for the Cmd and its args; and its environment; and a directory in which to run.

func New

func New(goos, arch string) (*Image, error)

New creates an Image, using the kernel and arch to select the Image. It will return an error if there is a problem uncompressing the kernel and initramfs.

func (*Image) CPUCommand

func (i *Image) CPUCommand(arg string, args ...string) (*client.Cmd, error)

CPUCommand runs a command in a guest running cpud. It is similar to exec.Command, in that it accepts an arg and a set of optional args. It differs in that it can return an error. If there are no errors, it returns a client.Cmd. The returned client.Cmd can be called with CombinedOutput, to make it easier to scan output from a command for error messages.

func (*Image) CommandContext

func (image *Image) CommandContext(ctx context.Context, d string, extra ...string) (*exec.Cmd, error)

CommandContext starts qemu, given a context, directory in which to run the command. The variadic arguments are a set of cpios which will be merged into Image.InitRAMFS. A typical use of the extra arguments will be to extend the initramfs; they are usually not needed.

func (*Image) StartVM

func (*Image) StartVM(c *exec.Cmd) error

StartVM is used to start a VM (or in fact any exec.Cmd). Once cmd.Start is called, StartVM delays for one second. This time has been experimentally determined as the minimum required for the guest network to be ready.

func (*Image) String

func (i *Image) String() string

func (*Image) Uroot

func (i *Image) Uroot(d string) (string, error)

Uroot builds a uroot cpio for an Image

Jump to

Keyboard shortcuts

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