Partitions and LVM
I'm trying to learn about partitions and LVM although I'm still getting my head around it. I've set up my RHEL test server (has single 80GB disk) with LVM. As I understand it, it goes like this: -
Setup up several partitions for this, in this case hda5 - 7. hda1 is my boot partition which has to be on primary. hda2 is a regular 10GB primary partition that holds the OS and hda3 is the swap partition. hda4 is the extended partition which houses hda5 to 7. They're 5GB each. I assume I cannot access partition 4 directly as it's simply the holder for the logical partitions? So I've set hda5 - 7 partitions with type '8e' (LVM). I then created a Volume Group called VolGroup01 and since the drive is only 80GB, stick with the default Physical Extent size of 4MB. I assign this Volume Group to /dev/hda5 (why does a Volume Group as an abstraction have to be assigned a partition?). I then create a Logical Volume called LogVol01 of 500MB and assign it to the new VolGroup01. I format this with ext3 and created a /etc/fstab entry to automount it. First I tried to use /dev/VolGroup01/LogVol01 as this seemed logical but this threw me into maintenance mode and I had to remount the drive as read-write to change the fstab :) Why do I have to use /dev/mapper/VolGroup01-LogVol01 instead? Doesn't seem very consistent. So I assume I can add as many Logical Volumes as I like, presumably across any of the partitions I've created with type '8e'. But I'm uncertain about the relationship between the various parts. Creating a Volume Group I get as it's a virtual holder for the partitions that I can add across many disks. So are Logical Volumes an abstraction of partitions? Since partitions themselves can be any size, why have added functionality to size Logical Volumes as well? Not sure I get that part. Now I need to learn how to either resize the current Logical Volume or add more :) |
Not exactly:
You can use partitions without using LVM. That is to say if you have a hard drive and you create /dev/sda1 through /dev/sda7 you could put an ext3 filesystem on each of those (except sda4 which is the partition that contains the extended partitions sda5-sda7). -OR- You can use each of those partitions as "physical devices" for an LVM Volume Group (VG) (or more than one VG - each VG has to have at least 1 physical device). Typically you wouldn't do this as there isn't really any value in splitting them up and recombining but there's nothing that prevents it. -OR- You could just make one partition and use that as the "physical device" for your single VG. Default scheme in RedHat/CentOS is: 2 partitions - 1 for /boot and 1 for LVM. (/boot shouldn't be on LVM as it would add a layer that might not be available if you were attempting to recover a failed system later). The original intent of LVM was that it allows you to put multiple disks (or partitions from different disks) into each VG which you can then subdivide any way you want into various logical volumes (LVs). Since single disks have a limited number of partitions it makes sense now to use LVM even for them as you can make a separate filesystem (or swap device) on each LV you create and exceed the number you would have been able to create with just partitions of a single disk. Additionally LVM allows for dynamic growth of a VG (by adding more physical devices [disks or partitions]] and LVs (by using lvextend to use free space). You can even shrink/reduce things thought that takes a little more planning. If you were only doing partitioning you couldn't grow any partition as the next one would be at its boundary. You'd have to redo all your partitions which might not be easy. |
Yes, I know I can use partitions without LVM, I just wanted to make sure I had the procedure correct for using LVM, hence my multiple itty-bitty partitions :)
|
hi
The easiest way to come to grips is to create a "hierarchical" understanding of LVM in your head. Basically there's a hierarchy of areas that you need to understand: 1. Partition : At a top level you have a partition - which based on your post I see you understand fairly well. For LVM you basically create the partition of time Linux LVM (or 8e) when you partition your drive. 2. Physical Volume A physical volume is basically your top level element when you're using LVM. Basically you create a physical volume on top of a particular LVM partition that you've defined. Note that you can have one or more physical volumes based on how you've partitioned. You can use pvdisplay to show all physical volumes on your system. 3. Volume Group The next level is the volume group. Basically a volume group is a grouping of one or more physical volumes. Thus it also has a capacity based on the capacities of its physical volumes summed up. The idea here is to be able to dynamically increase/decrease the size of a volume group by adding/removing physical volumes from it. Thereby you can add a disk for example, create a phys volume and add this disk to the volume group without having to unmount/repartition or anything like this. Common commands used here are vgcreate (to create volume group), vgextend/vgreduce (to add/remove PV's from a volume group). You can use vgdisplay to show all volume groups on your system. 4. Logical Volume A logical volume is a chunk (or an entire) volume group's capacity. You can have more than one logical volume created from the same volume group. The logical volume is the actual logical device on top of which you'd format a filesystem (instead of a raw partition) and its power is that it can be increased in size after the fact if you're running out of space. You can also descrease its size; but the thing about this is that depending on circumstances you can lose information. Commonly used commands for creating a logical volume is lvcreate; lvextend/lvreduce to grow/shrink a LV. You also can use lvdisplay to show ALL logical volumes on your system. Note you can also use system-config-lvm on RHEL which allows you a GUI interface to configure LVM (though my personal opinion is that it isn't that great). |
Thanks, that explained it pretty well!
|
Quote:
|
Quote:
Try to stick to maybe 2-3 PV's at most (to allow yourself breathing space in future should you have some crazily growing app) ; and just one VG should do the trick. Also a personal choice of mine is to avoid having the root partition within LVM - rather just a plain old ext3/ext4 partition (as I said just a preference). |
Quote:
|
This machine is literally being used to practice what I'm reading about - nothing more. I *could* use my multi-disk home server for this if I wanted to live dangerously, but I don't think my heart could take it :D
|
Okay, I'm stuck
My Logical Volume is mounted as /mnt/lvm. This has a size of 500MB. I created this with: - Code: lvcreate -L 500M -n LogVol01 VolGroup01 The actual partition (/dev/hda5) is 5GB. So I want to resize the current Logical Volume. Code:
[root@joshua9 ~]# lvdisplay Do I have to start again and should I simply have formatted the partition before adding the Volume Group? |
You'll find this a good howto/ref for LVMs. http://tldp.org/HOWTO/LVM-HOWTO/ Note you'll have to resizse the ext3 filesystem after extending the LV http://tldp.org/HOWTO/LVM-HOWTO/extendlv.html
|
As per chrism01 - you need to resize your filesystem.
You don't need to start again. All your steps up to the lvextend are correct. Now, I assume that you used mke2fs to format a filesystem on /mnt/lvm In order to increase the usable space you need to now resize your original filesystem. First you unmount the filesystem: Code:
# umount /mnt/lvm Code:
# resize2fs /dev/VolGroup01/LogVol01 1G Code:
# mount -t ext4 /dev/VolGroup01/LogVol01 /mnt/lvm |
Phew - thanks very much. After going through several times and extending and reducing the Logical Volume and adding and removing different Physical Volumes, I think I've got it now.
Thanks again :) |
All times are GMT -5. The time now is 09:51 AM. |