Rooot.net

  • Increase font size
  • Default font size
  • Decrease font size
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Home Geek stuff Linux Resize root partition without reboot

Resize root partition without reboot

Today let's resize a root EXT3 partition on a LVM without rebooting!

As every sysadmin knows, partition size must be choosen carefully to avoid running into big problems if one of your partition runs out of space. Hopefully LVM  allow you to manage disk space in a flexible way, allowing you to create partitions across several physical hard drives. Now let's see how to resize a root partition with no service interruption (!). In this example, my root partition uses the EXT3 format and is managed by LVM.

The server LVM has a virtual group "raid0" of 558Go. This virtual group is 100% used.

~$ vgdisplay raid0
--- Volume group ---
VG Name raid0
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 558,79 GB
PE Size 4,00 MB
Total PE 143051
Alloc PE / Size 143051 / 558,79 GB
Free PE / Size 0 / 0
VG UUID QR8u96-fZ3S-nLha-Px6Q-E2VA-g8Gd-IMoIss

In this virtual group are 3 logical volumes : "root", "var" et "storage".

~$ lvdisplay raid0
--- Logical volume ---
LV Name /dev/raid0/root
VG Name raid0
LV UUID WXEOOi-LYiD-IN6P-nfa7-QbbX-wmxx-jAa3YV
LV Write Access read/write
LV Status available
# open 1
LV Size 4,88 GB
Current LE 1250
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0

--- Logical volume ---
LV Name /dev/raid0/var
VG Name raid0
LV UUID 6bOrnk-vtpI-egk7-Qw9I-M0Ml-j0gq-qTIXGS
LV Write Access read/write
LV Status available
# open 1
LV Size 2,93 GB
Current LE 750
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1

--- Logical volume ---
LV Name /dev/raid0/storage
VG Name raid0
LV UUID lLlNM8-Zc8f-Le8H-Nvby-YQnO-ZPZI-gQsaTQ
LV Write Access read/write
LV Status available
# open 0
LV Size 550,98 GB
Current LE 141051
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2

To get some space into the virtual group I first want to reduce the size of the "storage" logical group. The safe way to do it is to unmount the EXT3 partition and check it before resizing it. Once done I can downsize the logical volume containing this EXT3 partition with no risk of corruption for the filesystem.

~$ umount /dev/mapper/raid0-storage

The e2fsck tool has a "-f" option to force filesystem check even if it looks "clean".

~$ e2fsck -f /dev/raid0/storage
e2fsck 1.41.0 (10-Jul-2008)
Passe 1 : vérification des i-noeuds, des blocs et des tailles
Passe 2 : vérification de la structure des répertoires
Passe 3 : vérification de la connectivité des répertoires
Passe 4 : vérification des compteurs de référence
Passe 5 : vérification de l'information du sommaire de groupe
/dev/raid0/storage : 75366/72220672 fichiers (1.0% non contigus), 110012950/144436224 blocs

You can now run resize2fs with the "-p" option to enable automatic repair.

~$ resize2fs -p /dev/raid0/storage 538G
resize2fs 1.41.0 (10-Jul-2008)
Resizing the filesystem on /dev/raid0/storage to 141033472 (4k) blocks.
Début de la passe 2 (max = 1822064)
Relocalisation de blocs XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Début de la passe 3 (max = 4408)
Examen de la table d'i-noeuds XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Début de la passe 4 (max = 4264)
Mise à jour des références d'i-noeudsXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXLe système de fichiers /dev/raid0/storage a maintenant une taille de 141033472 blocs.

The EXT3 partition is now resized. We can safely resize the logical volume.

~$ lvresize -L 538G /dev/raid0/storage
WARNING: Reducing active logical volume to 538,00 GB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce storage? [y/n]: y
Reducing logical volume storage to 538,00 GB
Logical volume storage successfully resized

Ok. now we mount the partition.

~$ mount /dev/mapper/raid0-storage

This resizing operation freed some space in the virtual group.

~$ vgdisplay raid0
--- Volume group ---
VG Name raid0
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 1
Act PV 1
VG Size 558,79 GB
PE Size 4,00 MB
Total PE 143051
Alloc PE / Size 139728 / 545,81 GB
Free PE / Size 3323 / 12,98 GB
VG UUID QR8u96-fZ3S-nLha-Px6Q-E2VA-g8Gd-IMoIss

We're going to use this space to size up the root partition. When increasing a partition size there is no risk of data lost or corruption. No need to unmount or check the partition? Great! We can do it without any service interruption.

~$ lvresize -L +12,98G /dev/raid0/root
Rounding up size to full physical extent 12,98 GB
Extending logical volume root to 17,86 GB
Logical volume root successfully resized

One last check shows us the space has been allocated; the virtual group has no more free space.

~$ vgdisplay raid0
--- Volume group ---
VG Name raid0
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 6
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 1
Act PV 1
VG Size 558,79 GB
PE Size 4,00 MB
Total PE 143051
Alloc PE / Size 143051 / 558,79 GB
Free PE / Size 0 / 0
VG UUID QR8u96-fZ3S-nLha-Px6Q-E2VA-g8Gd-IMoIss

Hope this helps Wink

Comments
Add New Search
João Matos  - You didn't resize the filesystem.   |::ffff:193.136..xxx |2011-05-25 21:21:05
You extended the root logical volume, but the filesystem is still the same size
as before.
If you had checked df before and after you did this, it'd be the same
- albeit with a smaller storage partition.

You should also run extend2fs again
for storage to make it take any unused space after rounding.
Santosh Behuray   |::ffff:209.51.1.xxx |2012-05-09 17:35:21
Thanks.

I performed the same and had the freed up space added the root volume.
Had to do a bit of calculations though to get the size right. The messages from
extend2fs gives the available blocks, and calculated the new size from there.

-
Santosh
Write comment
Name:
Email:
 
Website:
Title:
UBBCode:
[b] [i] [u] [url] [quote] [code] [img] 
 
 
:angry::0:confused::cheer:B):evil::silly::dry::lol::kiss::D:pinch:
:(:shock::X:side::):P:unsure::woohoo::huh::whistle:;):s
:!::?::idea::arrow:
 
Please input the anti-spam code that you can read in the image.

3.26 Copyright (C) 2008 Compojoom.com / Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."