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