Java 2 Ada

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

To add a comment, you must be connected. Login to add a comment
  • Page 1