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

swapon

Switch swap spaces on (swapon) or off (swapoff), and show which are active.

المستوى
امتحان RHCSA
المجموعة
الأقراص وأنظمة الملفات
يحتاج root
للتغييرات
الحزمة
util-linux
يُسمّى أيضًا
swapoff

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

ماذا يفعل

swapon DEVICE activates a swap partition, LV or file; swapon -a activates all swap lines from /etc/fstab. swapon --show lists active swap spaces with size, use and priority. swapoff moves the pages back to RAM and turns swap off — it needs enough free memory.

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

swapon [OPTION]... [DEVICE]...
swapon --show
swapoff [-va] [DEVICE]...

الخيارات 18

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

-a, --all
All swap entries in /etc/fstab (not noauto).
--show[=COLUMNS]
List active swap spaces (NAME, TYPE, SIZE, USED, PRIO).
-s, --summary
Old summary format (like /proc/swaps).
-p, --priority N
Priority (-1 … 32767); higher is used first.
-d, --discard[=once|pages]
Use TRIM on SSDs.
-e, --ifexists
Skip devices that do not exist (with -a).
-f, --fixpgsz
Reinitialize when the page size does not match.
-L LABEL
Use the swap space with this label.
-U UUID
Use the swap space with this UUID.
-o, --options OPTS
Options like in fstab (pri=, discard).
-T, --fstab PATH
Use another fstab file.
--output-all
All columns.
--noheadings
No header line.
--raw
Raw output.
--bytes
Sizes in bytes.
-v, --verbose
Verbose.
-h, --help
Show help.
-V, --version
Show the version.

أمثلة 10

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

  1. 1Switch on a swap partition

    swapon /dev/vdb2

    Active until reboot.

  2. 2Show active swap

    swapon --show
    NAME      TYPE      SIZE USED PRIO
    /dev/dm-1 partition   2G   0B   -2
    /dev/vdb2 partition   1G   0B   -3

    Lower PRIO is used later.

  3. 3Switch on everything from fstab

    swapon -a

    Tests your fstab swap lines.

  4. 4Turn swap off

    swapoff /dev/vdb2

    Needs enough free RAM.

  5. 5Turn all swap off and on (empty it)

    swapoff -a && swapon -a

    Moves swapped pages back to RAM. Check free -h first.

  6. 6Use a fast disk first

    swapon -p 10 /dev/nvme0n1p3

    Higher priority = used first.

  7. 7Priority in fstab

    grep swap /etc/fstab
    UUID=8f1b… none swap defaults,pri=10 0 0

    Kept after reboot.

  8. 8By UUID or label

    swapon -U 8f1b2c3d-…; swapon -L swap2

    Without the device name.

  9. 9Discard on SSD

    swapon -d /dev/nvme0n1p3

    Frees unused blocks on the SSD.

  10. 10Check the kernel view

    cat /proc/swaps

    Same data as swapon -s.

الملفات

/etc/fstab
Swap lines (type swap).
/proc/swaps
Active swap spaces.

رموز الخروج

0Done.
1Error.
2Some swap spaces failed (with -a).