Using partedUtil command line disk partitioning utility on ESXi
search cancel

Using partedUtil command line disk partitioning utility on ESXi

book

Article ID: 323144

calendar_today

Updated On:

Products

VMware vSphere ESXi

Issue/Introduction

This article provides information on using the partedUtil command-line disk-partitioning utility on VMware ESXi and its use cases. 

Note: VMFS datastores can be created and deleted using the vSphere Client connected to an ESXi host or to vCenter Server. It is not necessary to manually create partitions using the command line utility.

For more information for your version of ESXi, see the Managing Storage Devices section of the vSphere Storage Guide.

Environment

VMware vSphere ESXi 6.x
VMware vSphere ESXi 7.x
VMware vSphere ESXi 8.x

Resolution

You can use the partedUtil command-line utility to directly manipulate partition tables for local and remote SAN disks on ESXi.

The partedUtil command-line only is supported for disk partitioning from ESXi 5.x and above. The command-line utility fdisk does not work with LUNs formatted with VMFS5 or VMFS6.

Note: This article assumes that a console session is available to the ESXi, and that you are familiar with the console and disk management concepts, and that you have made adequate backups before proceeding.


This article covers these tasks:

  • Retrieving a list of disk devices
  • Printing an existing partition table
  • Creating a new partition table (which of the following commands...., type gpt)
  • Deleting a partition (parted delete/remove partition. delete partition cmd)
  • Resizing a partition (parted resize partition)

Retrieving a list of disk devices

Each partedUtil command accepts a device argument specifying a local or SAN-based disk to operate against. This should be a path name beginning with /vmfs/devices/disks/. It should specify the whole block device rather than an existing partition on the device.

To obtain a list of disk device names that can be managed by partedUtil, run this command:

ls -ltrh /vmfs/devices/disks/

Example output shared below:



The fields listed in blue are the vml IDs of the same devices highlighted below. 

Note: When specifying a block device using the partedUtil command, use the full path and enclose it in double-quotes.

For example:

partedUtil getptbl "/vmfs/devices/disks/mpx.vmhba0:C0:T0:L0"

For more information on identifying a specific disk device, see Identifying disks when working with VMware ESX (1014953).

Printing an existing partition table

An existing partition table on a block disk device may be examined using the partedUtil command-line utility. To obtain a list of partitions defined on a block disk device:

partedUtil getptbl "/vmfs/devices/disks/DeviceName"

For example:

partedUtil getptbl /vmfs/devices/disks/naa.6589cfc000000dcc6071c4243094f34b

gpt
32635 255 63 524288000
1 2048 524287966 AA31E02A400F11DB9590000C2911D1B8 vmfs 0


The first line is only present in the getptbl form of the command and displays the disk label identifying the partitioning scheme being used. Common labels are bsd, dvh, gpt, loop, mac, msdos, pc98, and sun. Of these, only the msdos (VMFS3) label and gpt (VMFS5 and VMFS6) partitioning scheme is used by ESXi/ESX.

Note: The label msdos does not mean that the device contains a Windows file system or is being used by a Windows machine. It only means that it is MBR (Master Boot Record) partition.

The second line displays the disk geometry information read from the underlying device(esxi partition layout/label):



The remaining lines identify each defined partition. If no partitions are defined, this list is blank. The list may not be sorted.

For example: Here there is 1 partition defined.  

Properties of a partition:

  • The starting and ending sectors specify how much contiguous disk space a partition occupies. User-friendly sizes of partitions can be calculated from this information.
Let's take the example of the datastore above, the datastore spans from sector 2048 to 524287966, covering 524285918 (524287966 - 2048) sectors of the disk. This disk has 512 bytes per sector, so this partition is 524285918 x 512 = 268434390016 bytes (approximately 250 GB in size).
  • The partition type identifies the purpose of a partition and may be represented by either a GUID (for example, AA31E02A400F11DB9590000C2911D1B8) or a decimal identifier (for example, 251). See the list of commonly used partitions in the Additional Information section.
  • A partition attribute is a number towards the end which identifies properties of the partition. A common attribute is, 128=0x80, which indicates that the partition is bootable. Otherwise, most partitions have an attribute value of 0.

Creating a new partition table

A new partition table can be created on a block disk device using the partedUtil command-line utility. To create a new partition on a block device, use a different command depending on the version of ESXi.

partedUtil setptbl "/vmfs/devices/disks/DeviceName" DiskLabel ["partNum startSector endSector type/guid attribute"]*

For example : 

partedUtil setptbl /vmfs/devices/disks/naa.6589cfc000000dcc6071c4243094f34b gpt "1 2048 7516192734 AA31E02A400F11DB9590000C2911D1B8 0"

