-3

Manpage of pvcreate says

pvcreate initializes a PV so that it is recognized as belonging to LVM, and allows the PV to be used in a VG. A PV can be a disk partition, whole disk, meta device, or loopback file.

Why doesn't the following pvcreate command fail to mark a disk as PV then?

$ sudo parted -l
Model: ATA TOSHIBA MQ01ABF0 (scsi)
Disk /dev/sda: 500GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End    Size   File system  Name                  Flags
 1      1049kB  538MB  537MB  fat32        EFI System Partition  boot, esp
 2      538MB   500GB  500GB  ext4
$ sudo lvmdiskscan
  /dev/sda1 [     512.00 MiB] 
  /dev/sda2 [    <465.26 GiB] 
  0 disks
  2 partitions
  0 LVM physical volume whole disks
  0 LVM physical volumes

$ sudo pvcreate /dev/sda
  Device /dev/sda excluded by a filter.

roaima wrote in https://unix.stackexchange.com/a/502428/674:

You're trying to use the entire /dev/sda for a PV. But you've got (at least) two partitions on that disk (sda1 and sda2), so LVM is rightly refusing to honour your request.

Does it mean that we can make a disk a PV by pvcreate, if and only if the disk has only one partition? In other words, we can't make a disk a PV by pvcreate, if and only if the disk has more than one partitions?

Thanks.

2

You said yourself:

A PV can be a disk partition, whole disk, meta device, or loopback file

I don't understand your question. A PV can be a partition or a whole disk. Delete all partitions and you will be able to use the whole disk. If you don't want to use the whole disk, then use a partition instead.

You should also know that one partition that covers the whole disk space could make less trouble.

Please read this answer before you wipe your hdd: What is the best practice for adding disks in LVM.

  • My question is "Does it mean that we can make a disk a PV by pvcreate, if and only if the disk has only one partition? In other words, we can't make a disk a PV by pvcreate, if and only if the disk has more than one partitions?" – Tim Feb 24 at 16:25
  • You can't make the whole disk a PV if there is at least one partition on it (because pvcreate won't let you). – Freddy Feb 24 at 16:28
  • What do you mean a disk without a partition? Any disk without being partitioned is a partition by itself – Tim Feb 24 at 16:34
  • “Any disk without being partitioned” is a disk with no partitions. It isn’t a partition by itself. When you get a new disk, or if you overwrite a disk with zeros, it’s empty, with no partition table, let alone partitions. – Stephen Kitt Feb 24 at 16:39
  • @Tim If you delete /dev/sda1 and /dev/sda2 with gparted or any other partitioning program, then your disk is without partitions. – Freddy Feb 24 at 16:52
1

No.

I have absolutely no experience with this, but from the information in the question. No.

You can pvcreate a partition or a disk, or …

It is stopping you, because it sees that the device you have asked to process, has partitions on it. The important word here is partitions (ignore pluralisation).

So the logical predicate you are after is:

Partitions on device implies, pvcreate refuses to work (destroy data).

If you want to do the whole disk, then remove partitions. However it looks like you have a boot partition, so you may want to pvcreate /dev/sda2.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.