LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware
User Name
Password
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?

Notices


Reply
  Search this Thread
Old 10-31-2008, 01:10 PM   #1
prabhatsoni
Member
 
Registered: Oct 2004
Location: India
Distribution: FC 12
Posts: 233

Rep: Reputation: 30
How to resize a logical volume mounted as /var (FC9)


Hello folks,
I am embaressed to ask this.

I have a logical volume (/dev/mapper/VolGroup00-LogVol01) which is mounted as /var.
Similarly there is another volume (/dev/mapper/VolGroup00-LogVol03) which mounted as /home.

Earlier the size of /home was 1000M. There was some spare space in it. And I needed the increase the size of /var.
I used the graphical lvm tool system-config-lvm to reduce the size of /home. It intimated that it would umount the /home partition. I asked it to go ahead. So it went ahead and reduced the size of /home by 200 M. So far so good.

Now I used the same tool to increase the size of /var (/dev/mapper/VolGroup00-LogVol01). It again asked me that it would unmount it. I told it to go ahead. And there it struck, intimating that it can not unmount, and it is correct also. So how do I now ahead with this. I have searched far and wide for this but, friends, no help.

Can any one help me in this.


Thanks in advance.


Prabhat Soni
 
Old 10-31-2008, 01:37 PM   #2
custangro
Senior Member
 
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , RHEL
Posts: 1,979
Blog Entries: 1

Rep: Reputation: 209Reputation: 209Reputation: 209
Quote:
Originally Posted by prabhatsoni View Post
Hello folks,
I am embaressed to ask this.

I have a logical volume (/dev/mapper/VolGroup00-LogVol01) which is mounted as /var.
Similarly there is another volume (/dev/mapper/VolGroup00-LogVol03) which mounted as /home.

Earlier the size of /home was 1000M. There was some spare space in it. And I needed the increase the size of /var.
I used the graphical lvm tool system-config-lvm to reduce the size of /home. It intimated that it would umount the /home partition. I asked it to go ahead. So it went ahead and reduced the size of /home by 200 M. So far so good.

Now I used the same tool to increase the size of /var (/dev/mapper/VolGroup00-LogVol01). It again asked me that it would unmount it. I told it to go ahead. And there it struck, intimating that it can not unmount, and it is correct also. So how do I now ahead with this. I have searched far and wide for this but, friends, no help.

Can any one help me in this.


Thanks in advance.


Prabhat Soni
I would normally do this in the command line...

Code:
root@host# lvextend -L +512M /dev/mapper/VolGroup00-LogVol01
root@host# resize2fs /dev/mapper/VolGroup00-LogVol01
DISCLAIMER: I take NO responsibility for lost data...use the above commands at your own risk...

-C
 
Old 10-31-2008, 09:02 PM   #3
prabhatsoni
Member
 
Registered: Oct 2004
Location: India
Distribution: FC 12
Posts: 233

Original Poster
Rep: Reputation: 30
That is right sir, but how do I go about unmounting the var partition.
I could create some other partition, copy all the files of /var to it, , then change the entries in the fstab to point to the new partition so that this new partition is now the /var, then reboot and then do the opertation with the older logical volume.
Besides the exercise looking inelegant I am also doubtful, whether a simple cp command would do for copying the contents of the current /var, or I will be required to use dd (or some other) command.


Prabhat Soni
 
Old 11-01-2008, 12:33 AM   #4
custangro
Senior Member
 
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , RHEL
Posts: 1,979
Blog Entries: 1

Rep: Reputation: 209Reputation: 209Reputation: 209
Quote:
Originally Posted by prabhatsoni View Post
That is right sir, but how do I go about unmounting the var partition.
I could create some other partition, copy all the files of /var to it, , then change the entries in the fstab to point to the new partition so that this new partition is now the /var, then reboot and then do the opertation with the older logical volume.
Besides the exercise looking inelegant I am also doubtful, whether a simple cp command would do for copying the contents of the current /var, or I will be required to use dd (or some other) command.


