pvcreate command to initialize a block device as an LVM physical volume. The following example uses /dev/vdb:pvcreate writes LVM labels and metadata to the target device. If a file system or other signatures already exist on the device, continuing the operation may destroy the original data. Before proceeding, confirm that the target device is correct and that you have backed up any data you need to keep.pvcreate /dev/vdb
Physical volume "/dev/vdb" successfully created.
WARNING: ext4 signature detected on /dev/vdb at offset 1080. Wipe it? [y/n]:
pvdisplay command displays attribute information of a Physical Volume, including its name, UUID, size, status, and allocation details.pvdisplay /dev/vdb
--- Physical volume ---PV Name /dev/vdbVG Name testPV Size 200.00 GiB / not usable 4.00 MiBAllocatable yesPE Size 4.00 MiBTotal PE 51199Free PE 51199Allocated PE 0PV UUID gQB42U-IKt2-517n-RB3q-p9ob-bAz7-Ggvjtd
pvdisplay command directly without any parameters to list information about all physical volumes in the system. You can also specify one or more physical volume names as parameters to display information only for the specified physical volumes. The output of the pvdisplay command includes the following information:pvs command displays the status of physical volumes:pvs
PV VG Fmt Attr PSize PFree/dev/vdb test lvm2 a-- <200.00g <200.00g
pvchange command is a command in LVM (Logical Volume Manager) on Linux systems, used to change the attributes of a physical volume. The following describes how to use the pvchange command:pvchange [options] [PhysicalVolumePath...]
PhysicalVolumePath is the path of the physical volume whose attributes you want to change. You can specify multiple physical volume paths, separated by spaces. The following are some common options:-a, --all: Change the attributes of all physical volumes.-x, --allocatable y/n: Set whether the physical volume is allocatable. y indicates allocatable, and n indicates not allocatable.-t, --test: Test mode. It does not actually change the attributes of the physical volume, but displays the operations that would be performed.pvchange command, back up important data and proceed with caution to avoid data loss or other unnecessary damage./dev/sdb1 to non-allocatable (you must first assign it to a logical volume group, and the same applies below):pvchange -x n /dev/sdb1
pvchange -x y -a
/dev/sdb1 to non-allocatable:pvchange -x n -t /dev/sdb1
pvremove /dev/vdb
Labels on physical volume "/dev/vdb" successfully wiped.
vgcreate command creates a Volume group (VG) and adds one or more physical volumes (PV) to it. Before execution, confirm that the target physical volumes have been initialized by pvcreate and are not used by any other Volume group.myvg and adds the physical volume /dev/sdb1 to it:vgcreate myvg /dev/sdb1
Volume group "myvg" successfully created
vgcreate myvg /dev/sdb1 /dev/sdc1 /dev/sdd1
-s, --physicalextentsize: Specifies the size of the physical extent (PE).-l, --maxlogicalvolumes: Specifies the maximum number of logical volumes that can be created in the volume group.-p, --maxphysicalvolumes: Specifies the maximum number of physical volumes that the volume group can contain.-A, --autobackup y|n: Specifies whether to automatically back up volume group metadata after changes. It is recommended to keep this option set to y.myvg with a PE size of 16 MiB:vgcreate -s 16M myvg /dev/sdb1
vgdisplay myvg or vgs myvg to verify the volume group status. The PE size is difficult to adjust after the volume group is created, so plan it properly based on your business needs before creation.vgdisplay command is used to view detailed information about a volume group, including its UUID, size, status, number of physical volumes, number of logical volumes, and free PEs. The following example views the volume group myvg:vgdisplay myvg
--- Volume group ---VG Name myvgVG Status resizableCur LV 0Cur PV 1VG Size <200.00 GiBPE Size 4.00 MiBTotal PE 51199Alloc PE / Size 0 / 0Free PE / Size 51199 / <200.00 GiB
vgs
VG #PV #LV #SN Attr VSize VFreemyvg 1 0 0 wz--n- <200.00g <200.00g
VG Status, Cur PV, Cur LV, VG Size, and VFree.vgchange command is used to modify attributes of a volume group and its logical volumes, such as the activation status and whether the volume group allows adding or removing physical volumes. Common options are as follows:-a, --activate y|n|ay: Activates or disables logical volumes in the volume group. y means activate, n means disable, and ay means automatically activate.-x, --resizeable y|n: Allows or prohibits adding or removing physical volumes through vgextend and vgreduce.-u, --uuid: Generates a new random UUID for the volume group. Before modifying the UUID, ensure that the volume group is inactive.myvg (no output is returned on success):vgchange -a n myvg
myvg:vgchange -a y myvg
1 logical volume(s) in volume group "myvg" now active
lvs -o lv_name,vg_name,lv_attr to verify the activation status of the logical volume.vgextend command is used to add one or more physical volumes to an existing volume group, thereby increasing the space that the volume group can allocate to logical volumes. Before doing so, confirm that the devices to be added are not used by other volume groups./dev/sdc1 to the volume group myvg:vgextend myvg /dev/sdc1
Volume group "myvg" successfully extended
vgextend myvg /dev/sdc1 /dev/sdd1
-A, --autobackup y|n: Specifies whether to automatically back up volume group metadata after changes. It is recommended to keep this option set to y.-t, --test: Performs a test operation without writing volume group metadata.-v, --verbose: Displays detailed execution information.vgcreate -s at creation time and cannot be modified through vgextend. After the extension is complete, run the following command to verify the volume group space:vgs myvg
vgreduce command is used to remove one or more unused physical volumes from a volume group. If the physical volume to be removed still contains allocated PEs, use pvmove first to migrate data to other physical volumes in the same volume group.pvs -o pv_name,pv_used to confirm that the PUsed value of the target physical volume is 0, and back up important data.vgreduce [options] <VG> <PV> [<PV>...]
<VG> represents the volume group name, and <PV> represents the path of the physical volume to be removed. Common options are as follows:-a, --all: Removes all physical volumes in the volume group that are free and do not contain data.-f, --force: Forces the operation, which may cause data loss and is not recommended for regular scenarios.-t, --test: Performs a test operation without writing volume group metadata./dev/sdb1 from the volume group vg01:vgreduce vg01 /dev/sdb1
vg01:vgreduce -a vg01
/dev/sdb1 from the volume group vg01:vgreduce -t vg01 /dev/sdb1
pvs or vgs -o vg_name,pv_count to verify the number of physical volumes in the volume group.vgremove command is used to delete a volume group and the logical volumes in it. After deletion, the physical volumes in the volume group retain their LVM physical volume tags and can be reused by other volume groups.vgremove [options] <VG>
<VG> represents the name of the volume group to be deleted. Common options are as follows:-f, --force: Forces the operation and bypasses some confirmations. It is not recommended for regular scenarios.-t, --test: Performs a test operation without writing volume group metadata.vg01:vgremove -t vg01
vg01:vgremove vg01
Volume group "vg01" successfully removed
vgs to confirm that vg01 no longer appears in the volume group list.lvcreate command is used to create logical volumes from the free space of a volume group. This command only creates block devices and does not create file systems such as ext4 or xfs.lvcreate -L <size> -n <LV> <VG>
<size> represents the logical volume size, <LV> represents the logical volume name, and <VG> represents the volume group name. Common options are as follows:-L, --size: Specifies the size of the logical volume. Units such as K, M, G, and T can be used.-l, --extents: Specifies the logical volume size by the number of PEs or as a percentage of the volume group space.-n, --name: Specifies the logical volume name.-r, --readahead: Specifies the number of read-ahead sectors for the logical volume. It can also be set to auto or none.mkfs on a logical volume clears existing data on that logical volume. Format only logical volumes that are newly created or confirmed to contain no data that needs to be retained.lv01 in the volume group vg01:lvcreate -L 10G -n lv01 vg01
Logical volume "lv01" created.
lv02, and then create an ext4 file system on it:lvcreate -L 100M -n lv02 vg01mkfs.ext4 /dev/vg01/lv02
lv03 with 256 read-ahead sectors:lvcreate -L 1T -n lv03 -r 256 vg01
lvs -o lv_name,vg_name,lv_size,lv_attr to verify the logical volume status.lvdisplay command is used to view detailed information about a logical volume, including its name, path, size, status, and volume group.lv01:lvdisplay /dev/vg01/lv01
--- Logical volume ---LV Path /dev/vg01/lv01LV Name lv01VG Name vg01LV Status availableLV Size 10.00 GiB
lvdisplay
lv01 in colon-separated format:lvdisplay -c /dev/vg01/lv01
lvs command.lvextend command is used to add capacity to a logical volume from the free space of a volume group. Common options are as follows:-L, --size: Specifies the absolute size after extension. When the + prefix is used, it indicates that capacity is added to the current size.-l, --extents: Extends the logical volume by the number of PEs or as a percentage of the volume group space.-r, --resizefs: After the logical volume is extended, resizes the supported file system accordingly.-r is not used, extend the file system separately according to its type after extending the logical volume.lv01 to 20GiB:lvextend -L 20G /dev/vg01/lv01
lv02 to 200MiB and resize the file system accordingly:lvextend -L 200M -r /dev/vg01/lv02
lvs /dev/vg01/lv01 /dev/vg01/lv02 to verify the logical volume capacity. If -r is not used, the ext4 file system can be extended with resize2fs, and a mounted xfs file system should be extended with xfs_growfs <mount point>.lvresize command can both extend and shrink a logical volume. Common options are as follows:-L, --size: Specifies the absolute size after adjustment. When the + or - prefix is used, it indicates that the specified capacity is increased or decreased.-l, --extents: Adjusts the logical volume size by the number of PEs or as a percentage of the volume group space.-r, --resizefs: Resizes the supported file system accordingly.lv01 to 20GiB and resize the file system accordingly:lvresize -L 20G -r /dev/vg01/lv01
lv02 to 100MiB and resizes the file system accordingly:lvresize -L 100M -r /dev/vg01/lv02
lvs and the corresponding file system check commands to verify the status of the logical volume and file system.lvremove command is used to delete a logical volume. After deletion, the file system and data in the logical volume are also lost.-f and -y options bypass some confirmations, so do not use them without verifying the target logical volume.lvremove [options] <LV>
-f, --force: Forces the operation and bypasses some checks.-y, --yes: Automatically answers "yes" to confirmation prompts.lv01, and then delete the logical volume:umount /dev/vg01/lv01lvremove /dev/vg01/lv01
Logical volume "lv01" successfully removed.
lv02:lvremove -f /dev/vg01/lv02
lvs to confirm that the target logical volume is no longer in the logical volume list./dev/vg01/lv01 and the ext4 file system.lvs /dev/vg01/lv01
LV VG Attr LSizelv01 vg01 -wi-a----- 10.00g
mkfs.ext4 /dev/vg01/lv01
Creating filesystem with 2621440 4k blocks and 655360 inodesAllocating group tables: doneWriting inode tables: doneCreating journal: doneWriting superblocks and filesystem accounting information: done
mkdir -p /mnt/myfs
/mnt/myfs (no output is returned on success):mount /dev/vg01/lv01 /mnt/myfs
findmnt /mnt/myfs
TARGET SOURCE FSTYPE OPTIONS/mnt/myfs /dev/mapper/vg01-lv01 ext4 rw,relatime
mount command creates a temporary mount, which becomes invalid after a system reboot. To make the mount permanent, first run blkid /dev/vg01/lv01 to obtain the file system UUID. Then add the following configuration to /etc/fstab and replace the sample UUID with the actual value:UUID=<actual UUID> /mnt/myfs ext4 defaults 0 2
/etc/fstab configuration. No output is returned on success:mount -a
umount /mnt/myfs
findmnt /mnt/myfs to verify. No output indicates that the mount point has been unmounted.Was this page helpful?
You can also Contact sales or Submit a Ticket for help.
Help us improve! Rate your documentation experience in 5 mins.
Feedback