Estendere volume logico tramite LVM (Logical Volume Management) su CentOS 7
In questo tutorial andremo a descrivere come estendere un volume logico tramite LVM (Logical Volume Management) su CentOS 7.
Consideriamo di partire da una macchina preinstallata CentOS 7 ( qui l’ articolo per l’ installazione) ed aggiorniamola
yum update
aggiungiamo un disco di 8 GB alla macchina virtuale e verifichiamo che il sistema lo veda
fdisk -l
Disk /dev/sda: 17.2 GB, 17179869184 bytes, 33554432 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Identificativo disco: 0x00052019Dispositivo Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 33554431 16264192 8e Linux LVMDisk /dev/sdb: 8589 MB, 8589934592 bytes, 16777216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/mapper/centos-root: 14.9 GB, 14889779200 bytes, 29081600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/mapper/centos-swap: 1719 MB, 1719664640 bytes, 3358720 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
in questa installazione di esempio è già presente un gruppo di volume ( volume group ) chiamato centos
vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 2 0 wz–n- <15,51g 40,00m
con un singolo volume fisico ( physical volume)
pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 centos lvm2 a– <15,51g 40,00m
e due volumi logici
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root centos -wi-ao—- <13,87g
swap centos -wi-ao—- 1,60g
supponiamo di voler estendere il volume logico root associato alla cartella del file system /
df -h
File system Dim. Usati Dispon. Uso% Montato su
/dev/mapper/centos-root 14G 1,3G 13G 10% /
devtmpfs 485M 0 485M 0% /dev
tmpfs 496M 0 496M 0% /dev/shm
tmpfs 496M 6,7M 489M 2% /run
tmpfs 496M 0 496M 0% /sys/fs/cgroup
/dev/sda1 497M 181M 317M 37% /boot
tmpfs 100M 0 100M 0% /run/user/0
Per incrementare le dimensioni di / , prima di tutto è necessario partizionare il nuovo disco
fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xba7378be.Comando (m per richiamare la guida): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Numero della partizione (1-4, default 1):
Primo sector (2048-16777215, predefinito 2048):
Utilizzo del valore predefinito 2048
Last sector, +sectors or +size{K,M,G} (2048-16777215, predefinito 16777215):
Utilizzo del valore predefinito 16777215
Partition 1 of type Linux and of size 8 GiB is set
selezioniamo la tipologia di partizione
Comando (m per richiamare la guida): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition ‘Linux’ to ‘Linux LVM’Comando (m per richiamare la guida): w
La tabella delle partizioni è stata alterata!Chiamata di ioctl() per rileggere la tabella delle partizioni.
Sincronizzazione dei dischi in corso.
verifichiamo la nuova partizione
fdisk -l /dev/sdb
Disk /dev/sdb: 8589 MB, 8589934592 bytes, 16777216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Identificativo disco: 0xba7378beDispositivo Boot Start End Blocks Id System
/dev/sdb1 2048 16777215 8387584 8e Linux LVM
creiamo quindi il nuovo volume fisico sulla nuova partizione
pvcreate /dev/sdb1
Physical volume “/dev/sdb1” successfully created.
verifichiamo la disponibilità
pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 centos lvm2 a– <15,51g 40,00m
/dev/sdb1 lvm2 — <8,00g <8,00g
l’ obiettivo di questo articolo è aumentare la dimensione del volume logico root, quindi prima estendiamo il volume group
vgextend centos /dev/sdb1
Volume group “centos” successfully extended
vgs
VG #PV #LV #SN Attr VSize VFree
centos 2 2 0 wz–n- 23,50g <8,04g
successivamente dopo una verifica dei volumi logici presenti
lvdisplay
— Logical volume —
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID 54NNfT-1nKu-NI0B-qxHe-dSDy-S5xk-Qy4xNU
LV Write Access read/write
LV Creation host, time localhost, 2018-04-05 17:49:18 +0200
LV Status available
# open 1
LV Size <13,87 GiB
Current LE 3550
Segments 1
Allocation inherit
Read ahead sectors auto
– currently set to 8192
Block device 253:0— Logical volume —
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID WI1VS1-n7ZK-w4ZF-o8MC-fpYs-ZNT9-E9ajts
LV Write Access read/write
LV Creation host, time localhost, 2018-04-05 17:49:18 +0200
LV Status available
# open 2
LV Size 1,60 GiB
Current LE 410
Segments 1
Allocation inherit
Read ahead sectors auto
– currently set to 8192
Block device 253:1
estendiamo il volume logico root al massimo dello spazio libero disponibile
lvextend -l +100%FREE /dev/centos/root
Size of logical volume centos/root changed from <13,87 GiB (3550 extents) to 21,90 GiB (5607 extents).
Logical volume centos/root successfully resized.
ed infine ridimensioniamo il file system xfs (per filesystem ext4 utilizzeremo l’istruzione resize2fs)
xfs_growfs /dev/centos/root
verifichiamo che il tutto sia come ci aspettavamo
df -hT
File system Tipo Dim. Usati Dispon. Uso% Montato su
/dev/mapper/centos-root xfs 22G 1,3G 21G 6% /
devtmpfs devtmpfs 485M 0 485M 0% /dev
tmpfs tmpfs 496M 0 496M 0% /dev/shm
tmpfs tmpfs 496M 6,7M 489M 2% /run
tmpfs tmpfs 496M 0 496M 0% /sys/fs/cgroup
/dev/sda1 xfs 497M 181M 317M 37% /boot
tmpfs tmpfs 100M 0 100M 0% /run/user/0