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
partedmay 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.
Creating a new partition table on a disk that already contains data erases all data on that disk. Back up your data before proceeding.
All changes made in fdisk stay in memory and are not written to disk until you enter w. Entering q discards all changes.
-
Verify that
fdiskis installed.fdisk --helpIf
fdiskis not found, install it.sudo yum install -y util-linux -
View disk information.
lsblkSample 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 -
Open the
fdiskinterface.sudo fdisk /dev/vdb -
Create a partition table:
Enter
gto create a GPT partition table.Enter
oto create an MBR partition table.
Then enter
pto 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 Enter
wto write the partition table to disk and exit.
Create a partition
The following example creates a partition on the /dev/vdb disk.
All changes stay in memory until you enter w. Entering q discards all changes without writing to disk.
-
Open the
fdiskinterface.sudo fdisk /dev/vdb -
Enter
pto 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 -
Enter
nto 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.NoteFor 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,+100Mcreates a 100 MB partition.
-
Enter
wto 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.
-
Install
parted.sudo yum install -y parted -
Open the
partedinterface.sudo parted /dev/vdb -
Set the display unit to MiB.
(parted) unit MiB -
Enter
pto 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 -
Resize the partition. Replace
NUMBERwith the partition number andENDwith the new end position.resizepart NUMBER ENDIn 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 Enter
quitto exitparted.-
Verify the updated partition size using
fdisk.sudo fdisk /dev/vdb -
Enter
pto 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 Enter
qto exitfdisk.
Change the partition type
Use fdisk to change the partition type.
-
Open the
fdiskinterface.sudo fdisk /dev/vdb -
Enter
pto 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 -
Enter
lto 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 / . ...... -
Change the partition type. To change partition 2 to an extended partition (type 5), enter
t, then2, then5.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'. -
Enter
pto 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 -
Enter
wto 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
Deleting a partition permanently removes all data stored in that partition. Back up your data before proceeding.
-
Open the
fdiskinterface.sudo fdisk /dev/vdb -
Enter
pto 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 -
Enter
dfollowed 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. -
Enter
pto 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 -
Enter
wto 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.