diskutils

package
v0.18.1 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2025 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AutoEndSize is used as the disk's "End" value to indicate it should be picked automatically
	AutoEndSize = 0

	EfiSystemPartitionTypeUuid    = "c12a7328-f81f-11d2-ba4b-00a0c93ec93b"
	BiosBootPartitionTypeUuid     = "21686148-6449-6e6f-744e-656564454649"
	GenericLinuxPartitionTypeUuid = "0FC63DAF-8483-4772-8E79-3D69D8477DE4"
)
View Source
const (
	B  = 1
	KB = 1000
	MB = 1000 * 1000
	GB = 1000 * 1000 * 1000
	TB = 1000 * 1000 * 1000 * 1000

	KiB = 1024
	MiB = 1024 * 1024
	GiB = 1024 * 1024 * 1024
	TiB = 1024 * 1024 * 1024 * 1024
)

Unit to byte conversion values

View Source
const (
	// DefaultKeyFilePath points to the initramfs keyfile for the install chroot
	DefaultKeyFilePath = "/etc/default.keyfile"
)

Variables

This section is empty.

Functions

func AddDefaultKeyfile

func AddDefaultKeyfile(keyFileDir, devPath string, encrypt configuration.RootEncryption) (fullKeyPath string, err error)

AddDefaultKeyfile adds a LUKS keyfile for initramfs unlock - keyFileDir is the directory to make the keyfile in - devPath is the path of the encrypted LUKS device - encrypt is the encryption settings

func ApplyRawBinaries

func ApplyRawBinaries(diskDevPath string, disk configuration.Disk) (err error)

ApplyRawBinaries applies all raw binaries described in disk configuration to the specified disk

func ApplyRawBinary

func ApplyRawBinary(diskDevPath string, rawBinary configuration.RawBinary) (err error)

ApplyRawBinary applies a single raw binary at offset (seek) with blocksize to the specified disk

func BlockOnDiskIO

func BlockOnDiskIO(diskDevPath string) (err error)

BlockOnDiskIO waits until all outstanding operations against a disk complete.

func BlockOnDiskIOByIds

func BlockOnDiskIOByIds(debugName string, maj string, min string) (err error)

BlockOnDiskIOById waits until all outstanding operations against a disk complete.

func BytesToSizeAndUnit

func BytesToSizeAndUnit(bytes uint64) string

BytesToSizeAndUnit takes a number of bytes and returns friendly representation of a size (for example 100GB).

func CleanupEncryptedDisks

func CleanupEncryptedDisks(encryptedRoot EncryptedRootDevice, isOfflineInstall bool) (err error)

CleanupEncryptedDisks performs cleanup work

func CreateEmptyDisk

func CreateEmptyDisk(workDirPath, diskName string, maxSize uint64) (diskFilePath string, err error)

CreateEmptyDisk creates an empty raw disk in the given working directory as described in disk configuration

func CreateSparseDisk

func CreateSparseDisk(diskPath string, size uint64, perm os.FileMode) (err error)

CreateSparseDisk creates an empty sparse disk file.

func DetachLoopbackDevice

func DetachLoopbackDevice(diskDevPath string) (err error)

DetachLoopbackDevice detaches the specified disk

func GetDiskIds

func GetDiskIds(diskDevPath string) (maj string, min string, err error)

func GetEncryptedRootVol

func GetEncryptedRootVol() string

GetEncryptedRootVol returns the full root volume name

func GetEncryptedRootVolMapping

func GetEncryptedRootVolMapping() string

GetEncryptedRootVolMapping returns the device mapping path of the root volume

func GetEncryptedRootVolPath

func GetEncryptedRootVolPath() string

GetEncryptedRootVolPath returns the device path of the root volume

func GetLuksMappingName

func GetLuksMappingName(uuid string) (mappingName string)

GetLuksMappingName returns the device name under /dev/mapepr

func GetSectorSize

func GetSectorSize(diskDevPath string) (logicalSectorSize, physicalSectorSize uint64, err error)

func IsEncryptedDevice

func IsEncryptedDevice(devicePath string) (result bool)

IsEncryptedDevice checks if a given device is a luks or LVM encrypted device - devicePath is the device to check

func RefreshPartitions

func RefreshPartitions(diskDevPath string) error

func SetupLoopbackDevice

func SetupLoopbackDevice(diskFilePath string) (devicePath string, err error)

SetupLoopbackDevice creates a /dev/loop device for the given disk file

func SizeAndUnitToBytes

func SizeAndUnitToBytes(sizeAndUnit string) (bytes uint64, err error)

SizeAndUnitToBytes takes a friendly representation of a size (for example 100GB) and return the number of bytes it represents.

func WaitForDiskDevice

func WaitForDiskDevice(diskDevPath string) error

func WaitForLoopbackToDetach

func WaitForLoopbackToDetach(devicePath string, diskPath string) error

func WriteFstabFile

func WriteFstabFile(entries []FstabEntry, fstabPath string) error

Types

type EncryptedRootDevice

type EncryptedRootDevice struct {
	Device      string
	LuksUUID    string
	HostKeyFile string
}

EncryptedRootDevice holds settings for an encrypted root partition or disk

func CreatePartitions

func CreatePartitions(targetOs targetos.TargetOs, diskDevPath string, disk configuration.Disk,
	rootEncryption configuration.RootEncryption,
) (partDevPathMap map[string]string, partIDToFsTypeMap map[string]string, encryptedRoot EncryptedRootDevice, err error)

CreatePartitions creates partitions on the specified disk according to the disk config

type FstabEntry

type FstabEntry struct {
	Source     string     `json:"source"`
	Target     string     `json:"target"`
	FsType     string     `json:"fstype"`
	Options    string     `json:"options"`
	VfsOptions MountFlags `json:"vfs-options"`
	FsOptions  string     `json:"fs-options"`
	Freq       int        `json:"freq"`
	PassNo     int        `json:"passno"`
}

func ReadFstabFile

func ReadFstabFile(fstabPath string) ([]FstabEntry, error)

type MountFlags

type MountFlags uintptr

func (*MountFlags) UnmarshalJSON

func (f *MountFlags) UnmarshalJSON(b []byte) (err error)

type PartitionInfo

type PartitionInfo struct {
	Name              string `json:"name"`       // Example: nbd0p1
	Path              string `json:"path"`       // Example: /dev/nbd0p1
	PartitionTypeUuid string `json:"parttype"`   // Example: c12a7328-f81f-11d2-ba4b-00a0c93ec93b
	FileSystemType    string `json:"fstype"`     // Example: vfat
	Uuid              string `json:"uuid"`       // Example: 4BD9-3A78
	PartUuid          string `json:"partuuid"`   // Example: 7b1367a6-5845-43f2-99b1-a742d873f590
	Mountpoint        string `json:"mountpoint"` // Example: /mnt/os/boot
	PartLabel         string `json:"partlabel"`  // Example: boot
	Type              string `json:"type"`       // Example: part
	SizeInBytes       uint64 `json:"size"`       // Example: 4096
}

func GetDiskPartitions

func GetDiskPartitions(diskDevPath string) ([]PartitionInfo, error)

GetDiskPartitions gets the kernel's view of a disk's partitions.

type PartitionTable

type PartitionTable struct {
	Label      string                    `json:"label"`      // Example: gpt
	Id         string                    `json:"id"`         // Example: 1DFD88CF-6214-4574-97A2-C605D411CFBE
	Device     string                    `json:"device"`     // Example: /dev/loop1
	Unit       string                    `json:"unit"`       // Example: sectors
	FirstLba   int64                     `json:"firstlba"`   // Example: 2048
	LastLba    int64                     `json:"lastlba"`    // Example: 8388574
	SectorSize int                       `json:"sectorsize"` // Example: 512
	Partitions []PartitionTablePartition `json:"partitions"`
}

func ReadDiskPartitionTable

func ReadDiskPartitionTable(diskDevPath string) (*PartitionTable, error)

ReadPartitionTable reads the partition table directly from the disk.

type PartitionTablePartition

type PartitionTablePartition struct {
	// Populated from "sfdisk --json":
	Path         string `json:"node"`  // Example: /dev/loop1p1
	Start        int64  `json:"start"` // Example: 2048
	Size         int64  `json:"size"`  // Example: 16384
	PartTypeUuid string `json:"type"`  // Example: C12A7328-F81F-11D2-BA4B-00A0C93EC93B
	PartUuid     string `json:"uuid"`  // Example: 2789D1BC-3909-4B06-AD2D-DA531DABF7C8
	PartLabel    string `json:"name"`  // Example: rootfs

	// Populated from "blkid --probe":
	FileSystemType string // Example: vfat
	FileSystemUuid string // Example: 4BD9-3A78
}

type SystemBlockDevice

type SystemBlockDevice struct {
	DevicePath  string // Example: /dev/sda
	RawDiskSize uint64 // Size in bytes
	Model       string // Example: Virtual Disk
}

SystemBlockDevice defines a block device on the host computer

func SystemBlockDevices

func SystemBlockDevices() (systemDevices []SystemBlockDevice, err error)

SystemBlockDevices returns all block devices on the host system.

Jump to

Keyboard shortcuts

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