LFCS Storage Management with LVM Questions and Answers — Questions and Answers
Question 1: A system administrator needs to create a new 10GB logical volume named `data_lv` within the `storage_vg` volume group. Which of the following commands correctly accomplishes this task?
- vgcreate -L 10G -n data_lv storage_vg
- pvcreate --size 10G --name data_lv storage_vg
- lvextend -L 10G -n data_lv storage_vg
- lvcreate -L 10G -n data_lv storage_vg (Correct answer)
Correct answer: lvcreate -L 10G -n data_lv storage_vg
The `lvcreate` command is used to create a new logical volume within an existing volume group. The `-L` option specifies the size of the logical volume, and the `-n` option specifies its name. The final argument is the name of the volume group from which the space will be allocated.
Question 2: You are managing a server with LVM and need to add a new physical disk, `/dev/sdd`, to an existing volume group named `data_vg`. Which sequence of commands is the correct way to achieve this?
- vgextend data_vg /dev/sdd; pvcreate /dev/sdd
- lvcreate /dev/sdd; vgextend data_vg /dev/sdd
- pvcreate /dev/sdd; vgextend data_vg /dev/sdd (Correct answer)
- pvcreate /dev/sdd; lvextend data_vg /dev/sdd
Correct answer: pvcreate /dev/sdd; vgextend data_vg /dev/sdd
First, the disk `/dev/sdd` must be initialized as a physical volume using `pvcreate /dev/sdd`. Once it is recognized by LVM, it can be added to the volume group `data_vg` using the `vgextend data_vg /dev/sdd` command.
Question 3: A logical volume `web_lv` in volume group `web_vg` is running out of space. The volume group has 20GB of free space. You need to add 5GB to the logical volume and resize the underlying ext4 filesystem simultaneously. Which command should you use?
- lvextend -L +5G /dev/web_vg/web_lv && resize2fs /dev/web_vg/web_lv
- lvresize -L 5G --resizefs /dev/web_vg/web_lv
- lvextend -L +5G --resizefs /dev/web_vg/web_lv (Correct answer)
- vgextend -L +5G /dev/web_vg/web_lv
Correct answer: lvextend -L +5G --resizefs /dev/web_vg/web_lv
The `lvextend` command is used to increase the size of a logical volume. The `-L +5G` option specifies that 5GB should be added to the current size. The `--resizefs` (or `-r`) flag is crucial as it automatically resizes the filesystem within the logical volume after the extend operation is successful, avoiding a separate step.
Question 4: Which of the following commands provides a verbose, multi-line output detailing the properties of all physical volumes known to the system?
- pvs
- pvdisplay (Correct answer)
- pvscan
- pvreport
Correct answer: pvdisplay
The `pvdisplay` command provides a detailed, verbose output for each physical volume, showing properties like PV name, VG name, size, PE size, total PEs, free PEs, and UUID. `pvs` provides a configurable, one-line summary, and `pvscan` scans for physical volumes on block devices.
Question 5: A system administrator needs to perform a risky software upgrade and wants to create a point-in-time snapshot of the logical volume `/dev/main_vg/app_lv` before proceeding. The snapshot should be named `app_snap` and be allocated 2GB of space for changes. What is the correct command?
- lvcreate -L 2G -n app_snap /dev/main_vg/app_lv
- lvsnapshot -L 2G --name app_snap /dev/main_vg/app_lv
- lvcreate -L 2G -s -n app_snap /dev/main_vg/app_lv (Correct answer)
- vgcreate --snapshot -L 2G -n app_snap /dev/main_vg/app_lv
Correct answer: lvcreate -L 2G -s -n app_snap /dev/main_vg/app_lv
The `lvcreate` command with the `-s` or `--snapshot` option is used to create a snapshot of an existing logical volume. The `-L` option specifies the size of the snapshot volume (for storing changes), `-n` provides the name, and the final argument is the path to the original logical volume.
Question 6: An administrator needs to reduce the size of the logical volume `archive_lv` in the `backup_vg` volume group by 10GB. The logical volume contains an ext4 filesystem that must be shrunk first to avoid data loss. Which command safely accomplishes both the filesystem and logical volume reduction?
- lvreduce -L 10G /dev/backup_vg/archive_lv
- lvextend -L -10G --resizefs /dev/backup_vg/archive_lv
- lvreduce -L -10G --resizefs /dev/backup_vg/archive_lv (Correct answer)
- lvshrink -L 10G --resizefs /dev/backup_vg/archive_lv
Correct answer: lvreduce -L -10G --resizefs /dev/backup_vg/archive_lv
The `lvreduce` command is used to decrease the size of a logical volume. Using `-L -10G` specifies reducing the size by 10GB. The `--resizefs` option is critical because it first attempts to shrink the filesystem, and only if that is successful does it proceed to shrink the logical volume, which is the correct and safe order of operations.
A system administrator needs to create a new 10GB logical volume named `data_lv` within the `storage_vg` volume group.
Which of the following commands correctly accomplishes this task?