LinuxQuestions.org
Visit Jeremy's Blog.
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 08-22-2011, 04:32 PM   #1
needsleep
Member
 
Registered: Apr 2011
Location: Minneapolis
Distribution: CentOS 7
Posts: 80

Rep: Reputation: 0
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.
 
Old 08-22-2011, 06:10 PM   #2
tommylovell
Member
 
Registered: Nov 2005
Distribution: Fedora, Redhat
Posts: 372

Rep: Reputation: 101Reputation: 101
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.
 
Old 08-22-2011, 07:04 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
Here's a good Ref/HOWTO http://tldp.org/HOWTO/LVM-HOWTO/
 
Old 08-23-2011, 12:18 AM   #4
needsleep
Member
 
Registered: Apr 2011
Location: Minneapolis
Distribution: CentOS 7
Posts: 80

Original Poster
Rep: Reputation: 0
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.
 
Old 08-23-2011, 05:22 PM   #5
needsleep
Member
 
Registered: Apr 2011
Location: Minneapolis
Distribution: CentOS 7
Posts: 80

Original Poster
Rep: Reputation: 0
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.
 
Old 08-23-2011, 09:01 PM   #6
needsleep
Member
 
Registered: Apr 2011
Location: Minneapolis
Distribution: CentOS 7
Posts: 80

Original Poster
Rep: Reputation: 0
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?
 
Old 08-23-2011, 11:34 PM   #7
tommylovell
Member
 
Registered: Nov 2005
Distribution: Fedora, Redhat
Posts: 372

Rep: Reputation: 101Reputation: 101
Quote:
Originally Posted by needsleep View Post
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Install CentOS V5.6 onto pre-degraded RAID1 + LVM? goony1 Linux - Software 0 06-11-2011 02:06 AM
centos - disable LVM via kickstart draeath Linux - Server 6 12-14-2010 10:04 AM
Error 15: File not Found after fresh install of Centos 5.3 with LVM Keds Linux - Server 2 10-21-2009 02:34 AM
is available for LVM for Linux/CentOS marcos602phx Linux - Newbie 6 10-05-2009 01:30 PM
Centos 5.2 LVM - Not Enough Space dschornack Linux - Server 5 08-07-2008 06:33 PM


All times are GMT -5. The time now is 05:40 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration