Documentation
¶
Index ¶
- Constants
- func DetectNVMeControllers() ([]string, error)
- func GenerateFstab(layout *config.PartitionLayout, device string) string
- func GenerateLVMFstab(lvm *config.LVMConfig) string
- func PartitionDevicePath(device string, num int) string
- func PartitionNumber(node, disk string) int
- type Commander
- type ExecCommander
- type Manager
- func (m *Manager) ApplyLVMConfig(ctx context.Context, device string, layout *config.PartitionLayout) error
- func (m *Manager) ApplyNVMeNamespaceLayout(ctx context.Context, cfgs []NVMeNamespaceConfig) (map[string][]string, error)
- func (m *Manager) ApplyPartitionLayout(ctx context.Context, device string, layout *config.PartitionLayout) error
- func (m *Manager) AttachNVMeNamespace(ctx context.Context, controller, nsid string) error
- func (m *Manager) BindMount(source, target string) error
- func (m *Manager) CheckFilesystem(ctx context.Context, device string) error
- func (m *Manager) ChrootRun(ctx context.Context, root, command string) ([]byte, error)
- func (m *Manager) CreateNVMeNamespace(ctx context.Context, controller string, sizeBlocks uint64, blockSize int) (string, error)
- func (m *Manager) CreateRAIDArray(ctx context.Context, name string, level int, devices []string) error
- func (m *Manager) DetectDisk(_ context.Context, minSizeGB int) (string, error)
- func (m *Manager) DisableLVM(ctx context.Context) error
- func (m *Manager) EnableLVM(ctx context.Context) error
- func (m *Manager) FindBootPartition(parts []Partition) (*Partition, error)
- func (m *Manager) FindDiskBySerial(ctx context.Context, serial string, minSizeGB int) (string, error)
- func (m *Manager) FindRootPartition(parts []Partition) (*Partition, error)
- func (m *Manager) FormatNVMeNamespace(ctx context.Context, device string, blockSize, lbafIndex int) error
- func (m *Manager) GrowPartition(ctx context.Context, disk string, partNum int) error
- func (m *Manager) MountPartition(ctx context.Context, device, mountpoint string) error
- func (m *Manager) MountPartitionReadOnly(ctx context.Context, device, mountpoint string) error
- func (m *Manager) NVMeIdentifyController(ctx context.Context, controller string) (map[string]string, error)
- func (m *Manager) NVMeListNamespaces(ctx context.Context, controller string) ([]string, error)
- func (m *Manager) NVMeResetNamespaces(ctx context.Context, controller string) error
- func (m *Manager) NVMeSupportsMultiNS(ctx context.Context, controller string) (bool, error)
- func (m *Manager) ParsePartitions(ctx context.Context, disk string) ([]Partition, error)
- func (m *Manager) PartProbe(ctx context.Context, disk string) error
- func (m *Manager) ResizeFilesystem(ctx context.Context, device string) error
- func (m *Manager) SecureEraseAllDisks(ctx context.Context) error
- func (m *Manager) SetupChrootBindMounts(root string) error
- func (m *Manager) StopRAIDArrays(ctx context.Context) error
- func (m *Manager) TeardownChrootBindMounts(root string) error
- func (m *Manager) Unmount(target string) error
- func (m *Manager) WipeAllDisks(ctx context.Context) error
- func (m *Manager) WipeDisk(ctx context.Context, device string) error
- func (m *Manager) WipeFilesystemSignatures(ctx context.Context, device string) error
- type NVMeNamespace
- type NVMeNamespaceConfig
- type Partition
Constants ¶
const ( EFISystemPartitionGUID = "C12A7328-F81F-11D2-BA4B-00A0C93EC93B" LinuxFilesystemGUID = "0FC63DAF-8483-4772-8E79-3D69D8477DE4" LinuxFilesystemMBRType = "83" )
EFI and Linux partition type GUIDs.
const LinuxLVMGUID = "E6D6D379-F507-44C2-A23C-238F2A3DF928"
LinuxLVMGUID is the GPT type GUID for Linux LVM partitions.
Variables ¶
This section is empty.
Functions ¶
func DetectNVMeControllers ¶ added in v0.0.8
DetectNVMeControllers lists NVMe controllers in /dev/.
func GenerateFstab ¶ added in v0.0.8
func GenerateFstab(layout *config.PartitionLayout, device string) string
GenerateFstab creates an fstab file for the partition layout.
func GenerateLVMFstab ¶ added in v0.0.8
GenerateLVMFstab adds LVM volume fstab entries.
func PartitionDevicePath ¶ added in v0.0.8
PartitionDevicePath returns the device path for a specific partition number.
func PartitionNumber ¶
PartitionNumber extracts the partition number from a device node path. For example: /dev/sda1 -> 1, /dev/nvme0n1p2 -> 2.
Types ¶
type ExecCommander ¶
type ExecCommander = executil.ExecCommander
ExecCommander executes real system commands.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles disk operations for provisioning.
func NewManager ¶
NewManager creates a Manager with the given Commander (nil = ExecCommander).
func (*Manager) ApplyLVMConfig ¶ added in v0.0.8
func (m *Manager) ApplyLVMConfig(ctx context.Context, device string, layout *config.PartitionLayout) error
ApplyLVMConfig creates PV, VG, and LVs according to the LVM config.
func (*Manager) ApplyNVMeNamespaceLayout ¶ added in v0.0.8
func (m *Manager) ApplyNVMeNamespaceLayout(ctx context.Context, cfgs []NVMeNamespaceConfig) (map[string][]string, error)
ApplyNVMeNamespaceLayout creates namespaces from config, using percentage-based sizing. Returns created NSIDs per controller in creation order.
func (*Manager) ApplyPartitionLayout ¶ added in v0.0.8
func (m *Manager) ApplyPartitionLayout(ctx context.Context, device string, layout *config.PartitionLayout) error
ApplyPartitionLayout creates partitions on a disk according to the layout. Only GPT partition tables are supported (via sgdisk).
func (*Manager) AttachNVMeNamespace ¶ added in v0.0.8
AttachNVMeNamespace attaches a namespace to controller 0.
func (*Manager) CheckFilesystem ¶
CheckFilesystem runs e2fsck on the device. Exit codes 0 (clean) and 1 (errors corrected) are acceptable. Exit code >= 4 indicates uncorrectable errors and returns an error.
func (*Manager) ChrootRun ¶
ChrootRun executes a command in a chroot environment. When using a mock commander (tests), the command is routed through the commander. For real execution, the external chroot binary is used. If the chroot binary is not found (e.g., in minimal initramfs), falls back to syscall-based chroot.
func (*Manager) CreateNVMeNamespace ¶ added in v0.0.8
func (m *Manager) CreateNVMeNamespace(ctx context.Context, controller string, sizeBlocks uint64, blockSize int) (string, error)
CreateNVMeNamespace creates a namespace with the given size in blocks and block size.
func (*Manager) CreateRAIDArray ¶
func (m *Manager) CreateRAIDArray(ctx context.Context, name string, level int, devices []string) error
CreateRAIDArray creates a software RAID array using mdadm. level is the RAID level (0, 1, 5, 6, 10). devices are the member disks.
func (*Manager) DetectDisk ¶
DetectDisk finds the target disk for provisioning. Prefers NVMe, falls back to SATA/SAS. Removable media (USB drives, SD cards) are rejected unless BOOTY_ALLOW_REMOVABLE=true.
func (*Manager) DisableLVM ¶
DisableLVM deactivates LVM volume groups before disk wipe.
func (*Manager) FindBootPartition ¶
FindBootPartition finds the EFI System Partition.
func (*Manager) FindDiskBySerial ¶ added in v0.0.18
func (m *Manager) FindDiskBySerial(ctx context.Context, serial string, minSizeGB int) (string, error)
FindDiskBySerial finds a non-virtual target disk whose serial or stable identifier exactly matches serial. Removable media are rejected unless BOOTY_ALLOW_REMOVABLE=true.
func (*Manager) FindRootPartition ¶
FindRootPartition finds the primary Linux filesystem partition. When multiple partitions share a Linux filesystem type, it prefers one with a "root" or "/" partition name, otherwise returns the last match (root is typically after /boot in the partition table).
func (*Manager) FormatNVMeNamespace ¶ added in v0.0.8
func (m *Manager) FormatNVMeNamespace(ctx context.Context, device string, blockSize, lbafIndex int) error
FormatNVMeNamespace performs a secure erase and reformat of a namespace. lbafIndex must be provided explicitly from device capabilities (e.g. nvme id-ns), because LBAF index ordering is vendor/device-specific.
func (*Manager) GrowPartition ¶
GrowPartition grows a partition to fill available space using growpart.
func (*Manager) MountPartition ¶
MountPartition mounts a device at the given mountpoint. Tries all supported filesystem types in order: ext4, xfs, btrfs, ext3, ext2, vfat. Waits up to 10 seconds for the device node to appear (devtmpfs may lag after partprobe).
func (*Manager) MountPartitionReadOnly ¶ added in v0.0.11
MountPartitionReadOnly mounts a device read-only at the given mountpoint. It tries the same supported filesystem list as MountPartition.
func (*Manager) NVMeIdentifyController ¶ added in v0.0.8
func (m *Manager) NVMeIdentifyController(ctx context.Context, controller string) (map[string]string, error)
NVMeIdentifyController returns basic controller info via nvme id-ctrl.
func (*Manager) NVMeListNamespaces ¶ added in v0.0.8
NVMeListNamespaces lists existing namespace IDs on a controller.
func (*Manager) NVMeResetNamespaces ¶ added in v0.0.8
NVMeResetNamespaces deletes all namespaces and recreates a single default namespace using the controller's full capacity at 512-byte block size. Used during deprovisioning to return the drive to a single-namespace factory state.
func (*Manager) NVMeSupportsMultiNS ¶ added in v0.0.8
NVMeSupportsMultiNS checks whether the controller supports multiple namespaces. Returns false for consumer drives (nn == 1).
func (*Manager) ParsePartitions ¶
ParsePartitions reads the partition table using sfdisk --json.
sfdisk may emit non-JSON warnings (e.g. "GPT PMBR size mismatch") on stderr which CombinedOutput merges before the JSON body. We strip everything before the first '{' so the JSON decoder sees clean input.
func (*Manager) PartProbe ¶
PartProbe re-reads partition table and triggers device node creation.
Calls partprobe first; falls back to blockdev --rereadpt if partprobe fails. After re-reading, runs mdev -s (busybox mini-udev) to ensure partition device nodes are created — devtmpfs alone may not create them in minimal initramfs environments without udevd.
func (*Manager) ResizeFilesystem ¶
ResizeFilesystem resizes the filesystem on the given device. Supports ext2/3/4 (resize2fs), XFS (xfs_growfs), and btrfs.
func (*Manager) SecureEraseAllDisks ¶
SecureEraseAllDisks performs hardware-level secure erase on all disks. For NVMe drives: uses nvme format (User Data Erase). For SATA/SAS drives: uses ATA SECURITY ERASE UNIT via hdparm. Falls back to quick erase (wipefs) if secure erase is not supported.
func (*Manager) SetupChrootBindMounts ¶
SetupChrootBindMounts creates standard bind mounts for chroot operations.
func (*Manager) StopRAIDArrays ¶
StopRAIDArrays stops all RAID arrays via mdadm.
func (*Manager) TeardownChrootBindMounts ¶
TeardownChrootBindMounts unmounts the standard chroot bind mounts and returns a joined error from the mandatory unmounts (/run, /sys, /proc, /dev). The efivarfs unmount is best-effort because efivarfs is only bind-mounted when /sys/firmware/efi/efivars exists on the host; failures there are logged at Debug level and never returned.
func (*Manager) WipeAllDisks ¶
WipeAllDisks runs wipefs on all block devices excluding loop and CD-ROM. This performs a quick erase: clears partition tables and filesystem signatures without overwriting data.
type NVMeNamespace ¶ added in v0.0.8
type NVMeNamespace struct {
Label string `json:"label"` // Human-readable label
SizePct int `json:"sizePct"` // Percentage of total capacity
BlockSize int `json:"blockSize,omitempty"` // 512 or 4096 (default: 512)
}
NVMeNamespace defines a single namespace to create.
type NVMeNamespaceConfig ¶ added in v0.0.8
type NVMeNamespaceConfig struct {
Controller string `json:"controller"` // e.g. "/dev/nvme0"
Namespaces []NVMeNamespace `json:"namespaces"`
}
NVMeNamespaceConfig defines the desired namespace layout for an NVMe controller.
func ParseNVMeConfig ¶ added in v0.0.8
func ParseNVMeConfig(data string) ([]NVMeNamespaceConfig, error)
ParseNVMeConfig parses a JSON NVMe namespace configuration string.