System and processes
The pvcreate command
Prepares a disk or a partition as an LVM physical volume (PV).
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 successCopy-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
| Message | Cause | Fix |
|---|---|---|
| Can't initialize physical volume "/dev/sdb" of volume group "datos" without -ff | The 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
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.
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