The breakdown of the command is as follows: 

DiskLabel - gpt 
partNum - 1
startSector - 2048
endSector - 7516192734
GUID - AA31E02A400F11DB9590000C2911D1B8
attribute - 0


The disk label is only specified in the setptbl form of the command and sets the disk label identifying the partitioning scheme being used. Common labels are bsd, dvh, gpt, loop, mac, msdos, pc98 and sun.

ESXi 5.x and higher supports both the msdos and gpt label and partitioning schemes, while ESXi/ESX 4.1 and earlier supports the msdos label and partitioning scheme exclusively.

The list of partitions to apply to the disk must be fully specified on the partedUtil command line. To add additional partitions to a disk with an existing partition, specify both the original and new partitions on the command line. If you do not, the existing partition is lost. The list of partitions is specified as quoted strings, each of which encapsulates a 5-tuple composed of the partition number, starting sector, ending sector, type ID, and attributes. 

For Example: To create two consecutive ~244 MB partitions of type gpt, the first of which is bootable and starts at offset 2048. The command to be used in this scenario would be as follows: 

partedUtil setptbl "/vmfs/devices/disks/naa.6589cfc000000dcc6071c4243094f34b" gpt "1 2048 500000 AA31E02A400F11DB9590000C2911D1B8 2048" "2 500001 999999 AA31E02A400F11DB9590000C2911D1B8 0"

The startSector and endSector specify how much contiguous disk space a partition occupies. The starting sector is enforced to be before the ending sector for the same partition, but no guarantee is made that the partition defined does not overlap another partition.

Note: Volumes that are upgraded from VMFS-3 to VMFS-5 continue to have the VMFS partition starting at sector 128, rather than at sector 2048.

Caution: There is no facility to undo a partition table change other than creating a new partition table. Ensure that you have a backup before making any change. Ensure that there is no active I/O to a partition prior to modifying it.

The sizing of partitions is outside the scope of this article.

Deleting a partition

A single partition can be deleted from a partition table on a device using the partedUtil command-line utility.

To delete a partition, run this command:

partedUtil delete "/vmfs/devices/disks/DeviceName" PartitionNumber

For example:

partedUtil delete "vmfs/devices/disks/naa.6589cfc000000dcc6071c4243094f34b" 1

Caution: There is no facility to undo a partition table change other than creating a new partition table. Ensure that you have a backup before making any change. Ensure that there is no active I/O to a partition before modifying it.

Resizing a partition

The partecUtil command can be used to resize an existing partition. This does not resize the file system within the partition and is no different from deleting and recreating the partition with a new starting or ending sector.

To resize a partition, run this command:

partedUtil resize "/vmfs/devices/disks/DeviceName" PartitionNumber NewStartSector NewEndSector

For example:

To increase the partition size of the above listed VMFS datastore from its existing last sector 524287966 to a new last sector 8679954582, the following command needs to be executed: 

partedUtil resize "/vmfs/devices/disks/naa.6589cfc000000dcc6071c4243094f34b" 1 2048 8679954582

Caution: There is no facility to undo a partition table change other than creating a new partition table. Ensure that you have a backup before making any change. Ensure that there is no active I/O to a partition before modifying it.

Additional Information

The partition type identifies the purpose of a partition and may indicate intended usage by a particular operating system. Partition types must be specified by the GUID only in the partition table (when running the partedUtil setptbl command).

You can obtain the GUID by running the command:

partedUtil showGuids

Partition types commonly seen by ESXi includes:
 

Partition GUID Type (Hex) Type (Decimal)
VMFS Datastore AA31E02A400F11DB9590000C2911D1B8 0xFB 251
VMKCore Diagnostic 9D27538040AD11DBBF97000C2911D1B8 0xFC 252
VMware Reserved 9198EFFC31C011DB8F78000C2911D1B8    
Basic Data EBD0A0A2B9E5443387C068B6B72699C7 0x83 131
Linux Swap 0657FD6DA4AB43C484E50933C84B4F4F 0x82 130
Linux LVM E6D6D379F50744C2A23C238F2A3DF928 0x8E 142
Linux RAID A19D880F05FC4D3BA006743F0F84911E 0xFD 253
EFi System C12A7328F81F11D2BA4B00A0C93EC93B 0xEF 239
Microsoft Reserved E3C9E3160B5C4DB8817DF92DF00215AE    
Unused Entry 00000000000000000000000000000000    
Fat16   0x6 6
Extended   0x5 5
SFS   0x42 66
NTFS   0x7 7