Documentation
¶
Index ¶
- Constants
- func PartitionNumber(node, disk string) int
- type Commander
- type ExecCommander
- type Manager
- 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) 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) FindRootPartition(parts []Partition) (*Partition, 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) 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)
- func (m *Manager) Unmount(target string) error
- func (m *Manager) WipeAllDisks(ctx context.Context) error
- type Partition
Constants ¶
const ( EFISystemPartitionGUID = "C12A7328-F81F-11D2-BA4B-00A0C93EC93B" LinuxFilesystemGUID = "0FC63DAF-8483-4772-8E79-3D69D8477DE4" )
EFI and Linux partition type GUIDs.
Variables ¶
This section is empty.
Functions ¶
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) CheckFilesystem ¶
CheckFilesystem runs e2fsck on the device.
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) 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.
func (*Manager) DisableLVM ¶
DisableLVM deactivates LVM volume groups before disk wipe.
func (*Manager) FindBootPartition ¶
FindBootPartition finds the EFI System Partition.
func (*Manager) FindRootPartition ¶
FindRootPartition finds the primary Linux filesystem partition.
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) 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 standard bind mounts. Errors are logged to aid debugging of stale mount points.