Expand a GPT disk using cfdisk in Linux

cfdisk – a system utility for managing hard disk partitions in the Linux operating system. Similar to fdisk, but with a friendly user interface

Objective: you need to increase the size of the GPT disk / dev / sdb1 (file system type ext4)

  • Turn off the virtual machine,
  • We expand the required disk,
  • Turn on the virtual machine

Stop all services that store data in the mounted disk

$ sudo systemctl stop zabbix-server
$ sudo systemctl stop [email protected]

Unmount the disk

$ sudo umount /mnt/data

Checking

$ lsblk

Run the cfdisk utility

$ sudo cfdisk /dev/sdb

Expand a GPT disk using cfdisk in Linux 2

Free space appeared

Expand a GPT disk using cfdisk in Linux 3

Select the “Resize” option, specify the size (the default will be the size of the entire disk), write the changes (write option) and exit

Pros of the cfdisk utility:

  • it works correctly with gpt markup,
  • installed by default on Debian 8+, Centos 7+ distributions,
  • no need to delete the partition, as is done in “fdisk”

Mount partitions that we have previously unmounted

$ sudo mount -a

Checking that the disk has expanded

$ lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
fd0      2:0    1    4K  0 disk 
sda      8:0    0    8G  0 disk 
├─sda1   8:1    0  243M  0 part /boot
├─sda2   8:2    0  1.9G  0 part [SWAP]
└─sda3   8:3    0  5.9G  0 part /
sdb      8:16   0   36G  0 disk 
└─sdb1   8:17   0   36G  0 part /mnt/data
sr0     11:0    1 1024M  0 rom

As you can see, sdb1 – now 36 Gb

Checking the amount of used disk space

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            2.9G     0  2.9G   0% /dev
tmpfs           597M  8.1M  589M   2% /run
/dev/sda3       5.7G  2.7G  2.8G  49% /
tmpfs           3.0G   16K  3.0G   1% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           3.0G     0  3.0G   0% /sys/fs/cgroup
/dev/sda1       232M   71M  145M  33% /boot
tmpfs           597M     0  597M   0% /run/user/1002
/dev/sdb1        16G   12G  3.0G  81% /mnt/data

The size of the file system is displayed here 16 Gb

Expandable (for ext4)

$ sudo resize2fs /dev/sdb1
resize2fs 1.44.5 (15-Dec-2018)
Filesystem at /dev/sdb1 is mounted on /mnt/data; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 3
The filesystem on /dev/sdb1 is now 9436919 (4k) blocks long.

Checking

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            2.9G     0  2.9G   0% /dev
tmpfs           597M  8.1M  589M   2% /run
/dev/sda3       5.7G  2.7G  2.8G  49% /
tmpfs           3.0G   16K  3.0G   1% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           3.0G     0  3.0G   0% /sys/fs/cgroup
/dev/sda1       232M   71M  145M  33% /boot
tmpfs           597M     0  597M   0% /run/user/1002
/dev/sdb1        36G   12G   22G  36% /mnt/data

As you can see, the / dev / sdb1 partition has become 36 Gb

We start the services that we stopped earlier

$ sudo systemctl start [email protected]
$ sudo systemctl start zabbix-server
Sidebar