2

I have installed Debian 7.4 on a server, and through the installer I setup both RAID and LVM for the drive that the OS is installed on. However, now I want to add two 4TB drives in a RAID-1 array to the system, and then add in LVM onto those drives.

The question I have is: do I need to partition the drives before I put them in an array?

Most of the guides that I have seen will do something like this:

mkfs.ext4 /dev/sdb  #create /dev/sdb1
mkfs.ext4 /dev/sdc  #create /dev/sdc1
mdadm --create --verbose /dev/md0 --level=mirror --raid-devices=2 /dev/sdb1 /dev/sdc1
mkfs.ext4 /dev/md0  #create a filesystem table on the RAID array

#LVM creation on the RAID array
vgcreate vg_name /dev/md0
lvcreate -n lv_name -l100%FREE vg_name
mkfs.ext4 /dev/mapper/vg_name-lv_name
mount /dev/mapper/vg_name-lv_name /mount_point

However, I have just tried the following in a VM, which appears to work properly:

mdadm --create --verbose /dev/md0 --level=mirror --raid-devices=2 /dev/sdb /dev/sdc

#LVM creation on the RAID array
vgcreate vg_name /dev/md0
lvcreate -n lv_name -l100%FREE vg_name
mkfs.ext4 /dev/mapper/vg_name-lv_name
mount /dev/mapper/vg_name-lv_name /mount_point

Is there any difference between these two methods of creating a RAID/LVM array? It seems as though creating a filesystem three times is unnecessary.

rm5248
  • 143
  • 3

1 Answers1

3

Your question boils down to the following two questions:

  1. What difference is there between using raw disk devices and partitions in a mdadm software RAID array?

    I'm not aware of any consensus on using a whole disk vs using a partitioned disk. There shouldn't be any real performance considerations and mdadm supports doing it both ways. I tend to use partitions myself for the sole reason that if I add to the RAID set or replace a failed disk, I don't need to match sizes of the disk and instead can size a partition to the RAID and use the remaining space for something else (if the disk is bigger).

  2. Do I need to write a filesystems to the disk partitions or the /dev/mdX device prior to making it an LVM PV?

    No, you do not. Neither the RAID or LVM need a filesystem on the member devices, and if you put one there it will get overwritten by either the filesystem you write to md0 or the LVM metadata if making md0 a PV.

    The script is incorrect in suggesting the mfks.ext4 calls create the partitions, but rather they are created when you partition the disk. You never need to write the filesystems to the first two devices in your script (that get added to RAID). You only need to create the filesystem on md0 if you are stopping there and using md0 directly mounted (i.e. not using LVM). If you are using md0 as an LVM PV, there is no reason to write a filesystem to it first, as that information will be destroyed by the LVM metadata.

casey
  • 14,754
  • Here's a previous Q&A regarding LVM whole disk vs. partitions: http://unix.stackexchange.com/questions/76588/what-is-the-best-practice-for-adding-disks-in-lvm/76642#76642 – slm Mar 10 '14 at 11:38