Linux – the best practice for adding disks in LVM

linuxlvmstorage

According to the Linux manpages you can add raw disks as well as partitions to a volume group.

In other documentation (RedHat, CentOS or openSUSE), all examples refer to adding partitions to the VG instead of raw disks. What is common (best) practice?

Best Answer

RHEL6 LVM Admin Guide

According to the RHEL 6 Logical Volume Administration Guide it's recommended that if you're going to use an entire drive as a physical volume in a LVM volume group, that you should still partition it:

excerpt from the guide "RHEL6 Logical Volume Manager Administration LVM Administrator Guide"

2.1.2. Multiple Partitions on a Disk

LVM allows you to create physical volumes out of disk partitions. It is generally recommended that you create a single partition that covers the whole disk to label as an LVM physical volume for the following reasons:

Administrative convenience

It is easier to keep track of the hardware in a system if each real disk only appears once. This becomes particularly true if a disk fails. In addition, multiple physical volumes on a single disk may cause a kernel warning about unknown partition types at boot-up.

LVM Howto

Section 11.1. Initializing disks or disk partitions of the LVM Howto states as follows:

excerpt from the LVM Howto

For entire disks:

Run pvcreate on the disk:

# pvcreate /dev/hdb

This creates a volume group descriptor at the start of disk.

Not Recommended

Using the whole disk as a PV (as opposed to a partition spanning the whole disk) is not recommended because of the management issues it can create. Any other OS that looks at the disk will not recognize the LVM metadata and display the disk as being free, so it is likely it will be overwritten. LVM itself will work fine with whole disk PVs.

If you get an error that LVM can't initialize a disk with a partition table on it, first make sure that the disk you are operating on is the correct one. If you are very sure that it is, run the following:

DANGEROUS

The following commands will destroy the partition table on the disk being operated on. Be very sure it is the correct disk.

# dd if=/dev/zero of=/dev/diskname bs=1k count=1
# blockdev --rereadpt /dev/diskname

Conclusions

These are the primary sources I would trust in determining whether you should format a single partition on a HDD prior to adding it as a physical volume or not. As other answers have indicated (and comments) you wouldn't be wrong in just adding the entire drive without a partition.

To me I liken it to driving in my car with my seat-belt on. If you never get in an accident then the seat-belt has served no purpose, but if I ever do get in an accident I"m sure glad I was wearing it.

Follow-up #1 (To @Joel's comments)

I thought the above 2 guides were 2 pretty good reasons. They're both official guides, one from RH the other a Howto put together by the LVM team.

Here's another reason. By not partitioning the HDD, no ID is being explicitly set on the HDD to clearly identify how it's being used.

 fdisk -l
 ...
/dev/sda6       318253056   956291071   319019008   8e  Linux LVM

As an administrator of systems, it's much more obvious to myself and others the intent of how this particular drive is being used vs. without the 8e.

I appreciate what you're saying @Joel, I too worked at a fortune 500 company where we had 100's of Linux deployments in both desktop/server physical/virtual deployments, as well as in large storage deployments, so I get what you're saying.

Related Question