Debian – Creazione VG-Group e LVM
In questa guida vedremo come creare un gruppo di volumi e un volume logico su di esso.
- Per prima cosa verifichiamo l'elenco dei volumi creati col comando pvscan:
# pvscanPV /dev/sda5 VG root-vg lvm2 [3,76 GiB / 0 free]
Total: 1 [3,76 GiB] / in use: 1 [3,76 GiB] / in no VG: 0 [0 ]
- Identifichiamo il disco o la partizione col comando fdisk:
# fdisk -l
Disk /dev/sda: 4 GiB, 4294967296 bytes, 8388608 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
Disklabel type: dos
Disk identifier: 0x9eb8d4e8
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 499711 497664 243M 83 Linux
/dev/sda2 501758 8386559 7884802 3,8G 5 Extended
/dev/sda5 501760 8386559 7884800 3,8G 8e Linux LVM
Disk /dev/sdb: 8 GiB, 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 /dev/mapper/root--vg-root: 3,6 GiB, 3812622336 bytes, 7446528 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 /dev/mapper/root--vg-swap_1: 212 MiB, 222298112 bytes, 434176 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
- Come si vede il disco sdb non ha una partizione, dobbiamo quindi iniziare creandone una, io uso solitamente fdisk o cfdisk:
# cfdisk /dev/sdb
4. Verifichiamo di nuovo ora dovremmo rilevare sdb1:
# fdisk -l
...
Disk /dev/sdb: 8 GiB, 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
Disklabel type: dos
Disk identifier: 0xc7092d7bDevice Boot Start End Sectors Size Id Type
/dev/sdb1 2048 16777215 16775168 8G 83 Linux
...
- Creiamo ora un volume fisico su sdb1:
# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created
- Verifichiamo che il volume fisico sia stato creato:
# pvscan
PV /dev/sda5 VG root-vg lvm2 [3,76 GiB / 0 free]
PV /dev/sdb1 lvm2 [8,00 GiB]
Total: 2 [11,76 GiB] / in use: 1 [3,76 GiB] / in no VG: 1 [8,00 GiB]
- Creiamo un nuovo gruppo di volumi chiamato "home_vg" ad esempio sul device sdb1:
# vgcreate home_vg /dev/sdb1
Volume group "home_vg" successfully created
- Visualizziamo l'elenco dei volumi esistenti:
# vgdisplay--- Volume group ---
VG Name home_vg
System ID
Format lvm2
Metadata Areas 1
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 1
Act PV 1
VG Size 8,00 GiB
PE Size 4,00 MiB
Total PE 2047
Alloc PE / Size 0 / 0
Free PE / Size 2047 / 8,00 GiB
VG UUID S5bdMf-4k7p-1Xv2-riGX-NnzN-s0mB-fiP1dQ--- Volume group ---
VG Name root-vg
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 3,76 GiB
PE Size 4,00 MiB
Total PE 962
Alloc PE / Size 962 / 3,76 GiB
Free PE / Size 0 / 0
VG UUID nIvyVA-2yp9-NpIZ-v826-PJfK-npXT-9gqaL1
- Creiamo un nuovo volume logico (lvm) da 2G sul gruppo di volumi home_vg:
# lvcreate -L 2G -n home-lv home_vg
Logical volume "home-lv" created
- Verifichiamo che il volume sia stato creato col comando lvdisplay:
# lvdisplay--- Logical volume ---
LV Path /dev/home_vg/home-lv
LV Name home-lv
VG Name home_vg
LV UUID hV8N5K-SR3t-gfNr-7chr-ofJO-7mxp-3RTvMy
LV Write Access read/write
LV Creation host, time debiannas, 2015-12-28 14:45:46 +0100
LV Status available
# open 0
LV Size 2,00 GiB
Current LE 512
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 254:2
...
- A questo punto dobbiamo formattare l'lvm, nell'esempio in ext4:
# mkfs.ext4 /dev/mapper/home_vg-home--lv
mke2fs 1.42.12 (29-Aug-2014)
Creazione del file system con 524288 4k blocchi e 131072 inode
Etichetta del file system=eef8936a-f3f5-4f9e-9938-cb9a4e3b289b
Backup del superblocco salvati nei blocchi:
32768, 98304, 163840, 229376, 294912
Allocating group tables: fatto
Scrittura delle tavole degli inode: fatto
Creating journal (16384 blocks): fatto
Scrittura delle informazioni dei super-blocchi e dell'accounting del file system: fatto
- Per fare in modo che venga montato in maniera automatica aggiungiamo il record nel file fstab:
# echo "/dev/mapper/home_vg-home--lv /home ext4 defaults 1 1" >> /etc/fstab
nell'esempio monto il volume creato al posto della /home quindi tutti gli eventuali file in home dovranno prima essere spostati su questo mount point per farlo potete fare un:
# mv /home /home.orig
e successivamente ricopiate verificando i diritti (rsync) oppure spostate col mv.
- Montiamo il volume:
# mount -a - Opzionalmente possiamo eliminare lost+found:
# cd home/
/home# ls -ahn
totale 24K
drwxr-xr-x 3 0 0 4,0K dic 28 14:51 .
drwxr-xr-x 22 0 0 4,0K dic 28 14:30 ..
drwx------ 2 0 0 16K dic 28 14:51 lost+found/home# rm -rf ./lost+found/
/home# ls -ahn
totale 8,0K
drwxr-xr-x 2 0 0 4,0K dic 28 14:52 .
drwxr-xr-x 22 0 0 4,0K dic 28 14:30 ..
- Per verificare che il volume logico sia effettivamente montato si può utilizzare anche il comando df:
# df -hFile system Dim. Usati Dispon. Uso% Montato su
/dev/dm-0 3,5G 1013M 2,3G 31% /
udev 10M 0 10M 0% /dev
tmpfs 201M 4,4M 196M 3% /run
tmpfs 501M 0 501M 0% /dev/shm
tmpfs 5,0M 0 5,0M 0% /run/lock
tmpfs 501M 0 501M 0% /sys/fs/cgroup
/dev/sda1 236M 33M 191M 15% /boot
/dev/mapper/home_vg-home--lv 2,0G 3,0M 1,8G 1% /home