10

I'm currently installing arch linux and when I try to create a physical volume it gives me this error.

Can not use /dev/sda: device is partitioned

What is this error and how can I get rid of it?

PS: I have formatted the disk with mkfs.ext4 /dev/sda

dead101
  • 101

5 Answers5

11

Upon my first attempt, pvcreate -ff /dev/vdh did not work for me, whether or not the disk contains a partition.

pvcreate -ff /dev/vdh
Cannot use /dev/vdh: device is partitioned

I had to use wipefs first to get rid of all metadata.

root@nextcloud:~ # wipefs --all --backup /dev/vdh
/dev/vdh : 8 bytes were erased at index 0x00000200 (gpt) : 45 46 49 20 50 41 52 54
/dev/vdh : 8 bytes were erased at index 0x9c3fffffe00 (gpt) : 45 46 49 20 50 41 52 54
/dev/vdh : bytes were erased at index 0x000001fe (PMBR) : 55 aa
/dev/vdh : ioctl call to reread partition table: Success

The creation of the volume was then able to be carried out correctly:

pvcreate -ff /dev/vdh
Physical volume "/dev/vdh" successfully created.

Probably I went too fast, I did not test without the -ff option.

AdminBee
  • 22,803
MaxiReglisse
  • 209
  • 2
  • 4
  • Tested on Pop_OS 22.04 LTS (based on Ubuntu 22.04 LTS) and this worked perfectly, and no -ff is necessary when creating the physical volume with pvcreate. The wipefs command does the job of removing the GPT partition table just fine so that LVM will deal with the entire raw device directly. – James Jan 24 '23 at 21:17
  • You can also big hammer with dd and wipe the table header out. dd if=/dev/zero of=/dev/sda bs=1M count=2

    wipefs didn't seem to help (not sure I was using it right though), but after the dd pvcreate didn't care

    – DeadChex Jun 06 '23 at 21:19
3

For future references, there are two cases:

1. When there are no partitions

This may happen when you have a GPT (GUID Partition Table). Unfortunately this cannot even be forced with -f (ref to a bug report)

You can check what partition table you have with fdisk -l /dev/sda for example.

The solution is to replace the GPT with a legacy BIOS table, for example with gparted:

  • Device / Create Partition Table...
  • Select new partition table: msdos

or with parted:

  • parted /dev/sda
  • mktable msdos
  • quit

After which you should be able to create your physical volume:

  • pvcreate /dev/sda

It is possible that pvcreate suggests to wipe out the dos signature found in the partition table. It is safe to do it.

2. When there are already partitions on the disk

It is a safety measure, and -f cannot override it either.

You can remove the partitions with the same solution above, since creating a new table will erase everything. There are other ways to do it, for example with fdisk, but the solution above makes sure you solve the GPT issue at the same time.

RedGlyph
  • 133
2

/dev/sda is an entire disk. Usually (but not necessarily always) you would partition the disk, giving device names such as /dev/sda1 and /dev/sda2, and you would use these for filesystems, swap space, LVM allocation, etc.

You have put a filesystem onto /dev/sda so it's no longer available for assignment to logical volume management (pvcreate). The LVM tool correctly warns you that the disk is already in use (with a filesystem).

If you really do want to destroy the filesystem and replace it with LVM you can read the documentation (man pvcreate) and see that,

The force option [-f] will create a PV without confirmation. Repeating the force option (-ff) will forcibly create a PV, overriding checks that normally prevent it, e.g. if the PV is already in a VG.

Chris Davies
  • 116,213
  • 16
  • 160
  • 287
0

It sounds like you may have destroyed your system.

/dev/sda is the entire disk. Normally, you will take your /dev/sda disk and partition it into numbered pieces /dev/sda1 /dev/sda2 /dev/sda3 and so on. Then you can use pvcreate to use one of these individual partitions. fdisk -l /dev/sda will print you a list of the partitions on your disk.

Further, you do not want an ext4 file system on a partition that you're going to use with LVM. LVM uses its own data format on the partitions it creates, not a standard file system.

hymie
  • 1,710
  • pvcreate works on disks too, in this case there is no reason to create partitions in the first place. No system was destroyed, he's installing it... – RedGlyph Apr 20 '22 at 14:29
0

Assuming your goal was to create a physical volume from the whole disk without a partition table, then you would need to zero out any existing partition table first:

dd if=/dev/zero of=/dev/sda bs=512 count=1

Note that not using a partition table may not be best practice. It may be misjudged as an unused, corrupt disk by a naive user or operating syste,.

More details in this answer.

Marwi
  • 31