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 15Naam in het boek: Managing Logical Volumes

Build and resize logical volumes (LVM)

LVM puts a flexible layer between disks and file systems. You can join disks into one pool, cut volumes from it, and make them bigger later without downtime. This chapter shows how to create physical volumes, volume groups and logical volumes, how to name and find them, and how to grow and shrink them.

  • 12 Lessen
  • 22 Commando's
  • 2 Labs

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

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

Examendoelen in dit hoofdstuk

  • Fysieke volumes maken en verwijderen
  • Fysieke volumes aan volumegroepen toevoegen
  • Logische volumes maken en verwijderen
  • Bestaande logische volumes groter maken

15.1

Understand the LVM layers

LVM has three layers: disks become physical volumes (PV), PVs are joined into a volume group (VG), and from the VG you cut logical volumes (LV). The file system goes on the LV.

LVM layers
 file systems:   /data (xfs)        /web (ext4)
 logical vols:   lvdata 5G          lvweb 3G
                 └────────── vgdata (VG, 12G) ──────────┘
 physical vols:  /dev/vdb1 (PV)  /dev/vdc (PV)
TermMeaning
PVA disk or partition prepared for LVM
VGThe storage pool made of one or more PVs
LVA "partition" cut from the VG; it gets a file system
PE / extentThe unit of space in a VG (default 4 MiB)

15.2

Know what LVM can do

The main reasons to use LVM.

  • Resize: grow (and for ext4 also shrink) volumes, add disks to a VG while it runs.
  • Join disks: one LV can use space from many disks.
  • Snapshots: a frozen view of an LV for backups.
  • Move data: pvmove moves data off a disk while it is in use, so you can replace the disk.
  • Thin provisioning, RAID and cache LVs (more advanced).

Notitie

RHEL installs the root and swap on LVM by default (VG rhel).

15.3

Create physical volumes

A PV can be a whole disk or a partition. With partitions, set the type to lvm first.

  1. (Partition way) Create a partition with type lvm.
    fdisk /dev/vdb
    Command (m for help): n          (+5G)
    Command (m for help): t          (lvm)
    Command (m for help): w
  2. Turn the partition (or a whole disk) into a PV.
    pvcreate /dev/vdb1
      Physical volume "/dev/vdb1" successfully created.
    pvcreate /dev/vdc
  3. Check the PVs.
    pvs
      PV         VG   Fmt  Attr PSize   PFree
      /dev/vda2  rhel lvm2 a--  <19.00g     0
      /dev/vdb1       lvm2 ---    5.00g  5.00g
      /dev/vdc        lvm2 ---   10.00g 10.00g
    pvdisplay /dev/vdb1

15.4

Create a volume group

Join one or more PVs into a VG. You can choose the extent size with -s (default 4 MiB).

vgcreate vgdata /dev/vdb1 /dev/vdc
  Volume group "vgdata" successfully created
vgs
  VG     #PV #LV #SN Attr   VSize   VFree
  vgdata   2   0   0 wz--n- <14.99g <14.99g
vgdisplay vgdata
vgcreate -s 8M vgbig /dev/vdd

Examentip

A task may ask for an extent size ("extents of 8 MiB") and an LV size in extents ("20 extents"): use vgcreate -s 8M and lvcreate -l 20. Check with vgdisplay (PE Size).

15.5

Create logical volumes and file systems

lvcreate cuts an LV from the VG: with -L a size, with -l a number of extents or a percentage.

  1. Create the LVs.
    lvcreate -n lvdata -L 5G vgdata
    lvcreate -n lvweb -l 50%FREE vgdata
    lvcreate -n lvlog -l 100 vgdata
    lvs
  2. Put a file system on them and mount them for good.
    mkfs.xfs /dev/vgdata/lvdata
    mkdir /data
    echo "/dev/vgdata/lvdata /data xfs defaults 0 0" >> /etc/fstab
    systemctl daemon-reload; mount -a
