LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Partitions and LVM (https://www.linuxquestions.org/questions/linux-newbie-8/partitions-and-lvm-812732/)

arashi256 06-07-2010 03:54 PM

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 :)

MensaWater 06-07-2010 04:09 PM

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.

arashi256 06-08-2010 04:42 AM

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 :)

alli_yas 06-08-2010 05:02 AM

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).

arashi256 06-08-2010 05:11 AM

Thanks, that explained it pretty well!

MensaWater 06-08-2010 10:21 AM

Quote:

Originally Posted by arashi256 (Post 3996405)
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 :)

I was saying for a single drive you don't need multiple itty-bitty partitions. You can have them but they don't gain you anything if you're putting them all in a single VG.

alli_yas 06-08-2010 10:25 AM

Quote:

I was saying for a single drive you don't need multiple itty-bitty partitions. You can have them but they don't gain you anything if you're putting them all in a single VG.
I agree with MensaWater here. The real benefit of getting fancy and having a lot of PV's and VG's; is when you have more than one drive. I understand you're playing at the moment; but good practice (in my opinion ;)) when installing with a single disk; is too keep things simple.

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).

arashi256 06-08-2010 10:27 AM

Quote:

Originally Posted by MensaWater (Post 3996726)
I was saying for a single drive you don't need multiple itty-bitty partitions. You can have them but they don't gain you anything if you're putting them all in a single VG.

I'm aware of that, but my RHEL test "server" is only a crusty Dell Latitude laptop with a single 80GB disk. This is the only machine I have that it doesn't matter if I hose completely :) I don't *need* multiple partitions on a single drive, but I'm figuring out LVM across multiple partitions and I'll use some of the free space to create partitions to learn RAID also. It's simply for testing and learning and not actually being used for anything in particular :D

arashi256 06-08-2010 10:29 AM

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

arashi256 06-08-2010 04:16 PM

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
  --- Logical volume ---
  LV Name                /dev/VolGroup01/LogVol01
  VG Name                VolGroup01
  LV UUID                Gji013-ROYQ-Qj9C-OETa-JeVS-980X-1dhtlU
  LV Write Access        read/write
  LV Status              available
  # open                1
  LV Size                500.00 MB
  Current LE            125
  Segments              1
  Allocation            inherit
  Read ahead sectors    auto
  - currently set to    256
  Block device          253:0

[root@joshua9 ~]# lvextend /dev/VolGroup01/LogVol01 --size 1000MB
  Extending logical volume LogVol01 to 1000.00 MB
  Logical volume LogVol01 successfully resized
[root@joshua9 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/hda2            9.5G  2.1G  6.9G  24% /
/dev/hda1            487M  22M  440M  5% /boot
tmpfs                252M    0  252M  0% /dev/shm
/dev/mapper/VolGroup01-LogVol01
                      485M  11M  469M  3% /mnt/lvm
[root@joshua9 ~]# lvdisplay
  --- Logical volume ---
  LV Name                /dev/VolGroup01/LogVol01
  VG Name                VolGroup01
  LV UUID                Gji013-ROYQ-Qj9C-OETa-JeVS-980X-1dhtlU
  LV Write Access        read/write
  LV Status              available
  # open                1
  LV Size                1000.00 MB
  Current LE            250
  Segments              1
  Allocation            inherit
  Read ahead sectors    auto
  - currently set to    256
  Block device          253:0

As you can see from the above, I used lvextend to extend the Logical Volume to 1GB, yet the mount point still only shows 500MB, which I suppose it's because the partition itself isn't formatted, so each time a Logical Volume is extended the new space is unformatted. Should I have formatted the partition before adding the Volume Group to it? I can't seem to format the entire partition now because of the Volume Group on it, as the system says it's in use.

Do I have to start again and should I simply have formatted the partition before adding the Volume Group?

chrism01 06-09-2010 01:07 AM

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

alli_yas 06-09-2010 02:24 AM

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
Then you resize the filesystem:

Code:

# resize2fs /dev/VolGroup01/LogVol01 1G
Then remount:

Code:

# mount -t ext4 /dev/VolGroup01/LogVol01 /mnt/lvm
That should do it!

arashi256 06-09-2010 04:03 AM

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.