Create and verify a Linux logical volume with lvcreate
You will create a named, activated logical volume in an existing LVM volume group, check that the block device exists, and remove it safely when the test is over. Allow 10 minutes for an uncomplicated volume. The examples use LVM 2.03.16(2), installed by the local lvm2 package.
The route
Jump straight to the step you need, or tick off Done means at the end.
Checkpoint
Stop after step 2 if you do not have a volume group with enough free space.
1. Confirm the tools and the version
These are administrative operations. Run the inspection commands as your normal user first. Creating or removing volumes normally requires sudo, and the commands change block-device state.
$ command -v lvcreate
/usr/sbin/lvcreate
$ lvcreate --version
LVM version: 2.03.16(2) (2022-05-18)
The exact version matters when you compare this guide with another machine. This guide follows the installed lvcreate(8) interface; do not assume that a newer release has identical defaults.
2. Inspect the volume group before changing it
Choose an existing volume group and inspect its free space. Replace vg_data with a real name from your system.
$ vgs vg_data
$ sudo lvs vg_data
You need enough free physical extents for the requested logical volume. A standard volume takes physical space from the volume group. If there is not enough room, stop here: add a physical volume with vgextend, or choose a smaller size. Do not reduce an existing filesystem or logical volume merely to make this example fit.
Common trap: -L 10G requests a size, while -l 10 requests a number of logical extents. The manpage also permits percentage forms for --extents. Use the size form when you want a predictable human-readable capacity.
3. Create a named linear volume
Review the target one more time, then create the volume. This example makes a 10 GiB logical volume named lv_test. A linear volume is the default type. The command activates new logical volumes by default and may wipe recognised signatures when appropriate, so never point it at a volume containing data you need.
$ sudo lvcreate --name lv_test --size 10G vg_data
Logical volume "lv_test" created.
The volume group name is the final positional argument here. You can append physical-volume names when allocation must be restricted, but then all requested extents must fit on those physical volumes. A missing name is allowed: lvcreate generates a unique name beginning with lvol. Naming volumes explicitly makes later checks and recovery less error-prone.
4. Verify the logical volume and device path
Check the LVM record and the device-mapper path before putting a filesystem on the new device.
$ sudo lvs -o vg_name,lv_name,lv_attr,lv_size,devices vg_data
$ sudo lvdisplay /dev/vg_data/lv_test
$ test -b /dev/vg_data/lv_test && echo "block device is present"
block device is present
The canonical path is /dev/<volume-group>/<logical-volume>. The equivalent mapper path is usually under /dev/mapper, but scripts should prefer the stable LVM path or a path resolved by your device-management policy. If the block-device test fails, inspect lv_attr and activation policy instead of formatting anything.
5. Add a filesystem only when that is really the next action
Destructive warning: mkfs writes filesystem metadata and will destroy existing signatures on the target. Confirm the device path and size first. The following is an optional example for a newly created, empty volume:
$ sudo mkfs.ext4 /dev/vg_data/lv_test
$ sudo blkid /dev/vg_data/lv_test
Mounting is a separate change. If you mount it temporarily, unmount it before removal:
$ sudo mkdir -p /mnt/lv_test
$ sudo mount /dev/vg_data/lv_test /mnt/lv_test
$ findmnt /mnt/lv_test
$ sudo umount /mnt/lv_test
6. Remove the test volume and recover from mistakes
Irreversible action: removing a logical volume destroys its contents. Check mounts, open files and the exact LV name first. If the volume is mounted, unmount it. Then remove it and answer the confirmation prompt deliberately.
$ sudo lvs vg_data
$ sudo lvremove /dev/vg_data/lv_test
Logical volume "lv_test" successfully removed.
$ sudo lvs vg_data
If creation failed, read the error before retrying. Typical causes are an unknown volume group, insufficient free extents, a locked or shared volume group, or an unavailable device-mapper interface. Do not add --yes to bypass a prompt until you understand the command and have constrained it to the intended target. If you selected the wrong name but have not removed anything, stop and reassess; LVM has no general undo for a completed removal.
Done means
- The installed
lvcreateversion was checked. - The chosen volume group had sufficient free space.
- The new LV appeared in
lvswith the expected name and size. - The expected block-device path passed a block-device check.
- Any temporary filesystem was unmounted before removal.
- The test LV was removed only after its contents were no longer needed.