08 Creare un mirrored Logical Volume

Da FOL Wiki.
Di: RobertMayr

Creazione mirrored LV

La creazione di un mirrorer LV comporta l'utilizzo di almeno 3 PV, perchè due PV saranno i rami del mirror, mentre il terzo PV servirà per salvare il mirror_log con le informazioni di tutte le scritture e letture svolte sul LV. Per prima cosa creare le partizioni sui dischi che ospiteranno i PV.

[[email protected] tmp]# fdisk /dev/hdb
[[email protected] tmp]# fdisk /dev/hdd
[[email protected] tmp]# fdisk /dev/hde

Inizializzare i PV sulle partizioni dei dischi in precedenza partizionati.

[[email protected] tmp]# pvcreate /dev/hd[bde]1
  Physical volume "/dev/hdb1" successfully created
  Physical volume "/dev/hdd1" successfully created
  Physical volume "/dev/hde1" successfully created

Creare un nuovo VG formato dai 3 nuovi PV. Nel nostro caso il nome del VG sarà "vg_mirror".

[[email protected] tmp]# vgcreate vg_mirr /dev/hdb1 /dev/hdd1 /dev/hde1
[[email protected] tmp]# pvs
  PV         VG         Fmt  Attr PSize   PFree  
  /dev/hda2  VolGroup00 lvm2 a-     7.88G      0 
  /dev/hdb1  vg_mirr    lvm2 a-     2.00G  2.00G
  /dev/hdd1  vg_mirr    lvm2 a-     2.00G  2.00G   
  /dev/hde1  vg_mirr    lvm2 a-   976.00M 976.00M

Ora bisognerà creare un nuovo LV tramite il comando lvcreate. Si dovrà specificare l'opzione "-m" che indica il tipo di mirror che verrà utilizzato. Se si specifica il valore 1 si avrà un linear LV con una copia dei dati su un altro PV, mentre specificando il valore 0 si avrà un semplice linear LV.

[[email protected] tmp]# lvcreate -m1 -l +1G  vg_mirr -n lv_mirr01
  Logical volume "lv_mirr01" created

Dopo aver creato il mirror si potrà verificare la percentuale di sync del mirror tramite il comando lvs, specificando le opzioni "-a" e "-o+devices". Nell'output del comando si potrà notare il LV appena creato e poi la composizione dei rami del mirror (LV_mimage_0/1) e del mirror log (LV_mlog). Quando il valore di copy sarà pari a 100.00 significa che tutti i dati sono stati allineati.

[[email protected] ~]# lvs -a -o +devices
  LV                   VG         Attr   LSize   Origin Snap%  Move Log            Copy%  Convert Devices                                   
  LogVol00             VolGroup01 -wi-ao   7.12G                                                  /dev/hda2(0)                              
  LogVol01             VolGroup01 -wi-ao 768.00M                                                  /dev/hda2(228)                            
  lv_mirr01            vg_mirr    mwi-a-   1.00G                    lv_mirr01_mlog 100.00         lv_mirr01_mimage_0(0),lv_mirr01_mimage_1(0)
  [lv_mirr01_mimage_0] vg_mirr    iwi-ao   1.00G                                                  /dev/hdb1(0)                              
  [lv_mirr01_mimage_1] vg_mirr    iwi-ao   1.00G                                                  /dev/hdd1(0)                              
  [lv_mirr01_mlog]     vg_mirr    lwi-ao   4.00M                                                  /dev/hde1(0)        

Se necessario, creare un filesystem sul nuovo LV creato. Successivamente, utilizzare il comando tune2fs per eseguire il tuning del fs e, nello specifico, azzerare i valori che comportano un fsck forzato schedulato.

[[email protected] ~]# mkfs.ext3 /dev/vg_mirr/lv_mirr01
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
256000 inodes, 512000 blocks
25600 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=524288000
16 block groups
32768 blocks per group, 32768 fragments per group
16000 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912

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

This filesystem will be automatically checked every 23 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

[[email protected] tmp]# tune2fs -c0 -i0 /dev/vg_mirr/lv_mirr01
tune2fs 1.39 (29-May-2006)
Setting maximal mount count to -1
Setting interval between checks to 0 seconds

Creare il mount point ed eseguire il mount manualmente. Se necesario fissare la modifica nel file /etc/fstab.

[[email protected] ~]# mkdir -p /mnt/mirr
[[email protected] ~]# mount /dev/vg_mirr/lv_mirr01 /mnt/mirr
[[email protected] ~]# df -h /mnt/mirr/
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_mirr-lv_mirr01
                     1008M   34M  924M   4% /mnt/mirr

