NVMe namespaces

Non-Volatile Memory Express (NVMe) disks often have multiple controllers. All Power Systems connect only one of the controllers to the Peripheral Component Interconnect Express (PCIe) slot. The secondary controller is not visible as a PCI device and is not a part of the NVMe topology of Linux®. However, when a NVMe drive is placed in a NVMe expansion drawer - 24 devices (NED24), both the controllers can be attached to the NVMe device.

For an operating system (OS) to use an NVMe device, the OS must have one or more NVMe namespaces associated with the OS. An NVMe namespace is seen in Linux as a block device. The NVMe namespace is also the device that is used for the following operations:
  • To create a file system.
  • To create a physical volume to add to the Logical Volume Manager (LVM) volume group.
  • To create a software Redundant Array of Independent Disks (RAID) array.

NVMe devices are provisioned with a single namespace that represents the entire NVMe device. For most users, only a single NVMe namespace is required. The device can further be partitioned into smaller block devices by using a disk partitioning tool (such as fdisk) or by using LVM. However, most NVMe devices support the capability to create more than one NVMe namespace.

A NVMe namespace must be created as a shared namespace. A shared namespace has the following benefits:
  • A shared namespace is visible to all the NVMe controllers within the device.
  • For multipath NVMe devices in a NED24 drawer, a shared namespace ensures that the Linux NVMe driver has access to each of the namespaces with the help of both the physical hardware paths.
  • For single-path NVMe devices, a shared namespace ensures that the namespace is visible to the Linux operating system.
  • It is possible to physically move a NVMe drive to a NED24 multipath drawer if required.
View namespaces
To view the details of the namespace nvme0, enter the following command:
# nvme list-ns /dev/nvme0

[   0]:0x1
Create namespaces

NVMe namespaces are created and attached to the NVMe devices as a part of the factory configuration. Only a single namespace is created for each NVMe device. The namespace that is created and attached to the NVMe device is a shared namespace. It is recommended to retain this factory configuration.

If a NVMe device is formatted due to some issue, a new namespace needs to be created and attached to the formatted NVMe device. To create a new shared namespace, enter the following command:
# nvme create-ns /dev/nvme0 -nsze 11995709440 -ncap 1199570940 -flbas 0 -dps 0 -nmic 1
Attach namespaces

After the NVMe namespaces are created, they must be attached to a NVMe device and controller. In most cases, the NVMe namespace is attached to the primary controller. If a NVMe drive is installed into a NED24 expansion drawer, both the controllers can be specified.

To attach a namespace to the NVMe device, complete the following steps:
  1. List all the controllers that are attached to a NVMe device by using the nvme list-ctrl <device> command. To list the controllers that are attached to the NVMe device nvme0, enter the following command:
    # nvme list-ctrl /dev/nvme0
    An example output is displayed:
    num of ctrls present: 2
    [   0]:0x1
    [   1]:0x2
    

    In this example, the NVMe device nvme0 has 0x1 and 0x2 controllers that are attached to it.

  2. Determine the primary controller by using the nvme id-ctrl <device> | grep cntlid command. To determine the primary controller for the NVMe device nvme0, enter the following command:
    # nvme id-ctrl /dev/nvme0 | grep cntlid
    An example output is displayed that specifies 0x1 as the primary controller:
    cntlid    : 0x1
  3. Attach the new namespace to the primary controller. To attach the new namespace to the primary controller 0x1, enter the following command:
    # nvme attach-ns /dev/nvme0 -n 0x1 -c 0x1
    An example message is displayed:
    attach-ns: Success, nsid:1
  4. List the namespaces that are attached to the NVMe device by using the nvme list command. An example output is displayed:
    
    Node              Generic     SN              Model                                      Namespace  Usage           Format           FW Rev
    ----------------- ----------- --------------- ------------------------------------------ -------------------------- ---------------- --------
    /dev/nvme0n1      /dev/ng0n1  S4WANA0R400036  PCIe4 1.6TB NVMe Flash Adapter 0x1         25.01  GB /  25.01  GB     4 KiB +  0 B     REV.SP47
    
Detach namespaces
To detach a namespace that is attached to the primary controller 0x1 of the NVMe device nvme0, enter the following command:
# nvme detach-ns /dev/nvme0 -namespace-id=1 -c 0x1
Delete namespaces
To delete a namespace that is attached to the NVMe device nvme0, enter the following command:
# nvme delete-ns /dev/nvme0 -namespace-id=1