How to resize ext4 root partition live without umount - LinuxConfig.org

This article will focus on how to resize EXT4 root partition without unmount. This is an easy way for some system where you are unable to unmount root partition and the system can be recovered easily if something goes wrong like for example AWS instance.
This is a companion discussion topic for the original entry at https://linuxconfig.org/how-to-resize-ext4-root-partition-live-without-umount

Bouteillier Nicolas

To have the “a” option, (I am under ubuntu Artful) I have to use “x” to have the expert feature, and the “A” to toggle the old boot option

ГГ

last step required for me:

lvextend -r -l +100%FREE /dev/mapper/centos-root

Fen

Thanks, worked mostly as described.
At the end in df -h my old partition sized was printed.
I had to run resize2fs /dev/xvda1 to finally see the whole size in df -h

Gavin Baumanis

Hi there, everything seems to work for me up to the final “write”…
I recreate the partition and make it bootable, too…
Device Boot Start End Sectors Size Id Type
/dev/sda1p1 * 2048 81917951 81915904 39.1G 83 Linux

(it is now 40 GB vs the original 8 GB)

However when I run the final “write” of the partition. I get the following;
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: Invalid argument

The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8).

I am not sure what the invalid argument is - but after quitting fdisk and re-running fdisk, I get told that the partition is still set 40GB. So it seems like it is working… but after a reboot, the partition is reverted to only being 8 GB. - kinda…

sudo df -h .
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 7.4G 6.2G 859M 88% /

(it still reads as if it is only 8 GB in size?)

But fdisk reports at as being 40 GB but with only 1 GB free? It all seems a bit weird…
sudo fdisk -l

Disk /dev/sda: 39.1 GiB, 41943040000 bytes, 81920000 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x78e64ad4

Device Boot Start End Sectors Size Id Type
/dev/sda1 2048 81919999 81917952 39.1G 83 Linux

Any ideas? - Thanks!

Stefan -> Gavin Baumanis

Even if it’s a year since you asked, I’m going to answer, maybe someone will need it:
Just run “resize2fs /dev/sda1” and it will expand to the desired size.

Graeme Evans -> Stefan

helped me! so thanks :smiley:

I need to understand that this wouldn’t delete the existing linux and other files on this partition as /dev/xvda1 by deleting the partition during fdisk or will it. Thanks

Hi Kalpana,

Welcome to our forums.

This operation is dangerous in the way that is you do not set the starting sector right, you most likely will destroy your data. If you set it right, the data stays intact. fdisk does not touch the data itself, but manipulates the way to find it. If you loose the way to find your data, that’s hard times.

But as long as your new partition starts from the same sector, and is of the same type, your data should be safe, but don’t skip the step of taking a backup if it is important.

Thank you for your help.

Very well written! Worked exactly as anticipated