m/installer/install: move from osbase/build/mkimage/osimage

Move the package osbase/build/mkimage/osimage to
metropolis/installer/install. The package contains "metropolis" in
various strings, so it fits better in //metropolis than in //osbase.
The parent package mkimage no longer exists.

The rename also removes the name clash with osbase/oci/osimage.

Change-Id: Ia228ab94c937f4c7a5b6eb1fcc77993a594d64b6
Reviewed-on: https://review.monogon.dev/c/monogon/+/4296
Tested-by: Jenkins CI
Reviewed-by: Tim Windelschmidt <tim@monogon.tech>
diff --git a/metropolis/cli/metroctl/core/BUILD.bazel b/metropolis/cli/metroctl/core/BUILD.bazel
index d785fad..e9c2117 100644
--- a/metropolis/cli/metroctl/core/BUILD.bazel
+++ b/metropolis/cli/metroctl/core/BUILD.bazel
@@ -13,13 +13,13 @@
     visibility = ["//visibility:public"],
     deps = [
         "//go/logging",
+        "//metropolis/installer/install",
         "//metropolis/node",
         "//metropolis/node/core/curator/proto/api",
         "//metropolis/node/core/rpc",
         "//metropolis/node/core/rpc/resolver",
         "//metropolis/proto/api",
         "//osbase/blockdev",
-        "//osbase/build/mkimage/osimage",
         "//osbase/fat32",
         "//osbase/gpt",
         "//osbase/oci",
diff --git a/metropolis/cli/metroctl/core/install.go b/metropolis/cli/metroctl/core/install.go
index 0927ba1..31fe4a0 100644
--- a/metropolis/cli/metroctl/core/install.go
+++ b/metropolis/cli/metroctl/core/install.go
@@ -11,13 +11,13 @@
 
 	"google.golang.org/protobuf/proto"
 
+	"source.monogon.dev/metropolis/installer/install"
 	"source.monogon.dev/metropolis/proto/api"
 	"source.monogon.dev/osbase/blockdev"
-	"source.monogon.dev/osbase/build/mkimage/osimage"
 	"source.monogon.dev/osbase/fat32"
 	"source.monogon.dev/osbase/gpt"
 	"source.monogon.dev/osbase/oci"
-	ociosimage "source.monogon.dev/osbase/oci/osimage"
+	"source.monogon.dev/osbase/oci/osimage"
 	"source.monogon.dev/osbase/structfs"
 )
 
@@ -43,11 +43,11 @@
 		return errors.New("installer is mandatory")
 	}
 
-	osImage, err := ociosimage.Read(args.Image)
+	osImage, err := osimage.Read(args.Image)
 	if err != nil {
 		return fmt.Errorf("failed to read OS image: %w", err)
 	}
-	bootPath, err := osimage.EFIBootPath(osImage.Config.ProductInfo.Architecture())
+	bootPath, err := install.EFIBootPath(osImage.Config.ProductInfo.Architecture())
 	if err != nil {
 		return err
 	}
diff --git a/metropolis/cli/takeover/BUILD.bazel b/metropolis/cli/takeover/BUILD.bazel
index 1b8f182..8e51836 100644
--- a/metropolis/cli/takeover/BUILD.bazel
+++ b/metropolis/cli/takeover/BUILD.bazel
@@ -30,12 +30,12 @@
     visibility = ["//visibility:private"],
     deps = [
         "//go/logging",
+        "//metropolis/installer/install",
         "//metropolis/node/core/devmgr",
         "//metropolis/proto/api",
         "//osbase/blockdev",
         "//osbase/bootparam",
         "//osbase/bringup",
-        "//osbase/build/mkimage/osimage",
         "//osbase/efivarfs",
         "//osbase/kexec",
         "//osbase/net/dump",
diff --git a/metropolis/cli/takeover/install.go b/metropolis/cli/takeover/install.go
index 37068ed..4d42269 100644
--- a/metropolis/cli/takeover/install.go
+++ b/metropolis/cli/takeover/install.go
@@ -10,11 +10,11 @@
 	"path/filepath"
 
 	"source.monogon.dev/go/logging"
+	"source.monogon.dev/metropolis/installer/install"
 	"source.monogon.dev/osbase/blockdev"
-	"source.monogon.dev/osbase/build/mkimage/osimage"
 	"source.monogon.dev/osbase/efivarfs"
 	"source.monogon.dev/osbase/oci"
-	ociosimage "source.monogon.dev/osbase/oci/osimage"
+	"source.monogon.dev/osbase/oci/osimage"
 	"source.monogon.dev/osbase/structfs"
 )
 
