Making GPT Partition Table and Creating Partitions Using parted in Linux

My best favorite disk partition table manipulation tools are cfdisk/fdisk on Linux. However, for large disks, cfdisk/fdisk (of the versions by this post is written) will just give up with a message suggesting GPT partition table format and using GNU parted like

WARNING: The size of this disk is 6.0 TB (6001042391040 bytes).
DOS partition table format can not be used on drives for volumes
larger than (2199023255040 bytes) for 512-byte sectors. Use parted(1) and GUID 
partition table format (GPT).

If you continue using fdisk/cfdisk, you will only create msdos partition table and use only less than 2TB space.

However, the parted‘s interface is not that easy to use at the first try. After some struggling with parted, I finally make a partition on the new 6TB RAID 0 storage array. Here is the process.

pc ~ # parted /dev/sdc
GNU Parted 2.3
Using /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel GPT
Warning: The existing disk label on /dev/sdc will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? Yes
(parted) mkpart primary 2048s 100%
(parted) q
Information: You may need to update /etc/fstab.

Why “2048s” is used here? Please check this blog post.

For the command mkpart primary 2048s 100%, an alternative command is

mkpart PARTITION_LABEL ext4 primary 2048s 100%

which makes a partition with label PARTITION_LABEL.

The partition can be easily accessed later at path /dev/disk/by-partlable/PARTITION_LABEL which will be useful for writing fstab entry or other usages that need to directly use a partition block device.

The new partition /dev/sdc1 is created:

pc ~ # ls /dev/sd*
/dev/sda  /dev/sda1  /dev/sda2  /dev/sda3  /dev/sda4  /dev/sda5  /dev/sdb  /dev/sdb1  /dev/sdc  /dev/sdc1

Check the information again:

pc ~ # parted /dev/sdc print
Model: ORICO H/ W RAID0 (scsi)
Disk /dev/sdc: 6001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt

Number  Start   End     Size    File system  Name     Flags
 1      1049kB  6001GB  6001GB               primary

Alternative to parted: if you don’t want to use parted, you may try cgdisk which is a curses-based GPT manipulator that feel very similar to cfdisk.

Eric Ma

Eric is a systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

6 comments:

  1. For the command

    `mkpart primary 2048s 100%`

    an alternative command is

    `mkpart PARTITION_LABEL ext4 primary 2048s 100%`

    which makes a partition with label PARTITION_LABEL.

    The partition can be easily accessed later at path

    `/dev/disk/by-partlable/PARTITION_LABEL`

    which will be useful for writing `fstab` entry or other usages that need to directly use a partition block device.

  2. Number Start End Size File system Name Flags
    1 1049kB 6001GB 6001GB primary

    There is not file system showing at the end? How do I get something like ext4 or ntfs there?

  3. For GPT partitions, do NOT use “primary” in the mkpart command.

    # parted -s /dev/sd$d mkpart “$partlabel” ntfs primary 2048s 100%
    Error: Invalid number.

    This works:

    # parted -s /dev/sd$d mkpart “$partlabel” ntfs 2048s 100%

Leave a Reply

Your email address will not be published. Required fields are marked *