Prabhat Soni
If I may ask...

Why do you need to unmount it?

I have added more space to a LVM and resized it without having to unmount it...

-C
 
Old 11-01-2008, 01:03 AM   #5
prabhatsoni
Member
 
Registered: Oct 2004
Location: India
Distribution: FC 12
Posts: 233

Original Poster
Rep: Reputation: 30
When I use system-config-lvm (graphical tool for lvm) before resizing, it asks me that the volume will have to be unmounted, and whether it should do it. To this I asked it to go ahead and unmount.
I dont want to unmount it. The tool is implying that the resizing can be done only after unmounting.
Am I making some mistake in invoking the tool.
From what you say I gather that it is possible to resize the volume on the fly. If that be so, perhaps I am wrong in using system-config-lvm. Please let me share your secret.
Or, if there is a howto somewhere, please direct me to it.

Thanking for taking time to reply.


Prabhat Soni

Last edited by prabhatsoni; 11-01-2008 at 09:26 AM.
 
Old 11-01-2008, 10:42 AM   #6
custangro
Senior Member
 
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , RHEL
Posts: 1,979
Blog Entries: 1

Rep: Reputation: 209Reputation: 209Reputation: 209
Quote:
Originally Posted by prabhatsoni View Post
When I use system-config-lvm (graphical tool for lvm) before resizing, it asks me that the volume will have to be unmounted, and whether it should do it. To this I asked it to go ahead and unmount.
I dont want to unmount it. The tool is implying that the resizing can be done only after unmounting.
Am I making some mistake in invoking the tool.
From what you say I gather that it is possible to resize the volume on the fly. If that be so, perhaps I am wrong in using system-config-lvm. Please let me share your secret.
Or, if there is a howto somewhere, please direct me to it.

Thanking for taking time to reply.


Prabhat Soni
I'm not 100% sure; but I think that the tool put that in as a "fail safe" (i.e. a "just in case")

I have always resized without umounting....

However, you should make a backup of /var just in case something goes wrong.

Then you can preform the steps that I mentioned before.

If you have any questions, you can post.

-C
 
Old 11-01-2008, 11:06 AM   #7
prabhatsoni
Member
 
Registered: Oct 2004
Location: India
Distribution: FC 12
Posts: 233

Original Poster
Rep: Reputation: 30
Are you using system-config-lvm for resizing on the fly ?
Could you please post a brief (briefest, if you find it inconvenient) howto for resizing on the fly.

Thanks for everything.

Prabhat Soni
 
Old 11-01-2008, 12:01 PM   #8
prabhatsoni
Member
 
Registered: Oct 2004
Location: India
Distribution: FC 12
Posts: 233

Original Poster
Rep: Reputation: 30
Ok !
I gave up playing with the system-config-lvm, and used the commands posted by you, and was able to increase the size of /var. Thank you very much.

But from academic point of view please refer to the following link:
http://www.linuxquestions.org/questi...ight=resize2fs

Here one of the members has posted
Quote:
I was able to get this to work by unmounting the filesystem and using "system-config-lvm".
How can anyone unmount a working system ? It is a working system since otherwise you won't have system-config-lvm.

Any ideas ?


Prabhat Soni
 
Old 11-01-2008, 12:27 PM   #9
custangro
Senior Member
 
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , RHEL
Posts: 1,979
Blog Entries: 1

Rep: Reputation: 209Reputation: 209Reputation: 209
Quote:
Originally Posted by prabhatsoni View Post
Ok !
I gave up playing with the system-config-lvm, and used the commands posted by you, and was able to increase the size of /var. Thank you very much.

But from academic point of view please refer to the following link:
http://www.linuxquestions.org/questi...ight=resize2fs

Here one of the members has posted


How can anyone unmount a working system ? It is a working system since otherwise you won't have system-config-lvm.

Any ideas ?


Prabhat Soni

Glad to hear that it worked out for you!

