lvmchange
Modify attributes of LVM logical volumes
SYNOPSIS
lvmchange [OPTIONS] {LogicalVolumeName | LogicalVolumePath | VolumeGroupName/LogicalVolumeName}...
PARAMETERS
-a, --activate {y|n}
Activate (y) or deactivate (n) a logical volume. This is one of the most frequently used options.
-l, --persistent {y|n}
Set the persistent activation state for the logical volume. If 'y', the LV will be automatically activated on system startup; if 'n', it won't.
-p, --permission {r|rw}
Set the access permission of the logical volume to read-only (r) or read/write (rw).
--readahead {auto|None|Number}
Set the read-ahead size for the logical volume. 'auto' lets the kernel decide, 'None' disables it, or specify a 'Number' of 512-byte sectors.
-Z, --zero {y|n}
Controls whether to zero the first 4KB of a new data segment. This is usually done automatically but can be explicitly controlled.
-s, --rebuildmirror
Rebuilds a faulty mirror logical volume. This option is specific to LVM RAID/mirror volumes.
-C, --cleared {y|n}
Mark a RAID or mirror logical volume as cleared. This can be used after a manual rebuild or recovery operation.
-m, --monitor {y|n}
Enables (y) or disables (n) monitoring of a RAID logical volume by dmeventd (device-mapper event daemon).
-P, --partial
Allows commands to proceed with a partial view of the LVM system. Useful in clustered environments where not all PVs might be visible.
--setactivationskip {y|n}
Set the activation skip flag for a logical volume. If 'y', LVM will skip activation of this LV during a normal 'vgchange -a y' operation.
DESCRIPTION
lvmchange is a fundamental command within the Logical Volume Manager (LVM) suite in Linux. Its primary function is to control the activation and deactivation state of logical volumes (LVs).
When a logical volume is activated, LVM creates a device node (typically in /dev/mapper/) making the volume accessible for read/write operations by the kernel and applications, such as mounting a filesystem or using it as a raw block device. Conversely, deactivating an LV unmaps the device, rendering it inaccessible.
This command is essential for managing the availability of storage resources. Common scenarios include:
- Bringing logical volumes online during system boot.
- Taking volumes offline before maintenance, backups, or snapshot operations.
- Managing the state of logical volumes in clustered environments where shared storage is used.
- Modifying various properties of an LV, such as its read-ahead size, permissions, or its persistent activation behavior across reboots.
Proper use of lvmchange ensures that LVM-managed storage is available when needed and safely taken offline when not.
CAVEATS
- Always unmount filesystems before deactivating their underlying logical volumes (using -a n) to prevent data corruption.
- Incorrect usage of lvmchange, especially with options like --zero or --cleared, can lead to data loss or integrity issues if not fully understood.
- When using --persistent y, ensure the logical volume is intended to be activated on every boot.
- In clustered LVM environments, ensure proper fencing and coordination to avoid split-brain scenarios when activating/deactivating shared LVs.
- Requires root privileges to execute.
ACTIVATION MODES
When activating logical volumes, LVM supports different modes, often controlled globally by lvm.conf or explicitly by options:
- complete: All components (e.g., all mirror legs, all PVs) must be present for activation.
- degraded: Allows activation even if some components are missing (e.g., a missing mirror leg in a RAID1 volume).
- partial: Activates even if some PVs belonging to the VG are missing from the system. This is often used with the -P option.
- systemid: Activates volumes matching the local system ID.
INTERACTION WITH SYSTEM STARTUP
Logical volumes marked with --persistent y are typically activated automatically during system boot by an init script or systemd service that runs vgchange -a y or lvchange -a y for all volumes. Deactivating a volume with -a n does not inherently prevent its re-activation on next boot if --persistent y is set; to prevent activation on boot, you must explicitly use lvchange --persistent n for that volume.
HISTORY
lvmchange has been a core component of the LVM (Logical Volume Manager) suite since its early versions, providing essential functionality for managing the operational state of logical volumes. Its role has remained consistently vital in the evolution of LVM on Linux, adapting to new features like RAID volumes and clustered LVM, while maintaining its fundamental purpose of activation and deactivation.