Enlarge ext4 partition on linux while system keeps running


On my own Linux web server I often have the “problem” that the data partition becomes too small. Databases and log files grow with the websites. And one is too stingy to order a generously dimensioned volume for one’s server ­čśë .

Therefore, it often happens that the monitoring reports an almost full partition and I then have to act so that the server does not stop at some point. I don’t want to shut down or restart the server.

Translated with www.DeepL.com/Translator (free version)


Fortunately, this is quite easy with an ext4 formatted partition under Linux. Here are the steps

  1. First, of course, you have to physically enlarge the volume. Fortunately, this can be done with 2 clicks with my cloud provider gridscale.
  2. Then open the parted programme on the affected volume, e.g. with parted /dev/sda (if parted is not installed, you have to do this according to your distribution, e.g. with apt install parted or yum install parted or apk add parted).
  3. Now let parted print the information about the current partitions and the volume with the command print
  4. Continue with the parted command resizepart [number of the partition to be resized]. After Enter, parted warns you that the partition is currently being used, but you can ignore this.
    NOTE: If you have several partitions on this volume and the partition to be resized is not the last partition, it may not be so easy. If there is only a swap partition or other unimportant partition behind the partition, you can of course simply delete it and restore it at the end. For more complicated cases, I recommend this article: https://codesilence.wordpress.com/2013/03/14/live-resizing-of-an-ext4-filesytem-on-linux/
  5. parted now asks where the end of the partition should go. Ideally, this is the size of the entire volume (displayed in the print command). If you have deleted a swap partition before, you have to subtract the space needed for the swap and then create the swap partition again.
  6. With Enter the partition is resized and you can quit parted with quit.
  7. But the partition is still not really grown – as e.g. a df -H shows, at least Linux has not noticed that yet. Finally, the command resize2fs /dev/sda1 (where instead of “/dev/sda1” you have to enter your volume (here “/dev/sda” for the first SATA drive) + the partition number starting at 1 (here “1”)) will help.
  8. After this command, a df -H should now show you the enlarged partition and the server should continue to run as if nothing had happened.

Translated with www.DeepL.com/Translator (free version)

A Terminal Session showing the parted commands


Dad, Husband, Web-Developer, Hobbyist, hobby gardener

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

WordPress Cookie Notice by Real Cookie Banner