LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-07-2010, 03:54 PM   #1
arashi256
Member
 
Registered: Jan 2008
Location: Brighton, UK
Distribution: Ubuntu 18.04 / CentOS 7.6
Posts: 397

Rep: Reputation: 62
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
 
Old 06-07-2010, 04:09 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
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.
 
1 members found this post helpful.
Old 06-08-2010, 04:42 AM   #3
arashi256
Member
 
Registered: Jan 2008
Location: Brighton, UK
Distribution: Ubuntu 18.04 / CentOS 7.6
Posts: 397

Original Poster
Rep: Reputation: 62
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
 
Old 06-08-2010, 05:02 AM   #4
alli_yas
Member
 
Registered: Apr 2010
Location: Johannesburg
Distribution: Fedora 14, RHEL 5.5, CentOS 5.5, Ubuntu 10.04
Posts: 559

Rep: Reputation: 92
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).
 
1 members found this post helpful.
Old 06-08-2010, 05:11 AM   #5
arashi256
Member
 
Registered: Jan 2008
Location: Brighton, UK
Distribution: Ubuntu 18.04 / CentOS 7.6
Posts: 397

Original Poster
Rep: Reputation: 62
Thanks, that explained it pretty well!
 
Old 06-08-2010, 10:21 AM   #6
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Quote:
Originally Posted by arashi256 View Post
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.
 
Old 06-08-2010, 10:25 AM   #7
alli_yas
Member
 
Registered: Apr 2010
Location: Johannesburg
Distribution: Fedora 14, RHEL 5.5, CentOS 5.5, Ubuntu 10.04
Posts: 559

Rep: Reputation: 92
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).
 
Old 06-08-2010, 10:27 AM   #8
arashi256
Member
 
Registered: Jan 2008
Location: Brighton, UK
Distribution: Ubuntu 18.04 / CentOS 7.6
Posts: 397

Original Poster
Rep: Reputation: 62
Quote:
Originally Posted by MensaWater View Post
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
 
Old 06-08-2010, 10:29 AM   #9
arashi256
Member
 
Registered: Jan 2008
Location: Brighton, UK
Distribution: Ubuntu 18.04 / CentOS 7.6
Posts: 397

Original Poster
Rep: Reputation: 62
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
 
Old 06-08-2010, 04:16 PM   #10
arashi256
Member
 
Registered: Jan 2008
Location: Brighton, UK
Distribution: Ubuntu 18.04 / CentOS 7.6
Posts: 397

Original Poster
Rep: Reputation: 62
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?
 
Old 06-09-2010, 01:07 AM   #11
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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
 
1 members found this post helpful.
Old 06-09-2010, 02:24 AM   #12
alli_yas
Member
 
Registered: Apr 2010
Location: Johannesburg
Distribution: Fedora 14, RHEL 5.5, CentOS 5.5, Ubuntu 10.04
Posts: 559

Rep: Reputation: 92
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!
 
1 members found this post helpful.
Old 06-09-2010, 04:03 AM   #13
arashi256
Member
 
Registered: Jan 2008
Location: Brighton, UK
Distribution: Ubuntu 18.04 / CentOS 7.6
Posts: 397

Original Poster
Rep: Reputation: 62
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Extended partitions and LVM gargamel Linux - Server 5 07-19-2010 11:48 AM
LVM partitions noir911 Red Hat 2 06-09-2009 06:19 AM
Partitions LVM Kryptos Linux - Newbie 1 11-17-2007 11:54 PM
LXer: Back Up (And Restore) LVM Partitions With LVM Snapshots LXer Syndicated Linux News 0 04-17-2007 11:16 AM
how do I add partitions to drives that have Logical Volume (LVM) partitions? The MJ Linux - Software 5 08-17-2006 06:15 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration