LVM
From AleikoumWiki
en tant que root ou via sudo
Voici la liste des partitions montees :
~# df -a Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda5 1921156 113472 1710092 7% / tmpfs 1682860 0 1682860 0% /lib/init/rw proc 0 0 0 - /proc sysfs 0 0 0 - /sys procbususb 0 0 0 - /proc/bus/usb udev 10240 112 10128 2% /dev tmpfs 1682860 0 1682860 0% /dev/shm devpts 0 0 0 - /dev/pts /dev/sda1 62193 14205 44777 25% /boot /dev/sda11 415286820 203084 393988388 1% /data /dev/sdb1 480719056 202796 456097060 1% /data2 /dev/sda8 9614116 152724 8973020 2% /home /dev/sda7 9614116 152692 8973052 2% /tmp /dev/sda6 9614116 411856 8713888 5% /usr /dev/sda10 9614116 152728 8973016 2% /usr/local /dev/sda9 9614116 316944 8808800 4% /var
On souhaite utiliser /dev/sdb1 pour nos tests lvm dans un premier temps il faut demonter la partition :
~# umount /data2/
puis la rendre eligible a lvm
~# pvcreate /dev/sdb1 Physical volume "/dev/sdb1" successfully created
ici une seule partition est concernee mais il faudrait demonter et rendre eligible chaque partition qu'on souhaite utiliser pour lvm
ensuite il faut creer un un groupe de volume avec les partitions rendues eligibles
~# vgcreate vg0 /dev/sdb1 Volume group "vg0" successfully created
si par exemple on avait rendu eligible en plus /dev/sda11 alors la creation du groupe de volume deviendrait :
~# vgcreate vg0 /dev/sdb1 /dev/sda11 Volume group "vg0" successfully created
pour controler les groupes de volumes disponibles :
~# vgdisplay --- Volume group --- VG Name vg0 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 465.76 GB PE Size 4.00 MB Total PE 119234 Alloc PE / Size 0 / 0 Free PE / Size 119234 / 465.76 GB VG UUID G5dRnp-GN95-kr09-6PS2-x410-ZnW1-IMeuP4
on peut maintenant creer des espaces (logical volume) a partir de ce groupe de volumes, je vais creer 3 partitions : 2 de 4Go et une de 256Mo
~# lvcreate -n p11 -L 4g vg0 Logical volume "p11" created ~# lvcreate -n p12s -L 256m vg0 Logical volume "p12s" created ~# lvcreate -n p13 -L 4g vg0 Logical volume "p13" created
on peut verifier avec la commande vgdisplay que les espaces crees sont bien alloues :
~# vgdisplay --- Volume group --- VG Name vg0 System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 4 VG Access read/write VG Status resizable MAX LV 0 Cur LV 3 Open LV 0 Max PV 0 Cur PV 1 Act PV 1 VG Size 465.76 GB PE Size 4.00 MB Total PE 119234 Alloc PE / Size 2112 / 8.25 GB # Ici Free PE / Size 117122 / 457.51 GB # et ici ! VG UUID G5dRnp-GN95-kr09-6PS2-x410-ZnW1-IMeuP4
les logical volumes sont crees et on les retrouve dans /dev/vg0/p11 /dev/vg0/p12s /dev/vg0/p13
on les formate (comme n'importe quelle partition) pour pouvoir les manipuler par la suite :
~# mke2fs -j /dev/vg0/p11 ~# mke2fs -j /dev/vg0/p13 ~# mkswap /dev/vg0/p12s
A ce niveau les logical volumes peuvent etre utilises comme n'importe quelle partition :
exemple :
mount /dev/vg0/p11 /data/test/ ~# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda5 1921156 113500 1710064 7% / tmpfs 1682860 0 1682860 0% /lib/init/rw udev 10240 124 10116 2% /dev tmpfs 1682860 0 1682860 0% /dev/shm /dev/sda1 62193 14205 44777 25% /boot /dev/sda11 415286820 203088 393988384 1% /data /dev/sda8 9614116 152724 8973020 2% /home /dev/sda7 9614116 152692 8973052 2% /tmp /dev/sda6 9614116 411856 8713888 5% /usr /dev/sda10 9614116 152728 8973016 2% /usr/local /dev/sda9 9614116 316948 8808796 4% /var /dev/mapper/vg0-p11 4128448 139388 3779348 4% /data/test
Manipulation pour agrandir les logical volume
Agrandir un logical volume a une taille definie :
ici je vais passer /dev/vg0/p11 de 4Go a 5Go
psrv-qg-dmz-0:~# lvresize -L 5g /dev/vg0/p11 Extending logical volume p11 to 5.00 GB Logical volume p11 successfully resized ~# ~# mount /dev/vg0/p11 /data/test/ ~# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda5 1.9G 111M 1.7G 7% / tmpfs 1.7G 0 1.7G 0% /lib/init/rw udev 10M 124K 9.9M 2% /dev tmpfs 1.7G 0 1.7G 0% /dev/shm /dev/sda1 61M 14M 44M 25% /boot /dev/sda11 397G 199M 376G 1% /data /dev/sda8 9.2G 150M 8.6G 2% /home /dev/sda7 9.2G 150M 8.6G 2% /tmp /dev/sda6 9.2G 403M 8.4G 5% /usr /dev/sda10 9.2G 150M 8.6G 2% /usr/local /dev/sda9 9.2G 310M 8.5G 4% /var /dev/mapper/vg0-p11 4.0G 137M 3.7G 4% /data/test # /!\ Ca ne suffit pas ! ~# umount /data/test/
Comme ce logical volume est formate en ext3 :
~# resize2fs /dev/vg0/p11 resize2fs 1.41.3 (12-Oct-2008) Please run 'e2fsck -f /dev/vg0/p11' first. ~# e2fsck -f /dev/vg0/p11 e2fsck 1.41.3 (12-Oct-2008) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/vg0/p11: 11/262144 files (0.0% non-contiguous), 51311/1048576 blocks ~# resize2fs /dev/vg0/p11 resize2fs 1.41.3 (12-Oct-2008) Resizing the filesystem on /dev/vg0/p11 to 1310720 (4k) blocks. The filesystem on /dev/vg0/p11 is now 1310720 blocks long. ~# mount /dev/vg0/p11 /data/test/ ~# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda5 1.9G 111M 1.7G 7% / tmpfs 1.7G 0 1.7G 0% /lib/init/rw udev 10M 124K 9.9M 2% /dev tmpfs 1.7G 0 1.7G 0% /dev/shm /dev/sda1 61M 14M 44M 25% /boot /dev/sda11 397G 199M 376G 1% /data /dev/sda8 9.2G 150M 8.6G 2% /home /dev/sda7 9.2G 150M 8.6G 2% /tmp /dev/sda6 9.2G 403M 8.4G 5% /usr /dev/sda10 9.2G 150M 8.6G 2% /usr/local /dev/sda9 9.2G 310M 8.5G 4% /var /dev/mapper/vg0-p11 5.0G 137M 4.6G 3% /data/test # Et voila !
A noter qu'on peut aussi faire ces manipulations a chaud (cad sans demonter le volume) comme suit :
~# lvresize -L 6g /dev/vg0/p11 Extending logical volume p11 to 6.00 GB Logical volume p11 successfully resized ~# resize2fs /dev/vg0/p11 resize2fs 1.41.3 (12-Oct-2008) Filesystem at /dev/vg0/p11 is mounted on /data/test; on-line resizing required old desc_blocks = 1, new_desc_blocks = 1 Performing an on-line resize of /dev/vg0/p11 to 1572864 (4k) blocks. The filesystem on /dev/vg0/p11 is now 1572864 blocks long. ~# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda5 1921156 113508 1710056 7% / tmpfs 1682860 0 1682860 0% /lib/init/rw udev 10240 124 10116 2% /dev tmpfs 1682860 0 1682860 0% /dev/shm /dev/sda1 62193 14205 44777 25% /boot /dev/sda11 415286820 203088 393988384 1% /data /dev/sda8 9614116 152724 8973020 2% /home /dev/sda7 9614116 152692 8973052 2% /tmp /dev/sda6 9614116 411856 8713888 5% /usr /dev/sda10 9614116 152728 8973016 2% /usr/local /dev/sda9 9614116 316948 8808796 4% /var /dev/mapper/vg0-p11 6192704 139388 5738760 3% /data/test # On est passe de 5Go a 6 !
Agrandir un logical volume de X en plus
~# lvresize -L +2g /dev/vg0/p11 Extending logical volume p11 to 8.00 GB Logical volume p11 successfully resized ~# resize2fs /dev/vg0/p11 resize2fs 1.41.3 (12-Oct-2008) Filesystem at /dev/vg0/p11 is mounted on /data/test; on-line resizing required old desc_blocks = 1, new_desc_blocks = 1 Performing an on-line resize of /dev/vg0/p11 to 2097152 (4k) blocks. The filesystem on /dev/vg0/p11 is now 2097152 blocks long. ~# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda5 1.9G 111M 1.7G 7% / tmpfs 1.7G 0 1.7G 0% /lib/init/rw udev 10M 124K 9.9M 2% /dev tmpfs 1.7G 0 1.7G 0% /dev/shm /dev/sda1 61M 14M 44M 25% /boot /dev/sda11 397G 199M 376G 1% /data /dev/sda8 9.2G 150M 8.6G 2% /home /dev/sda7 9.2G 150M 8.6G 2% /tmp /dev/sda6 9.2G 403M 8.4G 5% /usr /dev/sda10 9.2G 150M 8.6G 2% /usr/local /dev/sda9 9.2G 310M 8.5G 4% /var /dev/mapper/vg0-p11 7.9G 138M 7.4G 2% /data/test
Retrecire un logical volume
attention ! il faut d'abord reduire le file system avant de reduire la taille du logical volume !
sinon il y a de tres forts risques de conrrompre le file system de plus pour ce type d'operation il faut absolument demonter le logical volume
si on souhaite reduire la taille du logical volume de 1Go :
d'abord on reduit d'un peu plus d'1Go le file system
a noter que la commande resize2fs ne permet pas de preciser une reduction de X, on est oblige de specifier la taille finale
-p : permet de voir l'evolution de la commande
~# mount /dev/vg0/p11 /data/test/ ~# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda5 1.9G 111M 1.7G 7% / tmpfs 1.7G 0 1.7G 0% /lib/init/rw udev 10M 124K 9.9M 2% /dev tmpfs 1.7G 0 1.7G 0% /dev/shm /dev/sda1 61M 14M 44M 25% /boot /dev/sda11 397G 199M 376G 1% /data /dev/sda8 9.2G 150M 8.6G 2% /home /dev/sda7 9.2G 150M 8.6G 2% /tmp /dev/sda6 9.2G 403M 8.4G 5% /usr /dev/sda10 9.2G 150M 8.6G 2% /usr/local /dev/sda9 9.2G 310M 8.5G 4% /var /dev/mapper/vg0-p11 6.9G 138M 6.5G 3% /data/test # Il a bien ete reduit !
Renommer un logical volume :
peut se faire a chaud
~# lvrename vg0 p11 p00