CompTIA Linux+ (XK0-006)System ManagementMedium
A technician runs 'lsblk' on a server and notices a logical volume /dev/vg_data/lv_apps is mounted at /opt/apps but the underlying volume group vg_data has 20GB of free (unallocated) extents. Management wants the mounted filesystem grown by 10GB without unmounting it, and the filesystem is ext4. Which sequence of commands correctly accomplishes this?
- Alvcreate -L 10G -n lv_apps2 vg_data && mount /dev/vg_data/lv_apps2 /opt/apps
- Bvgextend vg_data /dev/sdb1 && mkfs.ext4 /dev/vg_data/lv_apps
- Clvextend -L +10G /dev/vg_data/lv_apps && resize2fs /dev/vg_data/lv_apps
- Dpvresize /dev/vg_data/lv_apps && reboot
Show answer & explanationAnswer & explanation
Correct answer: C. lvextend -L +10G /dev/vg_data/lv_apps && resize2fs /dev/vg_data/lv_apps
Since free space already exists in the volume group, the correct approach is to extend the logical volume with 'lvextend -L +10G' and then grow the ext4 filesystem online with 'resize2fs' so it uses the new space, all without unmounting.
Why the other options are wrong
- A. Creating a new separate LV doesn't grow the existing mounted filesystem at /opt/apps.
- B. vgextend adds a new physical volume, not needed since free space already exists, and mkfs.ext4 would destroy existing data.
- D. pvresize is used to resize a physical volume after its underlying partition/disk changes, not to grow a logical volume, and rebooting is unnecessary.
Online ext4 Logical Volume Extension
To grow a mounted ext4 filesystem on LVM without downtime, extend the logical volume with lvextend, then resize the filesystem with resize2fs.
- lvextend -L +10G adds 10GB to the logical volume
- resize2fs grows ext4 to fill the extended LV, and can run online
- XFS filesystems use xfs_growfs instead of resize2fs
Memory trick: lvextend then resize2fs = 'stretch the box, then stretch the contents inside'