Prepare a Disk for LVM with pvcreate Without Losing Data
pvcreate writes an LVM label onto a device and wipes its first four sectors, so the wrong path erases a boot partition, not the spare disk you meant. This guide walks you through initialising a whole device or partition as an LVM physical volume (PV), checking the resulting data-area alignment, and leaving it ready for vgcreate or vgextend. The examples match LVM 2.03.16(2), from the installed lvm2 package version 2.03.16-3ubuntu3.2.
The route
Jump straight to the step you need, or tick off Done means at the end.
Allow about fifteen minutes, plus whatever time you need to identify the correct disk. You need a shell, the lvm2 package and root privileges for the operation. This guide assumes the device is disposable or has been backed up.
1. Confirm the installed command
This is a read-only checkpoint and needs no elevated privileges:
$ pvcreate --version
LVM version: 2.03.16(2)
Library version: 1.02.185
Exact build configuration lines may vary; the version is the relevant compatibility detail here. Read the local help too if this machine has a different LVM release:
$ pvcreate --help | sed -n '1,35p'
pvcreate - Initialize physical volume(s) for use by LVM
Checkpoint
Do not continue until command -v pvcreate points to the command you intend to use and the package version is known.
2. Identify the exact target
List devices and their current signatures before choosing a path. This read-only command is normally unprivileged, though some columns may need access to device metadata:
$ lsblk -o NAME,PATH,SIZE,TYPE,FSTYPE,MOUNTPOINTS
NAME PATH SIZE TYPE FSTYPE MOUNTPOINTS
nvme0n1 /dev/nvme0n1 931.5G disk
|-nvme0n1p1 /dev/nvme0n1p1 512M part vfat /boot/efi
`-nvme0n1p2 /dev/nvme0n1p2 931G part ext4 /
sdb /dev/sdb 1.8T disk
- Match size, type and physical device to your storage plan before replacing
/dev/sdbbelow with your own target. - A whole disk and a partition are different targets.
/dev/sdband/dev/sdb1are not interchangeable. - Never infer the target from a changing letter in a script, and never use a mounted filesystem's device unless you have deliberately planned the outage.
Checkpoint
Run findmnt --source /dev/sdb. Empty output is a useful sign that the example device is not currently the source of a mounted filesystem, but it is not proof the device is safe to erase. Check multipath, RAID and backup arrangements separately.
3. Preview the operation
Use --test with the real target path before writing metadata. LVM disables metadata writing in this mode but still runs its checks, and returns success in cases where the real command would proceed:
$ sudo pvcreate --test /dev/sdb
TEST MODE: Metadata will NOT be updated and volumes will not be changed.
Physical volume "/dev/sdb" successfully created.
Output depends on the device and configuration. What matters is that the path is the intended device, the command does not report an existing volume group or incompatible signature, and it returns status 0. Capture that immediately:
$ printf 'preview status: %s\n' "$?"
preview status: 0
A successful dry run is not a backup and does not reserve the device; it also does not prove another process will not open it before the real command runs. Stop if the device holds data you have not explicitly accounted for.
4. Initialise the physical volume
Destructive action
The next command changes on-disk metadata and may wipe the first 2048 bytes. Check the target one more time before running it. Use sudo because writing a block device needs elevated privileges:
$ sudo pvcreate /dev/sdb
Physical volume "/dev/sdb" successfully created.
The default metadata type is the current lvm2 format. Without --uuid, LVM generates a random PV UUID. Do not add --force or --yes to silence a warning until you understand it: one --force overrides some checks and confirmations, while repeating it as --force --force overrides stronger protections, including checks that a PV is already in a volume group.
If the command stops with a prompt or warning, treat that as a safety signal. Do not answer yes out of habit; resolve the existing filesystem, PV or VG state first.
5. Verify the label and alignment
Ask LVM to report the new PV. Reading the device needs access to its metadata but does not change it:
$ sudo pvs -o pv_name,pv_size,pv_uuid,pe_start,mda_size,pv_attr /dev/sdb
PV PSize PV UUID 1st PE MdaSize Attr
/dev/sdb <1.82t 3w... 1.00m 1020.00k a--
The UUID and rounded sizes will differ. With the installed command's default settings, the first physical extent is usually aligned at 1 MiB. pe_start and mda_size are the facts worth checking, not any particular UUID.
Do not assume every disk has the same alignment: LVM may adjust the data-area start from device or MD properties reported by sysfs. If an application or array needs a specific alignment, set it deliberately with --dataalignment, then inspect pe_start afterwards.
6. Choose metadata space before creating a large VG
The metadata area holds text copies of volume-group metadata. Its size cannot grow after pvcreate, and two metadata copies must fit when the PV is used that way. For a VG expected to have unusually large or frequently changing metadata, choose a larger area during initialisation:
$ sudo pvcreate --metadatasize 8m /dev/sdb
$ sudo pvs -o pv_name,pe_start,mda_size /dev/sdb
Run that example instead of the plain initialisation in step 4, and only on a device not already initialised for the intended VG. The requested size is approximate: alignment can round it up, moving pe_start. Verify the result rather than treating 8m as the final reported size.
7. Continue or recover
Once the PV is verified, create a new volume group with vgcreate VG_NAME /dev/sdb, or add it to an existing group with vgextend VG_NAME /dev/sdb. Those commands change LVM configuration and deserve their own separate planning. Keep the PV's UUID and the output of pvs in your change record.
Recovery
If you initialised the wrong unused device and need to remove the LVM label, pvremove /dev/sdb is the normal reversal, but it does not restore bytes that were overwritten, and should not be used on a PV holding wanted data. If the PV belongs to a VG, do not improvise with force options; consult the VG layout, metadata backups and the recovery plan first.
Done means
- Target verified. The device path was checked against
lsblk, mounts and the storage plan. - Dry run clean. The dry run succeeded for that exact path, or its warning was understood and resolved.
- No unexamined force.
pvcreatecompleted without unexamined force options. - Label confirmed.
pvsshows the expected PV, UUID,pe_startand metadata size. - Next step separated. The next VG operation is recorded as a separate, deliberate change.