Sostituzione ramo del mirror guasto

Nel nostro caso il primo ramo del mirror si è guastato ed ora sarà necesario eseguire la sostituzione del disco ed il recover del mirror LVM. Per prima cosa verificare che il filesystem creato sopra il LV in mirror sia ancora UP e funzionante.

[[email protected] mirr]# df -H /mnt/mirr/
Filesystem             Size   Used  Avail Use% Mounted on
/dev/mapper/vg_mirr-lv_mirr01 1.1G    35M   969M   4% /mnt/mirr
[[email protected] mirr]# touch  /mnt/mirr/prova

Verificando lo stato del LV si noterà che un nodo del mirror darà molteplici errori di "Input/output error", perchè non più raggiungibile. Nel nostro caso il disco che si è guastato sarà quello che ospita il PV /dev/hdb1.

[[email protected] ~]# lvs -a -o +devices
  /dev/mapper/vg_mirr-lv_mirr01_mimage_1-missing_0_0: read failed after 0 of 4096 at 0: Input/output error
  /dev/mapper/vg_mirr-lv_mirr01_mimage_1: read failed after 0 of 4096 at 0: Input/output error
  /dev/mapper/vg_mirr-lv_mirr01_mimage_1-missing_0_0: read failed after 0 of 4096 at 1073676288: Input/output error
  /dev/mapper/vg_mirr-lv_mirr01_mimage_1-missing_0_0: read failed after 0 of 4096 at 1073733632: Input/output error
  /dev/mapper/vg_mirr-lv_mirr01_mimage_1-missing_0_0: read failed after 0 of 4096 at 0: Input/output error
  /dev/mapper/vg_mirr-lv_mirr01_mimage_1-missing_0_0: read failed after 0 of 4096 at 4096: Input/output error
  /dev/mapper/vg_mirr-lv_mirr01_mimage_1-missing_0_0: read failed after 0 of 4096 at 0: Input/output error
  /dev/mapper/vg_mirr-lv_mirr01_mimage_1: read failed after 0 of 4096 at 1073676288: Input/output error
  /dev/mapper/vg_mirr-lv_mirr01_mimage_1: read failed after 0 of 4096 at 1073733632: Input/output error
  /dev/mapper/vg_mirr-lv_mirr01_mimage_1: read failed after 0 of 4096 at 0: Input/output error
  /dev/mapper/vg_mirr-lv_mirr01_mimage_1: read failed after 0 of 4096 at 4096: Input/output error
  /dev/mapper/vg_mirr-lv_mirr01_mimage_1: read failed after 0 of 4096 at 0: Input/output error
  Couldn't find device with uuid 'CokMiX-G2yp-4roK-ksrv-qpX0-Dt1l-7vcVGR'.
  /dev/mapper/vg_mirr-lv_mirr01_mimage_1-missing_0_0: read failed after 0 of 4096 at 0: Input/output error
  /dev/mapper/vg_mirr-lv_mirr01_mimage_1: read failed after 0 of 4096 at 0: Input/output error
  Couldn't find device with uuid 'CokMiX-G2yp-4roK-ksrv-qpX0-Dt1l-7vcVGR'.
  LV                   VG         Attr   LSize   Origin Snap%  Move Log            Copy%  Convert Devices                                    
  LogVol00             VolGroup01 -wi-ao   7.12G                                                  /dev/hda2(0)                               
  LogVol01             VolGroup01 -wi-ao 768.00M                                                  /dev/hda2(228)                             
  lv_mirr01            vg_mirr    mwi-a-   1.00G                    lv_mirr01_mlog 100.00         lv_mirr01_mimage_0(0),lv_mirr01_mimage_1(0)
  [lv_mirr01_mimage_0] vg_mirr    iwi-ao   1.00G                                                  /dev/hdd1(0)                               
  [lv_mirr01_mimage_1] vg_mirr    iwi-ao   1.00G                                                  unknown device(0)                          
  [lv_mirr01_mlog]     vg_mirr    lwi-ao   4.00M                                                  /dev/hde1(0)   

Per poter eseguire il recover bisognerà trasformare il LV in tipologia linear, e poi rimuovere tutti i PV guasti dal VG che ospita il mirror. Sarà dunque possibile lanciare il comando vgremove con l'opzione "--removemissing" per togliere tutti i PV che hanno problemi. In automatico il filesystem verrà smontato e il LV diventerà di tipo linear.

