Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

lvreduce

Make a logical volume smaller — with -r the file system is shrunk first (ext4 only; XFS cannot shrink).

Level
RHCSA exam
Group
LVM
Needs root
Yes
Package
lvm2

What it does

Shrinking is risky: if the LV gets smaller than the file system, data is lost. lvreduce -r checks and shrinks the file system before the LV (it may need to unmount it; newer lvm2 asks or does it with --fsmode manage).

XFS file systems cannot be shrunk. To make an XFS volume smaller: back up, recreate smaller, restore.

How to write it

lvreduce (-L [-]SIZE | -l [-]EXTENTS) [-r] [OPTION]... VG/LV

Options 21

Most used

-L, --size [-]SIZE
New size or - removed size, like -1G or 3G.
-l, --extents [-]N[%VG|%LV|%FREE|%ORIGIN]
In extents or percent.
-r, --resizefs
Shrink the file system first (ext4).
-n, --nofsck
Do not check the file system first.
--fs checksize|resize|resize_fsadm|ignore
File system handling (newer lvm2).
--fsmode manage|offline|nochange
May LVM unmount/mount for the resize.
-f, --force
Do not ask (dangerous).
-A, --autobackup y|n
Back up the metadata.
--noudevsync
Do not wait for udev.
--reportformat basic|json
Output format.

Common LVM options

-t, --test
Test only; change nothing.
-v, --verbose
More output (repeat for more).
-q, --quiet
Less output.
-y, --yes
Answer yes to questions.
-d, --debug
Debug output.
--config STRING
Override lvm.conf settings for this command only.
--commandprofile STRING, --profile STRING
Use a configuration profile.
--devices PV, --devicesfile STRING
Limit the devices LVM looks at.
--driverloaded y|n, --nolocking, --lockopt STRING, --nohints, --journal STRING
Special and debug settings.
-h, --help, --longhelp
Show help.
--version
Show the version.

Examples 10

$ run as a normal user# run as root (or with sudo)

  1. 1Shrink an ext4 LV safely

    lvreduce -r -L 3G /dev/vgfiles/lvdocs

    Runs e2fsck and resize2fs, then shrinks the LV.

  2. 2Remove 1 GiB

    lvreduce -r -L -1G /dev/vgfiles/lvdocs

    Relative size.

  3. 3Check the free space first

    df -h /docs

    The data must fit into the new size.

  4. 4Do it by hand (old way)

    umount /docs
    e2fsck -f /dev/vgfiles/lvdocs
    resize2fs /dev/vgfiles/lvdocs 3G
    lvreduce -L 3G /dev/vgfiles/lvdocs
    mount /docs

    File system first, then LV — never the other way.

  5. 5Test only

    lvreduce -t -r -L 3G /dev/vgfiles/lvdocs

    Shows what would happen.

  6. 6XFS cannot shrink

    lvreduce -r -L 3G /dev/vgfiles/lvfiles

    Fails for XFS: back up, lvremove, lvcreate smaller, mkfs.xfs, restore.

  7. 7Shrink a swap LV

    swapoff /dev/rhel/swap; lvreduce -L 1G /dev/rhel/swap; mkswap /dev/rhel/swap; swapon -a

    Swap holds no data after swapoff.

  8. 8Free space for another LV

    lvreduce -r -L -2G /dev/vgdata/lvweb; lvcreate -n lvnew -L 2G vgdata

    Move space between LVs in one VG.

  9. 9Verify the data afterwards

    ls /docs; df -h /docs

    Your files are still there.

  10. 10Back up before shrinking

    tar -czf /root/docs-backup.tgz -C /docs .

    Always, on real systems.

Watch out

  • Never lvreduce without -r on an LV with a file system: the end of the file system is cut off.

Exit codes

0Done.
5Error.