Friday, May 20, 2016

Using the partedUtil command line utility on ESXi and ESX



Note: VMFS datastores can be created and deleted using the vSphere Client connected to an ESXi/ESX host or to vCenter Server. It is not necessary to manually create partitions using the command line utility. For more information, see the Managing Storage section of theConfiguration Guide for your version of ESXi/ESX.
You can use the partedUtil command line utility to directly manipulate partition tables for local and remote SAN disks on ESXi and ESX.

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

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 /vmfs/devices/disks/

Example of output under ESXi/ESX 3.x:

vmhba0:0:0:0 <-- disk device
vmhba0:0:0:1 <-- partition 1
vmhba0:0:0:2 <-- partition 2
vmhba0:0:0:3 <-- partition 3
vmhba0:0:0:5 <-- partition 5
vmhba3:0:0:0 <-- disk device
vmhba3:0:0:1 <-- partition 1

Example of output under ESXi/ESX 4.0 and later:

mpx.vmhba0:C0:T0:L0 <-- disk device
mpx.vmhba0:C0:T0:L0:1 <-- partition 1
mpx.vmhba0:C0:T0:L0:2 <-- partition 2
mpx.vmhba0:C0:T0:L0:3 <-- partition 3
mpx.vmhba0:C0:T0:L0:5 <-- partition 5
naa.60060160205010004265efd36125df11 <-- disk device
naa.60060160205010004265efd36125df11:1 <-- partition 1

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

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:
  • For ESXi/ESX 4.0 and earlier, run this command:

    partedUtil get "/vmfs/devices/disks/DeviceName"
  • For ESXi/ESX 4.1 and later, run this command:

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

    Example: To display the partition table for a device on an ESX 4.1 host:

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

msdos
17834 255 63 286513152
1 63 2249099 131 128
2 2249100 2474009 252 0
3 2474010 286487144 5 0
5 2474073 286487144 251 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 bsddvhgptloopmacmsdospc98, and sun. Of these, only the msdos label and gpt 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 a MBR (Master Boot Record) partition.

The second line displays the disk geometry information read from the underlying device:

17834 255 63 286513152
| | | |
| | | \----- quantity of sectors
| | \-------- quantity of sectors per track
| \------------ quantity of heads
\------------------ quantity of cylinders


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

Example: Here there are 4 partitions defined. The first partition (type 131 = 0x83 = Linux) is bootable. The second partition is a VMKcore coredump partition datastore (type 252 = 0xFC). The third partition is an Extended partition (type 5) containing additional Logical partitions. The fourth partition (numbered 5), is a Logical partition within partition number 5 and contains a VMFS Datastore (type 251 = 0xFB).

1 63 2249099 131 128
2 2249100 2474009 252 0
3 2474010 286487144 5 0
5 2474073 286487144 251 0
| | | | |
| | | | \--- attribute
| | | \------- type
| | \----------------- ending sector
| \------------------------- starting sector
\--------------------------- partition number


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. For example, VMKCore partition 2 spans from sector 2249100 to 2474009, covering 224909 sectors of the disk. This disk has 512 bytes per sector, so this partition is 224909 x 512 = 115153408 bytes = 109 MB in size.
  • The partition type identifies the purpose of a partition, and may be represented by either a decimal identifier (for example, 251) or a GUID (for example, AA31E02A400F11DB9590000C2911D1B8). See the list of commonly used partitions in the Additional Informationsection.
  • The partition attribute is a number 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/ESX:
  • For ESXi/ESX 4.0 and earlier, use the command:

    partedUtil set "/vmfs/devices/disks/DeviceName" ["partNum startSector endSector type/guid attribute"]*
  • For ESXi/ESX 4.1 and later, use the command:

    partedUtil setptbl "/vmfs/devices/disks/DeviceName" DiskLabel ["partNum startSector endSector type/guid attribute"]*
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 bsddvhgptloopmacmsdospc98, 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 are specified as quoted strings, each of which encapsulates a 5-tuple composed of the partition number, starting sector, ending sector, type ID, and attributes:
  • 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.
  • The partition type identifies the purpose of a partition, and may be represented by either a a decimal identifier (for example, 251) or a GUID (for example, AA31E02A400F11DB9590000C2911D1B8). See the list of commonly used partitions in the Additional Informationsection. Partitions created on ESXi 5.x and higher with the gpt disklabel must be specified using the GUID.
  • The partition attribute is a number 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.
Example: To create two consecutive ~244 MB partitions of type 131 = 0x83, the first of which is bootable and starts at offset 128:
  • For ESXi/ESX 4.0 and earlier, run this command:

    partedUtil set "/vmfs/devices/disks/mpx.vmhba0:C0:T0:L0" "1 128 500000 131 128" "2 500001 999999 131 0"
  • For ESXi/ESX 4.1 and later on an msdos label, run this command:

    partedUtil set "/vmfs/devices/disks/mpx.vmhba0:C0:T0:L0" msdos "1 128 500000 251 0"
  • On ESXi 5.x and later on a gpt label, run this command:

    partedUtil setptbl "/vmfs/devices/disks/mpx.vmhba0:C0:T0:L0" gpt "1 128 500000 AA31E02A400F11DB9590000C2911D1B8 128" "2 500001 999999 AA31E02A400F11DB9590000C2911D1B8 0"

    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 marking any change. Ensure that there is no active I/O to a partition prior to modifying it.

Sizing of partitions is outside the scope of this article. For more information, see Recommended disk or LUN sizes for VMware ESXi/ESX installations (1026500).

Deleting a partition

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

To delete a partition, run this command:

partedUtil delete "/vmfs/devices/disks/DeviceNamePartitionNumber

Example:

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

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 partedUtil command can be used to resize an existing partition on ESXi/ESX 4.0 and higher. 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/DeviceNamePartitionNumber NewStartSector NewEndSector

Example: To move partition 4 such that it starts in the same location (for example, 2474073) and ends at the new ending sector (1234567890), run this command:

partedUtil resize "/vmfs/devices/disks/mpx.vmhba0:C0:T0:L0" 4 2474073 1234567890

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.
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 used by ESXi/ESX include:


PartitionGUIDType (Hex)Type (Decimal)
VMFS DatastoreAA31E02A400F11DB9590000C2911D1B80xFB251
VMKCore Diagnostic9D27538040AD11DBBF97000C2911D1B80xFC252
VMware Reserved9198EFFC31C011DB8F78000C2911D1B8
Basic DataEBD0A0A2B9E5443387C068B6B72699C70x83131
Linux Swap0657FD6DA4AB43C484E50933C84B4F4F0x82130
Linux LVME6D6D379F50744C2A23C238F2A3DF9280x8E142
Linux RAIDA19D880F05FC4D3BA006743F0F84911E0xFD253
EFi SystemC12A7328F81F11D2BA4B00A0C93EC93B0xEF239
Microsoft ReservedE3C9E3160B5C4DB8817DF92DF00215AE
Unused Entry00000000000000000000000000000000
Fat160x66
Extended0x55
SFS0x4266
NTFS

No comments:

Post a Comment