Linux+ Logical Volume Management (LVM) Questions and Answers 1 — Questions and Answers
Question 1: In the Logical Volume Management (LVM) hierarchy, which component serves as a pool of storage created from one or more Physical Volumes, from which Logical Volumes are then allocated?
- Physical Extent (PE)
- Volume Group (VG) (Correct answer)
- Logical Volume (LV)
- Filesystem
Correct answer: Volume Group (VG)
A Volume Group (VG) is a fundamental LVM component that pools one or more Physical Volumes (PVs) together, creating a single storage pool from which Logical Volumes (LVs) can be created.
Question 2: A system administrator needs to shrink a logical volume named `/dev/datavg/archives` from 100G to 80G. What is the most critical prerequisite step that MUST be performed *before* running the `lvreduce` command?
- Run `vgreduce` to ensure the Volume Group has sufficient free space.
- Deactivate the logical volume using `lvchange -an`.
- Resize the filesystem on the logical volume to be smaller than or equal to 80G. (Correct answer)
- Create a temporary snapshot of the logical volume.
Correct answer: Resize the filesystem on the logical volume to be smaller than or equal to 80G.
It is critical to shrink the filesystem (e.g., using `resize2fs` for ext4) before shrinking the logical volume. Failure to do so will result in data loss, as the `lvreduce` command will cut off the end of the volume, destroying any filesystem data that resides in that space.
Question 3: A new disk, `/dev/sdd`, has been added to a server. A Linux administrator needs to add this disk's capacity to an existing Volume Group named `vg_data`. Which sequence of commands is the correct way to accomplish this?
- 1. `lvcreate /dev/sdd` 2. `vgextend vg_data /dev/sdd`
- 1. `pvcreate /dev/sdd` 2. `vgextend vg_data /dev/sdd` (Correct answer)
- 1. `vgcreate vg_data /dev/sdd`
- 1. `pvcreate /dev/sdd` 2. `lvresize vg_data /dev/sdd`
Correct answer: 1. `pvcreate /dev/sdd` 2. `vgextend vg_data /dev/sdd`
The correct procedure is to first initialize the disk as a Physical Volume (PV) using `pvcreate`. Once the disk is prepared for LVM, it can then be added to an existing Volume Group (VG) using the `vgextend` command.
Question 4: Which of the following commands is used to create a 5GB point-in-time snapshot named `webapp_backup` for the logical volume `/dev/vg_apps/lv_webapp`?
- `lvcreate -L 5G -n webapp_backup /dev/vg_apps/lv_webapp`
- `snapcreate -L 5G -n webapp_backup /dev/vg_apps/lv_webapp`
- `vgcreate -s -L 5G -n webapp_backup /dev/vg_apps/lv_webapp`
- `lvcreate -s -L 5G -n webapp_backup /dev/vg_apps/lv_webapp` (Correct answer)
Correct answer: `lvcreate -s -L 5G -n webapp_backup /dev/vg_apps/lv_webapp`
The `lvcreate` command is used for creating logical volumes, and the `-s` or `--snapshot` option specifically designates the new LV as a snapshot of an existing origin LV. The `-L` option sets the size, and `-n` provides the name.
Question 5: A logical volume `/dev/vg01/lv_logs` is full. The volume group `vg01` has 20GB of free space. Which command will extend the logical volume to use all available free space in the volume group and resize its ext4 filesystem in a single operation?
- `lvextend -l +100%FREE -r /dev/vg01/lv_logs` (Correct answer)
- `lvresize --size +100%FREE /dev/vg01/lv_logs && fsadm resize /dev/vg01/lv_logs`
- `vgextend -l +100%FREE /dev/vg01/lv_logs`
- `lvextend -L +20G /dev/vg01/lv_logs`
Correct answer: `lvextend -l +100%FREE -r /dev/vg01/lv_logs`
The `lvextend` command with the `-l +100%FREE` option tells LVM to allocate all remaining free extents in the volume group to the specified logical volume. The `-r` or `--resizefs` option then automatically resizes the filesystem to fill the newly enlarged volume, making it a convenient single-step operation.
Question 6: Which command would you use to display a detailed, multi-line report of the attributes for a specific Physical Volume, such as `/dev/sda2`?
- `pvs /dev/sda2`
- `lvmdiskscan`
- `pvdisplay /dev/sda2` (Correct answer)
- `vgdisplay /dev/sda2`
Correct answer: `pvdisplay /dev/sda2`
The `pvdisplay` command provides detailed, verbose information about a Physical Volume, including its name, the VG it belongs to, its size, PE size, and UUID. In contrast, `pvs` provides a brief, one-line summary.
In the Logical Volume Management (LVM) hierarchy, which component serves as a pool of storage created from one or more Physical Volumes, from which Logical Volumes are then allocated?