LVM logical volume manager sous Linux

Mise à jour: 2 janvier 2007
Version: 1.0
Author: Jean-Louis Bicquelet-Salaün
Location: http://jlbicquelet.free.fr
Copyright: (c) 2007 Jean-Louis BICQUELET-SALAÜN

FAQ Revised: Tuesday 02 January 2007 17:47:17


Table of Contents

1. physical volume
2. volume group
3. volume logique
4. filessytem

1. physical volume

1.1. Quelles sont les commandes permettant de manipuler les physical volumes?
pvchange  pvcreate  pvdata  pvdisplay  pvmove  pvscan


1.2. Comment savoir si on dispose d'un volume groupe?

Rechercher avec fdisk (p pour afficher, q pour quitter), les partitions de type Linux LVM.

fdisk /dev/hda

The number of cylinders for this disk is set to 4863.
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)

Commande (m pour aide) : p

Disk /dev/hda: 40.0 GB, 40000000000 bytes
255 heads, 63 sectors/track, 4863 cylinders
Units = cylindres of 16065 * 512 = 8225280 bytes

Peripherique Amorce    Debut       Fin    Blocs   Id  Systeme
/dev/hda1   *         1         8     64228+  83  Linux
/dev/hda2             9       530   4192965   83  Linux
/dev/hda3           531       791   2096482+  82  Echange Linux
/dev/hda4           792      4863  32708340   8e  Linux LVM

Commande (m pour aide) : q
Commande (m pour aide) : q

Utiliser pvdisplay sur la partition.

# pvdisplay /dev/hda4
--- Physical volume ---
PV Name               /dev/hda4
VG Name               datavg
PV Size               31.19 GB [65416680 secs] / NOT usable 32.19 MB [LVM: 131 KB]
PV#                   1
PV Status             available
Allocatable           yes
Cur LV                0
PE Size (KByte)       32768
Total PE              997
Free PE               997
Allocated PE          0
PV UUID               rg0134-lSEg-lvsj-kWUP-9PWC-btkV-pegj3M


1.3. Comment creer un volume groupe?
Utiliser pvcreate.


2. volume group

2.1. Quelles sont les commandes permettant de manipuler les volumes groupes?
vgcfgbackup      vgck       vgextend   vgreduce  vgscan.static
vgcfgrestore     vgcreate   vgimport   vgremove  vgsplit
vgchange         vgdisplay  vgmerge    vgrename  vgwrapper
vgchange.static  vgexport   vgmknodes  vgscan


2.2. Comment afficher les volumes groupes ?
 ./vgdisplay
--- Volume group ---
VG Name               datavg
VG Access             read/write
VG Status             available/resizable
VG #                  0
MAX LV                256
Cur LV                0
Open LV               0
MAX LV Size           2 TB
Max PV                256
Cur PV                1
Act PV                1
VG Size               31.16 GB
PE Size               32 MB
Total PE              997
Alloc PE / Size       0 / 0
Free  PE / Size       997 / 31.16 GB
VG UUID               9KoKrV-9u7P-wPPE-5Xrm-KkAA-V8XR-vG8eLZ


2.3. Comment afficher les caracteristiques d'un volume groupe?
Avec pvdisplay on obtient le nom du volume groupe:
pvdisplay /dev/hda4
--- Physical volume ---
PV Name               /dev/hda4
VG Name               datavg
PV Size               31.19 GB [65416680 secs] / NOT usable 32.19 MB [LVM: 131 KB]
PV#                   1
PV Status             available
Allocatable           yes
Cur LV                0
PE Size (KByte)       32768
Total PE              997
Free PE               997
Allocated PE          0
PV UUID               rg0134-lSEg-lvsj-kWUP-9PWC-btkV-pegj3M


Ici c'est datavg.

