Linux resize partition after block storage size increase

In this article, we explain how to update partition settings after you have expanded block storage capacity on Linux.
After expanding the block storage capacity on your Cloud Server, you need to resize the partition manually.
Proceed with the following steps to resize the partition manually:Requirements

  • You have restarted the server after increasing the block storage size.
  • You have accessed your server as an administrator.

1 - Install the  growpart program .

On Ubuntu:

[root@localhost ~]# apt-get update
[root@localhost ~]# apt-get install cloud-initramfs-growroot
On CentOS 7 and CentOS 8:
[root@localhost ~]# yum install cloud-utils-growpart
2 - To view the block storage allocated to the server, enter the following command:
[root@localhost ~]# lsblk
After entering the command, you will be able to see all the important information about the existing storage devices and allocated block storage that you have resized.

[root@localhost ~]# lsblk
sda 8:0 0 100G 0 disk
├─sda1 8:1 0 512M 0 part /boot
└─sda2 8:2 0 99.5G 0 part
  ├─ centos-root 253:0 0 97.5G 0 lvm /
  └─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 40G 0 disk
└─sdb1 8:17 0 20G 0 part /mnt/block
sr0 11:0 1 1024M 0 rom
In the example above, a block storage has been allocated to the server, whose name is sdb and whose size has increased from 20 GB to 40 GB.

3 - Use the growpart command to expand the first block storage partition. Note that there is a space between the device name and the partition number.
[root@localhost ~]# growpart /dev/device-name 1
[root@localhost ~]# growpart /dev/sdb 1
4 - To configure the ext4 file system, enter the following command:
[root@localhost ~]# resize2fs -p /dev/sdb1
If the file system has not been resized, restart the server. Then enter the command resize2fs -p /dev/sdb1 again.

5 - To check the block storage space, enter the following command:
[root@localhost ~]# df -h
You can then see the new block storage size, for example:
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 17M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/mapper/centos-root 98G 2.3G 96G 3% /
/dev/sdb1 40G 48M 38G 1% /mnt/block
/dev/sda1 507M 228M 280M 45 % /boot
tmpfs 376M 0 376M 0% /run/user/0

No comments

Powered by Blogger.