[[email protected] ~]# vgreduce --removemissing --force vg_mirr
  /dev/mapper/vg_mirr-lv_mirr01_mimage_1-missing_0_0: read failed after 0 of 4096 at 0: Input/output error
  /dev/mapper/vg_mirr-lv_mirr01_mimage_1: read failed after 0 of 4096 at 0: Input/output error
  /dev/mapper/vg_mirr-lv_mirr01_mimage_1-missing_0_0: read failed after 0 of 4096 at 1073676288: Input/output error
  /dev/mapper/vg_mirr-lv_mirr01_mimage_1-missing_0_0: read failed after 0 of 4096 at 1073733632: Input/output error
  /dev/mapper/vg_mirr-lv_mirr01_mimage_1-missing_0_0: read failed after 0 of 4096 at 0: Input/output error
  /dev/mapper/vg_mirr-lv_mirr01_mimage_1-missing_0_0: read failed after 0 of 4096 at 4096: Input/output error
  /dev/mapper/vg_mirr-lv_mirr01_mimage_1-missing_0_0: read failed after 0 of 4096 at 0: Input/output error
  /dev/mapper/vg_mirr-lv_mirr01_mimage_1: read failed after 0 of 4096 at 1073676288: Input/output error
  /dev/mapper/vg_mirr-lv_mirr01_mimage_1: read failed after 0 of 4096 at 1073733632: Input/output error
  /dev/mapper/vg_mirr-lv_mirr01_mimage_1: read failed after 0 of 4096 at 0: Input/output error
  /dev/mapper/vg_mirr-lv_mirr01_mimage_1: read failed after 0 of 4096 at 4096: Input/output error
  /dev/mapper/vg_mirr-lv_mirr01_mimage_1: read failed after 0 of 4096 at 0: Input/output error
  Couldn't find device with uuid 'CokMiX-G2yp-4roK-ksrv-qpX0-Dt1l-7vcVGR'.
  /dev/mapper/vg_mirr-lv_mirr01_mimage_1-missing_0_0: read failed after 0 of 4096 at 0: Input/output error
  /dev/mapper/vg_mirr-lv_mirr01_mimage_1: read failed after 0 of 4096 at 0: Input/output error
  Couldn't find device with uuid 'CokMiX-G2yp-4roK-ksrv-qpX0-Dt1l-7vcVGR'.
  /dev/mapper/vg_mirr-lv_mirr01_mimage_1-missing_0_0: read failed after 0 of 4096 at 0: Input/output error
  /dev/mapper/vg_mirr-lv_mirr01_mimage_1: read failed after 0 of 4096 at 0: Input/output error
  Couldn't find device with uuid 'CokMiX-G2yp-4roK-ksrv-qpX0-Dt1l-7vcVGR'.
  /dev/mapper/vg_mirr-lv_mirr01_mimage_1-missing_0_0: read failed after 0 of 4096 at 0: Input/output error
  /dev/mapper/vg_mirr-lv_mirr01_mimage_1: read failed after 0 of 4096 at 0: Input/output error
  Couldn't find device with uuid 'CokMiX-G2yp-4roK-ksrv-qpX0-Dt1l-7vcVGR'.
  /dev/mapper/vg_mirr-lv_mirr01_mimage_1-missing_0_0: read failed after 0 of 4096 at 0: Input/output error
  /dev/mapper/vg_mirr-lv_mirr01_mimage_1: read failed after 0 of 4096 at 0: Input/output error
  Couldn't find device with uuid 'CokMiX-G2yp-4roK-ksrv-qpX0-Dt1l-7vcVGR'.
  /dev/mapper/vg_mirr-lv_mirr01_mimage_1-missing_0_0: read failed after 0 of 4096 at 0: Input/output error
  /dev/mapper/vg_mirr-lv_mirr01_mimage_1: read failed after 0 of 4096 at 0: Input/output error
  Couldn't find device with uuid 'CokMiX-G2yp-4roK-ksrv-qpX0-Dt1l-7vcVGR'.
  WARNING: Bad device removed from mirror volume, vg_mirr/lv_mirr01
  WARNING: Mirror volume, vg_mirr/lv_mirr01 converted to linear due to device failure.
  Wrote out consistent volume group vg_mirr

Verificare che il LV sia diventato LV e che montando il filesystem non si siano persi dei dati utili.

[[email protected] mirr]# lvs -a -o +devices
  /dev/mapper/vg_mirr-lv_mirr01_mimage_1-missing_0_0: read failed after 0 of 4096 at 0: Input/output error
  LV        VG         Attr   LSize   Origin Snap%  Move Log Copy%  Convert Devices       
  LogVol00  VolGroup01 -wi-ao   7.12G                                       /dev/hda2(0)  
  LogVol01  VolGroup01 -wi-ao 768.00M                                       /dev/hda2(228)
  lv_mirr01 vg_mirr    -wi-ao   1.00G                                       /dev/hdd1(0)  
