partutil

package
v0.0.0-...-f7eae2a Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GRUBCfgEFIPath = "/efi/boot/grub.cfg"

Functions

func AddCmdToGRUB

func AddCmdToGRUB(grubPath, cmd string) error

AddCmdToGRUB adds a command string to after every `cros_efi` command

func BootDev

func BootDev(rootdevCmd string) (string, error)

func ConvertSizeToBytes

func ConvertSizeToBytes(size string) (uint64, error)

ConvertSizeToBytes converts a size string to int unit: bytes. It takes a string of number with no unit (sectors), unit B, unit K, unit M, or unit G.

func ConvertSizeToGBRoundUp

func ConvertSizeToGBRoundUp(size string) (uint64, error)

ConvertSizeToGBRoundUp converts input size to GB unit. Rounded up, since extend disk can only take GB unit. Used by Daisy workflow to resize the disk.

func ExtendPartition

func ExtendPartition(disk string, partNumInt int, end uint64, extendFS bool) error

ExtendPartition extends a partition to a specific end sector.

func FindLast4KSector

func FindLast4KSector(start uint64) uint64

FindLast4KSector returns the last 4K bytes aligned sector from start. If input is a 4K aligned sector, return itself.

func GPTPriority

func GPTPriority(attrs string) (uint64, error)

GPTPriority extracts the GPT priority value from the given sfdisk attributes.

func GRUBContains

func GRUBContains(grubPath, cmd string) (bool, error)

GRUBContains seaches for the command string inside of the GRUB file

func GetPartUUID

func GetPartUUID(partName string) (string, error)

GetPartUUID finds the PartUUID of a partition using blkid

func HandlePartitionTable

func HandlePartitionTable(table, partName string, change bool, f func(p *PartContent)) (string, error)

HandlePartitionTable takes a partition table and get the start and size of the target partition. If change==true, it will rebuild the partition table with data passed in by p *PartContent and return the new table

func IsPartitionMinimal

func IsPartitionMinimal(disk string, partNumInt int) (bool, error)

IsPartitionMinimal determines if a partition is the smallest size it can be. If this function returns true, MinimizePartition can make the given partition smaller.

func MinimizePartition

func MinimizePartition(disk string, partNumInt int) (uint64, error)

MinimizePartition minimizes the input partition and returns the next sector of the end sector. The smallest partition from fdisk is 1 sector partition.

func MountEFIPartition

func MountEFIPartition() (string, error)

MountEFIPartition mounts the EFI partition (/dev/sda12) and returns the path where it is mounted.

func MovePartition

func MovePartition(disk string, partNumInt int, dest string) error

MovePartition moves a partition to a start sector. It takes destination input like 2048 (absolute sector number), +5G or -200M.

func ParseGPTAttrs

func ParseGPTAttrs(attrs string) (uint64, error)

ParseGPTAttrs reads a GPT attributes string output by sfdisk and converts it into a uint64 with the appropriate bits set.

func PartNumIntToString

func PartNumIntToString(disk string, partNumInt int) (string, error)

PartNumIntToString converts input int partNumInt into string, if disk ends with number, add 'p' to the front. Example: /dev/loop5p1

func ReadPartitionData

func ReadPartitionData(disk string, partNum int) ([]byte, error)

ReadPartitionData reads the content of the given partition on the given disk.

func ReadPartitionSize

func ReadPartitionSize(disk string, partNumInt int) (uint64, error)

ReadPartitionSize reads the size of a partition (unit:sectors of 512 Bytes).

func ReadPartitionStart

func ReadPartitionStart(disk string, partNumInt int) (uint64, error)

ReadPartitionStart reads the start sector of a partition.

func ReadPartitionTable

func ReadPartitionTable(disk string) (string, error)

ReadPartitionTable reads the partition table of a disk.

func ReadPartitionUUID

func ReadPartitionUUID(disk string, partNumInt int) (string, error)

ReadPartitionUUID reads PARTUUID of a partition.

func UnmountEFIPartition

func UnmountEFIPartition() error

UnmountEFIPartition unmounts the EFI partition (/dev/sda12)

func WritePartitionData

func WritePartitionData(disk string, partNum int, data []byte) error

WritePartitionData writes data to a given partition on the given disk. The data size must match the partition size exactly.

Types

type PartContent

type PartContent struct {
	Start uint64
	Size  uint64
}

PartContent contains the info of a partition

type Partition

type Partition struct {
	Node  string `json:"node"`
	Start int    `json:"start"`
	Size  int    `json:"size"`
	Type  string `json:"type"`
	UUID  string `json:"uuid"`
	Name  string `json:"name"`
	Attrs string `json:"attrs"`
}

type PartitionTable

type PartitionTable struct {
	Label      string      `json:"label"`
	ID         string      `json:"id"`
	Device     string      `json:"device"`
	Unit       string      `json:"unit"`
	FirstLBA   int         `json:"firstlba"`
	SectorSize int         `json:"sectorsize"`
	Partitions []Partition `json:"partitions"`
}

type SFDiskTable

type SFDiskTable struct {
	PartitionTable PartitionTable `json:"partitiontable"`
}

func ReadPartitionTableJSON

func ReadPartitionTableJSON(disk string) (SFDiskTable, error)

ReadPartitionTableJSON reads a partition table into a SFDiskTable type.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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