Extend Disk Partition on Linux Data Disk
Overview
Disk expansion increases storage capacity but does not automatically extend the partition or file system. Manual operations are required to fully utilize the expanded disk.
Description:
- Before expanding the partition, it is strongly recommended to create a snapshot for the disk. For details, please refer to [Create Disk Snapshot](CDS/Snapshot Operation Guide/Disk Snapshot/Manual Snapshot.md);
- Before expanding the partition, confirm the existing partitioning method of the Cloud Disk Server (CDS) and ensure the current partitioning method matches it;
- If you are using CentOS or Ubuntu system versions, you can use the CDSCMD Tool to automatically expand partitions;
- If you have any questions, please submit a Ticket in the console to contact professional technical service personnel.
If you are operating on a Windows system instance, please refer to [Windows Data Disk Partition](CDS/Disk Operation Guide/Elastic Operations/Resize cloud disks/Extend Disk Partition on Windows Data Disk.md).
Operation guide
This document uses an example of data disk expansion on CentOS 6.5 x86_64 (64bit); similar operations apply to other Linux systems.
Sign in to the instance and check the status
1. Sign in to BCC instance
You can sign in to the BCC instance in multiple ways, and you can refer to Sign in to Instance for specific login methods.
2. Check current partition status and partitioning method
Execute fdisk -l to view the current partition size. The data disk /dev/vde is currently mounted and expanded from 50 GB to 100 GB.
1[root@instance-xxxx ~]# fdisk -l
2 Disk /dev/vda: 42.9 GB, 42,949,672,960 bytes, 83,886,080 sectors
3 Units = sectors of 1 * 512 = 512 bytes
4 Sector size (logical/physical): 512 bytes / 512 bytes
5 I/O size (min/optimal): 512 bytes / 512 bytes
6 Disk Tag Type: dos
7 Disk identifier: 0x000b8163
8 Device Boot Start End Blocks Id System
9/dev/vda1 * 2048 83886046 41941999+ 83 Linux
10 Disk /dev/vde: 107.4 GB, 107,374,182,400 bytes, 209,715,200 sectors
11 Units = sectors of 1 * 512 = 512 bytes
12 Sector size (logical/physical): 512 bytes / 512 bytes
13 I/O size (min/optimal): 512 bytes / 512 bytes
14 Disk Tag Type: dos
15 Disk identifier: 0x63ffc036
16 Device Boot Start End Blocks Id System
17/dev/vde1 2048 104857599 52427776 83 Linux
Description:
- If your disk capacity is less than 2 TB, you can use either MBR or GPT to expand partitions and the file system. However, if your disk capacity exceeds 2 TB after expansion and the current partitioning uses MBR, you'll need to switch to GPT. If preserving existing data is crucial, we recommend creating a new disk, initializing it with GPT, and transferring data to the new disk.
3. View file system type
Execute the command blkid to view the current file system type. The current file system type of the data disk /dev/vde1 is ext4.
1[root@instance-xxxx ~]# blkid
2/dev/vda1: UUID="84953f78-xxxx-4dbd-ac60-aaabc2e4cb9c" TYPE="ext4"
3/dev/vde1: UUID="cb664382-xxxx-49f0-874e-d68d8cba0141" TYPE="ext4"
4. Check file system operation status
If your file system is ext, you can execute the command e2fsck -n /dev/vd* to check; if it is xfs, execute xfs_repair -n /dev/vd*. A "clean" result indicates your file system is functioning normally; otherwise, please check promptly.
1[root@instance-xxxx ~]# e2fsck -n /dev/vde1
2e2fsck 1.42.9 (28-Dec-2013)
3Warning! /dev/vde1 is mounted.
4Warning: skipping journal recovery because doing a read-only filesystem check.
5/dev/vde1: clean, 11/3276800 files, 251790/13106944 blocks
After completing these steps, you need to confirm the current operation type for the disk. The choice of operation type depends on the current state of the data disk, the mounted file system's status, and the desired partitioning method post-expansion. Based on these factors, choose the appropriate operation type.
| Data disk status | File system status | Expected partitioning form | Operation types |
|---|---|---|---|
| Partitioned | Created | When the existing partitioning method of the disk is MBR and you wish to expand the capacity of an existing partition | Expand the existing MBR disk partition |
| When the existing partitioning method of the disk is MBR and you wish to add the currently expanding region as an independent new MBR disk partition | Add a new MBR disk partition | ||
| When the existing partitioning method of the disk is GPT and you wish to expand the capacity of an existing partition | Expand the existing GPT disk partition | ||
| When the existing partitioning method of the disk is GPT and you wish to add the currently expanding region as an independent new GPT disk partition | Add a new GPT disk partition | ||
| Unpartitioned | Uncreated | You wish to complete the partitioning of the disk and create a file system | Format disk |
| Unpartitioned | Created | You wish to directly expand the file system based on the existing file system | Expand the file system of a raw device |
When your data disk is not partitioned and no file system is created, you need to format the disk. For details, see [Format Disk](CDS/Disk Operation Guide/Basic Operations/Format cloud disks/Overview.md). For the subsequent operation steps of other operation types, please click the corresponding operation name directly according to the directory on the right.
Expand the existing MBR disk partition
In this example, the existing partition is extended from 50 GB to 100 GB.
1. View the current mount target of the file system
Execute the command mount | grep "/dev/vde" to view the current mount target of the disk /dev/vde. After execution, the mount target will be displayed as /mnt.
1[root@instance-xxxx ~]# mount | grep "/dev/vde"
2/dev/vde1 on /mnt type ext4 (rw,relatime,data=ordered)
2. Unmount the current file system
1[root@instance-xxxx ~]# umount /dev/vde1
Description:
- To extend an existing MBR partition, unmount it first to avoid data loss, and then remount it after the extension process.
- If you're dealing with an unpartitioned disk (e.g., /dev/vde), follow these operations on the unpartitioned disk's drive letter (/dev/vde) to prevent data loss during the extension and remount it after the process is complete.
3. Adjust partition size
Execute the command fdisk /dev/vde to adjust the disk partition size. After entering the fdisk environment, enter the following commands in sequence:
- Enter p: Print the current partition table
- Enter d: Delete the current partition. When you see the message "Partition 1 selected, and partition 1 deleted" displayed, it confirms that the existing 50 GB partition has been deleted.
- Enter n: Create a new partition;
- Enter p: Select the partition type as primary;
- Enter the partition number: The current input value is the default value 1. You can also press Enter, and the system will directly select the current default value;
- Enter the starting sector position: The current input value is the default value 2048. You can also press Enter, and the system will directly select the current default value;
- Enter last sector position: You can press Enter, and the system will directly select the current default value;
- Enter w: Save changes and exit. At this stage, the partition size adjustment is complete, with the new partition expanded to 100 GB.
1[root@instance-xxxx ~]# fdisk /dev/vde
2 Welcome to fdisk (util-linux 2.23.2).
3 Changes will remain in memory until you decide to write them to the disk.
4 Think carefully before executing the write Command.
5 Command (enter m for help): p
6 Disk /dev/vde: 107.4 GB, 107,374,182,400 bytes, 209,715,200 sectors
7 Units = sectors of 1 * 512 = 512 bytes
8 Sector size (logical/physical): 512 bytes / 512 bytes
9 I/O size (min/optimal): 512 bytes / 512 bytes
10 Disk Tag Type: dos
11 Disk identifier: 0x63ffc036
12 Device Boot Start End Blocks Id System
13/dev/vde1 2048 104857599 52427776 83 Linux
14 Command (enter m for help): d
15 Partition 1 selected
16 Partition 1 deleted
17 Command (enter m for help): n
18Partition type:
19 p primary (0 primary, 0 extended, 4 free)
20 e extended
21Select (default p): p
22 Partition number (1-4, default 1):1
23 Starting sector (2048-209715199, default 2048): 2048
24 The default value 2048 will be used
25 Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199):
26 The default value 209715199 will be used
27 Partition 1 has been set to Linux type, with a size of 100 GiB
28 Command (enter m for help): w
29The partition table has been altered!
30Calling ioctl() to re-read partition table.
31 Synchronizing disk.
4. View partitions and check the file system
Execute the command lsblk /dev/vde to check whether the partition table has been added to the current file system. Below, you can see that the /vde1 partition table has been added.
Execute the command e2fsck -n /dev/vde1 to check whether the current file system status is clean.
1[root@instance-xxxx ~]# lsblk /dev/vde
2NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
3vde 253:64 0 100G 0 disk
4└─vde1 253:65 0 100G 0 part
5[root@instance-xxxx ~]# e2fsck -n /dev/vde1
6e2fsck 1.42.9 (28-Dec-2013)
7/dev/vde1: clean, 11/3276800 files, 251790/13106944 blocks
5. Notify the kernel to update the partition table
Execute the command partprobe /dev/vde to notify the kernel to synchronize the data disk partition table information.
6. Expand file system size
The disk uses the ext file system. You can execute the command resize2fs /dev/vde1 to expand the file system size. Then execute the command mount /dev/vde1 /mnt to mount the new partition to the /mnt node.
1[root@instance-xxxx ~]# resize2fs /dev/vde1
2resize2fs 1.42.9 (28-Dec-2013)
3Resizing the filesystem on /dev/vde1 to 26214144 (4k) blocks.
4The filesystem on /dev/vde1 is now 26214144 blocks long.
5[root@instance-xxxx ~]# mount /dev/vde1 /mnt
For xfs file systems, you need to execute the command mount /dev/vde1 /mnt/ first, and then execute the command xfs_growfs /dev/vde1 to complete file system expansion.
7. View the adjusted partition size
At this point, execute the command df -h to view the adjusted partition size. Below, you can see that the /dev/vde partition has been expanded to 100 GB and remounted to the /mnt node.
1[root@instance-xxxx~]# df -h
2 File system Capacity Used Available Used% Mount target
3/dev/vda1 40G 1.8G 36G 5% /
4devtmpfs 2.0G 0 2.0G 0% /dev
5tmpfs 2.0G 0 2.0G 0% /dev/shm
6tmpfs 2.0G 17M 2.0G 1% /run
7tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
8/dev/vde1 99G 60M 94G 1% /mnt
9tmpfs 396M 0 396M 0% /run/user/0
At this stage, you have successfully completed all operations required to extend the existing MBR disk partition and can now use the disk normally.
Add a new MBR disk partition
If you'd like to add the extended disk space as a new MBR disk partition, follow these steps. You don't need to unmount the existing file system on the disk; you can directly partition the newly added space and create a file system.
In this example, a new 100 GB partition 2 to the disk /dev/vdb is added while preserving the existing 100 GB partition 1 and its file system, and then a file system is created for the new partition.
1. Adjust partition size
Execute the command fdisk /dev/vdb to adjust the disk partition size. After entering the fdisk environment, enter the following commands in sequence:
- Enter p: Print the current partition table
- Enter n: Create a new partition;
- Enter p: Select the partition type as primary;
- Enter partition number: By default, the input value is 2, indicating the creation of a new partition numbered 2 alongside the existing partition 1. You can also press Enter to have the system automatically select the default value.
- Enter starting sector position: You can press Enter, and the system will directly select the current default value;
- Enter last sector position: You can press Enter, and the system will directly select the current default value;
- Enter w: Save changes and exit. At this stage, the size of the new partition 2 has been configured to 100 GB, while the original partition 1 remains at its previous size of 100 GB.
1[root@instance-xxxx ~]# fdisk /dev/vdb
2 Welcome to fdisk (util-linux 2.23.2).
3 Changes will remain in memory until you decide to write them to the disk.
4 Think carefully before executing the write Command.
5 Command (enter m for help): p
6 Disk /dev/vdb: 214.7 GB, 214,748,364,800 bytes, 419,430,400 sectors
7 Units = sectors of 1 * 512 = 512 bytes
8 Sector size (logical/physical): 512 bytes / 512 bytes
9 I/O size (min/optimal): 512 bytes / 512 bytes
10 Disk Tag Type: dos
11 Disk identifier: 0x63ffc036
12 Device Boot Start End Blocks Id System
13/dev/vdb1 2048 209715199 104856576 83 Linux
14 Command (enter m for help): n
15Partition type:
16 p primary (1 primary, 0 extended, 3 free)
17 e extended
18Select (default p): p
19 Partition number (2-4, default 2):
20 Starting sector (209715200-419430399, default 209715200):
21 The default value 209715200 will be used
22 Last sector, +sectors or +size{K,M,G} (209715200-419430399, default 419430399):
23 The default value 419430399 will be used
24 Partition 2 has been set to Linux type, with a size of 100 GiB
25 Command (enter m for help): w
26The partition table has been altered!
27Calling ioctl() to re-read partition table.
28 Synchronizing disk.
2. View partition
Execute the command lsblk /dev/vdb to view the partition, and you can see that the new partition dev/vdb2 has been added to the partition table.
1[root@instance-xxxx ~]# lsblk /dev/vdb
2NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
3vdb 253:16 0 200G 0 disk
4├─vdb1 253:17 0 100G 0 part /mnt
5└─vdb2 253:18 0 100G 0 part
3. Create and mount a file system for the new partition
Execute the command mkfs.ext4 /dev/vdb2 to create an ext4 file system for the new partition/dev/vdb2. After successful creation, you can execute the command mount /dev/vdb2 /xxx to mount the partition to the /xxx node. In this example, the new partition is mounted to the /mnt node.
1[root@instance-xxxx ~]# mkfs.ext4 /dev/vdb2
2mke2fs 1.42.9 (28-Dec-2013)
3 File System label=
4OS type: Linux
5 Block size=4096 (log=2)
6 Part size=4096 (log=2)
7Stride=0 blocks, Stripe width=0 blocks
86553600 inodes, 26214400 blocks
91310720 blocks (5.00%) reserved for the super user
10 First data block=0
11Maximum filesystem blocks=2174746624
12800 block groups
1332768 blocks per group, 32768 fragments per group
148192 inodes per group
15Superblock backups stored on blocks:
16 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
17 4096000, 7962624, 11239424, 20480000, 23887872
18 Allocating group tables: Done
19 Writing into inode table: Done
20 Creating journal (32768 blocks): Done
21 Writing superblocks and filesystem accounting information: Done
22[root@instance-xxxx ~]# mount /dev/vdb2 /mnt
4. View the adjusted partition size
At this point, execute the command df -h to view the adjusted partition size. Below, you can see that the /dev/vdb2
partition has been expanded to 100 GB and remounted to the /mnt node.
1[root@instance-xxxx ~]# df -h
2 File system Capacity Used Available Used% Mount target
3/dev/vda1 40G 1.8G 36G 5% /
4devtmpfs 2.0G 0 2.0G 0% /dev
5tmpfs 2.0G 0 2.0G 0% /dev/shm
6tmpfs 2.0G 17M 2.0G 1% /run
7tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
8/dev/vdb2 99G 61M 94G 1% /mnt
9tmpfs 396M 0 396M 0% /run/user/0
At this stage, you have successfully completed all operations required to expand the MBR disk partition and can now use the disk normally.
Expand the existing GPT disk partition
After completing disk expansion in the console, executing the command fdisk -l will display the current capacity of the disk as the expanded capacity. In this example, a /dev/vdb disk that has been partitioned by GPT is expanded. Prior to the following partitioning, the capacity of the disk has been expanded from 2000 GB to 2500 GB.
1. View the current mount target of the file system
Execute the command mount | grep "/dev/vdb" to view the current mount target of the disk /dev/vdb. After execution, the mount target will be displayed as /mnt.
1[root@instance-xxxx ~]# mount | grep "/dev/vdb"
2/dev/vdb on /mnt type ext4 (rw,relatime,data=ordered)
2. Unmount the current file system
1[root@instance-xxxx ~]# umount /dev/vdb
Description:
- To expand an existing GPT partition, unmount it first to avoid data loss, and then remount it after the expansion process.
3. Adjust partition size
You need to use the parted tool to expand the partition of the /dev/vdb disk. Please enter the following commands in sequence:
- Execute the command
parted /dev/vdbto expand the partition; - Execute the command
printto view partition number (number) and capacity (size) for expansion. In this example, the disk /dev/vdb/ is expanded from 2000 GB to 2500 GB, with the existing partition number being 1; - Execute the command
resizepart 1 100%to expand the partition. You may modify the partition number in the command statement as needed; - Execute the command
printto view the current partition number and capacity status.
1[root@instance-xxxx ~]# parted /dev/vdb
2GNU Parted 3.1
3 Use /dev/vdb
4Welcome to GNU Parted! Type 'help' to view a list of commands.
5(parted) print
6Model: Virtio Block Device (virtblk)
7Disk /dev/vdb: 2684GB
8Sector size (logical/physical): 512B/512B
9Partition Table: loop
10Disk Flags:
11 Number Start End Size File system Flags
12 1 0.00B 2684GB 2684GB ext4
13
14(parted) resizepart 1 100%
15(parted) print
16Model: Virtio Block Device (virtblk)
17Disk /dev/vdb: 2684GB
18Sector size (logical/physical): 512B/512B
19Partition Table: loop
20Disk Flags:
21 Number Start End Size File system Flags
22 1 0.00B 2684GB 2684GB ext4
23(parted) quit
24 Information: You may need to update /etc/fstab.
4. Mount the file system
- Execute the command
fsck -f /dev/vdb1to check the consistency of the file system; - If your file system is
ext, execute the commandresize2fs /dev/vdb1to expand the file system corresponding to the partition first, and then execute the commandmount /dev/vdb1 /mntto mount the file system to the/mntmount target. You may also mount it to other mount targets as needed, or create a new mount target viamkdir <mount target>; - If your file system is
xfs, first execute the commandmount /dev/vdb1 /mnt/, followed by the commandxfs_growfs /dev/vdb1.
The ext file system is used in the following example.
1[root@instance-xxxx ~]# fsck -f /dev/vdb1
2 fsck, from util-linux 2.23.2
3e2fsck 1.42.9 (28-Dec-2013)
4 Step 1: Check inode, block, and size
5 Step 2: Check the directory structure
6 Step 3: Check directory connectivity
7Pass 4: Checking reference counts
8 Step 5: Check cluster summary information
9/dev/vdb1: 11/131072000 files (0.0% non-contiguous), 8282274/524288000 blocks
10[root@instance-xxxx ~]# resize2fs /dev/vdb1
11resize2fs 1.42.9 (28-Dec-2013)
12Resizing the filesystem on /dev/vdb1 to 655360000 (4k) blocks.
13The filesystem on /dev/vdb1 is now 655360000 blocks long.
14[root@instance-hnl92ipp ~]# mount /dev/vdb1 /mnt
5. View the adjusted partition
After completing the above steps, you can execute the command df -h to view the adjusted partition.
Add a new GPT disk partition
If you'd like to add the additional disk space as a new GPT disk partition, follow these steps. The existing file system on the disk does not need to be unmounted; you can directly partition the new space and create a file system.
In this example, a new 500 GB partition 2 to the disk /dev/vdb1 is added while preserving the existing 2500 GB partition 1 and its file system, and then an ext file system is created for the new partition.
1. Adjust partition size
You need to use the parted tool to add a new partition to the disk by executing the command parted /dev/vdb. Execute the following commands in sequence for partitioning:
- Execute the command
printto view the current status of the data disk. At this point, the system will display a prompt. Enter Ignore to ignore it. At this point, the screen shows that the current capacity of the disk has been expanded to 3000 GB; - Record the end position of
/dev/vdb1at this time, i.e., the disk location corresponding to End, which serves as the starting position for the new partition. In this example, the end position of/dev/vdb1is 2147 GB; - Enter
mkpartto create a new partition. If the prompt continues to appear, please continue to ignore it; - Enter new partition name: In this example, enter 2;
- Enter the file system type for the new partition: In this example, enter
ext4, with the system default beingext2; - Enter the starting position of the new partition: In this example, 2147 GB;
- Execute the command
printto view the current disk status; - Execute the command
quitto exit the parted tool.
1[root@instance-xxxx ~]# parted /dev/vdb
2GNU Parted 3.1
3 Use /dev/vdb
4Welcome to GNU Parted! Type 'help' to view a list of commands.
5(parted) print
6 Warning: Not all of the space available to /dev/vdb appears to be used, you can fix the GPT to use all of the space (an extra 2097152000 blocks) or continue with the current setting?
7 Fix/Ignore? Ignore
8Model: Virtio Block Device (virtblk)
9Disk /dev/vdb: 3221GB
10Sector size (logical/physical): 512B/512B
11Partition Table: gpt
12Disk Flags:
13 Number Start End Size File system Name Flags
14 1 1049kB 2147GB 2147GB ext4 primary
15(parted) mkpart
16 Partition name? []? 2
17 File system type? [ext2]? ext4
18 Starting point? 2147GB
19 End point? 100%
20(parted) print
21Model: Virtio Block Device (virtblk)
22Disk /dev/vdb: 3221GB
23Sector size (logical/physical): 512B/512B
24Partition Table: gpt
25Disk Flags:
26 Number Start End Size File system Name Flags
27 1 1049kB 2147GB 2147GB ext4 primary
28 2 2147GB 3221GB 1074kB 2
29
30(parted) quit
2. Mount a file system for the new partition
You can execute the command mount /dev/vdb2 /xxx to mount the partition to the /xxx node. In this example, the new partition is mounted to the /mnt node.
1[root@instance-xxxx ~]# mount /dev/vdb2 /mnt
3. View the adjusted partition size
At this point, execute the command df -h to view the adjusted partition size.
At this stage, you have successfully completed all operations required to expand the GPT disk partition and can now use the disk normally.
Expand the file system of a raw device
If your data disk has no partition but already contains a file system, you can directly extend the file system on the disk.
1. If you have created an ext file system
Execute the command resize2fs with root permission to expand the file system.
1resize2fs /dev/vdb
2. If you have created an xfs file system
Execute the command xfs_growfs with root permission to expand the file system.
1xfs_growfs /dev/vdb
