Extending an ext4 LVM partition

By Stephane Carrez 2 comments

From time to time a disk partition becomes full and it becomes desirable to grow the partition. Since I often don't remember how to do this, I wrote this short description to keep track of how to do it.

Extending the LVM partition

The first step is to extend the size of the LVM partition. This is done easily by using the lvextend (8) command. You just need to specify the amount and the LVM partition. In my case, the vg02-ext volume was using 60G and the +40G command will grow its size to 100G. Note that you can run this command while your file system is mounted (if you grow the size of your LVM partition).

$ sudo lvextend --size +40G /dev/mapper/vg02-ext Extending logical volume ext to 100.00 GiB Logical volume ext successfully resized

Preparing the ext4 filesystem for resize

Before resizing the ext4 filesystem, you must make sure it is not mounted:

$ sudo umount /ext

The file system must be clean and you should run the e2fsck (8) command to check it:

$ sudo e2fsck -f /dev/mapper/vg02-ext e2fsck 1.42 (29-Nov-2011) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/mapper/vg02-ext: 1974269/3932160 files (0.1% non-contiguous), 14942044/15728640 blocks 5.392u 1.476s 0:48.25 14.2% 0+0k 3208184+48io 2pf+0w

Resizing the ext4 filesystem

The last step is to resize the ext4 file system by using the resize2fs (8) command. The command can enlarge or shrink an unmounted file system of type ext2, ext3 or ext4. The command only needs the block device path to operate.

$ sudo resize2fs /dev/mapper/vg02-ext resize2fs 1.42 (29-Nov-2011) Resizing the filesystem on /dev/mapper/vg02-ext to 26214400 (4k) blocks. The filesystem on /dev/mapper/vg02-ext is now 26214400 blocks long.

After the resize, we can re-mount the ext4 partition:

$ sudo mount -a

Add a comment

To add a comment, you must be connected. Login

2 comments

stephane.carrez@gmail.com
Stephane Carrez on 2015-01-06 19:27:19 said:
I agree that a graphical tool is easier. You're right that I'm using Ubuntu but none of the 12 virtual machines I'm using have a GUI installed. Command line is also a lot easier to use for me when you have to run them on several machines...
darkquark99@gmail.com
darkquark99 on 2015-01-06 06:51:11 said:
Much simpler: since you are using sudo at every step I deduce you are using a derivative of Ubuntu. Since you are using supposedly user-friendly distribution just use the Volume manager or whatever is called there (I assume Ubuntu has one, Redhat/Suse/Mandriva have): it will resize both the volume and the filesystem in one _graphical_ operation: it is far easier and you are far less likely to mess up your filesystem and lose data than by doing it by hand. You should only do it by hand when you have no alternative like when you are forced to use putty from Windows since you cann't use graphical commands from it.