User Tools

Site Tools


wikiv3:lvm

lvm

Comandos utilizados para os testes com o LVM:

PV (Phisical Volume)

  • pvs - saída resumida
  • pvscan - saída simples
  • pvdisplay - saída detalhada

VG (Volume Group)

  • vgs - saída resumida
  • vgscan - saída simples
  • vgdisplay - saída detahada

LV (Logical Volume)

  • vgs - saída resumida
  • vgscan - saída simples
  • vgdisplay - saída detahada

Criando um PV - (Phisical Volume)

root@storage:~# pvcreate /dev/sdb1 
  Physical volume "/dev/sdb1" successfully created
root@storage:~# pvdisplay 
  --- Physical volume ---
[...]
 
  "/dev/sdb1" is a new physical volume of "10,00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb1
  VG Name               
  PV Size               10,00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               0COeTY-cKv5-2XO8-eEvO-aeqp-p8cr-S6KMFZ

Criando um VG - (Volume Group)

root@storage:~# vgcreate storage /dev/sdb1 
  Volume group "storage" successfully created
root@storage:~# vgdisplay -v storage
    Using volume group(s) on command line.
  --- Volume group ---
  VG Name               storage
  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               10,00 GiB
  PE Size               4,00 MiB
  Total PE              2559
  Alloc PE / Size       0 / 0   
  Free  PE / Size       2559 / 10,00 GiB
  VG UUID               ISDC8i-JmXS-2cH7-WD8y-klzE-sSLo-FzuWmr
 
  --- Physical volumes ---
  PV Name               /dev/sdb1     
  PV UUID               0COeTY-cKv5-2XO8-eEvO-aeqp-p8cr-S6KMFZ
  PV Status             allocatable
  Total PE / Free PE    2559 / 2559

Criando um LV - (Logical Volume)

root@storage:~# lvcreate -L 2G -n lv_volume01 storage
  Logical volume "lv_volume01" created.
root@storage:~# lvcreate -L 2G -n lv_volume02 storage
  Logical volume "lv_volume02" created.
root@storage:~# lvdisplay -v /dev/storage/lv_volume01 
    Using logical volume(s) on command line.
  --- Logical volume ---
  LV Path                /dev/storage/lv_volume01
  LV Name                lv_volume01
  VG Name                storage
  LV UUID                SDXx5n-8V49-HsX3-fvqA-VFUo-bZ0u-ZpPs7a
  LV Write Access        read/write
  LV Creation host, time storage, 2016-01-28 14:55:48 -0300
  LV Status              available
  # open                 0
  LV Size                2,00 GiB
  Current LE             512
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:6

Aplicando sistema de arquivo

  • EXT4 para o volume01
  • XFS para o volume02
root@storage:~# mkfs.ext4 /dev/storage/lv_volume01 
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
131072 inodes, 524288 blocks
26214 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=536870912
16 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912
 
Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
root@storage:~# mkfs.xfs /dev/storage/lv_volume02 
meta-data=/dev/storage/lv_volume02 isize=256    agcount=4, agsize=131072 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0
data     =                       bsize=4096   blocks=524288, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

Montando os volumes

root@storage:~# mount /dev/storage/lv_volume01 /srv/
root@storage:~# mount /dev/storage/lv_volume02 /mnt/

Aumentando o tamanho do LV - (Logical Volume)

Aumentar em mais 2GB os lvs

root@storage:~# lvextend -L +2G /dev/storage/lv_volume01 
  Size of logical volume storage/lv_volume01 changed from 2,00 GiB (512 extents) to 4,00 GiB (1024 extents).
  Logical volume lv_volume01 successfully resized.

Checando a integridade do volume para o sistema EXT4

root@storage:~# umount /srv/
root@storage:~# e2fsck -f /dev/storage/lv_volume01 
e2fsck 1.42.9 (28-Dec-2013)
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/storage/lv_volume01: 11/131072 files (0.0% non-contiguous), 26156/524288 blocks
root@storage:~# resize2fs /dev/storage/lv_volume01 
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/storage/lv_volume01 to 1048576 (4k) blocks.
The filesystem on /dev/storage/lv_volume01 is now 1048576 blocks long.

Para o file system XFS:

root@storage:~# lvextend -L +2G /dev/storage/lv_volume02 
  Size of logical volume storage/lv_volume02 changed from 2,00 GiB (512 extents) to 4,00 GiB (1024 extents).
  Logical volume lv_volume02 successfully resized.
root@storage:~# xfs_growfs /mnt/
meta-data=/dev/mapper/storage-lv_volume02 isize=256    agcount=4, agsize=131072 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0
data     =                       bsize=4096   blocks=524288, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 524288 to 1048576

FIXME Sistemas de arquivos XFS deve ser montado para ser redimensionada e o ponto de montagem é especificado em vez do nome do dispositivo.

root@storage:~# mount /dev/storage/lv_volume01 /srv/
root@storage:~# df -hT | tail -n2
/dev/mapper/storage-lv_volume02 xfs       4,0G   33M  4,0G   1% /mnt
/dev/mapper/storage-lv_volume01 ext4      3,9G  8,0M  3,7G   1% /srv

Diminuindo o tamanho do LV

Para file system extX

root@storage:~# umount /srv/
root@storage:~# e2fsck -ff /dev/storage/lv_volume01 
e2fsck 1.42.9 (28-Dec-2013)
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/storage/lv_volume01: 11/262144 files (0.0% non-contiguous), 53326/1048576 blocks
root@storage:~# resize2fs /dev/storage/lv_volume01 2GB
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Invalid new size: 2GB
root@storage:~# lvreduce -L -2G /dev/storage/lv_volume01 
  WARNING: Reducing active logical volume to 2,00 GiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv_volume01? [y/n]: y
  Size of logical volume storage/lv_volume01 changed from 4,00 GiB (1024 extents) to 2,00 GiB (512 extents).
  Logical volume lv_volume01 successfully resized.
root@storage:~# mount /dev/storage/lv_volume01 /srv/
root@storage:~# df -hT | tail -n1
/dev/mapper/storage-lv_volume01 ext4      1,9G   12M  1,8G   1% /srv

FIXME Não é possível reduzir o file system XFS

Removendo o LV

root@storage:~# lvremove /dev/storage/lv_volume01 
Do you really want to remove active logical volume lv_volume01? [y/n]: y
  Logical volume "lv_volume01" successfully removed
root@storage:~# lvremove /dev/storage/lv_volume02
Do you really want to remove active logical volume lv_volume02? [y/n]: y
  Logical volume "lv_volume02" successfully removed

FIXME Os volumes precisam estar desmontatos

wikiv3/lvm.txt · Last modified: by 127.0.0.1