@@ -47,7 +47,7 @@
 		return err
 	}
 
-	be, err := osimage.Write(installParams)
+	be, err := install.Write(installParams)
 	if err != nil {
 		return fmt.Errorf("failed to apply installation: %w", err)
 	}
@@ -62,13 +62,13 @@
 	return nil
 }
 
-func setupOSImageParams(image *oci.Image, metropolisSpecRaw []byte, installTarget string) (*osimage.Params, error) {
+func setupOSImageParams(image *oci.Image, metropolisSpecRaw []byte, installTarget string) (*install.Params, error) {
 	rootDev, err := blockdev.Open(filepath.Join("/dev", installTarget))
 	if err != nil {
 		return nil, fmt.Errorf("failed to open root device: %w", err)
 	}
 
-	osImage, err := ociosimage.Read(image)
+	osImage, err := osimage.Read(image)
 	if err != nil {
 		return nil, fmt.Errorf("failed to read OS image: %w", err)
 	}
@@ -82,8 +82,8 @@
 		return nil, fmt.Errorf("cannot open system image in OS image: %w", err)
 	}
 
-	return &osimage.Params{
-		PartitionSize: osimage.PartitionSizeInfo{
+	return &install.Params{
+		PartitionSize: install.PartitionSizeInfo{
 			ESP:    384,
 			System: 4096,
 			Data:   128,
diff --git a/metropolis/cli/takeover/takeover.go b/metropolis/cli/takeover/takeover.go
index cd537a9..805a06d 100644
--- a/metropolis/cli/takeover/takeover.go
+++ b/metropolis/cli/takeover/takeover.go
@@ -18,8 +18,8 @@
 	apb "source.monogon.dev/metropolis/proto/api"
 	netapi "source.monogon.dev/osbase/net/proto"
 
+	"source.monogon.dev/metropolis/installer/install"
 	"source.monogon.dev/osbase/bootparam"
-	"source.monogon.dev/osbase/build/mkimage/osimage"
 	"source.monogon.dev/osbase/kexec"
 	netdump "source.monogon.dev/osbase/net/dump"
 	"source.monogon.dev/osbase/oci"
@@ -136,7 +136,7 @@
 	}
 
 	// Validate that this installation will not fail because of disk issues
-	if _, err := osimage.Plan(oParams); err != nil {
+	if _, err := install.Plan(oParams); err != nil {
 		return nil, fmt.Errorf("failed to plan installation: %w", err)
 	}
 
diff --git a/metropolis/installer/BUILD.bazel b/metropolis/installer/BUILD.bazel
index 29eb04c..72fee1a 100644
--- a/metropolis/installer/BUILD.bazel
+++ b/metropolis/installer/BUILD.bazel
@@ -13,9 +13,9 @@
     importpath = "source.monogon.dev/metropolis/installer",
     visibility = ["//visibility:private"],
     deps = [
+        "//metropolis/installer/install",
         "//osbase/blockdev",
         "//osbase/bringup",
-        "//osbase/build/mkimage/osimage",
         "//osbase/efivarfs",
         "//osbase/oci",
         "//osbase/oci/osimage",
diff --git a/metropolis/installer/install/BUILD.bazel b/metropolis/installer/install/BUILD.bazel
new file mode 100644
index 0000000..1532198
--- /dev/null
+++ b/metropolis/installer/install/BUILD.bazel
@@ -0,0 +1,16 @@
+load("@io_bazel_rules_go//go:def.bzl", "go_library")
+
+go_library(
+    name = "install",
+    srcs = ["install.go"],
+    importpath = "source.monogon.dev/metropolis/installer/install",
+    visibility = ["//visibility:public"],
+    deps = [
+        "//osbase/blockdev",
+        "//osbase/efivarfs",
+        "//osbase/fat32",
+        "//osbase/gpt",
+        "//osbase/structfs",
+        "@com_github_google_uuid//:uuid",
+    ],
+)
diff --git a/metropolis/installer/install/install.go b/metropolis/installer/install/install.go
new file mode 100644
index 0000000..a2b9ff8
--- /dev/null
+++ b/metropolis/installer/install/install.go
@@ -0,0 +1,252 @@
+// Copyright The Monogon Project Authors.
+// SPDX-License-Identifier: Apache-2.0
+
+// Package install allows planning and executing the installation of Metropolis
+// to a block device.
+package install
+
+import (
+	"fmt"
+	"io"
+
+	"github.com/google/uuid"
+
+	"source.monogon.dev/osbase/blockdev"
+	"source.monogon.dev/osbase/efivarfs"
+	"source.monogon.dev/osbase/fat32"
+	"source.monogon.dev/osbase/gpt"
+	"source.monogon.dev/osbase/structfs"
+)
+
+var (
+	SystemAType = uuid.MustParse("ee96054b-f6d0-4267-aaaa-724b2afea74c")
+	SystemBType = uuid.MustParse("ee96054b-f6d0-4267-bbbb-724b2afea74c")
+
+	DataType = uuid.MustParse("9eeec464-6885-414a-b278-4305c51f7966")
+)
+
+const (
+	SystemALabel = "METROPOLIS-SYSTEM-A"
+	SystemBLabel = "METROPOLIS-SYSTEM-B"
+	DataLabel    = "METROPOLIS-NODE-DATA"
+	ESPLabel     = "ESP"
+
+	EFIBootAPath   = "EFI/metropolis/boot-a.efi"
+	EFIBootBPath   = "EFI/metropolis/boot-b.efi"
+	nodeParamsPath = "metropolis/parameters.pb"
+)
+
+var EFIBootName = map[string]string{
+	"x86_64":  "BOOTx64.EFI",
+	"aarch64": "BOOTAA64.EFI",
+}
+
+// EFIBootPath returns the default file path according to the UEFI Specification
+// v2.11 Section 3.5.1.1. This file is booted by any compliant UEFI firmware in
+// absence of another bootable boot entry.
+func EFIBootPath(architecture string) (string, error) {
+	bootName, ok := EFIBootName[architecture]
+	if !ok {
+		return "", fmt.Errorf("unsupported architecture %q", architecture)
+	}
+	return "EFI/BOOT/" + bootName, nil
+}
+
+// PartitionSizeInfo contains parameters used during partition table
+// initialization and, in case of image files, space allocation.
+type PartitionSizeInfo struct {
+	// Size of the EFI System Partition (ESP), in mebibytes. The size must
+	// not be zero.
+	ESP int64
+	// Size of the Metropolis system partition, in mebibytes. The partition
+	// won't be created if the size is zero.
+	System int64
+	// Size of the Metropolis data partition, in mebibytes. The partition
+	// won't be created if the size is zero. If the image is output to a
+	// block device, the partition will be extended to fill the remaining
+	// space.
+	Data int64
+}
+
+// Params contains parameters used by Plan or Write to install Metropolis OS.
+type Params struct {
+	// Output is the block device to which the OS is installed.
+	Output blockdev.BlockDev
+	// Architecture is the CPU architecture of the OS image.
+	Architecture string
+	// ABLoader provides the A/B loader which then loads the EFI loader for the
+	// correct slot.
+	ABLoader structfs.Blob
+	// EFIPayload provides contents of the EFI payload file. It must not be
+	// nil. This gets put into boot slot A.
+	EFIPayload structfs.Blob
+	// SystemImage provides contents of the Metropolis system partition.
+	// If nil, no contents will be copied into the partition.
+	SystemImage structfs.Blob
+	// NodeParameters provides contents of the node parameters file. If nil,
+	// the node parameters file won't be created in the target ESP
+	// filesystem.
+	NodeParameters structfs.Blob
+	// DiskGUID is a unique identifier of the image and a part of Table
+	// header. It's optional and can be left blank if the identifier is
+	// to be randomly generated. Setting it to a predetermined value can
+	// help in implementing reproducible builds.
+	DiskGUID uuid.UUID
+	// PartitionSize specifies a size for the ESP, Metropolis System and
+	// Metropolis data partition.
+	PartitionSize PartitionSizeInfo
+	// BIOSBootCode provides the optional contents for the protective MBR
+	// block which gets executed by legacy BIOS boot.
+	BIOSBootCode []byte
+}
+
+type plan struct {
+	*Params
+	efiBootPath      string
+	efiRoot          structfs.Tree
+	tbl              *gpt.Table
+	efiPartition     *gpt.Partition
+	systemPartitionA *gpt.Partition
+	systemPartitionB *gpt.Partition
+	dataPartition    *gpt.Partition
+}
+
+// Apply actually writes the planned installation to the blockdevice.
+func (i *plan) Apply() (*efivarfs.LoadOption, error) {
+	// Discard the entire device, we're going to write new data over it.
+	// Ignore errors, this is only advisory.
+	i.Output.Discard(0, i.Output.BlockCount()*i.Output.BlockSize())
+
+	if err := fat32.WriteFS(blockdev.NewRWS(i.efiPartition), i.efiRoot, fat32.Options{
+		BlockSize:  uint16(i.efiPartition.BlockSize()),
+		BlockCount: uint32(i.efiPartition.BlockCount()),
+		Label:      "MNGN_BOOT",
+	}); err != nil {
+		return nil, fmt.Errorf("failed to write FAT32: %w", err)
+	}
+
+	systemImage, err := i.SystemImage.Open()
+	if err != nil {
+		return nil, fmt.Errorf("failed to open system image: %w", err)
+	}
+	if _, err := io.CopyN(blockdev.NewRWS(i.systemPartitionA), systemImage, i.SystemImage.Size()); err != nil {
+		systemImage.Close()
+		return nil, fmt.Errorf("failed to write system partition A: %w", err)
+	}
+	systemImage.Close()
+
+	if err := i.tbl.Write(); err != nil {
+		return nil, fmt.Errorf("failed to write Table: %w", err)
+	}
+
+	// Build an EFI boot entry pointing to the image's ESP.
+	return &efivarfs.LoadOption{
+		Description: "Metropolis",
+		FilePath: efivarfs.DevicePath{
+			&efivarfs.HardDrivePath{
+				PartitionNumber:     1,
+				PartitionStartBlock: i.efiPartition.FirstBlock,
+				PartitionSizeBlocks: i.efiPartition.SizeBlocks(),
+				PartitionMatch: efivarfs.PartitionGPT{
+					PartitionUUID: i.efiPartition.ID,
+				},
+			},
+			efivarfs.FilePath("/" + i.efiBootPath),
+		},
+	}, nil
+}
+
+// Plan allows to prepare an installation without modifying any data on the
+// system. To apply the planned installation, call Apply on the returned plan.
+func Plan(p *Params) (*plan, error) {
+	params := &plan{Params: p}
+
+	var err error
+	params.tbl, err = gpt.New(params.Output)
+	if err != nil {
+		return nil, fmt.Errorf("invalid block device: %w", err)
+	}
+
+	params.tbl.ID = params.DiskGUID
+	params.tbl.BootCode = p.BIOSBootCode
+	params.efiPartition = &gpt.Partition{
+		Type: gpt.PartitionTypeEFISystem,
+		Name: ESPLabel,
+	}
+
+	if err := params.tbl.AddPartition(params.efiPartition, params.PartitionSize.ESP*Mi); err != nil {
+		return nil, fmt.Errorf("failed to allocate ESP: %w", err)
+	}
+
+	if err := params.efiRoot.PlaceFile(EFIBootAPath, params.EFIPayload); err != nil {
+		return nil, err
+	}
+	// Place the A/B loader at the EFI bootloader autodiscovery path.
+	params.efiBootPath, err = EFIBootPath(p.Architecture)
+	if err != nil {
+		return nil, err
+	}
+	if err := params.efiRoot.PlaceFile(params.efiBootPath, params.ABLoader); err != nil {
+		return nil, err
+	}
+	if params.NodeParameters != nil {
+		if err := params.efiRoot.PlaceFile(nodeParamsPath, params.NodeParameters); err != nil {
+			return nil, err
+		}
+	}
+
+	// Try to layout the fat32 partition. If it detects that the disk is too
+	// small, an error will be returned.
+	if _, err := fat32.SizeFS(params.efiRoot, fat32.Options{
+		BlockSize:  uint16(params.efiPartition.BlockSize()),
+		BlockCount: uint32(params.efiPartition.BlockCount()),
+		Label:      "MNGN_BOOT",
+	}); err != nil {
+		return nil, fmt.Errorf("failed to calculate size of FAT32: %w", err)
+	}
+
+	// Create the system partition only if its size is specified.
+	if params.PartitionSize.System != 0 && params.SystemImage != nil {
+		params.systemPartitionA = &gpt.Partition{
+			Type: SystemAType,
+			Name: SystemALabel,
+		}
+		if err := params.tbl.AddPartition(params.systemPartitionA, params.PartitionSize.System*Mi); err != nil {
+			return nil, fmt.Errorf("failed to allocate system partition A: %w", err)
+		}
+		params.systemPartitionB = &gpt.Partition{
+			Type: SystemBType,
+			Name: SystemBLabel,
+		}
+		if err := params.tbl.AddPartition(params.systemPartitionB, params.PartitionSize.System*Mi); err != nil {
+			return nil, fmt.Errorf("failed to allocate system partition B: %w", err)
+		}
+	} else if params.PartitionSize.System == 0 && params.SystemImage != nil {
+		// Safeguard against contradicting parameters.
+		return nil, fmt.Errorf("the system image parameter was passed while the associated partition size is zero")
+	}
+	// Create the data partition only if its size is specified.
+	if params.PartitionSize.Data != 0 {
+		params.dataPartition = &gpt.Partition{
+			Type: DataType,
+			Name: DataLabel,
+		}
+		if err := params.tbl.AddPartition(params.dataPartition, -1); err != nil {
+			return nil, fmt.Errorf("failed to allocate data partition: %w", err)
+		}
+	}
+
+	return params, nil
+}
+
+const Mi = 1024 * 1024
+
+// Write installs Metropolis OS to a block device.
+func Write(params *Params) (*efivarfs.LoadOption, error) {
+	p, err := Plan(params)
+	if err != nil {
+		return nil, err
+	}
+
+	return p.Apply()
+}
diff --git a/metropolis/installer/main.go b/metropolis/installer/main.go
index 20a8240..ac6152f 100644
--- a/metropolis/installer/main.go
+++ b/metropolis/installer/main.go
@@ -18,12 +18,12 @@
 
 	"golang.org/x/sys/unix"
 
+	"source.monogon.dev/metropolis/installer/install"
 	"source.monogon.dev/osbase/blockdev"
 	"source.monogon.dev/osbase/bringup"
-	"source.monogon.dev/osbase/build/mkimage/osimage"
 	"source.monogon.dev/osbase/efivarfs"
 	"source.monogon.dev/osbase/oci"
-	ociosimage "source.monogon.dev/osbase/oci/osimage"
+	"source.monogon.dev/osbase/oci/osimage"
 	"source.monogon.dev/osbase/structfs"
 	"source.monogon.dev/osbase/supervisor"
 	"source.monogon.dev/osbase/sysfs"
@@ -159,7 +159,7 @@
 	if err != nil {
 		return fmt.Errorf("failed to read OS image from ESP: %w", err)
 	}
-	osImage, err := ociosimage.Read(ociImage)
+	osImage, err := osimage.Read(ociImage)
 	if err != nil {
 		return fmt.Errorf("failed to read OS image from ESP: %w", err)
 	}
@@ -173,16 +173,16 @@
 		return fmt.Errorf("cannot open system image in OS image: %w", err)
 	}
 
-	// Build the osimage parameters.
-	installParams := osimage.Params{
-		PartitionSize: osimage.PartitionSizeInfo{
+	// Build the install parameters.
+	installParams := install.Params{
+		PartitionSize: install.PartitionSizeInfo{
 			// ESP is the size of the node ESP partition, expressed in mebibytes.
 			ESP: 384,
 			// System is the size of the node system partition, expressed in
 			// mebibytes.
 			System: 4096,
 			// Data must be nonzero in order for the data partition to be created.
-			// osimage will extend the data partition to fill all the available space
+			// install will extend the data partition to fill all the available space
 			// whenever it's writing to block devices, such as now.
 			Data: 128,
 		},
@@ -207,7 +207,7 @@
 	}
 	// Set the first suitable block device found as the installation target.
 	tgtBlkdevName := blkDevs[0]
-	// Update the osimage parameters with a path pointing at the target device.
+	// Update the install parameters with a path pointing at the target device.
 	tgtBlkdevPath := filepath.Join("/dev", tgtBlkdevName)
 
 	tgtBlockDev, err := blockdev.Open(tgtBlkdevPath)
@@ -216,10 +216,10 @@
 	}
 	installParams.Output = tgtBlockDev
 
-	// Use osimage to partition the target block device and set up its ESP.
+	// Use install to partition the target block device and set up its ESP.
 	// Write will return an EFI boot entry on success.
 	l.Infof("Installing to %s...", tgtBlkdevPath)
-	be, err := osimage.Write(&installParams)
+	be, err := install.Write(&installParams)
 	if err != nil {
 		return fmt.Errorf("while installing: %w", err)
 	}
diff --git a/metropolis/installer/test/BUILD.bazel b/metropolis/installer/test/BUILD.bazel
index d68f78a..a5e8973 100644
--- a/metropolis/installer/test/BUILD.bazel
+++ b/metropolis/installer/test/BUILD.bazel
@@ -21,8 +21,8 @@
     },
     deps = [
         "//metropolis/cli/metroctl/core",
+        "//metropolis/installer/install",
         "//metropolis/proto/api",
-        "//osbase/build/mkimage/osimage",
         "//osbase/cmd",
         "//osbase/oci",
         "//osbase/oci/osimage",
diff --git a/metropolis/installer/test/run_test.go b/metropolis/installer/test/run_test.go
index bba323f..9d9d136 100644
--- a/metropolis/installer/test/run_test.go
+++ b/metropolis/installer/test/run_test.go
@@ -24,10 +24,10 @@
 	"source.monogon.dev/metropolis/proto/api"
 
 	mctl "source.monogon.dev/metropolis/cli/metroctl/core"
-	"source.monogon.dev/osbase/build/mkimage/osimage"
+	"source.monogon.dev/metropolis/installer/install"
 	"source.monogon.dev/osbase/cmd"
 	"source.monogon.dev/osbase/oci"
-	ociosimage "source.monogon.dev/osbase/oci/osimage"
+	"source.monogon.dev/osbase/oci/osimage"
 	"source.monogon.dev/osbase/structfs"
 )
 
@@ -147,11 +147,11 @@
 		log.Fatal(err)
 	}
 
-	osImage, err := ociosimage.Read(image)
+	osImage, err := osimage.Read(image)
 	if err != nil {
 		log.Fatal(err)
 	}
-	bootPath, err = osimage.EFIBootPath(osImage.Config.ProductInfo.Architecture())
+	bootPath, err = install.EFIBootPath(osImage.Config.ProductInfo.Architecture())
 	if err != nil {
 		log.Fatal(err)
 	}
@@ -284,22 +284,22 @@
 	// Check that the first partition is likely to be a valid ESP.
 	pi := ti.GetPartitions()
 	esp := (pi[0]).(*gpt.Partition)
-	if esp.Name != osimage.ESPLabel || esp.Start == 0 || esp.End == 0 {
+	if esp.Name != install.ESPLabel || esp.Start == 0 || esp.End == 0 {
 		t.Fatal("The node's ESP GPT entry looks off.")
 	}
 	// Verify the system partition's GPT entry.
 	system := (pi[1]).(*gpt.Partition)
-	if system.Name != osimage.SystemALabel || system.Start == 0 || system.End == 0 {
+	if system.Name != install.SystemALabel || system.Start == 0 || system.End == 0 {
 		t.Fatal("The node's system partition GPT entry looks off.")
 	}
 	// Verify the system partition's GPT entry.
 	systemB := (pi[2]).(*gpt.Partition)
-	if systemB.Name != osimage.SystemBLabel || systemB.Start == 0 || systemB.End == 0 {
+	if systemB.Name != install.SystemBLabel || systemB.Start == 0 || systemB.End == 0 {
 		t.Fatal("The node's system partition GPT entry looks off.")
 	}
 	// Verify the data partition's GPT entry.
 	data := (pi[3]).(*gpt.Partition)
-	if data.Name != osimage.DataLabel || data.Start == 0 || data.End == 0 {
+	if data.Name != install.DataLabel || data.Start == 0 || data.End == 0 {
 		t.Fatalf("The node's data partition GPT entry looks off: %+v", data)
 	}
 	// Verify that there are no more partitions.
diff --git a/metropolis/node/core/update/BUILD.bazel b/metropolis/node/core/update/BUILD.bazel
index 0ce75b4..73f6773 100644
--- a/metropolis/node/core/update/BUILD.bazel
+++ b/metropolis/node/core/update/BUILD.bazel
@@ -10,11 +10,11 @@
     visibility = ["//visibility:public"],
     deps = [
         "//go/logging",
+        "//metropolis/installer/install",
         "//metropolis/node/abloader/spec",
         "//metropolis/node/core/productinfo",
         "//metropolis/proto/api",
         "//osbase/blockdev",
-        "//osbase/build/mkimage/osimage",
         "//osbase/efivarfs",
         "//osbase/gpt",
         "//osbase/kexec",
diff --git a/metropolis/node/core/update/e2e/BUILD.bazel b/metropolis/node/core/update/e2e/BUILD.bazel
index 19738eb..5960e66 100644
--- a/metropolis/node/core/update/e2e/BUILD.bazel
+++ b/metropolis/node/core/update/e2e/BUILD.bazel
@@ -25,8 +25,8 @@
         "xAbloaderPath": "$(rlocationpath //metropolis/node/abloader )",
     },
     deps = [
+        "//metropolis/installer/install",
         "//osbase/blockdev",
-        "//osbase/build/mkimage/osimage",
         "//osbase/oci",
         "//osbase/oci/osimage",
         "//osbase/oci/registry",
diff --git a/metropolis/node/core/update/e2e/e2e_test.go b/metropolis/node/core/update/e2e/e2e_test.go
index 8bc2bb9..124883e 100644
--- a/metropolis/node/core/update/e2e/e2e_test.go
+++ b/metropolis/node/core/update/e2e/e2e_test.go
@@ -20,10 +20,10 @@
 
 	"github.com/bazelbuild/rules_go/go/runfiles"
 
+	"source.monogon.dev/metropolis/installer/install"
 	"source.monogon.dev/osbase/blockdev"
-	"source.monogon.dev/osbase/build/mkimage/osimage"
 	"source.monogon.dev/osbase/oci"
-	ociosimage "source.monogon.dev/osbase/oci/osimage"
+	"source.monogon.dev/osbase/oci/osimage"
 	"source.monogon.dev/osbase/oci/registry"
 	"source.monogon.dev/osbase/structfs"
 )
@@ -150,7 +150,7 @@
 		t.Fatal(err)
 	}
 
-	osImageY, err := ociosimage.Read(imageY)
+	osImageY, err := osimage.Read(imageY)
 	if err != nil {
 		t.Fatal(err)
 	}
@@ -189,13 +189,13 @@
 		t.Fatal(err)
 	}
 
-	if _, err := osimage.Write(&osimage.Params{
+	if _, err := install.Write(&install.Params{
 		Output:       rootDisk,
 		Architecture: osImageY.Config.ProductInfo.Architecture(),
 		ABLoader:     loader,
 		EFIPayload:   boot,
 		SystemImage:  system,
-		PartitionSize: osimage.PartitionSizeInfo{
+		PartitionSize: install.PartitionSizeInfo{
 			ESP:    128,
 			System: 256,
 			Data:   10,
diff --git a/metropolis/node/core/update/e2e/testos/BUILD.bazel b/metropolis/node/core/update/e2e/testos/BUILD.bazel
index 5301b57..a4011ce 100644
--- a/metropolis/node/core/update/e2e/testos/BUILD.bazel
+++ b/metropolis/node/core/update/e2e/testos/BUILD.bazel
@@ -13,12 +13,12 @@
     importpath = "source.monogon.dev/metropolis/node/core/update/e2e/testos",
     visibility = ["//visibility:private"],
     deps = [
+        "//metropolis/installer/install",
         "//metropolis/node/core/network",
         "//metropolis/node/core/update",
         "//metropolis/proto/api",
         "//osbase/blockdev",
         "//osbase/bringup",
-        "//osbase/build/mkimage/osimage",
         "//osbase/gpt",
         "//osbase/supervisor",
         "@org_golang_x_sys//unix",
diff --git a/metropolis/node/core/update/e2e/testos/main.go b/metropolis/node/core/update/e2e/testos/main.go
index 2cafebc..0b40127 100644
--- a/metropolis/node/core/update/e2e/testos/main.go
+++ b/metropolis/node/core/update/e2e/testos/main.go
@@ -11,11 +11,11 @@
 
 	"golang.org/x/sys/unix"
 
+	"source.monogon.dev/metropolis/installer/install"
 	"source.monogon.dev/metropolis/node/core/network"
 	"source.monogon.dev/metropolis/node/core/update"
 	"source.monogon.dev/osbase/blockdev"
 	"source.monogon.dev/osbase/bringup"
-	"source.monogon.dev/osbase/build/mkimage/osimage"
 	"source.monogon.dev/osbase/gpt"
 	"source.monogon.dev/osbase/supervisor"
 
@@ -57,11 +57,11 @@
 				return fmt.Errorf("unable to mkdir ESP mountpoint: %w", err)
 			}
 			updateSvc.ProvideESP("/esp", uint32(pn+1), p)
-		case osimage.SystemAType:
+		case install.SystemAType:
 			if err := unix.Symlink(fmt.Sprintf("/dev/vda%d", pn+1), "/dev/system-a"); err != nil {
 				return fmt.Errorf("failed to symlink system-a: %w", err)
 			}
-		case osimage.SystemBType:
+		case install.SystemBType:
 			if err := unix.Symlink(fmt.Sprintf("/dev/vda%d", pn+1), "/dev/system-b"); err != nil {
 				return fmt.Errorf("failed to symlink system-b: %w", err)
 			}
diff --git a/metropolis/node/core/update/update.go b/metropolis/node/core/update/update.go
index ee53f90..d37bb38 100644
--- a/metropolis/node/core/update/update.go
+++ b/metropolis/node/core/update/update.go
@@ -26,13 +26,13 @@
 	"google.golang.org/protobuf/proto"
 
 	"source.monogon.dev/go/logging"
+	"source.monogon.dev/metropolis/installer/install"
 	"source.monogon.dev/metropolis/node/core/productinfo"
 	"source.monogon.dev/osbase/blockdev"
-	"source.monogon.dev/osbase/build/mkimage/osimage"
 	"source.monogon.dev/osbase/efivarfs"
 	"source.monogon.dev/osbase/gpt"
 	"source.monogon.dev/osbase/kexec"
-	ociosimage "source.monogon.dev/osbase/oci/osimage"
+	"source.monogon.dev/osbase/oci/osimage"
 	"source.monogon.dev/osbase/oci/registry"
 
 	abloaderpb "source.monogon.dev/metropolis/node/abloader/spec"
@@ -88,9 +88,9 @@
 func (s Slot) EFIBootPath() string {
 	switch s {
 	case SlotA:
-		return osimage.EFIBootAPath
+		return install.EFIBootAPath
 	case SlotB:
-		return osimage.EFIBootBPath
+		return install.EFIBootBPath
 	default:
 		return ""
 	}
@@ -294,7 +294,7 @@
 		return fmt.Errorf("failed to fetch OS image: %w", err)
 	}
 
-	osImage, err := ociosimage.Read(image)
+	osImage, err := osimage.Read(image)
 	if err != nil {
 		return fmt.Errorf("failed to fetch OS image: %w", err)
 	}
@@ -428,7 +428,7 @@
 var abloader []byte
 
 func (s *Service) fixupPreloader() error {
-	efiBootPath, err := osimage.EFIBootPath(productinfo.Get().Info.Architecture())
+	efiBootPath, err := install.EFIBootPath(productinfo.Get().Info.Architecture())
 	if err != nil {
 		return err
 	}
@@ -473,7 +473,7 @@
 // fixupEFI checks for the existence and correctness of the EFI boot entry
 // repairs/recreates it if needed.
 func (s *Service) fixupEFI() error {
-	efiBootPath, err := osimage.EFIBootPath(productinfo.Get().Info.Architecture())
+	efiBootPath, err := install.EFIBootPath(productinfo.Get().Info.Architecture())
 	if err != nil {
 		return err
 	}
diff --git a/metropolis/test/launch/BUILD.bazel b/metropolis/test/launch/BUILD.bazel
index bbe3eb9..6c76d5b 100644
--- a/metropolis/test/launch/BUILD.bazel
+++ b/metropolis/test/launch/BUILD.bazel
@@ -44,6 +44,7 @@
     deps = [
         "//go/logging",
         "//metropolis/cli/metroctl/core",
+        "//metropolis/installer/install",
         "//metropolis/node",
         "//metropolis/node/core/curator/proto/api",
         "//metropolis/node/core/rpc",
@@ -51,7 +52,6 @@
         "//metropolis/proto/api",
         "//metropolis/proto/common",
         "//osbase/blockdev",
-        "//osbase/build/mkimage/osimage",
         "//osbase/logbuffer",
         "//osbase/oci",
         "//osbase/oci/osimage",
diff --git a/metropolis/test/launch/cluster.go b/metropolis/test/launch/cluster.go
index 1e3f42b..744c0cc 100644
--- a/metropolis/test/launch/cluster.go
+++ b/metropolis/test/launch/cluster.go
@@ -47,13 +47,13 @@
 
 	"source.monogon.dev/go/logging"
 	metroctl "source.monogon.dev/metropolis/cli/metroctl/core"
+	"source.monogon.dev/metropolis/installer/install"
 	"source.monogon.dev/metropolis/node"
 	"source.monogon.dev/metropolis/node/core/rpc"
 	"source.monogon.dev/metropolis/node/core/rpc/resolver"
 	"source.monogon.dev/osbase/blockdev"
-	"source.monogon.dev/osbase/build/mkimage/osimage"
 	"source.monogon.dev/osbase/oci"
-	ociosimage "source.monogon.dev/osbase/oci/osimage"
+	"source.monogon.dev/osbase/oci/osimage"
 	"source.monogon.dev/osbase/oci/registry"
 	"source.monogon.dev/osbase/structfs"
 	"source.monogon.dev/osbase/test/qemu"
@@ -170,7 +170,7 @@
 	if err != nil {
 		return nil, fmt.Errorf("failed to read OS image: %w", err)
 	}
-	osImage, err := ociosimage.Read(ociImage)
+	osImage, err := osimage.Read(ociImage)
 	if err != nil {
 		return nil, fmt.Errorf("failed to read OS image: %w", err)
 	}
@@ -198,8 +198,8 @@
 	}
 	defer df.Close()
 
-	installParams := &osimage.Params{
-		PartitionSize: osimage.PartitionSizeInfo{
+	installParams := &install.Params{
+		PartitionSize: install.PartitionSizeInfo{
 			ESP:    128,
 			System: 1024,
 			Data:   128,
@@ -210,7 +210,8 @@
 		ABLoader:     abloader,
 		Output:       df,
 	}
-	if _, err := osimage.Write(installParams); err != nil {
+
+	if _, err := install.Write(installParams); err != nil {
 		return nil, fmt.Errorf("while creating node image: %w", err)
 	}