|
![]() |
Overclock.net - Overclocking.net > Components > Hard Drives & Storage | |
A Guide To LVM: Making Your Hard Drives Fit Your Data, Not The Other Way Around.
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) | |||||||||||||
|
The Game
![]() |
A Guide To LVM: Making Your Hard Drives Fit Your Data, Not The Other Way Around.
LVM? What is this? LVM - Logical Volume Management - is a way you make your hard drives fit your data. Let me explain further, I'll use a specific example. Let's say a user has 3 hard drives as so: hda: 250GB hard drive hdb: 500GB hard drive hdc: 80GB hard drive Now, say this user has his drives partitioned as so: hda1: (/) 50GB System Partition. hda2: 2GB Swap Partition. hda3: (/home) 148GB Storage Partition. hdb1: (/media/storage1) 500GB Storage Partition. hdc1: (/media/storage2) 80GB Storage Partition. Now, this works. Problem is, the user has a lot of video, but he runs out of space, so he moves to to his other drive, but this means when he wants something, he has to go to /media/storage1 and /home to look for the files. Then if he uses all three, he has to do it again. This ends up getting very annoying. So, how does LVM help? Well, it works like this: (Same system) hda1: (/) 50GB System Partition. hda2: 2GB Swap Partition. hda3: 148GB LVM Partition. hdb1: 500GB LVM Partition. hdc1: 80GB LVM Partition. The user then adds hda4, hdb1 & hdc1 to a Logical Volume Group. Then he creates a logical volume 'data' and assigns 148GB of storage to it. This gives him the same effect as before, and, as before, he runs out of space. This time, he just adds to the volume. He puts on another 100GB of space. When he needs more he adds more, and no data is lost in doing so. It all gets mounted at /home. LVM makes seamless space. Different drives are all seen as one large space, which can be used as needed. You can create as many logical volumes as you want, and mount them anywhere, and give them any amount of space you wish. The Good & The Bad Good Points About LVM:
Bad Points About LVM:
How would I create an LVM setup? First of all, install the stuff needed for LVM. You'll be looking for the lvm2 & dmsetup packages ('sudo apt-get install lvm2 dmsetup' for those 'buntu users, pacman -S lvm2 dmsetup for Arch, etc...). Next you will need to partition your drives. Unfortunatly gParted doesn't support LVM partitions, so you'll have to use the command-line fdisk to create them - don't worry, it's not too hard. First of all, clear out your drives till you have all the blank space you want to put your LVM volumes into - you can do that with gParted. Then just do 'fdisk /dev/hdx' replacing hdx with your volume you want to add an LVM partition to. Once done, do 'n' for new partition, make it a primary one and use up all the availible space (so just hit enter spacing-wise), then do t, choose the partition you just made, and make it type 8e (Linux LVM). Then hit 'w' to write it to disc. Then do the same for any other LVM partitions you want to make. Now we use 'pvcreate' - this creates our physical volumes for use with LVM. You just need to put all of the LVM volumes you just made into it. So, with out example the command would be 'pvcreate /dev/hda3 /dev/hdb1 /dev/hdc1'. Once this is done you can do 'pvdisplay' to see about the volumes. Next we create our Volume Group - this is our heap of storage space. 'vgcreate' is the command. You need to do 'vgcreate name volumes' - the name can be anything you want, lower case and one word. So for our example we could use 'vgcreate data /dev/hda3 /dev/hdb1 /dev/hdc1' - the name is just for your benefit - data generally suits. You can use 'vgdisplay' to show your volume groups, 'vgscan' to look for Volume Groups, and 'vgrename <old name> <new name>' to... well, I'm sure you can work it out. Now we can create our Logical Volume. Can you guess the command? The inventively named 'lvcreate' is here to do the job. 'lvcreate --name <name> --size xGB <volume group>' - so if I wanted one as per the example I'd use 'lvcreate --name data --size 100GB data' - I'm being unimaginative and using the same name for logical volume and volume group. Say we want a backup Logical Volume as well, we could do 'lvcreate --name backup --size 100GB data' to make it. We can use 'lvdisplay' to take a look at our handywork, and 'lvscan' and 'lvrename' are there too. We can also do 'lvextend' or 'lvreduce' - the latter being risky to your data. 'lvextend -L10GB /dev/data/data' and 'lvreduce -L10GB /dev/data/backup' for example. At the moment, we have Logical Volumes, but they are useless. Let's create an ext3 filesystem on our 'data' logical volume in our 'data' logical volume group. 'mkfs.ext3 /dev/data/data' will do the trick, and, obviously, 'mkfs.ext3 /dev/data/backup' You can now mount your filesystems. 'mount /dev/data/data /home/user/Documents' - for example. Remember to add them to fstab if you want them to be mounted at boot. (so do 'sudo nano /etc/fstab' or 'su && nano /etc/fstab' and then add a line such as '/dev/data/data /home/user/Documents ext3 rw,noatime 0 0' to the end. Changing the LVM setup. You can add another hard disc to a Volume Group with 'vgextend <volume group name> <physical volume>' after creating the physical volume. You can extend a volume after it's got a file system on by extending with 'lvextend', then doing 'e2fsck -f' and 'resize2fs' on your logical volume. You can shrink by doing the same thing in reverse (e2fsck and resize2fs, then lvreduce). Where can I get more help? Ask here, google it, or check out the man pages for that command.
__________________
Lattyware | Main (Sig) Rig: gBOX42 | Lan Rig: gLAN42 Never been convinced by Linux? Here is a challenge. | Using LVM Scratched Disc? | Guide To LAN Parties | Writing a GUI application in Python/Glade Etching an image into your case. | Wireless Access Points: Easy wireless networking. A Member Of The OCN Anime/Manga Club "I disapprove of what you say, but I will defend to the death your right to say it." --Evelyn Beatrice Hall
|
|||||||||||||
|
|
|
|
#2 (permalink) | |||||||||||||
|
Sup'
![]() |
Interesting... Sort of sounds like the linux equal to Dynamic drives in Windows. Good guide though
__________________
Crucial Ballistix Club ![]() My First Guide: The Perfectionist's Guide To Ripping Audio CD's Check This Out (Intel Users Only): The Definitive Answer To: RAM Overclocking: Higher Speed vs. Tighter Timings
|
|||||||||||||
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|