متقدم
البحث فيأدلة «كيف»
طريقة البحث
  • اكتب المهمة بكلماتك (find port، open firewall، disk full) أو الصق رسالة الخطأ بين علامتي تنصيص.
  • اختر «الإجابة السريعة» لترى الأوامر فقط، أو مجالًا لتبقى في مجال واحد.
  • "كلمتان" تجد العبارة بالضبط.
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث
جرّب:

كيف 73System · Storage

How to extend an LVM volume and its file system

/var is 95 % full and the app will stop soon. With LVM you can make a volume bigger online — no reboot, no unmount. You need free space in the volume group: from a new disk, or from a disk you made bigger in the hypervisor or cloud. This how-to covers both cases and grows the logical volume and the file system in one command.

  • 5 الدروس
  • 11 الأوامر

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

$ مستخدم عادي# بصلاحية root (أو مع sudo)

73.1

The quick answer

df -h /var
vgs
lvextend -r -L +20G /dev/rhel/var
df -h /var

-r (--resizefs) grows the file system too (XFS or ext4). Without it, df shows no change.

73.2

Step by step

  1. See the layout — which LV, which VG, how much is free:
lsblk
vgs
  VG   #PV #LV #SN Attr   VSize   VFree
  rhel   1   3   0 wz--n- <79.00g    0
lvs

VFree 0 = no free space: add some first (step 2 or 3).

  1. Case A — a new disk (for example /dev/sdb):
pvcreate /dev/sdb
vgextend rhel /dev/sdb
vgs
  1. Case B — the existing disk was made bigger (VMware, cloud disk resize). Grow the partition, then the PV:
growpart /dev/sda 3
pvresize /dev/sda3
vgs

growpart is in the cloud-utils-growpart package. If the PV is the whole disk (no partition), only pvresize /dev/sdb.

  1. Grow the LV and the file system together:
lvextend -r -L +20G /dev/rhel/var
lvextend -r -l +100%FREE /dev/rhel/var

The first adds 20 GB; the second takes all free space in the VG. Keep some free space when you use snapshots.

  1. **Forgot -r?** Grow the file system yourself:
xfs_growfs /var
resize2fs /dev/rhel/var

xfs_growfs takes the mount point; resize2fs (ext4) takes the device.

  1. Shrinking: XFS can not shrink. ext4 can, but only unmounted (lvreduce -r) — plan the size well, and back up first.

73.3

Check that it worked

df -h /var
Filesystem             Size  Used Avail Use% Mounted on
/dev/mapper/rhel-var    40G   19G   22G  47% /var
lvs rhel/var

df shows the new size, and the app writes again.

الأوامر في هذا الدرس

73.4

Common problems

ProblemCauseFix
Insufficient free spaceNo free extents in the VG.Add a disk (vgextend) or grow the disk (growpart + pvresize).
df still shows the old sizeOnly the LV grew, not the file system.xfs_growfs MOUNTPOINT or resize2fs DEVICE.
pvresize changes nothingThe partition was not grown.growpart DISK PARTNUM first.
growpart: NOCHANGEThe disk itself is not bigger (yet).Grow it in the hypervisor/cloud; on VMware rescan: echo 1 > /sys/class/block/sda/device/rescan.
New disk not visible in lsblkThe kernel did not see it.Rescan SCSI hosts or reboot (in a window).
Want to shrink XFSNot possible.Create a new smaller LV, copy the data, switch.

73.5

Go further

1What does -r do in lvextend -r -L +20G?

It grows the file system together with the logical volume.

2The disk was made bigger in the cloud, but vgs shows no free space. What is missing?

Grow the partition (growpart) and then the PV (pvresize).

كل الأوامر في هذا الفصل