Dans notre cas un Linux CENTOS 7 a été installé sur un disque de 8Go déjà existant.
A l’issue 2 disques de 1 Go ont été ajoutés
I Disques / partition
Lister les disques physiques vu par le système :
- ls -als /dev/[hs]d[a-z] –> (Xen, RAIS et LVM non pris en compte)
0 brw-rw----. 1 root disk 8, 0 27 juil. 15:11 /dev/sda 0 brw-rw----. 1 root disk 8, 16 27 juil. 15:11 /dev/sdb 0 brw-rw----. 1 root disk 8, 32 27 juil. 15:11 /dev/sdc
hd* –> disque IDE
sd* –> disque SATA, SCSI, USB
scd* ou sr* –> lecteur CDROM SATA,SCSI,…
- lsblk | grep disk
sda 8:0 0 8G 0 disk sdb 8:16 0 1010,9M 0 disk sdc 8:32 0 1,1G 0 disk
- lsblk –> Liste des disques et partitions associées
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 8G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 7G 0 part ├─centos-root 253:0 0 6,2G 0 lvm / └─centos-swap 253:1 0 820M 0 lvm [SWAP] sdb 8:16 0 1010,9M 0 disk sdc 8:32 0 1,1G 0 disk sr0 11:0 1 1024M 0 rom
- lsblk -f –> Liste des disques et partitions associées + type de filesystem
NAME FSTYPE LABEL UUID MOUNTPOINT sda ├─sda1 xfs dc103496-c8f0-427c-8d24-182472f24d3f /boot └─sda2 LVM2_member i63M7M-z29v-ccrO-58fh-UVbx-OZYq-yLBhNf ├─centos-root xfs 66b2362b-959c-4eb7-b2e5-a917172f56a7 / └─centos-swap swap 1eefbfad-a121-48ae-ac30-3b042cd56b91 [SWAP] sdb sdc sr0
- fdisk -l –> liste des disques physiques et partitions associées
Disque /dev/sda : 8589 Mo, 8589934592 octets, 16777216 secteurs Unités = secteur de 1 × 512 = 512 octets Taille de secteur (logique / physique) : 512 octets / 512 octets taille d'E/S (minimale / optimale) : 512 octets / 512 octets Type d'étiquette de disque : dos Identifiant de disque : 0x000c9656 Périphérique Amorçage Début Fin Blocs Id. Système /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 16777215 7339008 8e Linux LVM Disque /dev/sdb : 1060 Mo, 1060025856 octets, 2070363 secteurs Unités = secteur de 1 × 512 = 512 octets Taille de secteur (logique / physique) : 512 octets / 512 octets taille d'E/S (minimale / optimale) : 512 octets / 512 octets Disque /dev/sdc : 1157 Mo, 1157994496 octets, 2261708 secteurs Unités = secteur de 1 × 512 = 512 octets Taille de secteur (logique / physique) : 512 octets / 512 octets taille d'E/S (minimale / optimale) : 512 octets / 512 octets Disque /dev/mapper/centos-root : 6652 Mo, 6652166144 octets, 12992512 secteurs Unités = secteur de 1 × 512 = 512 octets Taille de secteur (logique / physique) : 512 octets / 512 octets taille d'E/S (minimale / optimale) : 512 octets / 512 octets Disque /dev/mapper/centos-swap : 859 Mo, 859832320 octets, 1679360 secteurs Unités = secteur de 1 × 512 = 512 octets Taille de secteur (logique / physique) : 512 octets / 512 octets taille d'E/S (minimale / optimale) : 512 octets / 512 octets
II Visualisation des filesystem
- df -h
Sys. de fichiers Taille Utilisé Dispo Uti% Monté sur /dev/mapper/centos-root 6,2G 1,1G 5,1G 18% / devtmpfs 485M 0 485M 0% /dev tmpfs 496M 0 496M 0% /dev/shm tmpfs 496M 6,8M 490M 2% /run tmpfs 496M 0 496M 0% /sys/fs/cgroup /dev/sda1 1014M 129M 886M 13% /boot tmpfs 100M 0 100M 0% /run/user/0
- mount / mount -l
- fdisk -l (partition + disque physique)
III LVM
III.1 Présentation
Logical Volume Manager ou gestionnaire de volumes logiques en français.
- Remplace le traditionnel partionnement logique des disques.
- Opération de redimensionnement moins risqué que sur une partition logique
- Inconvénient : si disque physique HS l’ensemble du volume logique est HS (utiliser des disques en RAID)
III.2 Vocabulaire:
- Volume physique ou PV (Physical Volume)
- C’est un disque ou une partition. Il sera confié à LVM
- Groupe de volumes ou VG (Volume Group)
- C’est un ensemble de volumes physiques
- Volume logique ou LV (Logical Volume)
- C’est un espace défini dans un groupe de volume (VG). Ce dernier aura un système de fichiers
- Déconseillé pour le moment d’y mettre /boot
III.3 Listes des principales commandes
Liste des princiaples commandes LVM pour manipuler les Volumes Physiques (PV) : man -k ^pv
pvchange (8) - Change attributes of physical volume(s) pvck (8) - Check the consistency of physical volume(s) pvcreate (8) - Initialize physical volume(s) for use by LVM pvdisplay (8) - Display various attributes of physical volume(s) pvmove (8) - Move extents from one physical volume to another pvremove (8) - Remove LVM label(s) from physical volume(s) pvresize (8) - Resize physical volume(s) pvs (8) - Display information about physical volumes pvscan (8) - List all physical volumes
Liste des princiaples commandes LVM pour manipuler les Groupes de Volumes (VG) : man -k ^vg
vgcfgbackup (8) - Backup volume group configuration(s) vgcfgrestore (8) - Restore volume group configuration vgchange (8) - Change volume group attributes vgck (8) - Check the consistency of volume group(s) vgconvert (8) - Change volume group metadata format vgcreate (8) - Create a volume group vgdisplay (8) - Display volume group information vgexport (8) - Unregister volume group(s) from the system vgextend (8) - Add physical volumes to a volume group vgimport (8) - Register exported volume group with system vgimportclone (8) - Import a VG from cloned PVs vgmerge (8) - Merge volume groups vgmknodes (8) - Create the special files for volume group devices in /dev vgreduce (8) - Remove physical volume(s) from a volume group vgremove (8) - Remove volume group(s) vgrename (8) - Rename a volume group vgs (8) - Display information about volume groups vgscan (8) - Search for all volume groups vgsplit (8) - Move physical volumes into a new or existing volume group
Liste des princiaples commandes LVM pour manipuler les Volumes Logiques (LV) : man -k ^lg
lvchange (8) - Change the attributes of logical volume(s) lvconvert (8) - Change logical volume layout lvcreate (8) - Create a logical volume lvdisplay (8) - Display information about a logical volume lvextend (8) - Add space to a logical volume lvm (8) - LVM2 tools lvm-config (8) - Display and manipulate configuration information lvm-dumpconfig (8) - Display and manipulate configuration information lvm-fullreport (8) - (sujet inconnu) lvm-lvpoll (8) - (sujet inconnu) lvm.conf (5) - Configuration file for LVM2 lvm2-activation-generator (8) - generator for systemd units to activate LVM2 volumes on boot lvmcache (7) - LVM caching lvmconf (8) - LVM configuration modifier lvmconfig (8) - Display and manipulate configuration information lvmdiskscan (8) - List devices that may be used as physical volumes lvmdump (8) - create lvm2 information dumps for diagnostic purposes lvmetad (8) - LVM metadata cache daemon lvmpolld (8) - LVM poll daemon lvmraid (7) - LVM RAID lvmreport (7) - LVM reporting and related features lvmsadc (8) - LVM system activity data collector lvmsar (8) - LVM system activity reporter lvmsystemid (7) - LVM system ID lvmthin (7) - LVM thin provisioning lvreduce (8) - Reduce the size of a logical volume lvremove (8) - Remove logical volume(s) from the system lvrename (8) - Rename a logical volume lvresize (8) - Resize a logical volume lvs (8) - Display information about logical volumes lvscan (8) - List all logical volumes in all volume groups
III.4 Groupes de Volumes (VG)
III.4.1 Afficher la liste des groupes de volumes :
- vgdisplay -s
"centos" <7,00 GiB [<7,00 GiB used / 0 free]
III.4.2 Création d’un groupe de volume sur le disque sdc
vgcreate mon_vol_grp /dev/sdc
Volume group "mon_vol_grp" successfully created
ce qui donne après un vgdisplay :
"mon_vol_grp" 1,07 GiB [0 used / 1,07 GiB free] "centos" <7,00 GiB [<7,00 GiB used / 0 free]
III.4.3 Suppression d’un groupe de volumes
vgremove mon_vol_grp
Volume group "mon_vol_grp" successfully removed
Résultat après un vg display :
"centos" <7,00 GiB [<7,00 GiB used / 0 free]
III.5 Volumes Logiques (VL)
III.5.1 Afficher les volumes logiques
- lvdisplay
--- Logical volume --- LV Path /dev/centos/swap LV Name swap VG Name centos LV UUID EWn4T0-2cLo-SWFu-skUZ-YiJ0-6bww-WywdiB LV Write Access read/write LV Creation host, time localhost, 2018-07-27 11:40:49 +0200 LV Status available # open 2 LV Size 820,00 MiB Current LE 205 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:1 --- Logical volume --- LV Path /dev/centos/root LV Name root VG Name centos LV UUID J9QkbE-3a1e-AQ4k-lupo-aFZB-3m3g-n3e3kO LV Write Access read/write LV Creation host, time localhost, 2018-07-27 11:40:49 +0200 LV Status available # open 1 LV Size <6,20 GiB Current LE 1586 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:0
III.5.2 Création d’un volume logique
Création d’un volume logique (LG) sur le volume groupe « mon_vol_grp »
- lvcreate -n Vol_log1 -L 100m mon_vol_grp
- lvcreate -n Vol_log2 -L 200m mon_vol_grp
Logical volume "Vol_log1" created. Logical volume "Vol_log2" created.
Résultat après un lvdisplay :
--- Logical volume --- LV Path /dev/mon_vol_grp/Vol_log1 LV Name Vol_log1 VG Name mon_vol_grp LV UUID IrFfsZ-2saw-meMq-KiAe-sK39-mAEw-2adMv2 LV Write Access read/write LV Creation host, time localhost.localdomain, 2018-08-09 17:45:06 +0200 LV Status available # open 0 LV Size 100,00 MiB Current LE 25 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:2 --- Logical volume --- LV Path /dev/mon_vol_grp/Vol_log2 LV Name Vol_log2 VG Name mon_vol_grp LV UUID IZPMp7-9cUV-eAxs-y8N9-cVE7-S7xZ-u60cWf LV Write Access read/write LV Creation host, time localhost.localdomain, 2018-08-09 17:45:20 +0200 LV Status available # open 0 LV Size 200,00 MiB Current LE 50 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:3 --- Logical volume --- LV Path /dev/centos/swap LV Name swap VG Name centos LV UUID EWn4T0-2cLo-SWFu-skUZ-YiJ0-6bww-WywdiB LV Write Access read/write LV Creation host, time localhost, 2018-07-27 11:40:49 +0200 LV Status available # open 2 LV Size 820,00 MiB Current LE 205 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:1 --- Logical volume --- LV Path /dev/centos/root LV Name root VG Name centos LV UUID J9QkbE-3a1e-AQ4k-lupo-aFZB-3m3g-n3e3kO LV Write Access read/write LV Creation host, time localhost, 2018-07-27 11:40:49 +0200 LV Status available # open 1 LV Size <6,20 GiB Current LE 1586 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:0
III.5.3 Formatter un volume logique
Mise en place d’un système de fichiers pour les 2 volumes logiques créés :
- mkfs -t ext4 /dev/mon_vol_grp/Vol_log1
- mkfs -t ext4 /dev/mon_vol_grp/Vol_log2
Sortie pour la création du premier système de fichiers :
mke2fs 1.42.9 (28-Dec-2013) Étiquette de système de fichiers= Type de système d'exploitation : Linux Taille de bloc=1024 (log=0) Taille de fragment=1024 (log=0) « Stride » = 0 blocs, « Stripe width » = 0 blocs 25688 i-noeuds, 102400 blocs 5120 blocs (5.00%) réservés pour le super utilisateur Premier bloc de données=1 Nombre maximum de blocs du système de fichiers=33685504 13 groupes de blocs 8192 blocs par groupe, 8192 fragments par groupe 1976 i-noeuds par groupe Superblocs de secours stockés sur les blocs : 8193, 24577, 40961, 57345, 73729 Allocation des tables de groupe : complété Écriture des tables d'i-noeuds : complété Création du journal (4096 blocs) : complété Écriture des superblocs et de l'information de comptabilité du système de fichiers : complété
III.5.4 Monter un volume logique
- mkdir /LVM_exemple
- mount /dev/mon_vol_grp/Vol_log1 /LVM_exemple/
- lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 8G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 7G 0 part ├─centos-root 253:0 0 6,2G 0 lvm / └─centos-swap 253:1 0 820M 0 lvm [SWAP] sdb 8:16 0 1010,9M 0 disk sdc 8:32 0 1,1G 0 disk ├─mon_vol_grp-Vol_log1 253:2 0 100M 0 lvm /LVM_exemple └─mon_vol_grp-Vol_log2 253:3 0 200M 0 lvm sr0 11:0 1 1024M 0 rom
III.5.5 Supprimer un volume logique
- umount /LVM_exemple/
- lvremove /dev/mon_vol_grp/Vol_log1
Do you really want to remove active logical volume mon_vol_grp/Vol_log1? [y/n]: y Logical volume "Vol_log1" successfully removed
- lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 8G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 7G 0 part ├─centos-root 253:0 0 6,2G 0 lvm / └─centos-swap 253:1 0 820M 0 lvm [SWAP] sdb 8:16 0 1010,9M 0 disk sdc 8:32 0 1,1G 0 disk └─mon_vol_grp-Vol_log2 253:3 0 200M 0 lvm sr0 11:0 1 1024M 0 rom
III.5 Redimmensionner
III.5.1 Augmenter un volume logique
- pvcreate /dev/sdb #création d’un volume physique sur le disque sdb
- vgextend mon_vol_grp /dev/sdb # ajout de ce voulme physique dans le volume groupe « mon_vol_grp »
Physical volume "/dev/sdb" successfully created. Volume group "mon_vol_grp" successfully extended
Après un pvdisplay :
--- Physical volume --- PV Name /dev/sdc VG Name mon_vol_grp PV Size <1,08 GiB / not usable <4,35 MiB Allocatable yes PE Size 4,00 MiB Total PE 275 Free PE 225 Allocated PE 50 PV UUID iySi5C-exUY-dBD0-ml14-2KdL-0SSS-j2vkAu --- Physical volume --- PV Name /dev/sdb VG Name mon_vol_grp PV Size <1010,92 MiB / not usable <2,92 MiB Allocatable yes PE Size 4,00 MiB Total PE 252 Free PE 252 Allocated PE 0 PV UUID Ffe1Wt-R94x-UyVh-kzJN-m2cR-vCc8-JPfHuj --- Physical volume --- PV Name /dev/sda2 VG Name centos PV Size <7,00 GiB / not usable 3,00 MiB Allocatable yes (but full) PE Size 4,00 MiB Total PE 1791 Free PE 0 Allocated PE 1791 PV UUID i63M7M-z29v-ccrO-58fh-UVbx-OZYq-yLBhNf
On voit maintenant que le volume de groupe « mon_vol_grp » repose sur 2 disques physiques.
Autre commande permettant une lecture plus simple : pvscan
PV /dev/sdc VG mon_vol_grp lvm2 [1,07 GiB / 900,00 MiB free] PV /dev/sdb VG mon_vol_grp lvm2 [1008,00 MiB / 1008,00 MiB free] PV /dev/sda2 VG centos lvm2 [<7,00 GiB / 0 free] Total: 3 [9,05 GiB] / in use: 3 [9,05 GiB] / in no VG: 0 [0 ]
Il faut maintenant redimmensionner le volume logique
- lvresize –resizefs –size +1,5G /dev/mon_vol_grp/Vol_log2
fsck de util-linux 2.23.2 /dev/mapper/mon_vol_grp-Vol_log2 : propre, 11/51200 fichiers, 12115/204800 blocs Size of logical volume mon_vol_grp/Vol_log2 changed from 200,00 MiB (50 extents) to <1,70 GiB (434 extents). Logical volume mon_vol_grp/Vol_log2 successfully resized. resize2fs 1.42.9 (28-Dec-2013) En train de redimensionner le système de fichiers sur /dev/mapper/mon_vol_grp-Vol_log2 à 1777664 (1k) blocs. Le système de fichiers /dev/mapper/mon_vol_grp-Vol_log2 a maintenant une taille de 1777664 blocs.
Vérification de l’augmentation d’espace du volume logique : lvdisplay
--- Logical volume ---
LV Path /dev/mon_vol_grp/Vol_log2
LV Name Vol_log2
VG Name mon_vol_grp
LV UUID IZPMp7-9cUV-eAxs-y8N9-cVE7-S7xZ-u60cWf
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2018-08-09 17:45:20 +0200
LV Status available
# open 0
LV Size <1,70 GiB
Current LE 434
Segments 3
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:3
--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID EWn4T0-2cLo-SWFu-skUZ-YiJ0-6bww-WywdiB
LV Write Access read/write
LV Creation host, time localhost, 2018-07-27 11:40:49 +0200
LV Status available
# open 2
LV Size 820,00 MiB
Current LE 205
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID J9QkbE-3a1e-AQ4k-lupo-aFZB-3m3g-n3e3kO
LV Write Access read/write
LV Creation host, time localhost, 2018-07-27 11:40:49 +0200
LV Status available
# open 1
LV Size <6,20 GiB
Current LE 1586
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
Voir effectivement que le filesystem est bien augmenté :
- mount /dev/mon_vol_grp/Vol_log2 /LVM_exemple/
- df -h
Sys. de fichiers Taille Utilisé Dispo Uti% Monté sur
/dev/mapper/centos-root 6,2G 1,1G 5,1G 18% /
devtmpfs 485M 0 485M 0% /dev
tmpfs 496M 0 496M 0% /dev/shm
tmpfs 496M 6,8M 490M 2% /run
tmpfs 496M 0 496M 0% /sys/fs/cgroup
/dev/sda1 1014M 129M 886M 13% /boot
tmpfs 100M 0 100M 0% /run/user/0
/dev/mapper/mon_vol_grp-Vol_log2 1,7G 2,7M 1,6G 1% /LVM_exemple
III.5.2 Réduire un volume logique
- lvresize –resizefs –size -1,5G /dev/mon_vol_grp/Vol_log2
Do you want to unmount "/LVM_exemple" ? [Y|n] y fsck de util-linux 2.23.2 /dev/mapper/mon_vol_grp-Vol_log2 : 11/444416 fichiers (0.0% non contigüs), 62946/1777664 blocs resize2fs 1.42.9 (28-Dec-2013) En train de redimensionner le système de fichiers sur /dev/mapper/mon_vol_grp-Vol_log2 à 204800 (1k) blocs. Le système de fichiers /dev/mapper/mon_vol_grp-Vol_log2 a maintenant une taille de 204800 blocs. Size of logical volume mon_vol_grp/Vol_log2 changed from <1,70 GiB (434 extents) to 200,00 MiB (50 extents). Logical volume mon_vol_grp/Vol_log2 successfully resized.
III.5.3 Enlever un disque physique d’un groupe de volumes
Enlever le volume physique du volume groupe :
- vgreduce mon_vol_grp /dev/sdb
Removed "/dev/sdb" from volume group "mon_vol_grp"
Résultat après un pvscan :
PV /dev/sdc VG mon_vol_grp lvm2 [1,07 GiB / 900,00 MiB free] PV /dev/sda2 VG centos lvm2 [<7,00 GiB / 0 free] PV /dev/sdb lvm2 [<1010,92 MiB] Total: 3 [<9,06 GiB] / in use: 2 [8,07 GiB] / in no VG: 1 [<1010,92 MiB]
Suppression du volume physique :
- pvremove /dev/sdb
Vérification avec pvscan :
PV /dev/sdc VG mon_vol_grp lvm2 [1,07 GiB / 900,00 MiB free] PV /dev/sda2 VG centos lvm2 [<7,00 GiB / 0 free] Total: 2 [8,07 GiB] / in use: 2 [8,07 GiB] / in no VG: 0 [0 ]