الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

lvreduce

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

المستوى
امتحان RHCSA
المجموعة
LVM
يحتاج root
نعم
الحزمة
lvm2

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

ماذا يفعل

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.

طريقة الكتابة

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

الخيارات 21

الأكثر استخدامًا

-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.

أمثلة 10

$ مستخدم عادي# بصلاحية root (أو مع 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.

انتبه

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

رموز الخروج

0 :: Done. 5 :: Error.

الدليل الكامل

هذه الصفحة تشرح الأمر بكلمات بسيطة. الدليل الأصلي فيه كل التفاصيل.

في الطرفية: man 8 lvreduce