Disks

Attach ext4 images, http(s) images and persistent disks.

import { createImageFromKwsparse, createKernel, bundledBoot, openDisk } from "unkernel/node";

const vm = await createKernel({
  distro,
  disks: [await openDisk("data.img")], // the data disk, or any ext4 image or https:// URL
});

#The data disk

A disk labelled kwdata is the guest's persistent data disk: the root file system is an overlay of the read-only distro image under your changes, and with a data disk attached each distro keeps its changes in /data/distros/<name>/ on it.

createImageFromKwsparse(file, template) makes a new data disk from the template the kernel carries (bundledBoot(module).datadisk).

#In the browser

  • openHttpDisk(url) reads an image over http(s) with range requests and keeps your writes in IndexedDB.
  • openDataDisk() gives you the persistent data disk that unkernel.dev uses.

#Your own disks

Anything that implements BlockDevice works too, and a disk of your own can be the root:

const vm = await createKernel({
  disks: [myDisk],
  cmdline: "console=hvc0 root=/dev/wda rw",
  initrd: null,
});