Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

pvcreate

Turn a disk or partition into an LVM physical volume (pvcreate), or remove the LVM label again (pvremove).

Level
RHCSA exam
Group
LVM
Needs root
Yes
Package
lvm2
Also called
pvremove

What it does

pvcreate DEVICE writes an LVM label and metadata area on the device, so it can join a volume group. It works on whole disks and on partitions (type lvm recommended). It refuses devices with an existing file system or partition table signature — clear them with wipefs -a first if you are sure.

pvremove deletes the LVM label from a PV that is no longer in a VG.

How to write it

pvcreate [OPTION]... DEVICE...
pvremove [OPTION]... PV...

Options 27

Most used

pvcreate

-f, --force
Create even when a signature is found (twice: also over an existing PV).
-u, --uuid UUID
Use this UUID (with --restorefile, for recovery).
--restorefile FILE
Metadata backup for -u.
--norestorefile
Allow -u without a restore file.
--metadatasize SIZE
Size of the metadata area.
--pvmetadatacopies 0|1|2, --metadatacopies 0|1|2
Number of metadata copies on the PV.
--metadataignore y|n
Ignore the metadata areas on this PV.
-M, --metadatatype lvm2
Metadata format.
--dataalignment SIZE
Align the start of data.
--dataalignmentoffset SIZE
Shift the alignment.
--bootloaderareasize SIZE
Reserve space for a boot loader.
--labelsector N
Sector of the LVM label.
--setphysicalvolumesize SIZE
Override the detected size.
-Z, --zero y|n
Wipe the first sectors.
--reportformat basic|json
Output format.

pvremove

-ff
Remove even if the PV is in a VG (dangerous).

Common LVM options

-t, --test
Test only; change nothing.
-v, --verbose
More output (repeat for more).
-q, --quiet
Less output.
-y, --yes
Answer yes to questions.
-d, --debug
Debug output.
--config STRING
Override lvm.conf settings for this command only.
--commandprofile STRING, --profile STRING
Use a configuration profile.
--devices PV, --devicesfile STRING
Limit the devices LVM looks at.
--driverloaded y|n, --nolocking, --lockopt STRING, --nohints, --journal STRING
Special and debug settings.
-h, --help, --longhelp
Show help.
--version
Show the version.

Examples 10

$ run as a normal user# run as root (or with sudo)

  1. 1Create a PV on a partition

    pvcreate /dev/vdb1
      Physical volume "/dev/vdb1" successfully created.

    Partition type lvm first (fdisk t → lvm).

  2. 2Whole disks

    pvcreate /dev/vdc /dev/vdd

    No partition table needed.

  3. 3Check the result

    pvs

    New PVs have no VG yet.

  4. 4A disk with old signatures

    pvcreate /dev/vde
      WARNING: xfs signature detected on /dev/vde at offset 0. Wipe it? [y/n]:

    Answer only if the data is not needed; or run wipefs -a first.

  5. 5Test first

    pvcreate -t /dev/vdc

    Shows what would happen.

  6. 6Remove the LVM label

    pvremove /dev/vdd
      Labels on physical volume "/dev/vdd" successfully wiped.

    Only after vgreduce took it out of the VG.

  7. 7Grow a PV after the disk or partition grew

    pvresize /dev/vdb1

    The VG gets the new space (for example after a VM disk resize).

  8. 8See details of a PV

    pvdisplay /dev/vdb1

    Size, PE count, VG.

  9. 9Find devices LVM can use

    lvmdiskscan

    Lists disks and partitions with sizes.

  10. 10Restore a lost PV label (recovery)

    pvcreate --uuid "Wq3k…" --restorefile /etc/lvm/backup/vgdata /dev/vdc

    Then vgcfgrestore vgdata. Metadata backups are in /etc/lvm/backup.

Files

/etc/lvm/lvm.conf
LVM settings.
/etc/lvm/backup/, /etc/lvm/archive/
Metadata backups.

Exit codes

0Done.
5Error.