[[email protected] mirr]# vgs
  /dev/mapper/vg_mirr-lv_mirr01_mimage_1-missing_0_0: read failed after 0 of 4096 at 0: Input/output error
  VG         #PV #LV #SN Attr   VSize VFree
  VolGroup01   1   2   0 wz--n- 7.88G    0 
  vg_mirr      2   1   0 wz--n- 2.95G 1.95G

Aggiungere il nuovo disco e ricreare il partizionamento e PV per poterlo poi aggiungere nuovamente al VG che ospita il mirror su cui invocare il recover. In questo caso è stato sostiuito il disco a caldo ed è stato presentato al sistema.

[[email protected] mirr]# fdisk /dev/hdb1
[[email protected] mirr]# pvcreate /dev/hdb1
  Physical volume "/dev/hdb1" successfully created
[[email protected] mirr]# pvs
  PV         VG         Fmt  Attr PSize   PFree   
  /dev/hda2  VolGroup01 lvm2 a-     7.88G       0 
  /dev/hdb1             lvm2 --     2.00G    2.00G
  /dev/hdd1  vg_mirr    lvm2 a-     2.00G 1020.00M
  /dev/hde1  vg_mirr    lvm2 a-   976.00M  976.00M

Dopo di che aggiungere il PV al VG che ospita il mirror.

[[email protected] mirr]# vgextend vg_mirr /dev/hdb1
  Volume group "vg_mirr" successfully extended
[[email protected] mirr]# vgs
  VG         #PV #LV #SN Attr   VSize VFree
  VolGroup01   1   2   0 wz--n- 7.88G    0 
  vg_mirr      3   1   0 wz--n- 4.95G 3.95G

Dopo si potrà riconvertire nuovamente il LV da tipo linear a mirrored, tramite il comando lvconvert.

[[email protected] mirr]# lvconvert -m1 /dev/vg_mirr/lv_mirr01 
  /dev/vg_mirr/lv_mirr01: Converted: 37.9%
  /dev/vg_mirr/lv_mirr01: Converted: 76.6%
  /dev/vg_mirr/lv_mirr01: Converted: 100.0%
  Logical volume lv_mirr01 converted.

Il mirror ora è ritornato ad uno stato di consistenza corretta.

[[email protected] mirr]# lvs -a -o +devices
  LV                   VG         Attr   LSize   Origin Snap%  Move Log            Copy%  Convert Devices                                    
  LogVol00             VolGroup01 -wi-ao   7.12G                                                  /dev/hda2(0)                               
  LogVol01             VolGroup01 -wi-ao 768.00M                                                  /dev/hda2(228)                             
  lv_mirr01            vg_mirr    mwi-ao   1.00G                    lv_mirr01_mlog 100.00         lv_mirr01_mimage_0(0),lv_mirr01_mimage_1(0)
  [lv_mirr01_mimage_0] vg_mirr    iwi-ao   1.00G                                                  /dev/hdd1(0)                               
  [lv_mirr01_mimage_1] vg_mirr    iwi-ao   1.00G                                                  /dev/hdb1(0)                               
  [lv_mirr01_mlog]     vg_mirr    lwi-ao   4.00M                                                  /dev/hde1(0)   

Salvataggio mirror_log in memoria

In alcuni casi è possibile salvare il mirror_log non su disco ma all'interno della memoria ram. Questa operazione comporta uno spiacevole incoveniente quando viene eseguito il reboot, perchè il mirror_log viene perso e viene automaticamente eseguito il resync dei dati tra i due PV che formano il LV. Il comando per switchare sul mirror_log in memoria è il seguente:

[[email protected] mirr]# lvconvert --mirrorlog core /dev/vg_mirr/lv_mirr01
[[email protected] mirr]# lvconvert --corelog /dev/vg_mirr/lv_mirr01

Per riportare il mirror_log su disco, lanciare il comando seguente:

[[email protected] mirr]# lvconvert --mirrorlog disk /dev/vg_mirr/lv_mirr01

Sincronizzazione forzata LV mirrored

E' possibile forzare la sincronizzazione dei rami del mirror tramite il comando lvchange passando l'opzione "--resync".

[[email protected] mirr]# lvchange --resync /dev/vg_mirr/lv_mirr01

Si ricorda che la sincronizzazione viene già svolta automaticamente da LVM2.