How to expand online a LVM partition in Ubuntu

This is something that I have to do several times in the last months. It is a really simple procedure but I always have to look for it in Google because I never remember the exact steps.

Context

  • An Ubuntu 11.04 server with LVM installed and configured.
  • A new hard disk added to the server (usually it is a virtual server and a virtual hard disk). For this tip I am going to assume that the new disk is /dev/sdb
  • I want to expand the root partition adding the space in the new disk.

Procedure

Create a new Physical Volume using the recently added disk…

root@server:~# pvcreate /dev/sdb

It is not necessary to create a partition table in the new disk.

Now we have to add to the Volume Group the new Physical Volume…

root@server:~# vgdisplay
--- Volume group ---
VG Name vg01
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 17.75 GiB
PE Size 4.00 MiB
Total PE 4545
Alloc PE / Size 4545 / 17.75 GiB
Free PE / Size 0 / 0
VG UUID D9jl8R-zqxe-7wwn-3Co2-dUhu-Dnwr-aNbKpv
root@server:~# vgextend vg01 /dev/sdb

Next step is expand the Logical Volume

root@server:~# lvextend -l+2567 /dev/vg01/root

We could use the lvdisplay command to find the exact name of the Logical Volume and the total number of free Physical Extends (PE).

Last step is to resize the file system in the disk to use all the space. We could do this online without need to unmount the file system.

root@server:~# resize2fs /dev/vg01/root

You can find this procedure in multiples places in Internet, the last one I have used is this.

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *