Extend Disk Partition on Linux System Disk
Overview
As your business grows, your current disk capacity may no longer suffice for storing data. You can expand the disk to your desired capacity while retaining the existing data. Expanding the system disk typically involves rebooting the server after the order is processed, and manual partition expansion is generally not required. However, if the partition is not automatically expanded after rebooting, you will need to perform the expansion manually by following the steps below.
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 have any questions, please submit a Ticket in the console to contact professional technical service personnel;
- The maximum expansion limit for the system disk is 500 GB;
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. Install expansion tools
-
CentOS 6
- Install the dracut-modules-growroot package.
Plain Text1yum install -y dracut-modules-growroot- Run the following command to overwrite the initramfs file.
Plain Text1dracut -f -
CentOS 7、CentOS 8
- Install the cloud-utils-growpart and xfsprogs packages.
Plain Text1yum install -y cloud-utils-growpart xfsprogs -
Ubuntu 14、Ubuntu 16、Ubuntu 18、Debian 9
- Install the cloud-guest-utils and xfsprogs packages.
Plain Text1apt install -y cloud-guest-utils xfsprogs
3. Check current partition status and partitioning method
Execute fdisk -l to view the current partition size. The current system disk is /dev/sda, and the disk has been expanded from 40 GB to 100 GB.
1[root@instance-xxx ~]# fdisk -l
2Disk /dev/sda: 107.4 GB, 107374182400 bytes
3255 heads, 63 sectors/track, 13054 cylinders
4Units = cylinders of 16065 * 512 = 8225280 bytes
5Sector size (logical/physical): 512 bytes / 512 bytes
6I/O size (minimum/optimal): 512 bytes / 512 bytes
7Disk identifier: 0x000344b8
8 Device Boot Start End Blocks Id System
9/dev/sda1 * 1 5222 41942016 83 Linux
4. View file system type
Execute the command df -Th to view the current file system type. The current file system type of the system disk partition /dev/sda1 is ext4.
1[root@instance-xxx ~]# df -Th
2Filesystem Type Size Used Avail Use% Mounted on
3/dev/sda1 ext4 40G 1.1G 37G 3% /
4tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
5. Adjust partition size
Run the following command to expand the partition.
1growpart <DeviceName> <PartionNumber>
As an example, expand /dev/sda1.
1[root@instance-xxx ~]# growpart /dev/sda 1
2CHANGED: partition=1 start=2048 old: size=83884032 end=83886080 new: size=209710462,end=209712510
Restarting the instance after the operation is required for lower kernel versions (CentOS 6.x).
6. Expand file system
- For the ext file system, use resize2fs to expand the partition.
1[root@instance-xxx ~]# resize2fs /dev/sda1
2resize2fs 1.41.12 (17-May-2010)
3Filesystem at /dev/sda1 is mounted on /; on-line resizing required
4old desc_blocks = 3, new_desc_blocks = 7
5Performing an on-line resize of /dev/sda1 to 26213807 (4k) blocks.
6The filesystem on /dev/sda1 is now 26213807 blocks long.
- For the xfs file system, use xfs_growfs to expand the partition.
1[root@instance-xxx ~]# xfs_growfs /
7. Check expansion result
1[root@instance-xxx ~]# df -Th
2Filesystem Type Size Used Avail Use% Mounted on
3/dev/sda1 ext4 99G 1.1G 93G 2% /
4tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
