LVM (Logical Volume Manager) implementación de un administrador de volúmenes lógicos para el kernel Linux. [ESP-ENG]

in blurtech •  2 years ago 

317.-Lvm.svg.png

Quien no ha tenido ese pequeño problema de quedarse sin espacio en disco. LVM nos va a permitir unir varios discos o particiones en un volumen lógico en caliente.

LVM es una implementación de un administrador de volúmenes lógicos para el kernel Linux. Se escribió originalmente en 1998 por Heinz Mauelshagen, que se basó en el administrador de volúmenes de Veritas usado en sistemas HP-UX.

LVM incluye muchas de las características que se esperan de un administrador de volúmenes, incluyendo:

• Redimensionado de grupos lógicos
• Redimensionado de volúmenes lógicos
• Instantáneas de sólo lectura (LVM2 ofrece lectura y escritura)
• RAID0 de volúmenes lógicos.
• En la imagen siguiente podemos observar cómo trabaja LVM. Los volúmenes lógicos agrupan particiones físicas de disco, y éstos a su vez, aunque no está representado en la figura, se engloban en un grupo lógico. De esta forma, /home se compone de hda3, hda4 y hdb3, y a su vez, /usr engloba a hda1, hda2, hdb1 y hdb2.
• LVM-esquema_basico
• Veamos la estructura de LVM:
• Volúmenes físicos (pv).
• Un volumen físico es un disco o una parte del disco que habilitaremos para su inclusión en un grupo de volúmenes.
• Los volúmenes físicos, pueden estar ubicados en una partición (si por ejemplo han de coexistir con sistemas tradicionales), o bien extenderse por toda una unidad de disco o incluso, sobre dispositivos md.

Grupos de volumen (vg).

Los grupos de volumen se definen agrupando uno o más volúmenes físicos y son por así decirlo como discos virtuales, que toman su capacidad de entre los volúmenes físicos asignados al grupo de volumen.

Volúmenes lógicos (lv).

Los volúmenes lógicos se crean dentro de un grupo de volumen y son el equivalente a las particiones en otros sistemas, es la parte de LVM que formateamos con un sistema de ficheros y que luego anexamos a nuestro sistema para poder utilizarlos como almacén de información.

Comandos

Los comandos relacionados con LVM utilizan una nomenclatura parecida entre sí, con la particularidad del comienzo de la orden que varía según sea:

  • pv(change,display,remove,create,move,resize,scan) para volúmenes físicos
  • vg(convert,extend,reduce,scan,create,import,remove,split,change,display,merge,rename,export) para grupos de volumen
  • lv(change,display,convert,extend,remove,rename,scan,create,reduce,resize) para volúmenes lógicos
    lvm estructura
    Supongamos un PC con espacio en disco que no estaba utilizando. Vamos a empezar con una excelente herramienta como es fdisk que desde la consola nos va a permitir trabajar con los discos.

En nuestro caso generar una partición con el espacio libre de que disponemos en el disco y convertirla en LVM.
nechuz@taringa:~$ fdisk -l
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 522 4088542+ 8e Linux LVM

El proceso seria el mismo si pinchamos un nuevo disco y extendemos nuestro volumen con el tamaño que nos interese del nuevo disco.
nechuz@taringa:~$ fdisk /dev/sda
The number of cylinders for this disk is set to 2610.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:

  1. software that runs at boot time (e.g., old versions of LILO)
  2. booting and partitioning software from other OSs
    e.g., DOS FDISK, OS/2 FDISK)
    Command (m for help): n
    Command action
    e extended
    p primary partition (1-4)
    p (primaria)
    3 (numero particion)
    w (grabamos los cambios)

Ahora debemos indicar que la partición se trata de una LVM (8e)
nechuz@taringa:~$ fdisk /dev/sda
The number of cylinders for this disk is set to 2610.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:

  1. software that runs at boot time (e.g., old versions of LILO)
  2. booting and partitioning software from other OSs
    (e.g., DOS FDISK, OS/2 FDISK)
    Command (m for help): t
    Partition number (1-4): 3
    Hex code (type L to list codes): 8e
    Command (m for help): w
    The partition table has been altered!
    Calling ioctl() to re-read partition table.
    WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
    The kernel still uses the old table.
    The new table will be used at the next reboot.
    Syncing disks.

Vemos como queda ahora todo esto :
nechuz@taringa:~$ fdisk -l
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 522 4088542+ 8e Linux LVM
/dev/sda3 523 2610 16771860 8e Linux LVM

Ahora generamos el volumen físico
nechuz@taringa:~$ pvcreate /dev/sda3
Physical volume “/dev/sda3″ successfully created

