disklayout

package
v0.0.0-...-0dba0d8 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package disklayout describes the gokrazy on-disk partition layout and provides helpers for writing it. It is intended for use by tools that install a gokrazy image onto a fresh disk (e.g. SD card flashing tools), so they can lay out the partition table the same way monogok does when it produces a full disk image.

Index

Constants

View Source
const (

	// BootPartitionSizeMB is the gokrazy boot (FAT) partition size.
	BootPartitionSizeMB = 100
	// RootPartitionSizeMB is the size of each of the two gokrazy root
	// (squashfs) partitions; the two are sized identically so OTA
	// updates can swap between them.
	RootPartitionSizeMB = 500

	// MinDiskMB is the smallest device size in megabytes that can hold
	// a gokrazy install with one byte of perm space, given
	// DefaultBootPartitionStartLBA.
	MinDiskMB = (DefaultBootPartitionStartLBA*sectorSize)/mb + BootPartitionSizeMB + 2*RootPartitionSizeMB + 1
)
View Source
const DefaultBootPartitionStartLBA int64 = 8192

DefaultBootPartitionStartLBA is the standard LBA at which gokrazy places the first (boot) partition. 8192 sectors of 512 bytes = 4 MiB, the recommended alignment for SD cards.

Variables

This section is empty.

Functions

func BootStartLBA

func BootStartLBA(firstLBA int64) uint32

BootStartLBA returns the LBA where the boot partition starts.

func BuildMBR

func BuildMBR(bootCode []byte, firstLBA int64, devsize uint64) ([512]byte, error)

BuildMBR returns a complete 512-byte MBR boot sector for a fresh gokrazy disk install: 446 bytes of bootCode (zero-padded if shorter; rejected if longer), followed by the 64-byte gokrazy partition table, followed by the 0xAA55 boot signature.

func PermSize

func PermSize(firstLBA int64, devsize uint64) uint32

PermSize returns the perm partition size in sectors on a disk of devsize bytes whose first partition starts at firstLBA. It is the unclamped "fill the rest of the disk" size, matching what monogok writes when building a full MBR image. Callers that need to reserve trailing space (e.g. for a secondary GPT) must subtract it themselves.

func PermStartLBA

func PermStartLBA(firstLBA int64) uint32

PermStartLBA returns the LBA where the perm (writable, ext4) partition starts.

func RootAStartLBA

func RootAStartLBA(firstLBA int64) uint32

RootAStartLBA returns the LBA where the root A partition starts.

func RootBStartLBA

func RootBStartLBA(firstLBA int64) uint32

RootBStartLBA returns the LBA where the root B partition starts.

func WritePartitionTable

func WritePartitionTable(w io.Writer, firstLBA int64, devsize uint64) error

WritePartitionTable writes the 64-byte gokrazy MBR primary partition table to w (not including the 446-byte boot code prefix or the 2-byte 0xAA55 signature). devsize is the total disk size in bytes.

firstLBA is typically DefaultBootPartitionStartLBA. devsize must be large enough to hold the boot + both root partitions + at least one perm sector, or an error is returned.

Types

This section is empty.

Jump to

Keyboard shortcuts

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