Which command is used to create and manage partitions on a hard disc?

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 a disk partition in Linux

Disk Partitioning 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.

Creating a Disk Partition in Linux

This procedure describes how to partition a storage disk in Linux using the parted command.

Procedure

  1. List the partitions using the 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

  2. 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.

  3. 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? Yes
    0,
    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? Yes
    2,
    (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
    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? Yes
    4,
    (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
    5,
    (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
    6, 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? Yes
    7. 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? Yes
    8 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.

  4. 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

  5. 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.

    What is the command to partition a disk in Linux?

    To create a new partition, we use the command 'n'. This will prompt you to specify the type of partition which you wish to create. If you wish to create a logical partition, choose 'l'. Alternatively, you can choose 'p' for a primary partition.

    What is to be used to manage hard drives and partitions?

    Disk Management is an extension of the Microsoft Management Console that allows full management of the disk-based hardware recognized by Windows. It's used to manage the drives installed in a computer—like hard disk drives (internal and external), optical disk drives, and flash drives.