Feb 6, 2011

Fitting virtual disks after reducing

This is the continuation of the article Shrinking virtual disks with LVM. It turns out that once you have mirrored your virtual disk to another smaller, it is normal to have wasted some space in the process, that is to say, an area of the new virtual disk which has been unused.

For this reason, we are going to learn in this article how to recover it. At this moment, the available size of our new disk is 16 GB.

[root@centos ~]# lvs
LV       VG         Attr   LSize  Origin Snap%  Move Log Copy%  Convert
LogVol00 VolGroup00 -wi-ao 16,00G                            
LogVol01 VolGroup00 -wi-ao  1,00G

The idea is to create a new partition on the disk in order to take that unutilized space. The partition type must be Linux LVM (8e hexadecimal code).

[root@centos ~]# fdisk /dev/sda
Orden (m para obtener ayuda): n
Acción de la orden
e   Partición extendida
p   Partición primaria (1-4)
Número de partición (1-4): 3
Primer cilindro (2241-2480, valor predeterminado 2241):
Se está utilizando el valor predeterminado 2241
Último cilindro o +tamaño o +tamañoM o +tamañoK (2241-2480, valor predeterminado 2480):
Se está utilizando el valor predeterminado 2480

Orden (m para obtener ayuda): t
Número de partición (1-4): 3
Código hexadecimal (escriba L para ver los códigos): 8e
Se ha cambiado el tipo de sistema de la partición 3 por 8e (Linux LVM)

Orden (m para obtener ayuda): w

[root@centos ~]# partprobe

[root@centos ~]# fdisk -l

Disco /dev/sda: 20.4 GB, 20401094656 bytes
255 heads, 63 sectors/track, 2480 cylinders
Unidades = cilindros de 16065 * 512 = 8225280 bytes

Disposit. Inicio    Comienzo      Fin      Bloques  Id  Sistema
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        2241    17891328+  8e  Linux LVM
/dev/sda3            2241        2480     1924849   8e  Linux LVM

Next step is to set up a PV (physical volume) on that new partition.

[root@centos ~]# pvcreate /dev/sda3

Now we have to add the new PV created to the existing VG (volume group) and then, extend the LV (logical volume).

[root@centos ~]# vgextend VolGroup00 /dev/sda3

[root@centos ~]# lvextend -l +100%FREE /dev/VolGroup00/LogVol00

And finally, we must only to expand the ext3 filesystem.

[root@centos ~]# resize2fs /dev/VolGroup00/LogVol00

After the operation, we have retrieved 1,81 GB.

[root@centos ~]# lvs
LV       VG         Attr   LSize  Origin Snap%  Move Log Copy%  Convert
LogVol00 VolGroup00 -wi-ao 17,81G                             
LogVol01 VolGroup00 -wi-ao  1,00G

So as to realize the task, it is not necessary to put the machine into rescue mode and it can be performed on hot.

No comments:

Post a Comment