en-US ar ast az be bg bn ca cs de el es es_419 fa fi fil fr fur he hi hr hu id it ja jp ko mr ms my nb_NO ne nl or pl pt pt_BR pt_PT ro ru si sk sq sv sw te tr tzm uk ur ur_PK uz zh_CN zh_Hans zh_TW
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 Disk Partitioning in Linux
Creating a Disk Partition in Linux
parted
command.Procedure
parted -l
command to identify the storage device you want to partition. Typically, the first hard disk [/dev/sda
or sudo parted /dev/vdc
GNU Parted 3.3
Using /dev/vdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
[parted]
0] 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 parted
command 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 parted
without a device name, it will randomly select a storage device to modify.
Set the partition table type to
sudo parted /dev/vdc GNU Parted 3.3 Using /dev/vdc Welcome to GNU Parted! Type 'help' to view a list of commands. [parted]3, then enter
sudo parted /dev/vdc GNU Parted 3.3 Using /dev/vdc Welcome to GNU Parted! Type 'help' to view a list of commands. [parted]4 to 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
The
sudo parted /dev/vdc GNU Parted 3.3 Using /dev/vdc Welcome to GNU Parted! Type 'help' to view a list of commands. [parted]5 and
sudo parted /dev/vdc GNU Parted 3.3 Using /dev/vdc Welcome to GNU Parted! Type 'help' to view a list of commands. [parted]6 commands are both used for making a partition table on a storage device. At the time of writing, the supported partition tables are:
sudo parted /dev/vdc GNU Parted 3.3 Using /dev/vdc Welcome to GNU Parted! Type 'help' to view a list of commands. [parted]7,
sudo parted /dev/vdc GNU Parted 3.3 Using /dev/vdc Welcome to GNU Parted! Type 'help' to view a list of commands. [parted]8,
sudo parted /dev/vdc GNU Parted 3.3 Using /dev/vdc Welcome to GNU Parted! Type 'help' to view a list of commands. [parted]9,
[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? Yes0,
sudo parted /dev/vdc GNU Parted 3.3 Using /dev/vdc Welcome to GNU Parted! Type 'help' to view a list of commands. [parted]3,
[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? Yes2,
[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? Yes3,
[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? Yes4,
[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? Yes5,
[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? Yes6, and
[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? Yes7. Use
[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? Yes8 to get a list of supported partition tables. Remember
sudo parted /dev/vdc GNU Parted 3.3 Using /dev/vdc Welcome to GNU Parted! Type 'help' to view a list of commands. [parted]5 will 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 a GPT partition table, the partition type is used as the partition name.