Show disks, partitions, filesystems and mount points
lsblk -fCreate, mount, grow and remove physical volumes, volume groups and logical volumes, including migrating existing data partitions to LVM, with XFS and ext4 grow differences.
Show disks, partitions, filesystems and mount points
lsblk -fList physical volumes in brief
pvsList volume groups and free space
vgsList logical volumes in brief
lvsShow detailed information for PV / VG / LV
pvdisplay / vgdisplay / lvdisplayInitialize a whole disk as a PV (wipes existing partition info)
sudo pvcreate /dev/sdbAlternatively initialize a single partition as a PV
sudo pvcreate /dev/sdb1Verify PV size and free space
pvs -o pv_name,pv_size,pv_freeCheck partitions, filesystem types and mount points to see whether data exists
sudo lsblk -f /dev/sdbUnmount the filesystem first; changing the partition type or writing a PV label requires it
sudo umount /dataIf it reports busy, find the holders with fuser -vm or lsof +D
-n previews existing filesystem and RAID signatures without erasing, showing what pvcreate will overwrite
sudo wipefs -n /dev/sdb1Set a GPT partition type to Linux LVM (8e00) and reload the table; on MBR disks use fdisk t and pick 8e
sudo sgdisk --typecode=1:8e00 /dev/sdb
sudo partprobe /dev/sdbChanging the type flag keeps the data, but the backup before the next step is still mandatory
A filesystem signature requires --force to write the PV label; this overwrites roughly the first 1MB of the partition
sudo pvcreate --force /dev/sdb1LVM cannot convert a live filesystem in place; back the data up first and rebuild it with the flow below
Take a block-level backup of the partition before migrating; use tar or rsync when space is tight
sudo dd if=/dev/sdb1 of=/backup/sdb1.img bs=4M status=progressFull migration: create VG and LV, format, mount, restore data, then put the UUID into fstab and only then clean up the old partition
sudo vgcreate data_vg /dev/sdb1
sudo lvcreate -l 100%FREE -n data_lv data_vg
sudo mkfs.xfs /dev/data_vg/data_lv
sudo mkdir -p /mnt/new && sudo mount /dev/data_vg/data_lv /mnt/new
sudo rsync -aHAX --info=progress2 /data/ /mnt/new/
sudo blkid /dev/data_vg/data_lv-aHAX preserves permissions, ACLs and xattrs; finish the switch inside a maintenance window to avoid split writes
Create a volume group named data_vg
sudo vgcreate data_vg /dev/sdbCreate a 20G logical volume in the VG
sudo lvcreate -L 20G -n data_lv data_vgUse all remaining VG space for the LV
sudo lvcreate -l 100%FREE -n data_lv data_vgCreate a mirrored LV (requires at least two PVs)
sudo lvcreate -L 10G -n log_lv -m 1 data_vgConfirm LV names and sizes
lvs -o lv_name,lv_size,pool_lvFormat as XFS; use mkfs.ext4 for ext4
sudo mkfs.xfs /dev/data_vg/data_lvCreate a mount point and mount it
sudo mkdir -p /data && sudo mount /dev/data_vg/data_lv /dataGet the UUID; prefer UUID entries in fstab
sudo blkid /dev/data_vg/data_lvAppend this line to /etc/fstab for mounting at boot
UUID=xxxx-xxxx /data xfs defaults 0 0Run mount -a after editing fstab to avoid boot failures
Add 10G to the logical volume
sudo lvextend -L +10G /dev/data_vg/data_lvExtend the LV by all remaining VG space
sudo lvextend -l +100%FREE /dev/data_vg/data_lvGrow an XFS filesystem; argument is the mount point
sudo xfs_growfs /dataGrow an ext4 filesystem; argument is the device path
sudo resize2fs /dev/data_vg/data_lvAdd a new disk to the VG to expand capacity
sudo vgextend data_vg /dev/sdcRefresh PV size after the underlying disk was enlarged
sudo pvresize /dev/sdbext4 shrink flow: unmount, check then resize; XFS cannot shrink
sudo umount /data && sudo e2fsck -f /dev/data_vg/data_lv && sudo resize2fs /dev/data_vg/data_lv 5GShrink an LV; shrink the filesystem first or data will corrupt
sudo lvreduce -L -5G /dev/data_vg/data_lvRemove a logical volume; data cannot be recovered
sudo lvremove /dev/data_vg/data_lvRemove a volume group
sudo vgremove data_vgRemove the PV label
sudo pvremove /dev/sdbThis website uses cookies to ensure you get the best experience on our website. Privacy Policy.