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

mkswap

Prepare a partition, logical volume or file to be used as swap space.

Niveau
RHCSA-examen
Groep
Schijven en bestandssystemen
Root nodig
Ja
Pakket
util-linux

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

Wat het doet

mkswap writes a swap signature (with a UUID and optional label). Then swapon switches it on. For a swap file, the file must exist first, be owned by root with mode 600, and have no holes.

Zo schrijf je het

mkswap [OPTION]... DEVICE [SIZE]

Opties 14

Meest gebruikt

-L, --label LABEL
Set a label.
-U, --uuid UUID
Set the UUID (clear, random, time or a value).
-c, --check
Check for bad blocks first.
-f, --force
Go on even when the device looks in use or too small.
-p, --pagesize SIZE
Page size to use.
-e, --endianness native|little|big
Byte order.
-v, --swapversion 1
Swap version (only 1).
-s, --size SIZE
Size of a swap file to create (newer util-linux).
-F, --file
Create the swap file (with --size; newer util-linux).
--lock[=MODE]
Lock the device.
-q, --quiet
No warnings.
--verbose
More output.
-h, --help
Show help.
-V, --version
Show the version.

Voorbeelden 10

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

  1. 1Swap on a partition

    mkswap /dev/vdb2
    Setting up swapspace version 1, size = 1024 MiB (1073737728 bytes)
    no label, UUID=8f1b2c3d-…

    Then swapon /dev/vdb2.

  2. 2With a label

    mkswap -L swap2 /dev/vdb2

    fstab can use LABEL=swap2.

  3. 3Swap on a logical volume

    lvcreate -n lvswap -L 2G rhel
    mkswap /dev/rhel/lvswap

    Easy to grow later.

  4. 4A swap file

    dd if=/dev/zero of=/swapfile bs=1M count=1024
    chmod 600 /swapfile
    mkswap /swapfile

    1 GiB file without holes.

  5. 5Create the swap file in one step (newer util-linux)

    mkswap -F -s 1G /swapfile

    Makes the file with the right mode.

  6. 6Use it and make it permanent

    swapon /swapfile
    echo '/swapfile none swap defaults 0 0' >> /etc/fstab

    Check with swapon --show.

  7. 7Get the UUID for fstab

    blkid -s UUID -o value /dev/vdb2

    Use UUID= in fstab, not the device name.

  8. 8Change the swap label later

    swaplabel -L swap2 /dev/vdb2

    Without recreating.

  9. 9Check for bad blocks first

    mkswap -c /dev/vdb2

    Slower; for old disks.

  10. 10Overwrite a device that looks in use

    mkswap -f /dev/vdb2

    Only when you are sure.

Let op

  • mkswap deletes the old content of the device.
  • A swap file with mode other than 600 lets users read memory pages: security risk.

Exitcodes

0Done.
1Error.