Creating a disk partition in Linux
Creating and deleting partitions in Linux is a regular practice because storage devices (such as hard drives and USB drives) must be structured in some way before they can be used. In most cases, large storage devices are divided into separate sections called partitions. Partitioning also allows you to divide your hard drive into isolated sections, where each section behaves as its own hard drive. Partitioning is particularly useful if you run multiple operating systems.
This procedure describes how to partition a storage disk in Linux using the
List the partitions using the
parted -lcommand to identify the storage device you want to partition. Typically, the first hard disk (
/dev/vda) will contain the operating system, so look for another disk to find the one you want. For example:
sudo parted -l Model: ATA RevuAhn_850X1TU5 (scsi) Disk /dev/vdc: 512GB Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags: Number Start End Size Type File system Flags 1 1049kB 525MB 524MB primary ext4 boot 2 525MB 512GB 512GB primary lvm
Open the storage device. Use the
partedcommand to begin working with the selected storage device. For example:
sudo parted /dev/vdc GNU Parted 3.3 Using /dev/vdc Welcome to GNU Parted! Type 'help' to view a list of commands. (parted)
Be sure to indicate the specific device you want to partition. If you just enter
partedwithout a device name, it will randomly select a storage device to modify.
Set the partition table type to
gpt, then enter
Yesto accept it.
(parted) mklabel gpt Warning: the existing disk label on /dev/vdc will be destroyed and all data on this disk will be lost. Do you want to continue? Yes/No? Yes
mktablecommands are both used for making a partition table on a storage device. At the time of writing, the supported partition tables are:
help mklabelto get a list of supported partition tables. Remember
mklabelwill not make a partition, rather it will make a partition table.
Review the partition table of the storage device.
(parted) print Model: Virtio Block Device (virtblk) Disk /dev/vdc: 1396MB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags
Create a new partition using the following command. For example, 1396 MB on partition 0:
(parted) mkpart primary 0 1396MB Warning: The resulting partition is not properly aligned for best performance Ignore/Cancel? I (parted) print Model: Virtio Block Device (virtblk) Disk /dev/vdc: 1396MB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 17.4kB 1396MB 1396MB primary
Providing a partition name under GPT is a must; in the above example, primary is the name, not the partition type. In a GPT partition table, the partition type is used as partition name.
Quit using the
quitcommand. Changes are automatically saved when you quit
(parted) quit Information: You may need to update /etc/fstab.
To get help on how to make a new partition, type:
(parted) help mkpart mkpart PART-TYPE [FS-TYPE] START END make a partition PART-TYPE is one of: primary, logical, extended FS-TYPE is one of: udf, btrfs, nilfs2, ext4, ext3, ext2, fat32, fat16, hfsx, hfs+, hfs, jfs, swsusp, linux-swap(v1), linux-swap(v0), ntfs, reiserfs, hp-ufs, sun-ufs, xfs, apfs2, apfs1, asfs, amufs5, amufs4, amufs3, amufs2, amufs1, amufs0, amufs, affs7, affs6, affs5, affs4, affs3, affs2, affs1, affs0, linux-swap, linux-swap(new), linux-swap(old) START and END are disk locations, such as 4GB or 10%. Negative values count from the end of the disk. For example, -1s specifies exactly the last sector. 'mkpart' makes a partition without creating a new file system on the partition. FS-TYPE may be specified to set an appropriate partition ID.
Want to help? Learn how to contribute to Fedora Docs ›