lvcreate sizeMeans
-L 5G5 GiB
-L 500M500 MiB
-l 100100 extents
-l 50%FREEHalf of the free space in the VG
-l 100%FREEAll free space
-l 20%VG20 % of the whole VG

15.6

Name and find LVM devices

An LV has several device names. All point to the same device-mapper device (/dev/dm-N).

NameExample
/dev/VG/LV/dev/vgdata/lvdata
/dev/mapper/VG-LV/dev/mapper/vgdata-lvdata
/dev/dm-N/dev/dm-3 (can change; do not use it)
ls -l /dev/vgdata/ /dev/mapper/
lsblk /dev/vdc
lvdisplay /dev/vgdata/lvdata

Onthoud

In fstab, /dev/VG/LV or /dev/mapper/VG-LV are stable names; you do not need the UUID for LVs.

15.7

Add space to a volume group

When the VG is full, add a new PV with vgextend.

pvcreate /dev/vdd
vgextend vgdata /dev/vdd
vgs vgdata

15.8

Grow a logical volume and its file system

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

lvextend -r -L +2G /dev/vgdata/lvdata
lvextend -r -l +100%FREE /dev/vgdata/lvweb
lvextend -r -L 10G /dev/vgdata/lvlog
df -h /data
Meaning
-L +2GAdd 2 GiB
-L 10GMake it 10 GiB in total
-l +100%FREEAdd all free space of the VG
-rAlso resize the file system (xfs_growfs or resize2fs)
  1. Without -r, grow the file system yourself.
    lvextend -L +2G /dev/vgdata/lvdata
    xfs_growfs /data
    resize2fs /dev/vgdata/lvweb

Examentip

Forgetting the file system is the classic mistake: the LV is bigger but df -h shows the old size. Always use lvextend -r.

15.9

Shrink volumes and reduce a volume group

XFS cannot shrink. ext4 can, but only unmounted — lvreduce -r does the steps for you. To remove a disk from a VG, first move its data away.

  1. Shrink an ext4 LV (with its file system).
    lvreduce -r -L 2G /dev/vgdata/lvweb
  2. Move data off a PV and remove it from the VG.
    pvmove /dev/vdc
    vgreduce vgdata /dev/vdc
    pvremove /dev/vdc
  3. Remove an LV and a VG you do not need anymore.
    umount /data
    lvremove /dev/vgdata/lvdata
    vgremove vgdata

Let op

Shrinking an LV without shrinking the file system first destroys the file system. Always use -r (or run resize2fs first). Remove the fstab line before you delete an LV, or the next boot fails.

15.10

Remember the main points

The most important facts of this chapter, in short.

15.11

Learn the key terms

The words of this chapter in simple English.

TermMeaning
LVMLogical Volume Manager: flexible storage on top of disks.
Physical volume (PV)A disk or partition prepared for LVM.
Volume group (VG)A pool of space made from one or more PVs.
Logical volume (LV)A part of a VG, used like a partition.
Physical extent (PE)The smallest block of space in a VG.
Device mapperThe kernel part that makes LVs appear as devices.
SnapshotA frozen copy of an LV at one moment.
Thin provisioningLVs that can be bigger than the space really used.

15.12

Check what you learned

Think about the answer first, then open it.

1Write the commands to make LV data of 500 MiB in a new VG vgdata on /dev/vdb.
2How do you make a VG with extents of 16 MiB?
3How do you make an LV of exactly 50 extents?
4How do you grow a mounted XFS LV by 1 GiB?
5The VG is full. How do you add the new disk /dev/vdc?

pvcreate /dev/vdc and vgextend VG /dev/vdc (vgextend can also make the PV for you).

6How do you see the free space in a VG?

vgs (column VFree) or vgdisplay VG.

7How do you take a disk out of a VG that holds data?

pvmove /dev/vdb to move the data to other PVs, then vgreduce VG /dev/vdb.

8Which two names can you use in fstab for LV data in VG vgdata?

/dev/vgdata/data or /dev/mapper/vgdata-data (or its UUID).

Oefenen

Alle commando's in dit hoofdstuk