All Products
Search
Document Center

Alibaba Cloud Linux:Manage disk partitions

Last Updated:Jun 02, 2026

Disk partitioning divides a physical disk into isolated areas so the operating system treats each area as an independent logical disk. This topic describes how to create partition tables, create partitions, resize partitions, change the partition type, and delete partitions on Alibaba Cloud Linux using fdisk and parted.

Disk partition limits

The maximum number of partitions per disk and the maximum partition size depend on the partition table type. Alibaba Cloud Linux supports two partition table types: Master Boot Record (MBR) and GUID Partition Table (GPT).

Maximum number of partitions per disk

  • On an MBR disk, you can create up to 4 primary partitions, or 3 primary partitions and 1 extended partition. The extended partition can contain multiple logical partitions.

  • On a GPT disk, you can create an unlimited number of partitions. However, specific partitioning tools such as parted may impose their own limits.

Maximum disk size

Partition table

Sector size

Maximum disk size

MBR

512 bytes

2 TB

MBR

4,096 bytes

16 TB

GPT

512 bytes

8 ZB

GPT

4,096 bytes

64 ZB

Create a partition table

The following example creates a partition table on the /dev/vdb disk using fdisk. Before you begin, verify that fdisk is installed.

Warning

Creating a new partition table on a disk that already contains data erases all data on that disk. Back up your data before proceeding.

Note

All changes made in fdisk stay in memory and are not written to disk until you enter w. Entering q discards all changes.

  1. Verify that fdisk is installed.

    fdisk --help

    If fdisk is not found, install it.

    sudo yum install -y util-linux
  2. View disk information.

    lsblk

    Sample output:

    NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    vda    253:0    0   40G  0 disk 
    ├─vda1 253:1 0 2M 0 part 
    ├─vda2 253:2 0 200M 0 part /boot/efi
    └─vda3 253:3 0 39.8G 0 part /
    vdb    253:16   0   20G  0 disk 
  3. Open the fdisk interface.

    sudo fdisk /dev/vdb
  4. Create a partition table:

    • Enter g to create a GPT partition table.

    • Enter o to create an MBR partition table.

    Then enter p to confirm the disk information. Sample output:

    Command (m for help): o
    Created a new DOS disklabel with disk identifier 0x34c3f526.
    
    Command (m for help): p
    Disk /dev/vdb: 20 GiB, 21474836480 bytes, 41943040 sectors
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disklabel type: dos
    Disk identifier: 0x34c3f526
  5. Enter w to write the partition table to disk and exit.

Create a partition

The following example creates a partition on the /dev/vdb disk.

Note

All changes stay in memory until you enter w. Entering q discards all changes without writing to disk.

  1. Open the fdisk interface.

    sudo fdisk /dev/vdb
  2. Enter p to view current disk information.

    Command (m for help): p
    Disk /dev/vdb: 20 GiB, 21474836480 bytes, 41943040 sectors
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disklabel type: dos
    Disk identifier: 0x34c3f526
  3. Enter n to create a partition. At each prompt, press Enter to accept the default or enter a custom value.

    Command (m for help): n 
    Partition type
       p   primary (0 primary, 0 extended, 4 free)
       e   extended (container for logical partitions)
    Select (default p): p
    Partition number (1-4, default 1):  
    First sector (2048-41943039, default 2048): 
    Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039): +100M
    
    Created a new partition 1 of type 'Linux' and of size 100 MiB.
    Note

    For the last sector, specify the partition size using one of the following formats:

    • +sectors: number of 512-byte sectors.

    • +size{K,M,G,T,P}: size with a unit. For example, +100M creates a 100 MB partition.

  4. Enter w to write the partition table to disk and exit.

    Command (m for help): w
    The partition table has been altered.
    Calling ioctl() to re-read partition table.
    Syncing disks.

Change the partition size