Vemos los volúmenes físicos que tenemos ahora generados.
nechuz@taringa:~$ pvdisplay
— Physical volume —
PV Name /dev/sda2
VG Name VolGroup00
PV Size 3.88 GB / not usable 0
Allocatable yes
PE Size (KByte) 32768
Total PE 124
Free PE 1
Allocated PE 123
PV UUID CZwxhG-ebU2-3lts-XC7m-2zpC-JMEL-kUcuwb
— NEW Physical volume —
PV Name /dev/sda3
VG Name
PV Size 15.99 GB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID aGTr8T-SsSw-OLcT-l4Z8-JUcz-Kb9v-zJs9Vx

Vemos que hemos generado un volumen físico nuevo pero aun no lo hemos asignado al volumen lógico que ya tenemos generado. Vamos a ver los datos del volumen que tenemos generado.
nechuz@taringa:~$ 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 3.88 GB
PE Size 32.00 MB
Total PE 124
Alloc PE / Size 123 / 3.84 GB
Free PE / Size 1 / 32.00 MB
VG UUID kRm22l-4SYZ-5nWf-ulXT-j8wg-aEvs-yDLNF0

Ahora vamos a extender nuestro volumen con la nueva partición que hemos generado.
nechuz@taringa:~$ vgextend VolGroup00 /dev/sda3
Volume group “VolGroup00″ successfully extended

Si volvemos a ver los datos de nuestro volumen físico.
nechuz@taringa:~$ vgdisplay
— Volume group —
VG Name VolGroup00
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
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 19.84 GB
PE Size 32.00 MB
Total PE 635
Alloc PE / Size 123 / 3.84 GB
Free PE / Size 512 / 16.00 GB
VG UUID kRm22l-4SYZ-5nWf-ulXT-j8wg-aEvs-yDLNF0

Vemos que ahora nos ha ampliado el disco con el espacio de nuestra nueva partición.
Ahora le tenemos que decir que nos añada todo el espacio (o el que nos interese) a nuestro volumen.

nechuz@taringa:~$ lvextend -L19840M /dev/VolGroup00/LogVol00
Extending logical volume LogVol00 to 19.38 GB
Logical volume LogVol00 successfully resized

Y ahora solo nos queda redimensionar el volumen actual para que nos lo muestre el sistema
nechuz@taringa:~$ ext2online /dev/VolGroup00/LogVol00
Y vemos que la cosa ha funcionado:
nechuz@taringa:~$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
19G 3.4G 15G 19% /
/dev/sda1 99M 15M 80M 16% /boot
tmpfs 1014M 0 1014M 0% /dev/shm

Veamos como queda nuestros fichero /etc/fstab
/dev/VolGroup00/LogVol00 / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2

separador-tux-tux.png

Who hasn't had that little problem of running out of disk space? LVM will allow you to merge multiple disks or partitions into a hot logical volume.

LVM is an implementation of a logical volume manager for the Linux kernel. It was originally written in 1998 by Heinz Mauelshagen, who based it on the Veritas volume manager used on HP-UX systems.

LVM includes many of the features expected of a volume manager, including:

  • Logical group resizing
    • Logical volume resizing
    • Read-only snapshots (LVM2 offers read and write)
    • RAID0 of logical volumes.
  • The following image shows how LVM works. Logical volumes group physical disk partitions, and these in turn, although not represented in the figure, are grouped into a logical group. Thus, /home is made up of hda3, hda4 and hdb3, and /usr is made up of hda1, hda2, hdb1 and hdb2.
  • LVM-basic_schema
    • Let's look at the LVM structure:
    • Physical volumes (pv).
    • A physical volume is a disk or a part of a disk that we will enable for inclusion in a volume group.
    • Physical volumes can be located on a partition (if for example they are to coexist with legacy systems), or spread over an entire disk drive or even over md devices.

Volume groups (vg).

Volume groups are defined by grouping one or more physical volumes and are so to speak like virtual disks, which take their capacity from among the physical volumes assigned to the volume group.

Logical volumes (lv).

Logical volumes are created within a volume group and are the equivalent of partitions on other systems, it is the part of LVM that we format with a file system and then attach to our system so that we can use it as an information store.

Commands

LVM-related commands use similar nomenclature to each other, with the start of the command varying from command to command:

  • pv(change,display,remove,create,move,resize,scan) for physical volumes.

-vg(convert,extend,reduce,scan,create,import,remove,split,change,display,merge,rename,export) for volume groups
-lv(change,display,convert,extend,remove,rename,scan,create,reduce,resize) for logical volumes
lvm structure
Let's assume a PC with unused disk space. Let's start with an excellent tool such as fdisk that will allow us to work with the disks from the console.

In our case, generate a partition with the free space we have on the disk and convert it to LVM.
nechuz@taringa:~$ fdisk -l
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 522 4088542+ 8e Linux LVM

