Setting up LVM on a running Ubuntu Linux system with striping

I spent about 10 minutes tonight to set up LVM on my running Ubuntu (14.04 LTS) Linux system. Things were much simpler than I thought. I first googled the keywords "lvm ubuntu server" and I got lots of mis-information that I can only set up LVM when freshly install Ubuntu. But it is not the case at all. I cannot believe Canonical, Inc. doesn't have such a chapter in their official doc for Ubunut Linux.

Step 0: I bought two 4TB hard drives (HDs) and I installed lvm2 on my Ubuntu box:
sudo apt-get install lvm2

Step 1: Use gdisk to create partition table and partition on the two 4TB HDs. I cannot do so using fdisk because 4TB is too big for traditional MBR-based partition table.

Step 2: Prepare the physical volume for LVM use. The two new HDs are physically /dev/sda1 and /dev/sdb1. So I did:
pvcreate /dev/sda1 
pvcreate /dev/sdb1

Step 3: Create the volume group. The key of LVM is to create a volume group, on which logical volumes can be further created. I simply did:
vgcreate datavg /dev/sda1 /dev/sdb1
meaning that I create a volume group called datavg on top of two physical volumes /dev/sda1 and /dev/sdb1.

Step 4: Build a logical volume. I decided to build a super big logical volume (that's why we used LVM, isn't it?) of 8TB. So I did:
lvcreate -i2 -n datalv -L7.25T datavg /dev/sda1 /dev/sdb1
meaning to create a logical volume called datalv of size 7.25T on top of volume group datavg which consists for two physical volumes. The option -i2 means striping data onto the two HDs in parallel. In this way, I can speed up (2X here) data access - another reason I pick LVM.

Note that if you use striping when setting up a logical volume, extending it requires some tiny hassle. See here. If you don't wanna bother the hassle in exchange for the speed, don't use striping.


Step 5:
Create a filesystem on and mount it. To users, a logical volume is the same as a physical volume. So the last step is to create a filesystem on it and mount it. Of course, you can play other fancy stuff such as LUKS encryption. The logical volume's device name is a little bit tricky. Instead of something like /dev/sdb1, it is in this format
/dev/VOLUME_GROUP_NAME/LOGICAL_VOLUME_NAME
In my case, it is
/dev/datavg/datalv
You can further add it to /etc/fstab so it will be mounted automatically for you when system restarts.

So, this is the steps to step LVM on a running Linux system. There are many other advanced topics such as extending an LV, adding a new HD into a VG or taking snapshots.

I feel some tutorials flowing on the Internet are quite helpful, especially RetHat Linux's official doc. Please find them below.

References:

No comments: