partition

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package partition writes GPT and MBR disk partition tables.

A partition table is not a filesystem and does not implement image.Filesystem: it carves a whole-disk device.Device into aligned regions and hands each back as a device.Section, which the caller formats with any engine (ext, fat, …). This is the container layer that turns bare filesystem images into a bootable disk (e.g. GPT + ESP FAT32 + ext4 root). Use FormatGPT for a modern GUID partition table or FormatMBR for a classic table of up to four primaries.

For GPT, GUIDs come from the injected image.UUIDSource, so a disk is reproducible by wiring; per-partition GUIDs are derived deterministically from the disk GUID to stay unique without extra entropy.

Index

Constants

View Source
const (
	MBRTypeEmpty     = 0x00
	MBRTypeFAT32LBA  = 0x0C
	MBRTypeLinux     = 0x83
	MBRTypeLinuxSwap = 0x82
	MBRTypeEFI       = 0xEF
)

MBR partition type bytes.

Variables

View Source
var (
	TypeEFI       = Type{0x28, 0x73, 0x2A, 0xC1, 0x1F, 0xF8, 0xD2, 0x11, 0xBA, 0x4B, 0x00, 0xA0, 0xC9, 0x3E, 0xC9, 0x3B}
	TypeLinuxData = Type{0xAF, 0x3D, 0xC6, 0x0F, 0x83, 0x84, 0x72, 0x47, 0x8E, 0x79, 0x3D, 0x69, 0xD8, 0x47, 0x7D, 0xE4}
	TypeLinuxRoot = Type{0xE3, 0xBC, 0x68, 0x4F, 0xCD, 0xE8, 0xB1, 0x4D, 0x96, 0xE7, 0xFB, 0xCA, 0xF9, 0x84, 0xB7, 0x09}
)

Common partition type GUIDs, in on-disk byte order.

Functions

This section is empty.

Types

type MBRSpec

type MBRSpec struct {
	Type     byte
	Size     int64
	Bootable bool
}

MBRSpec describes one MBR primary partition. Size is in bytes, rounded up to the alignment; a Size of 0 fills the remaining space (last spec only).

type Partition

type Partition struct {
	Name             string
	StartLBA, EndLBA uint64 // inclusive
	Section          *device.Section
}

Partition is a created partition: its byte range on the disk and the Section the caller formats.

func FormatGPT

func FormatGPT(dev device.Device, deps image.Deps, specs []Spec) ([]Partition, error)

FormatGPT writes a protective MBR, primary and backup GPT, and returns the created partitions (each with a device.Section to format). The disk device size must be a multiple of the sector size.

func FormatMBR

func FormatMBR(dev device.Device, specs []MBRSpec) ([]Partition, error)

FormatMBR writes a classic MBR partition table (up to four primaries) and returns the created partitions, each with a device.Section to format.

type Spec

type Spec struct {
	Type Type
	Name string
	Size int64
}

Spec describes one partition to create. Size is in bytes and is rounded up to the alignment; a Size of 0 means "use all remaining space" and is only valid for the last spec.

type Type

type Type [16]byte

Type is a 16-byte partition type GUID in on-disk (mixed-endian) byte order.

Jump to

Keyboard shortcuts

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