Prepare a Disk for LVM with pvcreate Without Losing the Wrong Data
You will initialise a whole device or partition as an LVM physical volume (PV), inspect the resulting data-area alignment, and leave 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. pvcreate writes an LVM label and metadata areas, and normally wipes the first four sectors, so a wrong device path can destroy useful partition or boot information.
1. Confirm the installed command
This is a read-only checkpoint and does not need elevated privileges:
$ pvcreate --version
LVM version: 2.03.16(2)
Library version: 1.02.185
The exact build configuration lines may vary. The version is the relevant compatibility detail here. Read the local help as well 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, although some columns may require 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
Replace /dev/sdb below only after matching the size, type and physical device with your storage plan. A whole disk such as /dev/sdb and a partition such as /dev/sdb1 are different targets. Do not infer the target from a changing letter in a script, and do not use a mounted filesystem's device unless you have deliberately planned the outage.
Checkpoint: run findmnt --source /dev/sdb. Empty output is a useful indication that the example device is not currently the source of a mounted filesystem, but it is not proof that 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. The important checks are that the path is the intended device, the command does not report an existing volume group or incompatible signature, and the command returns status 0. Capture it 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 that another process will not open it before the real command. Stop if the device contains 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 requires 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; repeating it as --force --force overrides stronger protections, including checks related to a PV already being in a volume group.
If the command stops with a prompt or warning, treat that as a safety signal. Do not answer yes by 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. The pe_start and mda_size columns are the useful facts, not a particular UUID.
Do not assume that 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 requires 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 be increased 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 only instead of the plain initialisation in step 4, and only on a device that has not already been 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 should be planned separately. Keep the PV's UUID and the output of pvs in your change record.
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 it should not be used on a PV containing wanted data. If the PV belongs to a VG, do not improvise with force options. First consult the VG layout, metadata backups and the recovery plan.
Done means
- The device path was checked against
lsblk, mounts and the storage plan. - The dry run succeeded for that exact path, or its warning was understood and resolved.
pvcreatecompleted without unexamined force options.pvsshows the expected PV, UUID,pe_startand metadata size.- The next VG operation is recorded as a separate, deliberate change.