Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

Hoofdstuk 11Naam in de cursus: Managing Storage with Logical Volume Manager

Manage storage with LVM

With plain partitions, a full disk is a big problem. With LVM (Logical Volume Manager), disks become a pool of space; you cut logical volumes out of it and make them bigger later — even while they are mounted. RHEL installs its own root file system on LVM. This chapter shows how to build, grow and shrink LVM storage.

  • 8 Lessen
  • 24 Commando's
  • 2 Labs

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

$ als gewone gebruiker# als root (of met sudo)

Vaardigheden in dit hoofdstuk

  • Logische volumes maken en vergroten

11.1

Know the three layers

Physical volumes (PV, disks or partitions) go into a volume group (VG, the pool). From the VG you make logical volumes (LV) that carry file systems or swap.

 /dev/vdb1   /dev/vdc        ← physical volumes (PV)
     └──────┬──────┘
         vg_data              ← volume group (VG): one pool, split into extents (4 MiB)
     ┌──────┴──────┐
   lv_web      lv_db         ← logical volumes (LV): /dev/vg_data/lv_web …
   (xfs)       (ext4)        ← file systems, mounted like any partition
WordMeaning
Physical extent (PE)The block size of the VG, 4 MiB by default. LV sizes are a number of extents.
/dev/VG/LVThe path of a logical volume (also /dev/mapper/VG-LV)

11.2

Create physical volumes and a volume group

pvcreate marks a disk or partition for LVM. vgcreate makes the pool from one or more PVs.

parted /dev/vdb mklabel gpt mkpart lvm1 1MiB 100% set 1 lvm on
pvcreate /dev/vdb1 /dev/vdc
  Physical volume "/dev/vdb1" successfully created.
  Physical volume "/dev/vdc" successfully created.
vgcreate vg_data /dev/vdb1 /dev/vdc
vgcreate -s 8M vg_big /dev/vdd
pvs
  PV         VG      Fmt  Attr PSize  PFree
  /dev/vda2  rhel    lvm2 a--  19.00g     0
  /dev/vdb1  vg_data lvm2 a--  <5.00g <5.00g
  /dev/vdc   vg_data lvm2 a--  <5.00g <5.00g
vgs
vgdisplay vg_data

-s 8M sets the extent size to 8 MiB (it can not change later).

Notitie

RHEL 10 keeps a list of the disks LVM may use in /etc/lvm/devices/system.devices. pvcreate and vgcreate add new disks to it. lvmdevices shows the list.

11.3

Create logical volumes

lvcreate cuts an LV out of the VG: by size (-L) or by number of extents (-l). Then make a file system and mount it like a partition.

lvcreate -n lv_web -L 2G vg_data
  Logical volume "lv_web" created.
lvcreate -n lv_db -l 250 vg_data
lvcreate -n lv_logs -l 50%FREE vg_data
lvcreate -n lv_rest -l 100%FREE vg_data
lvs
  LV      VG      Attr       LSize
  lv_db   vg_data -wi-a----- 1000.00m
  lv_web  vg_data -wi-a-----    2.00g
mkfs.xfs /dev/vg_data/lv_web
mkfs.ext4 /dev/vg_data/lv_db
mkdir -p /srv/web /srv/db
echo '/dev/vg_data/lv_web  /srv/web  xfs   defaults  0 0' >> /etc/fstab
echo '/dev/vg_data/lv_db   /srv/db   ext4  defaults  0 0' >> /etc/fstab
systemctl daemon-reload
mount -a

Examentip

"An LV of 250 extents with an extent size of 8 MiB" means vgcreate -s 8M and lvcreate -l 250. Read the task for both numbers.

11.4

Grow a volume group

When the VG is full, add a new disk with vgextend. Remove a PV with pvmove (move its data away) and vgreduce.

pvcreate /dev/vdd
vgextend vg_data /dev/vdd
vgs vg_data
pvmove /dev/vdc
vgreduce vg_data /dev/vdc
pvremove /dev/vdc

11.5

Grow a logical volume and its file system

lvextend -r makes the LV bigger and grows the file system in one step, while it is mounted.

lvextend -r -L +1G /dev/vg_data/lv_web
  Size of logical volume vg_data/lv_web changed from 2.00 GiB to 3.00 GiB.
  Logical volume vg_data/lv_web successfully resized.
meta-data=/dev/mapper/vg_data-lv_web isize=512    agcount=6, agsize=131072 blks
data blocks changed from 524288 to 786432
lvextend -r -l +100%FREE /dev/vg_data/lv_db
lvextend -r -L 5G /dev/vg_data/lv_web
df -h /srv/web
FormMeaning
-L +1G1 GiB more
-L 5GMake it 5 GiB in total
-l +100%FREEAll free space of the VG
-rAlso resize the file system (xfs_growfs or resize2fs)

Onthoud

Without -r, the LV grows but the file system does not — df shows the old size. Then run xfs_growfs /srv/web (XFS) or resize2fs /dev/vg_data/lv_db (ext4).

11.6

Make a logical volume smaller

Only ext4 can shrink, and it must be unmounted. XFS can not shrink: back up, make a new smaller LV, restore.

umount /srv/db
lvreduce -r -L 600M /dev/vg_data/lv_db
Do you want to unmount "/srv/db" ? [Y|n] y
mount /srv/db
df -h /srv/db

Let op

Shrinking below the space the data uses destroys data. Check df -h first and keep a backup.

11.7

Use an LV as swap

Swap on LVM can grow later, like any LV.

lvcreate -n lv_swap -L 1G vg_data
mkswap /dev/vg_data/lv_swap
echo '/dev/vg_data/lv_swap  none  swap  defaults  0 0' >> /etc/fstab
swapon -a
swapon --show
swapoff /dev/vg_data/lv_swap
lvextend -L +1G /dev/vg_data/lv_swap
mkswap /dev/vg_data/lv_swap
swapon -a

11.8

Remove LVM storage

Remove in the opposite order: unmount, LV, VG, PV — and remove the fstab line.

umount /srv/web
vim /etc/fstab
lvremove /dev/vg_data/lv_web
vgremove vg_data
pvremove /dev/vdb1 /dev/vdd

More: the RHCSA LVM chapter.

Oefenen

Alle commando's in dit hoofdstuk