Introduction
What is LVM? LVM is the acronym for Logical Volume Manager, a powerful tool present in current Linux systems, inspired by the implementation available in other systems such as AIX and HP-UX.
LVM It introduces a separation between the typical structure of a system and the elements of disks, partitions, and file systems that we are used to.
LVM It works at three levels, namely:
- Physical volumes
- Volume Groups
- Logical volumes
One of the main advantages of the system LVM about the traditional system, is that LVM It abstracts us from physical disks and the limitations of a disk, allowing us to have file systems on several disks, resizing them according to needs and therefore, making more efficient use of the space we have, regardless of their location.
Facility
Debian and derivatives:
rokitoh@redorbita:~# aptitude install lvm2RedHat and derivatives:
rokitoh@redorbita:~# yum install lvm2We check that it has recognized the added disk:
rokitoh@redorbita:~# fdisk -l
Disco /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders, 4194304 sectores en total
Units = sectores of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Identificador del disco: 0x00000000
El disco /dev/sdb no contiene una tabla de particiones válidaWe format the disk
rokitoh@redorbita:~# fdisk /dev/sdbOnce inside, we press “n” to create a new partition:
- n: Add a new partition
We press “p” to create a new primary partition
- Partición primaria (1-4)
Presionamos «1» to create it as the first partition of the disk, then press
ENTER until accepting all the default values for first and last cylinder.
Once finished and back in the fdisk menu, we press “t” to change the system identifier of the partition.
- t: Change the system identifier of a partition
We will change it to the type “LVM partition type (0×8e)", for this we introduce 8e. We can in this
point press “p” to print the partition table and see that everything is correct:
Hexadecimal code (type L to see codes): 8e
Partition 1 system type changed to 8e (Linux LVM)
We press P to print the partition table
Orden (m para obtener ayuda): p
Disco /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders, 4194304 sectores en total
Units = sectores of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Identificador del disco: 0x32e68449
Disposit. Inicio Comienzo Fin Bloques Id Sistema
/dev/sdb1 2048 4194303 2096128 8e Linux LVMWe press W to save the changes made.
Orden (m para obtener ayuda): w
¡Se ha modificado la tabla de particiones!Create the physical volumes
The first thing we must do when working with LVM is create physical volumes (PV)
of the partitions with which we want to create logical volumes. We do this with the
pvcreate command. This must be done on all the partitions that we want to use with LVM.
rokitoh@redorbita:~# pvcreate /dev/sdb1
Writing physical volume data to disk «/dev/sdb1»
Physical volume «/dev/sdb1» successfully createdCreate the volume group (VG – vgcreate)
Now that we have configured the partitions that we want to use as LVM, we can add the first volume group, which will already contain our final logical volumes. We will do this with the vgcreate command. In our case we only have one partition, but if we wanted to add several to the group we would do it like this:
rokitoh@redorbita:~# vgcreate vg_backup /dev/sdb1
Volume group «vg_backup» successfully createdCreate logical volumes (LV – lvcreate)
At this point, we only need to create the logical volume, to which we will add
the desired file system.
rokitoh@redorbita:~# lvcreate -L 1G -n lv_backup vg_backup
Logical volume «lv_backup» createdAll that remains is to format it and assemble it as a
rokitoh@redorbita:~# mkfs.ext4 /dev/mapper/vg_backup-lv_backupWe add the following line to the file /etc/fstab
/dev/mapper/vg_backup-lv_backup /backup ext4 defaults 0 0We mount the disk:
root@subversion:~# mount -a
root@subversion:~# df -h
/dev/mapper/vg_backup-lv_backup 1008M 34M 924M 4% /backupRegards, Rokitoh
:wq!
Comments