# vgdisplay datavg
--- Volume group ---
VG Name               datavg
VG Access             read/write
VG Status             available/resizable
VG #                  0
MAX LV                256
Cur LV                0
Open LV               0
MAX LV Size           2 TB
Max PV                256
Cur PV                1
Act PV                1
VG Size               31.16 GB
PE Size               32 MB
Total PE              997
Alloc PE / Size       0 / 0
Free  PE / Size       997 / 31.16 GB
VG UUID               9KoKrV-9u7P-wPPE-5Xrm-KkAA-V8XR-vG8eLZ

L'autre solution consiste à afficher les volume groupes actifs:

vgdisplay -A
--- Volume group ---
VG Name               datavg
VG Access             read/write
VG Status             available/resizable
VG #                  0
MAX LV                256
Cur LV                0
Open LV               0
MAX LV Size           2 TB
Max PV                256
Cur PV                1
Act PV                1
VG Size               31.16 GB
PE Size               32 MB
Total PE              997
Alloc PE / Size       0 / 0
Free  PE / Size       997 / 31.16 GB
VG UUID               9KoKrV-9u7P-wPPE-5Xrm-KkAA-V8XR-vG8eLZ


2.4. Comment afficher la liste des volumes groupes existants?
#vgdisplay -s
vgdisplay -- "datavg" (active/idle) 31.16 GB  [0         used / 31.16 GB free]


2.5. Comment ajouter un disque ou une partition à un volume groupe?
vgextend datavg /dev/hdb1


2.6. Comment supprimer un disque ou une partition à un volume groupe?
vgreduce datavg /dev/hdb1



3. volume logique

3.1. Quelles sont les commandes permettant de manipuler les volumes logiques?
lvchange  lvdisplay  lvmchange    lvmsadc  lvreduce  lvrename
lvcreate  lvextend   lvmdiskscan  lvmsar   lvremove  lvscan


3.2. Comment creer un volume logique?

Pour creer un volume logique de 1Go dans datavg:

#lvcreate -L1000 -n lv_intranet datavg
lvcreate -- rounding size up to physical extent boundary
lvcreate -- doing automatic backup of "datavg"
lvcreate -- logical volume "/dev/datavg/lv_intranet" successfully created


3.3. Comment connaitre les volumes logiques?

Premiere solution utiliser lvscan.

lvscan
lvscan -- ACTIVE            "/dev/datavg/lv_intranet" [1 GB]
lvscan -- 1 logical volumes with 1 GB total in 1 volume group
lvscan -- 1 active logical volumes

deuxieme solution lister /dev/vgname #ls /dev/datavg lv_intranet lv_tempo

3.4. Comment connaitre les volumes logiques?
#lvcreate -L1 -n lv_tempo datavg
lvcreate -- rounding size up to physical extent boundary
lvcreate -- doing automatic backup of "datavg"
lvcreate -- logical volume "/dev/datavg/lv_tempo" successfully created

# lvscan
lvscan -- ACTIVE            "/dev/datavg/lv_intranet" [1 GB]
lvscan -- ACTIVE            "/dev/datavg/lv_tempo" [32 MB]
lvscan -- 2 logical volumes with 1.03 GB total in 1 volume group
lvscan -- 2 active logical volumes
# lvremove /dev/datavg/lv_tempo
lvremove -- do you really want to remove "/dev/datavg/lv_tempo"? [y/n]: y
lvremove -- doing automatic backup of volume group "datavg"
lvremove -- logical volume "/dev/datavg/lv_tempo" successfully removed
# lvscan
lvscan -- ACTIVE            "/dev/datavg/lv_intranet" [1 GB]
lvscan -- 1 logical volumes with 1 GB total in 1 volume group
lvscan -- 1 active logical volumes


3.5. Comment supprimer un volume logique?
#lvremove /dev/datavg/lv_tempo



4. filessytem

4.1. Comment creer un filesystem et le monter sur un volume logique?
# mkfs.ext3 /dev/datavg/lv_intranet
mke2fs 1.32 (09-Nov-2002)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
131072 inodes, 262144 blocks
13107 blocks (5.00%) reserved for the super user
First data block=0
8 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376

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

