Monday, September 3, 2012

Create GPT partition for LVM using parted tool

Traditional MBR(MSDOS) disk label has limitation of 2^32 (2TiB) in capacity and 15 in partition numbers(including logical partitions), while GUID Partition Table (GPT) supports 2^64 KiB (2 ZiB) and 128 partitions by default.

In Linux, fdisk doesn’t support GPT, parted is the common built-in tool for GPT.

#mpathb is the disk name is in FC SAN with multipath enabled in my test env
>parted  /dev/mapper/mpathb
(parted) mklabel gpt
(parted) mkpart primary ext4 1024kb 2tb
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel?
#This warning indicates the start position of the partition may not aligned with physical sector of the #hard disk. It is very important for harddisk of hardware raid, the start position must be n*stripe size.
#see also: http://honglus.blogspot.com.au/2009/08/align-partitions-on-stripe-boundary-for.html
#It may also hold true for single hard disk, because even a single harddisk has sector size of 2K,4K #nowadays .
#To fix the issue, just change the unit from SI to IEC 60027-2 standard
# k- stands for kilo, meaning 1,000 in Metric(SI) Prefix
# ki- stands for kilobinary ("kibi-"), meaning 1,024 in IEC 60027-2 standard
(parted) help unit
  unit UNIT                                set the default unit to UNIT
        UNIT is one of: s, B, kB, MB, GB, TB, compact, cyl, chs, %, kiB, MiB, GiB, TiB
(parted) mkpart primary ext4 1024KiB 8TiB
#the values are accepted without any warning
(parted) print
..
Number  Start   End     Size    File system  Name     Flags
 1      1049kB  8796GB  8796GB               primary
#1049KB is shown, because the default unit is KB, we change it to KiB
(parted) unit KiB
(parted) print
..
Number  Start    End            Size           File system  Name     Flags
 1      1024kiB  8589934592kiB  8589933568kiB               primary 
#set  LVM flag
#GPT has  reserved GUID for different partitions e.g LVM= E6D6D379-F507-44C2-A23C-238F2A3DF928
#
(parted) set 1 lvm on
(parted) p
Model: Linux device-mapper (multipath) (dm)
Disk /dev/mapper/mpathb: 19527106560kiB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number  Start    End            Size           File system  Name     Flags
 1      1024kiB  8589934592kiB  8589933568kiB               primary  lvm
#create LVM physical volume as usual.
>pvcreate /dev/mapper/mpathb1

4 comments:

  1. "(parted) mkpart primary ext4 1024KiB 8TiB
    #the values are accepted without any warning"

    Yes, but is the partition properly aligned?

    ReplyDelete
  2. 1024KiB offset is safe, the common stripe size of RAID is 64KiB~512KiB
    more info
    http://honglus.blogspot.com.au/2009/08/align-partitions-on-stripe-boundary-for.html

    ReplyDelete
  3. I have fired 'print' command on parted prompt it throws below error.

    "Error: msdos labels do not support devices that have more than 4294967295 sectors."

    ReplyDelete
    Replies
    1. As the message explains, you are using "msdos" or MBR-style partitioning on a device that isn't supported by that partitioning model. You must first set up that device as gpt with "mklabel gpt". Please note that this operation will destroy all partitions currently existing in that HDD. Some external HDDs are still formatted with MBR but have some weird hack that enables them to show 3TB partitions, even though this is by definition impossible. These HDDs should be repartitioned as GPT then formatted before storing any data on them!

      Delete