I have never unmounted a filesystem while it's in use. If the file system is quiescent (i.e. when it's not doing anything at the moment).

From what I gather /var is pretty busy on an active file system. I don't know if you _can_ unmount it when it's "active".

This is one of the strengths of LVM...you can resize "on the fly" without taking it "offline".

I have never used system-config-lvm so I don't know too much about it.
 
Old 11-01-2008, 01:25 PM   #10
prabhatsoni
Member
 
Registered: Oct 2004
Location: India
Distribution: FC 12
Posts: 233

Original Poster
Rep: Reputation: 30
Feedback

When I posted the last messages, I had not rebooted the system after this resizing (by giving twin commands).
When I rebooted, the system fell to "single user" with reports about errors in the file system. I then ran e2fsck and gave "y" to all its queries (with trepidation). And after repairing, I rebooted it and was online.
What people say about resizing (more so when it is on the fly) being a dangerous command is definitely true.
What I believe is this that it would not have precipitated, had I known how to use system-config-lvm correctly. Because when I resized the /home through system-config-lvm, the going was really smooth.
So if there are any gurus who can guide the vast multitude of lvm-users through the perils of this exercise, they should come forward and write a brief howto.
Till then it is my advise to all that before issuing resize2fs command, please ensure to take a full back of your partition.
AFter completing this resizing exercise one should always run the e2fsck. But for this you would be required to unmount the file system, which is (perhaps) not possible for /var etc. So again we are struck.

Or did I slipped somewhere ? How come custangro is always doing it on the fly and not having any problem !

Any ideas ?


Prabhat Soni
 
Old 01-04-2009, 03:40 PM   #11
zulsolar
LQ Newbie
 
Registered: Mar 2005
Location: Buenos Aires, Argentina
Distribution: Slackware, Solaris 10, Ubuntu
Posts: 9

Rep: Reputation: 0
Thumbs up

Hi guys,

I had a problem. When I was trying to set up a cluster with Centos using VMware, I configure VM's with low space. Root filesystem almost ran out of space right after OS was installed. I did'n want to re-build everything. So I was googling around for some answers, the most important was if it was possible to increase a LV wich is used by root without rebooting or using a rescue CD. These are my founds. I hope this helps. Remember that all this work was performed inside a VM, I think that this should be used with careful in production environments.

As you can see here, I had 91% used by / filesystem. My mistake was to let the OS performs automagically all the partition work, very bad!