This filesystem will be automatically checked every 32 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
# mkdir -p /intranet
# mount /dev/datavg/lv_intranet /intranet
# df
SysFichier           1K-blocs    Utilise Dispo.   Util% Monte sur
/dev/hda2              4127108   2979104    938356  77% /
/dev/hda1                62193      9315     49667  16% /boot
none                    251676         0    251676   0% /dev/shm
/dev/datavg/lv_intranet
                       1032088     32828    946832   4% /intranet



4.2. Comment augmenter la taille un tel filessytem?

Contrairement à AIX, il faut demonter le filesystem, le redimensionner puis le remonter. On eviote cependant, le reboot obligatoire avec fdisk.

# umount /intranet
[root@syst0018 sbin]# e2fsadm -L+1M  /dev/datavg/lv_intranet
e2fsadm -- rounding size up to physical extent boundary
e2fsck 1.32 (09-Nov-2002)
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/datavg/lv_intranet: 11/131072 files (0.0% non-contiguous), 12329/262144 blocks
lvextend -- extending logical volume "/dev/datavg/lv_intranet" to 1.03 GB
lvextend -- doing automatic backup of volume group "datavg"
lvextend -- logical volume "/dev/datavg/lv_intranet" successfully extended

resize2fs 1.32 (09-Nov-2002)
Begin pass 1 (max = 1)
Extending the inode table     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/datavg/lv_intranet is now 270336 blocks long.

e2fsadm -- ext2fs in logical volume /dev/datavg/lv_intranet successfully extended to 1.03 GB

[root@syst0018 sbin]# mount /dev/datavg/lv_intranet /intranet
# df
SysFichier           1K-blocs    Utilise Dispo.   Util% Monte sur
/dev/hda2              4127108   2979260    938200  77% /
/dev/hda1                62193      9315     49667  16% /boot
none                    251676         0    251676   0% /dev/shm
/dev/datavg/lv_intranet
                       1062800     32828    986720   4% /intranet

la commande e2fsadm fonctionne uniquement pour les filesystems de type ext2 et ext3. Pour les autres type de filesystems il faut utiliser:

lvextend -L+1M /dev/datavg/lv_intranet
lvextend -- rounding relative size up to physical extent boundary
lvextend -- extending logical volume "/dev/datavg/lv_intranet" to 1.06 GB
lvextend -- doing automatic backup of volume group "datavg"
lvextend -- logical volume "/dev/datavg/lv_intranet" successfully extended

# resize2fs /dev/datavg/lv_intranet
resize2fs 1.32 (09-Nov-2002)
Please run 'e2fsck -f /dev/datavg/lv_intranet' first.

# e2fsck -f /dev/datavg/lv_intranet
e2fsck 1.32 (09-Nov-2002)
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/datavg/lv_intranet: 11/147456 files (0.0% non-contiguous), 12843/270336 blocks
[root@syst0018 sbin]# resize2fs /dev/datavg/lv_intranet
resize2fs 1.32 (09-Nov-2002)
The filesystem on /dev/datavg/lv_intranet is now 278528 blocks long.


4.3. Comment diminuer la taille un tel filessytem?

Demonter le filesystem, utiliser lvreduce puis remonter le filesystem.

# lvreduce -L-2M /dev/datavg/lv_intranet
lvreduce -- rounding relative size up to physical extent boundary size
lvreduce -- WARNING: reducing active logical volume to 1.03 GB
lvreduce -- THIS MAY DESTROY YOUR DATA (filesystem etc.)
lvreduce -- do you really want to reduce "/dev/datavg/lv_intranet"? [y/n]: y
lvreduce -- doing automatic backup of volume group "datavg"
lvreduce -- logical volume "/dev/datavg/lv_intranet" successfully reduced



Copyright (c) 2006 Jean-Louis BICQUELET

Cette liste de question a été générée par makefaq.