Fonti
Esempio, creazione di un Logical Volume in Volume Group con tre partizioni ed Estensione del VG.
Visualizzare i dischi fisici e le partizioni
fdisk -l
lsblk
pvscan (mostra spazio libero)
Nuovo disco:
/dev/sdb
Creare 3 partizioni sul disco /dev/sdb da 100M
fdisk /dev/sdb
n
Creare 3 partizioni sul disco /dev/sdb da 100M
fdisk /dev/sdb
n
p
1
(primo settore default)
ultimo: +100M
fdisk /dev/sdb
n
n
p
2
(primo settore default)
ultimo: +100M
fdisk /dev/sdb
n
n
p
3
(primo settore default)
ultimo: +100M
Visualizzare le partizioni create:
p
p
Device Boot Start End Blocks Id System
/dev/sdb1 2048 206847 102400 83 Linux
/dev/sdb2 206848 411647 102400 83 Linux
/dev/sdb3 411648 616447 102400 83 Linux
/dev/sdb1 2048 206847 102400 83 Linux
/dev/sdb2 206848 411647 102400 83 Linux
/dev/sdb3 411648 616447 102400 83 Linux
eventualmente t per cambiare tipo di partizione in LSV
8e = changes to LVM partition type
8e = changes to LVM partition type
ma non sembra necessario
w per salvare
———————–
Update the kernel to save the changes without restarting the system.
partprobe
Creare i volumi fisici
[root@localhost boot]# pvcreate /dev/sdb1 /dev/sdb2 /dev/sdb3
Physical volume "/dev/sdb1" successfully created
Physical volume "/dev/sdb2" successfully created
Physical volume "/dev/sdb3" successfully created
Physical volume "/dev/sdb1" successfully created
Physical volume "/dev/sdb2" successfully created
Physical volume "/dev/sdb3" successfully created
Visualizza i volumi fisici:
[root@localhost boot]# pvdisplay
— Physical volume —
PV Name /dev/sda2
VG Name centos
PV Size 19.51 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 4994
Free PE 10
Allocated PE 4984
PV UUID 5YZUsZ-zVgG-xW7k-rIsC-EAJa-UmhV-emiLFk
"/dev/sdb3" is a new physical volume of "100.00 MiB"
— NEW Physical volume —
PV Name /dev/sdb3
VG Name
PV Size 100.00 MiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID kCpgqS-Q4mx-AaiR-kydR-7ltE-SepA-xGL7zM
"/dev/sdb1" is a new physical volume of "100.00 MiB"
— NEW Physical volume —
PV Name /dev/sdb1
VG Name
PV Size 100.00 MiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID sy34gi-QIt4-vT7F-xH25-4bE9-luEc-qBThrs
"/dev/sdb2" is a new physical volume of "100.00 MiB"
— NEW Physical volume —
PV Name /dev/sdb2
VG Name
PV Size 100.00 MiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID AQm0MW-yRIU-12LM-dRip-7IIA-bkAe-ncdwvI
— Physical volume —
PV Name /dev/sda2
VG Name centos
PV Size 19.51 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 4994
Free PE 10
Allocated PE 4984
PV UUID 5YZUsZ-zVgG-xW7k-rIsC-EAJa-UmhV-emiLFk
"/dev/sdb3" is a new physical volume of "100.00 MiB"
— NEW Physical volume —
PV Name /dev/sdb3
VG Name
PV Size 100.00 MiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID kCpgqS-Q4mx-AaiR-kydR-7ltE-SepA-xGL7zM
"/dev/sdb1" is a new physical volume of "100.00 MiB"
— NEW Physical volume —
PV Name /dev/sdb1
VG Name
PV Size 100.00 MiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID sy34gi-QIt4-vT7F-xH25-4bE9-luEc-qBThrs
"/dev/sdb2" is a new physical volume of "100.00 MiB"
— NEW Physical volume —
PV Name /dev/sdb2
VG Name
PV Size 100.00 MiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID AQm0MW-yRIU-12LM-dRip-7IIA-bkAe-ncdwvI
Visualizza un ricapitolativo di lvm
[root@localhost boot]# lvmdiskscan
/dev/centos/root [ 17.47 GiB]
/dev/sda1 [ 500.00 MiB]
/dev/centos/swap [ 2.00 GiB]
/dev/sda2 [ 19.51 GiB] LVM physical volume
/dev/sdb1 [ 100.00 MiB] LVM physical volume
/dev/sdb2 [ 100.00 MiB] LVM physical volume
/dev/sdb3 [ 100.00 MiB] LVM physical volume
Creare i volume group
Creo un VG con i due vuoumi fisici, il terzo lo aggiungo dopo per espandere
[root@localhost boot]# vgcreate vg1 /dev/sdb1 /dev/sdb2
Volume group "vg1" successfully created
Volume group "vg1" successfully created
Visualizzo i volume groups
[root@localhost boot]# vgdisplay
— Volume group —
VG Name vg1
System ID
Format lvm2
Metadata Areas 2
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 2
Act PV 2
VG Size 192.00 MiB
PE Size 4.00 MiB
Total PE 48
Alloc PE / Size 0 / 0
Free PE / Size 48 / 192.00 MiB
VG UUID gjGT2M-e1u7-51OB-zER1-2Vtg-A0KW-eRv6OI
VG Name vg1
System ID
Format lvm2
Metadata Areas 2
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 2
Act PV 2
VG Size 192.00 MiB
PE Size 4.00 MiB
Total PE 48
Alloc PE / Size 0 / 0
Free PE / Size 48 / 192.00 MiB
VG UUID gjGT2M-e1u7-51OB-zER1-2Vtg-A0KW-eRv6OI
Creo il volume logico
[root@localhost boot]# lvcreate -L 180M vg1 -n lv1
Visualizzo il volume logico creato
[root@localhost boot]# lvdisplay
— Logical volume —
LV Path /dev/vg1/lv1
LV Name lv1
VG Name vg1
LV UUID yDJY0o-b56e-OAbq-uoJW-c57K-HDpI-I6tXns
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2015-08-04 12:52:51 +0200
LV Status available
# open 0
LV Size 180.00 MiB
Current LE 45
Segments 2
Allocation inherit
Read ahead sectors auto
– currently set to 8192
Block device 253:2
LV Path /dev/vg1/lv1
LV Name lv1
VG Name vg1
LV UUID yDJY0o-b56e-OAbq-uoJW-c57K-HDpI-I6tXns
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2015-08-04 12:52:51 +0200
LV Status available
# open 0
LV Size 180.00 MiB
Current LE 45
Segments 2
Allocation inherit
Read ahead sectors auto
– currently set to 8192
Block device 253:2
Formatto e monto il volume logico creato
[root@localhost boot]# mkfs.ext4 /dev/vg1/lv1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
46184 inodes, 184320 blocks
9216 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=33816576
23 block groups
8192 blocks per group, 8192 fragments per group
2008 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
46184 inodes, 184320 blocks
9216 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=33816576
23 block groups
8192 blocks per group, 8192 fragments per group
2008 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
[root@localhost boot]# mount /dev/vg1/lv1 /mnt/
Esterndere un volume group
Estendo il volume group aggiungendo un'altra partizione
[root@localhost boot]# vgextend vg1 /dev/sdb3
Volume group "vg1" successfully extended
Volume group "vg1" successfully extended
Faccio il resize del del volume logico
[root@localhost vg1]# lvresize -L +100M /dev/vg1/lv1
oppure
[root@localhost vg1]# lvresize -l +100%FREE /dev/vg1/lv1
Faccio il resize del filesystem del volume logico
[root@localhost vg1]# resize2fs /dev/vg1/lv1
Rimuovere un Volume logico
[root@localhost /]# cd ..
[root@localhost /]# umount /mnt/
[root@localhost /]# lvremove /dev/vg1/lv1
Do you really want to remove active logical volume lv1? [y/n]: y
Logical volume "lv1" successfully removed
[root@localhost /]# umount /mnt/
[root@localhost /]# lvremove /dev/vg1/lv1
Do you really want to remove active logical volume lv1? [y/n]: y
Logical volume "lv1" successfully removed
Rimuovere un Volume Group
[root@localhost /]# vgremove /dev/vg1
Volume group "vg1" successfully removed
Volume group "vg1" successfully removed
Rimuovere un Phisical Volume
[root@localhost /]# pvremove /dev/sdb1 /dev/sdb2 /dev/sdb3
Labels on physical volume "/dev/sdb1" successfully wiped
Labels on physical volume "/dev/sdb2" successfully wiped
Labels on physical volume "/dev/sdb3" successfully wiped
Labels on physical volume "/dev/sdb1" successfully wiped
Labels on physical volume "/dev/sdb2" successfully wiped
Labels on physical volume "/dev/sdb3" successfully wiped
INFO
I Volume group e i Logical Volume si trovano sotto:
/dev/NomeVolumeGroup/NomeLogicalVolume