Code:
[root@localhost ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                      2.9G  2.5G  268M  91% /
/dev/sda1              99M   12M   83M  13% /boot
tmpfs                 506M     0  506M   0% /dev/shm
/dev/hdc              3.8G  3.8G     0 100% /media/CentOS_5.2_Final
[root@localhost ~]#
This is my LVM setup:

Code:
[root@localhost ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               VolGroup00
  PV Size               4.89 GB / not usable 20.47 MB
  Allocatable           yes (but full)
  PE Size (KByte)       32768
  Total PE              156
  Free PE               0
  Allocated PE          156
  PV UUID               RHROqS-6opV-61kb-RnQ3-aClu-AD4d-4SD6OP
   

[root@localhost ~]# vgdisplay
  --- Volume group ---
  VG Name               VolGroup00
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               4.88 GB
  PE Size               32.00 MB
  Total PE              156
  Alloc PE / Size       156 / 4.88 GB
  Free  PE / Size       0 / 0   
  VG UUID               zTcy0h-Ixj5-L3an-0r01-xaSE-x2Zo-2XYL2f
   
[root@localhost ~]# lvdisplay
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol00
  VG Name                VolGroup00
  LV UUID                CfrNXh-aPVr-0z48-S8ds-Ysx8-9Tir-DXRj45
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                2.94 GB
  Current LE             94
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
   
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol01
  VG Name                VolGroup00
  LV UUID                fEJdkW-WDdB-LDPg-L3Qr-YC08-h8DW-n41wBq
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                1.94 GB
  Current LE             62
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
   
[root@localhost ~]#

This shows mount command:

Code:
[root@localhost ~]# mount
/dev/mapper/VolGroup00-LogVol00 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
none on /proc/fs/vmblock/mountPoint type vmblock (rw)
/dev/hdc on /media/CentOS_5.2_Final type iso9660 (ro,noexec,nosuid,nodev,uid=500)
[root@localhost ~]#

I have two logical volumes. LogVol00 has 2.94 GB and is used by / filesystem. LogVol01 has 1.94 GB and is not mounted neither used. So I thought it was possible to reduce LogVol01 and increase LogVol00 and then resize / filesystem.
---
Code:

[root@localhost ~]# lvdisplay
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol00
  VG Name                VolGroup00
  LV UUID                CfrNXh-aPVr-0z48-S8ds-Ysx8-9Tir-DXRj45
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                2.94 GB
  Current LE             94
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
   
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol01
  VG Name                VolGroup00
  LV UUID                fEJdkW-WDdB-LDPg-L3Qr-YC08-h8DW-n41wBq
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                1.94 GB
  Current LE             62
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
   
[root@localhost ~]#

I reduce LV LogVol01 with the next command:
resize2fs /dev/VolGroup00/LogVol01 1G


Code:
[root@localhost ~]# lvreduce -L1G /dev/VolGroup00/LogVol01
  WARNING: Reducing active and open logical volume to 1.00 GB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce LogVol01? [y/n]: y
  Reducing logical volume LogVol01 to 1.00 GB
  Logical volume LogVol01 successfully resized
We can see now that LogVol01 has been reduced.
Code:


[root@localhost ~]# lvdisplay
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol00
  VG Name                VolGroup00
  LV UUID                CfrNXh-aPVr-0z48-S8ds-Ysx8-9Tir-DXRj45
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                2.94 GB
  Current LE             94
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
   
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol01
  VG Name                VolGroup00
  LV UUID                fEJdkW-WDdB-LDPg-L3Qr-YC08-h8DW-n41wBq
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                1.00 GB
  Current LE             32
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
   
[root@localhost ~]#
Now we extend LV LogVol00 in 1 GB with this command
lvextend -L +1G /dev/VolGroup00/LogVol00

Code:

[root@localhost ~]# lvextend -L +1G /dev/VolGroup00/LogVol00
  Extending logical volume LogVol00 to 3.94 GB
  Insufficient free space: 32 extents needed, but only 30 available
[root@localhost ~]# lvdisplay
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol00
  VG Name                VolGroup00
  LV UUID                CfrNXh-aPVr-0z48-S8ds-Ysx8-9Tir-DXRj45
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                2.94 GB
  Current LE             94
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
   
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol01
  VG Name                VolGroup00
  LV UUID                fEJdkW-WDdB-LDPg-L3Qr-YC08-h8DW-n41wBq
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                1.00 GB
  Current LE             32
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
   
[root@localhost ~]# resize2fs /dev/VolGroup00/LogVol00
resize2fs 1.39 (29-May-2006)
The filesystem is already 770048 blocks long.  Nothing to do!

[root@localhost ~]#

What happened?!? LV LogVol00 did not extend but why? In a closer look, we can see that we are not allowed to extend this LV by 1 GB as there is not enough space to do that. We only have 30 extents in our LV and 1 GB needs 32 of them.
The man of lvextend shows find the following:

"...

Code:
-l, --extents [+]LogicalExtentsNumber[%{VG|LV|PVS|FREE}]
              Extend or set the logical volume size in units of logical extents.  With the + sign the  value  is
              added  to  the actual size of the logical volume and without it, the value is taken as an absolute
              one.  The number can also be expressed as a percentage of the total space in the Volume Group with
              the  suffix  %VG,  relative to the existing size of the Logical Volume with the suffix %LV, of the
              remaining free space for the specified PhysicalVolume(s) with the suffix %PVS, or as a  percentage
              of the remaining free space in the Volume Group with the suffix %FREE.
..."


So, we are going to try again with the next command:

lvextend -l +30 /dev/VolGroup00/LogVol00

Code:
[root@localhost ~]# lvextend -l +30 /dev/VolGroup00/LogVol00
  Extending logical volume LogVol00 to 3.88 GB
  Logical volume LogVol00 successfully resized
[root@localhost ~]# lvdisplay
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol00
  VG Name                VolGroup00
  LV UUID                CfrNXh-aPVr-0z48-S8ds-Ysx8-9Tir-DXRj45
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                3.88 GB
  Current LE             124
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
   
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol01
  VG Name                VolGroup00
  LV UUID                fEJdkW-WDdB-LDPg-L3Qr-YC08-h8DW-n41wBq
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                1.00 GB
  Current LE             32
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
   
[root@localhost ~]#
As we can see, we have succedded in resizing our LV. Now it has 3.88 GB.


Next step is resizing root filesystem on the fly. Will this be possible? The next link is rather old, http://www.redhat.com/magazine/009ju...ed_hat_speaks/
Among other things, it says it can be performed and sounds logical to me, why develop a tool for huge datacenters and high availavility clusters that will need a reboot in order to increase or decrease a filesystem?


We try the following command:
resize2fs /dev/VolGroup00/LogVol00


Code:
[root@localhost ~]# resize2fs /dev/VolGroup00/LogVol00
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizing required
Performing an on-line resize of /dev/VolGroup00/LogVol00 to 1015808 (4k) blocks.
The filesystem on /dev/VolGroup00/LogVol00 is now 1015808 blocks long.

[root@localhost ~]#
That's all? No error messages, no segmentation fault? Do I feel lucky? Let's check.


This was the df -h output command before changes:


Code:
[root@localhost ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                      2.9G  2.5G  268M  91% /
/dev/sda1              99M   12M   83M  13% /boot
tmpfs                 506M     0  506M   0% /dev/shm
/dev/hdc              3.8G  3.8G     0 100% /media/CentOS_5.2_Final
[root@localhost ~]# 
And this is the output now after the changes:

Code:
[root@localhost ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                      3.8G  2.5G  1.2G  69% /
/dev/sda1              99M   12M   83M  13% /boot
tmpfs                 506M     0  506M   0% /dev/shm
/dev/hdc              3.8G  3.8G     0 100% /media/CentOS_5.2_Final
[root@localhost ~]#
Summarizing, we have 2 LV in the same VG, one using by root filesystem and the other one unusued. We can reduce one of them in order to extend the other one. And once extended it is possible to resize the ext3 mounted filesystem (even root), on the fly, without reboot, without fsck, everything while the system is running. Almost unvelievable, huh?


These were the steps, just for copy & paste


Code:
lvreduce -L1G /dev/VolGroup00/LogVol01

lvextend -l +30 /dev/VolGroup00/LogVol00

resize2fs /dev/VolGroup00/LogVol00

Again, remember that all this work was performed inside a VM, I think that this should be used with careful in production environments.

Hope this helps everyone. Thanks for reading.



DISCLAIMER: I take NO responsibility for lost data...use the above commands at your own risk...

Last edited by zulsolar; 01-04-2009 at 03:44 PM.
 
  


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
How to Resize Root LVM Logical Volume??? jdupre Fedora 17 10-02-2010 07:21 AM
LXer: What is the procedure to resize an LVM2 logical volume and the ext2 or ext3 fil LXer Syndicated Linux News 0 07-17-2008 03:50 AM
Fedora LVM volume group & Physical Volume resize problem gabeyg Fedora 1 05-14-2008 11:26 AM
How do I move /var to a logical volume? bret Linux - General 5 02-03-2006 11:59 AM
In fc3 Can I umount a Logical Volume which is mounted auto in fstab? TomF Linux - Newbie 2 12-16-2004 01:40 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 11:38 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