Pages

Friday, October 21, 2011

LVM - Como agregar un disco nuevo a un grupo de volumenes nuevo (VG)

Tanto tiempo sin postear nada.. Aqui un pequeo ejemplo de como utilizar lvm,  vamos a agregar un disco nuevo presentado en un servidor HP Proliant, en un grupo de volumenes.

Revisar que el disco este presente, por lo general no existe una tabla de particion:
-------------------------------------------------------------------------------------------------------------
[root@koopa ~]# fdisk -l

Disk /dev/cciss/c0d1: 72.8 GB, 72833679360 bytes
255 heads, 32 sectors/track, 17433 cylinders
Units = cylinders of 8160 * 512 = 4177920 bytes

           Device Boot      Start         End      Blocks   Id  System


-------------------------------------------------------------------------------------------------------------

Creamos una particion primaria utilizando el comando fdisk
-------------------------------------------------------------------------------------------------------------
[root@koopa ~]# fdisk /dev/cciss/c0d1

-------------------------------------------------------------------------------------------------------------

**Se seleccionan en este ejemplo las siguientes opciones para crear una particion primaria

- n - nueva particion
- p - primaria
- se seleccionan los valores por default para utilizar todo el espacio del disco duro
- p - para imprimir las particiones
- w - para escribir los cambios y salir

-------------------------------------------------------------------------------------------------------------
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)

p
Partition number (1-4): 1
First cylinder (1-17433, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-17433, default 17433):
Using default value 17433

Command (m for help): fdisk -l
f: unknown command
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

Command (m for help): p

Disk /dev/cciss/c0d1: 72.8 GB, 72833679360 bytes
255 heads, 32 sectors/track, 17433 cylinders
Units = cylinders of 8160 * 512 = 4177920 bytes

           Device Boot      Start         End      Blocks   Id  System
/dev/cciss/c0d1p1               1       17433    71126624   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

-------------------------------------------------------------------------------------------------------------

Se crea el volumen fisico utilizando pvcreate
-------------------------------------------------------------------------------------------------------------
[root@koopa ~]# pvcreate /dev/cciss/c0d1
  Physical volume "/dev/cciss/c0d1" successfully created


-------------------------------------------------------------------------------------------------------------

Se lista el volumen fisico con pvdisplay
-------------------------------------------------------------------------------------------------------------
[root@koopa ~]# pvdisplay
 
  "/dev/cciss/c0d1" is a new physical volume of "67.83 GB"
  --- NEW Physical volume ---
  PV Name               /dev/cciss/c0d1
  VG Name             
  PV Size               67.83 GB
  Allocatable           NO
  PE Size (KByte)       0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               0XUc4w-5YAY-0QdP-4eKr-fUtX-LtCY-pqNYdy

-------------------------------------------------------------------------------------------------------------

Se crea el grupo de volumenes utilizando vgcreate
-------------------------------------------------------------------------------------------------------------  
[root@koopa ~]# vgcreate VG_Share /dev/cciss/c0d1
  Volume group "VG_Share" successfully created

-------------------------------------------------------------------------------------------------------------

Se lista el grupo de volumenes creado con vgdisplay
-------------------------------------------------------------------------------------------------------------
[root@koopa ~]# vgdisplay
  --- Volume group ---
  VG Name               VG_Share
  System ID           
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               67.83 GB
  PE Size               4.00 MB
  Total PE              17364
  Alloc PE / Size       0 / 0 
  Free  PE / Size       17364 / 67.83 GB
  VG UUID               SacoKh-16Yb-i3lr-JxT0-7SAK-zRTs-WxR0TR

-------------------------------------------------------------------------------------------------------------

Se crea un volumen logico con lvcreate
-------------------------------------------------------------------------------------------------------------
Nota: para utilizar todo el espacio del disco se puede utilizar le valor de Free PE mostrado anteriormente, esto equivale a:

PE Size * Free PE = Espacio del disco
 4 * 17364 = 67.83GB

[root@koopa ~]# lvcreate -l 17364 -n LV_Share VG_Share
  Logical volume "LV_Share" created

-------------------------------------------------------------------------------------------------------------

Se lista el volumen logico con lvdisplay
-------------------------------------------------------------------------------------------------------------
[root@koopa ~]# lvdisplay
  --- Logical volume ---
  LV Name                /dev/VG_Share/LV_Share
  VG Name                VG_Share
  LV UUID                NNzm0p-doEJ-CUix-dHWR-2Z0s-PI7z-gOO1sx
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                67.83 GB
  Current LE             17364
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2

-------------------------------------------------------------------------------------------------------------

Se formatea el volument logico, en este caso a ext3 utilizando mke2fs
 -------------------------------------------------------------------------------------------------------------
[root@koopa ~]# mke2fs -j /dev/VG_Share/LV_Share
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
8896512 inodes, 17780736 blocks
889036 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
543 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
    4096000, 7962624, 11239424

Writing inode tables: done                          
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 20 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

-------------------------------------------------------------------------------------------------------------

Luego el disco ya esta listo para ser montado al sistema.

Se crea un punto de montaje
-------------------------------------------------------------------------------------------------------------
[root@koopa ~]# mkdir /mnt/kshare
-------------------------------------------------------------------------------------------------------------

Se monta el volumen logico
-------------------------------------------------------------------------------------------------------------
[root@koopa ~]# mount /dev/VG_Share/LV_Share /mnt/kshare
-------------------------------------------------------------------------------------------------------------

Si se quiere mantener este disco montado despues de cada reinicio, se agrega la siguiente linea a /etc/fstab
-------------------------------------------------------------------------------------------------------------
/dev/VG_Share/LV_Share   /mnt/kshare              ext3   defaults       0 0
-------------------------------------------------------------------------------------------------------------

Listo!!! Que disfruten!

WilC