Extend Linux ext4 disk with cfdisk

There are times when you need to extend a disk to accommodate more data or improve performance. While using UI tools to extend disks can make the process easier and more intuitive, there are situations where these tools aren’t available. In such cases, knowing how to extend a disk using command-line tools can be invaluable. This post will guide you through the process of extending a disk without the need for graphical interfaces like gparted.

TLDR;

swapoff /dev/sda5
cfdisk
resize2fs /dev/sda1
mkswap /dev/sda5

swapon /dev/sda5
blkid /dev/sda5
nano /etc/fstab

Full procedure

First check the current partition structure with lsblk

As you can see you have 65G total but only 15GB on /

Start cfdisk


As you can see I cannot extend the disk because of the swap partition. So disable the swap first:

sudo swapoff /dev/sda5

Then start cfdisk to remove the extended and the swap partitions and extend the /dev/sda1

In my case I reseverd 1GB for the new swap.

Then create a new extended /dev/sda2 (max size) partition and within the extended partition a new swap partition /dev/sda5

Change the type of the swap partition to 82 Linux Swap / Solaris

So the partition structure looks like:

Give a write and exit the cfdisk tool

Now you can extend the /dev/sda1 partition with: resize2fs /dev/sda1

As you can see the partition is extended. Now can can reactivate your swap partition

First check the current status

Enter the commands:

  • mkswap /dev/sda5
  • swapon /dev/sda5

And as you can see the swap is actived

last thing you need to do is change the fsab to when the system reboots everything still works 😉

Get the UUID with blkid /dev/sda5

Edit the fstab file: nano /etc/fstab and change the UID to the new ID

That’s all. Happy resizing 🙂

Author: Thomas Faddegon

Do you like my posts and want to do something back? You can buy me a beer :) Â