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/sdb1meaning 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/sdb1meaning 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_NAMEIn my case, it is
/dev/datavg/datalvYou 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:
- How to Manage and Use LVM, How-to Geeks, http://www.howtogeek.com/howto/40702/how-to-manage-and-use-lvm-logical-volume-management-in-ubuntu/
- Andrew Wojnarek, Basic Linux LVM striping, IBM developerWorks, https://www.ibm.com/developerworks/community/blogs/AWojo/entry/basic_linux_lvm_striping1?lang=en [Note that the way he specifies partitions is not right.]
- RedHat Inc., Logical Volume Manager Administration, RedHat Enterprise Linux 6, https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_Linux/6/html-single/Logical_Volume_Manager_Administration/ [If you want a thorough understanding to LVM and its usage, read it. ]
- Ubuntu LVM Guide Part 1, Tutonics, http://www.tutonics.com/2012/11/ubuntu-lvm-guide-part-1.html
No comments:
Post a Comment