The difference between the LV state "inactivate"/"active" in Linux
Categories:
Understanding LVM Logical Volume States: 'active' vs. 'inactivate'

Explore the critical differences between 'active' and 'inactivate' states for Logical Volumes (LVs) in Linux LVM, and learn how to manage them effectively.
Logical Volume Management (LVM) in Linux provides a flexible way to manage disk space. A core concept in LVM is the state of a Logical Volume (LV), specifically whether it is 'active' or 'inactivate'. Understanding these states is crucial for proper system administration, data integrity, and troubleshooting. This article delves into what each state signifies, why it matters, and how to transition between them.
What is an 'active' Logical Volume?
An 'active' Logical Volume (LV) is one that is currently available for use by the operating system. When an LV is active, its underlying physical extents are mapped and accessible, allowing the kernel to recognize it as a block device. This means you can mount its filesystem, read from it, write to it, or use it as a raw block device for applications like databases or virtual machine disks. Activation typically happens automatically during system boot for LVs defined in /etc/fstab
or when explicitly activated by a system administrator.
sudo lvdisplay /dev/myvg/mylv
# --- Logical volume ---
# LV Path /dev/myvg/mylv
# LV Name mylv
# VG Name myvg
# LV UUID ...
# LV Write Access read/write
# LV Status available
# # open 1
# ...
sudo lvs -o lv_name,vg_name,lv_attr,lv_size,lv_health
# LV VG Attr LSize Health
# mylv myvg -wi-a----- 10.00g ok
Checking the status of an active Logical Volume using lvdisplay
and lvs
.
lv_attr
field in lvs
output provides detailed information. The fifth character, 'a', indicates an active LV. For example, -wi-a-----
means writeable, inherited, active, open.What is an 'inactivate' Logical Volume?
An 'inactivate' Logical Volume (LV) is one that exists within a Volume Group (VG) but is not currently accessible by the operating system as a block device. Its metadata is present, but the kernel does not have a device node for it, and its physical extents are not mapped. Inactivated LVs cannot be mounted, read from, or written to. This state is often used for maintenance, snapshots, or when an LV is temporarily not needed. Inactivating an LV is a safe way to take it offline without deleting its data.
sudo lvchange -an /dev/myvg/mylv
sudo lvdisplay /dev/myvg/mylv
# --- Logical volume ---
# LV Path /dev/myvg/mylv
# LV Name mylv
# VG Name myvg
# LV UUID ...
# LV Write Access read/write
# LV Status NOT available
# # open 0
# ...
sudo lvs -o lv_name,vg_name,lv_attr,lv_size,lv_health
# LV VG Attr LSize Health
# mylv myvg -wi------- 10.00g ok
Inactivating a Logical Volume and verifying its status.
Why and When to Change LV States?
The ability to activate and inactivate LVs provides significant flexibility in managing storage. Here are common scenarios:
- Maintenance: Inactivate an LV to perform filesystem checks (e.g.,
fsck
), resize operations, or move its underlying Physical Volumes (PVs) without affecting other LVs in the same VG. - Snapshots: LVM snapshots are often created from active LVs, and the snapshot itself can be activated/inactivated independently for backup or recovery purposes.
- Troubleshooting: If an LV is causing issues, inactivating it can help isolate the problem without taking down the entire system.
- Resource Management: Temporarily inactivate LVs that are not in use to free up kernel resources or prevent accidental access.
- Migration: When migrating data or moving LVs between systems, they are often inactivated on the source and then activated on the destination.
stateDiagram-v2 [*] --> Inactive Inactive --> Active: `lvchange -ay` Active --> Inactive: `lvchange -an` Active --> [*]: Unmount & Remove Inactive --> [*]: Remove (lvremove)
State diagram illustrating transitions between active and inactive LVM Logical Volume states.
Managing LV States: Commands and Best Practices
The primary command for managing LV states is lvchange
. It allows you to activate or inactivate LVs, either individually or all LVs within a Volume Group.
Activating an LV
To activate an LV, use the -ay
(activate yes) option. You can specify a single LV or an entire Volume Group.
Inactivating an LV
To inactivate an LV, use the -an
(activate no) option. Remember to unmount any filesystems first.
Best Practices:
- Always Unmount First: Before inactivating an LV that contains a filesystem, always unmount the filesystem to prevent data corruption.
- Verify State: After changing an LV's state, always verify it using
lvdisplay
orlvs
. - Consider Dependencies: Be aware of any applications or services that rely on the LV. Ensure they are stopped before inactivation and restarted after activation.
- Read-Only Activation: For recovery or inspection, you can activate an LV in read-only mode using
lvchange -ar
.
# Activate a specific Logical Volume
sudo lvchange -ay /dev/myvg/mylv
# Activate all Logical Volumes in a Volume Group
sudo vgchange -ay myvg
# Inactivate a specific Logical Volume
sudo umount /mnt/mylv # IMPORTANT: Unmount first!
sudo lvchange -an /dev/myvg/mylv
# Inactivate all Logical Volumes in a Volume Group
sudo vgchange -an myvg
# Activate an LV in read-only mode
sudo lvchange -ar /dev/myvg/mylv
Common lvchange
and vgchange
commands for managing LV states.