kubectl directpv init

The kubectl directpv init command formats selected drives with the XFS filesystem and mounts them for DirectPV to manage. DirectPV uses initialized drives to provision PersistentVolumes in response to PersistentVolumeClaims with the directpv-min-io StorageClass.

Before running this command, use kubectl directpv discover to generate the drives.yaml configuration file. Review the file and remove any drives you do not want to format.

For a complete workflow including discovery, initialization, and drive management, see Managing Drives.

Irrevocable data loss

This command completely and irreversibly erases all data on the selected drives. Always review the drives.yaml file before running init.

Syntax

Initialize all drives listed in the configuration file:

kubectl directpv init drives.yaml --dangerous

Output:

┌────────────────────────────────────────┬───────┬──────────┬─────────┐
│ REQUESTID                              │ NODE  │ DRIVE    │ MESSAGE │
├────────────────────────────────────────┼───────┼──────────┼─────────┤
│ a1b2c3d4-e5f6-7890-abcd-ef1234567890   │ node1 │ /dev/sdb │ Success │
│ a1b2c3d4-e5f6-7890-abcd-ef1234567890   │ node1 │ /dev/sdc │ Success │
│ b2c3d4e5-f6a7-8901-bcde-f12345678901   │ node2 │ /dev/sdb │ Success │
└────────────────────────────────────────┴───────┴──────────┴─────────┘
kubectl directpv init INPUT_FILE    \
                      --dangerous   \
                      [--timeout "duration"]
  • INPUT_FILE is the path to the YAML configuration file generated by discover.
  • Brackets [] indicate optional parameters.

Parameters

INPUT_FILE

Required

The path to the YAML configuration file containing the drives to initialize. This file is generated by the kubectl directpv discover command.

--dangerous

Required

Confirms that you understand this operation permanently erases all existing data on the selected drives. The command does not run without this flag.

--timeout

Optional

Set a timeout duration for the initialization process.

Default: 2m0s

Global flags

This command supports the following global flags:

FlagDescription
--kubeconfigPath to the kubeconfig file to use for CLI requests.
--quietSuppress printing error messages.

Examples

Initialize drives from the default configuration file

Initialize all drives listed in drives.yaml:

kubectl directpv init drives.yaml --dangerous

Initialize drives from a custom configuration file

Initialize drives from a file in a different location:

kubectl directpv init /tmp/production-drives.yaml --dangerous

Initialize with extended timeout

For large clusters, increase the timeout to allow all nodes to complete initialization:

kubectl directpv init drives.yaml --dangerous --timeout=10m

Behavior

Initialization process

When you run the init command, DirectPV performs the following operations on each selected drive:

  1. Formats the drive with the XFS filesystem
  2. Mounts the drive to /var/lib/directpv/mnt/<UUID>
  3. Registers the drive as available for PersistentVolume provisioning

Drive requirements

Drives must meet the following conditions to be initialized:

  • Listed in the input configuration file.
  • Available (no existing filesystem, partition table, or mount).
  • Accessible by the DirectPV DaemonSet on the target node.

Use kubectl directpv discover --all to see why specific drives may be unavailable.

Output interpretation

The command displays a table showing the initialization results:

ColumnDescription
REQUESTIDUnique identifier for the initialization request
NODEThe Kubernetes node where the drive is located
DRIVEThe device path (for example, /dev/sdb)
MESSAGESuccess or an error message explaining the failure

Error handling

If initialization fails for a drive, the command continues processing remaining drives. Review the output table to identify which drives failed and why.

Common failure reasons:

  • Drive is in use by another process.
  • Drive has an existing filesystem that was not detected during discovery.
  • Node communication timeout.

For troubleshooting, see kubectl directpv list-drives to check drive status.

On this page