The process would be the same if we tap a new disk and extend our volume with the size of the new disk we are interested in.
nechuz@taringa:~$ fdisk /dev/sda
The number of cylinders for this disk is set to 2610.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:

  1. software that runs at boot time (e.g., old versions of LILO)
  2. booting and partitioning software from other OSs
    e.g., DOS FDISK, OS/2 FDISK)
    Command (m for help): n
    Command action
    e extended
    p primary partition (1-4)
    p (primary)
    3 (partition number)
    w (save changes)

Now we must indicate that the partition is an LVM partition (8e)
nechuz@taringa:~$ fdisk /dev/sda
The number of cylinders for this disk is set to 2610.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:

  1. software that runs at boot time (e.g., old versions of LILO)
  2. booting and partitioning software from other OSs
    (e.g., DOS FDISK, OS/2 FDISK)
    Command (m for help): t
    Partition number (1-4): 3
    Hex code (type L to list codes): 8e
    Command (m for help): w
    The partition table has been altered!
    Calling ioctl() to re-read partition table.
    WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
    The kernel still uses the old table.
    The new table will be used at the next reboot.
    Syncing disks.

Let's see what it looks like now:
nechuz@taringa:~$ fdisk -l
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 522 4088542+ 8e Linux LVM
/dev/sda3 523 2610 16771860 8e Linux LVM

Now we generate the physical volume
nechuz@taringa:~$ pvcreate /dev/sda3

  • Physical volume "/dev/sda3″ successfully created

We see the physical volumes we have now generated.
nechuz@taringa:~$ pvdisplay

  • Physical volume -
    PV Name /dev/sda2
    VG Name VolGroup00
    PV Size 3.88 GB / not usable 0
    Allocatable yes
    PE Size (KByte) 32768
    Total PE 124
    Free PE 1
    Allocated PE 123
    PV UUID CZwxhG-ebU2-3lts-XC7m-2zpC-JMEL-kUcuwb
  • NEW Physical volume -
    PV Name /dev/sda3
    VG Name
    PV Size 15.99 GB
    Allocatable NO
    PE Size (KByte) 0
    Total PE 0
    Free PE 0
    Allocated PE 0
    PV UUID aGTr8T-SsSw-OLcT-l4Z8-JUcz-Kb9v-zJs9Vx

We can see that we have generated a new physical volume but we have not yet assigned it to the logical volume that we have already generated. Let's see the data of the volume we have generated.
nechuz@taringa:~$ 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 3.88 GB
    PE Size 32.00 MB
    Total PE 124
    Alloc PE / Size 123 / 3.84 GB
    Free PE / Size 1 / 32.00 MB
    VG UUID kRm22l-4SYZ-5nWf-ulXT-j8wg-aEvs-yDLNF0

Now let's extend our volume with the new partition we have generated.
nechuz@taringa:~$ vgextend VolGroup00 /dev/sda3
Volume group "VolGroup00″ successfully extended

If we go back to see the data of our physical volume.
nechuz@taringa:~$ vgdisplay

  • Volume group -
    VG Name VolGroup00
    System ID
    Format lvm2
    Metadata Areas 2
    Metadata Sequence No 4
    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 19.84 GB
    PE Size 32.00 MB
    Total PE 635
    Alloc PE / Size 123 / 3.84 GB
    Free PE / Size 512 / 16.00 GB
    VG UUID kRm22l-4SYZ-5nWf-ulXT-j8wg-aEvs-yDLNF0

We can see that it has now expanded the disk with the space of our new partition.
Now we have to tell it to add all the space (or as much as we want) to our volume.

nechuz@taringa:~$ lvextend -L19840M /dev/VolGroup00/LogVol00
Extending logical volume LogVol00 to 19.38 GB
Logical volume LogVol00 successfully resized

And now we only have to resize the current volume so that the system shows it to us
nechuz@taringa:~$ ext2online /dev/VolGroup00/LogVol00
And we can see that it has worked:
nechuz@taringa:~$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
19G 3.4G 15G 19% /
/dev/sda1 99M 15M 80M 16% /boot
tmpfs 1014M 0 1014M 0% /dev/shm

Let's see how our /etc/fstab file looks like
/dev/VolGroup00/LogVol00/LogVol00 / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2

Screenshots / Capturas de pantallas:

Wikipedia

Blogs, Sitios Web y Redes Sociales / Blogs, Webs & Social NetworksPlataformas de Contenidos/ Contents Platforms
Mi Blog / My BlogLos Apuntes de Tux
Red Social Twitter / Twitter Social Network@hugorep

separador-firma-rounded-in-photoretrica.png



Posted from https://blurtlatam.intinte.org

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE BLURT!