CentOS / RHEL : Resize (extend) non-root EXT3/4 filesystem on LVM device

Backup all data on filesystem to be resized

Resizing a filesystem and underlying devices is dangerous and potentially destructive if performed incorrectly. Repartitioning devices is similarly destructive and may result in complete data loss. Before proceeding, backup the contents of the filesystem/device to be resized.

Resizing (extending) non-root EXT3/4 filesystem on LVM device

1. Example Setup
In this example, a Volume Group (VG) called VolGroupData of size 20Gb contains a Logical Volume (LV) called LogVolData01 of size 10Gb with an EXT3/4 filesystem (/data) utilising all space within the Logical Volume. Both the LV and EXT3/4 filesystem are resized (extended).

Before proceeding, run the following commands – record output for later use.

# fdisk -l /dev/sdb

Disk /dev/sdb: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 2610 20964793+ 8e Linux LVM
# cat /proc/partitions | grep sdb
   8    16  20971520 sdb
   8    17  20964793 sdb1
# pvs
PV         VG           Fmt  Attr PSize  PFree
/dev/sdb1  VolGroupData lvm2 a-   19.99G 9.99G
# vgs
VG           #PV #LV #SN Attr   VSize   VFree
VolGroupData   1   1   0 wz--n- 19.99G 9.99G
# lvs
LV           VG           Attr   LSize  Origin Snap%  Move Log Copy%  Convert
LogVolData01 VolGroupData -wi-ao 10.00G
# df -k /dev/mapper/VolGroupData-LogVolData01
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/VolGroupData-LogVolData01
                      10321208   9600672    196248  98% /data

2. Unmount the filesystem
Unmount the EXT3/4 filesystem to be resized e.g.:

# umount /data

3. Perform a filesystem check
Perform a filesystem check of the resized EXT3/4 filesystem ensuring to use the corresponding filesystem check utility (fsck.ext3, fsck.ext4) for the filesystem type in use e.g.:

# blkid /dev/VolGroupData/LogVolData01
/dev/VolGroupData/LogVolData01: LABEL="/data" UUID="1fc0bbcd-ba86-40b6-b562-5da90fb0d7af" TYPE="ext3"
# fsck.ext3 -fy /dev/VolGroupData/LogVolData01
e2fsck 1.39 (29-May-2006)
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
data: 20/1294336 files (5.0% non-contiguous), 2440792/2580302 blocks

4. Resize (extend) the Logical Volume
Use the lvextend or lvresize utility to extend the Logical Volume to use available space in the Volume Group e.g.:

# lvextend -L 15G /dev/VolGroupData/LogVolData01
  Extending logical volume LogVolData01 to 15.00 GB
  Logical volume LogVolData01 successfully resized

5. Verify Logical Volume resize
Verify Logical Volume resize e.g.:

# vgs
VG           #PV #LV #SN Attr   VSize  VFree
VolGroupData  1    1   0 wz--n- 19.99G 4.99G
# lvs
LV           VG           Attr   LSize  Origin Snap%  Move Log Copy%  Convert
LogVolData01 VolGroupData -wi-a- 15.00G
# lvs --units m
LV           VG           Attr   LSize     Origin Snap%  Move Log Copy%  Convert
LogVolData01 VolGroupData -wi-a- 15360.00M

6. Perform a filesystem check
Perform a filesystem check of the resized EXT3/4 filesystem ensuring to use the corresponding filesystem check utility (fsck.ext3, fsck.ext4) for the filesystem type in use e.g.:

# fsck.ext3 -fy /dev/VolGroupData/LogVolData01 
e2fsck 1.39 (29-May-2006)
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
data: 20/1310720 files (5.0% non-contiguous), 2441306/2621440 blocks

7. Resize (extend) the filesystem
Use the resize2fs utility to extend the EXT3/4 filesystem to use the additional space in the Logical Volume e.g.:

# resize2fs /dev/VolGroupData/LogVolData01 
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/VolGroupData/LogVolData01 to 3932160 (4k) blocks.
The filesystem on /dev/VolGroupData/LogVolData01 is now 3932160 blocks long.
Note: when running resize2fs, if no size is specified, the filesystem will be extended to utilise all available/remaining space in the partition.

8. Mount the resized filesystem
Mount the newly EXT3/4 resized filesystem e.g.:

# mount /data

9. Verify filesystem resize
Review dmesg, messages log, df command output, etc. to verify successful EXT3/4 filesystem resize e.g.:

# df -k /dev/mapper/VolGroupData-LogVolData01 
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/VolGroupData-LogVolData01
                      15481840   9603228   5092180  66% /data
Related Post