fdisk cannot resize partitions directly — it can only delete and recreate them, which risks data loss. Use parted instead, which provides a resizepart command for non-destructive resizing.

  1. Install parted.

    sudo yum install -y parted
  2. Open the parted interface.

    sudo parted /dev/vdb
  3. Set the display unit to MiB.

    (parted) unit MiB
  4. Enter p to list all partitions.

    (parted) p                                                                
    Model: Virtio Block Device (virtblk)
    Disk /dev/vdb: 20480MiB
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos
    Disk Flags: 
    
    Number  Start    End     Size    Type     File system  Flags
     1      1.00MiB  101MiB  100MiB  primary
     2      101MiB   201MiB  100MiB  primary
  5. Resize the partition. Replace NUMBER with the partition number and END with the new end position.

    resizepart NUMBER END

    In this example, partition 2 starts at 101 MiB. To extend it to 500 MiB, set the end position to 601 MiB.

    (parted) resizepart 2 601MiB
    (parted) p                                                                
    Model: Virtio Block Device (virtblk)
    Disk /dev/vdb: 20480MiB
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos
    Disk Flags: 
    
    Number  Start    End     Size    Type     File system  Flags
     1      1.00MiB  101MiB  100MiB  primary
     2      101MiB   601MiB  500MiB  primary
  6. Enter quit to exit parted.

  7. Verify the updated partition size using fdisk.

    sudo fdisk /dev/vdb
  8. Enter p to confirm the partition size.

    Command (m for help): p
    Disk /dev/vdb: 20 GiB, 21474836480 bytes, 41943040 sectors
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disklabel type: dos
    Disk identifier: 0xefabc860
    
    Device     Boot  Start     End Sectors  Size Id Type
    /dev/vdb1         2048  206847  204800  100M 83 Linux
    /dev/vdb2       206848 1230847 1024000  500M 83 Linux
  9. Enter q to exit fdisk.

Change the partition type

Use fdisk to change the partition type.

  1. Open the fdisk interface.

    sudo fdisk /dev/vdb
  2. Enter p to view the current partition information.

    Command (m for help): p
    Disk /dev/vdb: 20 GiB, 21474836480 bytes, 41943040 sectors
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disklabel type: dos
    Disk identifier: 0xefabc860
    
    Device     Boot  Start     End Sectors  Size Id Type
    /dev/vdb1         2048  206847  204800  100M 83 Linux
    /dev/vdb2       206848 1230847 1024000  500M 83 Linux
  3. Enter l to list all available partition types.

     0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris        
     1  FAT12           27  Hidden NTFS Win 82  Linux swap / So c1  DRDOS/sec (FAT-
     2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
     3  XENIX usr       3c  PartitionMagic  84  OS/2 hidden or  c6  DRDOS/sec (FAT-
     4  FAT16 <32M      40  Venix 80286     85  Linux extended  c7  Syrinx         
     5  Extended        41  PPC PReP Boot   86  NTFS volume set da  Non-FS data    
     6  FAT16           42  SFS             87  NTFS volume set db  CP/M / CTOS / .
    ......
  4. Change the partition type. To change partition 2 to an extended partition (type 5), enter t, then 2, then 5.

    Command (m for help): t
    Partition number (1,2, default 2): 2
    Hex code (type L to list all codes): 5
    
    Changed type of partition 'Linux' to 'Extended'.
  5. Enter p to confirm the updated partition information.

    Command (m for help): p
    Disk /dev/vdb: 20 GiB, 21474836480 bytes, 41943040 sectors
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disklabel type: dos
    Disk identifier: 0xefabc860
    
    Device     Boot  Start     End Sectors  Size Id Type
    /dev/vdb1         2048  206847  204800  100M 83 Linux
    /dev/vdb2       206848 1230847 1024000  500M  5 Extended
  6. Enter w to write the changes to disk and exit.

    Command (m for help): w
    The partition table has been altered.
    Calling ioctl() to re-read partition table.
    Syncing disks.

Delete a partition

Warning

Deleting a partition permanently removes all data stored in that partition. Back up your data before proceeding.

  1. Open the fdisk interface.

    sudo fdisk /dev/vdb
  2. Enter p to view the current partitions.

    Command (m for help): p
    Disk /dev/vdb: 20 GiB, 21474836480 bytes, 41943040 sectors
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disklabel type: dos
    Disk identifier: 0xefabc860
    
    Device     Boot  Start     End Sectors  Size Id Type
    /dev/vdb1         2048  206847  204800  100M 83 Linux
    /dev/vdb2       206848 1230847 1024000  500M  5 Extended
  3. Enter d followed by the partition number to delete. The following example deletes partition 2.

    Command (m for help): d
    Partition number (1,2, default 2): 2
    
    Partition 2 has been deleted.
  4. Enter p to confirm the deletion.

    Command (m for help): p
    Disk /dev/vdb: 20 GiB, 21474836480 bytes, 41943040 sectors
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disklabel type: dos
    Disk identifier: 0xefabc860
    
    Device     Boot Start    End Sectors  Size Id Type
    /dev/vdb1        2048 206847  204800  100M 83 Linux
  5. Enter w to write the changes to disk and exit.

    Command (m for help): w
    The partition table has been altered.
    Calling ioctl() to re-read partition table.
    Syncing disks.