System and processes

The pvcreate command

Prepares a disk or a partition as an LVM physical volume (PV).

Syntax

sudo pvcreate <dispositivo...>Try it in the terminal →

Most useful options

-f, --forceSkips confirmations and some checks. Repeated (-ff) it forces creation even when the device is already a PV in a group: use it only when you know why
-y, --yesNever asks and answers yes to everything. Use it only in scripts you have already tested
-Z, --zero y|nZeroes the first 4 sectors (2048 bytes). By default they are wiped, unless you use --uuid or --restorefile
-u, --uuid <uuid>Assigns a specific UUID to the PV. Without it a random one is generated. Every PV needs a unique UUID
--dataalignment <tamaño>Aligns the start of the PV data area to a multiple of that size
--metadatasize <tamaño>Approximate size of the metadata area for each group. It cannot be increased once the PV exists
-t, --testTest mode: does not write the metadata, though it still returns success

Copy-ready examples

$ lsblkshows which disks and partitions exist before you touch any.
$ sudo pvcreate /dev/sdcprepares a whole disk. Destructive: it writes the LVM header, so the disk must be empty or hold no data you want to keep.

Example output

Physical volume "/dev/sdc" successfully created.
$ sudo pvcreate /dev/sdc1 /dev/sddprepares a partition and a whole disk in one command. Same warning: it overwrites the start of both devices.
$ sudo pvcreate --metadatasize 2048k /dev/sdesets the metadata area size instead of the default one. Same write warning.

You can try them in the browser terminal: it does not touch your computer.

Common errors

MessageCauseFix
Can't initialize physical volume "/dev/sdb" of volume group "datos" without -ffThe disk is already a PV in the datos group. pvcreate blocks it as a safeguard so that group does not break.If the group is still in use, do not force it. Remove the PV with vgreduce first and run the command again.
Can't open /dev/sdb exclusively. Mounted filesystem?The disk or one of its partitions is mounted or in use, and LVM cannot open it exclusively.Unmount whatever sits on the device with umount, and check with lsblk what is still mounted.
Failed to write physical volume "/dev/sdb".LVM could not write the header to the disk. It may be an I/O error or a device that is read-only.Check the kernel messages with dmesg. If there are I/O errors, inspect the disk before trying again.

Typical mistakes

  • pvcreate writes the LVM header at the start of the disk: do not use it on a disk with data you want to keep.
  • By default the first physical extent (PE) starts 1 MiB from the start of the device. Check it with pvs -o pe_start.
  • If the disk carries signatures from another file system, LVM asks before wiping them. With -y it does not ask.
  • With -ff pvcreate skips checks that normally protect your data: do not use it as a shortcut around a device error.

Differences from similar commands

  • vgcreate: creates a volume group on top of PVs. pvcreate only prepares disks and forms no group.
  • pvremove: does the opposite: it wipes the LVM label from a disk you no longer want as a PV.
  • mkfs.ext4: creates a file system on the disk. pvcreate creates none: it leaves the disk ready for LVM.

FAQ

What happens to a disk's data when you run pvcreate?

They can be lost: pvcreate writes the LVM header and the disk becomes managed by LVM. Back up first if there is anything you want to keep.

Can I create the PV on a partition instead of the whole disk?

Yes. Pass the partition, such as /dev/sdc1, and the PV will use only that area. The rest of the disk stays free for other uses.

How do I check that the PV was created correctly?

With pvs to see the summary, or with pvs -o pe_start to see where the first physical extent starts.

More System and processes commands

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course