LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   LVM on install centos 5.6, mis-allocated - options?? (https://www.linuxquestions.org/questions/linux-newbie-8/lvm-on-install-centos-5-6-mis-allocated-options-898828/)

needsleep 08-22-2011 03:32 PM

LVM on install centos 5.6, mis-allocated - options??
 
I really didn't understand LVM when I ran the installer's version to allocate disk space. After some more reading today, I see that I allocated all remaining disk space to a single logical volume, named lv_all. I then put the root drive on that and everything below it, except for /swap, which has it's own logical volume.
When I'm in LVM GUI, it says it has to unmount this volume, so I know that won't happen while the O/S is running. Do I need to start all over (reinstall Linux), or is there an option to run something from a CD that would allow me to re-allocate space before the O/S has a chance to load?

Thanks.

tommylovell 08-22-2011 05:10 PM

No need to reinstall, but "yes", you need to come up on your rescue CD. The reason for that is that you need to use the 'resize2fs' command to shrink the filesystem before you 'lvreduce' or 'lvresize' the Logical Volume and shrinking can't be done to a mounted filesystem.

Here's an example of shrinking my /home filesystem (just not from rescue mode, but they're similar).

Here's my original /home filesystem.
Code:

[root@athlon ~]# df -h /home
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/athlon-home
                      9.9G  506M  8.9G  6% /home

[root@athlon ~]# umount /home

[root@athlon ~]# lvs
  LV  VG    Attr  LSize  Origin Snap%  Move Log Copy%  Convert
  bkup athlon -wi-ao 300.00g                                     
  home athlon -wi-a-  10.00g                                     
  root athlon -wi-ao 100.00g                                     
  swap athlon -wi-ao  6.00g                                     
[root@athlon ~]#

When you come up in rescue mode LVM will not be active, so you need to activate it.
And since rescue mode uses busybox instead of the normal executables, the LVM commands are not independent commands but subcommands of 'lvm'.
Code:

[root@athlon ~]# lvm pvscan
  PV /dev/md0  VG athlon  lvm2 [1.36 TiB / 981.16 GiB free]
  Total: 1 [1.36 TiB] / in use: 1 [1.36 TiB] / in no VG: 0 [0  ]

[root@athlon ~]# lvm vgchange -ay
  4 logical volume(s) in volume group "athlon" now active

So, 'home is 10G; I want to make it 4G. I always like to shrink the file system smaller than its eventual size, then resize it up to fit the resized Logical Volume. Superstition, but I don't run into rounding discrepancies...
Code:

[root@athlon ~]# resize2fs /dev/mapper/athlon-home 3G
resize2fs 1.41.14 (22-Dec-2010)
Please run 'e2fsck -f /dev/mapper/athlon-home' first.

[root@athlon ~]# e2fsck -f /dev/mapper/athlon-home
e2fsck 1.41.14 (22-Dec-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mapper/athlon-home: 6852/655360 files (0.4% non-contiguous), 170537/2621440 blocks

[root@athlon ~]# resize2fs /dev/mapper/athlon-home 3G
resize2fs 1.41.14 (22-Dec-2010)
Resizing the filesystem on /dev/mapper/athlon-home to 786432 (4k) blocks.
The filesystem on /dev/mapper/athlon-home is now 786432 blocks long.

[root@athlon ~]# lvm lvresize /dev/mapper/athlon-home -L4G
  WARNING: Reducing active logical volume to 4.00 GiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce home? [y/n]: y
  Reducing logical volume home to 4.00 GiB
  Logical volume home successfully resized

[root@athlon ~]# resize2fs /dev/mapper/athlon-home
resize2fs 1.41.14 (22-Dec-2010)
Resizing the filesystem on /dev/mapper/athlon-home to 1048576 (4k) blocks.
The filesystem on /dev/mapper/athlon-home is now 1048576 blocks long.

[root@athlon ~]#

The outcome.
Code:

[root@athlon ~]# mount /home
[root@athlon ~]# df -h /home
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/athlon-home
                      4.0G  503M  3.3G  14% /home
[root@athlon ~]#

If worse comes to worse, you'll need to reinstall.

Hope this helps.

chrism01 08-22-2011 06:04 PM

Here's a good Ref/HOWTO http://tldp.org/HOWTO/LVM-HOWTO/

needsleep 08-22-2011 11:18 PM

Thank you Tommy for the information and the example. This is just what I need. Thanks for the time you put into your reply.

I read some more of the reference that chrism01 offered, which I discovered a few days ago while looking for LVM information on the net. It's a fantastic document of good penmanship, expert technical knowledge and a writing style that makes it easy to learn the material.

I'll report back when the deed is done.

needsleep 08-23-2011 04:22 PM

I am pleased to report that I was completely successful. There were some differences, as you said there might be.

I couldn't figure out how to activate the LVM. I tried various things, but in the end, I got into system/administration/service configuration. I selected the background services tab. lvm2-monitor was already active.

Any lvm command I try won't work. I get a command not found error. which lvm returned "no lvm in...".

The vg I was interested in reducing in size was vg_all. It is normally mounted on /. Well, Live CD is mounted on /, so I can't umount /. I figured out that the other name for this is /dev/mapper/vg_all-lv_all. I start using that name for it.

resize2fs -p /dev/mapper/vg_all-lv_all 20G tells me the volume is mounted.
umount /dev/mapper/vg_all-lv_all
...works!

I run resize2fs. I get the request to run e2fsck. I run e2fsck. I run resize2fs again.
Now, for some reason, the lvm commands start working.

I try to understand your statement about shrinking "the file system smaller than its eventual
size, then resizing it up to fit the resized Logical Volume," and something about rounding
discrepancies... I'm uncertain! I've given the filesystem twice as much space as it needs
for the data it has, or soon will have (Linux + Oracle). I decide to proceed without worrying about that for now. Next time, I will be more comfortable about this process and you'll have had time to explain it just a little more.

It's been a good experience, thanks in no small measure to your roadmap Tommy.

needsleep 08-23-2011 08:01 PM

I just had a flash of insight, Tommy. Are you saying you resize the filesystem slightly smaller, then inch up toward the size of the filesystem because you can add space with everything up, but in order to decrease space you have to go through the process you listed? Is that why you do it this way?

tommylovell 08-23-2011 10:34 PM

Quote:

Originally Posted by needsleep (Post 4451587)
Are you saying you resize the filesystem slightly smaller, then inch up toward the size of the filesystem because you can add space with everything up, but in order to decrease space you have to go through the process you listed? Is that why you do it this way?

Basically, you can always resize up to the size of the volume you are on, with the filesystem mounted or unmounted. You leave off the size on the 'resize2fs' and it figures it out, so it's not really inching up.

There really is no problem with resize2fs'ing a filesystem to 4GB, then lvresize'ing the volume to 4GB. But I wouldn't do that with a real partition where 4GB may not be exactly 4GB on the nose, but a value on a cylinder boundary that is roughly 4GB... Hence my statement that the way I do it is superstitious. I do it the same way whether it is on LVM or a real partition.


All times are GMT -5. The time now is 12:25 AM.