KB
Storage & Filesystems

Creating new LVM Partition Linux

5 min read953 words20 code blocks

At a glance#

  • Purpose: Turn a newly attached disk into a mounted, persistent LVM volume.
  • Applies to: Any Linux distribution with lvm2 installed.
  • Risk: Medium — pvcreate destroys existing data on the target disk.
  • Time: About 20 minutes.

Overview#

LVM (Logical Volume Manager) sits between physical disks and filesystems, and is the reason a server can grow its storage without downtime or repartitioning. It has three layers:

LayerWhat it isCommand
PV — Physical VolumeA disk or partition handed to LVMpvcreate
VG — Volume GroupA pool of one or more PVsvgcreate
LV — Logical VolumeA slice of the pool that gets a filesystemlvcreate

The filesystem goes on the LV, not on the disk. Because an LV can be extended across any free space in its VG, adding capacity later is a live operation.

Warning: pvcreate writes LVM metadata to the start of the device and makes any existing filesystem unreachable. Confirm the device path before running it.

Before you start#

  • Root access.
  • A new disk attached to the machine (added in vSphere, or physically installed).
  • lvm2 installed — present by default on most server images. If not: sudo apt install lvm2 or sudo yum install lvm2.

Identify the new disk#

bash
lsblk

The new disk has no partitions and no mount points:

text
sda      8:0    0   50G  0 disk
├─sda1   8:1    0    1G  0 part /boot
└─sda2   8:2    0   49G  0 part /
sdb      8:16   0  100G  0 disk          <-- the new disk

If it does not appear, rescan the SCSI bus rather than rebooting:

bash
echo "- - -" | sudo tee /sys/class/scsi_host/host0/scan
lsblk

Confirm the disk is genuinely empty:

bash
sudo blkid /dev/sdb

No output means no recognised filesystem. Any output means stop and check before continuing.

Procedure#

1. Create the physical volume#

You can hand LVM a whole disk or a partition. Using the whole disk is simpler and is what the examples below do.

bash
sudo pvcreate /dev/sdb

For multiple disks in one go:

bash
sudo pvcreate /dev/sdb /dev/sdc

Confirm:

bash
sudo pvs

2. Create the volume group#

The volume group is the pool. Give it a name that describes its purpose — vgdata, vgapp — rather than something generic.

bash
sudo vgcreate vgdata /dev/sdb

Confirm, and note the free space:

bash
sudo vgs
sudo vgdisplay vgdata

3. Create the logical volume#

To use all available space in the group:

bash
sudo lvcreate -n lvdata -l 100%FREE vgdata

To allocate a fixed size and leave the rest free for later:

bash
sudo lvcreate -n lvdata -L 50G vgdata
FlagMeaning
-nName of the logical volume
-LSize as an absolute value (50G)
-lSize as an extent count or percentage (100%FREE)
Tip: Leaving some space unallocated in the VG is good practice. It gives you room to take an LVM snapshot before a risky change, and to grow whichever volume actually turns out to need it.

The new volume appears at /dev/<vg-name>/<lv-name>:

bash
sudo lvs
ls -l /dev/vgdata/lvdata

4. Create a filesystem#

bash
sudo mkfs.xfs /dev/vgdata/lvdata
FilesystemChoose whenCommand
xfsGeneral purpose, large files, heavy writes. Grows but cannot shrink.mkfs.xfs
ext4You may need to shrink it later.mkfs.ext4

5. Create a mount point and mount it#

bash
sudo mkdir -p /data
sudo mount /dev/vgdata/lvdata /data
df -hT /data

At this point the volume works but will not survive a reboot.

6. Make the mount persistent#

Get the UUID:

bash
sudo blkid /dev/vgdata/lvdata

Edit fstab:

bash
sudo nano /etc/fstab

Add a line using the UUID:

text
UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx  /data  xfs  defaults  0  2

The six fields are: device, mount point, filesystem type, options, dump flag, and fsck order (0 for root, 2 for other filesystems).

Warning: Test the entry before rebooting. An invalid fstab line can stop the server booting and force a rescue-mode recovery. ``bash sudo umount /data sudo mount -a df -hT /data ` If mount -a completes silently and /data` is mounted, the entry is correct.

Verification#

bash
sudo pvs        # physical volume present
sudo vgs        # volume group with expected size
sudo lvs        # logical volume present
df -hT /data    # mounted with expected capacity

Then reboot and confirm /data returns automatically:

bash
sudo reboot
# after it comes back
df -hT /data

Extending later#

The reason for using LVM. Once more space is added to the VG:

bash
sudo lvextend -l +100%FREE /dev/vgdata/lvdata
sudo xfs_growfs /data                  # xfs
sudo resize2fs /dev/vgdata/lvdata      # ext4

Both can be done while the filesystem is mounted and in use. See Extending partition size LVM Linux.

Troubleshooting#

SymptomCause and fix
Device /dev/sdb not found or ignored by filteringThe kernel has not registered the disk. Rescan the SCSI bus, or reboot.
Device /dev/sdb excluded by a filterAn old signature is present. Inspect with wipefs /dev/sdb; clear it with sudo wipefs -a /dev/sdb only if the disk is confirmed empty.
Volume group "vgdata" not foundName typo, or the VG is not active. Run sudo vgchange -ay.
mkfs reports the device is busySomething already has it open. Check with sudo lsof /dev/vgdata/lvdata.
Mount lost after rebootMissing or incorrect fstab entry. Recheck the UUID with blkid.
Boot fails after fstab editBoot to rescue mode, comment out the line, and retest with mount -a.